Consolidate Proxy caching code in GrResourceProvider

This doesn't implement the GrSurfaceProxy-based caching but just carves out a space for it.

Split out of: https://skia-review.googlesource.com/c/8823/ (Remove GrFragmentProcessor-derived class' GrTexture-based ctors)

Change-Id: Iec87b45e3264b349d7804f63e361e970b925e335
Reviewed-on: https://skia-review.googlesource.com/9626
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
diff --git a/src/gpu/GrClipStackClip.cpp b/src/gpu/GrClipStackClip.cpp
index b2dd936..d44373f 100644
--- a/src/gpu/GrClipStackClip.cpp
+++ b/src/gpu/GrClipStackClip.cpp
@@ -380,16 +380,15 @@
     SkDEBUGFAIL("Gen ID was not found in stack.");
 }
 
-// MDB TODO (caching): this side-steps the issue of texture proxies cached by unique ID
 sk_sp<GrTextureProxy> GrClipStackClip::createAlphaClipMask(GrContext* context,
                                                            const GrReducedClip& reducedClip) const {
     GrResourceProvider* resourceProvider = context->resourceProvider();
     GrUniqueKey key;
     create_clip_mask_key(reducedClip.elementsGenID(), reducedClip.ibounds(), &key);
 
-    sk_sp<GrTexture> texture(resourceProvider->findAndRefTextureByUniqueKey(key));
-    if (texture) {
-        return GrSurfaceProxy::MakeWrapped(std::move(texture));
+    sk_sp<GrTextureProxy> proxy(resourceProvider->findProxyByUniqueKey(key));
+    if (proxy) {
+        return proxy;
     }
 
     sk_sp<GrRenderTargetContext> rtc(context->makeRenderTargetContextWithFallback(
@@ -411,27 +410,22 @@
         return nullptr;
     }
 
-    GrTexture* tex = result->instantiate(context->resourceProvider());
-    if (!tex) {
-        return nullptr;
-    }
-
-    context->resourceProvider()->assignUniqueKeyToTexture(key, tex);
+    resourceProvider->assignUniqueKeyToProxy(key, result.get());
+    // MDB TODO (caching): this has to play nice with the GrSurfaceProxy's caching
     add_invalidate_on_pop_message(*fStack, reducedClip.elementsGenID(), key);
 
     return result;
 }
 
-// MDB TODO (caching): This side-steps the caching of texture proxies by unique ID
 sk_sp<GrTextureProxy> GrClipStackClip::createSoftwareClipMask(
                                                           GrContext* context,
                                                           const GrReducedClip& reducedClip) const {
     GrUniqueKey key;
     create_clip_mask_key(reducedClip.elementsGenID(), reducedClip.ibounds(), &key);
 
-    sk_sp<GrTexture> texture(context->resourceProvider()->findAndRefTextureByUniqueKey(key));
-    if (texture) {
-        return GrSurfaceProxy::MakeWrapped(std::move(texture));
+    sk_sp<GrTextureProxy> proxy(context->resourceProvider()->findProxyByUniqueKey(key));
+    if (proxy) {
+        return proxy;
     }
 
     // The mask texture may be larger than necessary. We round out the clip bounds and pin the top
@@ -485,14 +479,10 @@
         }
     }
 
-    sk_sp<GrTextureProxy> result(helper.toTexture(context, SkBackingFit::kApprox));
+    sk_sp<GrTextureProxy> result(helper.toTextureProxy(context, SkBackingFit::kApprox));
 
-    GrTexture* tex = result->instantiate(context->resourceProvider());
-    if (!tex) {
-        return nullptr;
-    }
-
-    context->resourceProvider()->assignUniqueKeyToTexture(key, tex);
+    context->resourceProvider()->assignUniqueKeyToProxy(key, result.get());
+    // MDB TODO (caching): this has to play nice with the GrSurfaceProxy's caching
     add_invalidate_on_pop_message(*fStack, reducedClip.elementsGenID(), key);
     return result;
 }