Remove SkAutoTUnref and SkAutoTDelete from public includes.

This also makes the required changed to src, tests, and tools. The few
public APIs modified by this change appear to be unused outside of Skia.

Removing these from the public API makes it easier to ensure users are
no longer using them.

This also updates GrGpu::wrapBackendXXX and the
::onWrapBackendXXX methods to clarify ownership.

GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2448593002

Review-Url: https://codereview.chromium.org/2448593002
diff --git a/src/gpu/GrAuditTrail.cpp b/src/gpu/GrAuditTrail.cpp
index 82dc7f7..ff6debd 100644
--- a/src/gpu/GrAuditTrail.cpp
+++ b/src/gpu/GrAuditTrail.cpp
@@ -88,7 +88,7 @@
 
 void GrAuditTrail::copyOutFromBatchList(BatchInfo* outBatchInfo, int batchListID) {
     SkASSERT(batchListID < fBatchList.count());
-    const BatchNode* bn = fBatchList[batchListID];
+    const BatchNode* bn = fBatchList[batchListID].get();
     SkASSERT(bn);
     outBatchInfo->fBounds = bn->fBounds;
     outBatchInfo->fRenderTargetUniqueID = bn->fRenderTargetUniqueID;
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index a0884f9..dfb2fce 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -132,11 +132,11 @@
     fCaps->unref();
 }
 
-GrContextThreadSafeProxy* GrContext::threadSafeProxy() {
+sk_sp<GrContextThreadSafeProxy> GrContext::threadSafeProxy() {
     if (!fThreadSafeProxy) {
-        fThreadSafeProxy.reset(new GrContextThreadSafeProxy(fCaps, this->uniqueID()));
+        fThreadSafeProxy.reset(new GrContextThreadSafeProxy(sk_ref_sp(fCaps), this->uniqueID()));
     }
-    return SkRef(fThreadSafeProxy.get());
+    return fThreadSafeProxy;
 }
 
 void GrContext::abandonContext() {
diff --git a/src/gpu/GrContextPriv.h b/src/gpu/GrContextPriv.h
index 29eb151..398fc8a 100644
--- a/src/gpu/GrContextPriv.h
+++ b/src/gpu/GrContextPriv.h
@@ -15,7 +15,7 @@
     data members or virtual methods. */
 class GrContextPriv {
 public:
-    GrDrawingManager* drawingManager() { return fContext->fDrawingManager; }
+    GrDrawingManager* drawingManager() { return fContext->fDrawingManager.get(); }
 
     // Create a drawContext that wraps an existing renderTarget
     sk_sp<GrDrawContext> makeWrappedDrawContext(sk_sp<GrRenderTarget> rt,
diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp
index 0de9fed..f576424 100644
--- a/src/gpu/GrGpu.cpp
+++ b/src/gpu/GrGpu.cpp
@@ -190,7 +190,8 @@
     return tex;
 }
 
-GrTexture* GrGpu::wrapBackendTexture(const GrBackendTextureDesc& desc, GrWrapOwnership ownership) {
+sk_sp<GrTexture> GrGpu::wrapBackendTexture(const GrBackendTextureDesc& desc,
+                                           GrWrapOwnership ownership) {
     this->handleDirtyContext();
     if (!this->caps()->isConfigTexturable(desc.fConfig)) {
         return nullptr;
@@ -203,22 +204,20 @@
     if (desc.fWidth > maxSize || desc.fHeight > maxSize) {
         return nullptr;
     }
-    GrTexture* tex = this->onWrapBackendTexture(desc, ownership);
-    if (nullptr == tex) {
+    sk_sp<GrTexture> tex = this->onWrapBackendTexture(desc, ownership);
+    if (!tex) {
         return nullptr;
     }
     // TODO: defer this and attach dynamically
     GrRenderTarget* tgt = tex->asRenderTarget();
     if (tgt && !fContext->resourceProvider()->attachStencilAttachment(tgt)) {
-        tex->unref();
         return nullptr;
-    } else {
-        return tex;
     }
+    return tex;
 }
 
-GrRenderTarget* GrGpu::wrapBackendRenderTarget(const GrBackendRenderTargetDesc& desc,
-                                               GrWrapOwnership ownership) {
+sk_sp<GrRenderTarget> GrGpu::wrapBackendRenderTarget(const GrBackendRenderTargetDesc& desc,
+                                                     GrWrapOwnership ownership) {
     if (!this->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) {
         return nullptr;
     }
@@ -226,7 +225,7 @@
     return this->onWrapBackendRenderTarget(desc, ownership);
 }
 
-GrRenderTarget* GrGpu::wrapBackendTextureAsRenderTarget(const GrBackendTextureDesc& desc) {
+sk_sp<GrRenderTarget> GrGpu::wrapBackendTextureAsRenderTarget(const GrBackendTextureDesc& desc) {
     this->handleDirtyContext();
     if (!(desc.fFlags & kRenderTarget_GrBackendTextureFlag)) {
       return nullptr;
diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h
index ba7ed6f..8e9407a 100644
--- a/src/gpu/GrGpu.h
+++ b/src/gpu/GrGpu.h
@@ -124,17 +124,17 @@
     /**
      * Implements GrTextureProvider::wrapBackendTexture
      */
-    GrTexture* wrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership);
+    sk_sp<GrTexture> wrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership);
 
     /**
      * Implements GrTextureProvider::wrapBackendRenderTarget
      */
-    GrRenderTarget* wrapBackendRenderTarget(const GrBackendRenderTargetDesc&, GrWrapOwnership);
+    sk_sp<GrRenderTarget> wrapBackendRenderTarget(const GrBackendRenderTargetDesc&,GrWrapOwnership);
 
     /**
      * Implements GrTextureProvider::wrapBackendTextureAsRenderTarget
      */
-    GrRenderTarget* wrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&);
+    sk_sp<GrRenderTarget> wrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&);
 
     /**
      * Creates a buffer in GPU memory. For a client-side buffer use GrBuffer::CreateCPUBacked.
@@ -532,10 +532,10 @@
                                                  SkBudgeted budgeted,
                                                  const SkTArray<GrMipLevel>& texels) = 0;
 
-    virtual GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership) = 0;
-    virtual GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&,
-                                                      GrWrapOwnership) = 0;
-    virtual GrRenderTarget* onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&) = 0;
+    virtual sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership) = 0;
+    virtual sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&,
+                                                            GrWrapOwnership) = 0;
+    virtual sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&)=0;
     virtual GrBuffer* onCreateBuffer(size_t size, GrBufferType intendedType, GrAccessPattern,
                                      const void* data) = 0;
 
diff --git a/src/gpu/GrRenderTargetOpList.cpp b/src/gpu/GrRenderTargetOpList.cpp
index e641e74..3eb047c 100644
--- a/src/gpu/GrRenderTargetOpList.cpp
+++ b/src/gpu/GrRenderTargetOpList.cpp
@@ -113,7 +113,7 @@
         if (GrTexture* rtTex = rt->asTexture()) {
             // The render target is a texture, so we can read from it directly in the shader. The XP
             // will be responsible to detect this situation and request a texture barrier.
-            dstTexture->setTexture(rtTex);
+            dstTexture->setTexture(sk_ref_sp(rtTex));
             dstTexture->setOffset(0, 0);
             return true;
         }
@@ -145,15 +145,15 @@
     desc.fHeight = copyRect.height();
 
     static const uint32_t kFlags = 0;
-    SkAutoTUnref<GrTexture> copy(fResourceProvider->createApproxTexture(desc, kFlags));
+    sk_sp<GrTexture> copy(fResourceProvider->createApproxTexture(desc, kFlags));
 
     if (!copy) {
         SkDebugf("Failed to create temporary copy of destination texture.\n");
         return false;
     }
     SkIPoint dstPoint = {0, 0};
-    this->copySurface(copy, rt, copyRect, dstPoint);
-    dstTexture->setTexture(copy);
+    this->copySurface(copy.get(), rt, copyRect, dstPoint);
+    dstTexture->setTexture(std::move(copy));
     dstTexture->setOffset(copyRect.fLeft, copyRect.fTop);
     return true;
 }
diff --git a/src/gpu/GrResourceProvider.cpp b/src/gpu/GrResourceProvider.cpp
index b63a7ea..9739b05 100644
--- a/src/gpu/GrResourceProvider.cpp
+++ b/src/gpu/GrResourceProvider.cpp
@@ -205,8 +205,9 @@
     return rt->renderTargetPriv().getStencilAttachment();
 }
 
-GrRenderTarget* GrResourceProvider::wrapBackendTextureAsRenderTarget(
-        const GrBackendTextureDesc& desc) {
+sk_sp<GrRenderTarget> GrResourceProvider::wrapBackendTextureAsRenderTarget(
+        const GrBackendTextureDesc& desc)
+{
     if (this->isAbandoned()) {
         return nullptr;
     }
diff --git a/src/gpu/GrResourceProvider.h b/src/gpu/GrResourceProvider.h
index 4c90cdd..c29a40a 100644
--- a/src/gpu/GrResourceProvider.h
+++ b/src/gpu/GrResourceProvider.h
@@ -164,7 +164,7 @@
       *
       * @return GrRenderTarget object or NULL on failure.
       */
-     GrRenderTarget* wrapBackendTextureAsRenderTarget(const GrBackendTextureDesc& desc);
+     sk_sp<GrRenderTarget> wrapBackendTextureAsRenderTarget(const GrBackendTextureDesc& desc);
 
 private:
     const GrBuffer* createInstancedIndexBuffer(const uint16_t* pattern,
diff --git a/src/gpu/GrTextureProvider.cpp b/src/gpu/GrTextureProvider.cpp
index 68a5540..dba24b5 100644
--- a/src/gpu/GrTextureProvider.cpp
+++ b/src/gpu/GrTextureProvider.cpp
@@ -158,8 +158,8 @@
     return nullptr;
 }
 
-GrTexture* GrTextureProvider::wrapBackendTexture(const GrBackendTextureDesc& desc,
-                                                 GrWrapOwnership ownership) {
+sk_sp<GrTexture> GrTextureProvider::wrapBackendTexture(const GrBackendTextureDesc& desc,
+                                                       GrWrapOwnership ownership) {
     ASSERT_SINGLE_OWNER
     if (this->isAbandoned()) {
         return nullptr;
@@ -167,10 +167,12 @@
     return fGpu->wrapBackendTexture(desc, ownership);
 }
 
-GrRenderTarget* GrTextureProvider::wrapBackendRenderTarget(const GrBackendRenderTargetDesc& desc) {
+sk_sp<GrRenderTarget> GrTextureProvider::wrapBackendRenderTarget(
+    const GrBackendRenderTargetDesc& desc)
+{
     ASSERT_SINGLE_OWNER
-    return this->isAbandoned() ? nullptr : fGpu->wrapBackendRenderTarget(desc,
-                                                                         kBorrow_GrWrapOwnership);
+    return this->isAbandoned() ? nullptr
+                               : fGpu->wrapBackendRenderTarget(desc, kBorrow_GrWrapOwnership);
 }
 
 void GrTextureProvider::assignUniqueKeyToResource(const GrUniqueKey& key, GrGpuResource* resource) {
diff --git a/src/gpu/gl/GrGLExtensions.cpp b/src/gpu/gl/GrGLExtensions.cpp
index 43a147d..29f7799 100644
--- a/src/gpu/gl/GrGLExtensions.cpp
+++ b/src/gpu/gl/GrGLExtensions.cpp
@@ -9,6 +9,7 @@
 #include "gl/GrGLDefines.h"
 #include "gl/GrGLUtil.h"
 
+#include "SkMakeUnique.h"
 #include "SkTSearch.h"
 #include "SkTSort.h"
 
@@ -99,12 +100,12 @@
         if (!extensions) {
             return false;
         }
-        eat_space_sep_strings(fStrings, extensions);
+        eat_space_sep_strings(fStrings.get(), extensions);
     }
     if (queryString) {
         const char* extensions = queryString(eglDisplay, GR_EGL_EXTENSIONS);
 
-        eat_space_sep_strings(fStrings, extensions);
+        eat_space_sep_strings(fStrings.get(), extensions);
     }
     if (!fStrings->empty()) {
         SkTLessFunctionToFunctorAdaptor<SkString, extension_compare> cmp;
@@ -122,27 +123,26 @@
 bool GrGLExtensions::remove(const char ext[]) {
     SkASSERT(fInitialized);
     int idx = find_string(*fStrings, ext);
-    if (idx >= 0) {
-        // This is not terribly effecient but we really only expect this function to be called at
-        // most a handful of times when our test programs start.
-        SkAutoTDelete< SkTArray<SkString> > oldStrings(fStrings.release());
-        fStrings.reset(new SkTArray<SkString>(oldStrings->count() - 1));
-        fStrings->push_back_n(idx, &oldStrings->front());
-        fStrings->push_back_n(oldStrings->count() - idx - 1, &(*oldStrings)[idx] + 1);
-        return true;
-    } else {
+    if (idx < 0) {
         return false;
     }
+
+    // This is not terribly effecient but we really only expect this function to be called at
+    // most a handful of times when our test programs start.
+    fStrings->removeShuffle(idx);
+    SkTLessFunctionToFunctorAdaptor<SkString, extension_compare> cmp;
+    SkTInsertionSort(&(fStrings->operator[](idx)), &fStrings->back(), cmp);
+    return true;
 }
 
 void GrGLExtensions::add(const char ext[]) {
     int idx = find_string(*fStrings, ext);
     if (idx < 0) {
-        // This is not the most effecient approach since we end up doing a full sort of the
+        // This is not the most effecient approach since we end up looking at all of the
         // extensions after the add
-        fStrings->push_back().set(ext);
+        fStrings->emplace_back(ext);
         SkTLessFunctionToFunctorAdaptor<SkString, extension_compare> cmp;
-        SkTQSort(&fStrings->front(), &fStrings->back(), cmp);
+        SkTInsertionSort(&fStrings->front(), &fStrings->back(), cmp);
     }
 }
 
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index 4e579cc..485a9bd 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -624,8 +624,8 @@
     }
 }
 
-GrTexture* GrGLGpu::onWrapBackendTexture(const GrBackendTextureDesc& desc,
-                                         GrWrapOwnership ownership) {
+sk_sp<GrTexture> GrGLGpu::onWrapBackendTexture(const GrBackendTextureDesc& desc,
+                                               GrWrapOwnership ownership) {
     const GrGLTextureInfo* info = reinterpret_cast<const GrGLTextureInfo*>(desc.fTextureHandle);
     if (!info || !info->fID) {
         return nullptr;
@@ -681,25 +681,18 @@
         surfDesc.fOrigin = desc.fOrigin;
     }
 
-    GrGLTexture* texture = nullptr;
     if (renderTarget) {
         GrGLRenderTarget::IDDesc rtIDDesc;
         if (!this->createRenderTargetObjects(surfDesc, idDesc.fInfo, &rtIDDesc)) {
             return nullptr;
         }
-        texture = GrGLTextureRenderTarget::CreateWrapped(this, surfDesc, idDesc, rtIDDesc);
-    } else {
-        texture = GrGLTexture::CreateWrapped(this, surfDesc, idDesc);
+        return GrGLTextureRenderTarget::MakeWrapped(this, surfDesc, idDesc, rtIDDesc);
     }
-    if (nullptr == texture) {
-        return nullptr;
-    }
-
-    return texture;
+    return GrGLTexture::MakeWrapped(this, surfDesc, idDesc);
 }
 
-GrRenderTarget* GrGLGpu::onWrapBackendRenderTarget(const GrBackendRenderTargetDesc& wrapDesc,
-                                                   GrWrapOwnership ownership) {
+sk_sp<GrRenderTarget> GrGLGpu::onWrapBackendRenderTarget(const GrBackendRenderTargetDesc& wrapDesc,
+                                                         GrWrapOwnership ownership) {
     GrGLRenderTarget::IDDesc idDesc;
     idDesc.fRTFBOID = static_cast<GrGLuint>(wrapDesc.fRenderTargetHandle);
     idDesc.fMSColorRenderbufferID = 0;
@@ -719,10 +712,10 @@
     desc.fSampleCnt = SkTMin(wrapDesc.fSampleCnt, this->caps()->maxSampleCount());
     desc.fOrigin = resolve_origin(wrapDesc.fOrigin, true);
 
-    return GrGLRenderTarget::CreateWrapped(this, desc, idDesc, wrapDesc.fStencilBits);
+    return GrGLRenderTarget::MakeWrapped(this, desc, idDesc, wrapDesc.fStencilBits);
 }
 
-GrRenderTarget* GrGLGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc& desc) {
+sk_sp<GrRenderTarget> GrGLGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc& desc){
     const GrGLTextureInfo* info = reinterpret_cast<const GrGLTextureInfo*>(desc.fTextureHandle);
     if (!info || !info->fID) {
         return nullptr;
@@ -759,7 +752,7 @@
     if (!this->createRenderTargetObjects(surfDesc, texInfo, &rtIDDesc)) {
         return nullptr;
     }
-    return GrGLRenderTarget::CreateWrapped(this, surfDesc, rtIDDesc, 0);
+    return GrGLRenderTarget::MakeWrapped(this, surfDesc, rtIDDesc, 0);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
diff --git a/src/gpu/gl/GrGLGpu.h b/src/gpu/gl/GrGLGpu.h
index 29d20e4..4420c65 100644
--- a/src/gpu/gl/GrGLGpu.h
+++ b/src/gpu/gl/GrGLGpu.h
@@ -164,10 +164,10 @@
 
     GrBuffer* onCreateBuffer(size_t size, GrBufferType intendedType, GrAccessPattern,
                              const void* data) override;
-    GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership) override;
-    GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&,
-                                              GrWrapOwnership) override;
-    GrRenderTarget* onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&) override;
+    sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership) override;
+    sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&,
+                                                    GrWrapOwnership) override;
+    sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&) override;
 
     gr_instanced::InstancedRendering* onCreateInstancedRendering() override;
 
diff --git a/src/gpu/gl/GrGLRenderTarget.cpp b/src/gpu/gl/GrGLRenderTarget.cpp
index f6ad3ba..65366bd 100644
--- a/src/gpu/gl/GrGLRenderTarget.cpp
+++ b/src/gpu/gl/GrGLRenderTarget.cpp
@@ -64,10 +64,10 @@
     SkASSERT(fGpuMemorySize <= WorstCaseSize(desc));
 }
 
-GrGLRenderTarget* GrGLRenderTarget::CreateWrapped(GrGLGpu* gpu,
-                                                  const GrSurfaceDesc& desc,
-                                                  const IDDesc& idDesc,
-                                                  int stencilBits) {
+sk_sp<GrGLRenderTarget> GrGLRenderTarget::MakeWrapped(GrGLGpu* gpu,
+                                                      const GrSurfaceDesc& desc,
+                                                      const IDDesc& idDesc,
+                                                      int stencilBits) {
     GrGLStencilAttachment* sb = nullptr;
     if (stencilBits) {
         GrGLStencilAttachment::IDDesc sbDesc;
@@ -80,7 +80,7 @@
         sb = new GrGLStencilAttachment(gpu, sbDesc, desc.fWidth, desc.fHeight,
                                        desc.fSampleCnt, format);
     }
-    return (new GrGLRenderTarget(gpu, desc, idDesc, sb));
+    return sk_sp<GrGLRenderTarget>(new GrGLRenderTarget(gpu, desc, idDesc, sb));
 }
 
 size_t GrGLRenderTarget::onGpuMemorySize() const {
diff --git a/src/gpu/gl/GrGLRenderTarget.h b/src/gpu/gl/GrGLRenderTarget.h
index 85e377f..08dd88d 100644
--- a/src/gpu/gl/GrGLRenderTarget.h
+++ b/src/gpu/gl/GrGLRenderTarget.h
@@ -31,10 +31,10 @@
         bool                       fIsMixedSampled;
     };
 
-    static GrGLRenderTarget* CreateWrapped(GrGLGpu*,
-                                           const GrSurfaceDesc&,
-                                           const IDDesc&,
-                                           int stencilBits);
+    static sk_sp<GrGLRenderTarget> MakeWrapped(GrGLGpu*,
+                                               const GrSurfaceDesc&,
+                                               const IDDesc&,
+                                               int stencilBits);
 
     void setViewport(const GrGLIRect& rect) { fViewport = rect; }
     const GrGLIRect& getViewport() const { return fViewport; }
diff --git a/src/gpu/gl/GrGLTexture.cpp b/src/gpu/gl/GrGLTexture.cpp
index ed75347..4653c5b 100644
--- a/src/gpu/gl/GrGLTexture.cpp
+++ b/src/gpu/gl/GrGLTexture.cpp
@@ -92,8 +92,8 @@
                                       texture_id.c_str());
 }
 
-GrGLTexture* GrGLTexture::CreateWrapped(GrGLGpu* gpu, const GrSurfaceDesc& desc,
-                                        const IDDesc& idDesc) {
-    return new GrGLTexture(gpu, kWrapped, desc, idDesc);
+sk_sp<GrGLTexture> GrGLTexture::MakeWrapped(GrGLGpu* gpu, const GrSurfaceDesc& desc,
+                                            const IDDesc& idDesc) {
+    return sk_sp<GrGLTexture>(new GrGLTexture(gpu, kWrapped, desc, idDesc));
 }
 
diff --git a/src/gpu/gl/GrGLTexture.h b/src/gpu/gl/GrGLTexture.h
index 05d26c8..ee027d7 100644
--- a/src/gpu/gl/GrGLTexture.h
+++ b/src/gpu/gl/GrGLTexture.h
@@ -56,7 +56,7 @@
 
     GrGLenum target() const { return fInfo.fTarget; }
 
-    static GrGLTexture* CreateWrapped(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&);
+    static sk_sp<GrGLTexture> MakeWrapped(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&);
 protected:
     // Constructor for subclasses.
     GrGLTexture(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&);
diff --git a/src/gpu/gl/GrGLTextureRenderTarget.cpp b/src/gpu/gl/GrGLTextureRenderTarget.cpp
index 2ba469a..9b37fbb 100644
--- a/src/gpu/gl/GrGLTextureRenderTarget.cpp
+++ b/src/gpu/gl/GrGLTextureRenderTarget.cpp
@@ -44,9 +44,10 @@
     return true;
 }
 
-GrGLTextureRenderTarget* GrGLTextureRenderTarget::CreateWrapped(GrGLGpu* gpu,
-                                                                const GrSurfaceDesc& desc,
-                                                                const GrGLTexture::IDDesc& texIDDesc,
-                                                                const GrGLRenderTarget::IDDesc& rtIDDesc) {
-    return new GrGLTextureRenderTarget(gpu, desc, texIDDesc, rtIDDesc);
+sk_sp<GrGLTextureRenderTarget> GrGLTextureRenderTarget::MakeWrapped(
+    GrGLGpu* gpu, const GrSurfaceDesc& desc,
+    const GrGLTexture::IDDesc& texIDDesc, const GrGLRenderTarget::IDDesc& rtIDDesc)
+{
+    return sk_sp<GrGLTextureRenderTarget>(
+        new GrGLTextureRenderTarget(gpu, desc, texIDDesc, rtIDDesc));
 }
diff --git a/src/gpu/gl/GrGLTextureRenderTarget.h b/src/gpu/gl/GrGLTextureRenderTarget.h
index 0826cf3..c5c020f 100644
--- a/src/gpu/gl/GrGLTextureRenderTarget.h
+++ b/src/gpu/gl/GrGLTextureRenderTarget.h
@@ -40,9 +40,9 @@
 
     void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const override;
 
-    static GrGLTextureRenderTarget* CreateWrapped(GrGLGpu* gpu, const GrSurfaceDesc& desc,
-                                                  const GrGLTexture::IDDesc& texIDDesc,
-                                                  const GrGLRenderTarget::IDDesc& rtIDDesc);
+    static sk_sp<GrGLTextureRenderTarget> MakeWrapped(GrGLGpu* gpu, const GrSurfaceDesc& desc,
+                                                      const GrGLTexture::IDDesc& texIDDesc,
+                                                      const GrGLRenderTarget::IDDesc& rtIDDesc);
 protected:
     void onAbandon() override {
         GrGLRenderTarget::onAbandon();
diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp
index b13e162..7d75921 100644
--- a/src/gpu/vk/GrVkGpu.cpp
+++ b/src/gpu/vk/GrVkGpu.cpp
@@ -756,8 +756,8 @@
     }
 }
 
-GrTexture* GrVkGpu::onWrapBackendTexture(const GrBackendTextureDesc& desc,
-                                         GrWrapOwnership ownership) {
+sk_sp<GrTexture> GrVkGpu::onWrapBackendTexture(const GrBackendTextureDesc& desc,
+                                               GrWrapOwnership ownership) {
     if (0 == desc.fTextureHandle) {
         return nullptr;
     }
@@ -791,22 +791,14 @@
     // In VK, we don't have this restriction
     surfDesc.fOrigin = resolve_origin(desc.fOrigin);
 
-    GrVkTexture* texture = nullptr;
-    if (renderTarget) {
-        texture = GrVkTextureRenderTarget::CreateWrappedTextureRenderTarget(this, surfDesc,
-                                                                            ownership, info);
-    } else {
-        texture = GrVkTexture::CreateWrappedTexture(this, surfDesc, ownership, info);
+    if (!renderTarget) {
+        return GrVkTexture::MakeWrappedTexture(this, surfDesc, ownership, info);
     }
-    if (!texture) {
-        return nullptr;
-    }
-
-    return texture;
+    return GrVkTextureRenderTarget::MakeWrappedTextureRenderTarget(this, surfDesc, ownership, info);
 }
 
-GrRenderTarget* GrVkGpu::onWrapBackendRenderTarget(const GrBackendRenderTargetDesc& wrapDesc,
-                                                   GrWrapOwnership ownership) {
+sk_sp<GrRenderTarget> GrVkGpu::onWrapBackendRenderTarget(const GrBackendRenderTargetDesc& wrapDesc,
+                                                         GrWrapOwnership ownership) {
 
     const GrVkImageInfo* info =
         reinterpret_cast<const GrVkImageInfo*>(wrapDesc.fRenderTargetHandle);
@@ -824,12 +816,10 @@
 
     desc.fOrigin = resolve_origin(wrapDesc.fOrigin);
 
-    GrVkRenderTarget* tgt = GrVkRenderTarget::CreateWrappedRenderTarget(this, desc,
-                                                                        ownership,
-                                                                        info);
+    sk_sp<GrVkRenderTarget> tgt = GrVkRenderTarget::MakeWrappedRenderTarget(this, desc,
+                                                                            ownership, info);
     if (tgt && wrapDesc.fStencilBits) {
-        if (!createStencilAttachmentForRenderTarget(tgt, desc.fWidth, desc.fHeight)) {
-            tgt->unref();
+        if (!createStencilAttachmentForRenderTarget(tgt.get(), desc.fWidth, desc.fHeight)) {
             return nullptr;
         }
     }
diff --git a/src/gpu/vk/GrVkGpu.h b/src/gpu/vk/GrVkGpu.h
index 77eb242..b622783 100644
--- a/src/gpu/vk/GrVkGpu.h
+++ b/src/gpu/vk/GrVkGpu.h
@@ -50,7 +50,7 @@
 
     ~GrVkGpu() override;
 
-    const GrVkInterface* vkInterface() const { return fBackendContext->fInterface; }
+    const GrVkInterface* vkInterface() const { return fBackendContext->fInterface.get(); }
     const GrVkCaps& vkCaps() const { return *fVkCaps; }
 
     VkDevice device() const { return fDevice; }
@@ -182,11 +182,13 @@
     GrTexture* onCreateCompressedTexture(const GrSurfaceDesc& desc, SkBudgeted,
                                          const SkTArray<GrMipLevel>&) override { return NULL; }
 
-    GrTexture* onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership) override;
+    sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTextureDesc&, GrWrapOwnership) override;
 
-    GrRenderTarget* onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&,
-                                              GrWrapOwnership) override;
-    GrRenderTarget* onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&) override { return NULL; }
+    sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTargetDesc&,
+                                                    GrWrapOwnership) override;
+    sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTextureDesc&) override {
+        return nullptr;
+    }
 
     GrBuffer* onCreateBuffer(size_t size, GrBufferType type, GrAccessPattern,
                              const void* data) override;
diff --git a/src/gpu/vk/GrVkRenderTarget.cpp b/src/gpu/vk/GrVkRenderTarget.cpp
index d6895d2..e2f0019 100644
--- a/src/gpu/vk/GrVkRenderTarget.cpp
+++ b/src/gpu/vk/GrVkRenderTarget.cpp
@@ -201,11 +201,11 @@
     return rt;
 }
 
-GrVkRenderTarget*
-GrVkRenderTarget::CreateWrappedRenderTarget(GrVkGpu* gpu,
-                                            const GrSurfaceDesc& desc,
-                                            GrWrapOwnership ownership,
-                                            const GrVkImageInfo* info) {
+sk_sp<GrVkRenderTarget>
+GrVkRenderTarget::MakeWrappedRenderTarget(GrVkGpu* gpu,
+                                          const GrSurfaceDesc& desc,
+                                          GrWrapOwnership ownership,
+                                          const GrVkImageInfo* info) {
     SkASSERT(info);
     // We can wrap a rendertarget without its allocation, as long as we don't take ownership
     SkASSERT(VK_NULL_HANDLE != info->fImage);
@@ -214,9 +214,8 @@
     GrVkImage::Wrapped wrapped = kBorrow_GrWrapOwnership == ownership ? GrVkImage::kBorrowed_Wrapped
                                                                       : GrVkImage::kAdopted_Wrapped;
 
-    GrVkRenderTarget* rt = GrVkRenderTarget::Create(gpu, SkBudgeted::kNo, desc, *info, wrapped);
-
-    return rt;
+    return sk_sp<GrVkRenderTarget>(
+        GrVkRenderTarget::Create(gpu, SkBudgeted::kNo, desc, *info, wrapped));
 }
 
 bool GrVkRenderTarget::completeStencilAttachment() {
diff --git a/src/gpu/vk/GrVkRenderTarget.h b/src/gpu/vk/GrVkRenderTarget.h
index e3ebefb..0855a6d 100644
--- a/src/gpu/vk/GrVkRenderTarget.h
+++ b/src/gpu/vk/GrVkRenderTarget.h
@@ -34,9 +34,9 @@
     static GrVkRenderTarget* CreateNewRenderTarget(GrVkGpu*, SkBudgeted, const GrSurfaceDesc&,
                                                    const GrVkImage::ImageDesc&);
 
-    static GrVkRenderTarget* CreateWrappedRenderTarget(GrVkGpu*, const GrSurfaceDesc&,
-                                                       GrWrapOwnership,
-                                                       const GrVkImageInfo*);
+    static sk_sp<GrVkRenderTarget> MakeWrappedRenderTarget(GrVkGpu*, const GrSurfaceDesc&,
+                                                           GrWrapOwnership,
+                                                           const GrVkImageInfo*);
 
     ~GrVkRenderTarget() override;
 
diff --git a/src/gpu/vk/GrVkTexture.cpp b/src/gpu/vk/GrVkTexture.cpp
index bf399a8..8c461f8 100644
--- a/src/gpu/vk/GrVkTexture.cpp
+++ b/src/gpu/vk/GrVkTexture.cpp
@@ -78,10 +78,10 @@
     return new GrVkTexture(gpu, budgeted, desc, info, imageView);
 }
 
-GrVkTexture* GrVkTexture::CreateWrappedTexture(GrVkGpu* gpu,
-                                               const GrSurfaceDesc& desc,
-                                               GrWrapOwnership ownership,
-                                               const GrVkImageInfo* info) {
+sk_sp<GrVkTexture> GrVkTexture::MakeWrappedTexture(GrVkGpu* gpu,
+                                                   const GrSurfaceDesc& desc,
+                                                   GrWrapOwnership ownership,
+                                                   const GrVkImageInfo* info) {
     SkASSERT(info);
     // Wrapped textures require both image and allocation (because they can be mapped)
     SkASSERT(VK_NULL_HANDLE != info->fImage && VK_NULL_HANDLE != info->fAlloc.fMemory);
@@ -96,7 +96,7 @@
     GrVkImage::Wrapped wrapped = kBorrow_GrWrapOwnership == ownership ? GrVkImage::kBorrowed_Wrapped
                                                                       : GrVkImage::kAdopted_Wrapped;
 
-    return new GrVkTexture(gpu, kWrapped, desc, *info, imageView, wrapped);
+    return sk_sp<GrVkTexture>(new GrVkTexture(gpu, kWrapped, desc, *info, imageView, wrapped));
 }
 
 GrVkTexture::~GrVkTexture() {
diff --git a/src/gpu/vk/GrVkTexture.h b/src/gpu/vk/GrVkTexture.h
index 06d1475..70db548 100644
--- a/src/gpu/vk/GrVkTexture.h
+++ b/src/gpu/vk/GrVkTexture.h
@@ -21,8 +21,8 @@
     static GrVkTexture* CreateNewTexture(GrVkGpu*, SkBudgeted budgeted, const GrSurfaceDesc&,
                                          const GrVkImage::ImageDesc&);
 
-    static GrVkTexture* CreateWrappedTexture(GrVkGpu*, const GrSurfaceDesc&,
-                                             GrWrapOwnership, const GrVkImageInfo*);
+    static sk_sp<GrVkTexture> MakeWrappedTexture(GrVkGpu*, const GrSurfaceDesc&,
+                                                 GrWrapOwnership, const GrVkImageInfo*);
 
     ~GrVkTexture() override;
 
diff --git a/src/gpu/vk/GrVkTextureRenderTarget.cpp b/src/gpu/vk/GrVkTextureRenderTarget.cpp
index 37b68af..cfa63be 100644
--- a/src/gpu/vk/GrVkTextureRenderTarget.cpp
+++ b/src/gpu/vk/GrVkTextureRenderTarget.cpp
@@ -135,11 +135,11 @@
     return trt;
 }
 
-GrVkTextureRenderTarget*
-GrVkTextureRenderTarget::CreateWrappedTextureRenderTarget(GrVkGpu* gpu,
-                                                          const GrSurfaceDesc& desc,
-                                                          GrWrapOwnership ownership,
-                                                          const GrVkImageInfo* info) {
+sk_sp<GrVkTextureRenderTarget>
+GrVkTextureRenderTarget::MakeWrappedTextureRenderTarget(GrVkGpu* gpu,
+                                                        const GrSurfaceDesc& desc,
+                                                        GrWrapOwnership ownership,
+                                                        const GrVkImageInfo* info) {
     SkASSERT(info);
     // Wrapped textures require both image and allocation (because they can be mapped)
     SkASSERT(VK_NULL_HANDLE != info->fImage && VK_NULL_HANDLE != info->fAlloc.fMemory);
@@ -147,9 +147,7 @@
     GrVkImage::Wrapped wrapped = kBorrow_GrWrapOwnership == ownership ? GrVkImage::kBorrowed_Wrapped
                                                                       : GrVkImage::kAdopted_Wrapped;
 
-    GrVkTextureRenderTarget* trt = Create(gpu, desc, *info, SkBudgeted::kNo, wrapped);
-
-    return trt;
+    return sk_sp<GrVkTextureRenderTarget>(Create(gpu, desc, *info, SkBudgeted::kNo, wrapped));
 }
 
 bool GrVkTextureRenderTarget::updateForMipmap(GrVkGpu* gpu, const GrVkImageInfo& newInfo) {
diff --git a/src/gpu/vk/GrVkTextureRenderTarget.h b/src/gpu/vk/GrVkTextureRenderTarget.h
index 2259511..daa1687 100644
--- a/src/gpu/vk/GrVkTextureRenderTarget.h
+++ b/src/gpu/vk/GrVkTextureRenderTarget.h
@@ -28,10 +28,10 @@
                                                                  const GrSurfaceDesc&,
                                                                  const GrVkImage::ImageDesc&);
 
-    static GrVkTextureRenderTarget* CreateWrappedTextureRenderTarget(GrVkGpu*,
-                                                                     const GrSurfaceDesc&,
-                                                                     GrWrapOwnership,
-                                                                     const GrVkImageInfo*);
+    static sk_sp<GrVkTextureRenderTarget> MakeWrappedTextureRenderTarget(GrVkGpu*,
+                                                                         const GrSurfaceDesc&,
+                                                                         GrWrapOwnership,
+                                                                         const GrVkImageInfo*);
 
     bool updateForMipmap(GrVkGpu* gpu, const GrVkImageInfo& newInfo);