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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "src/gpu/mock/GrMockBuffer.h" |
| 9 | #include "src/gpu/mock/GrMockCaps.h" |
| 10 | #include "src/gpu/mock/GrMockGpu.h" |
| 11 | #include "src/gpu/mock/GrMockGpuCommandBuffer.h" |
| 12 | #include "src/gpu/mock/GrMockStencilAttachment.h" |
| 13 | #include "src/gpu/mock/GrMockTexture.h" |
Mike Klein | de2244c | 2018-12-04 11:16:08 -0500 | [diff] [blame] | 14 | #include <atomic> |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 15 | |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 16 | int GrMockGpu::NextInternalTextureID() { |
Mike Klein | de2244c | 2018-12-04 11:16:08 -0500 | [diff] [blame] | 17 | static std::atomic<int> nextID{1}; |
Chris Dalton | 351e80c | 2019-01-06 22:51:00 -0700 | [diff] [blame] | 18 | int id; |
| 19 | do { |
| 20 | id = nextID.fetch_add(1); |
| 21 | } while (0 == id); // Reserve 0 for an invalid ID. |
| 22 | return id; |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | int GrMockGpu::NextExternalTextureID() { |
| 26 | // We use negative ints for the "testing only external textures" so they can easily be |
| 27 | // identified when debugging. |
Mike Klein | de2244c | 2018-12-04 11:16:08 -0500 | [diff] [blame] | 28 | static std::atomic<int> nextID{-1}; |
| 29 | return nextID--; |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 30 | } |
| 31 | |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 32 | int GrMockGpu::NextInternalRenderTargetID() { |
Mike Klein | de2244c | 2018-12-04 11:16:08 -0500 | [diff] [blame] | 33 | // 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] | 34 | // technically in a different space. |
Mike Klein | de2244c | 2018-12-04 11:16:08 -0500 | [diff] [blame] | 35 | static std::atomic<int> nextID{SK_MaxS32}; |
| 36 | return nextID--; |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | int GrMockGpu::NextExternalRenderTargetID() { |
| 40 | // We use large negative ints for the "testing only external render targets" so they can easily |
| 41 | // be identified when debugging. |
Mike Klein | de2244c | 2018-12-04 11:16:08 -0500 | [diff] [blame] | 42 | static std::atomic<int> nextID{SK_MinS32}; |
| 43 | return nextID++; |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 44 | } |
| 45 | |
Brian Salomon | 384fab4 | 2017-12-07 12:33:05 -0500 | [diff] [blame] | 46 | sk_sp<GrGpu> GrMockGpu::Make(const GrMockOptions* mockOptions, |
| 47 | const GrContextOptions& contextOptions, GrContext* context) { |
Greg Daniel | 02611d9 | 2017-07-25 10:05:01 -0400 | [diff] [blame] | 48 | static const GrMockOptions kDefaultOptions = GrMockOptions(); |
| 49 | if (!mockOptions) { |
| 50 | mockOptions = &kDefaultOptions; |
| 51 | } |
Brian Salomon | 384fab4 | 2017-12-07 12:33:05 -0500 | [diff] [blame] | 52 | return sk_sp<GrGpu>(new GrMockGpu(context, *mockOptions, contextOptions)); |
Greg Daniel | 02611d9 | 2017-07-25 10:05:01 -0400 | [diff] [blame] | 53 | } |
| 54 | |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 55 | GrGpuRTCommandBuffer* GrMockGpu::getCommandBuffer( |
Ethan Nicholas | 56d19a5 | 2018-10-15 11:26:20 -0400 | [diff] [blame] | 56 | GrRenderTarget* rt, GrSurfaceOrigin origin, const SkRect& bounds, |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 57 | const GrGpuRTCommandBuffer::LoadAndStoreInfo&, |
| 58 | const GrGpuRTCommandBuffer::StencilLoadAndStoreInfo&) { |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 59 | return new GrMockGpuRTCommandBuffer(this, rt, origin); |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 60 | } |
| 61 | |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 62 | GrGpuTextureCommandBuffer* GrMockGpu::getCommandBuffer(GrTexture* texture, GrSurfaceOrigin origin) { |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 63 | return new GrMockGpuTextureCommandBuffer(texture, origin); |
| 64 | } |
| 65 | |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 66 | void GrMockGpu::submit(GrGpuCommandBuffer* buffer) { |
| 67 | if (buffer->asRTCommandBuffer()) { |
| 68 | this->submitCommandBuffer( |
| 69 | static_cast<GrMockGpuRTCommandBuffer*>(buffer->asRTCommandBuffer())); |
| 70 | } |
| 71 | |
| 72 | delete buffer; |
| 73 | } |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 74 | |
| 75 | void GrMockGpu::submitCommandBuffer(const GrMockGpuRTCommandBuffer* cmdBuffer) { |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 76 | for (int i = 0; i < cmdBuffer->numDraws(); ++i) { |
| 77 | fStats.incNumDraws(); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | GrMockGpu::GrMockGpu(GrContext* context, const GrMockOptions& options, |
| 82 | const GrContextOptions& contextOptions) |
Chris Dalton | 91ab155 | 2018-04-18 13:24:25 -0600 | [diff] [blame] | 83 | : INHERITED(context) |
| 84 | , fMockOptions(options) { |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 85 | fCaps.reset(new GrMockCaps(contextOptions, options)); |
| 86 | } |
| 87 | |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 88 | void GrMockGpu::querySampleLocations(GrRenderTarget* rt, SkTArray<SkPoint>* sampleLocations) { |
| 89 | sampleLocations->reset(); |
| 90 | int numRemainingSamples = rt->numSamples(); |
| 91 | while (numRemainingSamples > 0) { |
| 92 | // Use standard D3D sample locations. |
| 93 | switch (numRemainingSamples) { |
| 94 | case 0: |
| 95 | case 1: |
| 96 | sampleLocations->push_back().set(.5, .5); |
| 97 | break; |
| 98 | case 2: |
| 99 | sampleLocations->push_back().set(.75, .75); |
| 100 | sampleLocations->push_back().set(.25, .25); |
| 101 | break; |
| 102 | case 3: |
| 103 | case 4: |
| 104 | sampleLocations->push_back().set(.375, .125); |
| 105 | sampleLocations->push_back().set(.875, .375); |
| 106 | sampleLocations->push_back().set(.125, .625); |
| 107 | sampleLocations->push_back().set(.625, .875); |
| 108 | break; |
| 109 | case 5: |
| 110 | case 6: |
| 111 | case 7: |
| 112 | case 8: |
| 113 | sampleLocations->push_back().set(.5625, .3125); |
| 114 | sampleLocations->push_back().set(.4375, .6875); |
| 115 | sampleLocations->push_back().set(.8125, .5625); |
| 116 | sampleLocations->push_back().set(.3125, .1875); |
| 117 | sampleLocations->push_back().set(.1875, .8125); |
| 118 | sampleLocations->push_back().set(.0625, .4375); |
| 119 | sampleLocations->push_back().set(.6875, .4375); |
| 120 | sampleLocations->push_back().set(.4375, .0625); |
| 121 | break; |
| 122 | default: |
| 123 | sampleLocations->push_back().set(.5625, .5625); |
| 124 | sampleLocations->push_back().set(.4375, .3125); |
| 125 | sampleLocations->push_back().set(.3125, .6250); |
| 126 | sampleLocations->push_back().set(.2500, .4375); |
| 127 | sampleLocations->push_back().set(.1875, .3750); |
| 128 | sampleLocations->push_back().set(.6250, .8125); |
| 129 | sampleLocations->push_back().set(.8125, .6875); |
| 130 | sampleLocations->push_back().set(.6875, .1875); |
| 131 | sampleLocations->push_back().set(.3750, .8750); |
| 132 | sampleLocations->push_back().set(.5000, .0625); |
| 133 | sampleLocations->push_back().set(.2500, .1250); |
| 134 | sampleLocations->push_back().set(.1250, .2500); |
| 135 | sampleLocations->push_back().set(.0000, .5000); |
| 136 | sampleLocations->push_back().set(.4375, .2500); |
| 137 | sampleLocations->push_back().set(.8750, .4375); |
| 138 | sampleLocations->push_back().set(.0625, .0000); |
| 139 | break; |
| 140 | } |
| 141 | numRemainingSamples = rt->numSamples() - sampleLocations->count(); |
| 142 | } |
| 143 | } |
| 144 | |
Brian Salomon | f2c2ba9 | 2019-07-17 09:59:59 -0400 | [diff] [blame] | 145 | sk_sp<GrTexture> GrMockGpu::onCreateTexture(const GrSurfaceDesc& desc, GrRenderable renderable, |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 146 | int renderTargetSampleCnt, SkBudgeted budgeted, |
| 147 | GrProtected isProtected, const GrMipLevel texels[], |
| 148 | int mipLevelCount) { |
Chris Dalton | 91ab155 | 2018-04-18 13:24:25 -0600 | [diff] [blame] | 149 | if (fMockOptions.fFailTextureAllocations) { |
| 150 | return nullptr; |
| 151 | } |
| 152 | |
Greg Daniel | e877dce | 2019-07-11 10:52:43 -0400 | [diff] [blame] | 153 | GrColorType ct = GrPixelConfigToColorType(desc.fConfig); |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 154 | if (GrColorType::kUnknown == ct) { |
| 155 | return nullptr; |
| 156 | } |
| 157 | |
Greg Daniel | 0fc4d2d | 2017-10-12 11:23:36 -0400 | [diff] [blame] | 158 | GrMipMapsStatus mipMapsStatus = mipLevelCount > 1 ? GrMipMapsStatus::kValid |
| 159 | : GrMipMapsStatus::kNotAllocated; |
Greg Daniel | e877dce | 2019-07-11 10:52:43 -0400 | [diff] [blame] | 160 | GrMockTextureInfo texInfo(ct, NextInternalTextureID()); |
Brian Salomon | f2c2ba9 | 2019-07-17 09:59:59 -0400 | [diff] [blame] | 161 | if (renderable == GrRenderable::kYes) { |
Greg Daniel | e877dce | 2019-07-11 10:52:43 -0400 | [diff] [blame] | 162 | GrMockRenderTargetInfo rtInfo(ct, NextInternalRenderTargetID()); |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 163 | return sk_sp<GrTexture>(new GrMockTextureRenderTarget(this, budgeted, desc, |
| 164 | renderTargetSampleCnt, isProtected, |
Brian Salomon | e8a766b | 2019-07-19 14:24:36 -0400 | [diff] [blame] | 165 | mipMapsStatus, texInfo, rtInfo)); |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 166 | } |
Brian Salomon | e8a766b | 2019-07-19 14:24:36 -0400 | [diff] [blame] | 167 | return sk_sp<GrTexture>( |
| 168 | new GrMockTexture(this, budgeted, desc, isProtected, mipMapsStatus, texInfo)); |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 169 | } |
| 170 | |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 171 | sk_sp<GrTexture> GrMockGpu::onCreateCompressedTexture(int width, int height, |
| 172 | SkImage::CompressionType compressionType, |
| 173 | SkBudgeted budgeted, const void* data) { |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 174 | return nullptr; |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 175 | } |
| 176 | |
Robert Phillips | dd39980 | 2019-07-18 12:28:00 +0000 | [diff] [blame] | 177 | sk_sp<GrTexture> GrMockGpu::onWrapBackendTexture(const GrBackendTexture& tex, |
Brian Salomon | fa2ebea | 2019-01-24 15:58:58 -0500 | [diff] [blame] | 178 | GrWrapOwnership ownership, |
| 179 | GrWrapCacheable wrapType, GrIOType ioType) { |
Robert Phillips | dd39980 | 2019-07-18 12:28:00 +0000 | [diff] [blame] | 180 | GrMockTextureInfo info; |
| 181 | SkAssertResult(tex.getMockTextureInfo(&info)); |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 182 | |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 183 | GrSurfaceDesc desc; |
| 184 | desc.fWidth = tex.width(); |
| 185 | desc.fHeight = tex.height(); |
Robert Phillips | dd39980 | 2019-07-18 12:28:00 +0000 | [diff] [blame] | 186 | desc.fConfig = info.pixelConfig(); |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 187 | |
| 188 | GrMipMapsStatus mipMapsStatus = tex.hasMipMaps() ? GrMipMapsStatus::kValid |
| 189 | : GrMipMapsStatus::kNotAllocated; |
Brian Salomon | e8a766b | 2019-07-19 14:24:36 -0400 | [diff] [blame] | 190 | auto isProtected = GrProtected(tex.isProtected()); |
| 191 | return sk_sp<GrTexture>( |
| 192 | new GrMockTexture(this, desc, isProtected, mipMapsStatus, info, wrapType, ioType)); |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 193 | } |
| 194 | |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 195 | sk_sp<GrTexture> GrMockGpu::onWrapRenderableBackendTexture(const GrBackendTexture& tex, |
| 196 | int sampleCnt, |
Robert Phillips | 0902c98 | 2019-07-16 07:47:56 -0400 | [diff] [blame] | 197 | GrColorType colorType, |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 198 | GrWrapOwnership ownership, |
| 199 | GrWrapCacheable cacheable) { |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 200 | GrMockTextureInfo texInfo; |
| 201 | SkAssertResult(tex.getMockTextureInfo(&texInfo)); |
| 202 | |
Robert Phillips | 0902c98 | 2019-07-16 07:47:56 -0400 | [diff] [blame] | 203 | SkASSERT(colorType == texInfo.fColorType); |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 204 | GrSurfaceDesc desc; |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 205 | desc.fWidth = tex.width(); |
| 206 | desc.fHeight = tex.height(); |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 207 | desc.fConfig = texInfo.pixelConfig(); |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 208 | |
| 209 | GrMipMapsStatus mipMapsStatus = |
| 210 | tex.hasMipMaps() ? GrMipMapsStatus::kValid : GrMipMapsStatus::kNotAllocated; |
| 211 | |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 212 | // The client gave us the texture ID but we supply the render target ID. |
Greg Daniel | e877dce | 2019-07-11 10:52:43 -0400 | [diff] [blame] | 213 | GrMockRenderTargetInfo rtInfo(texInfo.fColorType, NextInternalRenderTargetID()); |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 214 | |
Brian Salomon | e8a766b | 2019-07-19 14:24:36 -0400 | [diff] [blame] | 215 | auto isProtected = GrProtected(tex.isProtected()); |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 216 | return sk_sp<GrTexture>(new GrMockTextureRenderTarget( |
| 217 | this, desc, sampleCnt, isProtected, mipMapsStatus, texInfo, rtInfo, cacheable)); |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 218 | } |
| 219 | |
Robert Phillips | dd39980 | 2019-07-18 12:28:00 +0000 | [diff] [blame] | 220 | sk_sp<GrRenderTarget> GrMockGpu::onWrapBackendRenderTarget(const GrBackendRenderTarget& rt) { |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 221 | GrMockRenderTargetInfo info; |
| 222 | SkAssertResult(rt.getMockRenderTargetInfo(&info)); |
| 223 | |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 224 | GrSurfaceDesc desc; |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 225 | desc.fWidth = rt.width(); |
| 226 | desc.fHeight = rt.height(); |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 227 | desc.fConfig = info.pixelConfig(); |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 228 | |
Brian Salomon | e8a766b | 2019-07-19 14:24:36 -0400 | [diff] [blame] | 229 | auto isProtected = GrProtected(rt.isProtected()); |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 230 | return sk_sp<GrRenderTarget>(new GrMockRenderTarget(this, GrMockRenderTarget::kWrapped, desc, |
| 231 | rt.sampleCnt(), isProtected, info)); |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | sk_sp<GrRenderTarget> GrMockGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTexture& tex, |
Robert Phillips | dd39980 | 2019-07-18 12:28:00 +0000 | [diff] [blame] | 235 | int sampleCnt) { |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 236 | GrMockTextureInfo texInfo; |
| 237 | SkAssertResult(tex.getMockTextureInfo(&texInfo)); |
| 238 | |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 239 | GrSurfaceDesc desc; |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 240 | desc.fWidth = tex.width(); |
| 241 | desc.fHeight = tex.height(); |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 242 | desc.fConfig = texInfo.pixelConfig(); |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 243 | |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 244 | // The client gave us the texture ID but we supply the render target ID. |
Greg Daniel | e877dce | 2019-07-11 10:52:43 -0400 | [diff] [blame] | 245 | GrMockRenderTargetInfo rtInfo(texInfo.fColorType, NextInternalRenderTargetID()); |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 246 | |
Brian Salomon | e8a766b | 2019-07-19 14:24:36 -0400 | [diff] [blame] | 247 | auto isProtected = GrProtected(tex.isProtected()); |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 248 | return sk_sp<GrRenderTarget>(new GrMockRenderTarget(this, GrMockRenderTarget::kWrapped, desc, |
| 249 | sampleCnt, isProtected, rtInfo)); |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 250 | } |
| 251 | |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 252 | sk_sp<GrGpuBuffer> GrMockGpu::onCreateBuffer(size_t sizeInBytes, GrGpuBufferType type, |
| 253 | GrAccessPattern accessPattern, const void*) { |
| 254 | return sk_sp<GrGpuBuffer>(new GrMockBuffer(this, sizeInBytes, type, accessPattern)); |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 255 | } |
| 256 | |
Chris Dalton | effee20 | 2019-07-01 22:28:03 -0600 | [diff] [blame] | 257 | GrStencilAttachment* GrMockGpu::createStencilAttachmentForRenderTarget( |
| 258 | const GrRenderTarget* rt, int width, int height, int numStencilSamples) { |
| 259 | SkASSERT(numStencilSamples == rt->numSamples()); |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 260 | static constexpr int kBits = 8; |
| 261 | fStats.incStencilAttachmentCreates(); |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 262 | return new GrMockStencilAttachment(this, width, height, kBits, rt->numSamples()); |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 263 | } |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 264 | |
Robert Phillips | f0313ee | 2019-05-21 13:51:11 -0400 | [diff] [blame] | 265 | GrBackendTexture GrMockGpu::createBackendTexture(int w, int h, |
| 266 | const GrBackendFormat& format, |
| 267 | GrMipMapped mipMapped, |
| 268 | GrRenderable /* renderable */, |
| 269 | const void* /* pixels */, |
Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 270 | size_t /* rowBytes */, |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 271 | const SkColor4f* /* color */, |
| 272 | GrProtected /* isProtected */) { |
Robert Phillips | 646f637 | 2018-09-25 09:31:10 -0400 | [diff] [blame] | 273 | |
Greg Daniel | e877dce | 2019-07-11 10:52:43 -0400 | [diff] [blame] | 274 | if (!format.getMockColorType()) { |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 275 | return GrBackendTexture(); // invalid; |
| 276 | } |
| 277 | |
Greg Daniel | e877dce | 2019-07-11 10:52:43 -0400 | [diff] [blame] | 278 | if (!this->caps()->isFormatTexturable(*format.getMockColorType(), format)) { |
Robert Phillips | 9dbcdcc | 2019-05-13 10:40:06 -0400 | [diff] [blame] | 279 | return GrBackendTexture(); // invalid |
| 280 | } |
| 281 | |
Greg Daniel | e877dce | 2019-07-11 10:52:43 -0400 | [diff] [blame] | 282 | GrMockTextureInfo info(*format.getMockColorType(), NextExternalTextureID()); |
Robert Phillips | 646f637 | 2018-09-25 09:31:10 -0400 | [diff] [blame] | 283 | |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 284 | fOutstandingTestingOnlyTextureIDs.add(info.fID); |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 285 | return GrBackendTexture(w, h, mipMapped, info); |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 286 | } |
| 287 | |
Robert Phillips | f0313ee | 2019-05-21 13:51:11 -0400 | [diff] [blame] | 288 | void GrMockGpu::deleteBackendTexture(const GrBackendTexture& tex) { |
Robert Phillips | f0ced62 | 2019-05-16 09:06:25 -0400 | [diff] [blame] | 289 | SkASSERT(GrBackendApi::kMock == tex.backend()); |
| 290 | |
| 291 | GrMockTextureInfo info; |
| 292 | if (tex.getMockTextureInfo(&info)) { |
| 293 | fOutstandingTestingOnlyTextureIDs.remove(info.fID); |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | #if GR_TEST_UTILS |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 298 | bool GrMockGpu::isTestingOnlyBackendTexture(const GrBackendTexture& tex) const { |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 299 | SkASSERT(GrBackendApi::kMock == tex.backend()); |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 300 | |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 301 | GrMockTextureInfo info; |
| 302 | if (!tex.getMockTextureInfo(&info)) { |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 303 | return false; |
| 304 | } |
| 305 | |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 306 | return fOutstandingTestingOnlyTextureIDs.contains(info.fID); |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 307 | } |
| 308 | |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 309 | GrBackendRenderTarget GrMockGpu::createTestingOnlyBackendRenderTarget(int w, int h, |
Brian Osman | 2d010b6 | 2018-08-09 10:55:09 -0400 | [diff] [blame] | 310 | GrColorType colorType) { |
Greg Daniel | e877dce | 2019-07-11 10:52:43 -0400 | [diff] [blame] | 311 | GrMockRenderTargetInfo info(colorType, NextExternalRenderTargetID()); |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 312 | static constexpr int kSampleCnt = 1; |
| 313 | static constexpr int kStencilBits = 8; |
Robert Phillips | a5e78be | 2019-07-09 12:34:38 -0400 | [diff] [blame] | 314 | return GrBackendRenderTarget(w, h, kSampleCnt, kStencilBits, info); |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | void GrMockGpu::deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget&) {} |
| 318 | #endif |