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