Add Make[backend] calls for creating GrContexts

Docs-Preview: https://skia.org/?cl=26369
Bug: skia:
Change-Id: I460ee63e466f85b05918479f068a2e5ca2d70550
Reviewed-on: https://skia-review.googlesource.com/26369
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
diff --git a/tools/fiddle/egl_context.cpp b/tools/fiddle/egl_context.cpp
index 107bb4f..696a86f 100644
--- a/tools/fiddle/egl_context.cpp
+++ b/tools/fiddle/egl_context.cpp
@@ -77,5 +77,5 @@
     }
     eglTerminate(eglDpy);
 
-    return sk_sp<GrContext>(GrContext::Create(kOpenGL_GrBackend, (GrBackendContext)interface));
+    return sk_sp<GrContext>(GrContext::MakeGL(interface));
 }
diff --git a/tools/fiddle/mesa_context.cpp b/tools/fiddle/mesa_context.cpp
index 3b3726b..89902ec 100644
--- a/tools/fiddle/mesa_context.cpp
+++ b/tools/fiddle/mesa_context.cpp
@@ -27,7 +27,5 @@
     if (!mesa) {
         return nullptr;
     }
-    return sk_sp<GrContext>(GrContext::Create(
-                kOpenGL_GrBackend,
-                reinterpret_cast<intptr_t>(mesa.get())));
+    return GrContext::MakeGL(mesa.get());
 }
diff --git a/tools/gpu/GrContextFactory.cpp b/tools/gpu/GrContextFactory.cpp
index 0686b79..b3ca1d9 100644
--- a/tools/gpu/GrContextFactory.cpp
+++ b/tools/gpu/GrContextFactory.cpp
@@ -133,8 +133,6 @@
     }
 
     std::unique_ptr<TestContext> testCtx;
-    GrBackendContext backendContext = 0;
-    sk_sp<const GrGLInterface> glInterface;
     GrBackend backend = ContextTypeBackend(type);
     switch (backend) {
         case kOpenGL_GrBackend: {
@@ -194,8 +192,6 @@
                 return ContextInfo();
             }
             testCtx.reset(glCtx);
-            glInterface.reset(SkRef(glCtx->gl()));
-            backendContext = reinterpret_cast<GrBackendContext>(glInterface.get());
             break;
         }
 #ifdef SK_VULKAN
@@ -220,7 +216,6 @@
                     fSentinelGLContext.reset(CreatePlatformGLTestContext(kGLES_GrGLStandard));
                 }
             }
-            backendContext = testCtx->backendContext();
             break;
         }
 #endif
@@ -244,7 +239,6 @@
             if (!testCtx) {
                 return ContextInfo();
             }
-            backendContext = testCtx->backendContext();
             break;
         }
         default:
@@ -266,9 +260,6 @@
         grOptions.fAvoidStencilBuffers = true;
     }
     sk_sp<GrContext> grCtx = testCtx->makeGrContext(grOptions);
-    if (!grCtx.get() && kMetal_GrBackend != backend) {
-        grCtx.reset(GrContext::Create(backend, backendContext, grOptions));
-    }
     if (!grCtx.get()) {
         return ContextInfo();
     }
diff --git a/tools/gpu/gl/GLTestContext.cpp b/tools/gpu/gl/GLTestContext.cpp
index abbb8a6..91fa82f 100644
--- a/tools/gpu/gl/GLTestContext.cpp
+++ b/tools/gpu/gl/GLTestContext.cpp
@@ -7,6 +7,7 @@
 
 #include "GLTestContext.h"
 
+#include "GrContext.h"
 #include "GpuTimer.h"
 #include "gl/GrGLUtil.h"
 
@@ -286,4 +287,9 @@
                                      externalFormat, externalType, data));
     return id;
 }
+
+sk_sp<GrContext> GLTestContext::makeGrContext(const GrContextOptions& options) {
+    return GrContext::MakeGL(fGL.get(), options);
+}
+
 }  // namespace sk_gpu_test
diff --git a/tools/gpu/gl/GLTestContext.h b/tools/gpu/gl/GLTestContext.h
index f5afa31..701000e 100644
--- a/tools/gpu/gl/GLTestContext.h
+++ b/tools/gpu/gl/GLTestContext.h
@@ -75,6 +75,8 @@
         }
     }
 
+    sk_sp<GrContext> makeGrContext(const GrContextOptions& options) override;
+
 protected:
     GLTestContext();
 
diff --git a/tools/gpu/mock/MockTestContext.cpp b/tools/gpu/mock/MockTestContext.cpp
index 56cd68c..68941ad 100644
--- a/tools/gpu/mock/MockTestContext.cpp
+++ b/tools/gpu/mock/MockTestContext.cpp
@@ -10,6 +10,8 @@
 
 #include "MockTestContext.h"
 
+#include "GrContext.h"
+
 namespace {
 
 class MockTestContext : public sk_gpu_test::TestContext {
@@ -25,6 +27,10 @@
     void submit() override {}
     void finish() override {}
 
+    sk_sp<GrContext> makeGrContext(const GrContextOptions& options) override {
+        return GrContext::MakeMock(nullptr, options);
+    }
+
 protected:
     void teardown() override {}
     void onPlatformMakeCurrent() const override {}
diff --git a/tools/gpu/vk/VkTestContext.cpp b/tools/gpu/vk/VkTestContext.cpp
index 125ead2..e329583 100644
--- a/tools/gpu/vk/VkTestContext.cpp
+++ b/tools/gpu/vk/VkTestContext.cpp
@@ -9,6 +9,7 @@
 
 #ifdef SK_VULKAN
 
+#include "GrContext.h"
 #include "vk/GrVkInterface.h"
 #include "vk/GrVkUtil.h"
 #include <vulkan/vulkan.h>
@@ -131,6 +132,10 @@
 
     void finish() override {}
 
+    sk_sp<GrContext> makeGrContext(const GrContextOptions& options) override {
+        return GrContext::MakeVulkan(fVk.get(), options);
+    }
+
 protected:
     void teardown() override {
         INHERITED::teardown();
diff --git a/tools/viewer/sk_app/GLWindowContext.cpp b/tools/viewer/sk_app/GLWindowContext.cpp
index 2f0d5dc..682fcbf 100644
--- a/tools/viewer/sk_app/GLWindowContext.cpp
+++ b/tools/viewer/sk_app/GLWindowContext.cpp
@@ -31,11 +31,10 @@
 
 void GLWindowContext::initializeContext() {
     this->onInitializeContext();
-    SkASSERT(nullptr == fContext);
+    SkASSERT(!fContext);
 
     fBackendContext.reset(GrGLCreateNativeInterface());
-    fContext = GrContext::Create(kOpenGL_GrBackend, (GrBackendContext)fBackendContext.get(),
-                                 fDisplayParams.fGrContextOptions);
+    fContext = GrContext::MakeGL(fBackendContext.get(), fDisplayParams.fGrContextOptions);
     if (!fContext && fDisplayParams.fMSAASampleCount) {
         fDisplayParams.fMSAASampleCount /= 2;
         this->initializeContext();
@@ -58,8 +57,7 @@
     if (fContext) {
         // in case we have outstanding refs to this guy (lua?)
         fContext->abandonContext();
-        fContext->unref();
-        fContext = nullptr;
+        fContext.reset();
     }
 
     fBackendContext.reset(nullptr);
@@ -83,7 +81,7 @@
                                             fPixelConfig,
                                             fbInfo);
 
-            fSurface = SkSurface::MakeFromBackendRenderTarget(fContext, backendRT,
+            fSurface = SkSurface::MakeFromBackendRenderTarget(fContext.get(), backendRT,
                                                               kBottomLeft_GrSurfaceOrigin,
                                                               fDisplayParams.fColorSpace,
                                                               &fSurfaceProps);
diff --git a/tools/viewer/sk_app/VulkanWindowContext.cpp b/tools/viewer/sk_app/VulkanWindowContext.cpp
index 261206c..a9124d5 100644
--- a/tools/viewer/sk_app/VulkanWindowContext.cpp
+++ b/tools/viewer/sk_app/VulkanWindowContext.cpp
@@ -67,8 +67,7 @@
     GET_DEV_PROC(AcquireNextImageKHR);
     GET_DEV_PROC(QueuePresentKHR);
 
-    fContext = GrContext::Create(kVulkan_GrBackend, (GrBackendContext) fBackendContext.get(),
-                                 fDisplayParams.fGrContextOptions);
+    fContext = GrContext::MakeVulkan(fBackendContext.get(), fDisplayParams.fGrContextOptions);
 
     fSurface = fCreateVkSurfaceFn(instance);
     if (VK_NULL_HANDLE == fSurface) {
@@ -280,7 +279,7 @@
 
         GrBackendTexture backendTex(fWidth, fHeight, info);
 
-        fSurfaces[i] = SkSurface::MakeFromBackendTextureAsRenderTarget(fContext, backendTex,
+        fSurfaces[i] = SkSurface::MakeFromBackendTextureAsRenderTarget(fContext.get(), backendTex,
                                                                        kTopLeft_GrSurfaceOrigin,
                                                                        fSampleCount,
                                                                        fDisplayParams.fColorSpace,
@@ -412,7 +411,7 @@
         fSurface = VK_NULL_HANDLE;
     }
 
-    fContext->unref();
+    fContext.reset();
 
     fBackendContext.reset(nullptr);
 }
diff --git a/tools/viewer/sk_app/WindowContext.h b/tools/viewer/sk_app/WindowContext.h
index fbd2756..cd4c357 100644
--- a/tools/viewer/sk_app/WindowContext.h
+++ b/tools/viewer/sk_app/WindowContext.h
@@ -8,11 +8,11 @@
 #define WindowContext_DEFINED
 
 #include "DisplayParams.h"
+#include "GrContext.h"
 #include "GrTypes.h"
 #include "SkRefCnt.h"
 #include "SkSurfaceProps.h"
 
-class GrContext;
 class SkSurface;
 class GrRenderTarget;
 
@@ -46,7 +46,7 @@
     }
 
     virtual GrBackendContext getBackendContext() = 0;
-    GrContext* getGrContext() const { return fContext; }
+    GrContext* getGrContext() const { return fContext.get(); }
 
     int width() const { return fWidth; }
     int height() const { return fHeight; }
@@ -56,7 +56,7 @@
 protected:
     virtual bool isGpuContext() { return true;  }
 
-    GrContext*        fContext;
+    sk_sp<GrContext>        fContext;
 
     int               fWidth;
     int               fHeight;