From 457469c7a0c879b9d8ff8ed9fabe3f3dcab06097 Mon Sep 17 00:00:00 2001 From: Greg Daniel Date: Thu, 8 Feb 2018 15:05:44 -0500 Subject: Make non-ddl lazy proxys clean-up and delete their callbacks immediately after instanstation. This makes sure resources are released and free'd as soon as possible if we no longer need them. Bug: skia: Change-Id: Ic216987649c54183f8cbbff90a633860a97754b3 Reviewed-on: https://skia-review.googlesource.com/105721 Commit-Queue: Greg Daniel Reviewed-by: Robert Phillips --- tests/LazyProxyTest.cpp | 51 +++++++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 19 deletions(-) (limited to 'tests/LazyProxyTest.cpp') diff --git a/tests/LazyProxyTest.cpp b/tests/LazyProxyTest.cpp index 1994eeb5c9..5a0211d717 100644 --- a/tests/LazyProxyTest.cpp +++ b/tests/LazyProxyTest.cpp @@ -213,29 +213,42 @@ DEF_GPUTEST(LazyProxyReleaseTest, reporter, /* options */) { desc.fHeight = kSize; desc.fConfig = kRGBA_8888_GrPixelConfig; + using LazyInstantiationType = GrSurfaceProxy::LazyInstantiationType; for (bool doInstantiate : {true, false}) { - int testCount = 0; - int* testCountPtr = &testCount; - sk_sp proxy = proxyProvider->createLazyProxy( - [testCountPtr](GrResourceProvider* resourceProvider, GrSurfaceOrigin* outOrigin) { - if (!resourceProvider) { - *testCountPtr = -1; + for (auto lazyType : {LazyInstantiationType::kSingleUse, + LazyInstantiationType::kMultipleUse}) { + int testCount = 0; + int* testCountPtr = &testCount; + sk_sp proxy = proxyProvider->createLazyProxy( + [testCountPtr](GrResourceProvider* resourceProvider, + GrSurfaceOrigin* /*outOrigin*/) { + if (!resourceProvider) { + *testCountPtr = -1; + return sk_sp(); + } + *testCountPtr = 1; return sk_sp(); - } - *testCountPtr = 1; - return sk_sp(); - }, desc, GrMipMapped::kNo, SkBackingFit::kExact, SkBudgeted::kNo); + }, desc, GrMipMapped::kNo, SkBackingFit::kExact, SkBudgeted::kNo); - REPORTER_ASSERT(reporter, 0 == testCount); + proxy->priv().testingOnly_setLazyInstantiationType(lazyType); - if (doInstantiate) { - proxy->priv().doLazyInstantiation(ctx->contextPriv().resourceProvider()); - REPORTER_ASSERT(reporter, 1 == testCount); - proxy.reset(); - REPORTER_ASSERT(reporter, -1 == testCount); - } else { - proxy.reset(); - REPORTER_ASSERT(reporter, -1 == testCount); + REPORTER_ASSERT(reporter, 0 == testCount); + + if (doInstantiate) { + proxy->priv().doLazyInstantiation(ctx->contextPriv().resourceProvider()); + if (LazyInstantiationType::kSingleUse == proxy->priv().lazyInstantiationType()) { + // In SingleUse we will call the cleanup and delete the callback in the + // doLazyInstantiationCall. + REPORTER_ASSERT(reporter, -1 == testCount); + } else { + REPORTER_ASSERT(reporter, 1 == testCount); + } + proxy.reset(); + REPORTER_ASSERT(reporter, -1 == testCount); + } else { + proxy.reset(); + REPORTER_ASSERT(reporter, -1 == testCount); + } } } } -- cgit v1.2.3