diff options
-rw-r--r-- | include/private/GrSurfaceProxy.h | 4 | ||||
-rw-r--r-- | src/gpu/GrSurfaceProxy.cpp | 5 | ||||
-rw-r--r-- | src/gpu/ccpr/GrCoverageCountingPathRenderer.cpp | 3 | ||||
-rw-r--r-- | tests/LazyProxyTest.cpp | 37 |
4 files changed, 49 insertions, 0 deletions
diff --git a/include/private/GrSurfaceProxy.h b/include/private/GrSurfaceProxy.h index 5a2a4b536e..cc12fcb010 100644 --- a/include/private/GrSurfaceProxy.h +++ b/include/private/GrSurfaceProxy.h @@ -198,6 +198,10 @@ public: * (Stencil is not supported by this method.) The width and height must either both be greater * than 0 or both less than or equal to zero. A non-positive value is a signal that the width * and height are currently unknown. + * + * When called, the callback must be able to cleanup any resources that it captured at creation. + * It also must support being passed in a null GrResourceProvider. When this happens, the + * callback should cleanup any resources it captured and return an empty sk_sp<GrTextureProxy>. * DDL TODO: remove this entry point */ static sk_sp<GrTextureProxy> MakeLazy(LazyInstantiateCallback&&, const GrSurfaceDesc& desc, diff --git a/src/gpu/GrSurfaceProxy.cpp b/src/gpu/GrSurfaceProxy.cpp index c9da6ce592..0408b79c91 100644 --- a/src/gpu/GrSurfaceProxy.cpp +++ b/src/gpu/GrSurfaceProxy.cpp @@ -83,6 +83,11 @@ GrSurfaceProxy::GrSurfaceProxy(sk_sp<GrSurface> surface, GrSurfaceOrigin origin, } GrSurfaceProxy::~GrSurfaceProxy() { + if (fLazyInstantiateCallback) { + // We have an uninstantiated lazy proxy. Call fLazyInstantiateCallback with a nullptr for + // the GrResourceProvider to signal the callback should clean itself up. + this->fLazyInstantiateCallback(nullptr, nullptr); + } // For this to be deleted the opList that held a ref on it (if there was one) must have been // deleted. Which would have cleared out this back pointer. SkASSERT(!fLastOpList); diff --git a/src/gpu/ccpr/GrCoverageCountingPathRenderer.cpp b/src/gpu/ccpr/GrCoverageCountingPathRenderer.cpp index 67098ccb9b..1e0bb29acd 100644 --- a/src/gpu/ccpr/GrCoverageCountingPathRenderer.cpp +++ b/src/gpu/ccpr/GrCoverageCountingPathRenderer.cpp @@ -227,6 +227,9 @@ void CCPR::ClipPath::init(const SkPath& deviceSpacePath, const SkIRect& accessRe fAtlasLazyProxy = GrSurfaceProxy::MakeFullyLazy( [this](GrResourceProvider* resourceProvider, GrSurfaceOrigin* outOrigin) { + if (!resourceProvider) { + return sk_sp<GrTexture>(); + } SkASSERT(fHasAtlas); SkASSERT(!fHasAtlasTransform); 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<GrContext> 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<GrTextureProxy> proxy = GrSurfaceProxy::MakeLazy( + [testCountPtr](GrResourceProvider* resourceProvider, GrSurfaceOrigin* outOrigin) { + if (!resourceProvider) { + *testCountPtr = -1; + return sk_sp<GrTexture>(); + } + *testCountPtr = 1; + return sk_sp<GrTexture>(); + }, 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 |