Switch SkImageGenerator over to generating GrTextureProxies

It does not seem irrational for generateTexture to always receive a valid GrContext. lockAsBitmap can do as it pleases.

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

Change-Id: I8aebc813a8a3a7d694b7369c2c9810e2164fe16e
Reviewed-on: https://skia-review.googlesource.com/9191
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
diff --git a/gm/image_pict.cpp b/gm/image_pict.cpp
index 387ceb8..1f273dc 100644
--- a/gm/image_pict.cpp
+++ b/gm/image_pict.cpp
@@ -231,11 +231,10 @@
         }
     }
 protected:
-    GrTexture* onGenerateTexture(GrContext* ctx, const SkImageInfo& info,
-                                 const SkIPoint& origin) override {
-        if (ctx) {
-            SkASSERT(ctx == fCtx.get());
-        }
+    sk_sp<GrTextureProxy> onGenerateTexture(GrContext* ctx, const SkImageInfo& info,
+                                            const SkIPoint& origin) override {
+        SkASSERT(ctx);
+        SkASSERT(ctx == fCtx.get());
 
         if (!fProxy) {
             return nullptr;
@@ -243,7 +242,7 @@
 
         if (origin.fX == 0 && origin.fY == 0 &&
             info.width() == fProxy->width() && info.height() == fProxy->height()) {
-            return SkSafeRef(fProxy->instantiate(fCtx->textureProvider())->asTexture());
+            return fProxy;
         }
 
         // need to copy the subset into a new texture
@@ -266,17 +265,14 @@
             return nullptr;
         }
 
-        GrSurface* dstSurf = dstContext->asSurfaceProxy()->instantiate(fCtx->textureProvider());
-        if (!dstSurf) {
-            return nullptr;
-        }
-
-        return SkRef(dstSurf->asTexture());
+        return dstContext->asTextureProxyRef();
     }
+
 private:
     sk_sp<GrContext>      fCtx;
-    sk_sp<GrSurfaceProxy> fProxy;
+    sk_sp<GrTextureProxy> fProxy;
 };
+
 static std::unique_ptr<SkImageGenerator> make_tex_generator(GrContext* ctx, sk_sp<SkPicture> pic) {
     const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100);
 
@@ -340,7 +336,8 @@
 
     static void draw_as_bitmap(SkCanvas* canvas, SkImageCacherator* cache, SkScalar x, SkScalar y) {
         SkBitmap bitmap;
-        cache->lockAsBitmap(&bitmap, nullptr, canvas->imageInfo().colorSpace());
+        cache->lockAsBitmap(canvas->getGrContext(), &bitmap, nullptr,
+                            canvas->imageInfo().colorSpace());
         canvas->drawBitmap(bitmap, x, y);
     }