Add GrGLMakeNativeInterface factory that returns sk_sp<const GrGLInterface>.

Removes the concept of a configurable "default" interface and makes the default
always be the "native" interface.

Also removes unused functions: GrGLInterfaceAddTestDebugMarker and
GrGLInterface::NewClone.

Keeps around legacy GrGLCreateNativeInterface() until clients can be weened.

Change-Id: I4a3bdafa8cf8c68ed13318393abd55686b045ccb
Reviewed-on: https://skia-review.googlesource.com/83000
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
diff --git a/tools/gpu/gl/GLTestContext.cpp b/tools/gpu/gl/GLTestContext.cpp
index 2c1d977..7a67a8a 100644
--- a/tools/gpu/gl/GLTestContext.cpp
+++ b/tools/gpu/gl/GLTestContext.cpp
@@ -284,9 +284,8 @@
     SkASSERT(nullptr == fGL.get());
 }
 
-void GLTestContext::init(const GrGLInterface* gl, std::unique_ptr<FenceSync> fenceSync) {
-    SkASSERT(!fGL.get());
-    fGL.reset(gl);
+void GLTestContext::init(sk_sp<const GrGLInterface> gl, std::unique_ptr<FenceSync> fenceSync) {
+    fGL = std::move(gl);
     fFenceSync = fenceSync ? std::move(fenceSync) : GLFenceSync::MakeIfSupported(this);
     fGpuTimer = GLGpuTimer::MakeIfSupported(this);
 }
diff --git a/tools/gpu/gl/GLTestContext.h b/tools/gpu/gl/GLTestContext.h
index 02fe78e..cea630a 100644
--- a/tools/gpu/gl/GLTestContext.h
+++ b/tools/gpu/gl/GLTestContext.h
@@ -83,7 +83,7 @@
     /*
      * Methods that sublcasses must call from their constructors and destructors.
      */
-    void init(const GrGLInterface *, std::unique_ptr<FenceSync> = nullptr);
+    void init(sk_sp<const GrGLInterface>, std::unique_ptr<FenceSync> = nullptr);
 
     void teardown() override;
 
diff --git a/tools/gpu/gl/angle/GLTestContext_angle.cpp b/tools/gpu/gl/angle/GLTestContext_angle.cpp
index 3b55c40..7de709f 100644
--- a/tools/gpu/gl/angle/GLTestContext_angle.cpp
+++ b/tools/gpu/gl/angle/GLTestContext_angle.cpp
@@ -232,7 +232,7 @@
         return;
     }
 
-    sk_sp<const GrGLInterface> gl(sk_gpu_test::CreateANGLEGLInterface());
+    sk_sp<const GrGLInterface> gl = sk_gpu_test::CreateANGLEGLInterface();
     if (nullptr == gl.get()) {
         SkDebugf("Could not create ANGLE GL interface!\n");
         this->destroyGLContext();
@@ -262,7 +262,7 @@
     }
 #endif
 
-    this->init(gl.release());
+    this->init(std::move(gl));
 }
 
 ANGLEGLContext::~ANGLEGLContext() {
@@ -389,7 +389,7 @@
 }  // anonymous namespace
 
 namespace sk_gpu_test {
-const GrGLInterface* CreateANGLEGLInterface() {
+sk_sp<const GrGLInterface> CreateANGLEGLInterface() {
     static Libs gLibs = { nullptr, nullptr };
 
     if (nullptr == gLibs.fGLLib) {
diff --git a/tools/gpu/gl/angle/GLTestContext_angle.h b/tools/gpu/gl/angle/GLTestContext_angle.h
index 5a72b93..de7659a 100644
--- a/tools/gpu/gl/angle/GLTestContext_angle.h
+++ b/tools/gpu/gl/angle/GLTestContext_angle.h
@@ -16,7 +16,7 @@
  * Creates a GrGLInterface for the current ANGLE GLES Context. Here current means bound in ANGLE's
  * implementation of EGL.
  */
-const GrGLInterface* CreateANGLEGLInterface();
+sk_sp<const GrGLInterface> CreateANGLEGLInterface();
 
 enum class ANGLEBackend {
     kD3D9,
diff --git a/tools/gpu/gl/command_buffer/GLTestContext_command_buffer.cpp b/tools/gpu/gl/command_buffer/GLTestContext_command_buffer.cpp
index be2b6ad..1924257 100644
--- a/tools/gpu/gl/command_buffer/GLTestContext_command_buffer.cpp
+++ b/tools/gpu/gl/command_buffer/GLTestContext_command_buffer.cpp
@@ -130,7 +130,7 @@
     once(load_command_buffer_functions);
 }
 
-static const GrGLInterface* create_command_buffer_interface() {
+static sk_sp<const GrGLInterface> create_command_buffer_interface() {
     load_command_buffer_once();
     if (!gfFunctionsLoadedSuccessfully) {
         return nullptr;
@@ -289,8 +289,8 @@
         return;
     }
 
-    sk_sp<const GrGLInterface> gl(create_command_buffer_interface());
-    if (nullptr == gl.get()) {
+    auto gl = create_command_buffer_interface();
+    if (!gl) {
         SkDebugf("Command Buffer: Could not create CommandBuffer GL interface.\n");
         this->destroyGLContext();
         return;
@@ -301,7 +301,7 @@
         return;
     }
 
-    this->init(gl.release());
+    this->init(std::move(gl));
 }
 
 CommandBufferGLTestContext::~CommandBufferGLTestContext() {
diff --git a/tools/gpu/gl/debug/DebugGLTestContext.cpp b/tools/gpu/gl/debug/DebugGLTestContext.cpp
index e28a3a7..4152997 100644
--- a/tools/gpu/gl/debug/DebugGLTestContext.cpp
+++ b/tools/gpu/gl/debug/DebugGLTestContext.cpp
@@ -1195,11 +1195,9 @@
 
 class DebugGLContext : public sk_gpu_test::GLTestContext {
 public:
-   DebugGLContext() {
-       this->init(new DebugInterface());
-   }
+    DebugGLContext() { this->init(sk_make_sp<DebugInterface>()); }
 
-   ~DebugGLContext() override { this->teardown(); }
+    ~DebugGLContext() override { this->teardown(); }
 
 private:
     void onPlatformMakeCurrent() const override {}
diff --git a/tools/gpu/gl/egl/CreatePlatformGLTestContext_egl.cpp b/tools/gpu/gl/egl/CreatePlatformGLTestContext_egl.cpp
index 4a09d22..03a211d 100644
--- a/tools/gpu/gl/egl/CreatePlatformGLTestContext_egl.cpp
+++ b/tools/gpu/gl/egl/CreatePlatformGLTestContext_egl.cpp
@@ -186,8 +186,8 @@
             continue;
         }
 
-        gl.reset(GrGLCreateNativeInterface());
-        if (nullptr == gl.get()) {
+        gl = GrGLMakeNativeInterface();
+        if (!gl) {
             SkDebugf("Failed to create gl interface.\n");
             this->destroyGLContext();
             continue;
@@ -199,7 +199,7 @@
             continue;
         }
 
-        this->init(gl.release(), EGLFenceSync::MakeIfSupported(fDisplay));
+        this->init(std::move(gl), EGLFenceSync::MakeIfSupported(fDisplay));
         break;
     }
 }
diff --git a/tools/gpu/gl/glx/CreatePlatformGLTestContext_glx.cpp b/tools/gpu/gl/glx/CreatePlatformGLTestContext_glx.cpp
index 066784d..3df45bd 100644
--- a/tools/gpu/gl/glx/CreatePlatformGLTestContext_glx.cpp
+++ b/tools/gpu/gl/glx/CreatePlatformGLTestContext_glx.cpp
@@ -239,8 +239,8 @@
         return;
     }
 
-    sk_sp<const GrGLInterface> gl(GrGLCreateNativeInterface());
-    if (nullptr == gl.get()) {
+    auto gl = GrGLMakeNativeInterface();
+    if (!gl) {
         SkDebugf("Failed to create gl interface");
         this->destroyGLContext();
         return;
@@ -252,7 +252,7 @@
         return;
     }
 
-    this->init(gl.release());
+    this->init(std::move(gl));
 }
 
 
diff --git a/tools/gpu/gl/iOS/CreatePlatformGLTestContext_iOS.mm b/tools/gpu/gl/iOS/CreatePlatformGLTestContext_iOS.mm
index 65d2861..c62a330 100644
--- a/tools/gpu/gl/iOS/CreatePlatformGLTestContext_iOS.mm
+++ b/tools/gpu/gl/iOS/CreatePlatformGLTestContext_iOS.mm
@@ -66,7 +66,7 @@
         "/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib",
         RTLD_LAZY);
 
-    this->init(gl.release());
+    this->init(std::move(gl));
 }
 
 IOSGLTestContext::~IOSGLTestContext() {
diff --git a/tools/gpu/gl/mac/CreatePlatformGLTestContext_mac.cpp b/tools/gpu/gl/mac/CreatePlatformGLTestContext_mac.cpp
index 9f1c61e..5b11227 100644
--- a/tools/gpu/gl/mac/CreatePlatformGLTestContext_mac.cpp
+++ b/tools/gpu/gl/mac/CreatePlatformGLTestContext_mac.cpp
@@ -68,8 +68,8 @@
     SkScopeExit restorer(context_restorer());
     CGLSetCurrentContext(fContext);
 
-    sk_sp<const GrGLInterface> gl(GrGLCreateNativeInterface());
-    if (nullptr == gl.get()) {
+    auto gl = GrGLMakeNativeInterface();
+    if (!gl) {
         SkDebugf("Context could not create GL interface.\n");
         this->destroyGLContext();
         return;
@@ -84,7 +84,7 @@
         "/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib",
         RTLD_LAZY);
 
-    this->init(gl.release());
+    this->init(std::move(gl));
 }
 
 MacGLTestContext::~MacGLTestContext() {
diff --git a/tools/gpu/gl/null/NullGLTestContext.cpp b/tools/gpu/gl/null/NullGLTestContext.cpp
index 9e7279b..de33a40 100644
--- a/tools/gpu/gl/null/NullGLTestContext.cpp
+++ b/tools/gpu/gl/null/NullGLTestContext.cpp
@@ -17,8 +17,10 @@
 namespace {
 class NullGLContext : public sk_gpu_test::GLTestContext {
 public:
-    NullGLContext(bool enableNVPR) { this->init(GrGLCreateNullInterface(enableNVPR)); }
-   ~NullGLContext() override { this->teardown(); }
+    NullGLContext(bool enableNVPR) {
+        this->init(sk_sp<const GrGLInterface>(GrGLCreateNullInterface(enableNVPR)));
+    }
+    ~NullGLContext() override { this->teardown(); }
 
 private:
     void onPlatformMakeCurrent() const override {}
diff --git a/tools/gpu/gl/win/CreatePlatformGLTestContext_win.cpp b/tools/gpu/gl/win/CreatePlatformGLTestContext_win.cpp
index 5fc355a..669d6d0 100644
--- a/tools/gpu/gl/win/CreatePlatformGLTestContext_win.cpp
+++ b/tools/gpu/gl/win/CreatePlatformGLTestContext_win.cpp
@@ -127,8 +127,8 @@
         return;
     }
 
-    sk_sp<const GrGLInterface> gl(GrGLCreateNativeInterface());
-    if (nullptr == gl.get()) {
+    auto gl = GrGLMakeNativeInterface();
+    if (!gl) {
         SkDebugf("Could not create GL interface.\n");
         this->destroyGLContext();
         return;
@@ -139,7 +139,7 @@
         return;
     }
 
-    this->init(gl.release());
+    this->init(std::move(gl));
 }
 
 WinGLTestContext::~WinGLTestContext() {