From f7cf81aefd28e5bfe74d40b4fc037df72f157f33 Mon Sep 17 00:00:00 2001 From: Robert Phillips Date: Thu, 2 Mar 2017 10:23:52 -0500 Subject: [PATCH] Use GrTextureProvider's uniqueKey setting method rather than directly setting it Clients will not be able to directly set the uniqueKey on GrTextureProxies. This CL sets up the choke point for the switch over to having uniqueKeys be managed by a third party (the textureProvider). Change-Id: I5061a970faf77ea0c4a320e021ff7c3ef90a0900 Reviewed-on: https://skia-review.googlesource.com/9140 Reviewed-by: Brian Salomon Commit-Queue: Robert Phillips --- include/gpu/GrTextureProvider.h | 1 + src/core/SkImageCacherator.cpp | 11 ++++++----- src/gpu/GrBitmapTextureMaker.cpp | 2 +- src/gpu/GrClipStackClip.cpp | 4 ++-- src/gpu/GrResourceProvider.cpp | 2 +- src/gpu/GrSoftwarePathRenderer.cpp | 4 ++-- src/gpu/GrTextureAdjuster.cpp | 2 +- src/gpu/SkGr.cpp | 2 +- 8 files changed, 15 insertions(+), 13 deletions(-) diff --git a/include/gpu/GrTextureProvider.h b/include/gpu/GrTextureProvider.h index b8d1856..dd139cc 100644 --- a/include/gpu/GrTextureProvider.h +++ b/include/gpu/GrTextureProvider.h @@ -51,6 +51,7 @@ public: /** Assigns a unique key to the texture. The texture will be findable via this key using findTextureByUniqueKey(). If an existing texture has this key, it's key will be removed. */ void assignUniqueKeyToTexture(const GrUniqueKey& key, GrTexture* texture) { + SkASSERT(key.isValid()); this->assignUniqueKeyToResource(key, texture); } diff --git a/src/core/SkImageCacherator.cpp b/src/core/SkImageCacherator.cpp index e971883..f36af3f 100644 --- a/src/core/SkImageCacherator.cpp +++ b/src/core/SkImageCacherator.cpp @@ -474,9 +474,10 @@ public: } }; -static GrTexture* set_key_and_return(GrTexture* tex, const GrUniqueKey& key) { +static GrTexture* set_key_and_return(GrTextureProvider* texProvider, + GrTexture* tex, const GrUniqueKey& key) { if (key.isValid()) { - tex->resourcePriv().setUniqueKey(key); + texProvider->assignUniqueKeyToTexture(key, tex); } return tex; } @@ -543,7 +544,7 @@ GrTexture* SkImageCacherator::lockTexture(GrContext* ctx, const GrUniqueKey& ori if (GrTexture* tex = generator->generateTexture(ctx, cacheInfo, fOrigin)) { SK_HISTOGRAM_ENUMERATION("LockTexturePath", kNative_LockTexturePath, kLockTexturePathCount); - return set_key_and_return(tex, key); + return set_key_and_return(ctx->textureProvider(), tex, key); } } @@ -570,7 +571,7 @@ GrTexture* SkImageCacherator::lockTexture(GrContext* ctx, const GrUniqueKey& ori if (tex) { SK_HISTOGRAM_ENUMERATION("LockTexturePath", kYUV_LockTexturePath, kLockTexturePathCount); - return set_key_and_return(tex.release(), key); + return set_key_and_return(ctx->textureProvider(), tex.release(), key); } } @@ -587,7 +588,7 @@ GrTexture* SkImageCacherator::lockTexture(GrContext* ctx, const GrUniqueKey& ori if (tex) { SK_HISTOGRAM_ENUMERATION("LockTexturePath", kRGBA_LockTexturePath, kLockTexturePathCount); - return set_key_and_return(tex, key); + return set_key_and_return(ctx->textureProvider(), tex, key); } } SK_HISTOGRAM_ENUMERATION("LockTexturePath", kFailure_LockTexturePath, diff --git a/src/gpu/GrBitmapTextureMaker.cpp b/src/gpu/GrBitmapTextureMaker.cpp index e4ea772..9d577cd 100644 --- a/src/gpu/GrBitmapTextureMaker.cpp +++ b/src/gpu/GrBitmapTextureMaker.cpp @@ -43,7 +43,7 @@ GrTexture* GrBitmapTextureMaker::refOriginalTexture(bool willBeMipped, tex = GrUploadBitmapToTexture(this->context(), fBitmap); } if (tex && fOriginalKey.isValid()) { - tex->resourcePriv().setUniqueKey(fOriginalKey); + this->context()->textureProvider()->assignUniqueKeyToTexture(fOriginalKey, tex); GrInstallBitmapUniqueKeyInvalidator(fOriginalKey, fBitmap.pixelRef()); } return tex; diff --git a/src/gpu/GrClipStackClip.cpp b/src/gpu/GrClipStackClip.cpp index 0b3089b..c69f79e 100644 --- a/src/gpu/GrClipStackClip.cpp +++ b/src/gpu/GrClipStackClip.cpp @@ -446,7 +446,7 @@ sk_sp GrClipStackClip::createAlphaClipMask(GrContext* context, return nullptr; } - tex->resourcePriv().setUniqueKey(key); + context->textureProvider()->assignUniqueKeyToTexture(key, tex); add_invalidate_on_pop_message(*fStack, reducedClip.elementsGenID(), key); return result; @@ -522,7 +522,7 @@ sk_sp GrClipStackClip::createSoftwareClipMask( return nullptr; } - tex->resourcePriv().setUniqueKey(key); + context->textureProvider()->assignUniqueKeyToTexture(key, tex); add_invalidate_on_pop_message(*fStack, reducedClip.elementsGenID(), key); return result; } diff --git a/src/gpu/GrResourceProvider.cpp b/src/gpu/GrResourceProvider.cpp index deb400c..272c6a6 100644 --- a/src/gpu/GrResourceProvider.cpp +++ b/src/gpu/GrResourceProvider.cpp @@ -161,7 +161,7 @@ GrStencilAttachment* GrResourceProvider::attachStencilAttachment(GrRenderTarget* // Need to try and create a new stencil stencil = this->gpu()->createStencilAttachmentForRenderTarget(rt, width, height); if (stencil) { - stencil->resourcePriv().setUniqueKey(sbKey); + this->assignUniqueKeyToResource(sbKey, stencil); newStencil = true; } } diff --git a/src/gpu/GrSoftwarePathRenderer.cpp b/src/gpu/GrSoftwarePathRenderer.cpp index 5ed9f42..b51ce63 100644 --- a/src/gpu/GrSoftwarePathRenderer.cpp +++ b/src/gpu/GrSoftwarePathRenderer.cpp @@ -206,7 +206,7 @@ bool GrSoftwarePathRenderer::onDrawPath(const DrawPathArgs& args) { sk_sp texture; if (useCache) { - texture.reset(args.fContext->textureProvider()->findAndRefTextureByUniqueKey(maskKey)); + texture.reset(fTexProvider->findAndRefTextureByUniqueKey(maskKey)); } if (!texture) { SkBackingFit fit = useCache ? SkBackingFit::kExact : SkBackingFit::kApprox; @@ -219,7 +219,7 @@ bool GrSoftwarePathRenderer::onDrawPath(const DrawPathArgs& args) { return false; } if (useCache) { - texture->resourcePriv().setUniqueKey(maskKey); + fTexProvider->assignUniqueKeyToTexture(maskKey, texture.get()); } } if (inverseFilled) { diff --git a/src/gpu/GrTextureAdjuster.cpp b/src/gpu/GrTextureAdjuster.cpp index 2fa5241..0c9c23e 100644 --- a/src/gpu/GrTextureAdjuster.cpp +++ b/src/gpu/GrTextureAdjuster.cpp @@ -56,7 +56,7 @@ GrTexture* GrTextureAdjuster::refCopy(const CopyParams& copyParams) { GrTexture* copy = CopyOnGpu(texture, contentArea, copyParams); if (copy) { if (key.isValid()) { - copy->resourcePriv().setUniqueKey(key); + context->textureProvider()->assignUniqueKeyToTexture(key, copy); this->didCacheCopy(key); } } diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp index fe7e98c..b685723 100644 --- a/src/gpu/SkGr.cpp +++ b/src/gpu/SkGr.cpp @@ -288,7 +288,7 @@ sk_sp GrMakeCachedBitmapProxy(GrContext* context, const SkBitmap if (!tex) { tex.reset(GrUploadBitmapToTexture(context, bitmap)); if (tex && originalKey.isValid()) { - tex->resourcePriv().setUniqueKey(originalKey); + context->textureProvider()->assignUniqueKeyToTexture(originalKey, tex.get()); GrInstallBitmapUniqueKeyInvalidator(originalKey, bitmap.pixelRef()); } } -- 2.7.4