| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2015 Google Inc. | 3 * Copyright 2015 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 #include "SkOnce.h" | 8 #include "SkOnce.h" |
| 9 #include "gl/GrGLInterface.h" | 9 #include "gl/GrGLInterface.h" |
| 10 #include "gl/GrGLAssembleInterface.h" | 10 #include "gl/GrGLAssembleInterface.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 #define EGL_HEIGHT 0x3056 | 47 #define EGL_HEIGHT 0x3056 |
| 48 | 48 |
| 49 #else | 49 #else |
| 50 | 50 |
| 51 #include <EGL/egl.h> | 51 #include <EGL/egl.h> |
| 52 | 52 |
| 53 #endif | 53 #endif |
| 54 | 54 |
| 55 typedef EGLDisplay (*GetDisplayProc)(EGLNativeDisplayType display_id); | 55 typedef EGLDisplay (*GetDisplayProc)(EGLNativeDisplayType display_id); |
| 56 typedef EGLBoolean (*InitializeProc)(EGLDisplay dpy, EGLint *major, EGLint *mino
r); | 56 typedef EGLBoolean (*InitializeProc)(EGLDisplay dpy, EGLint *major, EGLint *mino
r); |
| 57 typedef EGLBoolean (*TerminateProc)(EGLDisplay dpy); | 57 typedef EGLBoolean (*ReleaseThreadProc)(); |
| 58 typedef EGLBoolean (*ChooseConfigProc)(EGLDisplay dpy, const EGLint* attrib_list
, EGLConfig* configs, EGLint config_size, EGLint* num_config); | 58 typedef EGLBoolean (*ChooseConfigProc)(EGLDisplay dpy, const EGLint* attrib_list
, EGLConfig* configs, EGLint config_size, EGLint* num_config); |
| 59 typedef EGLBoolean (*GetConfigAttrib)(EGLDisplay dpy, EGLConfig config, EGLint a
ttribute, EGLint* value); | 59 typedef EGLBoolean (*GetConfigAttrib)(EGLDisplay dpy, EGLConfig config, EGLint a
ttribute, EGLint* value); |
| 60 typedef EGLSurface (*CreateWindowSurfaceProc)(EGLDisplay dpy, EGLConfig config,
EGLNativeWindowType win, const EGLint* attrib_list); | 60 typedef EGLSurface (*CreateWindowSurfaceProc)(EGLDisplay dpy, EGLConfig config,
EGLNativeWindowType win, const EGLint* attrib_list); |
| 61 typedef EGLSurface (*CreatePbufferSurfaceProc)(EGLDisplay dpy, EGLConfig config,
const EGLint* attrib_list); | 61 typedef EGLSurface (*CreatePbufferSurfaceProc)(EGLDisplay dpy, EGLConfig config,
const EGLint* attrib_list); |
| 62 typedef EGLBoolean (*DestroySurfaceProc)(EGLDisplay dpy, EGLSurface surface); | 62 typedef EGLBoolean (*DestroySurfaceProc)(EGLDisplay dpy, EGLSurface surface); |
| 63 typedef EGLContext (*CreateContextProc)(EGLDisplay dpy, EGLConfig config, EGLCon
text share_context, const EGLint* attrib_list); | 63 typedef EGLContext (*CreateContextProc)(EGLDisplay dpy, EGLConfig config, EGLCon
text share_context, const EGLint* attrib_list); |
| 64 typedef EGLBoolean (*DestroyContextProc)(EGLDisplay dpy, EGLContext ctx); | 64 typedef EGLBoolean (*DestroyContextProc)(EGLDisplay dpy, EGLContext ctx); |
| 65 typedef EGLBoolean (*MakeCurrentProc)(EGLDisplay dpy, EGLSurface draw, EGLSurfac
e read, EGLContext ctx); | 65 typedef EGLBoolean (*MakeCurrentProc)(EGLDisplay dpy, EGLSurface draw, EGLSurfac
e read, EGLContext ctx); |
| 66 typedef EGLBoolean (*SwapBuffersProc)(EGLDisplay dpy, EGLSurface surface); | 66 typedef EGLBoolean (*SwapBuffersProc)(EGLDisplay dpy, EGLSurface surface); |
| 67 typedef __eglMustCastToProperFunctionPointerType (*GetProcAddressProc)(const cha
r* procname); | 67 typedef __eglMustCastToProperFunctionPointerType (*GetProcAddressProc)(const cha
r* procname); |
| 68 | 68 |
| 69 static GetDisplayProc gfGetDisplay = nullptr; | 69 static GetDisplayProc gfGetDisplay = nullptr; |
| 70 static InitializeProc gfInitialize = nullptr; | 70 static InitializeProc gfInitialize = nullptr; |
| 71 static TerminateProc gfTerminate = nullptr; | 71 static ReleaseThreadProc gfReleaseThread = nullptr; |
| 72 static ChooseConfigProc gfChooseConfig = nullptr; | 72 static ChooseConfigProc gfChooseConfig = nullptr; |
| 73 static GetConfigAttrib gfGetConfigAttrib = nullptr; | 73 static GetConfigAttrib gfGetConfigAttrib = nullptr; |
| 74 static CreateWindowSurfaceProc gfCreateWindowSurface = nullptr; | 74 static CreateWindowSurfaceProc gfCreateWindowSurface = nullptr; |
| 75 static CreatePbufferSurfaceProc gfCreatePbufferSurface = nullptr; | 75 static CreatePbufferSurfaceProc gfCreatePbufferSurface = nullptr; |
| 76 static DestroySurfaceProc gfDestroySurface = nullptr; | 76 static DestroySurfaceProc gfDestroySurface = nullptr; |
| 77 static CreateContextProc gfCreateContext = nullptr; | 77 static CreateContextProc gfCreateContext = nullptr; |
| 78 static DestroyContextProc gfDestroyContext = nullptr; | 78 static DestroyContextProc gfDestroyContext = nullptr; |
| 79 static MakeCurrentProc gfMakeCurrent = nullptr; | 79 static MakeCurrentProc gfMakeCurrent = nullptr; |
| 80 static SwapBuffersProc gfSwapBuffers = nullptr; | 80 static SwapBuffersProc gfSwapBuffers = nullptr; |
| 81 static GetProcAddressProc gfGetProcAddress = nullptr; | 81 static GetProcAddressProc gfGetProcAddress = nullptr; |
| 82 | 82 |
| 83 static void* gLibrary = nullptr; | 83 static void* gLibrary = nullptr; |
| 84 static bool gfFunctionsLoadedSuccessfully = false; | 84 static bool gfFunctionsLoadedSuccessfully = false; |
| 85 | 85 |
| 86 static void load_command_buffer_functions() { | 86 static void load_command_buffer_functions() { |
| 87 if (!gLibrary) { | 87 if (!gLibrary) { |
| 88 #if defined _WIN32 | 88 #if defined _WIN32 |
| 89 gLibrary = DynamicLoadLibrary("command_buffer_gles2.dll"); | 89 gLibrary = DynamicLoadLibrary("command_buffer_gles2.dll"); |
| 90 #elif defined SK_BUILD_FOR_MAC | 90 #elif defined SK_BUILD_FOR_MAC |
| 91 gLibrary = DynamicLoadLibrary("libcommand_buffer_gles2.dylib"); | 91 gLibrary = DynamicLoadLibrary("libcommand_buffer_gles2.dylib"); |
| 92 #else | 92 #else |
| 93 gLibrary = DynamicLoadLibrary("libcommand_buffer_gles2.so"); | 93 gLibrary = DynamicLoadLibrary("libcommand_buffer_gles2.so"); |
| 94 #endif // defined _WIN32 | 94 #endif // defined _WIN32 |
| 95 if (gLibrary) { | 95 if (gLibrary) { |
| 96 gfGetDisplay = (GetDisplayProc)GetProcedureAddress(gLibrary, "eglGet
Display"); | 96 gfGetDisplay = (GetDisplayProc)GetProcedureAddress(gLibrary, "eglGet
Display"); |
| 97 gfInitialize = (InitializeProc)GetProcedureAddress(gLibrary, "eglIni
tialize"); | 97 gfInitialize = (InitializeProc)GetProcedureAddress(gLibrary, "eglIni
tialize"); |
| 98 gfTerminate = (TerminateProc)GetProcedureAddress(gLibrary, "eglTermi
nate"); | 98 gfReleaseThread = (ReleaseThreadProc)GetProcedureAddress(gLibrary, "
eglReleaseThread"); |
| 99 gfChooseConfig = (ChooseConfigProc)GetProcedureAddress(gLibrary, "eg
lChooseConfig"); | 99 gfChooseConfig = (ChooseConfigProc)GetProcedureAddress(gLibrary, "eg
lChooseConfig"); |
| 100 gfGetConfigAttrib = (GetConfigAttrib)GetProcedureAddress(gLibrary, "
eglGetConfigAttrib"); | 100 gfGetConfigAttrib = (GetConfigAttrib)GetProcedureAddress(gLibrary, "
eglGetConfigAttrib"); |
| 101 gfCreateWindowSurface = (CreateWindowSurfaceProc)GetProcedureAddress
(gLibrary, "eglCreateWindowSurface"); | 101 gfCreateWindowSurface = (CreateWindowSurfaceProc)GetProcedureAddress
(gLibrary, "eglCreateWindowSurface"); |
| 102 gfCreatePbufferSurface = (CreatePbufferSurfaceProc)GetProcedureAddre
ss(gLibrary, "eglCreatePbufferSurface"); | 102 gfCreatePbufferSurface = (CreatePbufferSurfaceProc)GetProcedureAddre
ss(gLibrary, "eglCreatePbufferSurface"); |
| 103 gfDestroySurface = (DestroySurfaceProc)GetProcedureAddress(gLibrary,
"eglDestroySurface"); | 103 gfDestroySurface = (DestroySurfaceProc)GetProcedureAddress(gLibrary,
"eglDestroySurface"); |
| 104 gfCreateContext = (CreateContextProc)GetProcedureAddress(gLibrary, "
eglCreateContext"); | 104 gfCreateContext = (CreateContextProc)GetProcedureAddress(gLibrary, "
eglCreateContext"); |
| 105 gfDestroyContext = (DestroyContextProc)GetProcedureAddress(gLibrary,
"eglDestroyContext"); | 105 gfDestroyContext = (DestroyContextProc)GetProcedureAddress(gLibrary,
"eglDestroyContext"); |
| 106 gfMakeCurrent = (MakeCurrentProc)GetProcedureAddress(gLibrary, "eglM
akeCurrent"); | 106 gfMakeCurrent = (MakeCurrentProc)GetProcedureAddress(gLibrary, "eglM
akeCurrent"); |
| 107 gfSwapBuffers = (SwapBuffersProc)GetProcedureAddress(gLibrary, "eglS
wapBuffers"); | 107 gfSwapBuffers = (SwapBuffersProc)GetProcedureAddress(gLibrary, "eglS
wapBuffers"); |
| 108 gfGetProcAddress = (GetProcAddressProc)GetProcedureAddress(gLibrary,
"eglGetProcAddress"); | 108 gfGetProcAddress = (GetProcAddressProc)GetProcedureAddress(gLibrary,
"eglGetProcAddress"); |
| 109 | 109 |
| 110 gfFunctionsLoadedSuccessfully = gfGetDisplay && gfInitialize && gfTe
rminate && | 110 gfFunctionsLoadedSuccessfully = gfGetDisplay && gfInitialize && gfRe
leaseThread && |
| 111 gfChooseConfig && gfCreateWindowSurf
ace && | 111 gfChooseConfig && gfCreateWindowSurf
ace && |
| 112 gfCreatePbufferSurface && gfDestroyS
urface && | 112 gfCreatePbufferSurface && gfDestroyS
urface && |
| 113 gfCreateContext && gfDestroyContext
&& gfMakeCurrent && | 113 gfCreateContext && gfDestroyContext
&& gfMakeCurrent && |
| 114 gfSwapBuffers && gfGetProcAddress; | 114 gfSwapBuffers && gfGetProcAddress; |
| 115 | 115 |
| 116 } | 116 } |
| 117 } | 117 } |
| 118 } | 118 } |
| 119 | 119 |
| 120 static GrGLFuncPtr command_buffer_get_gl_proc(void* ctx, const char name[]) { | 120 static GrGLFuncPtr command_buffer_get_gl_proc(void* ctx, const char name[]) { |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 if (fContext) { | 277 if (fContext) { |
| 278 gfDestroyContext(fDisplay, fContext); | 278 gfDestroyContext(fDisplay, fContext); |
| 279 fContext = EGL_NO_CONTEXT; | 279 fContext = EGL_NO_CONTEXT; |
| 280 } | 280 } |
| 281 | 281 |
| 282 if (fSurface) { | 282 if (fSurface) { |
| 283 gfDestroySurface(fDisplay, fSurface); | 283 gfDestroySurface(fDisplay, fSurface); |
| 284 fSurface = EGL_NO_SURFACE; | 284 fSurface = EGL_NO_SURFACE; |
| 285 } | 285 } |
| 286 | 286 |
| 287 gfTerminate(fDisplay); | |
| 288 fDisplay = EGL_NO_DISPLAY; | 287 fDisplay = EGL_NO_DISPLAY; |
| 289 } | 288 } |
| 290 } | 289 } |
| 291 | 290 |
| 292 void SkCommandBufferGLContext::onPlatformMakeCurrent() const { | 291 void SkCommandBufferGLContext::onPlatformMakeCurrent() const { |
| 293 if (!gfFunctionsLoadedSuccessfully) { | 292 if (!gfFunctionsLoadedSuccessfully) { |
| 294 return; | 293 return; |
| 295 } | 294 } |
| 296 if (!gfMakeCurrent(fDisplay, fSurface, fSurface, fContext)) { | 295 if (!gfMakeCurrent(fDisplay, fSurface, fSurface, fContext)) { |
| 297 SkDebugf("Command Buffer: Could not make EGL context current.\n"); | 296 SkDebugf("Command Buffer: Could not make EGL context current.\n"); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 EGLint result = 0; | 329 EGLint result = 0; |
| 331 gfGetConfigAttrib(fDisplay, static_cast<EGLConfig>(fConfig), EGL_STENCIL_SIZ
E, &result); | 330 gfGetConfigAttrib(fDisplay, static_cast<EGLConfig>(fConfig), EGL_STENCIL_SIZ
E, &result); |
| 332 return result; | 331 return result; |
| 333 } | 332 } |
| 334 | 333 |
| 335 int SkCommandBufferGLContext::getSampleCount() { | 334 int SkCommandBufferGLContext::getSampleCount() { |
| 336 EGLint result = 0; | 335 EGLint result = 0; |
| 337 gfGetConfigAttrib(fDisplay, static_cast<EGLConfig>(fConfig), EGL_SAMPLES, &r
esult); | 336 gfGetConfigAttrib(fDisplay, static_cast<EGLConfig>(fConfig), EGL_SAMPLES, &r
esult); |
| 338 return result; | 337 return result; |
| 339 } | 338 } |
| 339 |
| 340 void SkCommandBufferGLContext::ReleaseGpuAPIsInThread() { |
| 341 if (!gfFunctionsLoadedSuccessfully) { |
| 342 return; |
| 343 } |
| 344 gfReleaseThread(); |
| 345 } |
| OLD | NEW |