Bring sk_sp to GrDrawContext

This is split out of: https://codereview.chromium.org/1914883002/ (Refactor drawContext/RenderTarget creation)

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

Review-Url: https://codereview.chromium.org/1918003003
diff --git a/gm/beziereffects.cpp b/gm/beziereffects.cpp
index 61d3795..0154508 100644
--- a/gm/beziereffects.cpp
+++ b/gm/beziereffects.cpp
@@ -109,7 +109,7 @@
             return;
         }
 
-        SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(rt));
+        sk_sp<GrDrawContext> drawContext(context->drawContext(sk_ref_sp(rt)));
         if (!drawContext) {
             return;
         }
@@ -248,7 +248,7 @@
             return;
         }
 
-        SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(rt));
+        sk_sp<GrDrawContext> drawContext(context->drawContext(sk_ref_sp(rt)));
         if (!drawContext) {
             return;
         }
@@ -465,7 +465,7 @@
             return;
         }
 
-        SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(rt));
+        sk_sp<GrDrawContext> drawContext(context->drawContext(sk_ref_sp(rt)));
         if (!drawContext) {
             return;
         }
diff --git a/gm/bigrrectaaeffect.cpp b/gm/bigrrectaaeffect.cpp
index f4a1252..b852961 100644
--- a/gm/bigrrectaaeffect.cpp
+++ b/gm/bigrrectaaeffect.cpp
@@ -56,7 +56,7 @@
             return;
         }
 
-        SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(rt));
+        sk_sp<GrDrawContext> drawContext(context->drawContext(sk_ref_sp(rt)));
         if (!drawContext) {
             return;
         }
diff --git a/gm/constcolorprocessor.cpp b/gm/constcolorprocessor.cpp
index 37295c7..cfc0339 100644
--- a/gm/constcolorprocessor.cpp
+++ b/gm/constcolorprocessor.cpp
@@ -57,7 +57,7 @@
             return;
         }
 
-        SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(rt));
+        sk_sp<GrDrawContext> drawContext(context->drawContext(sk_ref_sp(rt)));
         if (!drawContext) {
             return;
         }
diff --git a/gm/convexpolyeffect.cpp b/gm/convexpolyeffect.cpp
index 28a4d5e..0c4c94b 100644
--- a/gm/convexpolyeffect.cpp
+++ b/gm/convexpolyeffect.cpp
@@ -163,7 +163,7 @@
             return;
         }
 
-        SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(rt));
+        sk_sp<GrDrawContext> drawContext(context->drawContext(sk_ref_sp(rt)));
         if (!drawContext) {
             return;
         }
diff --git a/gm/rrects.cpp b/gm/rrects.cpp
index d8b5e38..57c11ad 100644
--- a/gm/rrects.cpp
+++ b/gm/rrects.cpp
@@ -66,14 +66,14 @@
 #if SK_SUPPORT_GPU
         GrRenderTarget* rt = canvas->internal_private_accessTopLayerRenderTarget();
         context = rt ? rt->getContext() : nullptr;
-        SkAutoTUnref<GrDrawContext> drawContext;
+        sk_sp<GrDrawContext> drawContext;
         if (kEffect_Type == fType) {
             if (!context) {
                 skiagm::GM::DrawGpuOnlyMessage(canvas);
                 return;
             }
 
-            drawContext.reset(context->drawContext(rt));
+            drawContext = context->drawContext(sk_ref_sp(rt));
             if (!drawContext) {
                 return;
             }
diff --git a/gm/texdata.cpp b/gm/texdata.cpp
index 8e29b23..20cad0c 100644
--- a/gm/texdata.cpp
+++ b/gm/texdata.cpp
@@ -21,7 +21,7 @@
 DEF_SIMPLE_GM_BG(texdata, canvas, 2 * S, 2 * S, SK_ColorBLACK) {
         GrRenderTarget* target = canvas->internal_private_accessTopLayerRenderTarget();
         GrContext* ctx = canvas->getGrContext();
-        SkAutoTUnref<GrDrawContext> drawContext(ctx ? ctx->drawContext(target) : nullptr);
+        sk_sp<GrDrawContext> drawContext(ctx ? ctx->drawContext(sk_ref_sp(target)) : nullptr);
         if (drawContext && target) {
             SkAutoTArray<SkPMColor> gTextureData((2 * S) * (2 * S));
             static const int stride = 2 * S;
diff --git a/gm/texturedomaineffect.cpp b/gm/texturedomaineffect.cpp
index 89d3b44..e4a02c1 100644
--- a/gm/texturedomaineffect.cpp
+++ b/gm/texturedomaineffect.cpp
@@ -80,7 +80,7 @@
             return;
         }
 
-        SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(rt));
+        sk_sp<GrDrawContext> drawContext(context->drawContext(sk_ref_sp(rt)));
         if (!drawContext) {
             return;
         }
diff --git a/gm/yuvtorgbeffect.cpp b/gm/yuvtorgbeffect.cpp
index 996e473..09c6176 100644
--- a/gm/yuvtorgbeffect.cpp
+++ b/gm/yuvtorgbeffect.cpp
@@ -79,7 +79,7 @@
             return;
         }
 
-        SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(rt));
+        sk_sp<GrDrawContext> drawContext(context->drawContext(sk_ref_sp(rt)));
         if (!drawContext) {
             return;
         }
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index d59b2a2..087d821 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -192,7 +192,7 @@
      *
      * @return a draw context
      */
-    GrDrawContext* drawContext(GrRenderTarget* rt, const SkSurfaceProps* surfaceProps = NULL);
+    sk_sp<GrDrawContext> drawContext(sk_sp<GrRenderTarget> rt, const SkSurfaceProps* = nullptr);
 
     ///////////////////////////////////////////////////////////////////////////
     // Misc.
diff --git a/include/gpu/GrDrawContext.h b/include/gpu/GrDrawContext.h
index 61b3907..7bb9aaf 100644
--- a/include/gpu/GrDrawContext.h
+++ b/include/gpu/GrDrawContext.h
@@ -278,14 +278,18 @@
     int numColorSamples() const { return fRenderTarget->numColorSamples(); }
     bool isGammaCorrect() const { return fSurfaceProps.isGammaCorrect(); }
 
-    GrRenderTarget* accessRenderTarget() { return fRenderTarget; }
+    GrRenderTarget* accessRenderTarget() { return fRenderTarget.get(); }
+
+    sk_sp<GrRenderTarget> renderTarget() { return fRenderTarget; }
+
+    sk_sp<GrTexture> asTexture() { return sk_ref_sp(fRenderTarget->asTexture()); }
 
     // Provides access to functions that aren't part of the public API.
     GrDrawContextPriv drawContextPriv();
     const GrDrawContextPriv drawContextPriv() const;
 
 protected:
-    GrDrawContext(GrContext*, GrDrawingManager*, GrRenderTarget*,
+    GrDrawContext(GrContext*, GrDrawingManager*, sk_sp<GrRenderTarget>,
                   const SkSurfaceProps* surfaceProps, GrAuditTrail*, GrSingleOwner*);
 
     GrDrawingManager* drawingManager() { return fDrawingManager; }
@@ -323,7 +327,7 @@
     GrDrawTarget* getDrawTarget();
 
     GrDrawingManager*                 fDrawingManager;
-    GrRenderTarget*                   fRenderTarget;
+    sk_sp<GrRenderTarget>             fRenderTarget;
 
     // In MDB-mode the drawTarget can be closed by some other drawContext that has picked
     // it up. For this reason, the drawTarget should only ever be accessed via 'getDrawTarget'.
diff --git a/src/core/SkImageFilter.cpp b/src/core/SkImageFilter.cpp
index fdd78f8..935ce77 100644
--- a/src/core/SkImageFilter.cpp
+++ b/src/core/SkImageFilter.cpp
@@ -301,7 +301,7 @@
         return nullptr;
     }
 
-    sk_sp<GrDrawContext> drawContext(context->drawContext(dst->asRenderTarget()));
+    sk_sp<GrDrawContext> drawContext(context->drawContext(sk_ref_sp(dst->asRenderTarget())));
     if (!drawContext) {
         return nullptr;
     }
diff --git a/src/effects/SkAlphaThresholdFilter.cpp b/src/effects/SkAlphaThresholdFilter.cpp
index bf2a3fd..bfbcfd2 100644
--- a/src/effects/SkAlphaThresholdFilter.cpp
+++ b/src/effects/SkAlphaThresholdFilter.cpp
@@ -111,7 +111,8 @@
         return nullptr;
     }
 
-    sk_sp<GrDrawContext> drawContext(context->drawContext(maskTexture->asRenderTarget()));
+    sk_sp<GrDrawContext> drawContext(
+                                context->drawContext(sk_ref_sp(maskTexture->asRenderTarget())));
     if (!drawContext) {
         return nullptr;
     }
diff --git a/src/effects/SkBlurMaskFilter.cpp b/src/effects/SkBlurMaskFilter.cpp
index 2afb42f..6eb8474 100644
--- a/src/effects/SkBlurMaskFilter.cpp
+++ b/src/effects/SkBlurMaskFilter.cpp
@@ -1276,7 +1276,8 @@
             paint.setCoverageSetOpXPFactory(SkRegion::kReplace_Op);
         }
 
-        SkAutoTUnref<GrDrawContext> drawContext(context->drawContext((*result)->asRenderTarget()));
+        sk_sp<GrDrawContext> drawContext(
+                                    context->drawContext(sk_ref_sp((*result)->asRenderTarget())));
         if (!drawContext) {
             return false;
         }
diff --git a/src/effects/SkDisplacementMapEffect.cpp b/src/effects/SkDisplacementMapEffect.cpp
index a8f0b81..797bd97 100644
--- a/src/effects/SkDisplacementMapEffect.cpp
+++ b/src/effects/SkDisplacementMapEffect.cpp
@@ -346,7 +346,7 @@
         SkMatrix matrix;
         matrix.setTranslate(-SkIntToScalar(colorBounds.x()), -SkIntToScalar(colorBounds.y()));
 
-        SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(dst->asRenderTarget()));
+        sk_sp<GrDrawContext> drawContext(context->drawContext(sk_ref_sp(dst->asRenderTarget())));
         if (!drawContext) {
             return nullptr;
         }
diff --git a/src/effects/SkGpuBlurUtils.cpp b/src/effects/SkGpuBlurUtils.cpp
index 0ecc501..c3681fa 100644
--- a/src/effects/SkGpuBlurUtils.cpp
+++ b/src/effects/SkGpuBlurUtils.cpp
@@ -228,7 +228,7 @@
         return nullptr;
     }
 
-    SkAutoTUnref<GrDrawContext> srcDrawContext;
+    sk_sp<GrDrawContext> srcDrawContext;
 
     for (int i = 1; i < scaleFactorX || i < scaleFactorY; i *= 2) {
         GrPaint paint;
@@ -258,8 +258,8 @@
         scale_rect(&dstRect, i < scaleFactorX ? 0.5f : 1.0f,
                              i < scaleFactorY ? 0.5f : 1.0f);
 
-        SkAutoTUnref<GrDrawContext> dstDrawContext(
-                                             context->drawContext(dstTexture->asRenderTarget()));
+        sk_sp<GrDrawContext> dstDrawContext(
+                                   context->drawContext(sk_ref_sp(dstTexture->asRenderTarget())));
         if (!dstDrawContext) {
             return nullptr;
         }
@@ -283,12 +283,12 @@
         // We shouldn't be scaling because this is a small size blur
         SkASSERT((1 == scaleFactorX) && (1 == scaleFactorY));
 
-        SkAutoTUnref<GrDrawContext> dstDrawContext(
-            context->drawContext(dstTexture->asRenderTarget(), &props));
+        sk_sp<GrDrawContext> dstDrawContext(
+            context->drawContext(sk_ref_sp(dstTexture->asRenderTarget()), &props));
         if (!dstDrawContext) {
             return nullptr;
         }
-        convolve_gaussian_2d(dstDrawContext, clip, srcRect, srcOffset,
+        convolve_gaussian_2d(dstDrawContext.get(), clip, srcRect, srcOffset,
                              srcTexture, radiusX, radiusY, sigmaX, sigmaY, srcBounds);
 
         srcDrawContext.swap(dstDrawContext);
@@ -304,7 +304,7 @@
             if (scaleFactorX > 1) {
                 // TODO: if we pass in the source draw context we don't need this here
                 if (!srcDrawContext) {
-                    srcDrawContext.reset(context->drawContext(srcTexture->asRenderTarget()));
+                    srcDrawContext = context->drawContext(sk_ref_sp(srcTexture->asRenderTarget()));
                     if (!srcDrawContext) {
                         return nullptr;
                     }
@@ -317,12 +317,12 @@
                 srcDrawContext->clear(&clearRect, 0x0, false);
             }
 
-            SkAutoTUnref<GrDrawContext> dstDrawContext(
-                context->drawContext(dstTexture->asRenderTarget(), &props));
+            sk_sp<GrDrawContext> dstDrawContext(
+                context->drawContext(sk_ref_sp(dstTexture->asRenderTarget()), &props));
             if (!dstDrawContext) {
                 return nullptr;
             }
-            convolve_gaussian(dstDrawContext, clip, srcRect,
+            convolve_gaussian(dstDrawContext.get(), clip, srcRect,
                               srcTexture, Gr1DKernelEffect::kX_Direction, radiusX, sigmaX,
                               srcBounds, srcOffset);
             srcDrawContext.swap(dstDrawContext);
@@ -337,7 +337,7 @@
             if (scaleFactorY > 1 || sigmaX > 0.0f) {
                 // TODO: if we pass in the source draw context we don't need this here
                 if (!srcDrawContext) {
-                    srcDrawContext.reset(context->drawContext(srcTexture->asRenderTarget()));
+                    srcDrawContext = context->drawContext(sk_ref_sp(srcTexture->asRenderTarget()));
                     if (!srcDrawContext) {
                         return nullptr;
                     }
@@ -350,12 +350,12 @@
                 srcDrawContext->clear(&clearRect, 0x0, false);
             }
 
-            SkAutoTUnref<GrDrawContext> dstDrawContext(
-                context->drawContext(dstTexture->asRenderTarget(), &props));
+            sk_sp<GrDrawContext> dstDrawContext(
+                context->drawContext(sk_ref_sp(dstTexture->asRenderTarget()), &props));
             if (!dstDrawContext) {
                 return nullptr;
             }
-            convolve_gaussian(dstDrawContext, clip, srcRect,
+            convolve_gaussian(dstDrawContext.get(), clip, srcRect,
                               srcTexture, Gr1DKernelEffect::kY_Direction, radiusY, sigmaY,
                               srcBounds, srcOffset);
 
@@ -391,8 +391,8 @@
         SkRect dstRect(srcRect);
         scale_rect(&dstRect, (float) scaleFactorX, (float) scaleFactorY);
 
-        SkAutoTUnref<GrDrawContext> dstDrawContext(
-                                context->drawContext(dstTexture->asRenderTarget()));
+        sk_sp<GrDrawContext> dstDrawContext(
+                                context->drawContext(sk_ref_sp(dstTexture->asRenderTarget())));
         if (!dstDrawContext) {
             return nullptr;
         }
diff --git a/src/effects/SkLightingImageFilter.cpp b/src/effects/SkLightingImageFilter.cpp
index 4252831..7223ae5 100644
--- a/src/effects/SkLightingImageFilter.cpp
+++ b/src/effects/SkLightingImageFilter.cpp
@@ -418,7 +418,7 @@
         return nullptr;
     }
 
-    sk_sp<GrDrawContext> drawContext(context->drawContext(dst->asRenderTarget()));
+    sk_sp<GrDrawContext> drawContext(context->drawContext(sk_ref_sp(dst->asRenderTarget())));
     if (!drawContext) {
         return nullptr;
     }
diff --git a/src/effects/SkMorphologyImageFilter.cpp b/src/effects/SkMorphologyImageFilter.cpp
index 810d0e1..9e87fe0 100644
--- a/src/effects/SkMorphologyImageFilter.cpp
+++ b/src/effects/SkMorphologyImageFilter.cpp
@@ -496,13 +496,13 @@
         if (!scratch) {
             return nullptr;
         }
-        SkAutoTUnref<GrDrawContext> dstDrawContext(
-                                                context->drawContext(scratch->asRenderTarget()));
+        sk_sp<GrDrawContext> dstDrawContext(
+                                      context->drawContext(sk_ref_sp(scratch->asRenderTarget())));
         if (!dstDrawContext) {
             return nullptr;
         }
 
-        apply_morphology_pass(dstDrawContext, clip, srcTexture.get(),
+        apply_morphology_pass(dstDrawContext.get(), clip, srcTexture.get(),
                               srcRect, dstRect, radius.fWidth, morphType,
                               Gr1DKernelEffect::kX_Direction);
         SkIRect clearRect = SkIRect::MakeXYWH(dstRect.fLeft, dstRect.fBottom,
@@ -520,13 +520,13 @@
         if (!scratch) {
             return nullptr;
         }
-        SkAutoTUnref<GrDrawContext> dstDrawContext(
-                                                context->drawContext(scratch->asRenderTarget()));
+        sk_sp<GrDrawContext> dstDrawContext(
+                                      context->drawContext(sk_ref_sp(scratch->asRenderTarget())));
         if (!dstDrawContext) {
             return nullptr;
         }
 
-        apply_morphology_pass(dstDrawContext, clip, srcTexture.get(),
+        apply_morphology_pass(dstDrawContext.get(), clip, srcTexture.get(),
                               srcRect, dstRect, radius.fHeight, morphType,
                               Gr1DKernelEffect::kY_Direction);
 
diff --git a/src/effects/SkXfermodeImageFilter.cpp b/src/effects/SkXfermodeImageFilter.cpp
index f4e896e..b1ac1c3 100644
--- a/src/effects/SkXfermodeImageFilter.cpp
+++ b/src/effects/SkXfermodeImageFilter.cpp
@@ -248,7 +248,7 @@
 
     paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode);
 
-    SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(dst->asRenderTarget()));
+    sk_sp<GrDrawContext> drawContext(context->drawContext(sk_ref_sp(dst->asRenderTarget())));
     if (!drawContext) {
         return nullptr;
     }
diff --git a/src/gpu/GrBlurUtils.cpp b/src/gpu/GrBlurUtils.cpp
index 8edc6b3..6827c83 100644
--- a/src/gpu/GrBlurUtils.cpp
+++ b/src/gpu/GrBlurUtils.cpp
@@ -124,7 +124,7 @@
 
     SkRect clipRect = SkRect::MakeWH(maskRect->width(), maskRect->height());
 
-    SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(mask->asRenderTarget()));
+    sk_sp<GrDrawContext> drawContext(context->drawContext(sk_ref_sp(mask->asRenderTarget())));
     if (!drawContext) {
         return nullptr;
     }
diff --git a/src/gpu/GrClipMaskManager.cpp b/src/gpu/GrClipMaskManager.cpp
index 7418e76..f0d6faf 100644
--- a/src/gpu/GrClipMaskManager.cpp
+++ b/src/gpu/GrClipMaskManager.cpp
@@ -632,7 +632,7 @@
 
     texture->resourcePriv().setUniqueKey(key);
 
-    SkAutoTUnref<GrDrawContext> dc(context->drawContext(texture->asRenderTarget()));
+    sk_sp<GrDrawContext> dc(context->drawContext(sk_ref_sp(texture->asRenderTarget())));
     if (!dc) {
         return nullptr;
     }
@@ -682,7 +682,7 @@
                                          0xffff,
                                          0xffff,
                                          0xffff)
-            if (!stencil_element(dc, &maskSpaceIBounds, kStencilInElement,
+            if (!stencil_element(dc.get(), &maskSpaceIBounds, kStencilInElement,
                                  translate, element)) {
                 texture->resourcePriv().removeUniqueKey();
                 return nullptr;
@@ -709,7 +709,7 @@
             paint.setAntiAlias(element->isAA());
             paint.setCoverageSetOpXPFactory(op, false);
 
-            draw_element(dc, GrClip::WideOpen(), paint, translate, element);
+            draw_element(dc.get(), GrClip::WideOpen(), paint, translate, element);
         }
     }
 
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index c223a60..5ebb2e9 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -362,7 +362,7 @@
             }
             SkMatrix matrix;
             matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top));
-            SkAutoTUnref<GrDrawContext> drawContext(this->drawContext(renderTarget));
+            sk_sp<GrDrawContext> drawContext(this->drawContext(sk_ref_sp(renderTarget)));
             if (!drawContext) {
                 return false;
             }
@@ -484,7 +484,8 @@
                 paint.addColorFragmentProcessor(fp);
                 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode);
                 SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height));
-                SkAutoTUnref<GrDrawContext> drawContext(this->drawContext(temp->asRenderTarget()));
+                sk_sp<GrDrawContext> drawContext(
+                                            this->drawContext(sk_ref_sp(temp->asRenderTarget())));
                 drawContext->drawRect(GrClip::WideOpen(), paint, SkMatrix::I(), rect, nullptr);
                 surfaceToRead.reset(SkRef(temp.get()));
                 left = 0;
@@ -569,7 +570,7 @@
         src->flushWrites();
         return fGpu->copySurface(dst, src, clippedSrcRect, clippedDstPoint);
     }
-    SkAutoTUnref<GrDrawContext> drawContext(this->drawContext(dst->asRenderTarget()));
+    sk_sp<GrDrawContext> drawContext(this->drawContext(sk_ref_sp(dst->asRenderTarget())));
     if (!drawContext) {
         return false;
     }
@@ -608,9 +609,10 @@
 }
 
 
-GrDrawContext* GrContext::drawContext(GrRenderTarget* rt, const SkSurfaceProps* surfaceProps) {
+sk_sp<GrDrawContext> GrContext::drawContext(sk_sp<GrRenderTarget> rt,
+                                            const SkSurfaceProps* surfaceProps) {
     ASSERT_SINGLE_OWNER
-    return fDrawingManager->drawContext(rt, surfaceProps);
+    return fDrawingManager->drawContext(std::move(rt), surfaceProps);
 }
 
 bool GrContext::abandoned() const {
diff --git a/src/gpu/GrDrawContext.cpp b/src/gpu/GrDrawContext.cpp
index 2e4b13f..af04f74 100644
--- a/src/gpu/GrDrawContext.cpp
+++ b/src/gpu/GrDrawContext.cpp
@@ -57,13 +57,13 @@
 // when the drawContext attempts to use it (via getDrawTarget).
 GrDrawContext::GrDrawContext(GrContext* context,
                              GrDrawingManager* drawingMgr,
-                             GrRenderTarget* rt,
+                             sk_sp<GrRenderTarget> rt,
                              const SkSurfaceProps* surfaceProps,
                              GrAuditTrail* auditTrail,
                              GrSingleOwner* singleOwner)
     : fDrawingManager(drawingMgr)
-    , fRenderTarget(rt)
-    , fDrawTarget(SkSafeRef(rt->getLastDrawTarget()))
+    , fRenderTarget(std::move(rt))
+    , fDrawTarget(SkSafeRef(fRenderTarget->getLastDrawTarget()))
     , fContext(context)
     , fSurfaceProps(SkSurfacePropsCopyOrDefault(surfaceProps))
     , fAuditTrail(auditTrail)
@@ -95,7 +95,7 @@
     SkDEBUGCODE(this->validate();)
 
     if (!fDrawTarget || fDrawTarget->isClosed()) {
-        fDrawTarget = fDrawingManager->newDrawTarget(fRenderTarget);
+        fDrawTarget = fDrawingManager->newDrawTarget(fRenderTarget.get());
     }
 
     return fDrawTarget;
@@ -107,7 +107,7 @@
     SkDEBUGCODE(this->validate();)
     GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::copySurface");
 
-    return this->getDrawTarget()->copySurface(fRenderTarget, src, srcRect, dstPoint);
+    return this->getDrawTarget()->copySurface(fRenderTarget.get(), src, srcRect, dstPoint);
 }
 
 void GrDrawContext::drawText(const GrClip& clip, const GrPaint& grPaint,
@@ -173,7 +173,7 @@
     GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::discard");
 
     AutoCheckFlush acf(fDrawingManager);
-    this->getDrawTarget()->discard(fRenderTarget);
+    this->getDrawTarget()->discard(fRenderTarget.get());
 }
 
 void GrDrawContext::clear(const SkIRect* rect,
@@ -185,7 +185,7 @@
     GR_AUDIT_TRAIL_AUTO_FRAME(fAuditTrail, "GrDrawContext::clear");
 
     AutoCheckFlush acf(fDrawingManager);
-    this->getDrawTarget()->clear(rect, color, canIgnoreRect, fRenderTarget);
+    this->getDrawTarget()->clear(rect, color, canIgnoreRect, fRenderTarget.get());
 }
 
 
@@ -235,7 +235,7 @@
         SkAutoTUnref<GrDrawBatch> batch(
                 GrRectBatchFactory::CreateNonAAFill(paint->getColor(), SkMatrix::I(), r, nullptr,
                                                     &localMatrix));
-        GrPipelineBuilder pipelineBuilder(*paint, fRenderTarget, clip);
+        GrPipelineBuilder pipelineBuilder(*paint, fRenderTarget.get(), clip);
         this->getDrawTarget()->drawBatch(pipelineBuilder, batch);
     }
 }
@@ -258,7 +258,7 @@
                                              const SkRect& rect) {
 
     GrDrawBatch* batch = nullptr;
-    if (should_apply_coverage_aa(paint, fRenderTarget)) {
+    if (should_apply_coverage_aa(paint, fRenderTarget.get())) {
         // The fill path can handle rotation but not skew.
         if (view_matrix_ok_for_aa_fill_rect(viewMatrix)) {
             SkRect devBoundRect;
@@ -319,7 +319,7 @@
                 // Will it blend?
                 GrColor clearColor;
                 if (paint.isConstantBlendedColor(&clearColor)) {
-                    this->getDrawTarget()->clear(nullptr, clearColor, true, fRenderTarget);
+                    this->getDrawTarget()->clear(nullptr, clearColor, true, fRenderTarget.get());
                     return;
                 }
             }
@@ -333,7 +333,7 @@
     } else {
         GrColor color = paint.getColor();
 
-        if (should_apply_coverage_aa(paint, fRenderTarget)) {
+        if (should_apply_coverage_aa(paint, fRenderTarget.get())) {
             // The stroke path needs the rect to remain axis aligned (no rotation or skew).
             if (viewMatrix.rectStaysRect()) {
                 batch.reset(GrRectBatchFactory::CreateAAStroke(color, viewMatrix, rect,
@@ -353,7 +353,7 @@
     }
 
     if (batch) {
-        GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip);
+        GrPipelineBuilder pipelineBuilder(paint, fRenderTarget.get(), clip);
 
         if (snapToPixelCenters) {
             pipelineBuilder.setState(GrPipelineBuilder::kSnapVerticesToPixelCenters_Flag,
@@ -391,7 +391,9 @@
 
     SkAutoTUnref<GrDrawBatch> batch(fDrawContext->getFillRectBatch(paint, viewMatrix, rect));
     if (batch) {
-        GrPipelineBuilder pipelineBuilder(paint, fDrawContext->fRenderTarget, GrClip::WideOpen());
+        GrPipelineBuilder pipelineBuilder(paint,
+                                          fDrawContext->accessRenderTarget(),
+                                          GrClip::WideOpen());
         pipelineBuilder.setStencil(ss);
 
         fDrawContext->getDrawTarget()->drawBatch(pipelineBuilder, batch, scissorRect);
@@ -417,7 +419,7 @@
     AutoCheckFlush acf(fDrawingManager);
 
     SkAutoTUnref<GrDrawBatch> batch;
-    if (should_apply_coverage_aa(paint, fRenderTarget) &&
+    if (should_apply_coverage_aa(paint, fRenderTarget.get()) &&
         view_matrix_ok_for_aa_fill_rect(viewMatrix)) {
         batch.reset(GrAAFillRectBatch::CreateWithLocalRect(paint.getColor(), viewMatrix, rectToDraw,
                                                            localRect));
@@ -427,7 +429,7 @@
     }
 
     if (batch) {
-        GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip);
+        GrPipelineBuilder pipelineBuilder(paint, fRenderTarget.get(), clip);
         this->drawBatch(&pipelineBuilder, batch);
     }
 }
@@ -445,7 +447,7 @@
     AutoCheckFlush acf(fDrawingManager);
 
     SkAutoTUnref<GrDrawBatch> batch;
-    if (should_apply_coverage_aa(paint, fRenderTarget) &&
+    if (should_apply_coverage_aa(paint, fRenderTarget.get()) &&
         view_matrix_ok_for_aa_fill_rect(viewMatrix)) {
         batch.reset(GrAAFillRectBatch::Create(paint.getColor(), viewMatrix, localMatrix,
                                               rectToDraw));
@@ -454,7 +456,7 @@
                                                         nullptr, &localMatrix));
     }
 
-    GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip);
+    GrPipelineBuilder pipelineBuilder(paint, fRenderTarget.get(), clip);
     this->getDrawTarget()->drawBatch(pipelineBuilder, batch);
 }
 
@@ -499,7 +501,7 @@
                                                                 indexCount, colors, texCoords,
                                                                 bounds));
 
-    GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip);
+    GrPipelineBuilder pipelineBuilder(paint, fRenderTarget.get(), clip);
     this->getDrawTarget()->drawBatch(pipelineBuilder, batch);
 }
 
@@ -524,7 +526,7 @@
     SkAutoTUnref<GrDrawBatch> batch(GrDrawAtlasBatch::Create(geometry, viewMatrix, spriteCount,
                                                              xform, texRect, colors));
 
-    GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip);
+    GrPipelineBuilder pipelineBuilder(paint, fRenderTarget.get(), clip);
     this->getDrawTarget()->drawBatch(pipelineBuilder, batch);
 }
 
@@ -548,7 +550,7 @@
 
     AutoCheckFlush acf(fDrawingManager);
 
-    if (should_apply_coverage_aa(paint, fRenderTarget)) {
+    if (should_apply_coverage_aa(paint, fRenderTarget.get())) {
         GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps();
 
         SkAutoTUnref<GrDrawBatch> batch(GrOvalRenderer::CreateRRectBatch(paint.getColor(),
@@ -557,7 +559,7 @@
                                                                          strokeInfo,
                                                                          shaderCaps));
         if (batch) {
-            GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip);
+            GrPipelineBuilder pipelineBuilder(paint, fRenderTarget.get(), clip);
             this->getDrawTarget()->drawBatch(pipelineBuilder, batch);
             return;
         }
@@ -651,7 +653,7 @@
     path.addRRect(outer);
     path.setFillType(SkPath::kEvenOdd_FillType);
 
-    GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip);
+    GrPipelineBuilder pipelineBuilder(paint, fRenderTarget.get(), clip);
     this->internalDrawPath(clip, paint, viewMatrix, path, GrStrokeInfo::FillInfo());
 }
 
@@ -675,7 +677,7 @@
 
     AutoCheckFlush acf(fDrawingManager);
 
-    if (should_apply_coverage_aa(paint, fRenderTarget)) {
+    if (should_apply_coverage_aa(paint, fRenderTarget.get())) {
         GrShaderCaps* shaderCaps = fContext->caps()->shaderCaps();
         SkAutoTUnref<GrDrawBatch> batch(GrOvalRenderer::CreateOvalBatch(paint.getColor(),
                                                                         viewMatrix,
@@ -683,7 +685,7 @@
                                                                         strokeInfo,
                                                                         shaderCaps));
         if (batch) {
-            GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip);
+            GrPipelineBuilder pipelineBuilder(paint, fRenderTarget.get(), clip);
             this->getDrawTarget()->drawBatch(pipelineBuilder, batch);
             return;
         }
@@ -713,7 +715,7 @@
                                                              imageWidth, imageHeight,
                                                              center, dst));
 
-    GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip);
+    GrPipelineBuilder pipelineBuilder(paint, fRenderTarget.get(), clip);
     this->getDrawTarget()->drawBatch(pipelineBuilder, batch);
 }
 
@@ -777,7 +779,7 @@
 
     AutoCheckFlush acf(fDrawingManager);
 
-    GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip);
+    GrPipelineBuilder pipelineBuilder(paint, fRenderTarget.get(), clip);
     this->getDrawTarget()->drawBatch(pipelineBuilder, batch);
 }
 
@@ -812,7 +814,7 @@
 
     AutoCheckFlush acf(fDrawingManager);
 
-    if (should_apply_coverage_aa(paint, fRenderTarget) && !strokeInfo.isDashed()) {
+    if (should_apply_coverage_aa(paint, fRenderTarget.get()) && !strokeInfo.isDashed()) {
         if (strokeInfo.getWidth() < 0 && !path.isConvex()) {
             // Concave AA paths are expensive - try to avoid them for special cases
             SkRect rects[2];
@@ -821,7 +823,7 @@
                 SkAutoTUnref<GrDrawBatch> batch(GrRectBatchFactory::CreateAAFillNestedRects(
                     paint.getColor(), viewMatrix, rects));
 
-                GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip);
+                GrPipelineBuilder pipelineBuilder(paint, fRenderTarget.get(), clip);
                 this->getDrawTarget()->drawBatch(pipelineBuilder, batch);
                 return;
             }
@@ -837,7 +839,7 @@
                                                                             strokeInfo,
                                                                             shaderCaps));
             if (batch) {
-                GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip);
+                GrPipelineBuilder pipelineBuilder(paint, fRenderTarget.get(), clip);
                 this->getDrawTarget()->drawBatch(pipelineBuilder, batch);
                 return;
             }
@@ -866,8 +868,8 @@
 
     if (path.isEmpty() && path.isInverseFillType()) {
         this->drawAndStencilRect(scissorRect, ss, op, invert, false, SkMatrix::I(),
-                                 SkRect::MakeIWH(fDrawContext->fRenderTarget->width(),
-                                                 fDrawContext->fRenderTarget->height()));
+                                 SkRect::MakeIWH(fDrawContext->width(),
+                                                 fDrawContext->height()));
         return true;
     }
 
@@ -910,7 +912,7 @@
         clip.setIRect(*scissorRect);
     }
 
-    GrPipelineBuilder pipelineBuilder(paint, fDrawContext->fRenderTarget, clip);
+    GrPipelineBuilder pipelineBuilder(paint, fDrawContext->accessRenderTarget(), clip);
     pipelineBuilder.setStencil(ss);
 
     GrPathRenderer::DrawPathArgs args;
@@ -940,7 +942,7 @@
     // the src color (either the input alpha or in the frag shader) to implement
     // aa. If we have some future driver-mojo path AA that can do the right
     // thing WRT to the blend then we'll need some query on the PR.
-    bool useCoverageAA = should_apply_coverage_aa(paint, fRenderTarget);
+    bool useCoverageAA = should_apply_coverage_aa(paint, fRenderTarget.get());
     const bool isStencilDisabled = true;
     bool isStencilBufferMSAA = fRenderTarget->isStencilBufferMultisampled();
 
@@ -1015,7 +1017,7 @@
         return;
     }
 
-    GrPipelineBuilder pipelineBuilder(paint, fRenderTarget, clip);
+    GrPipelineBuilder pipelineBuilder(paint, fRenderTarget.get(), clip);
 
     GrPathRenderer::DrawPathArgs args;
     args.fTarget = this->getDrawTarget();
diff --git a/src/gpu/GrDrawingManager.cpp b/src/gpu/GrDrawingManager.cpp
index 976fbb6..4b035bc 100644
--- a/src/gpu/GrDrawingManager.cpp
+++ b/src/gpu/GrDrawingManager.cpp
@@ -159,8 +159,8 @@
     return pr;
 }
 
-GrDrawContext* GrDrawingManager::drawContext(GrRenderTarget* rt,
-                                             const SkSurfaceProps* surfaceProps) {
+sk_sp<GrDrawContext> GrDrawingManager::drawContext(sk_sp<GrRenderTarget> rt,
+                                                   const SkSurfaceProps* surfaceProps) {
     if (this->abandoned()) {
         return nullptr;
     }
@@ -173,13 +173,16 @@
 
     if (useDIF && fContext->caps()->shaderCaps()->pathRenderingSupport() &&
         rt->isStencilBufferMultisampled()) {
-        GrStencilAttachment* sb = fContext->resourceProvider()->attachStencilAttachment(rt);
+        GrStencilAttachment* sb = fContext->resourceProvider()->attachStencilAttachment(rt.get());
         if (sb) {
-            return new GrPathRenderingDrawContext(fContext, this, rt, surfaceProps,
-                                                  fContext->getAuditTrail(), fSingleOwner);
+            return sk_sp<GrDrawContext>(new GrPathRenderingDrawContext(
+                                                        fContext, this, std::move(rt), 
+                                                        surfaceProps,
+                                                        fContext->getAuditTrail(), fSingleOwner));
         }
     }
 
-    return new GrDrawContext(fContext, this, rt, surfaceProps, fContext->getAuditTrail(),
-                             fSingleOwner);
+    return sk_sp<GrDrawContext>(new GrDrawContext(fContext, this, std::move(rt), surfaceProps,
+                                                  fContext->getAuditTrail(),
+                                                  fSingleOwner));
 }
diff --git a/src/gpu/GrDrawingManager.h b/src/gpu/GrDrawingManager.h
index f011b41..72db2ae 100644
--- a/src/gpu/GrDrawingManager.h
+++ b/src/gpu/GrDrawingManager.h
@@ -31,7 +31,7 @@
     bool abandoned() const { return fAbandoned; }
     void freeGpuResources();
 
-    GrDrawContext* drawContext(GrRenderTarget* rt, const SkSurfaceProps*);
+    sk_sp<GrDrawContext> drawContext(sk_sp<GrRenderTarget> rt, const SkSurfaceProps*);
 
     // The caller automatically gets a ref on the returned drawTarget. It must
     // be balanced by an unref call.
diff --git a/src/gpu/GrLayerCache.cpp b/src/gpu/GrLayerCache.cpp
index 3c7ab88..8bdc3fb 100644
--- a/src/gpu/GrLayerCache.cpp
+++ b/src/gpu/GrLayerCache.cpp
@@ -468,8 +468,8 @@
     SkASSERT(0 == fPictureHash.count());
 
     if (fAtlas->getTextureOrNull()) {
-        SkAutoTUnref<GrDrawContext> drawContext(
-                                    fContext->drawContext(fAtlas->getTexture()->asRenderTarget()));
+        sk_sp<GrDrawContext> drawContext(
+                       fContext->drawContext(sk_ref_sp(fAtlas->getTexture()->asRenderTarget())));
 
         if (drawContext) {
             drawContext->discard();
diff --git a/src/gpu/GrPathRenderingDrawContext.h b/src/gpu/GrPathRenderingDrawContext.h
index 49a0e1d..5d1893c 100644
--- a/src/gpu/GrPathRenderingDrawContext.h
+++ b/src/gpu/GrPathRenderingDrawContext.h
@@ -26,10 +26,10 @@
                       SkScalar x, SkScalar y,
                       SkDrawFilter*, const SkIRect& clipBounds) override;
 protected:
-    GrPathRenderingDrawContext(GrContext* ctx, GrDrawingManager* mgr, GrRenderTarget* rt,
+    GrPathRenderingDrawContext(GrContext* ctx, GrDrawingManager* mgr, sk_sp<GrRenderTarget> rt,
                                const SkSurfaceProps* surfaceProps, GrAuditTrail* at,
                                GrSingleOwner* so)
-        : INHERITED(ctx, mgr, rt, surfaceProps, at, so) {}
+        : INHERITED(ctx, mgr, std::move(rt), surfaceProps, at, so) {}
 
 private:
     SkAutoTDelete<GrStencilAndCoverTextContext> fStencilAndCoverTextContext;
diff --git a/src/gpu/GrRenderTarget.cpp b/src/gpu/GrRenderTarget.cpp
index ae44071..a673640 100644
--- a/src/gpu/GrRenderTarget.cpp
+++ b/src/gpu/GrRenderTarget.cpp
@@ -29,7 +29,7 @@
         return;
     }
 
-    SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(this));
+    sk_sp<GrDrawContext> drawContext(context->drawContext(sk_ref_sp(this)));
     if (!drawContext) {
         return;
     }
diff --git a/src/gpu/GrTextureParamsAdjuster.cpp b/src/gpu/GrTextureParamsAdjuster.cpp
index 429a63a..8868309 100644
--- a/src/gpu/GrTextureParamsAdjuster.cpp
+++ b/src/gpu/GrTextureParamsAdjuster.cpp
@@ -112,7 +112,7 @@
         localRect = SkRect::MakeWH(1.f, 1.f);
     }
 
-    SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(copy->asRenderTarget()));
+    sk_sp<GrDrawContext> drawContext(context->drawContext(sk_ref_sp(copy->asRenderTarget())));
     if (!drawContext) {
         return nullptr;
     }
diff --git a/src/gpu/GrTextureToYUVPlanes.cpp b/src/gpu/GrTextureToYUVPlanes.cpp
index 6a8d7b6..a8eec63 100644
--- a/src/gpu/GrTextureToYUVPlanes.cpp
+++ b/src/gpu/GrTextureToYUVPlanes.cpp
@@ -117,49 +117,49 @@
 
         // Do all the draws before any readback.
         if (yuvTex) {
-            SkAutoTUnref<GrDrawContext> dc(context->drawContext(yuvTex->asRenderTarget()));
+            sk_sp<GrDrawContext> dc(context->drawContext(sk_ref_sp(yuvTex->asRenderTarget())));
             if (!dc) {
                 return false;
             }
-            if (!convert_texture(texture, dc, sizes[0].fWidth, sizes[0].fHeight, colorSpace,
+            if (!convert_texture(texture, dc.get(), sizes[0].fWidth, sizes[0].fHeight, colorSpace,
                                  GrYUVEffect::CreateRGBToYUV)) {
                 return false;
             }
 
         } else {
             SkASSERT(yTex);
-            SkAutoTUnref<GrDrawContext> dc(context->drawContext(yTex->asRenderTarget()));
+            sk_sp<GrDrawContext> dc(context->drawContext(sk_ref_sp(yTex->asRenderTarget())));
             if (!dc) {
                 return false;
             }
-            if (!convert_texture(texture, dc, sizes[0].fWidth, sizes[0].fHeight, colorSpace,
+            if (!convert_texture(texture, dc.get(), sizes[0].fWidth, sizes[0].fHeight, colorSpace,
                                  GrYUVEffect::CreateRGBToY)) {
                 return false;
             }
             if (uvTex) {
-                dc.reset(context->drawContext(uvTex->asRenderTarget()));
+                dc = context->drawContext(sk_ref_sp(uvTex->asRenderTarget()));
                 if (!dc) {
                     return false;
                 }
-                if (!convert_texture(texture, dc, sizes[1].fWidth, sizes[1].fHeight,
+                if (!convert_texture(texture, dc.get(), sizes[1].fWidth, sizes[1].fHeight,
                                      colorSpace,  GrYUVEffect::CreateRGBToUV)) {
                     return false;
                 }
             } else {
                 SkASSERT(uTex && vTex);
-                dc.reset(context->drawContext(uTex->asRenderTarget()));
+                dc = context->drawContext(sk_ref_sp(uTex->asRenderTarget()));
                 if (!dc) {
                     return false;
                 }
-                if (!convert_texture(texture, dc, sizes[1].fWidth, sizes[1].fHeight,
+                if (!convert_texture(texture, dc.get(), sizes[1].fWidth, sizes[1].fHeight,
                                      colorSpace, GrYUVEffect::CreateRGBToU)) {
                     return false;
                 }
-                dc.reset(context->drawContext(vTex->asRenderTarget()));
+                dc = context->drawContext(sk_ref_sp(vTex->asRenderTarget()));
                 if (!dc) {
                     return false;
                 }
-                if (!convert_texture(texture, dc, sizes[2].fWidth, sizes[2].fHeight,
+                if (!convert_texture(texture, dc.get(), sizes[2].fWidth, sizes[2].fHeight,
                                      colorSpace, GrYUVEffect::CreateRGBToV)) {
                     return false;
                 }
diff --git a/src/gpu/GrYUVProvider.cpp b/src/gpu/GrYUVProvider.cpp
index 3990e88..6cd7c95 100644
--- a/src/gpu/GrYUVProvider.cpp
+++ b/src/gpu/GrYUVProvider.cpp
@@ -137,7 +137,7 @@
     const SkRect r = SkRect::MakeIWH(yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY].fWidth,
             yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY].fHeight);
 
-    SkAutoTUnref<GrDrawContext> drawContext(ctx->drawContext(renderTarget));
+    sk_sp<GrDrawContext> drawContext(ctx->drawContext(sk_ref_sp(renderTarget)));
     if (!drawContext) {
         return nullptr;
     }
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 535d55e..3644da4 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -172,7 +172,7 @@
     fLegacyBitmap.setInfo(info);
     fLegacyBitmap.setPixelRef(pr)->unref();
 
-    fDrawContext.reset(this->context()->drawContext(rt, &this->surfaceProps()));
+    fDrawContext = this->context()->drawContext(sk_ref_sp(rt), &this->surfaceProps());
     if (flags & kNeedClear_Flag) {
         this->clearAll();
     }
@@ -385,7 +385,8 @@
     SkPixelRef* pr = new SkGrPixelRef(fLegacyBitmap.info(), fRenderTarget);
     fLegacyBitmap.setPixelRef(pr)->unref();
 
-    fDrawContext.reset(this->context()->drawContext(fRenderTarget, &this->surfaceProps()));
+    fDrawContext = this->context()->drawContext(sk_ref_sp(fRenderTarget.get()),
+                                                &this->surfaceProps());
 }
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -513,7 +514,7 @@
         SkPath path;
         path.setIsVolatile(true);
         path.addRect(rect);
-        GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext,
+        GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext.get(),
                                             fClip, path, paint,
                                             *draw.fMatrix, nullptr,
                                             draw.fRC->getBounds(), true);
@@ -564,7 +565,7 @@
                         return;
                     }
                     if (paint.getMaskFilter()->directFilterRRectMaskGPU(fContext->textureProvider(),
-                                                                        fDrawContext,
+                                                                        fDrawContext.get(),
                                                                         &grPaint,
                                                                         fClip,
                                                                         *draw.fMatrix,
@@ -585,7 +586,7 @@
         SkPath path;
         path.setIsVolatile(true);
         path.addRRect(rect);
-        GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext,
+        GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext.get(),
                                             fClip, path, paint,
                                             *draw.fMatrix, nullptr,
                                             draw.fRC->getBounds(), true);
@@ -631,7 +632,7 @@
     path.addRRect(inner);
     path.setFillType(SkPath::kEvenOdd_FillType);
 
-    GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext,
+    GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext.get(),
                                         fClip, path, paint,
                                         *draw.fMatrix, nullptr,
                                         draw.fRC->getBounds(), true);
@@ -701,7 +702,7 @@
     CHECK_SHOULD_DRAW(draw);
     GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawPath", fContext);
 
-    GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext,
+    GrBlurUtils::drawPathWithMaskFilter(fContext, fDrawContext.get(),
                                         fClip, origSrcPath, paint,
                                         *draw.fMatrix, prePathMatrix,
                                         draw.fRC->getBounds(), pathIsMutable);
diff --git a/src/gpu/SkGpuDevice.h b/src/gpu/SkGpuDevice.h
index ca0488b..1e8d301d 100644
--- a/src/gpu/SkGpuDevice.h
+++ b/src/gpu/SkGpuDevice.h
@@ -146,7 +146,7 @@
     // We want these unreffed in DrawContext, RenderTarget, GrContext order.
     SkAutoTUnref<GrContext>         fContext;
     SkAutoTUnref<GrRenderTarget>    fRenderTarget;
-    SkAutoTUnref<GrDrawContext>     fDrawContext;
+    sk_sp<GrDrawContext>            fDrawContext;
 
     SkAutoTUnref<const SkClipStack> fClipStack;
     SkIPoint                        fClipOrigin;
diff --git a/src/gpu/SkGpuDevice_drawTexture.cpp b/src/gpu/SkGpuDevice_drawTexture.cpp
index 7abe49c..9750c96 100644
--- a/src/gpu/SkGpuDevice_drawTexture.cpp
+++ b/src/gpu/SkGpuDevice_drawTexture.cpp
@@ -228,7 +228,7 @@
     SkRRect rrect;
     rrect.setRect(clippedDstRect);
     if (mf->directFilterRRectMaskGPU(fContext->textureProvider(),
-                                      fDrawContext,
+                                      fDrawContext.get(),
                                       &grPaint,
                                       clip,
                                       viewMatrix,
@@ -239,7 +239,7 @@
     SkPath rectPath;
     rectPath.addRect(clippedDstRect);
     rectPath.setIsVolatile(true);
-    GrBlurUtils::drawPathWithMaskFilter(this->context(), fDrawContext, fClip,
+    GrBlurUtils::drawPathWithMaskFilter(this->context(), fDrawContext.get(), fClip,
                                         rectPath, &grPaint, viewMatrix, mf, paint.getPathEffect(),
                                         GrStrokeInfo::FillInfo(), true);
 }
diff --git a/src/gpu/effects/GrConfigConversionEffect.cpp b/src/gpu/effects/GrConfigConversionEffect.cpp
index 4743f34..6b43606 100644
--- a/src/gpu/effects/GrConfigConversionEffect.cpp
+++ b/src/gpu/effects/GrConfigConversionEffect.cpp
@@ -225,8 +225,8 @@
         paint1.setPorterDuffXPFactory(SkXfermode::kSrc_Mode);
 
 
-        SkAutoTUnref<GrDrawContext> readDrawContext(
-                                    context->drawContext(readTex->asRenderTarget()));
+        sk_sp<GrDrawContext> readDrawContext(
+                                    context->drawContext(sk_ref_sp(readTex->asRenderTarget())));
         if (!readDrawContext) {
             failed = true;
             break;
@@ -243,8 +243,8 @@
         paint2.addColorFragmentProcessor(upmToPM);
         paint2.setPorterDuffXPFactory(SkXfermode::kSrc_Mode);
 
-        SkAutoTUnref<GrDrawContext> tempDrawContext(
-                                    context->drawContext(tempTex->asRenderTarget()));
+        sk_sp<GrDrawContext> tempDrawContext(
+                                    context->drawContext(sk_ref_sp(tempTex->asRenderTarget())));
         if (!tempDrawContext) {
             failed = true;
             break;
@@ -258,7 +258,7 @@
         paint3.addColorFragmentProcessor(pmToUPM2);
         paint3.setPorterDuffXPFactory(SkXfermode::kSrc_Mode);
 
-        readDrawContext.reset(context->drawContext(readTex->asRenderTarget()));
+        readDrawContext = context->drawContext(sk_ref_sp(readTex->asRenderTarget()));
         if (!readDrawContext) {
             failed = true;
             break;
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp
index 359c775..a66a623 100644
--- a/src/image/SkImage_Gpu.cpp
+++ b/src/image/SkImage_Gpu.cpp
@@ -270,7 +270,7 @@
 
     const SkRect rect = SkRect::MakeWH(SkIntToScalar(dstDesc.fWidth),
                                        SkIntToScalar(dstDesc.fHeight));
-    SkAutoTUnref<GrDrawContext> drawContext(ctx->drawContext(dst->asRenderTarget()));
+    sk_sp<GrDrawContext> drawContext(ctx->drawContext(sk_ref_sp(dst->asRenderTarget())));
     if (!drawContext) {
         return nullptr;
     }
diff --git a/tests/ClearTest.cpp b/tests/ClearTest.cpp
index 56f2fe1..1065d94 100644
--- a/tests/ClearTest.cpp
+++ b/tests/ClearTest.cpp
@@ -39,7 +39,7 @@
 
 // We only really need the DC, but currently the DC doesn't own the RT so we also ref it, but that
 // could be dropped when DC is a proper owner of its RT.
-static bool reset_dc(SkAutoTUnref<GrDrawContext>* dc, SkAutoTUnref<GrSurface>* rtKeepAlive,
+static bool reset_dc(sk_sp<GrDrawContext>* dc, SkAutoTUnref<GrSurface>* rtKeepAlive,
                      GrContext* context, int w, int h) {
     SkDEBUGCODE(uint32_t oldID = 0;)
     if (*dc) {
@@ -61,7 +61,7 @@
     }
     GrRenderTarget* rt = (*rtKeepAlive)->asRenderTarget();
     SkASSERT(rt->getUniqueID() != oldID);
-    dc->reset(context->drawContext(rt));
+    *dc = context->drawContext(sk_ref_sp(rt));
     return *dc != nullptr;
 }
 
@@ -71,7 +71,7 @@
     static const int kH = 10;
 
     SkIRect fullRect = SkIRect::MakeWH(kW, kH);
-    SkAutoTUnref<GrDrawContext> drawContext;
+    sk_sp<GrDrawContext> drawContext;
     SkAutoTUnref<GrSurface> rtKeepAlive;
 
     // A rectangle that is inset by one on all sides and the 1-pixel wide rectangles that surround
@@ -102,7 +102,7 @@
     }
     // Check a full clear
     drawContext->clear(&fullRect, kColor1, false);
-    if (!check_rect(drawContext, fullRect, kColor1, &actualValue, &failX, &failY)) {
+    if (!check_rect(drawContext.get(), fullRect, kColor1, &actualValue, &failX, &failY)) {
         ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue,
                failX, failY);
     }
@@ -114,7 +114,7 @@
     // Check two full clears, same color
     drawContext->clear(&fullRect, kColor1, false);
     drawContext->clear(&fullRect, kColor1, false);
-    if (!check_rect(drawContext, fullRect, kColor1, &actualValue, &failX, &failY)) {
+    if (!check_rect(drawContext.get(), fullRect, kColor1, &actualValue, &failX, &failY)) {
         ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue,
                failX, failY);
     }
@@ -126,7 +126,7 @@
     // Check two full clears, different colors
     drawContext->clear(&fullRect, kColor1, false);
     drawContext->clear(&fullRect, kColor2, false);
-    if (!check_rect(drawContext, fullRect, kColor2, &actualValue, &failX, &failY)) {
+    if (!check_rect(drawContext.get(), fullRect, kColor2, &actualValue, &failX, &failY)) {
         ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor2, actualValue,
                failX, failY);
     }
@@ -138,7 +138,7 @@
     // Test a full clear followed by a same color inset clear
     drawContext->clear(&fullRect, kColor1, false);
     drawContext->clear(&mid1Rect, kColor1, false);
-    if (!check_rect(drawContext, fullRect, kColor1, &actualValue, &failX, &failY)) {
+    if (!check_rect(drawContext.get(), fullRect, kColor1, &actualValue, &failX, &failY)) {
         ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue,
                failX, failY);
     }
@@ -150,7 +150,7 @@
     // Test a inset clear followed by same color full clear
     drawContext->clear(&mid1Rect, kColor1, false);
     drawContext->clear(&fullRect, kColor1, false);
-    if (!check_rect(drawContext, fullRect, kColor1, &actualValue, &failX, &failY)) {
+    if (!check_rect(drawContext.get(), fullRect, kColor1, &actualValue, &failX, &failY)) {
         ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue,
                failX, failY);
     }
@@ -162,14 +162,14 @@
     // Test a full clear followed by a different color inset clear
     drawContext->clear(&fullRect, kColor1, false);
     drawContext->clear(&mid1Rect, kColor2, false);
-    if (!check_rect(drawContext, mid1Rect, kColor2, &actualValue, &failX, &failY)) {
+    if (!check_rect(drawContext.get(), mid1Rect, kColor2, &actualValue, &failX, &failY)) {
         ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor2, actualValue,
                failX, failY);
     }
-    if (!check_rect(drawContext, outerLeftEdge, kColor1, &actualValue, &failX, &failY) ||
-        !check_rect(drawContext, outerTopEdge, kColor1, &actualValue, &failX, &failY) ||
-        !check_rect(drawContext, outerRightEdge, kColor1, &actualValue, &failX, &failY) ||
-        !check_rect(drawContext, outerBottomEdge, kColor1, &actualValue, &failX, &failY)) {
+    if (!check_rect(drawContext.get(), outerLeftEdge, kColor1, &actualValue, &failX, &failY) ||
+        !check_rect(drawContext.get(), outerTopEdge, kColor1, &actualValue, &failX, &failY) ||
+        !check_rect(drawContext.get(), outerRightEdge, kColor1, &actualValue, &failX, &failY) ||
+        !check_rect(drawContext.get(), outerBottomEdge, kColor1, &actualValue, &failX, &failY)) {
         ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue,
                failX, failY);
     }
@@ -181,7 +181,7 @@
     // Test a inset clear followed by a different full clear
     drawContext->clear(&mid1Rect, kColor2, false);
     drawContext->clear(&fullRect, kColor1, false);
-    if (!check_rect(drawContext, fullRect, kColor1, &actualValue, &failX, &failY)) {
+    if (!check_rect(drawContext.get(), fullRect, kColor1, &actualValue, &failX, &failY)) {
         ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue,
                failX, failY);
     }
@@ -195,21 +195,21 @@
     drawContext->clear(&fullRect, kColor1, false);
     drawContext->clear(&mid1Rect, kColor2, false);
     drawContext->clear(&mid2Rect, kColor1, false);
-    if (!check_rect(drawContext, mid2Rect, kColor1, &actualValue, &failX, &failY)) {
+    if (!check_rect(drawContext.get(), mid2Rect, kColor1, &actualValue, &failX, &failY)) {
         ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue,
                failX, failY);
     }
-    if (!check_rect(drawContext, innerLeftEdge, kColor2, &actualValue, &failX, &failY) ||
-        !check_rect(drawContext, innerTopEdge, kColor2, &actualValue, &failX, &failY) ||
-        !check_rect(drawContext, innerRightEdge, kColor2, &actualValue, &failX, &failY) ||
-        !check_rect(drawContext, innerBottomEdge, kColor2, &actualValue, &failX, &failY)) {
+    if (!check_rect(drawContext.get(), innerLeftEdge, kColor2, &actualValue, &failX, &failY) ||
+        !check_rect(drawContext.get(), innerTopEdge, kColor2, &actualValue, &failX, &failY) ||
+        !check_rect(drawContext.get(), innerRightEdge, kColor2, &actualValue, &failX, &failY) ||
+        !check_rect(drawContext.get(), innerBottomEdge, kColor2, &actualValue, &failX, &failY)) {
         ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor2, actualValue,
                failX, failY);
     }
-    if (!check_rect(drawContext, outerLeftEdge, kColor1, &actualValue, &failX, &failY) ||
-        !check_rect(drawContext, outerTopEdge, kColor1, &actualValue, &failX, &failY) ||
-        !check_rect(drawContext, outerRightEdge, kColor1, &actualValue, &failX, &failY) ||
-        !check_rect(drawContext, outerBottomEdge, kColor1, &actualValue, &failX, &failY)) {
+    if (!check_rect(drawContext.get(), outerLeftEdge, kColor1, &actualValue, &failX, &failY) ||
+        !check_rect(drawContext.get(), outerTopEdge, kColor1, &actualValue, &failX, &failY) ||
+        !check_rect(drawContext.get(), outerRightEdge, kColor1, &actualValue, &failX, &failY) ||
+        !check_rect(drawContext.get(), outerBottomEdge, kColor1, &actualValue, &failX, &failY)) {
         ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue,
                failX, failY);
     }
@@ -222,14 +222,14 @@
     drawContext->clear(&fullRect, kColor1, false);
     drawContext->clear(&mid2Rect, kColor1, false);
     drawContext->clear(&mid1Rect, kColor2, false);
-    if (!check_rect(drawContext, mid1Rect, kColor2, &actualValue, &failX, &failY)) {
+    if (!check_rect(drawContext.get(), mid1Rect, kColor2, &actualValue, &failX, &failY)) {
         ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor2, actualValue,
                failX, failY);
     }
-    if (!check_rect(drawContext, outerLeftEdge, kColor1, &actualValue, &failX, &failY) ||
-        !check_rect(drawContext, outerTopEdge, kColor1, &actualValue, &failX, &failY) ||
-        !check_rect(drawContext, outerRightEdge, kColor1, &actualValue, &failX, &failY) ||
-        !check_rect(drawContext, outerBottomEdge, kColor1, &actualValue, &failX, &failY)) {
+    if (!check_rect(drawContext.get(), outerLeftEdge, kColor1, &actualValue, &failX, &failY) ||
+        !check_rect(drawContext.get(), outerTopEdge, kColor1, &actualValue, &failX, &failY) ||
+        !check_rect(drawContext.get(), outerRightEdge, kColor1, &actualValue, &failX, &failY) ||
+        !check_rect(drawContext.get(), outerBottomEdge, kColor1, &actualValue, &failX, &failY)) {
         ERRORF(reporter, "Expected 0x%08x but got 0x%08x at (%d, %d).", kColor1, actualValue,
                failX, failY);
     }
diff --git a/tests/GLProgramsTest.cpp b/tests/GLProgramsTest.cpp
index 8e7d800..0d825c6 100644
--- a/tests/GLProgramsTest.cpp
+++ b/tests/GLProgramsTest.cpp
@@ -334,7 +334,7 @@
     static const int NUM_TESTS = 1024;
     for (int t = 0; t < NUM_TESTS; t++) {
         // setup random render target(can fail)
-        SkAutoTUnref<GrRenderTarget> rt(random_render_target(
+        sk_sp<GrRenderTarget> rt(random_render_target(
             context->textureProvider(), &random, context->caps()));
         if (!rt.get()) {
             SkDebugf("Could not allocate render target");
@@ -348,13 +348,13 @@
         SkAutoTUnref<GrDrawBatch> batch(GrRandomDrawBatch(&random, context));
         SkASSERT(batch);
 
-        GrProcessorTestData ptd(&random, context, context->caps(), rt, dummyTextures);
+        GrProcessorTestData ptd(&random, context, context->caps(), rt.get(), dummyTextures);
         set_random_color_coverage_stages(&pipelineBuilder, &ptd, maxStages);
         set_random_xpf(&pipelineBuilder, &ptd);
         set_random_state(&pipelineBuilder, &random);
         set_random_stencil(&pipelineBuilder, &random);
 
-        SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(rt));
+        sk_sp<GrDrawContext> drawContext(context->drawContext(rt));
         if (!drawContext) {
             SkDebugf("Could not allocate drawContext");
             return false;
@@ -371,7 +371,7 @@
     rtDesc.fHeight = kRenderTargetHeight;
     rtDesc.fFlags = kRenderTarget_GrSurfaceFlag;
     rtDesc.fConfig = kRGBA_8888_GrPixelConfig;
-    SkAutoTUnref<GrRenderTarget> rt(
+    sk_sp<GrRenderTarget> rt(
         context->textureProvider()->createTexture(rtDesc, SkBudgeted::kNo)->asRenderTarget());
     int fpFactoryCnt = GrProcessorTestFactory<GrFragmentProcessor>::Count();
     for (int i = 0; i < fpFactoryCnt; ++i) {
@@ -379,10 +379,10 @@
         for (int j = 0; j < 10; ++j) {
             SkAutoTUnref<GrDrawBatch> batch(GrRandomDrawBatch(&random, context));
             SkASSERT(batch);
-            GrProcessorTestData ptd(&random, context, context->caps(), rt, dummyTextures);
+            GrProcessorTestData ptd(&random, context, context->caps(), rt.get(), dummyTextures);
             GrPipelineBuilder builder;
             builder.setXPFactory(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode))->unref();
-            builder.setRenderTarget(rt);
+            builder.setRenderTarget(rt.get());
             builder.setClip(clip);
 
             SkAutoTUnref<const GrFragmentProcessor> fp(
@@ -391,7 +391,7 @@
                 BlockInputFragmentProcessor::Create(fp));
             builder.addColorFragmentProcessor(blockFP);
 
-            SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(rt));
+            sk_sp<GrDrawContext> drawContext(context->drawContext(rt));
             if (!drawContext) {
                 SkDebugf("Could not allocate a drawcontext");
                 return false;
diff --git a/tests/PrimitiveProcessorTest.cpp b/tests/PrimitiveProcessorTest.cpp
index f8c19e3..6d4ede1 100644
--- a/tests/PrimitiveProcessorTest.cpp
+++ b/tests/PrimitiveProcessorTest.cpp
@@ -114,7 +114,7 @@
         ERRORF(reporter, "Could not create render target.");
         return;
     }
-    SkAutoTUnref<GrDrawContext> dc(context->drawContext(target->asRenderTarget()));
+    sk_sp<GrDrawContext> dc(context->drawContext(sk_ref_sp(target->asRenderTarget())));
     if (!dc) {
         ERRORF(reporter, "Could not create draw context.");
         return;
diff --git a/tests/RectangleTextureTest.cpp b/tests/RectangleTextureTest.cpp
index 3c2a50d..8c3bdd6 100644
--- a/tests/RectangleTextureTest.cpp
+++ b/tests/RectangleTextureTest.cpp
@@ -89,7 +89,8 @@
 static void test_clear(skiatest::Reporter* reporter, GrContext* context,
                        GrTexture* rectangleTexture) {
     if (rectangleTexture->asRenderTarget()) {
-        SkAutoTUnref<GrDrawContext> dc(context->drawContext(rectangleTexture->asRenderTarget()));
+        sk_sp<GrDrawContext> dc(
+                            context->drawContext(sk_ref_sp(rectangleTexture->asRenderTarget())));
         if (!dc) {
             ERRORF(reporter, "Could not get GrDrawContext for rectangle texture.");
             return;