Add ability to remove unique key from proxy and underlying surface.

Bug: skia:
Change-Id: I66b891ce9ca35906fdbddb36f565b35b25825112
Reviewed-on: https://skia-review.googlesource.com/51240
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
diff --git a/src/gpu/GrResourceCache.h b/src/gpu/GrResourceCache.h
index 96323be..771196c 100644
--- a/src/gpu/GrResourceCache.h
+++ b/src/gpu/GrResourceCache.h
@@ -160,8 +160,9 @@
     ///////////////////////////////////////////////////////////////////////////
     // TextureProxies & GrUniqueKeys
     //
-    // The two GrResourceCache methods assignUniqueKeyToProxy and findProxyByUniqueKey drive
-    // the behavior of uniqueKeys on proxies.
+    // The four GrResourceCache methods assignUniqueKeyToProxy, adoptUniqueKeyFromSurface,
+    // findPorxyByUniqueKey, and findOrCreateProxyByUniqueKey drive the behavior of uniqueKeys on
+    // proxies.
     //
     // assignUniqueKeyToProxy does the following:
     //    if the proxy is wrapped, it sets the texture & proxy keys & adds the proxy to the hash
@@ -174,8 +175,16 @@
     //    determines that the key will never be used again but, in that case, the proxy should
     //    never receive another key.
     //
+    // adoptUniqueKeyFromSurface does the following:
+    //    takes in a GrSurface which must have a valid unique key. It sets the proxy's key to match
+    //    the surface and adds the proxy to the hash.
+    //
     // findProxyByUniqueKey does the following:
-    //    first looks in the UniqueKeyProxy hash table to see if there is already a proxy w/ the key
+    //    looks in the UniqueKeyProxy hash table to see if there is already a proxy w/ the key and
+    //    returns the proxy. If it fails it will return null.
+    //
+    // findOrCreateProxyByUniqueKey does the following:
+    //    first calls findProxyByUniqueKey to see if a proxy already exists with the key
     //    failing that it looks in the ResourceCache to see there is a texture with that key
     //       if so, it will wrap the texture in a proxy, add the proxy to the hash and return it
     //    failing that it will return null
@@ -185,12 +194,26 @@
      */
     void assignUniqueKeyToProxy(const GrUniqueKey&, GrTextureProxy*);
 
+    /*
+     * Sets the unique key of the provided proxy to the unique key of the surface. The surface must
+     * have a valid unique key.
+     */
+    void adoptUniqueKeyFromSurface(GrTextureProxy* proxy, const GrSurface*);
+
     /**
-     * Find a texture proxy that is associated with the provided unique key.
+     * Find a texture proxy that is associated with the provided unique key. It will not look for a
+     * GrSurface that has the unique key.
      */
     sk_sp<GrTextureProxy> findProxyByUniqueKey(const GrUniqueKey&, GrSurfaceOrigin);
 
     /**
+     * Find a texture proxy that is associated with the provided unique key. If not proxy is found,
+     * try to find a resources that is associated with the unique key and create a proxy that wraps
+     * it.
+     */
+    sk_sp<GrTextureProxy> findOrCreateProxyByUniqueKey(const GrUniqueKey&, GrSurfaceOrigin);
+
+    /**
      * Either the proxy attached to the unique key is being deleted (in which case we
      * don't want it cluttering up the hash table) or the client has indicated that
      * it will never refer to the unique key again. In either case, remove the key
@@ -200,6 +223,13 @@
     void processInvalidProxyUniqueKey(const GrUniqueKey&);
 
     /**
+     * Same as above, but you must pass in a GrTextureProxy to save having to search for it. The
+     * GrUniqueKey of the proxy must be valid and it must match the passed in key. This function
+     * also gives the option to invalidate the GrUniqueKey on the underlying GrTexture.
+     */
+    void processInvalidProxyUniqueKey(const GrUniqueKey&, GrTextureProxy*, bool invalidateSurface);
+
+    /**
      * Query whether a unique key exists in the cache.
      */
     bool hasUniqueKey(const GrUniqueKey& key) const {