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