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/BUILD.gn b/BUILD.gn
index d838ccd..bfb4be0 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -546,42 +546,37 @@
]
public_defines = []
- sources = skia_gpu_sources + skia_sksl_sources +
- [ "src/gpu/gl/GrGLDefaultInterface_native.cpp" ] +
- skia_gpu_processor_outputs
+ sources = skia_gpu_sources + skia_sksl_sources + skia_gpu_processor_outputs
# These paths need to be absolute to match the ones produced by shared_sources.gni.
- sources -= get_path_info([
- "src/gpu/gl/GrGLCreateNativeInterface_none.cpp",
- "src/gpu/gl/GrGLDefaultInterface_none.cpp",
- ],
+ sources -= get_path_info([ "src/gpu/gl/GrGLMakeNativeInterface_none.cpp" ],
"abspath")
libs = []
if (is_android) {
- sources += [ "src/gpu/gl/android/GrGLCreateNativeInterface_android.cpp" ]
+ sources += [ "src/gpu/gl/android/GrGLMakeNativeInterface_android.cpp" ]
# this lib is required to link against AHardwareBuffer
if (defined(ndk_api) && ndk_api >= 26) {
libs += [ "android" ]
}
} else if (skia_use_egl) {
- sources += [ "src/gpu/gl/egl/GrGLCreateNativeInterface_egl.cpp" ]
+ sources += [ "src/gpu/gl/egl/GrGLMakeNativeInterface_egl.cpp" ]
libs += [ "EGL" ]
} else if (is_linux) {
- sources += [ "src/gpu/gl/glx/GrGLCreateNativeInterface_glx.cpp" ]
+ sources += [ "src/gpu/gl/glx/GrGLMakeNativeInterface_glx.cpp" ]
libs += [
"GL",
"GLU",
]
} else if (is_mac) {
- sources += [ "src/gpu/gl/mac/GrGLCreateNativeInterface_mac.cpp" ]
+ sources += [ "src/gpu/gl/mac/GrGLMakeNativeInterface_mac.cpp" ]
} else if (is_ios) {
- sources += [ "src/gpu/gl/iOS/GrGLCreateNativeInterface_iOS.cpp" ]
+ sources += [ "src/gpu/gl/iOS/GrGLMakeNativeInterface_iOS.cpp" ]
} else if (is_win) {
- sources += [ "src/gpu/gl/win/GrGLCreateNativeInterface_win.cpp" ]
+ sources += [ "src/gpu/gl/win/GrGLMakeNativeInterface_win.cpp" ]
libs += [ "OpenGL32.lib" ]
} else {
- sources += [ "src/gpu/gl/GrGLCreateNativeInterface_none.cpp" ]
+ sources += [ "src/gpu/gl/GrGLMakeNativeInterface_none.cpp" ]
}
if (skia_use_vulkan) {
diff --git a/debugger/QT/SkGLWidget.cpp b/debugger/QT/SkGLWidget.cpp
index 98874d2..f80ffaf 100644
--- a/debugger/QT/SkGLWidget.cpp
+++ b/debugger/QT/SkGLWidget.cpp
@@ -27,7 +27,7 @@
void SkGLWidget::initializeGL() {
if (!fCurIntf) {
- fCurIntf.reset(GrGLCreateNativeInterface());
+ fCurIntf = GrGLMakeNativeInterface();
}
if (!fCurIntf) {
return;
diff --git a/example/SkiaSDLExample.cpp b/example/SkiaSDLExample.cpp
index ab181cb..3e23e57 100644
--- a/example/SkiaSDLExample.cpp
+++ b/example/SkiaSDLExample.cpp
@@ -189,7 +189,7 @@
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
// setup GrContext
- sk_sp<const GrGLInterface> interface(GrGLCreateNativeInterface());
+ auto interface = GrGLMakeNativeInterface();
// setup contexts
sk_sp<GrContext> grContext(GrContext::MakeGL(interface));
diff --git a/gn/gpu.gni b/gn/gpu.gni
index a16a9f9..d1cc8ba 100644
--- a/gn/gpu.gni
+++ b/gn/gpu.gni
@@ -407,9 +407,8 @@
"$_src/gpu/gl/GrGLCaps.h",
"$_src/gpu/gl/GrGLContext.cpp",
"$_src/gpu/gl/GrGLContext.h",
- "$_src/gpu/gl/GrGLCreateNativeInterface_none.cpp",
+ "$_src/gpu/gl/GrGLMakeNativeInterface_none.cpp",
"$_src/gpu/gl/GrGLCreateNullInterface.cpp",
- "$_src/gpu/gl/GrGLDefaultInterface_none.cpp",
"$_src/gpu/gl/GrGLDefines.h",
"$_src/gpu/gl/GrGLGLSL.cpp",
"$_src/gpu/gl/GrGLGLSL.h",
@@ -611,13 +610,12 @@
]
skia_native_gpu_sources = [
- "$_src/gpu/gl/GrGLDefaultInterface_native.cpp",
- "$_src/gpu/gl/mac/GrGLCreateNativeInterface_mac.cpp",
- "$_src/gpu/gl/win/GrGLCreateNativeInterface_win.cpp",
- "$_src/gpu/gl/glx/GrGLCreateNativeInterface_glx.cpp",
- "$_src/gpu/gl/egl/GrGLCreateNativeInterface_egl.cpp",
- "$_src/gpu/gl/iOS/GrGLCreateNativeInterface_iOS.cpp",
- "$_src/gpu/gl/android/GrGLCreateNativeInterface_android.cpp",
+ "$_src/gpu/gl/mac/GrGLMakeNativeInterface_mac.cpp",
+ "$_src/gpu/gl/win/GrGLMakeNativeInterface_win.cpp",
+ "$_src/gpu/gl/glx/GrGLMakeNativeInterface_glx.cpp",
+ "$_src/gpu/gl/egl/GrGLMakeNativeInterface_egl.cpp",
+ "$_src/gpu/gl/iOS/GrGLMakeNativeInterface_iOS.cpp",
+ "$_src/gpu/gl/android/GrGLMakeNativeInterface_android.cpp",
]
skia_atlas_text_sources = [
diff --git a/include/gpu/GrTypes.h b/include/gpu/GrTypes.h
index 08eb2da..3081543 100644
--- a/include/gpu/GrTypes.h
+++ b/include/gpu/GrTypes.h
@@ -197,7 +197,7 @@
/**
* Backend-specific 3D context handle
- * OpenGL: const GrGLInterface*. If null will use the result of GrGLCreateNativeInterface().
+ * OpenGL: const GrGLInterface*. If null will use the result of GrGLMakeNativeInterface().
* Vulkan: GrVkBackendContext*.
* Mock: const GrMockOptions* or null for default constructed GrMockContextOptions.
*/
diff --git a/include/gpu/gl/GrGLAssembleInterface.h b/include/gpu/gl/GrGLAssembleInterface.h
index b9881a9..db44ce7 100644
--- a/include/gpu/gl/GrGLAssembleInterface.h
+++ b/include/gpu/gl/GrGLAssembleInterface.h
@@ -9,22 +9,21 @@
typedef GrGLFuncPtr (*GrGLGetProc)(void* ctx, const char name[]);
-
/**
* Generic function for creating a GrGLInterface for an either OpenGL or GLES. It calls
* get() to get each function address. ctx is a generic ptr passed to and interpreted by get().
*/
-SK_API const GrGLInterface* GrGLAssembleInterface(void* ctx, GrGLGetProc get);
+SK_API sk_sp<const GrGLInterface> GrGLAssembleInterface(void* ctx, GrGLGetProc get);
/**
* Generic function for creating a GrGLInterface for an OpenGL (but not GLES) context. It calls
* get() to get each function address. ctx is a generic ptr passed to and interpreted by get().
*/
-SK_API const GrGLInterface* GrGLAssembleGLInterface(void* ctx, GrGLGetProc get);
+SK_API sk_sp<const GrGLInterface> GrGLAssembleGLInterface(void* ctx, GrGLGetProc get);
/**
* Generic function for creating a GrGLInterface for an OpenGL ES (but not Open GL) context. It
* calls get() to get each function address. ctx is a generic ptr passed to and interpreted by
* get().
*/
-SK_API const GrGLInterface* GrGLAssembleGLESInterface(void* ctx, GrGLGetProc get);
+SK_API sk_sp<const GrGLInterface> GrGLAssembleGLESInterface(void* ctx, GrGLGetProc get);
diff --git a/include/gpu/gl/GrGLInterface.h b/include/gpu/gl/GrGLInterface.h
index e752c2d..e6451ec 100644
--- a/include/gpu/gl/GrGLInterface.h
+++ b/include/gpu/gl/GrGLInterface.h
@@ -14,40 +14,26 @@
////////////////////////////////////////////////////////////////////////////////
+typedef void(*GrGLFuncPtr)();
+struct GrGLInterface;
+
+
/**
* Rather than depend on platform-specific GL headers and libraries, we require
* the client to provide a struct of GL function pointers. This struct can be
* specified per-GrContext as a parameter to GrContext::MakeGL. If NULL is
- * passed to MakeGL then a "default" GL interface is created. If the default is
+ * passed to MakeGL then a "native" GL interface is created. If the native is
* also NULL GrContext creation will fail.
*
- * The default interface is returned by GrGLDefaultInterface. This function's
- * implementation is platform-specific. Several have been provided, along with
- * an implementation that simply returns NULL.
- *
- * By defining GR_GL_PER_GL_CALL_IFACE_CALLBACK to 1 the client can specify a
- * callback function that will be called prior to each GL function call. See
- * comments in GrGLConfig.h
+ * The default interface is returned by GrGLMakeNativeInterface. This function's
+ * implementation is platform-specific. Several have been provided
+ * (for GLX, WGL, EGL, etc), along with an implementation that simply returns
+ * NULL.
*/
-
-typedef void(*GrGLFuncPtr)();
-
-struct GrGLInterface;
-
-const GrGLInterface* GrGLDefaultInterface();
-
-/**
- * Creates a GrGLInterface for a "native" GL context (e.g. WGL on windows,
- * GLX on linux, AGL on Mac). The interface is only valid for the GL context
- * that is current when the interface is created.
- */
+SK_API sk_sp<const GrGLInterface> GrGLMakeNativeInterface();
+// Deprecated alternative to GrGLMakeNativeInterface().
SK_API const GrGLInterface* GrGLCreateNativeInterface();
-#if GR_GL_PER_GL_FUNC_CALLBACK
-typedef void (*GrGLInterfaceCallbackProc)(const GrGLInterface*);
-typedef intptr_t GrGLInterfaceCallbackData;
-#endif
-
/**
* Creates a null GrGLInterface that doesn't draw anything. Used for measuring
* CPU overhead. TODO: We would like to move this to tools/gpu/gl/null but currently
@@ -55,13 +41,6 @@
*/
const SK_API GrGLInterface* GrGLCreateNullInterface(bool enableNVPR = false);
-/** Function that returns a new interface identical to "interface" but with support for
- test version of GL_EXT_debug_marker. */
-const GrGLInterface* GrGLInterfaceAddTestDebugMarker(const GrGLInterface*,
- GrGLInsertEventMarkerProc insertEventMarkerFn,
- GrGLPushGroupMarkerProc pushGroupMarkerFn,
- GrGLPopGroupMarkerProc popGroupMarkerFn);
-
/**
* GrContext uses the following interface to make all calls into OpenGL. When a
* GrContext is created it is given a GrGLInterface. The interface's function
@@ -80,8 +59,6 @@
public:
GrGLInterface();
- static GrGLInterface* NewClone(const GrGLInterface*);
-
// Validates that the GrGLInterface supports its advertised standard. This means the necessary
// function pointers have been initialized for both the GL version and any advertised
// extensions.
diff --git a/public.bzl b/public.bzl
index 7d2ee5d..e01e9da 100644
--- a/public.bzl
+++ b/public.bzl
@@ -233,9 +233,7 @@
# Exclude multiple definitions.
# TODO(mtklein): Move to opts?
"src/pdf/SkDocument_PDF_None.cpp", # We use src/pdf/SkPDFDocument.cpp.
- "src/gpu/gl/GrGLCreateNativeInterface_none.cpp",
- "src/gpu/gl/GrGLDefaultInterface_native.cpp",
- "src/gpu/gl/GrGLDefaultInterface_none.cpp",
+ "src/gpu/gl/GrGLMakeNativeInterface_none.cpp",
# Exclude files that don't compile with the current DEFINES.
"src/svg/**/*", # Depends on XML.
@@ -276,7 +274,6 @@
# Platform-dependent SRCS for google3-default platform.
BASE_SRCS_UNIX = struct(
include = [
- "src/gpu/gl/GrGLDefaultInterface_none.cpp",
"src/ports/**/*.cpp",
"src/ports/**/*.h",
],
@@ -304,7 +301,6 @@
# Platform-dependent SRCS for google3-default Android.
BASE_SRCS_ANDROID = struct(
include = [
- "src/gpu/gl/GrGLDefaultInterface_none.cpp",
# TODO(benjaminwagner): Figure out how to compile with EGL.
"src/ports/**/*.cpp",
"src/ports/**/*.h",
@@ -333,8 +329,7 @@
# Platform-dependent SRCS for google3-default iOS.
BASE_SRCS_IOS = struct(
include = [
- "src/gpu/gl/GrGLDefaultInterface_native.cpp",
- "src/gpu/gl/iOS/GrGLCreateNativeInterface_iOS.cpp",
+ "src/gpu/gl/iOS/GrGLMakeNativeInterface_iOS.cpp",
"src/ports/**/*.cpp",
"src/ports/**/*.h",
"src/utils/mac/*.cpp",
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)
diff --git a/tools/fiddle/egl_context.cpp b/tools/fiddle/egl_context.cpp
index 696a86f..c82382b 100644
--- a/tools/fiddle/egl_context.cpp
+++ b/tools/fiddle/egl_context.cpp
@@ -71,7 +71,7 @@
driverinfo << "GL Renderer: " << getString(GL_RENDERER) << "\n";
driverinfo << "GL Extensions: " << getString(GL_EXTENSIONS) << "\n";
- auto interface = GrGLCreateNativeInterface();
+ auto interface = GrGLMakeNativeInterface();
if (!interface) {
return nullptr;
}
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() {
diff --git a/tools/sk_app/android/GLWindowContext_android.cpp b/tools/sk_app/android/GLWindowContext_android.cpp
index 9448659..acdb587 100644
--- a/tools/sk_app/android/GLWindowContext_android.cpp
+++ b/tools/sk_app/android/GLWindowContext_android.cpp
@@ -121,7 +121,7 @@
SkASSERT(EGL_NO_SURFACE != fSurfaceAndroid);
SkAssertResult(eglMakeCurrent(fDisplay, fSurfaceAndroid, fSurfaceAndroid, fEGLContext));
- // GLWindowContext::initializeContext will call GrGLCreateNativeInterface so we
+ // GLWindowContext::initializeContext will call GrGLMakeNativeInterface so we
// won't call it here.
glClearStencil(0);
@@ -132,7 +132,7 @@
eglGetConfigAttrib(fDisplay, surfaceConfig, EGL_STENCIL_SIZE, &fStencilBits);
eglGetConfigAttrib(fDisplay, surfaceConfig, EGL_SAMPLES, &fSampleCount);
- return sk_sp<const GrGLInterface>(GrGLCreateNativeInterface());
+ return GrGLMakeNativeInterface();
}
void GLWindowContext_android::onDestroyContext() {
diff --git a/tools/sk_app/ios/GLWindowContext_ios.cpp b/tools/sk_app/ios/GLWindowContext_ios.cpp
index 30bacf5..f4c0d6b 100644
--- a/tools/sk_app/ios/GLWindowContext_ios.cpp
+++ b/tools/sk_app/ios/GLWindowContext_ios.cpp
@@ -73,7 +73,7 @@
} else {
SkDebugf("MakeCurrent failed: %s\n", SDL_GetError());
}
- return sk_sp<const GrGLInterface>(GrGLCreateNativeInterface());
+ return GrGLMakeNativeInterface();
}
void GLWindowContext_ios::onDestroyContext() {
diff --git a/tools/sk_app/ios/RasterWindowContext_ios.cpp b/tools/sk_app/ios/RasterWindowContext_ios.cpp
index 08b6560..cae5774 100644
--- a/tools/sk_app/ios/RasterWindowContext_ios.cpp
+++ b/tools/sk_app/ios/RasterWindowContext_ios.cpp
@@ -90,7 +90,7 @@
SkImageInfo info = SkImageInfo::Make(fWidth, fHeight, fDisplayParams.fColorType,
kPremul_SkAlphaType, fDisplayParams.fColorSpace);
fBackbufferSurface = SkSurface::MakeRaster(info);
- return sk_sp<const GrGLInterface>(GrGLCreateNativeInterface());
+ return GrGLMakeNativeInterface();
}
void RasterWindowContext_ios::onDestroyContext() {
diff --git a/tools/sk_app/mac/GLWindowContext_mac.cpp b/tools/sk_app/mac/GLWindowContext_mac.cpp
index 7f09d54..005fc07 100644
--- a/tools/sk_app/mac/GLWindowContext_mac.cpp
+++ b/tools/sk_app/mac/GLWindowContext_mac.cpp
@@ -73,7 +73,7 @@
} else {
SkDebugf("MakeCurrent failed: %s\n", SDL_GetError());
}
- return sk_sp<const GrGLInterface>(GrGLCreateNativeInterface());
+ return GrGLMakeNativeInterface();
}
void GLWindowContext_mac::onDestroyContext() {
diff --git a/tools/sk_app/mac/RasterWindowContext_mac.cpp b/tools/sk_app/mac/RasterWindowContext_mac.cpp
index 409c49f..67022af 100644
--- a/tools/sk_app/mac/RasterWindowContext_mac.cpp
+++ b/tools/sk_app/mac/RasterWindowContext_mac.cpp
@@ -90,7 +90,7 @@
SkImageInfo info = SkImageInfo::Make(fWidth, fHeight, fDisplayParams.fColorType,
kPremul_SkAlphaType, fDisplayParams.fColorSpace);
fBackbufferSurface = SkSurface::MakeRaster(info);
- return sk_sp<const GrGLInterface>(GrGLCreateNativeInterface());
+ return GrGLMakeNativeInterface();
}
void RasterWindowContext_mac::onDestroyContext() {
diff --git a/tools/sk_app/unix/GLWindowContext_unix.cpp b/tools/sk_app/unix/GLWindowContext_unix.cpp
index d7a4387..25ec95c 100644
--- a/tools/sk_app/unix/GLWindowContext_unix.cpp
+++ b/tools/sk_app/unix/GLWindowContext_unix.cpp
@@ -107,7 +107,7 @@
&border_width, &depth);
glViewport(0, 0, fWidth, fHeight);
- return sk_sp<const GrGLInterface>(GrGLCreateNativeInterface());
+ return GrGLMakeNativeInterface();
}
GLWindowContext_xlib::~GLWindowContext_xlib() {
diff --git a/tools/sk_app/win/GLWindowContext_win.cpp b/tools/sk_app/win/GLWindowContext_win.cpp
index 17a6b32..7e43d2b 100644
--- a/tools/sk_app/win/GLWindowContext_win.cpp
+++ b/tools/sk_app/win/GLWindowContext_win.cpp
@@ -61,9 +61,9 @@
// Look to see if RenderDoc is attached. If so, re-create the context with a core profile
if (wglMakeCurrent(dc, fHGLRC)) {
- const GrGLInterface* glInterface = GrGLCreateNativeInterface();
- bool renderDocAttached = glInterface->hasExtension("GL_EXT_debug_tool");
- SkSafeUnref(glInterface);
+ auto interface = GrGLMakeNativeInterface();
+ bool renderDocAttached = interface->hasExtension("GL_EXT_debug_tool");
+ interface.reset(nullptr);
if (renderDocAttached) {
wglDeleteContext(fHGLRC);
fHGLRC = SkCreateWGLContext(dc, fDisplayParams.fMSAASampleCount, false /* deepColor */,
@@ -106,7 +106,7 @@
fHeight = rect.bottom - rect.top;
glViewport(0, 0, fWidth, fHeight);
}
- return sk_sp<const GrGLInterface>(GrGLCreateNativeInterface());
+ return GrGLMakeNativeInterface();
}