blob: c048ea6a28f93e90b792d2ab31c1d74cfbabe7ec [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 }
99 void wasRecorded(GrRenderTargetOpList*) override {}
100 bool onCombineIfPossible(GrOp* other, const GrCaps& caps) override { return false; }
101 void onPrepare(GrOpFlushState*) override {}
102
103 LazyProxyTest* const fTest;
104 sk_sp<GrTextureProxy> fProxy;
105 };
106
107 class ClipFP : public GrFragmentProcessor {
108 public:
Robert Phillips777707b2018-01-17 11:40:14 -0500109 ClipFP(GrProxyProvider* proxyProvider, LazyProxyTest* test, GrTextureProxy* atlas)
Chris Dalton706a6ff2017-11-29 22:01:06 -0700110 : GrFragmentProcessor(kTestFP_ClassID, kNone_OptimizationFlags)
Robert Phillips777707b2018-01-17 11:40:14 -0500111 , fProxyProvider(proxyProvider)
Chris Dalton706a6ff2017-11-29 22:01:06 -0700112 , fTest(test)
113 , fAtlas(atlas) {
Robert Phillipsce5209a2018-02-13 11:13:51 -0500114 fLazyProxy = proxyProvider->createFullyLazyProxy(
115 [this](GrResourceProvider* rp) {
116 if (!rp) {
117 return sk_sp<GrTexture>();
118 }
119 REPORTER_ASSERT(fTest->fReporter, !fTest->fHasClipTexture);
120 fTest->fHasClipTexture = true;
121 fAtlas->instantiate(rp);
122 return sk_ref_sp(fAtlas->priv().peekTexture());
123 },
124 GrProxyProvider::Renderable::kYes,
125 kBottomLeft_GrSurfaceOrigin,
126 kAlpha_half_GrPixelConfig);
Chris Dalton706a6ff2017-11-29 22:01:06 -0700127 fAccess.reset(fLazyProxy, GrSamplerState::Filter::kNearest,
128 GrSamplerState::WrapMode::kClamp, kFragment_GrShaderFlag);
129 this->addTextureSampler(&fAccess);
130 }
131
132 private:
133 const char* name() const override { return "LazyProxyTest::ClipFP"; }
134 std::unique_ptr<GrFragmentProcessor> clone() const override {
Robert Phillips777707b2018-01-17 11:40:14 -0500135 return skstd::make_unique<ClipFP>(fProxyProvider, fTest, fAtlas);
Chris Dalton706a6ff2017-11-29 22:01:06 -0700136 }
137 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { return nullptr; }
138 void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override {}
139 bool onIsEqual(const GrFragmentProcessor&) const override { return false; }
140
Robert Phillips777707b2018-01-17 11:40:14 -0500141 GrProxyProvider* const fProxyProvider;
Chris Dalton706a6ff2017-11-29 22:01:06 -0700142 LazyProxyTest* const fTest;
143 GrTextureProxy* const fAtlas;
144 sk_sp<GrTextureProxy> fLazyProxy;
145 TextureSampler fAccess;
146 };
147
148
149 class Clip : public GrClip {
150 public:
151 Clip(LazyProxyTest* test, GrTextureProxy* atlas)
152 : fTest(test)
153 , fAtlas(atlas) {}
154
155 private:
Robert Phillips777707b2018-01-17 11:40:14 -0500156 bool apply(GrContext* context, GrRenderTargetContext*, bool, bool, GrAppliedClip* out,
Chris Dalton706a6ff2017-11-29 22:01:06 -0700157 SkRect* bounds) const override {
Robert Phillips777707b2018-01-17 11:40:14 -0500158 GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider();
159 out->addCoverageFP(skstd::make_unique<ClipFP>(proxyProvider, fTest, fAtlas));
Chris Dalton706a6ff2017-11-29 22:01:06 -0700160 return true;
161 }
162 bool quickContains(const SkRect&) const final { return false; }
163 bool isRRect(const SkRect& rtBounds, SkRRect* rr, GrAA*) const final { return false; }
164 void getConservativeBounds(int width, int height, SkIRect* rect, bool* iior) const final {
165 rect->set(0, 0, width, height);
166 if (iior) {
167 *iior = false;
168 }
169 }
170
171 LazyProxyTest* const fTest;
172 GrTextureProxy* fAtlas;
173 };
174
175private:
176 skiatest::Reporter* fReporter;
177 bool fHasOpTexture;
178 bool fHasClipTexture;
179};
180
181DEF_GPUTEST(LazyProxyTest, reporter, /* options */) {
182 GrMockOptions mockOptions;
Brian Salomonbdecacf2018-02-02 20:32:49 -0500183 mockOptions.fConfigOptions[kAlpha_half_GrPixelConfig].fRenderability =
184 GrMockOptions::ConfigOptions::Renderability::kNonMSAA;
Chris Dalton706a6ff2017-11-29 22:01:06 -0700185 mockOptions.fConfigOptions[kAlpha_half_GrPixelConfig].fTexturable = true;
186 sk_sp<GrContext> ctx = GrContext::MakeMock(&mockOptions, GrContextOptions());
Robert Phillips777707b2018-01-17 11:40:14 -0500187 GrProxyProvider* proxyProvider = ctx->contextPriv().proxyProvider();
Chris Dalton706a6ff2017-11-29 22:01:06 -0700188 for (bool nullTexture : {false, true}) {
189 LazyProxyTest test(reporter);
190 ctx->contextPriv().addOnFlushCallbackObject(&test);
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500191 sk_sp<GrRenderTargetContext> rtc = ctx->contextPriv().makeDeferredRenderTargetContext(
192 SkBackingFit::kExact, 100, 100,
193 kRGBA_8888_GrPixelConfig, nullptr);
Chris Dalton706a6ff2017-11-29 22:01:06 -0700194 REPORTER_ASSERT(reporter, rtc);
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500195 sk_sp<GrRenderTargetContext> mockAtlas = ctx->contextPriv().makeDeferredRenderTargetContext(
196 SkBackingFit::kExact, 10, 10,
Chris Dalton706a6ff2017-11-29 22:01:06 -0700197 kAlpha_half_GrPixelConfig, nullptr);
198 REPORTER_ASSERT(reporter, mockAtlas);
199 rtc->priv().testingOnly_addDrawOp(LazyProxyTest::Clip(&test, mockAtlas->asTextureProxy()),
Robert Phillips777707b2018-01-17 11:40:14 -0500200 skstd::make_unique<LazyProxyTest::Op>(proxyProvider, &test, nullTexture));
Chris Dalton706a6ff2017-11-29 22:01:06 -0700201 ctx->contextPriv().testingOnly_flushAndRemoveOnFlushCallbackObject(&test);
202 }
203}
204
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500205static const int kSize = 16;
206
Greg Daniel94a6ce82018-01-16 16:14:41 -0500207DEF_GPUTEST(LazyProxyReleaseTest, reporter, /* options */) {
208 GrMockOptions mockOptions;
209 sk_sp<GrContext> ctx = GrContext::MakeMock(&mockOptions, GrContextOptions());
Robert Phillips777707b2018-01-17 11:40:14 -0500210 auto proxyProvider = ctx->contextPriv().proxyProvider();
Greg Daniel94a6ce82018-01-16 16:14:41 -0500211
212 GrSurfaceDesc desc;
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500213 desc.fWidth = kSize;
214 desc.fHeight = kSize;
Greg Daniel94a6ce82018-01-16 16:14:41 -0500215 desc.fConfig = kRGBA_8888_GrPixelConfig;
216
Greg Daniel457469c2018-02-08 15:05:44 -0500217 using LazyInstantiationType = GrSurfaceProxy::LazyInstantiationType;
Greg Daniel94a6ce82018-01-16 16:14:41 -0500218 for (bool doInstantiate : {true, false}) {
Greg Daniel457469c2018-02-08 15:05:44 -0500219 for (auto lazyType : {LazyInstantiationType::kSingleUse,
Greg Daniela8d92112018-03-09 12:05:04 -0500220 LazyInstantiationType::kMultipleUse,
221 LazyInstantiationType::kUninstantiate}) {
Greg Daniel457469c2018-02-08 15:05:44 -0500222 int testCount = 0;
223 int* testCountPtr = &testCount;
224 sk_sp<GrTextureProxy> proxy = proxyProvider->createLazyProxy(
Robert Phillipsce5209a2018-02-13 11:13:51 -0500225 [testCountPtr](GrResourceProvider* resourceProvider) {
Greg Daniel457469c2018-02-08 15:05:44 -0500226 if (!resourceProvider) {
227 *testCountPtr = -1;
228 return sk_sp<GrTexture>();
229 }
230 *testCountPtr = 1;
Greg Daniel94a6ce82018-01-16 16:14:41 -0500231 return sk_sp<GrTexture>();
Brian Salomon2a4f9832018-03-03 22:43:43 -0500232 },
Robert Phillipsfe0253f2018-03-16 16:47:25 -0400233 desc, kTopLeft_GrSurfaceOrigin, GrMipMapped::kNo, GrInternalSurfaceFlags::kNone,
Greg Daniela8d92112018-03-09 12:05:04 -0500234 SkBackingFit::kExact, SkBudgeted::kNo, lazyType);
Greg Daniel94a6ce82018-01-16 16:14:41 -0500235
Greg Daniel92cbf3f2018-04-12 16:50:17 -0400236 REPORTER_ASSERT(reporter, proxy.get());
Greg Daniel457469c2018-02-08 15:05:44 -0500237 REPORTER_ASSERT(reporter, 0 == testCount);
238
239 if (doInstantiate) {
240 proxy->priv().doLazyInstantiation(ctx->contextPriv().resourceProvider());
241 if (LazyInstantiationType::kSingleUse == proxy->priv().lazyInstantiationType()) {
242 // In SingleUse we will call the cleanup and delete the callback in the
243 // doLazyInstantiationCall.
244 REPORTER_ASSERT(reporter, -1 == testCount);
245 } else {
246 REPORTER_ASSERT(reporter, 1 == testCount);
247 }
248 proxy.reset();
249 REPORTER_ASSERT(reporter, -1 == testCount);
250 } else {
251 proxy.reset();
252 REPORTER_ASSERT(reporter, -1 == testCount);
253 }
Greg Daniel94a6ce82018-01-16 16:14:41 -0500254 }
255 }
256}
257
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500258class LazyFailedInstantiationTestOp : public GrDrawOp {
259public:
260 DEFINE_OP_CLASS_ID
261
262 LazyFailedInstantiationTestOp(GrProxyProvider* proxyProvider, int* testExecuteValue,
263 bool shouldFailInstantiation)
264 : INHERITED(ClassID())
265 , fTestExecuteValue(testExecuteValue) {
266 GrSurfaceDesc desc;
267 desc.fWidth = kSize;
268 desc.fHeight = kSize;
269 desc.fConfig = kRGBA_8888_GrPixelConfig;
270
271 fLazyProxy = proxyProvider->createLazyProxy(
Brian Salomon2a4f9832018-03-03 22:43:43 -0500272 [testExecuteValue, shouldFailInstantiation, desc](GrResourceProvider* rp) {
Greg Daniel0a375db2018-02-01 12:21:39 -0500273 if (!rp) {
274 return sk_sp<GrTexture>();
275 }
276 if (shouldFailInstantiation) {
277 *testExecuteValue = 1;
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500278 return sk_sp<GrTexture>();
279 }
280 return rp->createTexture(desc, SkBudgeted::kNo);
Brian Salomon2a4f9832018-03-03 22:43:43 -0500281 },
282 desc, kTopLeft_GrSurfaceOrigin, GrMipMapped::kNo, SkBackingFit::kExact,
283 SkBudgeted::kNo);
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500284
Greg Daniel92cbf3f2018-04-12 16:50:17 -0400285 SkASSERT(fLazyProxy.get());
286
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500287 this->setBounds(SkRect::MakeIWH(kSize, kSize),
288 HasAABloat::kNo, IsZeroArea::kNo);
289 }
290
291 void visitProxies(const VisitProxyFunc& func) const override {
292 func(fLazyProxy.get());
293 }
294
295private:
296 const char* name() const override { return "LazyFailedInstantiationTestOp"; }
297 FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; }
298 RequiresDstTexture finalize(const GrCaps&, const GrAppliedClip*,
299 GrPixelConfigIsClamped) override {
300 return RequiresDstTexture::kNo;
301 }
302 bool onCombineIfPossible(GrOp* other, const GrCaps& caps) override { return false; }
303 void onPrepare(GrOpFlushState*) override {}
304 void onExecute(GrOpFlushState* state) override {
305 *fTestExecuteValue = 2;
306 }
307
308 int* fTestExecuteValue;
309 sk_sp<GrSurfaceProxy> fLazyProxy;
310
311 typedef GrDrawOp INHERITED;
312};
313
314// Test that when a lazy proxy fails to instantiate during flush that we drop the Op that it was
315// associated with.
316DEF_GPUTEST(LazyProxyFailedInstantiationTest, reporter, /* options */) {
317 GrMockOptions mockOptions;
318 sk_sp<GrContext> ctx = GrContext::MakeMock(&mockOptions, GrContextOptions());
Robert Phillips4150eea2018-02-07 17:08:21 -0500319 GrResourceProvider* resourceProvider = ctx->contextPriv().resourceProvider();
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500320 GrProxyProvider* proxyProvider = ctx->contextPriv().proxyProvider();
321 for (bool failInstantiation : {false, true}) {
Robert Phillips0c4b7b12018-03-06 08:20:37 -0500322 sk_sp<GrRenderTargetContext> rtc = ctx->contextPriv().makeDeferredRenderTargetContext(
323 SkBackingFit::kExact, 100, 100,
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500324 kRGBA_8888_GrPixelConfig, nullptr);
325 REPORTER_ASSERT(reporter, rtc);
326
327 rtc->clear(nullptr, 0xbaaaaaad, GrRenderTargetContext::CanClearFullscreen::kYes);
328
329 int executeTestValue = 0;
330 rtc->priv().testingOnly_addDrawOp(
331 skstd::make_unique<LazyFailedInstantiationTestOp>(proxyProvider, &executeTestValue,
332 failInstantiation));
333 ctx->flush();
334
335 if (failInstantiation) {
Robert Phillips4150eea2018-02-07 17:08:21 -0500336 if (resourceProvider->explicitlyAllocateGPUResources()) {
337 REPORTER_ASSERT(reporter, 1 == executeTestValue);
338 } else {
339 // When we disable explicit gpu resource allocation we don't throw away ops that
340 // have uninstantiated proxies.
341 REPORTER_ASSERT(reporter, 2 == executeTestValue);
342 }
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500343 } else {
344 REPORTER_ASSERT(reporter, 2 == executeTestValue);
345 }
346 }
Greg Daniel4684f822018-03-08 15:27:36 -0500347}
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500348
Greg Daniel4684f822018-03-08 15:27:36 -0500349class LazyUninstantiateTestOp : public GrDrawOp {
350public:
351 DEFINE_OP_CLASS_ID
352
353 LazyUninstantiateTestOp(sk_sp<GrTextureProxy> proxy)
354 : INHERITED(ClassID())
355 , fLazyProxy(std::move(proxy)) {
356
357 this->setBounds(SkRect::MakeIWH(kSize, kSize),
358 HasAABloat::kNo, IsZeroArea::kNo);
359 }
360
361 void visitProxies(const VisitProxyFunc& func) const override {
362 func(fLazyProxy.get());
363 }
364
365private:
366 const char* name() const override { return "LazyUninstantiateTestOp"; }
367 FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; }
368 RequiresDstTexture finalize(const GrCaps&, const GrAppliedClip*,
369 GrPixelConfigIsClamped) override {
370 return RequiresDstTexture::kNo;
371 }
372 bool onCombineIfPossible(GrOp* other, const GrCaps& caps) override { return false; }
373 void onPrepare(GrOpFlushState*) override {}
374 void onExecute(GrOpFlushState* state) override {}
375
376 sk_sp<GrSurfaceProxy> fLazyProxy;
377
378 typedef GrDrawOp INHERITED;
379};
380
381static void UninstantiateReleaseProc(void* releaseValue) {
382 (*static_cast<int*>(releaseValue))++;
383}
384
385// Test that lazy proxies with the Uninstantiate LazyCallbackType are uninstantiated and released as
386// expected.
387DEF_GPUTEST(LazyProxyUninstantiateTest, reporter, /* options */) {
388 GrMockOptions mockOptions;
389 sk_sp<GrContext> ctx = GrContext::MakeMock(&mockOptions, GrContextOptions());
390 GrProxyProvider* proxyProvider = ctx->contextPriv().proxyProvider();
391 GrGpu* gpu = ctx->contextPriv().getGpu();
392
393 using LazyType = GrSurfaceProxy::LazyInstantiationType;
394 for (auto lazyType : {LazyType::kSingleUse, LazyType::kMultipleUse, LazyType::kUninstantiate}) {
395 sk_sp<GrRenderTargetContext> rtc = ctx->contextPriv().makeDeferredRenderTargetContext(
396 SkBackingFit::kExact, 100, 100,
397 kRGBA_8888_GrPixelConfig, nullptr);
398 REPORTER_ASSERT(reporter, rtc);
399
400 rtc->clear(nullptr, 0xbaaaaaad, GrRenderTargetContext::CanClearFullscreen::kYes);
401
402 int instantiateTestValue = 0;
403 int releaseTestValue = 0;
404 int* instantiatePtr = &instantiateTestValue;
405 int* releasePtr = &releaseTestValue;
406 GrSurfaceDesc desc;
407 desc.fWidth = kSize;
408 desc.fHeight = kSize;
409 desc.fConfig = kRGBA_8888_GrPixelConfig;
410
411 GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(
412 nullptr, kSize, kSize, kRGBA_8888_GrPixelConfig, false, GrMipMapped::kNo);
413
414 sk_sp<GrTextureProxy> lazyProxy = proxyProvider->createLazyProxy(
415 [instantiatePtr, releasePtr, backendTex](GrResourceProvider* rp) {
416 if (!rp) {
417 return sk_sp<GrTexture>();
418 }
419
420 sk_sp<GrTexture> texture = rp->wrapBackendTexture(backendTex);
421 if (!texture) {
422 return sk_sp<GrTexture>();
423 }
424 (*instantiatePtr)++;
425 texture->setRelease(UninstantiateReleaseProc, releasePtr);
426 return texture;
427 },
Robert Phillipsfe0253f2018-03-16 16:47:25 -0400428 desc, kTopLeft_GrSurfaceOrigin, GrMipMapped::kNo, GrInternalSurfaceFlags::kNone,
Greg Daniela8d92112018-03-09 12:05:04 -0500429 SkBackingFit::kExact, SkBudgeted::kNo, lazyType);
Greg Daniel4684f822018-03-08 15:27:36 -0500430
Greg Daniel92cbf3f2018-04-12 16:50:17 -0400431 REPORTER_ASSERT(reporter, lazyProxy.get());
432
Greg Daniel4684f822018-03-08 15:27:36 -0500433 rtc->priv().testingOnly_addDrawOp(skstd::make_unique<LazyUninstantiateTestOp>(lazyProxy));
434
435 ctx->flush();
436
437 REPORTER_ASSERT(reporter, 1 == instantiateTestValue);
438 if (LazyType::kUninstantiate == lazyType) {
439 REPORTER_ASSERT(reporter, 1 == releaseTestValue);
440 } else {
441 REPORTER_ASSERT(reporter, 0 == releaseTestValue);
442 }
443
444 // This should cause the uninstantiate proxies to be instantiated again but have no effect
445 // on the others
446 rtc->priv().testingOnly_addDrawOp(skstd::make_unique<LazyUninstantiateTestOp>(lazyProxy));
447 // Add a second op to make sure we only instantiate once.
448 rtc->priv().testingOnly_addDrawOp(skstd::make_unique<LazyUninstantiateTestOp>(lazyProxy));
449 ctx->flush();
450
451 if (LazyType::kUninstantiate == lazyType) {
452 REPORTER_ASSERT(reporter, 2 == instantiateTestValue);
453 REPORTER_ASSERT(reporter, 2 == releaseTestValue);
454 } else {
455 REPORTER_ASSERT(reporter, 1 == instantiateTestValue);
456 REPORTER_ASSERT(reporter, 0 == releaseTestValue);
457 }
458
459 lazyProxy.reset();
460 if (LazyType::kUninstantiate == lazyType) {
461 REPORTER_ASSERT(reporter, 2 == releaseTestValue);
462 } else {
463 REPORTER_ASSERT(reporter, 1 == releaseTestValue);
464 }
465
Brian Salomon26102cb2018-03-09 09:33:19 -0500466 gpu->deleteTestingOnlyBackendTexture(backendTex);
Greg Daniel4684f822018-03-08 15:27:36 -0500467 }
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500468}
469
Chris Dalton706a6ff2017-11-29 22:01:06 -0700470#endif