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