| 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 |
| 9 #include "SkOnce.h" | 9 #include "SkOnce.h" |
| 10 #include "gl/GrGLInterface.h" | 10 #include "gl/GrGLInterface.h" |
| 11 #include "gl/GrGLAssembleInterface.h" | 11 #include "gl/GrGLAssembleInterface.h" |
| 12 #include "gl/command_buffer/GLContext_command_buffer.h" | 12 #include "gl/command_buffer/GLTestContext_command_buffer.h" |
| 13 #include "../ports/SkOSEnvironment.h" | 13 #include "../ports/SkOSEnvironment.h" |
| 14 #include "../ports/SkOSLibrary.h" | 14 #include "../ports/SkOSLibrary.h" |
| 15 | 15 |
| 16 #if defined SK_BUILD_FOR_MAC | 16 #if defined SK_BUILD_FOR_MAC |
| 17 | 17 |
| 18 // 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. |
| 19 typedef void *EGLDisplay; | 19 typedef void *EGLDisplay; |
| 20 typedef unsigned int EGLBoolean; | 20 typedef unsigned int EGLBoolean; |
| 21 typedef void *EGLConfig; | 21 typedef void *EGLConfig; |
| 22 typedef void *EGLSurface; | 22 typedef void *EGLSurface; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 if (!gfFunctionsLoadedSuccessfully) { | 136 if (!gfFunctionsLoadedSuccessfully) { |
| 137 return nullptr; | 137 return nullptr; |
| 138 } | 138 } |
| 139 return GrGLAssembleGLESInterface(gLibrary, command_buffer_get_gl_proc); | 139 return GrGLAssembleGLESInterface(gLibrary, command_buffer_get_gl_proc); |
| 140 } | 140 } |
| 141 | 141 |
| 142 } // anonymous namespace | 142 } // anonymous namespace |
| 143 | 143 |
| 144 namespace sk_gpu_test { | 144 namespace sk_gpu_test { |
| 145 | 145 |
| 146 CommandBufferGLContext::CommandBufferGLContext() | 146 CommandBufferGLTestContext::CommandBufferGLTestContext() |
| 147 : fContext(EGL_NO_CONTEXT), fDisplay(EGL_NO_DISPLAY), fSurface(EGL_NO_SURFAC
E) { | 147 : fContext(EGL_NO_CONTEXT), fDisplay(EGL_NO_DISPLAY), fSurface(EGL_NO_SURFAC
E) { |
| 148 | 148 |
| 149 static const EGLint configAttribs[] = { | 149 static const EGLint configAttribs[] = { |
| 150 EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, | 150 EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, |
| 151 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, | 151 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
| 152 EGL_RED_SIZE, 8, | 152 EGL_RED_SIZE, 8, |
| 153 EGL_GREEN_SIZE, 8, | 153 EGL_GREEN_SIZE, 8, |
| 154 EGL_BLUE_SIZE, 8, | 154 EGL_BLUE_SIZE, 8, |
| 155 EGL_ALPHA_SIZE, 8, | 155 EGL_ALPHA_SIZE, 8, |
| 156 EGL_NONE | 156 EGL_NONE |
| 157 }; | 157 }; |
| 158 | 158 |
| 159 static const EGLint surfaceAttribs[] = { | 159 static const EGLint surfaceAttribs[] = { |
| 160 EGL_WIDTH, 1, | 160 EGL_WIDTH, 1, |
| 161 EGL_HEIGHT, 1, | 161 EGL_HEIGHT, 1, |
| 162 EGL_NONE | 162 EGL_NONE |
| 163 }; | 163 }; |
| 164 | 164 |
| 165 initializeGLContext(nullptr, configAttribs, surfaceAttribs); | 165 initializeGLContext(nullptr, configAttribs, surfaceAttribs); |
| 166 } | 166 } |
| 167 | 167 |
| 168 CommandBufferGLContext::CommandBufferGLContext(void *nativeWindow, int msaaSampl
eCount) { | 168 CommandBufferGLTestContext::CommandBufferGLTestContext(void *nativeWindow, int m
saaSampleCount) { |
| 169 static const EGLint surfaceAttribs[] = {EGL_NONE}; | 169 static const EGLint surfaceAttribs[] = {EGL_NONE}; |
| 170 | 170 |
| 171 EGLint configAttribs[] = { | 171 EGLint configAttribs[] = { |
| 172 EGL_RED_SIZE, 8, | 172 EGL_RED_SIZE, 8, |
| 173 EGL_GREEN_SIZE, 8, | 173 EGL_GREEN_SIZE, 8, |
| 174 EGL_BLUE_SIZE, 8, | 174 EGL_BLUE_SIZE, 8, |
| 175 EGL_ALPHA_SIZE, 8, | 175 EGL_ALPHA_SIZE, 8, |
| 176 EGL_DEPTH_SIZE, 8, | 176 EGL_DEPTH_SIZE, 8, |
| 177 EGL_STENCIL_SIZE, 8, | 177 EGL_STENCIL_SIZE, 8, |
| 178 EGL_SAMPLE_BUFFERS, 1, | 178 EGL_SAMPLE_BUFFERS, 1, |
| 179 EGL_SAMPLES, msaaSampleCount, | 179 EGL_SAMPLES, msaaSampleCount, |
| 180 EGL_NONE | 180 EGL_NONE |
| 181 }; | 181 }; |
| 182 if (msaaSampleCount == 0) { | 182 if (msaaSampleCount == 0) { |
| 183 configAttribs[12] = EGL_NONE; | 183 configAttribs[12] = EGL_NONE; |
| 184 } | 184 } |
| 185 | 185 |
| 186 initializeGLContext(nativeWindow, configAttribs, surfaceAttribs); | 186 initializeGLContext(nativeWindow, configAttribs, surfaceAttribs); |
| 187 } | 187 } |
| 188 | 188 |
| 189 void CommandBufferGLContext::initializeGLContext(void *nativeWindow, const int *
configAttribs, | 189 void CommandBufferGLTestContext::initializeGLContext(void *nativeWindow, const i
nt *configAttribs, |
| 190 const int *surfaceAttribs) { | 190 const int *surfaceAttribs) { |
| 191 load_command_buffer_once(); | 191 load_command_buffer_once(); |
| 192 if (!gfFunctionsLoadedSuccessfully) { | 192 if (!gfFunctionsLoadedSuccessfully) { |
| 193 SkDebugf("Command Buffer: Could not load EGL functions.\n"); | 193 SkDebugf("Command Buffer: Could not load EGL functions.\n"); |
| 194 return; | 194 return; |
| 195 } | 195 } |
| 196 | 196 |
| 197 // Make sure CHROMIUM_path_rendering is enabled for NVPR support. | 197 // Make sure CHROMIUM_path_rendering is enabled for NVPR support. |
| 198 sk_setenv("CHROME_COMMAND_BUFFER_GLES2_ARGS", "--enable-gl-path-rendering"); | 198 sk_setenv("CHROME_COMMAND_BUFFER_GLES2_ARGS", "--enable-gl-path-rendering"); |
| 199 fDisplay = gfGetDisplay(EGL_DEFAULT_DISPLAY); | 199 fDisplay = gfGetDisplay(EGL_DEFAULT_DISPLAY); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 } | 259 } |
| 260 if (!gl->validate()) { | 260 if (!gl->validate()) { |
| 261 SkDebugf("Command Buffer: Could not validate CommandBuffer GL interface.
\n"); | 261 SkDebugf("Command Buffer: Could not validate CommandBuffer GL interface.
\n"); |
| 262 this->destroyGLContext(); | 262 this->destroyGLContext(); |
| 263 return; | 263 return; |
| 264 } | 264 } |
| 265 | 265 |
| 266 this->init(gl.release()); | 266 this->init(gl.release()); |
| 267 } | 267 } |
| 268 | 268 |
| 269 CommandBufferGLContext::~CommandBufferGLContext() { | 269 CommandBufferGLTestContext::~CommandBufferGLTestContext() { |
| 270 this->teardown(); | 270 this->teardown(); |
| 271 this->destroyGLContext(); | 271 this->destroyGLContext(); |
| 272 } | 272 } |
| 273 | 273 |
| 274 void CommandBufferGLContext::destroyGLContext() { | 274 void CommandBufferGLTestContext::destroyGLContext() { |
| 275 if (!gfFunctionsLoadedSuccessfully) { | 275 if (!gfFunctionsLoadedSuccessfully) { |
| 276 return; | 276 return; |
| 277 } | 277 } |
| 278 if (fDisplay) { | 278 if (fDisplay) { |
| 279 gfMakeCurrent(fDisplay, 0, 0, 0); | 279 gfMakeCurrent(fDisplay, 0, 0, 0); |
| 280 | 280 |
| 281 if (fContext) { | 281 if (fContext) { |
| 282 gfDestroyContext(fDisplay, fContext); | 282 gfDestroyContext(fDisplay, fContext); |
| 283 fContext = EGL_NO_CONTEXT; | 283 fContext = EGL_NO_CONTEXT; |
| 284 } | 284 } |
| 285 | 285 |
| 286 if (fSurface) { | 286 if (fSurface) { |
| 287 gfDestroySurface(fDisplay, fSurface); | 287 gfDestroySurface(fDisplay, fSurface); |
| 288 fSurface = EGL_NO_SURFACE; | 288 fSurface = EGL_NO_SURFACE; |
| 289 } | 289 } |
| 290 | 290 |
| 291 gfTerminate(fDisplay); | 291 gfTerminate(fDisplay); |
| 292 fDisplay = EGL_NO_DISPLAY; | 292 fDisplay = EGL_NO_DISPLAY; |
| 293 } | 293 } |
| 294 } | 294 } |
| 295 | 295 |
| 296 void CommandBufferGLContext::onPlatformMakeCurrent() const { | 296 void CommandBufferGLTestContext::onPlatformMakeCurrent() const { |
| 297 if (!gfFunctionsLoadedSuccessfully) { | 297 if (!gfFunctionsLoadedSuccessfully) { |
| 298 return; | 298 return; |
| 299 } | 299 } |
| 300 if (!gfMakeCurrent(fDisplay, fSurface, fSurface, fContext)) { | 300 if (!gfMakeCurrent(fDisplay, fSurface, fSurface, fContext)) { |
| 301 SkDebugf("Command Buffer: Could not make EGL context current.\n"); | 301 SkDebugf("Command Buffer: Could not make EGL context current.\n"); |
| 302 } | 302 } |
| 303 } | 303 } |
| 304 | 304 |
| 305 void CommandBufferGLContext::onPlatformSwapBuffers() const { | 305 void CommandBufferGLTestContext::onPlatformSwapBuffers() const { |
| 306 if (!gfFunctionsLoadedSuccessfully) { | 306 if (!gfFunctionsLoadedSuccessfully) { |
| 307 return; | 307 return; |
| 308 } | 308 } |
| 309 if (!gfSwapBuffers(fDisplay, fSurface)) { | 309 if (!gfSwapBuffers(fDisplay, fSurface)) { |
| 310 SkDebugf("Command Buffer: Could not complete gfSwapBuffers.\n"); | 310 SkDebugf("Command Buffer: Could not complete gfSwapBuffers.\n"); |
| 311 } | 311 } |
| 312 } | 312 } |
| 313 | 313 |
| 314 GrGLFuncPtr CommandBufferGLContext::onPlatformGetProcAddress(const char *name) c
onst { | 314 GrGLFuncPtr CommandBufferGLTestContext::onPlatformGetProcAddress(const char *nam
e) const { |
| 315 if (!gfFunctionsLoadedSuccessfully) { | 315 if (!gfFunctionsLoadedSuccessfully) { |
| 316 return nullptr; | 316 return nullptr; |
| 317 } | 317 } |
| 318 return gfGetProcAddress(name); | 318 return gfGetProcAddress(name); |
| 319 } | 319 } |
| 320 | 320 |
| 321 void CommandBufferGLContext::presentCommandBuffer() { | 321 void CommandBufferGLTestContext::presentCommandBuffer() { |
| 322 if (this->gl()) { | 322 if (this->gl()) { |
| 323 this->gl()->fFunctions.fFlush(); | 323 this->gl()->fFunctions.fFlush(); |
| 324 } | 324 } |
| 325 | 325 |
| 326 this->onPlatformSwapBuffers(); | 326 this->onPlatformSwapBuffers(); |
| 327 } | 327 } |
| 328 | 328 |
| 329 bool CommandBufferGLContext::makeCurrent() { | 329 bool CommandBufferGLTestContext::makeCurrent() { |
| 330 return gfMakeCurrent(fDisplay, fSurface, fSurface, fContext) != EGL_FALSE; | 330 return gfMakeCurrent(fDisplay, fSurface, fSurface, fContext) != EGL_FALSE; |
| 331 } | 331 } |
| 332 | 332 |
| 333 int CommandBufferGLContext::getStencilBits() { | 333 int CommandBufferGLTestContext::getStencilBits() { |
| 334 EGLint result = 0; | 334 EGLint result = 0; |
| 335 gfGetConfigAttrib(fDisplay, static_cast<EGLConfig>(fConfig), EGL_STENCIL_SIZ
E, &result); | 335 gfGetConfigAttrib(fDisplay, static_cast<EGLConfig>(fConfig), EGL_STENCIL_SIZ
E, &result); |
| 336 return result; | 336 return result; |
| 337 } | 337 } |
| 338 | 338 |
| 339 int CommandBufferGLContext::getSampleCount() { | 339 int CommandBufferGLTestContext::getSampleCount() { |
| 340 EGLint result = 0; | 340 EGLint result = 0; |
| 341 gfGetConfigAttrib(fDisplay, static_cast<EGLConfig>(fConfig), EGL_SAMPLES, &r
esult); | 341 gfGetConfigAttrib(fDisplay, static_cast<EGLConfig>(fConfig), EGL_SAMPLES, &r
esult); |
| 342 return result; | 342 return result; |
| 343 } | 343 } |
| 344 | 344 |
| 345 } // namespace sk_gpu_test | 345 } // namespace sk_gpu_test |
| OLD | NEW |