diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gpu/gl/angle/GrGLCreateANGLEInterface.cpp | 19 | ||||
-rw-r--r-- | src/gpu/gl/command_buffer/SkCommandBufferGLContext.cpp | 44 | ||||
-rw-r--r-- | src/ports/SkOSLibrary.h | 16 | ||||
-rw-r--r-- | src/ports/SkOSLibrary_posix.cpp | 18 | ||||
-rw-r--r-- | src/ports/SkOSLibrary_win.cpp | 17 |
5 files changed, 79 insertions, 35 deletions
diff --git a/src/gpu/gl/angle/GrGLCreateANGLEInterface.cpp b/src/gpu/gl/angle/GrGLCreateANGLEInterface.cpp index 9a4dffb4b1..1ebd376288 100644 --- a/src/gpu/gl/angle/GrGLCreateANGLEInterface.cpp +++ b/src/gpu/gl/angle/GrGLCreateANGLEInterface.cpp @@ -6,25 +6,14 @@ * found in the LICENSE file. */ - #include "gl/GrGLInterface.h" #include "gl/GrGLAssembleInterface.h" - -#if defined _WIN32 -#define WIN32_LEAN_AND_MEAN -#include <windows.h> -#else -#include <dlfcn.h> -#endif // defined _WIN32 +#include "../ports/SkOSLibrary.h" #include <EGL/egl.h> static GrGLFuncPtr angle_get_gl_proc(void* ctx, const char name[]) { -#if defined _WIN32 - GrGLFuncPtr proc = (GrGLFuncPtr) GetProcAddress((HMODULE)ctx, name); -#else - GrGLFuncPtr proc = (GrGLFuncPtr) dlsym(ctx, name); -#endif // defined _WIN32 + GrGLFuncPtr proc = (GrGLFuncPtr) GetProcedureAddress(ctx, name); if (proc) { return proc; } @@ -37,9 +26,9 @@ const GrGLInterface* GrGLCreateANGLEInterface() { if (nullptr == gANGLELib) { // We load the ANGLE library and never let it go #if defined _WIN32 - gANGLELib = LoadLibrary("libGLESv2.dll"); + gANGLELib = DynamicLoadLibrary("libGLESv2.dll"); #else - gANGLELib = dlopen("libGLESv2.so", RTLD_LAZY); + gANGLELib = DynamicLoadLibrary("libGLESv2.so"); #endif // defined _WIN32 } diff --git a/src/gpu/gl/command_buffer/SkCommandBufferGLContext.cpp b/src/gpu/gl/command_buffer/SkCommandBufferGLContext.cpp index 11a8444853..bb1908651f 100644 --- a/src/gpu/gl/command_buffer/SkCommandBufferGLContext.cpp +++ b/src/gpu/gl/command_buffer/SkCommandBufferGLContext.cpp @@ -11,6 +11,7 @@ #include "gl/GrGLInterface.h" #include "gl/GrGLAssembleInterface.h" #include "gl/command_buffer/SkCommandBufferGLContext.h" +#include "../ports/SkOSLibrary.h" typedef EGLDisplay (*GetDisplayProc)(EGLNativeDisplayType display_id); typedef EGLBoolean (*InitializeProc)(EGLDisplay dpy, EGLint *major, EGLint *minor); @@ -40,27 +41,30 @@ static MakeCurrentProc gfMakeCurrent = nullptr; static SwapBuffersProc gfSwapBuffers = nullptr; static GetProcAddressProc gfGetProcAddress = nullptr; -static HMODULE ghLibrary = nullptr; +static void* gLibrary = nullptr; static bool gfFunctionsLoadedSuccessfully = false; static void load_command_buffer_functions() { - if (!ghLibrary) { - ghLibrary = LoadLibrary("command_buffer_gles2.dll"); - - if (ghLibrary) { - gfGetDisplay = (GetDisplayProc)::GetProcAddress(ghLibrary, "eglGetDisplay"); - gfInitialize = (InitializeProc)::GetProcAddress(ghLibrary, "eglInitialize"); - gfTerminate = (TerminateProc)::GetProcAddress(ghLibrary, "eglTerminate"); - gfChooseConfig = (ChooseConfigProc)::GetProcAddress(ghLibrary, "eglChooseConfig"); - gfGetConfigAttrib = (GetConfigAttrib)::GetProcAddress(ghLibrary, "eglGetConfigAttrib"); - gfCreateWindowSurface = (CreateWindowSurfaceProc)::GetProcAddress(ghLibrary, "eglCreateWindowSurface"); - gfCreatePbufferSurface = (CreatePbufferSurfaceProc)::GetProcAddress(ghLibrary, "eglCreatePbufferSurface"); - gfDestroySurface = (DestroySurfaceProc)::GetProcAddress(ghLibrary, "eglDestroySurface"); - gfCreateContext = (CreateContextProc)::GetProcAddress(ghLibrary, "eglCreateContext"); - gfDestroyContext = (DestroyContextProc)::GetProcAddress(ghLibrary, "eglDestroyContext"); - gfMakeCurrent = (MakeCurrentProc)::GetProcAddress(ghLibrary, "eglMakeCurrent"); - gfSwapBuffers = (SwapBuffersProc)::GetProcAddress(ghLibrary, "eglSwapBuffers"); - gfGetProcAddress = (GetProcAddressProc)::GetProcAddress(ghLibrary, "eglGetProcAddress"); + if (!gLibrary) { +#if defined _WIN32 + gLibrary = DynamicLoadLibrary("command_buffer_gles2.dll"); +#else + gLibrary = DynamicLoadLibrary("libcommand_buffer_gles2.so"); +#endif // defined _WIN32 + if (gLibrary) { + gfGetDisplay = (GetDisplayProc)GetProcedureAddress(gLibrary, "eglGetDisplay"); + gfInitialize = (InitializeProc)GetProcedureAddress(gLibrary, "eglInitialize"); + gfTerminate = (TerminateProc)GetProcedureAddress(gLibrary, "eglTerminate"); + gfChooseConfig = (ChooseConfigProc)GetProcedureAddress(gLibrary, "eglChooseConfig"); + gfGetConfigAttrib = (GetConfigAttrib)GetProcedureAddress(gLibrary, "eglGetConfigAttrib"); + gfCreateWindowSurface = (CreateWindowSurfaceProc)GetProcedureAddress(gLibrary, "eglCreateWindowSurface"); + gfCreatePbufferSurface = (CreatePbufferSurfaceProc)GetProcedureAddress(gLibrary, "eglCreatePbufferSurface"); + gfDestroySurface = (DestroySurfaceProc)GetProcedureAddress(gLibrary, "eglDestroySurface"); + gfCreateContext = (CreateContextProc)GetProcedureAddress(gLibrary, "eglCreateContext"); + gfDestroyContext = (DestroyContextProc)GetProcedureAddress(gLibrary, "eglDestroyContext"); + gfMakeCurrent = (MakeCurrentProc)GetProcedureAddress(gLibrary, "eglMakeCurrent"); + gfSwapBuffers = (SwapBuffersProc)GetProcedureAddress(gLibrary, "eglSwapBuffers"); + gfGetProcAddress = (GetProcAddressProc)GetProcedureAddress(gLibrary, "eglGetProcAddress"); gfFunctionsLoadedSuccessfully = gfGetDisplay && gfInitialize && gfTerminate && gfChooseConfig && gfCreateWindowSurface && @@ -73,7 +77,7 @@ static void load_command_buffer_functions() { } static GrGLFuncPtr command_buffer_get_gl_proc(void* ctx, const char name[]) { - GrGLFuncPtr proc = (GrGLFuncPtr) GetProcAddress((HMODULE)ctx, name); + GrGLFuncPtr proc = (GrGLFuncPtr) GetProcedureAddress(ctx, name); if (proc) { return proc; } @@ -93,7 +97,7 @@ const GrGLInterface* GrGLCreateCommandBufferInterface() { if (!gfFunctionsLoadedSuccessfully) { return nullptr; } - return GrGLAssembleGLESInterface(ghLibrary, command_buffer_get_gl_proc); + return GrGLAssembleGLESInterface(gLibrary, command_buffer_get_gl_proc); } SkCommandBufferGLContext::SkCommandBufferGLContext() diff --git a/src/ports/SkOSLibrary.h b/src/ports/SkOSLibrary.h new file mode 100644 index 0000000000..7de2b902e3 --- /dev/null +++ b/src/ports/SkOSLibrary.h @@ -0,0 +1,16 @@ + +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkOSLibrary_DEFINED +#define SkOSLibrary_DEFINED + +void* DynamicLoadLibrary(const char* libraryName); +void* GetProcedureAddress(void* library, const char* functionName); + +#endif + diff --git a/src/ports/SkOSLibrary_posix.cpp b/src/ports/SkOSLibrary_posix.cpp new file mode 100644 index 0000000000..cca55f16a1 --- /dev/null +++ b/src/ports/SkOSLibrary_posix.cpp @@ -0,0 +1,18 @@ + +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#include "SkOSLibrary.h" + +#include <dlfcn.h> + +void* DynamicLoadLibrary(const char* libraryName) { + return dlopen(libraryName, RTLD_LAZY); +} + +void* GetProcedureAddress(void* library, const char* functionName) { + return dlsym(library, functionName); +} diff --git a/src/ports/SkOSLibrary_win.cpp b/src/ports/SkOSLibrary_win.cpp new file mode 100644 index 0000000000..ca80415391 --- /dev/null +++ b/src/ports/SkOSLibrary_win.cpp @@ -0,0 +1,17 @@ + +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#include "SkOSLibrary.h" +#include <windows.h> + +void* DynamicLoadLibrary(const char* libraryName) { + return LoadLibrary(libraryName); +} + +void* GetProcedureAddress(void* library, const char* functionName) { + return ::GetProcAddress((HMODULE)library, functionName); +} |