blob: df59f17e0689ccbfc98cad6598f13a3997188d85 [file] [log] [blame]
Brian Salomoncfe910d2017-07-06 16:40:18 -04001/*
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 Kleinc0bd9f92019-04-23 12:05:21 -05008#include "src/gpu/mock/GrMockBuffer.h"
9#include "src/gpu/mock/GrMockCaps.h"
10#include "src/gpu/mock/GrMockGpu.h"
Greg Daniel2d41d0d2019-08-26 11:08:51 -040011#include "src/gpu/mock/GrMockOpsRenderPass.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "src/gpu/mock/GrMockStencilAttachment.h"
13#include "src/gpu/mock/GrMockTexture.h"
Mike Kleinde2244c2018-12-04 11:16:08 -050014#include <atomic>
Brian Salomoncfe910d2017-07-06 16:40:18 -040015
Brian Salomon8fe24272017-07-07 12:56:11 -040016int GrMockGpu::NextInternalTextureID() {
Mike Kleinde2244c2018-12-04 11:16:08 -050017 static std::atomic<int> nextID{1};
Chris Dalton351e80c2019-01-06 22:51:00 -070018 int id;
19 do {
20 id = nextID.fetch_add(1);
21 } while (0 == id); // Reserve 0 for an invalid ID.
22 return id;
Brian Salomon8fe24272017-07-07 12:56:11 -040023}
24
25int GrMockGpu::NextExternalTextureID() {
26 // We use negative ints for the "testing only external textures" so they can easily be
27 // identified when debugging.
Mike Kleinde2244c2018-12-04 11:16:08 -050028 static std::atomic<int> nextID{-1};
29 return nextID--;
Brian Salomon8fe24272017-07-07 12:56:11 -040030}
31
Brian Salomon0c51eea2018-03-09 17:02:09 -050032int GrMockGpu::NextInternalRenderTargetID() {
Mike Kleinde2244c2018-12-04 11:16:08 -050033 // We start off with large numbers to differentiate from texture IDs, even though they're
Brian Salomon0c51eea2018-03-09 17:02:09 -050034 // technically in a different space.
Mike Kleinde2244c2018-12-04 11:16:08 -050035 static std::atomic<int> nextID{SK_MaxS32};
36 return nextID--;
Brian Salomon0c51eea2018-03-09 17:02:09 -050037}
38
39int 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 Kleinde2244c2018-12-04 11:16:08 -050042 static std::atomic<int> nextID{SK_MinS32};
43 return nextID++;
Brian Salomon0c51eea2018-03-09 17:02:09 -050044}
45
Brian Salomon384fab42017-12-07 12:33:05 -050046sk_sp<GrGpu> GrMockGpu::Make(const GrMockOptions* mockOptions,
47 const GrContextOptions& contextOptions, GrContext* context) {
Greg Daniel02611d92017-07-25 10:05:01 -040048 static const GrMockOptions kDefaultOptions = GrMockOptions();
49 if (!mockOptions) {
50 mockOptions = &kDefaultOptions;
51 }
Brian Salomon384fab42017-12-07 12:33:05 -050052 return sk_sp<GrGpu>(new GrMockGpu(context, *mockOptions, contextOptions));
Greg Daniel02611d92017-07-25 10:05:01 -040053}
54
Greg Daniel2d41d0d2019-08-26 11:08:51 -040055GrOpsRenderPass* GrMockGpu::getOpsRenderPass(
Greg Daniel4a0d36d2019-09-30 12:24:36 -040056 GrRenderTarget* rt, GrSurfaceOrigin origin, const SkIRect& bounds,
Greg Daniel2d41d0d2019-08-26 11:08:51 -040057 const GrOpsRenderPass::LoadAndStoreInfo& colorInfo,
Greg Danielb20d7e52019-09-03 13:54:39 -040058 const GrOpsRenderPass::StencilLoadAndStoreInfo&,
Michael Ludwigfcdd0612019-11-25 08:34:31 -050059 const SkTArray<GrSurfaceProxy*, true>& sampledProxies) {
Greg Daniel2d41d0d2019-08-26 11:08:51 -040060 return new GrMockOpsRenderPass(this, rt, origin, colorInfo);
Brian Salomoncfe910d2017-07-06 16:40:18 -040061}
62
Greg Daniel2d41d0d2019-08-26 11:08:51 -040063void GrMockGpu::submit(GrOpsRenderPass* renderPass) {
64 for (int i = 0; i < static_cast<GrMockOpsRenderPass*>(renderPass)->numDraws(); ++i) {
Brian Salomoncfe910d2017-07-06 16:40:18 -040065 fStats.incNumDraws();
66 }
Greg Daniel2d41d0d2019-08-26 11:08:51 -040067 delete renderPass;
Brian Salomoncfe910d2017-07-06 16:40:18 -040068}
69
70GrMockGpu::GrMockGpu(GrContext* context, const GrMockOptions& options,
71 const GrContextOptions& contextOptions)
Chris Dalton91ab1552018-04-18 13:24:25 -060072 : INHERITED(context)
73 , fMockOptions(options) {
Brian Salomoncfe910d2017-07-06 16:40:18 -040074 fCaps.reset(new GrMockCaps(contextOptions, options));
75}
76
Chris Daltonc3318f02019-07-19 14:20:53 -060077void 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 Salomon81536f22019-08-08 16:30:49 -0400134sk_sp<GrTexture> GrMockGpu::onCreateTexture(const GrSurfaceDesc& desc,
135 const GrBackendFormat& format,
136 GrRenderable renderable,
137 int renderTargetSampleCnt,
138 SkBudgeted budgeted,
139 GrProtected isProtected,
Brian Salomond2a8ae22019-09-10 16:03:59 -0400140 int mipLevelCount,
141 uint32_t levelClearMask) {
Chris Dalton91ab1552018-04-18 13:24:25 -0600142 if (fMockOptions.fFailTextureAllocations) {
143 return nullptr;
144 }
145
Robert Phillipsa27d6252019-12-10 14:48:36 -0500146 // Compressed formats should go through onCreateCompressedTexture
147 SkASSERT(format.asMockCompressionType() == SkImage::CompressionType::kNone);
148
Brian Salomon81536f22019-08-08 16:30:49 -0400149 GrColorType ct = format.asMockColorType();
150 SkASSERT(ct != GrColorType::kUnknown);
Robert Phillipsa5e78be2019-07-09 12:34:38 -0400151
Brian Salomond2a8ae22019-09-10 16:03:59 -0400152 GrMipMapsStatus mipMapsStatus =
153 mipLevelCount > 1 ? GrMipMapsStatus::kDirty : GrMipMapsStatus::kNotAllocated;
Robert Phillipsa27d6252019-12-10 14:48:36 -0500154 GrMockTextureInfo texInfo(ct, SkImage::CompressionType::kNone, NextInternalTextureID());
Brian Salomonf2c2ba92019-07-17 09:59:59 -0400155 if (renderable == GrRenderable::kYes) {
Greg Daniele877dce2019-07-11 10:52:43 -0400156 GrMockRenderTargetInfo rtInfo(ct, NextInternalRenderTargetID());
Brian Salomon27b4d8d2019-07-22 14:23:45 -0400157 return sk_sp<GrTexture>(new GrMockTextureRenderTarget(this, budgeted, desc,
158 renderTargetSampleCnt, isProtected,
Brian Salomone8a766b2019-07-19 14:24:36 -0400159 mipMapsStatus, texInfo, rtInfo));
Brian Salomoncfe910d2017-07-06 16:40:18 -0400160 }
Brian Salomone8a766b2019-07-19 14:24:36 -0400161 return sk_sp<GrTexture>(
162 new GrMockTexture(this, budgeted, desc, isProtected, mipMapsStatus, texInfo));
Brian Salomoncfe910d2017-07-06 16:40:18 -0400163}
164
Robert Phillipsa27d6252019-12-10 14:48:36 -0500165// TODO: why no 'isProtected' ?!
166sk_sp<GrTexture> GrMockGpu::onCreateCompressedTexture(int width, int height,
167 const GrBackendFormat& format,
Brian Salomonbb8dde82019-06-27 10:52:13 -0400168 SkImage::CompressionType compressionType,
Robert Phillipsa27d6252019-12-10 14:48:36 -0500169 SkBudgeted budgeted,
170 const void* data) {
171 if (fMockOptions.fFailTextureAllocations) {
172 return nullptr;
173 }
174
175 // Uncompressed formats should go through onCreateTexture
176 SkImage::CompressionType compression = format.asMockCompressionType();
177 SkASSERT(compression != SkImage::CompressionType::kNone);
178 SkASSERT(compression == compressionType);
179
180 GrSurfaceDesc desc;
181 desc.fWidth = width;
182 desc.fHeight = height;
183 desc.fConfig = GrCompressionTypeToPixelConfig(compression);
184
185 GrMipMapsStatus mipMapsStatus = GrMipMapsStatus::kNotAllocated;
186 GrMockTextureInfo texInfo(GrColorType::kUnknown,
187 format.asMockCompressionType(),
188 NextInternalTextureID());
189
190 return sk_sp<GrTexture>(new GrMockTexture(this, budgeted, desc, GrProtected::kNo,
191 mipMapsStatus, texInfo));
Brian Salomonbb8dde82019-06-27 10:52:13 -0400192}
193
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400194sk_sp<GrTexture> GrMockGpu::onWrapBackendTexture(const GrBackendTexture& tex, GrColorType colorType,
Brian Salomonfa2ebea2019-01-24 15:58:58 -0500195 GrWrapOwnership ownership,
196 GrWrapCacheable wrapType, GrIOType ioType) {
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400197 GrMockTextureInfo texInfo;
198 SkAssertResult(tex.getMockTextureInfo(&texInfo));
Robert Phillipsa5e78be2019-07-09 12:34:38 -0400199
Robert Phillipsa27d6252019-12-10 14:48:36 -0500200 SkImage::CompressionType compression = texInfo.compressionType();
Robert Phillipsb915c942019-12-17 14:44:37 -0500201 if (compression != SkImage::CompressionType::kNone) {
202 return nullptr;
Robert Phillipsa27d6252019-12-10 14:48:36 -0500203 }
204
Robert Phillipsb915c942019-12-17 14:44:37 -0500205 SkASSERT(colorType == texInfo.colorType());
206
Greg Daniel4684f822018-03-08 15:27:36 -0500207 GrSurfaceDesc desc;
208 desc.fWidth = tex.width();
209 desc.fHeight = tex.height();
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400210 desc.fConfig = texInfo.pixelConfig();
Greg Daniel4684f822018-03-08 15:27:36 -0500211
212 GrMipMapsStatus mipMapsStatus = tex.hasMipMaps() ? GrMipMapsStatus::kValid
213 : GrMipMapsStatus::kNotAllocated;
Brian Salomone8a766b2019-07-19 14:24:36 -0400214 auto isProtected = GrProtected(tex.isProtected());
215 return sk_sp<GrTexture>(
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400216 new GrMockTexture(this, desc, isProtected, mipMapsStatus, texInfo, wrapType, ioType));
Greg Daniel4684f822018-03-08 15:27:36 -0500217}
218
Robert Phillipsb915c942019-12-17 14:44:37 -0500219sk_sp<GrTexture> GrMockGpu::onWrapCompressedBackendTexture(const GrBackendTexture& tex,
220 GrWrapOwnership ownership,
221 GrWrapCacheable wrapType) {
222 return nullptr;
223}
224
Brian Salomon0c51eea2018-03-09 17:02:09 -0500225sk_sp<GrTexture> GrMockGpu::onWrapRenderableBackendTexture(const GrBackendTexture& tex,
226 int sampleCnt,
Robert Phillips0902c982019-07-16 07:47:56 -0400227 GrColorType colorType,
Brian Salomonaa6ca0a2019-01-24 16:03:07 -0500228 GrWrapOwnership ownership,
229 GrWrapCacheable cacheable) {
Robert Phillipsa5e78be2019-07-09 12:34:38 -0400230 GrMockTextureInfo texInfo;
231 SkAssertResult(tex.getMockTextureInfo(&texInfo));
Robert Phillipsa27d6252019-12-10 14:48:36 -0500232 SkASSERT(texInfo.compressionType() == SkImage::CompressionType::kNone);
Robert Phillipsa5e78be2019-07-09 12:34:38 -0400233
Robert Phillipsa27d6252019-12-10 14:48:36 -0500234 SkASSERT(colorType == texInfo.colorType());
Brian Salomon0c51eea2018-03-09 17:02:09 -0500235 GrSurfaceDesc desc;
Brian Salomon0c51eea2018-03-09 17:02:09 -0500236 desc.fWidth = tex.width();
237 desc.fHeight = tex.height();
Robert Phillipsa5e78be2019-07-09 12:34:38 -0400238 desc.fConfig = texInfo.pixelConfig();
Brian Salomon0c51eea2018-03-09 17:02:09 -0500239
240 GrMipMapsStatus mipMapsStatus =
241 tex.hasMipMaps() ? GrMipMapsStatus::kValid : GrMipMapsStatus::kNotAllocated;
242
Brian Salomon0c51eea2018-03-09 17:02:09 -0500243 // The client gave us the texture ID but we supply the render target ID.
Robert Phillipsa27d6252019-12-10 14:48:36 -0500244 GrMockRenderTargetInfo rtInfo(texInfo.colorType(), NextInternalRenderTargetID());
Brian Salomon0c51eea2018-03-09 17:02:09 -0500245
Brian Salomone8a766b2019-07-19 14:24:36 -0400246 auto isProtected = GrProtected(tex.isProtected());
Brian Salomon27b4d8d2019-07-22 14:23:45 -0400247 return sk_sp<GrTexture>(new GrMockTextureRenderTarget(
248 this, desc, sampleCnt, isProtected, mipMapsStatus, texInfo, rtInfo, cacheable));
Brian Salomon0c51eea2018-03-09 17:02:09 -0500249}
250
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400251sk_sp<GrRenderTarget> GrMockGpu::onWrapBackendRenderTarget(const GrBackendRenderTarget& rt,
252 GrColorType colorType) {
Robert Phillipsa5e78be2019-07-09 12:34:38 -0400253 GrMockRenderTargetInfo info;
254 SkAssertResult(rt.getMockRenderTargetInfo(&info));
255
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400256 SkASSERT(colorType == info.colorType());
Brian Salomon0c51eea2018-03-09 17:02:09 -0500257 GrSurfaceDesc desc;
Brian Salomon0c51eea2018-03-09 17:02:09 -0500258 desc.fWidth = rt.width();
259 desc.fHeight = rt.height();
Robert Phillipsa5e78be2019-07-09 12:34:38 -0400260 desc.fConfig = info.pixelConfig();
Brian Salomon0c51eea2018-03-09 17:02:09 -0500261
Brian Salomone8a766b2019-07-19 14:24:36 -0400262 auto isProtected = GrProtected(rt.isProtected());
Brian Salomon27b4d8d2019-07-22 14:23:45 -0400263 return sk_sp<GrRenderTarget>(new GrMockRenderTarget(this, GrMockRenderTarget::kWrapped, desc,
264 rt.sampleCnt(), isProtected, info));
Brian Salomon0c51eea2018-03-09 17:02:09 -0500265}
266
267sk_sp<GrRenderTarget> GrMockGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTexture& tex,
Robert Phillipsc80b0e92019-07-23 10:27:09 -0400268 int sampleCnt,
269 GrColorType colorType) {
Robert Phillipsa5e78be2019-07-09 12:34:38 -0400270 GrMockTextureInfo texInfo;
271 SkAssertResult(tex.getMockTextureInfo(&texInfo));
Robert Phillipsa27d6252019-12-10 14:48:36 -0500272 SkASSERT(texInfo.compressionType() == SkImage::CompressionType::kNone);
Robert Phillipsa5e78be2019-07-09 12:34:38 -0400273
Robert Phillipsa27d6252019-12-10 14:48:36 -0500274 SkASSERT(colorType == texInfo.colorType());
Brian Salomon0c51eea2018-03-09 17:02:09 -0500275 GrSurfaceDesc desc;
Brian Salomon0c51eea2018-03-09 17:02:09 -0500276 desc.fWidth = tex.width();
277 desc.fHeight = tex.height();
Robert Phillipsa5e78be2019-07-09 12:34:38 -0400278 desc.fConfig = texInfo.pixelConfig();
Brian Salomon0c51eea2018-03-09 17:02:09 -0500279
Brian Salomon0c51eea2018-03-09 17:02:09 -0500280 // The client gave us the texture ID but we supply the render target ID.
Robert Phillipsa27d6252019-12-10 14:48:36 -0500281 GrMockRenderTargetInfo rtInfo(texInfo.colorType(), NextInternalRenderTargetID());
Brian Salomon0c51eea2018-03-09 17:02:09 -0500282
Brian Salomone8a766b2019-07-19 14:24:36 -0400283 auto isProtected = GrProtected(tex.isProtected());
Brian Salomon27b4d8d2019-07-22 14:23:45 -0400284 return sk_sp<GrRenderTarget>(new GrMockRenderTarget(this, GrMockRenderTarget::kWrapped, desc,
285 sampleCnt, isProtected, rtInfo));
Brian Salomon0c51eea2018-03-09 17:02:09 -0500286}
287
Brian Salomondbf70722019-02-07 11:31:24 -0500288sk_sp<GrGpuBuffer> GrMockGpu::onCreateBuffer(size_t sizeInBytes, GrGpuBufferType type,
289 GrAccessPattern accessPattern, const void*) {
290 return sk_sp<GrGpuBuffer>(new GrMockBuffer(this, sizeInBytes, type, accessPattern));
Brian Salomoncfe910d2017-07-06 16:40:18 -0400291}
292
Chris Daltoneffee202019-07-01 22:28:03 -0600293GrStencilAttachment* GrMockGpu::createStencilAttachmentForRenderTarget(
294 const GrRenderTarget* rt, int width, int height, int numStencilSamples) {
295 SkASSERT(numStencilSamples == rt->numSamples());
Brian Salomoncfe910d2017-07-06 16:40:18 -0400296 static constexpr int kBits = 8;
297 fStats.incStencilAttachmentCreates();
Chris Dalton6ce447a2019-06-23 18:07:38 -0600298 return new GrMockStencilAttachment(this, width, height, kBits, rt->numSamples());
Brian Salomoncfe910d2017-07-06 16:40:18 -0400299}
Brian Salomon8fe24272017-07-07 12:56:11 -0400300
Brian Salomon85c3d682019-11-04 15:04:54 -0500301GrBackendTexture GrMockGpu::onCreateBackendTexture(SkISize dimensions,
Robert Phillips57ef6802019-09-23 10:12:47 -0400302 const GrBackendFormat& format,
Brian Salomon85c3d682019-11-04 15:04:54 -0500303 GrRenderable,
304 const BackendTextureData*,
Robert Phillips0d7e2f12019-12-18 13:01:04 -0500305 GrMipMapped mipMapped,
Brian Salomon85c3d682019-11-04 15:04:54 -0500306 GrProtected) {
Robert Phillipsa27d6252019-12-10 14:48:36 -0500307 SkImage::CompressionType compression = format.asMockCompressionType();
308 if (compression != SkImage::CompressionType::kNone) {
309 return {}; // should go through onCreateCompressedBackendTexture
310 }
311
Brian Salomond4764a12019-08-08 12:08:24 -0400312 auto colorType = format.asMockColorType();
Greg Daniel7bfc9132019-08-14 14:23:53 -0400313 if (!this->caps()->isFormatTexturable(format)) {
Robert Phillips9dbcdcc2019-05-13 10:40:06 -0400314 return GrBackendTexture(); // invalid
315 }
316
Robert Phillipsa27d6252019-12-10 14:48:36 -0500317 GrMockTextureInfo info(colorType, SkImage::CompressionType::kNone, NextExternalTextureID());
Robert Phillips646f6372018-09-25 09:31:10 -0400318
Robert Phillipsa27d6252019-12-10 14:48:36 -0500319 fOutstandingTestingOnlyTextureIDs.add(info.id());
Brian Salomon85c3d682019-11-04 15:04:54 -0500320 return GrBackendTexture(dimensions.width(), dimensions.height(), mipMapped, info);
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500321}
322
Robert Phillipsb915c942019-12-17 14:44:37 -0500323GrBackendTexture GrMockGpu::onCreateCompressedBackendTexture(SkISize dimensions,
324 const GrBackendFormat& format,
325 const BackendTextureData*,
326 GrMipMapped mipMapped,
327 GrProtected) {
328 SkImage::CompressionType compression = format.asMockCompressionType();
329 if (compression == SkImage::CompressionType::kNone) {
330 return {}; // should go through onCreateBackendTexture
331 }
332
333 if (!this->caps()->isFormatTexturable(format)) {
334 return {};
335 }
336
337 GrMockTextureInfo info(GrColorType::kUnknown, compression, NextExternalTextureID());
338
339 fOutstandingTestingOnlyTextureIDs.add(info.id());
340 return GrBackendTexture(dimensions.width(), dimensions.height(), mipMapped, info);
341}
342
Robert Phillipsf0313ee2019-05-21 13:51:11 -0400343void GrMockGpu::deleteBackendTexture(const GrBackendTexture& tex) {
Robert Phillipsf0ced622019-05-16 09:06:25 -0400344 SkASSERT(GrBackendApi::kMock == tex.backend());
345
346 GrMockTextureInfo info;
347 if (tex.getMockTextureInfo(&info)) {
Robert Phillipsa27d6252019-12-10 14:48:36 -0500348 fOutstandingTestingOnlyTextureIDs.remove(info.id());
Robert Phillipsf0ced622019-05-16 09:06:25 -0400349 }
350}
351
352#if GR_TEST_UTILS
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500353bool GrMockGpu::isTestingOnlyBackendTexture(const GrBackendTexture& tex) const {
Greg Danielbdf12ad2018-10-12 09:31:11 -0400354 SkASSERT(GrBackendApi::kMock == tex.backend());
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500355
Greg Daniel52e16d92018-04-10 09:34:07 -0400356 GrMockTextureInfo info;
357 if (!tex.getMockTextureInfo(&info)) {
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500358 return false;
359 }
360
Robert Phillipsa27d6252019-12-10 14:48:36 -0500361 return fOutstandingTestingOnlyTextureIDs.contains(info.id());
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500362}
363
Brian Salomon0c51eea2018-03-09 17:02:09 -0500364GrBackendRenderTarget GrMockGpu::createTestingOnlyBackendRenderTarget(int w, int h,
Brian Osman2d010b62018-08-09 10:55:09 -0400365 GrColorType colorType) {
Greg Daniele877dce2019-07-11 10:52:43 -0400366 GrMockRenderTargetInfo info(colorType, NextExternalRenderTargetID());
Brian Salomon0c51eea2018-03-09 17:02:09 -0500367 static constexpr int kSampleCnt = 1;
368 static constexpr int kStencilBits = 8;
Robert Phillipsa5e78be2019-07-09 12:34:38 -0400369 return GrBackendRenderTarget(w, h, kSampleCnt, kStencilBits, info);
Brian Salomonf865b052018-03-09 09:01:53 -0500370}
371
372void GrMockGpu::deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget&) {}
373#endif