Minor GrRenderTarget retraction
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1967743003

Review-Url: https://codereview.chromium.org/1967743003
diff --git a/src/core/SkImageCacherator.cpp b/src/core/SkImageCacherator.cpp
index 7b5ff22..0df14df 100644
--- a/src/core/SkImageCacherator.cpp
+++ b/src/core/SkImageCacherator.cpp
@@ -291,11 +291,11 @@
     {
         ScopedGenerator generator(this);
         Generator_GrYUVProvider provider(generator);
-        GrTexture* tex = provider.refAsTexture(ctx, desc, true);
+        sk_sp<GrTexture> tex = provider.refAsTexture(ctx, desc, true);
         if (tex) {
             SK_HISTOGRAM_ENUMERATION("LockTexturePath", kYUV_LockTexturePath,
                                      kLockTexturePathCount);
-            return set_key_and_return(tex, key);
+            return set_key_and_return(tex.release(), key);
         }
     }
 
diff --git a/src/gpu/GrYUVProvider.cpp b/src/gpu/GrYUVProvider.cpp
index 6cd7c95..b4320d0 100644
--- a/src/gpu/GrYUVProvider.cpp
+++ b/src/gpu/GrYUVProvider.cpp
@@ -80,7 +80,9 @@
     return true;
 }
 
-GrTexture* GrYUVProvider::refAsTexture(GrContext* ctx, const GrSurfaceDesc& desc, bool useCache) {
+sk_sp<GrTexture> GrYUVProvider::refAsTexture(GrContext* ctx,
+                                             const GrSurfaceDesc& desc,
+                                             bool useCache) {
     SkYUVPlanesCache::Info yuvInfo;
     void* planes[3];
     YUVScoper scoper;
@@ -110,18 +112,13 @@
             }
     }
 
-    GrSurfaceDesc rtDesc = desc;
-    rtDesc.fFlags = rtDesc.fFlags | kRenderTarget_GrSurfaceFlag;
-
-    SkAutoTUnref<GrTexture> result(ctx->textureProvider()->createTexture(rtDesc, SkBudgeted::kYes,
-                                                                         nullptr, 0));
-    if (!result) {
+    sk_sp<GrDrawContext> drawContext(ctx->newDrawContext(SkBackingFit::kExact,
+                                                         desc.fWidth, desc.fHeight,
+                                                         desc.fConfig, desc.fSampleCnt));
+    if (!drawContext) {
         return nullptr;
     }
 
-    GrRenderTarget* renderTarget = result->asRenderTarget();
-    SkASSERT(renderTarget);
-
     GrPaint paint;
     // We may be decoding an sRGB image, but the result of our linear math on the YUV planes
     // is already in sRGB in that case. Don't convert (which will make the image too bright).
@@ -137,12 +134,7 @@
     const SkRect r = SkRect::MakeIWH(yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY].fWidth,
             yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY].fHeight);
 
-    sk_sp<GrDrawContext> drawContext(ctx->drawContext(sk_ref_sp(renderTarget)));
-    if (!drawContext) {
-        return nullptr;
-    }
-
     drawContext->drawRect(GrClip::WideOpen(), paint, SkMatrix::I(), r);
 
-    return result.release();
+    return drawContext->asTexture();
 }
diff --git a/src/gpu/GrYUVProvider.h b/src/gpu/GrYUVProvider.h
index 85b238d..c32af15 100644
--- a/src/gpu/GrYUVProvider.h
+++ b/src/gpu/GrYUVProvider.h
@@ -35,7 +35,7 @@
      *
      *  On failure (e.g. the provider had no data), this returns NULL.
      */
-    GrTexture* refAsTexture(GrContext*, const GrSurfaceDesc&, bool useCache);
+    sk_sp<GrTexture> refAsTexture(GrContext*, const GrSurfaceDesc&, bool useCache);
 
     virtual uint32_t onGetID() = 0;
 
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index f1f48bc..120db13 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -181,8 +181,8 @@
     }
 };
 
-static GrTexture* create_texture_from_yuv(GrContext* ctx, const SkBitmap& bm,
-                                          const GrSurfaceDesc& desc) {
+static sk_sp<GrTexture> create_texture_from_yuv(GrContext* ctx, const SkBitmap& bm,
+                                                const GrSurfaceDesc& desc) {
     // Subsets are not supported, the whole pixelRef is loaded when using YUV decoding
     SkPixelRef* pixelRef = bm.pixelRef();
     if ((nullptr == pixelRef) ||
@@ -218,8 +218,9 @@
         return texture;
     }
 
-    if (GrTexture* texture = create_texture_from_yuv(ctx, bitmap, desc)) {
-        return texture;
+    sk_sp<GrTexture> texture(create_texture_from_yuv(ctx, bitmap, desc));
+    if (texture) {
+        return texture.release();
     }
 
     SkAutoLockPixels alp(bitmap);
@@ -339,9 +340,9 @@
         }
     }
 
-    GrTexture* texture = create_texture_from_yuv(ctx, bitmap, desc);
+    sk_sp<GrTexture> texture(create_texture_from_yuv(ctx, bitmap, desc));
     if (texture) {
-        return texture;
+        return texture.release();
     }
 
     // SkMipMap::Build doesn't handle sRGB data correctly (yet).