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/src/gpu/gl/GrGLAssembleInterface.cpp b/src/gpu/gl/GrGLAssembleInterface.cpp
index b7698f1..c5e9901 100644
--- a/src/gpu/gl/GrGLAssembleInterface.cpp
+++ b/src/gpu/gl/GrGLAssembleInterface.cpp
@@ -15,7 +15,7 @@
 
 #define GET_EGL_PROC_SUFFIX(F, S) functions->fEGL ## F = (GrEGL ## F ## Proc) get(ctx, "egl" #F #S)
 
-const GrGLInterface* GrGLAssembleInterface(void* ctx, GrGLGetProc get) {
+sk_sp<const GrGLInterface> GrGLAssembleInterface(void* ctx, GrGLGetProc get) {
     GET_PROC_LOCAL(GetString);
     if (nullptr == GetString) {
         return nullptr;
@@ -51,7 +51,7 @@
     }
 }
 
-const GrGLInterface* GrGLAssembleGLInterface(void* ctx, GrGLGetProc get) {
+sk_sp<const GrGLInterface> GrGLAssembleGLInterface(void* ctx, GrGLGetProc get) {
     GET_PROC_LOCAL(GetString);
     GET_PROC_LOCAL(GetStringi);
     GET_PROC_LOCAL(GetIntegerv);
@@ -78,7 +78,7 @@
         return nullptr;
     }
 
-    GrGLInterface* interface = new GrGLInterface();
+    sk_sp<GrGLInterface> interface(new GrGLInterface());
     GrGLInterface::Functions* functions = &interface->fFunctions;
 
     GET_PROC(ActiveTexture);
@@ -315,7 +315,6 @@
         }
     } else {
         // we must have FBOs
-        delete interface;
         return nullptr;
     }
 
@@ -547,7 +546,7 @@
     return interface;
 }
 
-const GrGLInterface* GrGLAssembleGLESInterface(void* ctx, GrGLGetProc get) {
+sk_sp<const GrGLInterface> GrGLAssembleGLESInterface(void* ctx, GrGLGetProc get) {
     GET_PROC_LOCAL(GetString);
     if (nullptr == GetString) {
         return nullptr;
@@ -571,7 +570,7 @@
         return nullptr;
     }
 
-    GrGLInterface* interface = new GrGLInterface;
+    sk_sp<GrGLInterface> interface(new GrGLInterface);
     GrGLInterface::Functions* functions = &interface->fFunctions;
 
     GET_PROC(ActiveTexture);
diff --git a/src/gpu/gl/GrGLCreateNativeInterface_none.cpp b/src/gpu/gl/GrGLCreateNativeInterface_none.cpp
deleted file mode 100644
index 0a0f279..0000000
--- a/src/gpu/gl/GrGLCreateNativeInterface_none.cpp
+++ /dev/null
@@ -1,12 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "gl/GrGLInterface.h"
-
-const GrGLInterface* GrGLCreateNativeInterface() {
-    return nullptr;
-}
diff --git a/src/gpu/gl/GrGLDefaultInterface_native.cpp b/src/gpu/gl/GrGLDefaultInterface_native.cpp
deleted file mode 100644
index e695f15..0000000
--- a/src/gpu/gl/GrGLDefaultInterface_native.cpp
+++ /dev/null
@@ -1,12 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "gl/GrGLInterface.h"
-
-const GrGLInterface* GrGLDefaultInterface() {
-    return GrGLCreateNativeInterface();
-}
diff --git a/src/gpu/gl/GrGLDefaultInterface_none.cpp b/src/gpu/gl/GrGLDefaultInterface_none.cpp
deleted file mode 100644
index f9e5247..0000000
--- a/src/gpu/gl/GrGLDefaultInterface_none.cpp
+++ /dev/null
@@ -1,12 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "gl/GrGLInterface.h"
-
-const GrGLInterface* GrGLDefaultInterface() {
-    return nullptr;
-}
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index c11f598..ddb80b4 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -184,7 +184,12 @@
 sk_sp<GrGpu> GrGLGpu::Make(sk_sp<const GrGLInterface> interface, const GrContextOptions& options,
                            GrContext* context) {
     if (!interface) {
-        interface.reset(GrGLDefaultInterface());
+        interface = GrGLMakeNativeInterface();
+        // For clients that have written their own GrGLCreateNativeInterface and haven't yet updated
+        // to GrGLMakeNativeInterface.
+        if (!interface) {
+            interface = sk_ref_sp(GrGLCreateNativeInterface());
+        }
         if (!interface) {
             return nullptr;
         }
diff --git a/src/gpu/gl/GrGLInterface.cpp b/src/gpu/gl/GrGLInterface.cpp
index 8ce8af7..2e7924d 100644
--- a/src/gpu/gl/GrGLInterface.cpp
+++ b/src/gpu/gl/GrGLInterface.cpp
@@ -12,37 +12,10 @@
 
 #include <stdio.h>
 
-const GrGLInterface* GrGLInterfaceAddTestDebugMarker(const GrGLInterface* interface,
-                                                     GrGLInsertEventMarkerProc insertEventMarkerFn,
-                                                     GrGLPushGroupMarkerProc pushGroupMarkerFn,
-                                                     GrGLPopGroupMarkerProc popGroupMarkerFn) {
-    GrGLInterface* newInterface = GrGLInterface::NewClone(interface);
-
-    if (!newInterface->fExtensions.has("GL_EXT_debug_marker")) {
-        newInterface->fExtensions.add("GL_EXT_debug_marker");
-    }
-
-    newInterface->fFunctions.fInsertEventMarker = insertEventMarkerFn;
-    newInterface->fFunctions.fPushGroupMarker = pushGroupMarkerFn;
-    newInterface->fFunctions.fPopGroupMarker = popGroupMarkerFn;
-
-    return newInterface;
-}
-
 GrGLInterface::GrGLInterface() {
     fStandard = kNone_GrGLStandard;
 }
 
-GrGLInterface* GrGLInterface::NewClone(const GrGLInterface* interface) {
-    SkASSERT(interface);
-
-    GrGLInterface* clone = new GrGLInterface;
-    clone->fStandard = interface->fStandard;
-    clone->fExtensions = interface->fExtensions;
-    clone->fFunctions = interface->fFunctions;
-    return clone;
-}
-
 #ifdef SK_DEBUG
     static int kIsDebug = 1;
 #else
diff --git a/src/gpu/gl/GrGLMakeNativeInterface_none.cpp b/src/gpu/gl/GrGLMakeNativeInterface_none.cpp
new file mode 100644
index 0000000..6d460c5
--- /dev/null
+++ b/src/gpu/gl/GrGLMakeNativeInterface_none.cpp
@@ -0,0 +1,12 @@
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "gl/GrGLInterface.h"
+
+sk_sp<const GrGLInterface> GrGLMakeNativeInterface() { return nullptr; }
+
+const GrGLInterface* GrGLCreateNativeInterface() { return nullptr; }
diff --git a/src/gpu/gl/android/GrGLCreateNativeInterface_android.cpp b/src/gpu/gl/android/GrGLMakeNativeInterface_android.cpp
similarity index 98%
rename from src/gpu/gl/android/GrGLCreateNativeInterface_android.cpp
rename to src/gpu/gl/android/GrGLMakeNativeInterface_android.cpp
index 3b24964..2630e87 100644
--- a/src/gpu/gl/android/GrGLCreateNativeInterface_android.cpp
+++ b/src/gpu/gl/android/GrGLMakeNativeInterface_android.cpp
@@ -232,8 +232,10 @@
     return eglGetProcAddress(name);
 }
 
-const GrGLInterface* GrGLCreateNativeInterface() {
+sk_sp<const GrGLInterface> GrGLMakeNativeInterface() {
     return GrGLAssembleInterface(nullptr, android_get_gl_proc);
 }
 
+const GrGLInterface* GrGLCreateNativeInterface() { return GrGLMakeNativeInterface().release(); }
+
 #endif//defined(SK_BUILD_FOR_ANDROID)
diff --git a/src/gpu/gl/egl/GrGLCreateNativeInterface_egl.cpp b/src/gpu/gl/egl/GrGLMakeNativeInterface_egl.cpp
similarity index 83%
rename from src/gpu/gl/egl/GrGLCreateNativeInterface_egl.cpp
rename to src/gpu/gl/egl/GrGLMakeNativeInterface_egl.cpp
index 4f42782..3fbe037 100644
--- a/src/gpu/gl/egl/GrGLCreateNativeInterface_egl.cpp
+++ b/src/gpu/gl/egl/GrGLMakeNativeInterface_egl.cpp
@@ -24,6 +24,8 @@
     return ptr;
 }
 
-const GrGLInterface* GrGLCreateNativeInterface() {
+sk_sp<const GrGLInterface> GrGLMakeNativeInterface() {
     return GrGLAssembleInterface(nullptr, egl_get_gl_proc);
 }
+
+const GrGLInterface* GrGLCreateNativeInterface() { return GrGLMakeNativeInterface().release(); }
diff --git a/src/gpu/gl/glfw/GrGLCreateNativeInterface_glfw.cpp b/src/gpu/gl/glfw/GrGLMakeNativeInterface_glfw.cpp
similarity index 78%
rename from src/gpu/gl/glfw/GrGLCreateNativeInterface_glfw.cpp
rename to src/gpu/gl/glfw/GrGLMakeNativeInterface_glfw.cpp
index e2f6e66..3873510 100644
--- a/src/gpu/gl/glfw/GrGLCreateNativeInterface_glfw.cpp
+++ b/src/gpu/gl/glfw/GrGLMakeNativeInterface_glfw.cpp
@@ -18,10 +18,12 @@
     return glfwGetProcAddress(name);
 }
 
-const GrGLInterface* GrGLCreateNativeInterface() {
+sk_sp<const GrGLInterface> GrGLMakeNativeInterface() {
     if (nullptr == glfwGetCurrentContext()) {
         return nullptr;
     }
 
     return GrGLAssembleInterface(nullptr, glfw_get);
 }
+
+const GrGLInterface* GrGLCreateNativeInterface() { return GrGLMakeNativeInterface().release(); }
diff --git a/src/gpu/gl/glx/GrGLCreateNativeInterface_glx.cpp b/src/gpu/gl/glx/GrGLMakeNativeInterface_glx.cpp
similarity index 85%
rename from src/gpu/gl/glx/GrGLCreateNativeInterface_glx.cpp
rename to src/gpu/gl/glx/GrGLMakeNativeInterface_glx.cpp
index 246a589..4bbbe08 100644
--- a/src/gpu/gl/glx/GrGLCreateNativeInterface_glx.cpp
+++ b/src/gpu/gl/glx/GrGLMakeNativeInterface_glx.cpp
@@ -26,10 +26,12 @@
     return glXGetProcAddress(reinterpret_cast<const GLubyte*>(name));
 }
 
-const GrGLInterface* GrGLCreateNativeInterface() {
+sk_sp<const GrGLInterface> GrGLMakeNativeInterface() {
     if (nullptr == glXGetCurrentContext()) {
         return nullptr;
     }
 
     return GrGLAssembleInterface(nullptr, glx_get);
 }
+
+const GrGLInterface* GrGLCreateNativeInterface() { return GrGLMakeNativeInterface().release(); }
diff --git a/src/gpu/gl/iOS/GrGLCreateNativeInterface_iOS.cpp b/src/gpu/gl/iOS/GrGLMakeNativeInterface_iOS.cpp
similarity index 87%
rename from src/gpu/gl/iOS/GrGLCreateNativeInterface_iOS.cpp
rename to src/gpu/gl/iOS/GrGLMakeNativeInterface_iOS.cpp
index c7eb46b..a0a6ac6 100644
--- a/src/gpu/gl/iOS/GrGLCreateNativeInterface_iOS.cpp
+++ b/src/gpu/gl/iOS/GrGLMakeNativeInterface_iOS.cpp
@@ -49,7 +49,9 @@
     return getter->getProc(name);
 }
 
-const GrGLInterface* GrGLCreateNativeInterface() {
+sk_sp<const GrGLInterface> GrGLMakeNativeInterface() {
     GLProcGetter getter;
     return GrGLAssembleGLESInterface(&getter, ios_get_gl_proc);
 }
+
+const GrGLInterface* GrGLCreateNativeInterface() { return GrGLMakeNativeInterface().release(); }
diff --git a/src/gpu/gl/mac/GrGLCreateNativeInterface_mac.cpp b/src/gpu/gl/mac/GrGLMakeNativeInterface_mac.cpp
similarity index 88%
rename from src/gpu/gl/mac/GrGLCreateNativeInterface_mac.cpp
rename to src/gpu/gl/mac/GrGLMakeNativeInterface_mac.cpp
index c843d0e..7220b13 100644
--- a/src/gpu/gl/mac/GrGLCreateNativeInterface_mac.cpp
+++ b/src/gpu/gl/mac/GrGLMakeNativeInterface_mac.cpp
@@ -53,9 +53,11 @@
     return getter->getProc(name);
 }
 
-const GrGLInterface* GrGLCreateNativeInterface() {
+sk_sp<const GrGLInterface> GrGLMakeNativeInterface() {
     GLProcGetter getter;
     return GrGLAssembleGLInterface(&getter, mac_get_gl_proc);
 }
 
+const GrGLInterface* GrGLCreateNativeInterface() { return GrGLMakeNativeInterface().release(); }
+
 #endif//defined(SK_BUILD_FOR_MAC)
diff --git a/src/gpu/gl/win/GrGLCreateNativeInterface_win.cpp b/src/gpu/gl/win/GrGLMakeNativeInterface_win.cpp
similarity index 93%
rename from src/gpu/gl/win/GrGLCreateNativeInterface_win.cpp
rename to src/gpu/gl/win/GrGLMakeNativeInterface_win.cpp
index 5f26fdd..77db59a 100644
--- a/src/gpu/gl/win/GrGLCreateNativeInterface_win.cpp
+++ b/src/gpu/gl/win/GrGLMakeNativeInterface_win.cpp
@@ -62,7 +62,7 @@
  * This implementation will only work if GR_GL_FUNCTION_TYPE is __stdcall.
  * Otherwise, a springboard would be needed that hides the calling convention.
  */
-const GrGLInterface* GrGLCreateNativeInterface() {
+sk_sp<const GrGLInterface> GrGLMakeNativeInterface() {
     if (nullptr == wglGetCurrentContext()) {
         return nullptr;
     }
@@ -87,4 +87,6 @@
     return nullptr;
 }
 
+const GrGLInterface* GrGLCreateNativeInterface() { return GrGLMakeNativeInterface().release(); }
+
 #endif//defined(SK_BUILD_FOR_WIN32)