From adbe1328789071d1f742023edd93b6948eed9470 Mon Sep 17 00:00:00 2001 From: Robert Phillips Date: Wed, 17 Jan 2018 13:35:46 -0500 Subject: Remove GrSurfaceProxy::MakeWrapped (take 2) TBR=bsalomon@google.com Change-Id: I26fd911da502fb00addacb8b2c1a263efc5aa4ec Reviewed-on: https://skia-review.googlesource.com/95881 Commit-Queue: Robert Phillips Reviewed-by: Greg Daniel --- src/gpu/GrProxyProvider.cpp | 55 +++++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 19 deletions(-) (limited to 'src/gpu/GrProxyProvider.cpp') diff --git a/src/gpu/GrProxyProvider.cpp b/src/gpu/GrProxyProvider.cpp index bf5caeb26a..f60fc3eba6 100644 --- a/src/gpu/GrProxyProvider.cpp +++ b/src/gpu/GrProxyProvider.cpp @@ -40,11 +40,11 @@ GrProxyProvider::~GrProxyProvider() { SkASSERT(!fUniquelyKeyedProxies.count()); } -void GrProxyProvider::assignUniqueKeyToProxy(const GrUniqueKey& key, GrTextureProxy* proxy) { +bool GrProxyProvider::assignUniqueKeyToProxy(const GrUniqueKey& key, GrTextureProxy* proxy) { ASSERT_SINGLE_OWNER SkASSERT(key.isValid()); if (this->isAbandoned() || !proxy) { - return; + return false; } // If there is already a GrResource with this key then the caller has violated the normal @@ -59,7 +59,7 @@ void GrProxyProvider::assignUniqueKeyToProxy(const GrUniqueKey& key, GrTexturePr if (SkBudgeted::kNo == proxy->isBudgeted() && (!proxy->priv().isInstantiated() || !proxy->priv().peekSurface()->resourcePriv().refsWrappedObjects())) { - return; + return false; } SkASSERT(!fUniquelyKeyedProxies.find(key)); // multiple proxies can't get the same key @@ -67,6 +67,7 @@ void GrProxyProvider::assignUniqueKeyToProxy(const GrUniqueKey& key, GrTexturePr proxy->cacheAccess().setUniqueKey(this, key); SkASSERT(proxy->getUniqueKey() == key); fUniquelyKeyedProxies.add(proxy); + return true; } void GrProxyProvider::adoptUniqueKeyFromSurface(GrTextureProxy* proxy, const GrSurface* surf) { @@ -101,6 +102,20 @@ sk_sp GrProxyProvider::findProxyByUniqueKey(const GrUniqueKey& k return result; } +sk_sp GrProxyProvider::createWrapped(sk_sp tex, GrSurfaceOrigin origin) { +#ifdef SK_DEBUG + if (tex->getUniqueKey().isValid()) { + SkASSERT(!this->findProxyByUniqueKey(tex->getUniqueKey(), origin)); + } +#endif + + if (tex->asRenderTarget()) { + return sk_sp(new GrTextureRenderTargetProxy(std::move(tex), origin)); + } else { + return sk_sp(new GrTextureProxy(std::move(tex), origin)); + } +} + sk_sp GrProxyProvider::findOrCreateProxyByUniqueKey(const GrUniqueKey& key, GrSurfaceOrigin origin) { ASSERT_SINGLE_OWNER @@ -122,9 +137,9 @@ sk_sp GrProxyProvider::findOrCreateProxyByUniqueKey(const GrUniq sk_sp texture(static_cast(resource)->asTexture()); SkASSERT(texture); - result = GrSurfaceProxy::MakeWrapped(std::move(texture), origin); + result = this->createWrapped(std::move(texture), origin); SkASSERT(result->getUniqueKey() == key); - // MakeWrapped should've added this for us + // createWrapped should've added this for us SkASSERT(fUniquelyKeyedProxies.find(key)); return result; } @@ -144,13 +159,7 @@ sk_sp GrProxyProvider::createInstantiatedProxy(const GrSurfaceDe return nullptr; } - SkASSERT(!tex->getUniqueKey().isValid()); - - if (tex->asRenderTarget()) { - return sk_sp(new GrTextureRenderTargetProxy(std::move(tex), desc.fOrigin)); - } - - return sk_sp(new GrTextureProxy(std::move(tex), desc.fOrigin)); + return this->createWrapped(std::move(tex), desc.fOrigin); } sk_sp GrProxyProvider::createTextureProxy(const GrSurfaceDesc& desc, @@ -170,7 +179,7 @@ sk_sp GrProxyProvider::createTextureProxy(const GrSurfaceDesc& d return nullptr; } - return GrSurfaceProxy::MakeWrapped(std::move(tex), desc.fOrigin); + return this->createWrapped(std::move(tex), desc.fOrigin); } return this->createProxy(desc, SkBackingFit::kExact, budgeted); @@ -225,7 +234,7 @@ sk_sp GrProxyProvider::createMipMapProxy( return nullptr; } - return GrSurfaceProxy::MakeWrapped(std::move(tex), desc.fOrigin); + return this->createWrapped(std::move(tex), desc.fOrigin); } sk_sp GrProxyProvider::createMipMapProxy(const GrSurfaceDesc& desc, @@ -310,19 +319,27 @@ sk_sp GrProxyProvider::createProxy(const GrSurfaceDesc& desc, #endif } -sk_sp GrProxyProvider::createWrappedTextureProxy(const GrBackendTexture& backendTex, - GrSurfaceOrigin origin) { +sk_sp GrProxyProvider::createWrappedTextureProxy( + const GrBackendTexture& backendTex, + GrSurfaceOrigin origin, + GrWrapOwnership ownership, + ReleaseProc releaseProc, + ReleaseContext releaseCtx) { if (this->isAbandoned()) { return nullptr; } - sk_sp texture(fResourceProvider->wrapBackendTexture(backendTex)); + sk_sp texture(fResourceProvider->wrapBackendTexture(backendTex, ownership)); if (!texture) { return nullptr; } + if (releaseProc) { + texture->setRelease(releaseProc, releaseCtx); + } + SkASSERT(!texture->asRenderTarget()); // Strictly a GrTexture - return GrSurfaceProxy::MakeWrapped(std::move(texture), origin); + return this->createWrapped(std::move(texture), origin); } sk_sp GrProxyProvider::createWrappedTextureProxy(const GrBackendTexture& tex, @@ -338,7 +355,7 @@ sk_sp GrProxyProvider::createWrappedTextureProxy(const GrBackend } SkASSERT(texture->asRenderTarget()); // A GrTextureRenderTarget - return GrSurfaceProxy::MakeWrapped(std::move(texture), origin); + return this->createWrapped(std::move(texture), origin); } sk_sp GrProxyProvider::createWrappedRenderTargetProxy( -- cgit v1.2.3