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 |
8 #include "SkOnce.h" | 9 #include "SkOnce.h" |
9 #include "gl/GrGLInterface.h" | 10 #include "gl/GrGLInterface.h" |
10 #include "gl/GrGLAssembleInterface.h" | 11 #include "gl/GrGLAssembleInterface.h" |
11 #include "gl/command_buffer/SkCommandBufferGLContext.h" | 12 #include "gl/command_buffer/GLContext_command_buffer.h" |
12 #include "../ports/SkOSEnvironment.h" | 13 #include "../ports/SkOSEnvironment.h" |
13 #include "../ports/SkOSLibrary.h" | 14 #include "../ports/SkOSLibrary.h" |
14 | 15 |
15 #if defined SK_BUILD_FOR_MAC | 16 #if defined SK_BUILD_FOR_MAC |
16 | 17 |
17 // EGL doesn't exist on the mac, so expose what we need to get the command buffe
r's EGL running. | 18 // EGL doesn't exist on the mac, so expose what we need to get the command buffe
r's EGL running. |
18 typedef void *EGLDisplay; | 19 typedef void *EGLDisplay; |
19 typedef unsigned int EGLBoolean; | 20 typedef unsigned int EGLBoolean; |
20 typedef void *EGLConfig; | 21 typedef void *EGLConfig; |
21 typedef void *EGLSurface; | 22 typedef void *EGLSurface; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 static DestroySurfaceProc gfDestroySurface = nullptr; | 77 static DestroySurfaceProc gfDestroySurface = nullptr; |
77 static CreateContextProc gfCreateContext = nullptr; | 78 static CreateContextProc gfCreateContext = nullptr; |
78 static DestroyContextProc gfDestroyContext = nullptr; | 79 static DestroyContextProc gfDestroyContext = nullptr; |
79 static MakeCurrentProc gfMakeCurrent = nullptr; | 80 static MakeCurrentProc gfMakeCurrent = nullptr; |
80 static SwapBuffersProc gfSwapBuffers = nullptr; | 81 static SwapBuffersProc gfSwapBuffers = nullptr; |
81 static GetProcAddressProc gfGetProcAddress = nullptr; | 82 static GetProcAddressProc gfGetProcAddress = nullptr; |
82 | 83 |
83 static void* gLibrary = nullptr; | 84 static void* gLibrary = nullptr; |
84 static bool gfFunctionsLoadedSuccessfully = false; | 85 static bool gfFunctionsLoadedSuccessfully = false; |
85 | 86 |
| 87 namespace { |
86 static void load_command_buffer_functions() { | 88 static void load_command_buffer_functions() { |
87 if (!gLibrary) { | 89 if (!gLibrary) { |
88 #if defined _WIN32 | 90 #if defined _WIN32 |
89 gLibrary = DynamicLoadLibrary("command_buffer_gles2.dll"); | 91 gLibrary = DynamicLoadLibrary("command_buffer_gles2.dll"); |
90 #elif defined SK_BUILD_FOR_MAC | 92 #elif defined SK_BUILD_FOR_MAC |
91 gLibrary = DynamicLoadLibrary("libcommand_buffer_gles2.dylib"); | 93 gLibrary = DynamicLoadLibrary("libcommand_buffer_gles2.dylib"); |
92 #else | 94 #else |
93 gLibrary = DynamicLoadLibrary("libcommand_buffer_gles2.so"); | 95 gLibrary = DynamicLoadLibrary("libcommand_buffer_gles2.so"); |
94 #endif // defined _WIN32 | 96 #endif // defined _WIN32 |
95 if (gLibrary) { | 97 if (gLibrary) { |
(...skipping 22 matching lines...) Expand all Loading... |
118 } | 120 } |
119 | 121 |
120 static GrGLFuncPtr command_buffer_get_gl_proc(void* ctx, const char name[]) { | 122 static GrGLFuncPtr command_buffer_get_gl_proc(void* ctx, const char name[]) { |
121 if (!gfFunctionsLoadedSuccessfully) { | 123 if (!gfFunctionsLoadedSuccessfully) { |
122 return nullptr; | 124 return nullptr; |
123 } | 125 } |
124 return gfGetProcAddress(name); | 126 return gfGetProcAddress(name); |
125 } | 127 } |
126 | 128 |
127 SK_DECLARE_STATIC_ONCE(loadCommandBufferOnce); | 129 SK_DECLARE_STATIC_ONCE(loadCommandBufferOnce); |
128 void LoadCommandBufferOnce() { | 130 static void load_command_buffer_once() { |
129 SkOnce(&loadCommandBufferOnce, load_command_buffer_functions); | 131 SkOnce(&loadCommandBufferOnce, load_command_buffer_functions); |
130 } | 132 } |
131 | 133 |
132 const GrGLInterface* GrGLCreateCommandBufferInterface() { | 134 static const GrGLInterface* create_command_buffer_interface() { |
133 LoadCommandBufferOnce(); | 135 load_command_buffer_once(); |
134 if (!gfFunctionsLoadedSuccessfully) { | 136 if (!gfFunctionsLoadedSuccessfully) { |
135 return nullptr; | 137 return nullptr; |
136 } | 138 } |
137 return GrGLAssembleGLESInterface(gLibrary, command_buffer_get_gl_proc); | 139 return GrGLAssembleGLESInterface(gLibrary, command_buffer_get_gl_proc); |
138 } | 140 } |
139 | 141 |
140 SkCommandBufferGLContext::SkCommandBufferGLContext() | 142 } // anonymous namespace |
141 : fContext(EGL_NO_CONTEXT) | 143 |
142 , fDisplay(EGL_NO_DISPLAY) | 144 namespace sk_gpu_test { |
143 , fSurface(EGL_NO_SURFACE) { | 145 |
| 146 CommandBufferGLContext::CommandBufferGLContext() |
| 147 : fContext(EGL_NO_CONTEXT), fDisplay(EGL_NO_DISPLAY), fSurface(EGL_NO_SURFAC
E) { |
144 | 148 |
145 static const EGLint configAttribs[] = { | 149 static const EGLint configAttribs[] = { |
146 EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, | 150 EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, |
147 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, | 151 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
148 EGL_RED_SIZE, 8, | 152 EGL_RED_SIZE, 8, |
149 EGL_GREEN_SIZE, 8, | 153 EGL_GREEN_SIZE, 8, |
150 EGL_BLUE_SIZE, 8, | 154 EGL_BLUE_SIZE, 8, |
151 EGL_ALPHA_SIZE, 8, | 155 EGL_ALPHA_SIZE, 8, |
152 EGL_NONE | 156 EGL_NONE |
153 }; | 157 }; |
154 | 158 |
155 static const EGLint surfaceAttribs[] = { | 159 static const EGLint surfaceAttribs[] = { |
156 EGL_WIDTH, 1, | 160 EGL_WIDTH, 1, |
157 EGL_HEIGHT, 1, | 161 EGL_HEIGHT, 1, |
158 EGL_NONE | 162 EGL_NONE |
159 }; | 163 }; |
160 | 164 |
161 initializeGLContext(nullptr, configAttribs, surfaceAttribs); | 165 initializeGLContext(nullptr, configAttribs, surfaceAttribs); |
162 } | 166 } |
163 | 167 |
164 SkCommandBufferGLContext::SkCommandBufferGLContext(void* nativeWindow, int msaaS
ampleCount) { | 168 CommandBufferGLContext::CommandBufferGLContext(void *nativeWindow, int msaaSampl
eCount) { |
165 static const EGLint surfaceAttribs[] = { EGL_NONE }; | 169 static const EGLint surfaceAttribs[] = {EGL_NONE}; |
166 | 170 |
167 EGLint configAttribs[] = { | 171 EGLint configAttribs[] = { |
168 EGL_RED_SIZE, 8, | 172 EGL_RED_SIZE, 8, |
169 EGL_GREEN_SIZE, 8, | 173 EGL_GREEN_SIZE, 8, |
170 EGL_BLUE_SIZE, 8, | 174 EGL_BLUE_SIZE, 8, |
171 EGL_ALPHA_SIZE, 8, | 175 EGL_ALPHA_SIZE, 8, |
172 EGL_DEPTH_SIZE, 8, | 176 EGL_DEPTH_SIZE, 8, |
173 EGL_STENCIL_SIZE, 8, | 177 EGL_STENCIL_SIZE, 8, |
174 EGL_SAMPLE_BUFFERS, 1, | 178 EGL_SAMPLE_BUFFERS, 1, |
175 EGL_SAMPLES, msaaSampleCount, | 179 EGL_SAMPLES, msaaSampleCount, |
176 EGL_NONE | 180 EGL_NONE |
177 }; | 181 }; |
178 if (msaaSampleCount == 0) { | 182 if (msaaSampleCount == 0) { |
179 configAttribs[12] = EGL_NONE; | 183 configAttribs[12] = EGL_NONE; |
180 } | 184 } |
181 | 185 |
182 initializeGLContext(nativeWindow, configAttribs, surfaceAttribs); | 186 initializeGLContext(nativeWindow, configAttribs, surfaceAttribs); |
183 } | 187 } |
184 | 188 |
185 void SkCommandBufferGLContext::initializeGLContext(void* nativeWindow, const int
* configAttribs, | 189 void CommandBufferGLContext::initializeGLContext(void *nativeWindow, const int *
configAttribs, |
186 const int* surfaceAttribs) { | 190 const int *surfaceAttribs) { |
187 LoadCommandBufferOnce(); | 191 load_command_buffer_once(); |
188 if (!gfFunctionsLoadedSuccessfully) { | 192 if (!gfFunctionsLoadedSuccessfully) { |
189 SkDebugf("Command Buffer: Could not load EGL functions.\n"); | 193 SkDebugf("Command Buffer: Could not load EGL functions.\n"); |
190 return; | 194 return; |
191 } | 195 } |
192 | 196 |
193 // Make sure CHROMIUM_path_rendering is enabled for NVPR support. | 197 // Make sure CHROMIUM_path_rendering is enabled for NVPR support. |
194 sk_setenv("CHROME_COMMAND_BUFFER_GLES2_ARGS", "--enable-gl-path-rendering"); | 198 sk_setenv("CHROME_COMMAND_BUFFER_GLES2_ARGS", "--enable-gl-path-rendering"); |
195 fDisplay = gfGetDisplay(EGL_DEFAULT_DISPLAY); | 199 fDisplay = gfGetDisplay(EGL_DEFAULT_DISPLAY); |
196 if (EGL_NO_DISPLAY == fDisplay) { | 200 if (EGL_NO_DISPLAY == fDisplay) { |
197 SkDebugf("Command Buffer: Could not create EGL display.\n"); | 201 SkDebugf("Command Buffer: Could not create EGL display.\n"); |
198 return; | 202 return; |
199 } | 203 } |
200 | 204 |
201 EGLint majorVersion; | 205 EGLint majorVersion; |
202 EGLint minorVersion; | 206 EGLint minorVersion; |
203 if (!gfInitialize(fDisplay, &majorVersion, &minorVersion)) { | 207 if (!gfInitialize(fDisplay, &majorVersion, &minorVersion)) { |
204 SkDebugf("Command Buffer: Could not initialize EGL display.\n"); | 208 SkDebugf("Command Buffer: Could not initialize EGL display.\n"); |
205 this->destroyGLContext(); | 209 this->destroyGLContext(); |
206 return; | 210 return; |
207 } | 211 } |
208 | 212 |
209 EGLint numConfigs; | 213 EGLint numConfigs; |
210 if (!gfChooseConfig(fDisplay, configAttribs, static_cast<EGLConfig*>(&fConfi
g), 1, | 214 if (!gfChooseConfig(fDisplay, configAttribs, static_cast<EGLConfig *>(&fConf
ig), 1, |
211 &numConfigs) || numConfigs != 1) { | 215 &numConfigs) || numConfigs != 1) { |
212 SkDebugf("Command Buffer: Could not choose EGL config.\n"); | 216 SkDebugf("Command Buffer: Could not choose EGL config.\n"); |
213 this->destroyGLContext(); | 217 this->destroyGLContext(); |
214 return; | 218 return; |
215 } | 219 } |
216 | 220 |
217 if (nativeWindow) { | 221 if (nativeWindow) { |
218 fSurface = gfCreateWindowSurface(fDisplay, | 222 fSurface = gfCreateWindowSurface(fDisplay, |
219 static_cast<EGLConfig>(fConfig), | 223 static_cast<EGLConfig>(fConfig), |
220 (EGLNativeWindowType)nativeWindow, | 224 (EGLNativeWindowType) nativeWindow, |
221 surfaceAttribs); | 225 surfaceAttribs); |
222 } else { | 226 } else { |
223 fSurface = gfCreatePbufferSurface(fDisplay, | 227 fSurface = gfCreatePbufferSurface(fDisplay, |
224 static_cast<EGLConfig>(fConfig), | 228 static_cast<EGLConfig>(fConfig), |
225 surfaceAttribs); | 229 surfaceAttribs); |
226 } | 230 } |
227 if (EGL_NO_SURFACE == fSurface) { | 231 if (EGL_NO_SURFACE == fSurface) { |
228 SkDebugf("Command Buffer: Could not create EGL surface.\n"); | 232 SkDebugf("Command Buffer: Could not create EGL surface.\n"); |
229 this->destroyGLContext(); | 233 this->destroyGLContext(); |
230 return; | 234 return; |
231 } | 235 } |
232 | 236 |
233 static const EGLint contextAttribs[] = { | 237 static const EGLint contextAttribs[] = { |
234 EGL_CONTEXT_CLIENT_VERSION, 2, | 238 EGL_CONTEXT_CLIENT_VERSION, 2, |
235 EGL_NONE | 239 EGL_NONE |
236 }; | 240 }; |
237 fContext = gfCreateContext(fDisplay, static_cast<EGLConfig>(fConfig), nullpt
r, contextAttribs); | 241 fContext = gfCreateContext(fDisplay, static_cast<EGLConfig>(fConfig), nullpt
r, contextAttribs); |
238 if (EGL_NO_CONTEXT == fContext) { | 242 if (EGL_NO_CONTEXT == fContext) { |
239 SkDebugf("Command Buffer: Could not create EGL context.\n"); | 243 SkDebugf("Command Buffer: Could not create EGL context.\n"); |
240 this->destroyGLContext(); | 244 this->destroyGLContext(); |
241 return; | 245 return; |
242 } | 246 } |
243 | 247 |
244 if (!gfMakeCurrent(fDisplay, fSurface, fSurface, fContext)) { | 248 if (!gfMakeCurrent(fDisplay, fSurface, fSurface, fContext)) { |
245 SkDebugf("Command Buffer: Could not make EGL context current.\n"); | 249 SkDebugf("Command Buffer: Could not make EGL context current.\n"); |
246 this->destroyGLContext(); | 250 this->destroyGLContext(); |
247 return; | 251 return; |
248 } | 252 } |
249 | 253 |
250 SkAutoTUnref<const GrGLInterface> gl(GrGLCreateCommandBufferInterface()); | 254 SkAutoTUnref<const GrGLInterface> gl(create_command_buffer_interface()); |
251 if (nullptr == gl.get()) { | 255 if (nullptr == gl.get()) { |
252 SkDebugf("Command Buffer: Could not create CommandBuffer GL interface.\n
"); | 256 SkDebugf("Command Buffer: Could not create CommandBuffer GL interface.\n
"); |
253 this->destroyGLContext(); | 257 this->destroyGLContext(); |
254 return; | 258 return; |
255 } | 259 } |
256 if (!gl->validate()) { | 260 if (!gl->validate()) { |
257 SkDebugf("Command Buffer: Could not validate CommandBuffer GL interface.
\n"); | 261 SkDebugf("Command Buffer: Could not validate CommandBuffer GL interface.
\n"); |
258 this->destroyGLContext(); | 262 this->destroyGLContext(); |
259 return; | 263 return; |
260 } | 264 } |
261 | 265 |
262 this->init(gl.release()); | 266 this->init(gl.release()); |
263 } | 267 } |
264 | 268 |
265 SkCommandBufferGLContext::~SkCommandBufferGLContext() { | 269 CommandBufferGLContext::~CommandBufferGLContext() { |
266 this->teardown(); | 270 this->teardown(); |
267 this->destroyGLContext(); | 271 this->destroyGLContext(); |
268 } | 272 } |
269 | 273 |
270 void SkCommandBufferGLContext::destroyGLContext() { | 274 void CommandBufferGLContext::destroyGLContext() { |
271 if (!gfFunctionsLoadedSuccessfully) { | 275 if (!gfFunctionsLoadedSuccessfully) { |
272 return; | 276 return; |
273 } | 277 } |
274 if (fDisplay) { | 278 if (fDisplay) { |
275 gfMakeCurrent(fDisplay, 0, 0, 0); | 279 gfMakeCurrent(fDisplay, 0, 0, 0); |
276 | 280 |
277 if (fContext) { | 281 if (fContext) { |
278 gfDestroyContext(fDisplay, fContext); | 282 gfDestroyContext(fDisplay, fContext); |
279 fContext = EGL_NO_CONTEXT; | 283 fContext = EGL_NO_CONTEXT; |
280 } | 284 } |
281 | 285 |
282 if (fSurface) { | 286 if (fSurface) { |
283 gfDestroySurface(fDisplay, fSurface); | 287 gfDestroySurface(fDisplay, fSurface); |
284 fSurface = EGL_NO_SURFACE; | 288 fSurface = EGL_NO_SURFACE; |
285 } | 289 } |
286 | 290 |
287 gfTerminate(fDisplay); | 291 gfTerminate(fDisplay); |
288 fDisplay = EGL_NO_DISPLAY; | 292 fDisplay = EGL_NO_DISPLAY; |
289 } | 293 } |
290 } | 294 } |
291 | 295 |
292 void SkCommandBufferGLContext::onPlatformMakeCurrent() const { | 296 void CommandBufferGLContext::onPlatformMakeCurrent() const { |
293 if (!gfFunctionsLoadedSuccessfully) { | 297 if (!gfFunctionsLoadedSuccessfully) { |
294 return; | 298 return; |
295 } | 299 } |
296 if (!gfMakeCurrent(fDisplay, fSurface, fSurface, fContext)) { | 300 if (!gfMakeCurrent(fDisplay, fSurface, fSurface, fContext)) { |
297 SkDebugf("Command Buffer: Could not make EGL context current.\n"); | 301 SkDebugf("Command Buffer: Could not make EGL context current.\n"); |
298 } | 302 } |
299 } | 303 } |
300 | 304 |
301 void SkCommandBufferGLContext::onPlatformSwapBuffers() const { | 305 void CommandBufferGLContext::onPlatformSwapBuffers() const { |
302 if (!gfFunctionsLoadedSuccessfully) { | 306 if (!gfFunctionsLoadedSuccessfully) { |
303 return; | 307 return; |
304 } | 308 } |
305 if (!gfSwapBuffers(fDisplay, fSurface)) { | 309 if (!gfSwapBuffers(fDisplay, fSurface)) { |
306 SkDebugf("Command Buffer: Could not complete gfSwapBuffers.\n"); | 310 SkDebugf("Command Buffer: Could not complete gfSwapBuffers.\n"); |
307 } | 311 } |
308 } | 312 } |
309 | 313 |
310 GrGLFuncPtr SkCommandBufferGLContext::onPlatformGetProcAddress(const char* name)
const { | 314 GrGLFuncPtr CommandBufferGLContext::onPlatformGetProcAddress(const char *name) c
onst { |
311 if (!gfFunctionsLoadedSuccessfully) { | 315 if (!gfFunctionsLoadedSuccessfully) { |
312 return nullptr; | 316 return nullptr; |
313 } | 317 } |
314 return gfGetProcAddress(name); | 318 return gfGetProcAddress(name); |
315 } | 319 } |
316 | 320 |
317 void SkCommandBufferGLContext::presentCommandBuffer() { | 321 void CommandBufferGLContext::presentCommandBuffer() { |
318 if (this->gl()) { | 322 if (this->gl()) { |
319 this->gl()->fFunctions.fFlush(); | 323 this->gl()->fFunctions.fFlush(); |
320 } | 324 } |
321 | 325 |
322 this->onPlatformSwapBuffers(); | 326 this->onPlatformSwapBuffers(); |
323 } | 327 } |
324 | 328 |
325 bool SkCommandBufferGLContext::makeCurrent() { | 329 bool CommandBufferGLContext::makeCurrent() { |
326 return gfMakeCurrent(fDisplay, fSurface, fSurface, fContext) != EGL_FALSE; | 330 return gfMakeCurrent(fDisplay, fSurface, fSurface, fContext) != EGL_FALSE; |
327 } | 331 } |
328 | 332 |
329 int SkCommandBufferGLContext::getStencilBits() { | 333 int CommandBufferGLContext::getStencilBits() { |
330 EGLint result = 0; | 334 EGLint result = 0; |
331 gfGetConfigAttrib(fDisplay, static_cast<EGLConfig>(fConfig), EGL_STENCIL_SIZ
E, &result); | 335 gfGetConfigAttrib(fDisplay, static_cast<EGLConfig>(fConfig), EGL_STENCIL_SIZ
E, &result); |
332 return result; | 336 return result; |
333 } | 337 } |
334 | 338 |
335 int SkCommandBufferGLContext::getSampleCount() { | 339 int CommandBufferGLContext::getSampleCount() { |
336 EGLint result = 0; | 340 EGLint result = 0; |
337 gfGetConfigAttrib(fDisplay, static_cast<EGLConfig>(fConfig), EGL_SAMPLES, &r
esult); | 341 gfGetConfigAttrib(fDisplay, static_cast<EGLConfig>(fConfig), EGL_SAMPLES, &r
esult); |
338 return result; | 342 return result; |
339 } | 343 } |
| 344 |
| 345 } // namespace sk_gpu_test |
OLD | NEW |