Use GrTextureProvider's uniqueKey setting method rather than directly setting it
authorRobert Phillips <robertphillips@google.com>
Thu, 2 Mar 2017 15:23:52 +0000 (10:23 -0500)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Thu, 2 Mar 2017 16:12:35 +0000 (16:12 +0000)
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 <bsalomon@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>

include/gpu/GrTextureProvider.h
src/core/SkImageCacherator.cpp
src/gpu/GrBitmapTextureMaker.cpp
src/gpu/GrClipStackClip.cpp
src/gpu/GrResourceProvider.cpp
src/gpu/GrSoftwarePathRenderer.cpp
src/gpu/GrTextureAdjuster.cpp
src/gpu/SkGr.cpp

index b8d1856..dd139cc 100644 (file)
@@ -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);
     }
 
index e971883..f36af3f 100644 (file)
@@ -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,
index e4ea772..9d577cd 100644 (file)
@@ -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;
index 0b3089b..c69f79e 100644 (file)
@@ -446,7 +446,7 @@ sk_sp<GrTextureProxy> 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<GrTextureProxy> GrClipStackClip::createSoftwareClipMask(
         return nullptr;
     }
 
-    tex->resourcePriv().setUniqueKey(key);
+    context->textureProvider()->assignUniqueKeyToTexture(key, tex);
     add_invalidate_on_pop_message(*fStack, reducedClip.elementsGenID(), key);
     return result;
 }
index deb400c..272c6a6 100644 (file)
@@ -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;
             }
         }
index 5ed9f42..b51ce63 100644 (file)
@@ -206,7 +206,7 @@ bool GrSoftwarePathRenderer::onDrawPath(const DrawPathArgs& args) {
 
     sk_sp<GrTexture> 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) {
index 2fa5241..0c9c23e 100644 (file)
@@ -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);
         }
     }
index fe7e98c..b685723 100644 (file)
@@ -288,7 +288,7 @@ sk_sp<GrTextureProxy> 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());
         }
     }