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