diff options
author | Brian Salomon <bsalomon@google.com> | 2017-12-11 10:06:31 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-12-11 17:54:38 +0000 |
commit | 3d6801eeee6b036de9f8d09e2ae8fa99df5a397c (patch) | |
tree | cbdcd23fe4924fbe25afae209d01bb6527244abf | |
parent | d67e5189802e89e74217244b36cc7263883d5dba (diff) |
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>
41 files changed, 112 insertions, 182 deletions
@@ -546,42 +546,37 @@ optional("gpu") { ] 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 98874d280d..f80ffaf848 100644 --- a/debugger/QT/SkGLWidget.cpp +++ b/debugger/QT/SkGLWidget.cpp @@ -27,7 +27,7 @@ void SkGLWidget::setSampleCount(int sampleCount) { void SkGLWidget::initializeGL() { if (!fCurIntf) { - fCurIntf.reset(GrGLCreateNativeInterface()); + fCurIntf = GrGLMakeNativeInterface(); } if (!fCurIntf) { return; diff --git a/example/SkiaSDLExample.cpp b/example/SkiaSDLExample.cpp index ab181cb1c1..3e23e576ed 100644 --- a/example/SkiaSDLExample.cpp +++ b/example/SkiaSDLExample.cpp @@ -189,7 +189,7 @@ int main(int argc, char** argv) { 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 a16a9f91c8..d1cc8ba88d 100644 --- a/gn/gpu.gni +++ b/gn/gpu.gni @@ -407,9 +407,8 @@ skia_gpu_sources = [ "$_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_metal_sources = [ ] 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 08eb2daa98..3081543aac 100644 --- a/include/gpu/GrTypes.h +++ b/include/gpu/GrTypes.h @@ -197,7 +197,7 @@ enum GrBackend { /** * 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 b9881a99b4..db44ce738f 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 e752c2d6e8..e6451ece3b 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 - */ - -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. + * 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. */ +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 @@ typedef intptr_t GrGLInterfaceCallbackData; */ 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 @@ private: 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 7d2ee5d1be..e01e9da0f1 100644 --- a/public.bzl +++ b/public.bzl @@ -233,9 +233,7 @@ BASE_SRCS_ALL = struct( # 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 @@ def codec_srcs(limited): # 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 @@ BASE_SRCS_UNIX = struct( # 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 @@ BASE_SRCS_ANDROID = struct( # 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 b7698f1473..c5e99015e0 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 @@ static void get_egl_query_and_display(GrEGLQueryStringProc* queryString, GrEGLDi } } -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 @@ const GrGLInterface* GrGLAssembleGLInterface(void* ctx, GrGLGetProc get) { return nullptr; } - GrGLInterface* interface = new GrGLInterface(); + sk_sp<GrGLInterface> interface(new GrGLInterface()); GrGLInterface::Functions* functions = &interface->fFunctions; GET_PROC(ActiveTexture); @@ -315,7 +315,6 @@ const GrGLInterface* GrGLAssembleGLInterface(void* ctx, GrGLGetProc get) { } } else { // we must have FBOs - delete interface; return nullptr; } @@ -547,7 +546,7 @@ const GrGLInterface* GrGLAssembleGLInterface(void* ctx, GrGLGetProc get) { 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 @@ const GrGLInterface* GrGLAssembleGLESInterface(void* ctx, GrGLGetProc get) { 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/GrGLDefaultInterface_native.cpp b/src/gpu/gl/GrGLDefaultInterface_native.cpp deleted file mode 100644 index e695f15a17..0000000000 --- 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 f9e52470bc..0000000000 --- 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 c11f598b7a..ddb80b4b62 100644 --- a/src/gpu/gl/GrGLGpu.cpp +++ b/src/gpu/gl/GrGLGpu.cpp @@ -184,7 +184,12 @@ sk_sp<GrGpu> GrGLGpu::Make(GrBackendContext backendContext, const GrContextOptio 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 8ce8af7098..2e7924d786 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/GrGLCreateNativeInterface_none.cpp b/src/gpu/gl/GrGLMakeNativeInterface_none.cpp index 0a0f279f16..6d460c5efe 100644 --- a/src/gpu/gl/GrGLCreateNativeInterface_none.cpp +++ b/src/gpu/gl/GrGLMakeNativeInterface_none.cpp @@ -7,6 +7,6 @@ #include "gl/GrGLInterface.h" -const GrGLInterface* GrGLCreateNativeInterface() { - return nullptr; -} +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 index 3b24964bb0..2630e87ba2 100644 --- a/src/gpu/gl/android/GrGLCreateNativeInterface_android.cpp +++ b/src/gpu/gl/android/GrGLMakeNativeInterface_android.cpp @@ -232,8 +232,10 @@ static GrGLFuncPtr android_get_gl_proc(void* ctx, const char name[]) { 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 index 4f427820b1..3fbe037b1c 100644 --- a/src/gpu/gl/egl/GrGLCreateNativeInterface_egl.cpp +++ b/src/gpu/gl/egl/GrGLMakeNativeInterface_egl.cpp @@ -24,6 +24,8 @@ static GrGLFuncPtr egl_get_gl_proc(void* ctx, const char name[]) { 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 index e2f6e668cd..3873510499 100644 --- a/src/gpu/gl/glfw/GrGLCreateNativeInterface_glfw.cpp +++ b/src/gpu/gl/glfw/GrGLMakeNativeInterface_glfw.cpp @@ -18,10 +18,12 @@ static GrGLFuncPtr glfw_get(void* ctx, const char name[]) { 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 index 246a589372..4bbbe087a2 100644 --- a/src/gpu/gl/glx/GrGLCreateNativeInterface_glx.cpp +++ b/src/gpu/gl/glx/GrGLMakeNativeInterface_glx.cpp @@ -26,10 +26,12 @@ static GrGLFuncPtr glx_get(void* ctx, const char name[]) { 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 index c7eb46b736..a0a6ac6615 100644 --- a/src/gpu/gl/iOS/GrGLCreateNativeInterface_iOS.cpp +++ b/src/gpu/gl/iOS/GrGLMakeNativeInterface_iOS.cpp @@ -49,7 +49,9 @@ static GrGLFuncPtr ios_get_gl_proc(void* ctx, const char name[]) { 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 index c843d0e8ca..7220b136c5 100644 --- a/src/gpu/gl/mac/GrGLCreateNativeInterface_mac.cpp +++ b/src/gpu/gl/mac/GrGLMakeNativeInterface_mac.cpp @@ -53,9 +53,11 @@ static GrGLFuncPtr mac_get_gl_proc(void* ctx, const char name[]) { 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 index 5f26fdde34..77db59a754 100644 --- a/src/gpu/gl/win/GrGLCreateNativeInterface_win.cpp +++ b/src/gpu/gl/win/GrGLMakeNativeInterface_win.cpp @@ -62,7 +62,7 @@ static GrGLFuncPtr win_get_gl_proc(void* ctx, const char name[]) { * 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 @@ const GrGLInterface* GrGLCreateNativeInterface() { 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 696a86f06b..c82382b22f 100644 --- a/tools/fiddle/egl_context.cpp +++ b/tools/fiddle/egl_context.cpp @@ -71,7 +71,7 @@ sk_sp<GrContext> create_grcontext(std::ostringstream &driverinfo) { 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 2c1d977b76..7a67a8a969 100644 --- a/tools/gpu/gl/GLTestContext.cpp +++ b/tools/gpu/gl/GLTestContext.cpp @@ -284,9 +284,8 @@ GLTestContext::~GLTestContext() { 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 02fe78e33e..cea630ac49 100644 --- a/tools/gpu/gl/GLTestContext.h +++ b/tools/gpu/gl/GLTestContext.h @@ -83,7 +83,7 @@ protected: /* * 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 3b55c40bac..7de709feae 100644 --- a/tools/gpu/gl/angle/GLTestContext_angle.cpp +++ b/tools/gpu/gl/angle/GLTestContext_angle.cpp @@ -232,7 +232,7 @@ ANGLEGLContext::ANGLEGLContext(ANGLEBackend type, ANGLEContextVersion version, 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 @@ ANGLEGLContext::ANGLEGLContext(ANGLEBackend type, ANGLEContextVersion version, } #endif - this->init(gl.release()); + this->init(std::move(gl)); } ANGLEGLContext::~ANGLEGLContext() { @@ -389,7 +389,7 @@ GrGLFuncPtr ANGLEGLContext::onPlatformGetProcAddress(const char* name) const { } // 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 5a72b93428..de7659a7a5 100644 --- a/tools/gpu/gl/angle/GLTestContext_angle.h +++ b/tools/gpu/gl/angle/GLTestContext_angle.h @@ -16,7 +16,7 @@ namespace sk_gpu_test { * 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 be2b6ad5e6..1924257be7 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 @@ static void load_command_buffer_once() { 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 @@ CommandBufferGLTestContext::CommandBufferGLTestContext(CommandBufferGLTestContex 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 @@ CommandBufferGLTestContext::CommandBufferGLTestContext(CommandBufferGLTestContex 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 e28a3a7f13..4152997b4d 100644 --- a/tools/gpu/gl/debug/DebugGLTestContext.cpp +++ b/tools/gpu/gl/debug/DebugGLTestContext.cpp @@ -1195,11 +1195,9 @@ const char* DebugInterface::kExtensions[] = { 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 4a09d2202a..03a211d603 100644 --- a/tools/gpu/gl/egl/CreatePlatformGLTestContext_egl.cpp +++ b/tools/gpu/gl/egl/CreatePlatformGLTestContext_egl.cpp @@ -186,8 +186,8 @@ EGLGLTestContext::EGLGLTestContext(GrGLStandard forcedGpuAPI, EGLGLTestContext* 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 @@ EGLGLTestContext::EGLGLTestContext(GrGLStandard forcedGpuAPI, EGLGLTestContext* 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 066784df69..3df45bda17 100644 --- a/tools/gpu/gl/glx/CreatePlatformGLTestContext_glx.cpp +++ b/tools/gpu/gl/glx/CreatePlatformGLTestContext_glx.cpp @@ -239,8 +239,8 @@ GLXGLTestContext::GLXGLTestContext(GrGLStandard forcedGpuAPI, GLXGLTestContext* 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 @@ GLXGLTestContext::GLXGLTestContext(GrGLStandard forcedGpuAPI, GLXGLTestContext* 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 65d2861483..c62a330715 100644 --- a/tools/gpu/gl/iOS/CreatePlatformGLTestContext_iOS.mm +++ b/tools/gpu/gl/iOS/CreatePlatformGLTestContext_iOS.mm @@ -66,7 +66,7 @@ IOSGLTestContext::IOSGLTestContext(IOSGLTestContext* shareContext) "/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 9f1c61e564..5b11227125 100644 --- a/tools/gpu/gl/mac/CreatePlatformGLTestContext_mac.cpp +++ b/tools/gpu/gl/mac/CreatePlatformGLTestContext_mac.cpp @@ -68,8 +68,8 @@ MacGLTestContext::MacGLTestContext(MacGLTestContext* shareContext) 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 @@ MacGLTestContext::MacGLTestContext(MacGLTestContext* shareContext) "/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 9e7279b501..de33a40e08 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 5fc355a22a..669d6d0182 100644 --- a/tools/gpu/gl/win/CreatePlatformGLTestContext_win.cpp +++ b/tools/gpu/gl/win/CreatePlatformGLTestContext_win.cpp @@ -127,8 +127,8 @@ WinGLTestContext::WinGLTestContext(GrGLStandard forcedGpuAPI, WinGLTestContext* 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 @@ WinGLTestContext::WinGLTestContext(GrGLStandard forcedGpuAPI, WinGLTestContext* 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 944865909b..acdb587230 100644 --- a/tools/sk_app/android/GLWindowContext_android.cpp +++ b/tools/sk_app/android/GLWindowContext_android.cpp @@ -121,7 +121,7 @@ sk_sp<const GrGLInterface> GLWindowContext_android::onInitializeContext() { 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 @@ sk_sp<const GrGLInterface> GLWindowContext_android::onInitializeContext() { 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 30bacf5cea..f4c0d6b3c0 100644 --- a/tools/sk_app/ios/GLWindowContext_ios.cpp +++ b/tools/sk_app/ios/GLWindowContext_ios.cpp @@ -73,7 +73,7 @@ sk_sp<const GrGLInterface> GLWindowContext_ios::onInitializeContext() { } 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 08b6560510..cae5774c28 100644 --- a/tools/sk_app/ios/RasterWindowContext_ios.cpp +++ b/tools/sk_app/ios/RasterWindowContext_ios.cpp @@ -90,7 +90,7 @@ sk_sp<const GrGLInterface> RasterWindowContext_ios::onInitializeContext() { 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 7f09d54522..005fc07df4 100644 --- a/tools/sk_app/mac/GLWindowContext_mac.cpp +++ b/tools/sk_app/mac/GLWindowContext_mac.cpp @@ -73,7 +73,7 @@ sk_sp<const GrGLInterface> GLWindowContext_mac::onInitializeContext() { } 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 409c49f218..67022af7fe 100644 --- a/tools/sk_app/mac/RasterWindowContext_mac.cpp +++ b/tools/sk_app/mac/RasterWindowContext_mac.cpp @@ -90,7 +90,7 @@ sk_sp<const GrGLInterface> RasterWindowContext_mac::onInitializeContext() { 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 d7a4387880..25ec95cdd6 100644 --- a/tools/sk_app/unix/GLWindowContext_unix.cpp +++ b/tools/sk_app/unix/GLWindowContext_unix.cpp @@ -107,7 +107,7 @@ sk_sp<const GrGLInterface> GLWindowContext_xlib::onInitializeContext() { &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 17a6b32962..7e43d2b544 100644 --- a/tools/sk_app/win/GLWindowContext_win.cpp +++ b/tools/sk_app/win/GLWindowContext_win.cpp @@ -61,9 +61,9 @@ sk_sp<const GrGLInterface> GLWindowContext_win::onInitializeContext() { // 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 @@ sk_sp<const GrGLInterface> GLWindowContext_win::onInitializeContext() { fHeight = rect.bottom - rect.top; glViewport(0, 0, fWidth, fHeight); } - return sk_sp<const GrGLInterface>(GrGLCreateNativeInterface()); + return GrGLMakeNativeInterface(); } |