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 <EGL/egl.h> | |
9 | |
10 #include "SkOnce.h" | 8 #include "SkOnce.h" |
11 #include "gl/GrGLInterface.h" | 9 #include "gl/GrGLInterface.h" |
12 #include "gl/GrGLAssembleInterface.h" | 10 #include "gl/GrGLAssembleInterface.h" |
13 #include "gl/command_buffer/SkCommandBufferGLContext.h" | 11 #include "gl/command_buffer/SkCommandBufferGLContext.h" |
14 #include "../ports/SkOSLibrary.h" | 12 #include "../ports/SkOSLibrary.h" |
15 | 13 |
| 14 #if defined SK_BUILD_FOR_MAC |
| 15 |
| 16 // EGL doesn't exist on the mac, so expose what we need to get the command buffe
r's EGL running. |
| 17 typedef void *EGLDisplay; |
| 18 typedef unsigned int EGLBoolean; |
| 19 typedef void *EGLConfig; |
| 20 typedef void *EGLSurface; |
| 21 typedef void *EGLContext; |
| 22 typedef int32_t EGLint; |
| 23 typedef void* EGLNativeDisplayType; |
| 24 typedef void* EGLNativeWindowType; |
| 25 typedef void (*__eglMustCastToProperFunctionPointerType)(void); |
| 26 #define EGL_FALSE 0 |
| 27 #define EGL_OPENGL_ES2_BIT 0x0004 |
| 28 #define EGL_CONTEXT_CLIENT_VERSION 0x3098 |
| 29 #define EGL_NO_SURFACE ((EGLSurface)0) |
| 30 #define EGL_NO_DISPLAY ((EGLDisplay)0) |
| 31 #define EGL_NO_CONTEXT ((EGLContext)0) |
| 32 #define EGL_DEFAULT_DISPLAY ((EGLNativeDisplayType)0) |
| 33 #define EGL_SURFACE_TYPE 0x3033 |
| 34 #define EGL_PBUFFER_BIT 0x0001 |
| 35 #define EGL_RENDERABLE_TYPE 0x3040 |
| 36 #define EGL_RED_SIZE 0x3024 |
| 37 #define EGL_GREEN_SIZE 0x3023 |
| 38 #define EGL_BLUE_SIZE 0x3022 |
| 39 #define EGL_ALPHA_SIZE 0x3021 |
| 40 #define EGL_DEPTH_SIZE 0x3025 |
| 41 #define EGL_STENCIL_SIZE 0x3025 |
| 42 #define EGL_SAMPLES 0x3031 |
| 43 #define EGL_SAMPLE_BUFFERS 0x3032 |
| 44 #define EGL_NONE 0x3038 |
| 45 #define EGL_WIDTH 0x3057 |
| 46 #define EGL_HEIGHT 0x3056 |
| 47 |
| 48 #else |
| 49 |
| 50 #include <EGL/egl.h> |
| 51 |
| 52 #endif |
| 53 |
16 typedef EGLDisplay (*GetDisplayProc)(EGLNativeDisplayType display_id); | 54 typedef EGLDisplay (*GetDisplayProc)(EGLNativeDisplayType display_id); |
17 typedef EGLBoolean (*InitializeProc)(EGLDisplay dpy, EGLint *major, EGLint *mino
r); | 55 typedef EGLBoolean (*InitializeProc)(EGLDisplay dpy, EGLint *major, EGLint *mino
r); |
18 typedef EGLBoolean (*TerminateProc)(EGLDisplay dpy); | 56 typedef EGLBoolean (*TerminateProc)(EGLDisplay dpy); |
19 typedef EGLBoolean (*ChooseConfigProc)(EGLDisplay dpy, const EGLint* attrib_list
, EGLConfig* configs, EGLint config_size, EGLint* num_config); | 57 typedef EGLBoolean (*ChooseConfigProc)(EGLDisplay dpy, const EGLint* attrib_list
, EGLConfig* configs, EGLint config_size, EGLint* num_config); |
20 typedef EGLBoolean (*GetConfigAttrib)(EGLDisplay dpy, EGLConfig config, EGLint a
ttribute, EGLint* value); | 58 typedef EGLBoolean (*GetConfigAttrib)(EGLDisplay dpy, EGLConfig config, EGLint a
ttribute, EGLint* value); |
21 typedef EGLSurface (*CreateWindowSurfaceProc)(EGLDisplay dpy, EGLConfig config,
EGLNativeWindowType win, const EGLint* attrib_list); | 59 typedef EGLSurface (*CreateWindowSurfaceProc)(EGLDisplay dpy, EGLConfig config,
EGLNativeWindowType win, const EGLint* attrib_list); |
22 typedef EGLSurface (*CreatePbufferSurfaceProc)(EGLDisplay dpy, EGLConfig config,
const EGLint* attrib_list); | 60 typedef EGLSurface (*CreatePbufferSurfaceProc)(EGLDisplay dpy, EGLConfig config,
const EGLint* attrib_list); |
23 typedef EGLBoolean (*DestroySurfaceProc)(EGLDisplay dpy, EGLSurface surface); | 61 typedef EGLBoolean (*DestroySurfaceProc)(EGLDisplay dpy, EGLSurface surface); |
24 typedef EGLContext (*CreateContextProc)(EGLDisplay dpy, EGLConfig config, EGLCon
text share_context, const EGLint* attrib_list); | 62 typedef EGLContext (*CreateContextProc)(EGLDisplay dpy, EGLConfig config, EGLCon
text share_context, const EGLint* attrib_list); |
25 typedef EGLBoolean (*DestroyContextProc)(EGLDisplay dpy, EGLContext ctx); | 63 typedef EGLBoolean (*DestroyContextProc)(EGLDisplay dpy, EGLContext ctx); |
(...skipping 15 matching lines...) Expand all Loading... |
41 static SwapBuffersProc gfSwapBuffers = nullptr; | 79 static SwapBuffersProc gfSwapBuffers = nullptr; |
42 static GetProcAddressProc gfGetProcAddress = nullptr; | 80 static GetProcAddressProc gfGetProcAddress = nullptr; |
43 | 81 |
44 static void* gLibrary = nullptr; | 82 static void* gLibrary = nullptr; |
45 static bool gfFunctionsLoadedSuccessfully = false; | 83 static bool gfFunctionsLoadedSuccessfully = false; |
46 | 84 |
47 static void load_command_buffer_functions() { | 85 static void load_command_buffer_functions() { |
48 if (!gLibrary) { | 86 if (!gLibrary) { |
49 #if defined _WIN32 | 87 #if defined _WIN32 |
50 gLibrary = DynamicLoadLibrary("command_buffer_gles2.dll"); | 88 gLibrary = DynamicLoadLibrary("command_buffer_gles2.dll"); |
| 89 #elif defined SK_BUILD_FOR_MAC |
| 90 gLibrary = DynamicLoadLibrary("libcommand_buffer_gles2.dylib"); |
51 #else | 91 #else |
52 gLibrary = DynamicLoadLibrary("libcommand_buffer_gles2.so"); | 92 gLibrary = DynamicLoadLibrary("libcommand_buffer_gles2.so"); |
53 #endif // defined _WIN32 | 93 #endif // defined _WIN32 |
54 if (gLibrary) { | 94 if (gLibrary) { |
55 gfGetDisplay = (GetDisplayProc)GetProcedureAddress(gLibrary, "eglGet
Display"); | 95 gfGetDisplay = (GetDisplayProc)GetProcedureAddress(gLibrary, "eglGet
Display"); |
56 gfInitialize = (InitializeProc)GetProcedureAddress(gLibrary, "eglIni
tialize"); | 96 gfInitialize = (InitializeProc)GetProcedureAddress(gLibrary, "eglIni
tialize"); |
57 gfTerminate = (TerminateProc)GetProcedureAddress(gLibrary, "eglTermi
nate"); | 97 gfTerminate = (TerminateProc)GetProcedureAddress(gLibrary, "eglTermi
nate"); |
58 gfChooseConfig = (ChooseConfigProc)GetProcedureAddress(gLibrary, "eg
lChooseConfig"); | 98 gfChooseConfig = (ChooseConfigProc)GetProcedureAddress(gLibrary, "eg
lChooseConfig"); |
59 gfGetConfigAttrib = (GetConfigAttrib)GetProcedureAddress(gLibrary, "
eglGetConfigAttrib"); | 99 gfGetConfigAttrib = (GetConfigAttrib)GetProcedureAddress(gLibrary, "
eglGetConfigAttrib"); |
60 gfCreateWindowSurface = (CreateWindowSurfaceProc)GetProcedureAddress
(gLibrary, "eglCreateWindowSurface"); | 100 gfCreateWindowSurface = (CreateWindowSurfaceProc)GetProcedureAddress
(gLibrary, "eglCreateWindowSurface"); |
61 gfCreatePbufferSurface = (CreatePbufferSurfaceProc)GetProcedureAddre
ss(gLibrary, "eglCreatePbufferSurface"); | 101 gfCreatePbufferSurface = (CreatePbufferSurfaceProc)GetProcedureAddre
ss(gLibrary, "eglCreatePbufferSurface"); |
62 gfDestroySurface = (DestroySurfaceProc)GetProcedureAddress(gLibrary,
"eglDestroySurface"); | 102 gfDestroySurface = (DestroySurfaceProc)GetProcedureAddress(gLibrary,
"eglDestroySurface"); |
63 gfCreateContext = (CreateContextProc)GetProcedureAddress(gLibrary, "
eglCreateContext"); | 103 gfCreateContext = (CreateContextProc)GetProcedureAddress(gLibrary, "
eglCreateContext"); |
64 gfDestroyContext = (DestroyContextProc)GetProcedureAddress(gLibrary,
"eglDestroyContext"); | 104 gfDestroyContext = (DestroyContextProc)GetProcedureAddress(gLibrary,
"eglDestroyContext"); |
65 gfMakeCurrent = (MakeCurrentProc)GetProcedureAddress(gLibrary, "eglM
akeCurrent"); | 105 gfMakeCurrent = (MakeCurrentProc)GetProcedureAddress(gLibrary, "eglM
akeCurrent"); |
66 gfSwapBuffers = (SwapBuffersProc)GetProcedureAddress(gLibrary, "eglS
wapBuffers"); | 106 gfSwapBuffers = (SwapBuffersProc)GetProcedureAddress(gLibrary, "eglS
wapBuffers"); |
67 gfGetProcAddress = (GetProcAddressProc)GetProcedureAddress(gLibrary,
"eglGetProcAddress"); | 107 gfGetProcAddress = (GetProcAddressProc)GetProcedureAddress(gLibrary,
"eglGetProcAddress"); |
68 | 108 |
69 gfFunctionsLoadedSuccessfully = gfGetDisplay && gfInitialize && gfTe
rminate && | 109 gfFunctionsLoadedSuccessfully = gfGetDisplay && gfInitialize && gfTe
rminate && |
70 gfChooseConfig && gfCreateWindowSurf
ace && | 110 gfChooseConfig && gfCreateWindowSurf
ace && |
71 gfCreatePbufferSurface && gfDestroyS
urface && | 111 gfCreatePbufferSurface && gfDestroyS
urface && |
72 gfCreateContext && gfDestroyContext
&& gfMakeCurrent && | 112 gfCreateContext && gfDestroyContext
&& gfMakeCurrent && |
73 gfSwapBuffers && gfGetProcAddress; | 113 gfSwapBuffers && gfGetProcAddress; |
74 | 114 |
75 } | 115 } |
76 } | 116 } |
77 } | 117 } |
78 | 118 |
79 static GrGLFuncPtr command_buffer_get_gl_proc(void* ctx, const char name[]) { | 119 static GrGLFuncPtr command_buffer_get_gl_proc(void* ctx, const char name[]) { |
80 GrGLFuncPtr proc = (GrGLFuncPtr) GetProcedureAddress(ctx, name); | |
81 if (proc) { | |
82 return proc; | |
83 } | |
84 if (!gfFunctionsLoadedSuccessfully) { | 120 if (!gfFunctionsLoadedSuccessfully) { |
85 return nullptr; | 121 return nullptr; |
86 } | 122 } |
87 return gfGetProcAddress(name); | 123 return gfGetProcAddress(name); |
88 } | 124 } |
89 | 125 |
90 SK_DECLARE_STATIC_ONCE(loadCommandBufferOnce); | 126 SK_DECLARE_STATIC_ONCE(loadCommandBufferOnce); |
91 void LoadCommandBufferOnce() { | 127 void LoadCommandBufferOnce() { |
92 SkOnce(&loadCommandBufferOnce, load_command_buffer_functions); | 128 SkOnce(&loadCommandBufferOnce, load_command_buffer_functions); |
93 } | 129 } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 | 196 |
161 EGLint majorVersion; | 197 EGLint majorVersion; |
162 EGLint minorVersion; | 198 EGLint minorVersion; |
163 gfInitialize(fDisplay, &majorVersion, &minorVersion); | 199 gfInitialize(fDisplay, &majorVersion, &minorVersion); |
164 | 200 |
165 EGLConfig surfaceConfig = static_cast<EGLConfig>(fConfig); | 201 EGLConfig surfaceConfig = static_cast<EGLConfig>(fConfig); |
166 EGLint numConfigs; | 202 EGLint numConfigs; |
167 gfChooseConfig(fDisplay, configAttribs, &surfaceConfig, 1, &numConfigs); | 203 gfChooseConfig(fDisplay, configAttribs, &surfaceConfig, 1, &numConfigs); |
168 | 204 |
169 if (nativeWindow) { | 205 if (nativeWindow) { |
170 fSurface = gfCreateWindowSurface(fDisplay, surfaceConfig, | 206 fSurface = gfCreateWindowSurface(fDisplay, surfaceConfig, |
171 (EGLNativeWindowType)nativeWindow, surf
aceAttribs); | 207 (EGLNativeWindowType)nativeWindow, surf
aceAttribs); |
172 } else { | 208 } else { |
173 fSurface = gfCreatePbufferSurface(fDisplay, surfaceConfig, surfaceAttrib
s); | 209 fSurface = gfCreatePbufferSurface(fDisplay, surfaceConfig, surfaceAttrib
s); |
174 } | 210 } |
175 | 211 |
176 static const EGLint contextAttribs[] = { | 212 static const EGLint contextAttribs[] = { |
177 EGL_CONTEXT_CLIENT_VERSION, 2, | 213 EGL_CONTEXT_CLIENT_VERSION, 2, |
178 EGL_NONE | 214 EGL_NONE |
179 }; | 215 }; |
180 fContext = gfCreateContext(fDisplay, surfaceConfig, nullptr, contextAttribs)
; | 216 fContext = gfCreateContext(fDisplay, surfaceConfig, nullptr, contextAttribs)
; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 gfGetConfigAttrib(fDisplay, surfaceConfig, EGL_STENCIL_SIZE, &result); | 302 gfGetConfigAttrib(fDisplay, surfaceConfig, EGL_STENCIL_SIZE, &result); |
267 return result; | 303 return result; |
268 } | 304 } |
269 | 305 |
270 int SkCommandBufferGLContext::getSampleCount() { | 306 int SkCommandBufferGLContext::getSampleCount() { |
271 EGLint result = 0; | 307 EGLint result = 0; |
272 EGLConfig surfaceConfig = static_cast<EGLConfig>(fConfig); | 308 EGLConfig surfaceConfig = static_cast<EGLConfig>(fConfig); |
273 gfGetConfigAttrib(fDisplay, surfaceConfig, EGL_SAMPLES, &result); | 309 gfGetConfigAttrib(fDisplay, surfaceConfig, EGL_SAMPLES, &result); |
274 return result; | 310 return result; |
275 } | 311 } |
OLD | NEW |