Revert "Remove GrSurfaceProxy::MakeWrapped"

This reverts commit 2ac5868f4a695b30777c7c57ffd493fed0fa597b.

Reason for revert: Breaking Android
Original change's description:
> Remove GrSurfaceProxy::MakeWrapped
> 
> Change-Id: Ic44cf1745dc3be21cbbaa1dc4ac85c8b1b21c6bb
> Reviewed-on: https://skia-review.googlesource.com/94101
> Commit-Queue: Robert Phillips <robertphillips@google.com>
> Reviewed-by: Greg Daniel <egdaniel@google.com>

TBR=egdaniel@google.com,robertphillips@google.com,brianosman@google.com

Change-Id: I312118106db1cf64fe959d36e65619a41d58e654
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/95860
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
diff --git a/include/private/GrSurfaceProxy.h b/include/private/GrSurfaceProxy.h
index 5fef077..55b30a5 100644
--- a/include/private/GrSurfaceProxy.h
+++ b/include/private/GrSurfaceProxy.h
@@ -182,6 +182,9 @@
 
 class GrSurfaceProxy : public GrIORefProxy {
 public:
+    // DDL TODO: remove this entry point
+    static sk_sp<GrTextureProxy> MakeWrapped(sk_sp<GrTexture>, GrSurfaceOrigin);
+
     enum class LazyState {
         kNot,       // The proxy has no lazy callback that must be made.
         kPartially, // The proxy has a lazy callback but knows basic information about itself.
diff --git a/src/gpu/GrProxyProvider.cpp b/src/gpu/GrProxyProvider.cpp
index f60fc3e..bf5caeb 100644
--- a/src/gpu/GrProxyProvider.cpp
+++ b/src/gpu/GrProxyProvider.cpp
@@ -40,11 +40,11 @@
     SkASSERT(!fUniquelyKeyedProxies.count());
 }
 
-bool GrProxyProvider::assignUniqueKeyToProxy(const GrUniqueKey& key, GrTextureProxy* proxy) {
+void GrProxyProvider::assignUniqueKeyToProxy(const GrUniqueKey& key, GrTextureProxy* proxy) {
     ASSERT_SINGLE_OWNER
     SkASSERT(key.isValid());
     if (this->isAbandoned() || !proxy) {
-        return false;
+        return;
     }
 
     // If there is already a GrResource with this key then the caller has violated the normal
@@ -59,7 +59,7 @@
     if (SkBudgeted::kNo == proxy->isBudgeted() &&
                     (!proxy->priv().isInstantiated() ||
                      !proxy->priv().peekSurface()->resourcePriv().refsWrappedObjects())) {
-        return false;
+        return;
     }
 
     SkASSERT(!fUniquelyKeyedProxies.find(key));     // multiple proxies can't get the same key
@@ -67,7 +67,6 @@
     proxy->cacheAccess().setUniqueKey(this, key);
     SkASSERT(proxy->getUniqueKey() == key);
     fUniquelyKeyedProxies.add(proxy);
-    return true;
 }
 
 void GrProxyProvider::adoptUniqueKeyFromSurface(GrTextureProxy* proxy, const GrSurface* surf) {
@@ -102,20 +101,6 @@
     return result;
 }
 
-sk_sp<GrTextureProxy> GrProxyProvider::createWrapped(sk_sp<GrTexture> tex, GrSurfaceOrigin origin) {
-#ifdef SK_DEBUG
-    if (tex->getUniqueKey().isValid()) {
-        SkASSERT(!this->findProxyByUniqueKey(tex->getUniqueKey(), origin));
-    }
-#endif
-
-    if (tex->asRenderTarget()) {
-        return sk_sp<GrTextureProxy>(new GrTextureRenderTargetProxy(std::move(tex), origin));
-    } else {
-        return sk_sp<GrTextureProxy>(new GrTextureProxy(std::move(tex), origin));
-    }
-}
-
 sk_sp<GrTextureProxy> GrProxyProvider::findOrCreateProxyByUniqueKey(const GrUniqueKey& key,
                                                                     GrSurfaceOrigin origin) {
     ASSERT_SINGLE_OWNER
@@ -137,9 +122,9 @@
     sk_sp<GrTexture> texture(static_cast<GrSurface*>(resource)->asTexture());
     SkASSERT(texture);
 
-    result = this->createWrapped(std::move(texture), origin);
+    result = GrSurfaceProxy::MakeWrapped(std::move(texture), origin);
     SkASSERT(result->getUniqueKey() == key);
-    // createWrapped should've added this for us
+    // MakeWrapped should've added this for us
     SkASSERT(fUniquelyKeyedProxies.find(key));
     return result;
 }
@@ -159,7 +144,13 @@
         return nullptr;
     }
 
-    return this->createWrapped(std::move(tex), desc.fOrigin);
+    SkASSERT(!tex->getUniqueKey().isValid());
+
+    if (tex->asRenderTarget()) {
+        return sk_sp<GrTextureProxy>(new GrTextureRenderTargetProxy(std::move(tex), desc.fOrigin));
+    }
+
+    return sk_sp<GrTextureProxy>(new GrTextureProxy(std::move(tex), desc.fOrigin));
 }
 
 sk_sp<GrTextureProxy> GrProxyProvider::createTextureProxy(const GrSurfaceDesc& desc,
@@ -179,7 +170,7 @@
             return nullptr;
         }
 
-        return this->createWrapped(std::move(tex), desc.fOrigin);
+        return GrSurfaceProxy::MakeWrapped(std::move(tex), desc.fOrigin);
     }
 
     return this->createProxy(desc, SkBackingFit::kExact, budgeted);
@@ -234,7 +225,7 @@
         return nullptr;
     }
 
-    return this->createWrapped(std::move(tex), desc.fOrigin);
+    return GrSurfaceProxy::MakeWrapped(std::move(tex), desc.fOrigin);
 }
 
 sk_sp<GrTextureProxy> GrProxyProvider::createMipMapProxy(const GrSurfaceDesc& desc,
@@ -319,27 +310,19 @@
 #endif
 }
 
-sk_sp<GrTextureProxy> GrProxyProvider::createWrappedTextureProxy(
-                                                         const GrBackendTexture& backendTex,
-                                                         GrSurfaceOrigin origin,
-                                                         GrWrapOwnership ownership,
-                                                         ReleaseProc releaseProc,
-                                                         ReleaseContext releaseCtx) {
+sk_sp<GrTextureProxy> GrProxyProvider::createWrappedTextureProxy(const GrBackendTexture& backendTex,
+                                                                 GrSurfaceOrigin origin) {
     if (this->isAbandoned()) {
         return nullptr;
     }
 
-    sk_sp<GrTexture> texture(fResourceProvider->wrapBackendTexture(backendTex, ownership));
+    sk_sp<GrTexture> texture(fResourceProvider->wrapBackendTexture(backendTex));
     if (!texture) {
         return nullptr;
     }
-    if (releaseProc) {
-        texture->setRelease(releaseProc, releaseCtx);
-    }
-
     SkASSERT(!texture->asRenderTarget());   // Strictly a GrTexture
 
-    return this->createWrapped(std::move(texture), origin);
+    return GrSurfaceProxy::MakeWrapped(std::move(texture), origin);
 }
 
 sk_sp<GrTextureProxy> GrProxyProvider::createWrappedTextureProxy(const GrBackendTexture& tex,
@@ -355,7 +338,7 @@
     }
     SkASSERT(texture->asRenderTarget());  // A GrTextureRenderTarget
 
-    return this->createWrapped(std::move(texture), origin);
+    return GrSurfaceProxy::MakeWrapped(std::move(texture), origin);
 }
 
 sk_sp<GrSurfaceProxy> GrProxyProvider::createWrappedRenderTargetProxy(
diff --git a/src/gpu/GrProxyProvider.h b/src/gpu/GrProxyProvider.h
index f2688aa..4c93886 100644
--- a/src/gpu/GrProxyProvider.h
+++ b/src/gpu/GrProxyProvider.h
@@ -32,7 +32,7 @@
      * Assigns a unique key to a proxy. The proxy will be findable via this key using
      * findProxyByUniqueKey(). It is an error if an existing proxy already has a key.
      */
-    bool assignUniqueKeyToProxy(const GrUniqueKey&, GrTextureProxy*);
+    void assignUniqueKeyToProxy(const GrUniqueKey&, GrTextureProxy*);
 
     /*
      * Sets the unique key of the provided proxy to the unique key of the surface. The surface must
@@ -102,17 +102,10 @@
     sk_sp<GrTextureProxy> createProxy(const GrSurfaceDesc&, SkBackingFit, SkBudgeted,
                                       uint32_t flags = 0);
 
-    // These match the definitions in SkImage & GrTexture.h, for whence they came
-    typedef void* ReleaseContext;
-    typedef void (*ReleaseProc)(ReleaseContext);
-
     /*
      * Create a texture proxy that wraps a (non-renderable) backend texture.
      */
-    sk_sp<GrTextureProxy> createWrappedTextureProxy(const GrBackendTexture&, GrSurfaceOrigin,
-                                                    GrWrapOwnership = kBorrow_GrWrapOwnership,
-                                                    ReleaseProc = nullptr,
-                                                    ReleaseContext = nullptr);
+    sk_sp<GrTextureProxy> createWrappedTextureProxy(const GrBackendTexture&, GrSurfaceOrigin);
 
     /*
      * Create a texture proxy that wraps a backend texture and is both texture-able and renderable
@@ -195,8 +188,6 @@
     void removeAllUniqueKeys();
 
 private:
-    sk_sp<GrTextureProxy> createWrapped(sk_sp<GrTexture> tex, GrSurfaceOrigin origin);
-
     struct UniquelyKeyedProxyHashTraits {
         static const GrUniqueKey& GetKey(const GrTextureProxy& p) { return p.getUniqueKey(); }
 
diff --git a/src/gpu/GrSurfaceProxy.cpp b/src/gpu/GrSurfaceProxy.cpp
index 9dadaca..828b936 100644
--- a/src/gpu/GrSurfaceProxy.cpp
+++ b/src/gpu/GrSurfaceProxy.cpp
@@ -228,6 +228,28 @@
     return fLastOpList ? fLastOpList->asTextureOpList() : nullptr;
 }
 
+sk_sp<GrTextureProxy> GrSurfaceProxy::MakeWrapped(sk_sp<GrTexture> tex, GrSurfaceOrigin origin) {
+    if (!tex) {
+        return nullptr;
+    }
+
+    if (tex->getUniqueKey().isValid()) {
+        // The proxy may already be in the hash. Thus we need to look for it first before creating
+        // new one.
+        GrProxyProvider* provider = tex->getContext()->contextPriv().proxyProvider();
+        sk_sp<GrTextureProxy> proxy = provider->findProxyByUniqueKey(tex->getUniqueKey(), origin);
+        if (proxy) {
+            return proxy;
+        }
+    }
+
+    if (tex->asRenderTarget()) {
+        return sk_sp<GrTextureProxy>(new GrTextureRenderTargetProxy(std::move(tex), origin));
+    } else {
+        return sk_sp<GrTextureProxy>(new GrTextureProxy(std::move(tex), origin));
+    }
+}
+
 int GrSurfaceProxy::worstCaseWidth() const {
     SkASSERT(LazyState::kFully != this->lazyInstantiationState());
     if (fTarget) {
diff --git a/src/gpu/GrTextureProxy.cpp b/src/gpu/GrTextureProxy.cpp
index 03b8108..9eca5d9 100644
--- a/src/gpu/GrTextureProxy.cpp
+++ b/src/gpu/GrTextureProxy.cpp
@@ -131,10 +131,8 @@
     SkASSERT(key.isValid());
     SkASSERT(!fUniqueKey.isValid()); // proxies can only ever get one uniqueKey
 
-    if (fTarget) {
-        if (!fTarget->getUniqueKey().isValid()) {
-            fTarget->resourcePriv().setUniqueKey(key);
-        }
+    if (fTarget && !fTarget->getUniqueKey().isValid()) {
+        fTarget->resourcePriv().setUniqueKey(key);
         SkASSERT(fTarget->getUniqueKey() == key);
     }
 
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp
index 4236037..d08f0a4 100644
--- a/src/image/SkImage_Gpu.cpp
+++ b/src/image/SkImage_Gpu.cpp
@@ -284,9 +284,17 @@
         return nullptr;
     }
 
-    GrProxyProvider* proxyProvider = ctx->contextPriv().proxyProvider();
-    sk_sp<GrTextureProxy> proxy = proxyProvider->createWrappedTextureProxy(
-                                        backendTex, origin, ownership, releaseProc, releaseCtx);
+    GrResourceProvider* resourceProvider = ctx->contextPriv().resourceProvider();
+
+    sk_sp<GrTexture> tex = resourceProvider->wrapBackendTexture(backendTex, ownership);
+    if (!tex) {
+        return nullptr;
+    }
+    if (releaseProc) {
+        tex->setRelease(releaseProc, releaseCtx);
+    }
+
+    sk_sp<GrTextureProxy> proxy(GrSurfaceProxy::MakeWrapped(std::move(tex), origin));
 
     return sk_make_sp<SkImage_Gpu>(ctx, kNeedNewImageUniqueID,
                                    at, std::move(proxy), std::move(colorSpace), SkBudgeted::kNo);
diff --git a/tests/TextureProxyTest.cpp b/tests/TextureProxyTest.cpp
index d422b07..914e83e 100644
--- a/tests/TextureProxyTest.cpp
+++ b/tests/TextureProxyTest.cpp
@@ -43,7 +43,8 @@
 // Basic test
 
 static sk_sp<GrTextureProxy> deferred_tex(skiatest::Reporter* reporter,
-                                          GrProxyProvider* proxyProvider, SkBackingFit fit) {
+                                          GrContext* context, SkBackingFit fit) {
+    GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider();
     const GrSurfaceDesc desc = make_desc(kNone_GrSurfaceFlags);
 
     sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(desc, fit, SkBudgeted::kYes);
@@ -53,7 +54,8 @@
 }
 
 static sk_sp<GrTextureProxy> deferred_texRT(skiatest::Reporter* reporter,
-                                            GrProxyProvider* proxyProvider, SkBackingFit fit) {
+                                            GrContext* context, SkBackingFit fit) {
+    GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider();
     const GrSurfaceDesc desc = make_desc(kRenderTarget_GrSurfaceFlag);
 
     sk_sp<GrTextureProxy> proxy = proxyProvider->createProxy(desc, fit, SkBudgeted::kYes);
@@ -63,7 +65,8 @@
 }
 
 static sk_sp<GrTextureProxy> wrapped(skiatest::Reporter* reporter,
-                                     GrProxyProvider* proxyProvider, SkBackingFit fit) {
+                                     GrContext* context, SkBackingFit fit) {
+    GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider();
     const GrSurfaceDesc desc = make_desc(kNone_GrSurfaceFlags);
 
     sk_sp<GrTextureProxy> proxy = proxyProvider->createInstantiatedProxy(desc, fit,
@@ -74,7 +77,9 @@
 }
 
 static sk_sp<GrTextureProxy> wrapped_with_key(skiatest::Reporter* reporter,
-                                              GrProxyProvider* proxyProvider, SkBackingFit fit) {
+                                              GrContext* context, SkBackingFit fit) {
+    GrResourceProvider* resourceProvider = context->contextPriv().resourceProvider();
+
     static GrUniqueKey::Domain d = GrUniqueKey::GenerateDomain();
     static int kUniqueKeyData = 0;
 
@@ -86,10 +91,18 @@
 
     const GrSurfaceDesc desc = make_desc(kNone_GrSurfaceFlags);
 
-    // Only budgeted & wrapped external proxies get to carry uniqueKeys
-    sk_sp<GrTextureProxy> proxy = proxyProvider->createInstantiatedProxy(desc, fit,
-                                                                         SkBudgeted::kYes, 0);
-    SkAssertResult(proxyProvider->assignUniqueKeyToProxy(key, proxy.get()));
+    sk_sp<GrTexture> tex;
+    if (SkBackingFit::kApprox == fit) {
+        tex = sk_sp<GrTexture>(resourceProvider->createApproxTexture(desc, 0));
+    } else {
+        // Only budgeted & wrapped external proxies get to carry uniqueKeys
+        tex = resourceProvider->createTexture(desc, SkBudgeted::kYes);
+    }
+
+    tex->resourcePriv().setUniqueKey(key);
+
+    sk_sp<GrTextureProxy> proxy = GrSurfaceProxy::MakeWrapped(std::move(tex),
+                                                              kBottomLeft_GrSurfaceOrigin);
     REPORTER_ASSERT(reporter, proxy->getUniqueKey().isValid());
     return proxy;
 }
@@ -134,7 +147,7 @@
 
         // Assigning the uniqueKey adds the proxy to the hash but doesn't force instantiation
         REPORTER_ASSERT(reporter, !proxyProvider->numUniqueKeyProxies_TestOnly());
-        SkAssertResult(proxyProvider->assignUniqueKeyToProxy(key, proxy.get()));
+        proxyProvider->assignUniqueKeyToProxy(key, proxy.get());
     }
 
     REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly());
@@ -252,8 +265,8 @@
     builder.finish();
 
     // Create proxy, assign unique key
-    sk_sp<GrTextureProxy> proxy = deferred_tex(reporter, proxyProvider, SkBackingFit::kExact);
-    SkAssertResult(proxyProvider->assignUniqueKeyToProxy(key, proxy.get()));
+    sk_sp<GrTextureProxy> proxy = deferred_tex(reporter, context, SkBackingFit::kExact);
+    proxyProvider->assignUniqueKeyToProxy(key, proxy.get());
 
     // Send an invalidation message, which will be sitting in the cache's inbox
     SkMessageBus<GrUniqueKeyInvalidatedMessage>::Post(GrUniqueKeyInvalidatedMessage(key));
@@ -289,7 +302,7 @@
     for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) {
         for (auto create : { deferred_tex, deferred_texRT, wrapped, wrapped_with_key }) {
             REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
-            basic_test(context, reporter, create(reporter, proxyProvider, fit), true);
+            basic_test(context, reporter, create(reporter, context, fit), true);
         }
 
         REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());