sk_spification of GrGpu creation.

Make GrContext::MakeGL take interface as sk_sp.

Make GrContext::MakeVulkan take GrVkBackendContext as sk_sp.

Change-Id: I13c22a57bd281c51738f503d9ed3418d35a466df
Reviewed-on: https://skia-review.googlesource.com/81842
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
diff --git a/example/SkiaSDLExample.cpp b/example/SkiaSDLExample.cpp
index 3878cc7..ab181cb 100644
--- a/example/SkiaSDLExample.cpp
+++ b/example/SkiaSDLExample.cpp
@@ -192,7 +192,7 @@
     sk_sp<const GrGLInterface> interface(GrGLCreateNativeInterface());
 
     // setup contexts
-    sk_sp<GrContext> grContext(GrContext::MakeGL(interface.get()));
+    sk_sp<GrContext> grContext(GrContext::MakeGL(interface));
     SkASSERT(grContext);
 
     // Wrap the frame buffer object attached to the screen in a Skia render target so Skia can
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index 7b87b0a..4aafab8 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -56,12 +56,12 @@
     static GrContext* Create(GrBackend, GrBackendContext, const GrContextOptions& options);
     static GrContext* Create(GrBackend, GrBackendContext);
 
-    static sk_sp<GrContext> MakeGL(const GrGLInterface*, const GrContextOptions&);
-    static sk_sp<GrContext> MakeGL(const GrGLInterface*);
+    static sk_sp<GrContext> MakeGL(sk_sp<const GrGLInterface>, const GrContextOptions&);
+    static sk_sp<GrContext> MakeGL(sk_sp<const GrGLInterface>);
 
 #ifdef SK_VULKAN
-    static sk_sp<GrContext> MakeVulkan(const GrVkBackendContext*, const GrContextOptions&);
-    static sk_sp<GrContext> MakeVulkan(const GrVkBackendContext*);
+    static sk_sp<GrContext> MakeVulkan(sk_sp<const GrVkBackendContext>, const GrContextOptions&);
+    static sk_sp<GrContext> MakeVulkan(sk_sp<const GrVkBackendContext>);
 #endif
 
 #ifdef SK_METAL
@@ -291,8 +291,8 @@
 
     ///////////////////////////////////////////////////////////////////////////
     // Functions intended for internal use only.
-    GrGpu* getGpu() { return fGpu; }
-    const GrGpu* getGpu() const { return fGpu; }
+    GrGpu* getGpu() { return fGpu.get(); }
+    const GrGpu* getGpu() const { return fGpu.get(); }
     GrAtlasGlyphCache* getAtlasGlyphCache() { return fAtlasGlyphCache; }
     GrTextBlobCache* getTextBlobCache() { return fTextBlobCache.get(); }
     bool abandoned() const;
@@ -344,7 +344,7 @@
     const GrContextPriv contextPriv() const;
 
 private:
-    GrGpu*                                  fGpu;
+    sk_sp<GrGpu>                            fGpu;
     const GrCaps*                           fCaps;
     GrResourceCache*                        fResourceCache;
     GrResourceProvider*                     fResourceProvider;
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 2b185c4..e8f5c4b 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -75,15 +75,15 @@
     return context.release();
 }
 
-sk_sp<GrContext> GrContext::MakeGL(const GrGLInterface* interface) {
+sk_sp<GrContext> GrContext::MakeGL(sk_sp<const GrGLInterface> interface) {
     GrContextOptions defaultOptions;
-    return MakeGL(interface, defaultOptions);
+    return MakeGL(std::move(interface), defaultOptions);
 }
 
-sk_sp<GrContext> GrContext::MakeGL(const GrGLInterface* interface,
+sk_sp<GrContext> GrContext::MakeGL(sk_sp<const GrGLInterface> interface,
                                    const GrContextOptions& options) {
     sk_sp<GrContext> context(new GrContext);
-    context->fGpu = GrGLGpu::Create(interface, options, context.get());
+    context->fGpu = GrGLGpu::Make(std::move(interface), options, context.get());
     if (!context->fGpu) {
         return nullptr;
     }
@@ -102,7 +102,7 @@
 sk_sp<GrContext> GrContext::MakeMock(const GrMockOptions* mockOptions,
                                      const GrContextOptions& options) {
     sk_sp<GrContext> context(new GrContext);
-    context->fGpu = GrMockGpu::Create(mockOptions, options, context.get());
+    context->fGpu = GrMockGpu::Make(mockOptions, options, context.get());
     if (!context->fGpu) {
         return nullptr;
     }
@@ -114,15 +114,15 @@
 }
 
 #ifdef SK_VULKAN
-sk_sp<GrContext> GrContext::MakeVulkan(const GrVkBackendContext* backendContext) {
+sk_sp<GrContext> GrContext::MakeVulkan(sk_sp<const GrVkBackendContext> backendContext) {
     GrContextOptions defaultOptions;
-    return MakeVulkan(backendContext, defaultOptions);
+    return MakeVulkan(std::move(backendContext), defaultOptions);
 }
 
-sk_sp<GrContext> GrContext::MakeVulkan(const GrVkBackendContext* backendContext,
+sk_sp<GrContext> GrContext::MakeVulkan(sk_sp<const GrVkBackendContext> backendContext,
                                        const GrContextOptions& options) {
     sk_sp<GrContext> context(new GrContext);
-    context->fGpu = GrVkGpu::Create(backendContext, options, context.get());
+    context->fGpu = GrVkGpu::Make(std::move(backendContext), options, context.get());
     if (!context->fGpu) {
         return nullptr;
     }
@@ -142,7 +142,7 @@
 
 sk_sp<GrContext> GrContext::MakeMetal(void* device, void* queue, const GrContextOptions& options) {
     sk_sp<GrContext> context(new GrContext);
-    context->fGpu = GrMtlTrampoline::CreateGpu(context.get(), options, device, queue);
+    context->fGpu = GrMtlTrampoline::MakeGpu(context.get(), options, device, queue);
     if (!context->fGpu) {
         return nullptr;
     }
@@ -164,7 +164,6 @@
 }
 
 GrContext::GrContext() : fUniqueID(next_id()) {
-    fGpu = nullptr;
     fCaps = nullptr;
     fResourceCache = nullptr;
     fResourceProvider = nullptr;
@@ -178,7 +177,7 @@
 
     fBackend = backend;
 
-    fGpu = GrGpu::Create(backend, backendContext, options, this);
+    fGpu = GrGpu::Make(backend, backendContext, options, this);
     if (!fGpu) {
         return false;
     }
@@ -189,7 +188,7 @@
     ASSERT_SINGLE_OWNER
     fCaps = SkRef(fGpu->caps());
     fResourceCache = new GrResourceCache(fCaps, fUniqueID);
-    fResourceProvider = new GrResourceProvider(fGpu, fResourceCache, &fSingleOwner);
+    fResourceProvider = new GrResourceProvider(fGpu.get(), fResourceCache, &fSingleOwner);
 
     fDisableGpuYUVConversion = options.fDisableGpuYUVConversion;
     fDidTestPMConversions = false;
@@ -261,7 +260,6 @@
     delete fResourceCache;
     delete fAtlasGlyphCache;
 
-    fGpu->unref();
     fCaps->unref();
 }
 
diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h
index 676b3b0..18ea772 100644
--- a/src/gpu/GrGpu.h
+++ b/src/gpu/GrGpu.h
@@ -55,7 +55,8 @@
      * not supported (at compile-time or run-time) this returns nullptr. The context will not be
      * fully constructed and should not be used by GrGpu until after this function returns.
      */
-    static GrGpu* Create(GrBackend, GrBackendContext, const GrContextOptions&, GrContext* context);
+    static sk_sp<GrGpu> Make(GrBackend, GrBackendContext, const GrContextOptions&,
+                             GrContext* context);
 
     ////////////////////////////////////////////////////////////////////////////
 
diff --git a/src/gpu/GrGpuFactory.cpp b/src/gpu/GrGpuFactory.cpp
index 1fc19c1..eb3c292 100644
--- a/src/gpu/GrGpuFactory.cpp
+++ b/src/gpu/GrGpuFactory.cpp
@@ -13,19 +13,19 @@
 #include "vk/GrVkGpu.h"
 #endif
 
-GrGpu* GrGpu::Create(GrBackend backend,
-                     GrBackendContext backendContext,
-                     const GrContextOptions& options,
-                     GrContext* context) {
+sk_sp<GrGpu> GrGpu::Make(GrBackend backend,
+                         GrBackendContext backendContext,
+                         const GrContextOptions& options,
+                         GrContext* context) {
     switch (backend) {
         case kOpenGL_GrBackend:
-            return GrGLGpu::Create(backendContext, options, context);
+            return GrGLGpu::Make(backendContext, options, context);
 #ifdef SK_VULKAN
         case kVulkan_GrBackend:
-            return GrVkGpu::Create(backendContext, options, context);
+            return GrVkGpu::Make(backendContext, options, context);
 #endif
         case kMock_GrBackend:
-            return GrMockGpu::Create(backendContext, options, context);
+            return GrMockGpu::Make(backendContext, options, context);
         default:
             return nullptr;
     }
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index 8bf6389..3309616 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -182,29 +182,26 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 
-
-GrGpu* GrGLGpu::Create(GrBackendContext backendContext, const GrContextOptions& options,
-                       GrContext* context) {
-    return Create(reinterpret_cast<const GrGLInterface*>(backendContext), options, context);
+sk_sp<GrGpu> GrGLGpu::Make(GrBackendContext backendContext, const GrContextOptions& options,
+                           GrContext* context) {
+    const auto* interface = reinterpret_cast<const GrGLInterface*>(backendContext);
+    return Make(sk_ref_sp(interface), options, context);
 }
 
-GrGpu* GrGLGpu::Create(const GrGLInterface* interface, const GrContextOptions& options,
-                       GrContext* context) {
-    sk_sp<const GrGLInterface> glInterface(interface);
-    if (!glInterface) {
-        glInterface.reset(GrGLDefaultInterface());
-    } else {
-        glInterface->ref();
-    }
-    if (!glInterface) {
-        return nullptr;
+sk_sp<GrGpu> GrGLGpu::Make(sk_sp<const GrGLInterface> interface, const GrContextOptions& options,
+                           GrContext* context) {
+    if (!interface) {
+        interface.reset(GrGLDefaultInterface());
+        if (!interface) {
+            return nullptr;
+        }
     }
 #ifdef USE_NSIGHT
     const_cast<GrContextOptions&>(options).fSuppressPathRendering = true;
 #endif
-    GrGLContext* glContext = GrGLContext::Create(glInterface.get(), options);
+    GrGLContext* glContext = GrGLContext::Create(interface.get(), options);
     if (glContext) {
-        return new GrGLGpu(glContext, context);
+        return sk_sp<GrGpu>(new GrGLGpu(glContext, context));
     }
     return nullptr;
 }
diff --git a/src/gpu/gl/GrGLGpu.h b/src/gpu/gl/GrGLGpu.h
index 4d8b056..5c26924 100644
--- a/src/gpu/gl/GrGLGpu.h
+++ b/src/gpu/gl/GrGLGpu.h
@@ -36,10 +36,10 @@
 
 class GrGLGpu final : public GrGpu, private GrMesh::SendToGpuImpl {
 public:
-    static GrGpu* Create(GrBackendContext backendContext, const GrContextOptions& options,
-                         GrContext* context);
-    static GrGpu* Create(const GrGLInterface*, const GrContextOptions& options,
-                         GrContext* context);
+    static sk_sp<GrGpu> Make(GrBackendContext backendContext, const GrContextOptions& options,
+                             GrContext* context);
+    static sk_sp<GrGpu> Make(sk_sp<const GrGLInterface>, const GrContextOptions& options,
+                             GrContext* context);
     ~GrGLGpu() override;
 
     void disconnect(DisconnectType) override;
diff --git a/src/gpu/mock/GrMockGpu.cpp b/src/gpu/mock/GrMockGpu.cpp
index a21991f..5969f2f 100644
--- a/src/gpu/mock/GrMockGpu.cpp
+++ b/src/gpu/mock/GrMockGpu.cpp
@@ -24,18 +24,18 @@
     return sk_atomic_dec(&gID) - 1;
 }
 
-GrGpu* GrMockGpu::Create(GrBackendContext backendContext, const GrContextOptions& contextOptions,
-                         GrContext* context) {
-    return Create(reinterpret_cast<const GrMockOptions*>(backendContext), contextOptions, context);
+sk_sp<GrGpu> GrMockGpu::Make(GrBackendContext backendContext,
+                             const GrContextOptions& contextOptions, GrContext* context) {
+    return Make(reinterpret_cast<const GrMockOptions*>(backendContext), contextOptions, context);
 }
 
-GrGpu* GrMockGpu::Create(const GrMockOptions* mockOptions, const GrContextOptions& contextOptions,
-                         GrContext* context) {
+sk_sp<GrGpu> GrMockGpu::Make(const GrMockOptions* mockOptions,
+                             const GrContextOptions& contextOptions, GrContext* context) {
     static const GrMockOptions kDefaultOptions = GrMockOptions();
     if (!mockOptions) {
         mockOptions = &kDefaultOptions;
     }
-    return new GrMockGpu(context, *mockOptions, contextOptions);
+    return sk_sp<GrGpu>(new GrMockGpu(context, *mockOptions, contextOptions));
 }
 
 
diff --git a/src/gpu/mock/GrMockGpu.h b/src/gpu/mock/GrMockGpu.h
index 574906e..49a52ff 100644
--- a/src/gpu/mock/GrMockGpu.h
+++ b/src/gpu/mock/GrMockGpu.h
@@ -20,8 +20,8 @@
 
 class GrMockGpu : public GrGpu {
 public:
-    static GrGpu* Create(GrBackendContext, const GrContextOptions&, GrContext*);
-    static GrGpu* Create(const GrMockOptions*, const GrContextOptions&, GrContext*);
+    static sk_sp<GrGpu> Make(GrBackendContext, const GrContextOptions&, GrContext*);
+    static sk_sp<GrGpu> Make(const GrMockOptions*, const GrContextOptions&, GrContext*);
 
     ~GrMockGpu() override {}
 
diff --git a/src/gpu/mtl/GrMtlGpu.h b/src/gpu/mtl/GrMtlGpu.h
index fb2c368..cb2744f 100644
--- a/src/gpu/mtl/GrMtlGpu.h
+++ b/src/gpu/mtl/GrMtlGpu.h
@@ -22,8 +22,8 @@
 
 class GrMtlGpu : public GrGpu {
 public:
-    static GrGpu* Create(GrContext* context, const GrContextOptions& options,
-                         id<MTLDevice> device, id<MTLCommandQueue> queue);
+    static sk_sp<GrGpu> Make(GrContext* context, const GrContextOptions& options,
+                             id<MTLDevice> device, id<MTLCommandQueue> queue);
 
     ~GrMtlGpu() override {}
 
diff --git a/src/gpu/mtl/GrMtlGpu.mm b/src/gpu/mtl/GrMtlGpu.mm
index a830959..149e562 100644
--- a/src/gpu/mtl/GrMtlGpu.mm
+++ b/src/gpu/mtl/GrMtlGpu.mm
@@ -69,8 +69,8 @@
     return false;
 }
 
-GrGpu* GrMtlGpu::Create(GrContext* context, const GrContextOptions& options,
-                        id<MTLDevice> device, id<MTLCommandQueue> queue) {
+sk_sp<GrGpu> GrMtlGpu::Make(GrContext* context, const GrContextOptions& options,
+                            id<MTLDevice> device, id<MTLCommandQueue> queue) {
     if (!device || !queue) {
         return nullptr;
     }
@@ -78,7 +78,7 @@
     if (!get_feature_set(device, &featureSet)) {
         return nullptr;
     }
-    return new GrMtlGpu(context, options, device, queue, featureSet);
+    return sk_sp<GrGpu>(new GrMtlGpu(context, options, device, queue, featureSet));
 }
 
 GrMtlGpu::GrMtlGpu(GrContext* context, const GrContextOptions& options,
diff --git a/src/gpu/mtl/GrMtlTrampoline.h b/src/gpu/mtl/GrMtlTrampoline.h
index 531a4ce..29a5bf3 100644
--- a/src/gpu/mtl/GrMtlTrampoline.h
+++ b/src/gpu/mtl/GrMtlTrampoline.h
@@ -9,6 +9,7 @@
 #define GrMtlTrampoline_DEFINED
 
 #include "GrTypes.h"
+#include "SkRefCnt.h"
 
 class GrContext;
 class GrGpu;
@@ -20,10 +21,10 @@
  */
 class GrMtlTrampoline {
 public:
-    static GrGpu* CreateGpu(GrContext* context,
-                            const GrContextOptions& options,
-                            void* device,
-                            void* queue);
+    static sk_sp<GrGpu> MakeGpu(GrContext* context,
+                                const GrContextOptions& options,
+                                void* device,
+                                void* queue);
 };
 
 #endif
diff --git a/src/gpu/mtl/GrMtlTrampoline.mm b/src/gpu/mtl/GrMtlTrampoline.mm
index 0f112e4..516ac52 100644
--- a/src/gpu/mtl/GrMtlTrampoline.mm
+++ b/src/gpu/mtl/GrMtlTrampoline.mm
@@ -9,13 +9,13 @@
 
 #include "GrMtlGpu.h"
 
-GrGpu* GrMtlTrampoline::CreateGpu(GrContext* context,
-                                  const GrContextOptions& options,
-                                  void* device,
-                                  void* queue) {
-    return GrMtlGpu::Create(context,
-                            options,
-                            (__bridge_transfer id<MTLDevice>)device,
-                            (__bridge_transfer id<MTLCommandQueue>)queue);
+sk_sp<GrGpu> GrMtlTrampoline::MakeGpu(GrContext* context,
+                                      const GrContextOptions& options,
+                                      void* device,
+                                      void* queue) {
+    return GrMtlGpu::Make(context,
+                          options,
+                          (__bridge_transfer id<MTLDevice>)device,
+                          (__bridge_transfer id<MTLCommandQueue>)queue);
 }
 
diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp
index a87c344..0a64234 100644
--- a/src/gpu/vk/GrVkGpu.cpp
+++ b/src/gpu/vk/GrVkGpu.cpp
@@ -73,40 +73,38 @@
 }
 #endif
 
-GrGpu* GrVkGpu::Create(GrBackendContext backendContext, const GrContextOptions& options,
-                       GrContext* context) {
-    return Create(reinterpret_cast<const GrVkBackendContext*>(backendContext), options, context);
+sk_sp<GrGpu> GrVkGpu::Make(GrBackendContext backendContext, const GrContextOptions& options,
+                           GrContext* context) {
+    const auto* backend = reinterpret_cast<const GrVkBackendContext*>(backendContext);
+    return Make(sk_ref_sp(backend), options, context);
 }
 
-GrGpu* GrVkGpu::Create(const GrVkBackendContext* backendContext, const GrContextOptions& options,
-                       GrContext* context) {
+sk_sp<GrGpu> GrVkGpu::Make(sk_sp<const GrVkBackendContext> backendContext,
+                           const GrContextOptions& options, GrContext* context) {
     if (!backendContext) {
         return nullptr;
-    } else {
-        backendContext->ref();
     }
 
     if (!backendContext->fInterface->validate(backendContext->fExtensions)) {
         return nullptr;
     }
 
-    return new GrVkGpu(context, options, backendContext);
+    return sk_sp<GrGpu>(new GrVkGpu(context, options, std::move(backendContext)));
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 
 GrVkGpu::GrVkGpu(GrContext* context, const GrContextOptions& options,
-                 const GrVkBackendContext* backendCtx)
-    : INHERITED(context)
-    , fDevice(backendCtx->fDevice)
-    , fQueue(backendCtx->fQueue)
-    , fResourceProvider(this)
-    , fDisconnected(false) {
-    fBackendContext.reset(backendCtx);
-
+                 sk_sp<const GrVkBackendContext> backendCtx)
+        : INHERITED(context)
+        , fBackendContext(std::move(backendCtx))
+        , fDevice(fBackendContext->fDevice)
+        , fQueue(fBackendContext->fQueue)
+        , fResourceProvider(this)
+        , fDisconnected(false) {
 #ifdef SK_ENABLE_VK_LAYERS
     fCallback = VK_NULL_HANDLE;
-    if (backendCtx->fExtensions & kEXT_debug_report_GrVkExtensionFlag) {
+    if (fBackendContext->fExtensions & kEXT_debug_report_GrVkExtensionFlag) {
         // Setup callback creation information
         VkDebugReportCallbackCreateInfoEXT callbackCreateInfo;
         callbackCreateInfo.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CREATE_INFO_EXT;
@@ -120,25 +118,26 @@
         callbackCreateInfo.pUserData = nullptr;
 
         // Register the callback
-        GR_VK_CALL_ERRCHECK(this->vkInterface(), CreateDebugReportCallbackEXT(
-                            backendCtx->fInstance, &callbackCreateInfo, nullptr, &fCallback));
+        GR_VK_CALL_ERRCHECK(this->vkInterface(),
+                            CreateDebugReportCallbackEXT(fBackendContext->fInstance,
+                                                         &callbackCreateInfo, nullptr, &fCallback));
     }
 #endif
 
     fCompiler = new SkSL::Compiler();
 
-    fVkCaps.reset(new GrVkCaps(options, this->vkInterface(), backendCtx->fPhysicalDevice,
-                               backendCtx->fFeatures, backendCtx->fExtensions));
+    fVkCaps.reset(new GrVkCaps(options, this->vkInterface(), fBackendContext->fPhysicalDevice,
+                               fBackendContext->fFeatures, fBackendContext->fExtensions));
     fCaps.reset(SkRef(fVkCaps.get()));
 
-    VK_CALL(GetPhysicalDeviceMemoryProperties(backendCtx->fPhysicalDevice, &fPhysDevMemProps));
+    VK_CALL(GetPhysicalDeviceMemoryProperties(fBackendContext->fPhysicalDevice, &fPhysDevMemProps));
 
     const VkCommandPoolCreateInfo cmdPoolInfo = {
         VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,      // sType
         nullptr,                                         // pNext
         VK_COMMAND_POOL_CREATE_TRANSIENT_BIT |
         VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, // CmdPoolCreateFlags
-        backendCtx->fGraphicsQueueIndex,                 // queueFamilyIndex
+        fBackendContext->fGraphicsQueueIndex,            // queueFamilyIndex
     };
     GR_VK_CALL_ERRCHECK(this->vkInterface(), CreateCommandPool(fDevice, &cmdPoolInfo, nullptr,
                                                                &fCmdPool));
diff --git a/src/gpu/vk/GrVkGpu.h b/src/gpu/vk/GrVkGpu.h
index 1d2aca3..8e6f391 100644
--- a/src/gpu/vk/GrVkGpu.h
+++ b/src/gpu/vk/GrVkGpu.h
@@ -38,10 +38,10 @@
 
 class GrVkGpu : public GrGpu {
 public:
-    static GrGpu* Create(GrBackendContext backendContext, const GrContextOptions& options,
-                         GrContext* context);
-    static GrGpu* Create(const GrVkBackendContext*, const GrContextOptions& options,
-                         GrContext* context);
+    static sk_sp<GrGpu> Make(GrBackendContext backendContext, const GrContextOptions& options,
+                             GrContext* context);
+    static sk_sp<GrGpu> Make(sk_sp<const GrVkBackendContext>, const GrContextOptions& options,
+                             GrContext* context);
 
     ~GrVkGpu() override;
 
@@ -174,7 +174,7 @@
 
 private:
     GrVkGpu(GrContext* context, const GrContextOptions& options,
-            const GrVkBackendContext* backendContext);
+            sk_sp<const GrVkBackendContext> backendContext);
 
     void onResetContext(uint32_t resetBits) override {}
 
diff --git a/tests/EGLImageTest.cpp b/tests/EGLImageTest.cpp
index 82e4c4b..53ff6f9 100644
--- a/tests/EGLImageTest.cpp
+++ b/tests/EGLImageTest.cpp
@@ -63,7 +63,7 @@
     if (!glCtx1) {
         return;
     }
-    sk_sp<GrContext> context1 = GrContext::MakeGL(glCtx1->gl());
+    sk_sp<GrContext> context1 = GrContext::MakeGL(sk_ref_sp(glCtx1->gl()));
     const GrGLTextureInfo* backendTexture1 = nullptr;
     GrEGLImage image = GR_EGL_NO_IMAGE;
     GrGLTextureInfo externalTexture;
diff --git a/tests/GpuSampleLocationsTest.cpp b/tests/GpuSampleLocationsTest.cpp
index e780063..de15e03 100644
--- a/tests/GpuSampleLocationsTest.cpp
+++ b/tests/GpuSampleLocationsTest.cpp
@@ -185,15 +185,15 @@
 };
 
 DEF_GPUTEST(GLSampleLocations, reporter, /* options */) {
-    GLTestSampleLocationsInterface testInterface;
-    sk_sp<GrContext> ctx(GrContext::MakeGL(&testInterface));
+    auto testInterface = sk_make_sp<GLTestSampleLocationsInterface>();
+    sk_sp<GrContext> ctx(GrContext::MakeGL(testInterface));
 
     // This test relies on at least 2 samples.
     int supportedSample = ctx->caps()->getSampleCount(2, kRGBA_8888_GrPixelConfig);
     if (supportedSample < 2) {
         return;
     }
-    test_sampleLocations(reporter, &testInterface, ctx.get());
+    test_sampleLocations(reporter, testInterface.get(), ctx.get());
 }
 
 #endif
diff --git a/tools/gpu/gl/GLTestContext.cpp b/tools/gpu/gl/GLTestContext.cpp
index 76e38b7..2c1d977 100644
--- a/tools/gpu/gl/GLTestContext.cpp
+++ b/tools/gpu/gl/GLTestContext.cpp
@@ -344,7 +344,7 @@
 }
 
 sk_sp<GrContext> GLTestContext::makeGrContext(const GrContextOptions& options) {
-    return GrContext::MakeGL(fGL.get(), options);
+    return GrContext::MakeGL(fGL, options);
 }
 
 }  // namespace sk_gpu_test
diff --git a/tools/gpu/gl/GLTestContext.h b/tools/gpu/gl/GLTestContext.h
index b5dd9ac..02fe78e 100644
--- a/tools/gpu/gl/GLTestContext.h
+++ b/tools/gpu/gl/GLTestContext.h
@@ -27,7 +27,7 @@
 
     bool isValid() const { return SkToBool(this->gl()); }
 
-    const GrGLInterface *gl() const { return fGL.get(); }
+    const GrGLInterface* gl() const { return fGL.get(); }
 
     /** Used for testing EGLImage integration. Take a GL_TEXTURE_2D and wraps it in an EGL Image */
     virtual GrEGLImage texture2DToEGLImage(GrGLuint /*texID*/) const { return nullptr; }
diff --git a/tools/gpu/vk/VkTestContext.cpp b/tools/gpu/vk/VkTestContext.cpp
index fa40c73..25069fe 100644
--- a/tools/gpu/vk/VkTestContext.cpp
+++ b/tools/gpu/vk/VkTestContext.cpp
@@ -137,7 +137,7 @@
     void finish() override {}
 
     sk_sp<GrContext> makeGrContext(const GrContextOptions& options) override {
-        return GrContext::MakeVulkan(fVk.get(), options);
+        return GrContext::MakeVulkan(fVk, options);
     }
 
 protected:
diff --git a/tools/sk_app/GLWindowContext.cpp b/tools/sk_app/GLWindowContext.cpp
index bdfa12a..d928a7b 100644
--- a/tools/sk_app/GLWindowContext.cpp
+++ b/tools/sk_app/GLWindowContext.cpp
@@ -33,7 +33,7 @@
     SkASSERT(!fContext);
 
     fBackendContext = this->onInitializeContext();
-    fContext = GrContext::MakeGL(fBackendContext.get(), fDisplayParams.fGrContextOptions);
+    fContext = GrContext::MakeGL(fBackendContext, fDisplayParams.fGrContextOptions);
     if (!fContext && fDisplayParams.fMSAASampleCount) {
         fDisplayParams.fMSAASampleCount /= 2;
         this->initializeContext();
diff --git a/tools/sk_app/VulkanWindowContext.cpp b/tools/sk_app/VulkanWindowContext.cpp
index 5e0f124..3517749 100644
--- a/tools/sk_app/VulkanWindowContext.cpp
+++ b/tools/sk_app/VulkanWindowContext.cpp
@@ -72,7 +72,7 @@
     GET_DEV_PROC(QueuePresentKHR);
     GET_DEV_PROC(GetDeviceQueue);
 
-    fContext = GrContext::MakeVulkan(fBackendContext.get(), fDisplayParams.fGrContextOptions);
+    fContext = GrContext::MakeVulkan(fBackendContext, fDisplayParams.fGrContextOptions);
 
     fSurface = fCreateVkSurfaceFn(instance);
     if (VK_NULL_HANDLE == fSurface) {