| 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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 configAttribs[12] = EGL_NONE; | 178 configAttribs[12] = EGL_NONE; |
| 179 } | 179 } |
| 180 | 180 |
| 181 initializeGLContext(nativeWindow, configAttribs, surfaceAttribs); | 181 initializeGLContext(nativeWindow, configAttribs, surfaceAttribs); |
| 182 } | 182 } |
| 183 | 183 |
| 184 void SkCommandBufferGLContext::initializeGLContext(void* nativeWindow, const int
* configAttribs, | 184 void SkCommandBufferGLContext::initializeGLContext(void* nativeWindow, const int
* configAttribs, |
| 185 const int* surfaceAttribs) { | 185 const int* surfaceAttribs) { |
| 186 LoadCommandBufferOnce(); | 186 LoadCommandBufferOnce(); |
| 187 if (!gfFunctionsLoadedSuccessfully) { | 187 if (!gfFunctionsLoadedSuccessfully) { |
| 188 SkDebugf("Command Buffer: Could not load EGL functions.\n"); |
| 188 return; | 189 return; |
| 189 } | 190 } |
| 190 | 191 |
| 191 fDisplay = gfGetDisplay(static_cast<EGLNativeDisplayType>(EGL_DEFAULT_DISPLA
Y)); | 192 fDisplay = gfGetDisplay(EGL_DEFAULT_DISPLAY); |
| 192 if (EGL_NO_DISPLAY == fDisplay) { | 193 if (EGL_NO_DISPLAY == fDisplay) { |
| 193 SkDebugf("Could not create EGL display!"); | 194 SkDebugf("Command Buffer: Could not create EGL display.\n"); |
| 194 return; | 195 return; |
| 195 } | 196 } |
| 196 | 197 |
| 197 EGLint majorVersion; | 198 EGLint majorVersion; |
| 198 EGLint minorVersion; | 199 EGLint minorVersion; |
| 199 gfInitialize(fDisplay, &majorVersion, &minorVersion); | 200 if (!gfInitialize(fDisplay, &majorVersion, &minorVersion)) { |
| 201 SkDebugf("Command Buffer: Could not initialize EGL display.\n"); |
| 202 this->destroyGLContext(); |
| 203 return; |
| 204 } |
| 200 | 205 |
| 201 EGLConfig surfaceConfig = static_cast<EGLConfig>(fConfig); | |
| 202 EGLint numConfigs; | 206 EGLint numConfigs; |
| 203 gfChooseConfig(fDisplay, configAttribs, &surfaceConfig, 1, &numConfigs); | 207 if (!gfChooseConfig(fDisplay, configAttribs, static_cast<EGLConfig*>(&fConfi
g), 1, |
| 208 &numConfigs) || numConfigs != 1) { |
| 209 SkDebugf("Command Buffer: Could not choose EGL config.\n"); |
| 210 this->destroyGLContext(); |
| 211 return; |
| 212 } |
| 204 | 213 |
| 205 if (nativeWindow) { | 214 if (nativeWindow) { |
| 206 fSurface = gfCreateWindowSurface(fDisplay, surfaceConfig, | 215 fSurface = gfCreateWindowSurface(fDisplay, |
| 207 (EGLNativeWindowType)nativeWindow, surf
aceAttribs); | 216 static_cast<EGLConfig>(fConfig), |
| 217 (EGLNativeWindowType)nativeWindow, |
| 218 surfaceAttribs); |
| 208 } else { | 219 } else { |
| 209 fSurface = gfCreatePbufferSurface(fDisplay, surfaceConfig, surfaceAttrib
s); | 220 fSurface = gfCreatePbufferSurface(fDisplay, |
| 221 static_cast<EGLConfig>(fConfig), |
| 222 surfaceAttribs); |
| 223 } |
| 224 if (EGL_NO_SURFACE == fSurface) { |
| 225 SkDebugf("Command Buffer: Could not create EGL surface.\n"); |
| 226 this->destroyGLContext(); |
| 227 return; |
| 210 } | 228 } |
| 211 | 229 |
| 212 static const EGLint contextAttribs[] = { | 230 static const EGLint contextAttribs[] = { |
| 213 EGL_CONTEXT_CLIENT_VERSION, 2, | 231 EGL_CONTEXT_CLIENT_VERSION, 2, |
| 214 EGL_NONE | 232 EGL_NONE |
| 215 }; | 233 }; |
| 216 fContext = gfCreateContext(fDisplay, surfaceConfig, nullptr, contextAttribs)
; | 234 fContext = gfCreateContext(fDisplay, static_cast<EGLConfig>(fConfig), nullpt
r, contextAttribs); |
| 235 if (EGL_NO_CONTEXT == fContext) { |
| 236 SkDebugf("Command Buffer: Could not create EGL context.\n"); |
| 237 this->destroyGLContext(); |
| 238 return; |
| 239 } |
| 217 | 240 |
| 218 gfMakeCurrent(fDisplay, fSurface, fSurface, fContext); | 241 if (!gfMakeCurrent(fDisplay, fSurface, fSurface, fContext)) { |
| 242 SkDebugf("Command Buffer: Could not make EGL context current.\n"); |
| 243 this->destroyGLContext(); |
| 244 return; |
| 245 } |
| 219 | 246 |
| 220 SkAutoTUnref<const GrGLInterface> gl(GrGLCreateCommandBufferInterface()); | 247 SkAutoTUnref<const GrGLInterface> gl(GrGLCreateCommandBufferInterface()); |
| 221 if (nullptr == gl.get()) { | 248 if (nullptr == gl.get()) { |
| 222 SkDebugf("Could not create CommandBuffer GL interface!\n"); | 249 SkDebugf("Command Buffer: Could not create CommandBuffer GL interface.\n
"); |
| 223 this->destroyGLContext(); | 250 this->destroyGLContext(); |
| 224 return; | 251 return; |
| 225 } | 252 } |
| 226 if (!gl->validate()) { | 253 if (!gl->validate()) { |
| 227 SkDebugf("Could not validate CommandBuffer GL interface!\n"); | 254 SkDebugf("Command Buffer: Could not validate CommandBuffer GL interface.
\n"); |
| 228 this->destroyGLContext(); | 255 this->destroyGLContext(); |
| 229 return; | 256 return; |
| 230 } | 257 } |
| 231 | 258 |
| 232 this->init(gl.detach()); | 259 this->init(gl.detach()); |
| 233 } | 260 } |
| 234 | 261 |
| 235 SkCommandBufferGLContext::~SkCommandBufferGLContext() { | 262 SkCommandBufferGLContext::~SkCommandBufferGLContext() { |
| 236 this->teardown(); | 263 this->teardown(); |
| 237 this->destroyGLContext(); | 264 this->destroyGLContext(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 257 gfTerminate(fDisplay); | 284 gfTerminate(fDisplay); |
| 258 fDisplay = EGL_NO_DISPLAY; | 285 fDisplay = EGL_NO_DISPLAY; |
| 259 } | 286 } |
| 260 } | 287 } |
| 261 | 288 |
| 262 void SkCommandBufferGLContext::onPlatformMakeCurrent() const { | 289 void SkCommandBufferGLContext::onPlatformMakeCurrent() const { |
| 263 if (!gfFunctionsLoadedSuccessfully) { | 290 if (!gfFunctionsLoadedSuccessfully) { |
| 264 return; | 291 return; |
| 265 } | 292 } |
| 266 if (!gfMakeCurrent(fDisplay, fSurface, fSurface, fContext)) { | 293 if (!gfMakeCurrent(fDisplay, fSurface, fSurface, fContext)) { |
| 267 SkDebugf("Could not set the context.\n"); | 294 SkDebugf("Command Buffer: Could not make EGL context current.\n"); |
| 268 } | 295 } |
| 269 } | 296 } |
| 270 | 297 |
| 271 void SkCommandBufferGLContext::onPlatformSwapBuffers() const { | 298 void SkCommandBufferGLContext::onPlatformSwapBuffers() const { |
| 272 if (!gfFunctionsLoadedSuccessfully) { | 299 if (!gfFunctionsLoadedSuccessfully) { |
| 273 return; | 300 return; |
| 274 } | 301 } |
| 275 if (!gfSwapBuffers(fDisplay, fSurface)) { | 302 if (!gfSwapBuffers(fDisplay, fSurface)) { |
| 276 SkDebugf("Could not complete gfSwapBuffers.\n"); | 303 SkDebugf("Command Buffer: Could not complete gfSwapBuffers.\n"); |
| 277 } | 304 } |
| 278 } | 305 } |
| 279 | 306 |
| 280 GrGLFuncPtr SkCommandBufferGLContext::onPlatformGetProcAddress(const char* name)
const { | 307 GrGLFuncPtr SkCommandBufferGLContext::onPlatformGetProcAddress(const char* name)
const { |
| 281 if (!gfFunctionsLoadedSuccessfully) { | 308 if (!gfFunctionsLoadedSuccessfully) { |
| 282 return nullptr; | 309 return nullptr; |
| 283 } | 310 } |
| 284 return gfGetProcAddress(name); | 311 return gfGetProcAddress(name); |
| 285 } | 312 } |
| 286 | 313 |
| 287 void SkCommandBufferGLContext::presentCommandBuffer() { | 314 void SkCommandBufferGLContext::presentCommandBuffer() { |
| 288 if (this->gl()) { | 315 if (this->gl()) { |
| 289 this->gl()->fFunctions.fFlush(); | 316 this->gl()->fFunctions.fFlush(); |
| 290 } | 317 } |
| 291 | 318 |
| 292 this->onPlatformSwapBuffers(); | 319 this->onPlatformSwapBuffers(); |
| 293 } | 320 } |
| 294 | 321 |
| 295 bool SkCommandBufferGLContext::makeCurrent() { | 322 bool SkCommandBufferGLContext::makeCurrent() { |
| 296 return gfMakeCurrent(fDisplay, fSurface, fSurface, fContext) != EGL_FALSE; | 323 return gfMakeCurrent(fDisplay, fSurface, fSurface, fContext) != EGL_FALSE; |
| 297 } | 324 } |
| 298 | 325 |
| 299 int SkCommandBufferGLContext::getStencilBits() { | 326 int SkCommandBufferGLContext::getStencilBits() { |
| 300 EGLint result = 0; | 327 EGLint result = 0; |
| 301 EGLConfig surfaceConfig = static_cast<EGLConfig>(fConfig); | 328 gfGetConfigAttrib(fDisplay, static_cast<EGLConfig>(fConfig), EGL_STENCIL_SIZ
E, &result); |
| 302 gfGetConfigAttrib(fDisplay, surfaceConfig, EGL_STENCIL_SIZE, &result); | |
| 303 return result; | 329 return result; |
| 304 } | 330 } |
| 305 | 331 |
| 306 int SkCommandBufferGLContext::getSampleCount() { | 332 int SkCommandBufferGLContext::getSampleCount() { |
| 307 EGLint result = 0; | 333 EGLint result = 0; |
| 308 EGLConfig surfaceConfig = static_cast<EGLConfig>(fConfig); | 334 gfGetConfigAttrib(fDisplay, static_cast<EGLConfig>(fConfig), EGL_SAMPLES, &r
esult); |
| 309 gfGetConfigAttrib(fDisplay, surfaceConfig, EGL_SAMPLES, &result); | |
| 310 return result; | 335 return result; |
| 311 } | 336 } |
| OLD | NEW |