Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
Greg Daniel | c0d6915 | 2020-10-08 14:59:00 -0400 | [diff] [blame] | 8 | #include "src/gpu/mock/GrMockGpu.h" |
| 9 | |
| 10 | #include "src/gpu/mock/GrMockAttachment.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "src/gpu/mock/GrMockBuffer.h" |
| 12 | #include "src/gpu/mock/GrMockCaps.h" |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 13 | #include "src/gpu/mock/GrMockOpsRenderPass.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "src/gpu/mock/GrMockTexture.h" |
Greg Daniel | c0d6915 | 2020-10-08 14:59:00 -0400 | [diff] [blame] | 15 | |
Mike Klein | de2244c | 2018-12-04 11:16:08 -0500 | [diff] [blame] | 16 | #include <atomic> |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 17 | |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 18 | int GrMockGpu::NextInternalTextureID() { |
Mike Klein | de2244c | 2018-12-04 11:16:08 -0500 | [diff] [blame] | 19 | static std::atomic<int> nextID{1}; |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 20 | int id; |
| 21 | do { |
Adlai Holler | 4888cda | 2020-11-06 16:37:37 -0500 | [diff] [blame] | 22 | id = nextID.fetch_add(1, std::memory_order_relaxed); |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 23 | } while (0 == id); // Reserve 0 for an invalid ID. |
| 24 | return id; |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | int GrMockGpu::NextExternalTextureID() { |
| 28 | // We use negative ints for the "testing only external textures" so they can easily be |
| 29 | // identified when debugging. |
Mike Klein | de2244c | 2018-12-04 11:16:08 -0500 | [diff] [blame] | 30 | static std::atomic<int> nextID{-1}; |
Adlai Holler | 4888cda | 2020-11-06 16:37:37 -0500 | [diff] [blame] | 31 | return nextID.fetch_add(-1, std::memory_order_relaxed); |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 32 | } |
| 33 | |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 34 | int GrMockGpu::NextInternalRenderTargetID() { |
Mike Klein | de2244c | 2018-12-04 11:16:08 -0500 | [diff] [blame] | 35 | // We start off with large numbers to differentiate from texture IDs, even though they're |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 36 | // technically in a different space. |
Mike Klein | de2244c | 2018-12-04 11:16:08 -0500 | [diff] [blame] | 37 | static std::atomic<int> nextID{SK_MaxS32}; |
Adlai Holler | 4888cda | 2020-11-06 16:37:37 -0500 | [diff] [blame] | 38 | return nextID.fetch_add(-1, std::memory_order_relaxed); |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | int GrMockGpu::NextExternalRenderTargetID() { |
| 42 | // We use large negative ints for the "testing only external render targets" so they can easily |
| 43 | // be identified when debugging. |
Mike Klein | de2244c | 2018-12-04 11:16:08 -0500 | [diff] [blame] | 44 | static std::atomic<int> nextID{SK_MinS32}; |
Adlai Holler | 4888cda | 2020-11-06 16:37:37 -0500 | [diff] [blame] | 45 | return nextID.fetch_add(1, std::memory_order_relaxed); |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 46 | } |
| 47 | |
Brian Salomon | 384fab4 | 2017-12-07 12:33:05 -0500 | [diff] [blame] | 48 | sk_sp<GrGpu> GrMockGpu::Make(const GrMockOptions* mockOptions, |
Adlai Holler | 3d0359a | 2020-07-09 15:35:55 -0400 | [diff] [blame] | 49 | const GrContextOptions& contextOptions, GrDirectContext* direct) { |
Greg Daniel | 02611d9 | 2017-07-25 10:05:01 -0400 | [diff] [blame] | 50 | static const GrMockOptions kDefaultOptions = GrMockOptions(); |
| 51 | if (!mockOptions) { |
| 52 | mockOptions = &kDefaultOptions; |
| 53 | } |
Adlai Holler | 3d0359a | 2020-07-09 15:35:55 -0400 | [diff] [blame] | 54 | return sk_sp<GrGpu>(new GrMockGpu(direct, *mockOptions, contextOptions)); |
Greg Daniel | 02611d9 | 2017-07-25 10:05:01 -0400 | [diff] [blame] | 55 | } |
| 56 | |
Greg Daniel | 65476e0 | 2020-10-27 09:20:20 -0400 | [diff] [blame] | 57 | GrOpsRenderPass* GrMockGpu::onGetOpsRenderPass(GrRenderTarget* rt, |
Greg Daniel | c0d6915 | 2020-10-08 14:59:00 -0400 | [diff] [blame] | 58 | GrAttachment*, |
| 59 | GrSurfaceOrigin origin, |
| 60 | const SkIRect& bounds, |
| 61 | const GrOpsRenderPass::LoadAndStoreInfo& colorInfo, |
| 62 | const GrOpsRenderPass::StencilLoadAndStoreInfo&, |
| 63 | const SkTArray<GrSurfaceProxy*, true>& sampledProxies, |
| 64 | GrXferBarrierFlags renderPassXferBarriers) { |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 65 | return new GrMockOpsRenderPass(this, rt, origin, colorInfo); |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 66 | } |
| 67 | |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 68 | void GrMockGpu::submit(GrOpsRenderPass* renderPass) { |
| 69 | for (int i = 0; i < static_cast<GrMockOpsRenderPass*>(renderPass)->numDraws(); ++i) { |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 70 | fStats.incNumDraws(); |
| 71 | } |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 72 | delete renderPass; |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 73 | } |
| 74 | |
Adlai Holler | 3d0359a | 2020-07-09 15:35:55 -0400 | [diff] [blame] | 75 | GrMockGpu::GrMockGpu(GrDirectContext* direct, const GrMockOptions& options, |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 76 | const GrContextOptions& contextOptions) |
Adlai Holler | 3d0359a | 2020-07-09 15:35:55 -0400 | [diff] [blame] | 77 | : INHERITED(direct) |
Chris Dalton | 91ab155 | 2018-04-18 13:24:25 -0600 | [diff] [blame] | 78 | , fMockOptions(options) { |
Brian Osman | cbdc261 | 2020-11-23 15:30:48 -0500 | [diff] [blame^] | 79 | this->initCapsAndCompiler(sk_make_sp<GrMockCaps>(contextOptions, options)); |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 80 | } |
| 81 | |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 82 | void GrMockGpu::querySampleLocations(GrRenderTarget* rt, SkTArray<SkPoint>* sampleLocations) { |
| 83 | sampleLocations->reset(); |
| 84 | int numRemainingSamples = rt->numSamples(); |
| 85 | while (numRemainingSamples > 0) { |
| 86 | // Use standard D3D sample locations. |
| 87 | switch (numRemainingSamples) { |
| 88 | case 0: |
| 89 | case 1: |
| 90 | sampleLocations->push_back().set(.5, .5); |
| 91 | break; |
| 92 | case 2: |
| 93 | sampleLocations->push_back().set(.75, .75); |
| 94 | sampleLocations->push_back().set(.25, .25); |
| 95 | break; |
| 96 | case 3: |
| 97 | case 4: |
| 98 | sampleLocations->push_back().set(.375, .125); |
| 99 | sampleLocations->push_back().set(.875, .375); |
| 100 | sampleLocations->push_back().set(.125, .625); |
| 101 | sampleLocations->push_back().set(.625, .875); |
| 102 | break; |
| 103 | case 5: |
| 104 | case 6: |
| 105 | case 7: |
| 106 | case 8: |
| 107 | sampleLocations->push_back().set(.5625, .3125); |
| 108 | sampleLocations->push_back().set(.4375, .6875); |
| 109 | sampleLocations->push_back().set(.8125, .5625); |
| 110 | sampleLocations->push_back().set(.3125, .1875); |
| 111 | sampleLocations->push_back().set(.1875, .8125); |
| 112 | sampleLocations->push_back().set(.0625, .4375); |
| 113 | sampleLocations->push_back().set(.6875, .4375); |
| 114 | sampleLocations->push_back().set(.4375, .0625); |
| 115 | break; |
| 116 | default: |
| 117 | sampleLocations->push_back().set(.5625, .5625); |
| 118 | sampleLocations->push_back().set(.4375, .3125); |
| 119 | sampleLocations->push_back().set(.3125, .6250); |
| 120 | sampleLocations->push_back().set(.2500, .4375); |
| 121 | sampleLocations->push_back().set(.1875, .3750); |
| 122 | sampleLocations->push_back().set(.6250, .8125); |
| 123 | sampleLocations->push_back().set(.8125, .6875); |
| 124 | sampleLocations->push_back().set(.6875, .1875); |
| 125 | sampleLocations->push_back().set(.3750, .8750); |
| 126 | sampleLocations->push_back().set(.5000, .0625); |
| 127 | sampleLocations->push_back().set(.2500, .1250); |
| 128 | sampleLocations->push_back().set(.1250, .2500); |
| 129 | sampleLocations->push_back().set(.0000, .5000); |
| 130 | sampleLocations->push_back().set(.4375, .2500); |
| 131 | sampleLocations->push_back().set(.8750, .4375); |
| 132 | sampleLocations->push_back().set(.0625, .0000); |
| 133 | break; |
| 134 | } |
| 135 | numRemainingSamples = rt->numSamples() - sampleLocations->count(); |
| 136 | } |
| 137 | } |
| 138 | |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 139 | sk_sp<GrTexture> GrMockGpu::onCreateTexture(SkISize dimensions, |
Brian Salomon | 81536f2 | 2019-08-08 16:30:49 -0400 | [diff] [blame] | 140 | const GrBackendFormat& format, |
| 141 | GrRenderable renderable, |
| 142 | int renderTargetSampleCnt, |
| 143 | SkBudgeted budgeted, |
| 144 | GrProtected isProtected, |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame] | 145 | int mipLevelCount, |
| 146 | uint32_t levelClearMask) { |
Chris Dalton | 91ab155 | 2018-04-18 13:24:25 -0600 | [diff] [blame] | 147 | if (fMockOptions.fFailTextureAllocations) { |
| 148 | return nullptr; |
| 149 | } |
| 150 | |
Robert Phillips | a27d625 | 2019-12-10 14:48:36 -0500 | [diff] [blame] | 151 | // Compressed formats should go through onCreateCompressedTexture |
| 152 | SkASSERT(format.asMockCompressionType() == SkImage::CompressionType::kNone); |
| 153 | |
Brian Salomon | 81536f2 | 2019-08-08 16:30:49 -0400 | [diff] [blame] | 154 | GrColorType ct = format.asMockColorType(); |
| 155 | SkASSERT(ct != GrColorType::kUnknown); |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 156 | |
Brian Salomon | a6db510 | 2020-07-21 09:56:23 -0400 | [diff] [blame] | 157 | GrMipmapStatus mipmapStatus = |
| 158 | mipLevelCount > 1 ? GrMipmapStatus::kDirty : GrMipmapStatus::kNotAllocated; |
Robert Phillips | a27d625 | 2019-12-10 14:48:36 -0500 | [diff] [blame] | 159 | GrMockTextureInfo texInfo(ct, SkImage::CompressionType::kNone, NextInternalTextureID()); |
Brian Salomon | f2c2ba9 | 2019-07-17 09:59:59 -0400 | [diff] [blame] | 160 | if (renderable == GrRenderable::kYes) { |
Greg Daniel | e877dce | 2019-07-11 10:52:43 -0400 | [diff] [blame] | 161 | GrMockRenderTargetInfo rtInfo(ct, NextInternalRenderTargetID()); |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 162 | return sk_sp<GrTexture>(new GrMockTextureRenderTarget(this, budgeted, dimensions, |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 163 | renderTargetSampleCnt, isProtected, |
Brian Salomon | a6db510 | 2020-07-21 09:56:23 -0400 | [diff] [blame] | 164 | mipmapStatus, texInfo, rtInfo)); |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 165 | } |
Brian Salomon | e8a766b | 2019-07-19 14:24:36 -0400 | [diff] [blame] | 166 | return sk_sp<GrTexture>( |
Brian Salomon | a6db510 | 2020-07-21 09:56:23 -0400 | [diff] [blame] | 167 | new GrMockTexture(this, budgeted, dimensions, isProtected, mipmapStatus, texInfo)); |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 168 | } |
| 169 | |
Robert Phillips | a27d625 | 2019-12-10 14:48:36 -0500 | [diff] [blame] | 170 | // TODO: why no 'isProtected' ?! |
Robert Phillips | 9f744f7 | 2019-12-19 19:14:33 -0500 | [diff] [blame] | 171 | sk_sp<GrTexture> GrMockGpu::onCreateCompressedTexture(SkISize dimensions, |
Robert Phillips | a27d625 | 2019-12-10 14:48:36 -0500 | [diff] [blame] | 172 | const GrBackendFormat& format, |
Robert Phillips | 3a83392 | 2020-01-21 15:25:58 -0500 | [diff] [blame] | 173 | SkBudgeted budgeted, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 174 | GrMipmapped mipMapped, |
Robert Phillips | 3a83392 | 2020-01-21 15:25:58 -0500 | [diff] [blame] | 175 | GrProtected isProtected, |
Robert Phillips | 9f744f7 | 2019-12-19 19:14:33 -0500 | [diff] [blame] | 176 | const void* data, size_t dataSize) { |
Robert Phillips | a27d625 | 2019-12-10 14:48:36 -0500 | [diff] [blame] | 177 | if (fMockOptions.fFailTextureAllocations) { |
| 178 | return nullptr; |
| 179 | } |
| 180 | |
Greg Daniel | b58a3c7 | 2020-01-23 10:05:14 -0500 | [diff] [blame] | 181 | #ifdef SK_DEBUG |
Robert Phillips | a27d625 | 2019-12-10 14:48:36 -0500 | [diff] [blame] | 182 | // Uncompressed formats should go through onCreateTexture |
| 183 | SkImage::CompressionType compression = format.asMockCompressionType(); |
| 184 | SkASSERT(compression != SkImage::CompressionType::kNone); |
Greg Daniel | b58a3c7 | 2020-01-23 10:05:14 -0500 | [diff] [blame] | 185 | #endif |
Robert Phillips | a27d625 | 2019-12-10 14:48:36 -0500 | [diff] [blame] | 186 | |
Brian Salomon | a6db510 | 2020-07-21 09:56:23 -0400 | [diff] [blame] | 187 | GrMipmapStatus mipmapStatus = (mipMapped == GrMipmapped::kYes) |
| 188 | ? GrMipmapStatus::kValid |
| 189 | : GrMipmapStatus::kNotAllocated; |
Robert Phillips | a27d625 | 2019-12-10 14:48:36 -0500 | [diff] [blame] | 190 | GrMockTextureInfo texInfo(GrColorType::kUnknown, |
| 191 | format.asMockCompressionType(), |
| 192 | NextInternalTextureID()); |
| 193 | |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 194 | return sk_sp<GrTexture>( |
Brian Salomon | a6db510 | 2020-07-21 09:56:23 -0400 | [diff] [blame] | 195 | new GrMockTexture(this, budgeted, dimensions, isProtected, mipmapStatus, texInfo)); |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 196 | } |
| 197 | |
Brian Salomon | 8a78e9c | 2020-03-27 10:42:15 -0400 | [diff] [blame] | 198 | sk_sp<GrTexture> GrMockGpu::onWrapBackendTexture(const GrBackendTexture& tex, |
Brian Salomon | fa2ebea | 2019-01-24 15:58:58 -0500 | [diff] [blame] | 199 | GrWrapOwnership ownership, |
Brian Salomon | 8a78e9c | 2020-03-27 10:42:15 -0400 | [diff] [blame] | 200 | GrWrapCacheable wrapType, |
| 201 | GrIOType ioType) { |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 202 | GrMockTextureInfo texInfo; |
| 203 | SkAssertResult(tex.getMockTextureInfo(&texInfo)); |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 204 | |
Robert Phillips | a27d625 | 2019-12-10 14:48:36 -0500 | [diff] [blame] | 205 | SkImage::CompressionType compression = texInfo.compressionType(); |
Robert Phillips | b915c94 | 2019-12-17 14:44:37 -0500 | [diff] [blame] | 206 | if (compression != SkImage::CompressionType::kNone) { |
| 207 | return nullptr; |
Robert Phillips | a27d625 | 2019-12-10 14:48:36 -0500 | [diff] [blame] | 208 | } |
| 209 | |
Brian Salomon | 40a4062 | 2020-07-21 10:32:07 -0400 | [diff] [blame] | 210 | GrMipmapStatus mipmapStatus = tex.hasMipmaps() ? GrMipmapStatus::kValid |
Brian Salomon | a6db510 | 2020-07-21 09:56:23 -0400 | [diff] [blame] | 211 | : GrMipmapStatus::kNotAllocated; |
Brian Salomon | e8a766b | 2019-07-19 14:24:36 -0400 | [diff] [blame] | 212 | auto isProtected = GrProtected(tex.isProtected()); |
Brian Salomon | a6db510 | 2020-07-21 09:56:23 -0400 | [diff] [blame] | 213 | return sk_sp<GrTexture>(new GrMockTexture(this, tex.dimensions(), isProtected, mipmapStatus, |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 214 | texInfo, wrapType, ioType)); |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 215 | } |
| 216 | |
Robert Phillips | b915c94 | 2019-12-17 14:44:37 -0500 | [diff] [blame] | 217 | sk_sp<GrTexture> GrMockGpu::onWrapCompressedBackendTexture(const GrBackendTexture& tex, |
| 218 | GrWrapOwnership ownership, |
| 219 | GrWrapCacheable wrapType) { |
| 220 | return nullptr; |
| 221 | } |
| 222 | |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 223 | sk_sp<GrTexture> GrMockGpu::onWrapRenderableBackendTexture(const GrBackendTexture& tex, |
| 224 | int sampleCnt, |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 225 | GrWrapOwnership ownership, |
| 226 | GrWrapCacheable cacheable) { |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 227 | GrMockTextureInfo texInfo; |
| 228 | SkAssertResult(tex.getMockTextureInfo(&texInfo)); |
Robert Phillips | a27d625 | 2019-12-10 14:48:36 -0500 | [diff] [blame] | 229 | SkASSERT(texInfo.compressionType() == SkImage::CompressionType::kNone); |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 230 | |
Brian Salomon | a6db510 | 2020-07-21 09:56:23 -0400 | [diff] [blame] | 231 | GrMipmapStatus mipmapStatus = |
Brian Salomon | 40a4062 | 2020-07-21 10:32:07 -0400 | [diff] [blame] | 232 | tex.hasMipmaps() ? GrMipmapStatus::kValid : GrMipmapStatus::kNotAllocated; |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 233 | |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 234 | // The client gave us the texture ID but we supply the render target ID. |
Robert Phillips | a27d625 | 2019-12-10 14:48:36 -0500 | [diff] [blame] | 235 | GrMockRenderTargetInfo rtInfo(texInfo.colorType(), NextInternalRenderTargetID()); |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 236 | |
Brian Salomon | e8a766b | 2019-07-19 14:24:36 -0400 | [diff] [blame] | 237 | auto isProtected = GrProtected(tex.isProtected()); |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 238 | return sk_sp<GrTexture>(new GrMockTextureRenderTarget(this, tex.dimensions(), sampleCnt, |
Brian Salomon | a6db510 | 2020-07-21 09:56:23 -0400 | [diff] [blame] | 239 | isProtected, mipmapStatus, texInfo, |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 240 | rtInfo, cacheable)); |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 241 | } |
| 242 | |
Brian Salomon | 8a78e9c | 2020-03-27 10:42:15 -0400 | [diff] [blame] | 243 | sk_sp<GrRenderTarget> GrMockGpu::onWrapBackendRenderTarget(const GrBackendRenderTarget& rt) { |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 244 | GrMockRenderTargetInfo info; |
| 245 | SkAssertResult(rt.getMockRenderTargetInfo(&info)); |
| 246 | |
Brian Salomon | e8a766b | 2019-07-19 14:24:36 -0400 | [diff] [blame] | 247 | auto isProtected = GrProtected(rt.isProtected()); |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 248 | return sk_sp<GrRenderTarget>(new GrMockRenderTarget(this, GrMockRenderTarget::kWrapped, |
| 249 | rt.dimensions(), rt.sampleCnt(), |
| 250 | isProtected, info)); |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 251 | } |
| 252 | |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 253 | sk_sp<GrGpuBuffer> GrMockGpu::onCreateBuffer(size_t sizeInBytes, GrGpuBufferType type, |
| 254 | GrAccessPattern accessPattern, const void*) { |
| 255 | return sk_sp<GrGpuBuffer>(new GrMockBuffer(this, sizeInBytes, type, accessPattern)); |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 256 | } |
| 257 | |
Greg Daniel | c0d6915 | 2020-10-08 14:59:00 -0400 | [diff] [blame] | 258 | sk_sp<GrAttachment> GrMockGpu::makeStencilAttachmentForRenderTarget(const GrRenderTarget* rt, |
| 259 | SkISize dimensions, |
| 260 | int numStencilSamples) { |
Chris Dalton | effee20 | 2019-07-01 22:28:03 -0600 | [diff] [blame] | 261 | SkASSERT(numStencilSamples == rt->numSamples()); |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 262 | fStats.incStencilAttachmentCreates(); |
Greg Daniel | c0d6915 | 2020-10-08 14:59:00 -0400 | [diff] [blame] | 263 | return sk_sp<GrAttachment>( |
Greg Daniel | 25ebd95 | 2020-11-03 11:17:05 -0500 | [diff] [blame] | 264 | new GrMockAttachment(this, dimensions, GrAttachment::UsageFlags::kStencilAttachment, |
Greg Daniel | c0d6915 | 2020-10-08 14:59:00 -0400 | [diff] [blame] | 265 | rt->numSamples())); |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 266 | } |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 267 | |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 268 | GrBackendTexture GrMockGpu::onCreateBackendTexture(SkISize dimensions, |
Robert Phillips | 57ef680 | 2019-09-23 10:12:47 -0400 | [diff] [blame] | 269 | const GrBackendFormat& format, |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 270 | GrRenderable, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 271 | GrMipmapped mipMapped, |
Greg Daniel | 16032b3 | 2020-05-06 15:31:10 -0400 | [diff] [blame] | 272 | GrProtected) { |
Robert Phillips | a27d625 | 2019-12-10 14:48:36 -0500 | [diff] [blame] | 273 | SkImage::CompressionType compression = format.asMockCompressionType(); |
| 274 | if (compression != SkImage::CompressionType::kNone) { |
| 275 | return {}; // should go through onCreateCompressedBackendTexture |
| 276 | } |
| 277 | |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 278 | auto colorType = format.asMockColorType(); |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 279 | if (!this->caps()->isFormatTexturable(format)) { |
Robert Phillips | 9dbcdcc | 2019-05-13 10:40:06 -0400 | [diff] [blame] | 280 | return GrBackendTexture(); // invalid |
| 281 | } |
| 282 | |
Robert Phillips | a27d625 | 2019-12-10 14:48:36 -0500 | [diff] [blame] | 283 | GrMockTextureInfo info(colorType, SkImage::CompressionType::kNone, NextExternalTextureID()); |
Robert Phillips | 646f637 | 2018-09-25 09:31:10 -0400 | [diff] [blame] | 284 | |
Robert Phillips | a27d625 | 2019-12-10 14:48:36 -0500 | [diff] [blame] | 285 | fOutstandingTestingOnlyTextureIDs.add(info.id()); |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 286 | return GrBackendTexture(dimensions.width(), dimensions.height(), mipMapped, info); |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 287 | } |
| 288 | |
Greg Daniel | c1ad77c | 2020-05-06 11:40:03 -0400 | [diff] [blame] | 289 | GrBackendTexture GrMockGpu::onCreateCompressedBackendTexture( |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 290 | SkISize dimensions, const GrBackendFormat& format, GrMipmapped mipMapped, |
Greg Daniel | aaf738c | 2020-07-10 09:30:33 -0400 | [diff] [blame] | 291 | GrProtected) { |
Robert Phillips | b915c94 | 2019-12-17 14:44:37 -0500 | [diff] [blame] | 292 | SkImage::CompressionType compression = format.asMockCompressionType(); |
| 293 | if (compression == SkImage::CompressionType::kNone) { |
| 294 | return {}; // should go through onCreateBackendTexture |
| 295 | } |
| 296 | |
| 297 | if (!this->caps()->isFormatTexturable(format)) { |
| 298 | return {}; |
| 299 | } |
| 300 | |
| 301 | GrMockTextureInfo info(GrColorType::kUnknown, compression, NextExternalTextureID()); |
| 302 | |
| 303 | fOutstandingTestingOnlyTextureIDs.add(info.id()); |
| 304 | return GrBackendTexture(dimensions.width(), dimensions.height(), mipMapped, info); |
| 305 | } |
| 306 | |
Robert Phillips | f0313ee | 2019-05-21 13:51:11 -0400 | [diff] [blame] | 307 | void GrMockGpu::deleteBackendTexture(const GrBackendTexture& tex) { |
Robert Phillips | f0ced62 | 2019-05-16 09:06:25 -0400 | [diff] [blame] | 308 | SkASSERT(GrBackendApi::kMock == tex.backend()); |
| 309 | |
| 310 | GrMockTextureInfo info; |
| 311 | if (tex.getMockTextureInfo(&info)) { |
Robert Phillips | a27d625 | 2019-12-10 14:48:36 -0500 | [diff] [blame] | 312 | fOutstandingTestingOnlyTextureIDs.remove(info.id()); |
Robert Phillips | f0ced62 | 2019-05-16 09:06:25 -0400 | [diff] [blame] | 313 | } |
| 314 | } |
| 315 | |
| 316 | #if GR_TEST_UTILS |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 317 | bool GrMockGpu::isTestingOnlyBackendTexture(const GrBackendTexture& tex) const { |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 318 | SkASSERT(GrBackendApi::kMock == tex.backend()); |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 319 | |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 320 | GrMockTextureInfo info; |
| 321 | if (!tex.getMockTextureInfo(&info)) { |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 322 | return false; |
| 323 | } |
| 324 | |
Robert Phillips | a27d625 | 2019-12-10 14:48:36 -0500 | [diff] [blame] | 325 | return fOutstandingTestingOnlyTextureIDs.contains(info.id()); |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 326 | } |
| 327 | |
Brian Salomon | 72c7b98 | 2020-10-06 10:07:38 -0400 | [diff] [blame] | 328 | GrBackendRenderTarget GrMockGpu::createTestingOnlyBackendRenderTarget(SkISize dimensions, |
| 329 | GrColorType colorType, |
Brian Salomon | f9b0042 | 2020-10-08 16:00:14 -0400 | [diff] [blame] | 330 | int sampleCnt, |
| 331 | GrProtected) { |
Greg Daniel | e877dce | 2019-07-11 10:52:43 -0400 | [diff] [blame] | 332 | GrMockRenderTargetInfo info(colorType, NextExternalRenderTargetID()); |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 333 | static constexpr int kStencilBits = 8; |
Brian Salomon | 72c7b98 | 2020-10-06 10:07:38 -0400 | [diff] [blame] | 334 | return GrBackendRenderTarget(dimensions.width(), dimensions.height(), sampleCnt, kStencilBits, |
| 335 | info); |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | void GrMockGpu::deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget&) {} |
| 339 | #endif |