From 94a6ce84ece51ff1c46c698753716f3f47585742 Mon Sep 17 00:00:00 2001 From: Greg Daniel Date: Tue, 16 Jan 2018 16:14:41 -0500 Subject: Add ability for lazy proxy callback to free captured resources This will be needed for DDLs that get recorded, but then deleted before the proxies actually get instantiated. Bug: skia: Change-Id: I745366fc7a7edbcd43bc617220d3d4997baa8319 Reviewed-on: https://skia-review.googlesource.com/95101 Reviewed-by: Robert Phillips Commit-Queue: Greg Daniel --- tests/LazyProxyTest.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'tests/LazyProxyTest.cpp') diff --git a/tests/LazyProxyTest.cpp b/tests/LazyProxyTest.cpp index a55593134d..1fe4fc4cb0 100644 --- a/tests/LazyProxyTest.cpp +++ b/tests/LazyProxyTest.cpp @@ -15,6 +15,7 @@ #include "GrRenderTargetContext.h" #include "GrRenderTargetContextPriv.h" #include "GrSurfaceProxy.h" +#include "GrSurfaceProxyPriv.h" #include "GrTexture.h" #include "GrTextureProxy.h" #include "GrTextureProxyPriv.h" @@ -187,4 +188,40 @@ DEF_GPUTEST(LazyProxyTest, reporter, /* options */) { } } +DEF_GPUTEST(LazyProxyReleaseTest, reporter, /* options */) { + GrMockOptions mockOptions; + sk_sp ctx = GrContext::MakeMock(&mockOptions, GrContextOptions()); + + GrSurfaceDesc desc; + desc.fWidth = 16; + desc.fHeight = 16; + desc.fConfig = kRGBA_8888_GrPixelConfig; + + for (bool doInstantiate : {true, false}) { + int testCount = 0; + int* testCountPtr = &testCount; + sk_sp proxy = GrSurfaceProxy::MakeLazy( + [testCountPtr](GrResourceProvider* resourceProvider, GrSurfaceOrigin* outOrigin) { + if (!resourceProvider) { + *testCountPtr = -1; + return sk_sp(); + } + *testCountPtr = 1; + return sk_sp(); + }, desc, GrMipMapped::kNo, SkBackingFit::kExact, SkBudgeted::kNo); + + REPORTER_ASSERT(reporter, 0 == testCount); + + 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); + } + } +} + #endif -- cgit v1.2.3