blob: dc8232b644babb3b18f9e62ae4034540c73d04b9 [file] [log] [blame]
Chris Dalton706a6ff2017-11-29 22:01:06 -07001/*
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
8#include "Test.h"
9
10#if SK_SUPPORT_GPU
11
12#include "GrClip.h"
13#include "GrContextPriv.h"
Robert Phillips777707b2018-01-17 11:40:14 -050014#include "GrProxyProvider.h"
Chris Dalton706a6ff2017-11-29 22:01:06 -070015#include "GrOnFlushResourceProvider.h"
16#include "GrRenderTargetContext.h"
17#include "GrRenderTargetContextPriv.h"
18#include "GrSurfaceProxy.h"
Greg Daniel94a6ce82018-01-16 16:14:41 -050019#include "GrSurfaceProxyPriv.h"
Chris Dalton706a6ff2017-11-29 22:01:06 -070020#include "GrTexture.h"
21#include "GrTextureProxy.h"
22#include "GrTextureProxyPriv.h"
23#include "SkMakeUnique.h"
Mike Reed274218e2018-01-08 15:05:02 -050024#include "SkRectPriv.h"
Greg Daniel4684f822018-03-08 15:27:36 -050025#include "mock/GrMockGpu.h"
Chris Dalton706a6ff2017-11-29 22:01:06 -070026#include "mock/GrMockTypes.h"
27
28// This test verifies that lazy proxy callbacks get invoked during flush, after onFlush callbacks,
29// but before Ops are executed. It also ensures that lazy proxy callbacks are invoked both for
30// regular Ops and for clips.
31class LazyProxyTest final : public GrOnFlushCallbackObject {
32public:
33 LazyProxyTest(skiatest::Reporter* reporter)
34 : fReporter(reporter)
35 , fHasOpTexture(false)
36 , fHasClipTexture(false) {
37 }
38
39 ~LazyProxyTest() override {
40 REPORTER_ASSERT(fReporter, fHasOpTexture);
41 REPORTER_ASSERT(fReporter, fHasClipTexture);
42 }
43
44 void preFlush(GrOnFlushResourceProvider*, const uint32_t*, int,
45 SkTArray<sk_sp<GrRenderTargetContext>>*) override {
46 REPORTER_ASSERT(fReporter, !fHasOpTexture);
47 REPORTER_ASSERT(fReporter, !fHasClipTexture);
48 }
49
50 void postFlush(GrDeferredUploadToken, const uint32_t* opListIDs, int numOpListIDs) override {
51 REPORTER_ASSERT(fReporter, fHasOpTexture);
52 REPORTER_ASSERT(fReporter, fHasClipTexture);
53 }
54
55 class Op final : public GrDrawOp {
56 public:
57 DEFINE_OP_CLASS_ID
58
Robert Phillips777707b2018-01-17 11:40:14 -050059 Op(GrProxyProvider* proxyProvider, LazyProxyTest* test, bool nullTexture)
60 : GrDrawOp(ClassID()), fTest(test) {
61 fProxy = proxyProvider->createFullyLazyProxy([this, nullTexture](
Robert Phillipsce5209a2018-02-13 11:13:51 -050062 GrResourceProvider* rp) {
Greg Daniel0a375db2018-02-01 12:21:39 -050063 if (!rp) {
64 return sk_sp<GrTexture>();
65 }
Chris Dalton706a6ff2017-11-29 22:01:06 -070066 REPORTER_ASSERT(fTest->fReporter, !fTest->fHasOpTexture);
67 fTest->fHasOpTexture = true;
Chris Dalton706a6ff2017-11-29 22:01:06 -070068 if (nullTexture) {
69 return sk_sp<GrTexture>();
70 } else {
71 GrSurfaceDesc desc;
72 desc.fWidth = 1234;
73 desc.fHeight = 567;
Chris Dalton706a6ff2017-11-29 22:01:06 -070074 desc.fConfig = kRGB_565_GrPixelConfig;
75 sk_sp<GrTexture> texture = rp->createTexture(desc, SkBudgeted::kYes);
76 REPORTER_ASSERT(fTest->fReporter, texture);
77 return texture;
78 }
Robert Phillipsce5209a2018-02-13 11:13:51 -050079 }, GrProxyProvider::Renderable::kNo, kTopLeft_GrSurfaceOrigin, kRGB_565_GrPixelConfig);
Mike Reed274218e2018-01-08 15:05:02 -050080 this->setBounds(SkRectPriv::MakeLargest(), GrOp::HasAABloat::kNo, GrOp::IsZeroArea::kNo);
Chris Dalton706a6ff2017-11-29 22:01:06 -070081 }
82
83 void visitProxies(const VisitProxyFunc& func) const override {
84 func(fProxy.get());
85 }
86
87 void onExecute(GrOpFlushState*) override {
88 REPORTER_ASSERT(fTest->fReporter, fTest->fHasOpTexture);
89 REPORTER_ASSERT(fTest->fReporter, fTest->fHasClipTexture);
90 }
91
92 private:
93 const char* name() const override { return "LazyProxyTest::Op"; }
94 FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; }
95 RequiresDstTexture finalize(const GrCaps&, const GrAppliedClip*,
96 GrPixelConfigIsClamped) override {
97 return RequiresDstTexture::kNo;
98 }
Chris Dalton706a6ff2017-11-29 22:01:06 -070099 bool onCombineIfPossible(GrOp* other, const GrCaps& caps) override { return false; }
100 void onPrepare(GrOpFlushState*) override {}
101
102 LazyProxyTest* const fTest;
103 sk_sp<GrTextureProxy> fProxy;
104 };
105
106 class ClipFP : public GrFragmentProcessor {
107 public:
Robert Phillips777707b2018-01-17 11:40:14 -0500108 ClipFP(GrProxyProvider* proxyProvider, LazyProxyTest* test, GrTextureProxy* atlas)
Chris Dalton706a6ff2017-11-29 22:01:06 -0700109 : GrFragmentProcessor(kTestFP_ClassID, kNone_OptimizationFlags)
Robert Phillips777707b2018-01-17 11:40:14 -0500110 , fProxyProvider(proxyProvider)
Chris Dalton706a6ff2017-11-29 22:01:06 -0700111 , fTest(test)
112 , fAtlas(atlas) {
Robert Phillipsce5209a2018-02-13 11:13:51 -0500113 fLazyProxy = proxyProvider->createFullyLazyProxy(
114 [this](GrResourceProvider* rp) {
115 if (!rp) {
116 return sk_sp<GrTexture>();
117 }
118 REPORTER_ASSERT(fTest->fReporter, !fTest->fHasClipTexture);
119 fTest->fHasClipTexture = true;
120 fAtlas->instantiate(rp);
121 return sk_ref_sp(fAtlas->priv().peekTexture());
122 },
123 GrProxyProvider::Renderable::kYes,
124 kBottomLeft_GrSurfaceOrigin,
125 kAlpha_half_GrPixelConfig);
Chris Dalton706a6ff2017-11-29 22:01:06 -0700126 fAccess.reset(fLazyProxy, GrSamplerState::Filter::kNearest,
127 GrSamplerState::WrapMode::kClamp, kFragment_GrShaderFlag);
128 this->addTextureSampler(&fAccess);
129 }
130
131 private:
132 const char* name() const override { return "LazyProxyTest::ClipFP"; }
133 std::unique_ptr<GrFragmentProcessor> clone() const override {
Robert Phillips777707b2018-01-17 11:40:14 -0500134 return skstd::make_unique<ClipFP>(fProxyProvider, fTest, fAtlas);
Chris Dalton706a6ff2017-11-29 22:01:06 -0700135 }
136 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { return nullptr; }
137 void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override {}
138 bool onIsEqual(const GrFragmentProcessor&) const override { return false; }
139
Robert Phillips777707b2018-01-17 11:40:14 -0500140 GrProxyProvider* const fProxyProvider;
Chris Dalton706a6ff2017-11-29 22:01:06 -0700141 LazyProxyTest* const fTest;
142 GrTextureProxy* const fAtlas;
143 sk_sp<GrTextureProxy> fLazyProxy;
144 TextureSampler fAccess;
145 };
146
147
148 class Clip : public GrClip {
149 public:
150 Clip(LazyProxyTest* test, GrTextureProxy* atlas)
151 : fTest(test)
152 , fAtlas(atlas) {}
153
154 private:
Robert Phillips777707b2018-01-17 11:40:14 -0500155 bool apply(GrContext* context, GrRenderTargetContext*, bool, bool, GrAppliedClip* out,
Chris Dalton706a6ff2017-11-29 22:01:06 -0700156 SkRect* bounds) const override {
Robert Phillips777707b2018-01-17 11:40:14 -0500157 GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider();
158 out->addCoverageFP(skstd::make_unique<ClipFP>(proxyProvider, fTest, fAtlas));
Chris Dalton706a6ff2017-11-29 22:01:06 -0700159 return true;
160 }
161 bool quickContains(const SkRect&) const final { return false; }
162 bool isRRect(const SkRect& rtBounds, SkRRect* rr, GrAA*) const final { return false; }
163 void getConservativeBounds(int width, int height, SkIRect* rect, bool* iior) const final {
164 rect->set(0, 0, width, height);
165 if (iior) {
166 *iior = false;
167 }
168 }
169
170 LazyProxyTest* const fTest;
171 GrTextureProxy* fAtlas;
172 };
173
174private:
175 skiatest::Reporter* fReporter;
176 bool fHasOpTexture;
177 bool fHasClipTexture;
178};
179
180DEF_GPUTEST(LazyProxyTest, reporter, /* options */) {
181 GrMockOptions mockOptions;
Brian Salomonbdecacf2018-02-02 20:32:49 -0500182 mockOptions.fConfigOptions[kAlpha_half_GrPixelConfig].fRenderability =
183 GrMockOptions::ConfigOptions::Renderability::kNonMSAA;
Chris Dalton706a6ff2017-11-29 22:01:06 -0700184 mockOptions.fConfigOptions[kAlpha_half_GrPixelConfig].fTexturable = true;
185 sk_sp<GrContext> ctx = GrContext::MakeMock(&mockOptions, GrContextOptions());
Robert Phillips777707b2018-01-17 11:40:14 -0500186 GrProxyProvider* proxyProvider = ctx->contextPriv().proxyProvider();
Chris Dalton706a6ff2017-11-29 22:01:06 -0700187 for (bool nullTexture : {false, true}) {
188 LazyProxyTest test(reporter);
189 ctx->contextPriv().addOnFlushCallbackObject(&test);
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500190 sk_sp<GrRenderTargetContext> rtc = ctx->contextPriv().makeDeferredRenderTargetContext(
191 SkBackingFit::kExact, 100, 100,
192 kRGBA_8888_GrPixelConfig, nullptr);
Chris Dalton706a6ff2017-11-29 22:01:06 -0700193 REPORTER_ASSERT(reporter, rtc);
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500194 sk_sp<GrRenderTargetContext> mockAtlas = ctx->contextPriv().makeDeferredRenderTargetContext(
195 SkBackingFit::kExact, 10, 10,
Chris Dalton706a6ff2017-11-29 22:01:06 -0700196 kAlpha_half_GrPixelConfig, nullptr);
197 REPORTER_ASSERT(reporter, mockAtlas);
198 rtc->priv().testingOnly_addDrawOp(LazyProxyTest::Clip(&test, mockAtlas->asTextureProxy()),
Robert Phillips777707b2018-01-17 11:40:14 -0500199 skstd::make_unique<LazyProxyTest::Op>(proxyProvider, &test, nullTexture));
Chris Dalton706a6ff2017-11-29 22:01:06 -0700200 ctx->contextPriv().testingOnly_flushAndRemoveOnFlushCallbackObject(&test);
201 }
202}
203
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500204static const int kSize = 16;
205
Greg Daniel94a6ce82018-01-16 16:14:41 -0500206DEF_GPUTEST(LazyProxyReleaseTest, reporter, /* options */) {
207 GrMockOptions mockOptions;
208 sk_sp<GrContext> ctx = GrContext::MakeMock(&mockOptions, GrContextOptions());
Robert Phillips777707b2018-01-17 11:40:14 -0500209 auto proxyProvider = ctx->contextPriv().proxyProvider();
Greg Daniel94a6ce82018-01-16 16:14:41 -0500210
211 GrSurfaceDesc desc;
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500212 desc.fWidth = kSize;
213 desc.fHeight = kSize;
Greg Daniel94a6ce82018-01-16 16:14:41 -0500214 desc.fConfig = kRGBA_8888_GrPixelConfig;
215
Greg Daniel457469c2018-02-08 15:05:44 -0500216 using LazyInstantiationType = GrSurfaceProxy::LazyInstantiationType;
Greg Daniel94a6ce82018-01-16 16:14:41 -0500217 for (bool doInstantiate : {true, false}) {
Greg Daniel457469c2018-02-08 15:05:44 -0500218 for (auto lazyType : {LazyInstantiationType::kSingleUse,
Greg Daniela8d92112018-03-09 12:05:04 -0500219 LazyInstantiationType::kMultipleUse,
220 LazyInstantiationType::kUninstantiate}) {
Greg Daniel457469c2018-02-08 15:05:44 -0500221 int testCount = 0;
222 int* testCountPtr = &testCount;
223 sk_sp<GrTextureProxy> proxy = proxyProvider->createLazyProxy(
Robert Phillipsce5209a2018-02-13 11:13:51 -0500224 [testCountPtr](GrResourceProvider* resourceProvider) {
Greg Daniel457469c2018-02-08 15:05:44 -0500225 if (!resourceProvider) {
226 *testCountPtr = -1;
227 return sk_sp<GrTexture>();
228 }
229 *testCountPtr = 1;
Greg Daniel94a6ce82018-01-16 16:14:41 -0500230 return sk_sp<GrTexture>();
Brian Salomon2a4f9832018-03-03 22:43:43 -0500231 },
Robert Phillipsfe0253f2018-03-16 16:47:25 -0400232 desc, kTopLeft_GrSurfaceOrigin, GrMipMapped::kNo, GrInternalSurfaceFlags::kNone,
Greg Daniela8d92112018-03-09 12:05:04 -0500233 SkBackingFit::kExact, SkBudgeted::kNo, lazyType);
Greg Daniel94a6ce82018-01-16 16:14:41 -0500234
Greg Daniel92cbf3f2018-04-12 16:50:17 -0400235 REPORTER_ASSERT(reporter, proxy.get());
Greg Daniel457469c2018-02-08 15:05:44 -0500236 REPORTER_ASSERT(reporter, 0 == testCount);
237
238 if (doInstantiate) {
239 proxy->priv().doLazyInstantiation(ctx->contextPriv().resourceProvider());
240 if (LazyInstantiationType::kSingleUse == proxy->priv().lazyInstantiationType()) {
241 // In SingleUse we will call the cleanup and delete the callback in the
242 // doLazyInstantiationCall.
243 REPORTER_ASSERT(reporter, -1 == testCount);
244 } else {
245 REPORTER_ASSERT(reporter, 1 == testCount);
246 }
247 proxy.reset();
248 REPORTER_ASSERT(reporter, -1 == testCount);
249 } else {
250 proxy.reset();
251 REPORTER_ASSERT(reporter, -1 == testCount);
252 }
Greg Daniel94a6ce82018-01-16 16:14:41 -0500253 }
254 }
255}
256
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500257class LazyFailedInstantiationTestOp : public GrDrawOp {
258public:
259 DEFINE_OP_CLASS_ID
260
261 LazyFailedInstantiationTestOp(GrProxyProvider* proxyProvider, int* testExecuteValue,
262 bool shouldFailInstantiation)
263 : INHERITED(ClassID())
264 , fTestExecuteValue(testExecuteValue) {
265 GrSurfaceDesc desc;
266 desc.fWidth = kSize;
267 desc.fHeight = kSize;
268 desc.fConfig = kRGBA_8888_GrPixelConfig;
269
270 fLazyProxy = proxyProvider->createLazyProxy(
Brian Salomon2a4f9832018-03-03 22:43:43 -0500271 [testExecuteValue, shouldFailInstantiation, desc](GrResourceProvider* rp) {
Greg Daniel0a375db2018-02-01 12:21:39 -0500272 if (!rp) {
273 return sk_sp<GrTexture>();
274 }
275 if (shouldFailInstantiation) {
276 *testExecuteValue = 1;
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500277 return sk_sp<GrTexture>();
278 }
279 return rp->createTexture(desc, SkBudgeted::kNo);
Brian Salomon2a4f9832018-03-03 22:43:43 -0500280 },
281 desc, kTopLeft_GrSurfaceOrigin, GrMipMapped::kNo, SkBackingFit::kExact,
282 SkBudgeted::kNo);
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500283
Greg Daniel92cbf3f2018-04-12 16:50:17 -0400284 SkASSERT(fLazyProxy.get());
285
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500286 this->setBounds(SkRect::MakeIWH(kSize, kSize),
287 HasAABloat::kNo, IsZeroArea::kNo);
288 }
289
290 void visitProxies(const VisitProxyFunc& func) const override {
291 func(fLazyProxy.get());
292 }
293
294private:
295 const char* name() const override { return "LazyFailedInstantiationTestOp"; }
296 FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; }
297 RequiresDstTexture finalize(const GrCaps&, const GrAppliedClip*,
298 GrPixelConfigIsClamped) override {
299 return RequiresDstTexture::kNo;
300 }
301 bool onCombineIfPossible(GrOp* other, const GrCaps& caps) override { return false; }
302 void onPrepare(GrOpFlushState*) override {}
303 void onExecute(GrOpFlushState* state) override {
304 *fTestExecuteValue = 2;
305 }
306
307 int* fTestExecuteValue;
308 sk_sp<GrSurfaceProxy> fLazyProxy;
309
310 typedef GrDrawOp INHERITED;
311};
312
313// Test that when a lazy proxy fails to instantiate during flush that we drop the Op that it was
314// associated with.
315DEF_GPUTEST(LazyProxyFailedInstantiationTest, reporter, /* options */) {
316 GrMockOptions mockOptions;
317 sk_sp<GrContext> ctx = GrContext::MakeMock(&mockOptions, GrContextOptions());
Robert Phillips4150eea2018-02-07 17:08:21 -0500318 GrResourceProvider* resourceProvider = ctx->contextPriv().resourceProvider();
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500319 GrProxyProvider* proxyProvider = ctx->contextPriv().proxyProvider();
320 for (bool failInstantiation : {false, true}) {
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500321 sk_sp<GrRenderTargetContext> rtc = ctx->contextPriv().makeDeferredRenderTargetContext(
322 SkBackingFit::kExact, 100, 100,
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500323 kRGBA_8888_GrPixelConfig, nullptr);
324 REPORTER_ASSERT(reporter, rtc);
325
326 rtc->clear(nullptr, 0xbaaaaaad, GrRenderTargetContext::CanClearFullscreen::kYes);
327
328 int executeTestValue = 0;
329 rtc->priv().testingOnly_addDrawOp(
330 skstd::make_unique<LazyFailedInstantiationTestOp>(proxyProvider, &executeTestValue,
331 failInstantiation));
332 ctx->flush();
333
334 if (failInstantiation) {
Robert Phillips4150eea2018-02-07 17:08:21 -0500335 if (resourceProvider->explicitlyAllocateGPUResources()) {
336 REPORTER_ASSERT(reporter, 1 == executeTestValue);
337 } else {
338 // When we disable explicit gpu resource allocation we don't throw away ops that
339 // have uninstantiated proxies.
340 REPORTER_ASSERT(reporter, 2 == executeTestValue);
341 }
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500342 } else {
343 REPORTER_ASSERT(reporter, 2 == executeTestValue);
344 }
345 }
Greg Daniel4684f822018-03-08 15:27:36 -0500346}
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500347
Greg Daniel4684f822018-03-08 15:27:36 -0500348class LazyUninstantiateTestOp : public GrDrawOp {
349public:
350 DEFINE_OP_CLASS_ID
351
352 LazyUninstantiateTestOp(sk_sp<GrTextureProxy> proxy)
353 : INHERITED(ClassID())
354 , fLazyProxy(std::move(proxy)) {
355
356 this->setBounds(SkRect::MakeIWH(kSize, kSize),
357 HasAABloat::kNo, IsZeroArea::kNo);
358 }
359
360 void visitProxies(const VisitProxyFunc& func) const override {
361 func(fLazyProxy.get());
362 }
363
364private:
365 const char* name() const override { return "LazyUninstantiateTestOp"; }
366 FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; }
367 RequiresDstTexture finalize(const GrCaps&, const GrAppliedClip*,
368 GrPixelConfigIsClamped) override {
369 return RequiresDstTexture::kNo;
370 }
371 bool onCombineIfPossible(GrOp* other, const GrCaps& caps) override { return false; }
372 void onPrepare(GrOpFlushState*) override {}
373 void onExecute(GrOpFlushState* state) override {}
374
375 sk_sp<GrSurfaceProxy> fLazyProxy;
376
377 typedef GrDrawOp INHERITED;
378};
379
380static void UninstantiateReleaseProc(void* releaseValue) {
381 (*static_cast<int*>(releaseValue))++;
382}
383
384// Test that lazy proxies with the Uninstantiate LazyCallbackType are uninstantiated and released as
385// expected.
386DEF_GPUTEST(LazyProxyUninstantiateTest, reporter, /* options */) {
387 GrMockOptions mockOptions;
388 sk_sp<GrContext> ctx = GrContext::MakeMock(&mockOptions, GrContextOptions());
389 GrProxyProvider* proxyProvider = ctx->contextPriv().proxyProvider();
390 GrGpu* gpu = ctx->contextPriv().getGpu();
391
392 using LazyType = GrSurfaceProxy::LazyInstantiationType;
393 for (auto lazyType : {LazyType::kSingleUse, LazyType::kMultipleUse, LazyType::kUninstantiate}) {
394 sk_sp<GrRenderTargetContext> rtc = ctx->contextPriv().makeDeferredRenderTargetContext(
395 SkBackingFit::kExact, 100, 100,
396 kRGBA_8888_GrPixelConfig, nullptr);
397 REPORTER_ASSERT(reporter, rtc);
398
399 rtc->clear(nullptr, 0xbaaaaaad, GrRenderTargetContext::CanClearFullscreen::kYes);
400
401 int instantiateTestValue = 0;
402 int releaseTestValue = 0;
403 int* instantiatePtr = &instantiateTestValue;
404 int* releasePtr = &releaseTestValue;
405 GrSurfaceDesc desc;
406 desc.fWidth = kSize;
407 desc.fHeight = kSize;
408 desc.fConfig = kRGBA_8888_GrPixelConfig;
409
410 GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(
411 nullptr, kSize, kSize, kRGBA_8888_GrPixelConfig, false, GrMipMapped::kNo);
412
413 sk_sp<GrTextureProxy> lazyProxy = proxyProvider->createLazyProxy(
414 [instantiatePtr, releasePtr, backendTex](GrResourceProvider* rp) {
415 if (!rp) {
416 return sk_sp<GrTexture>();
417 }
418
419 sk_sp<GrTexture> texture = rp->wrapBackendTexture(backendTex);
420 if (!texture) {
421 return sk_sp<GrTexture>();
422 }
423 (*instantiatePtr)++;
424 texture->setRelease(UninstantiateReleaseProc, releasePtr);
425 return texture;
426 },
Robert Phillipsfe0253f2018-03-16 16:47:25 -0400427 desc, kTopLeft_GrSurfaceOrigin, GrMipMapped::kNo, GrInternalSurfaceFlags::kNone,
Greg Daniela8d92112018-03-09 12:05:04 -0500428 SkBackingFit::kExact, SkBudgeted::kNo, lazyType);
Greg Daniel4684f822018-03-08 15:27:36 -0500429
Greg Daniel92cbf3f2018-04-12 16:50:17 -0400430 REPORTER_ASSERT(reporter, lazyProxy.get());
431
Greg Daniele3204862018-04-16 11:24:10 -0400432 // We can't pass the fact that this creates a wrapped texture into createLazyProxy so we
433 // need to manually call setDoesNotSupportMipMaps.
434 lazyProxy->texPriv().setDoesNotSupportMipMaps();
435
Greg Daniel4684f822018-03-08 15:27:36 -0500436 rtc->priv().testingOnly_addDrawOp(skstd::make_unique<LazyUninstantiateTestOp>(lazyProxy));
437
438 ctx->flush();
439
440 REPORTER_ASSERT(reporter, 1 == instantiateTestValue);
441 if (LazyType::kUninstantiate == lazyType) {
442 REPORTER_ASSERT(reporter, 1 == releaseTestValue);
443 } else {
444 REPORTER_ASSERT(reporter, 0 == releaseTestValue);
445 }
446
447 // This should cause the uninstantiate proxies to be instantiated again but have no effect
448 // on the others
449 rtc->priv().testingOnly_addDrawOp(skstd::make_unique<LazyUninstantiateTestOp>(lazyProxy));
450 // Add a second op to make sure we only instantiate once.
451 rtc->priv().testingOnly_addDrawOp(skstd::make_unique<LazyUninstantiateTestOp>(lazyProxy));
452 ctx->flush();
453
454 if (LazyType::kUninstantiate == lazyType) {
455 REPORTER_ASSERT(reporter, 2 == instantiateTestValue);
456 REPORTER_ASSERT(reporter, 2 == releaseTestValue);
457 } else {
458 REPORTER_ASSERT(reporter, 1 == instantiateTestValue);
459 REPORTER_ASSERT(reporter, 0 == releaseTestValue);
460 }
461
462 lazyProxy.reset();
463 if (LazyType::kUninstantiate == lazyType) {
464 REPORTER_ASSERT(reporter, 2 == releaseTestValue);
465 } else {
466 REPORTER_ASSERT(reporter, 1 == releaseTestValue);
467 }
468
Brian Salomon26102cb2018-03-09 09:33:19 -0500469 gpu->deleteTestingOnlyBackendTexture(backendTex);
Greg Daniel4684f822018-03-08 15:27:36 -0500470 }
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500471}
472
Chris Dalton706a6ff2017-11-29 22:01:06 -0700473#endif