| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 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 "gl/SkGLContext.h" | 8 #include "gl/SkGLContext.h" |
| 9 | 9 |
| 10 #include <GLES2/gl2.h> | 10 #include <GLES2/gl2.h> |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 size_t api = 0; | 86 size_t api = 0; |
| 87 if (forcedGpuAPI == kGL_GrGLStandard) { | 87 if (forcedGpuAPI == kGL_GrGLStandard) { |
| 88 apiLimit = 1; | 88 apiLimit = 1; |
| 89 } else if (forcedGpuAPI == kGLES_GrGLStandard) { | 89 } else if (forcedGpuAPI == kGLES_GrGLStandard) { |
| 90 api = 1; | 90 api = 1; |
| 91 } | 91 } |
| 92 SkASSERT(forcedGpuAPI == kNone_GrGLStandard || kAPIs[api].fStandard == force
dGpuAPI); | 92 SkASSERT(forcedGpuAPI == kNone_GrGLStandard || kAPIs[api].fStandard == force
dGpuAPI); |
| 93 | 93 |
| 94 SkAutoTUnref<const GrGLInterface> gl; | 94 SkAutoTUnref<const GrGLInterface> gl; |
| 95 | 95 |
| 96 for (; NULL == gl.get() && api < apiLimit; ++api) { | 96 for (; nullptr == gl.get() && api < apiLimit; ++api) { |
| 97 fDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); | 97 fDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
| 98 | 98 |
| 99 EGLint majorVersion; | 99 EGLint majorVersion; |
| 100 EGLint minorVersion; | 100 EGLint minorVersion; |
| 101 eglInitialize(fDisplay, &majorVersion, &minorVersion); | 101 eglInitialize(fDisplay, &majorVersion, &minorVersion); |
| 102 | 102 |
| 103 #if 0 | 103 #if 0 |
| 104 SkDebugf("VENDOR: %s\n", eglQueryString(fDisplay, EGL_VENDOR)); | 104 SkDebugf("VENDOR: %s\n", eglQueryString(fDisplay, EGL_VENDOR)); |
| 105 SkDebugf("APIS: %s\n", eglQueryString(fDisplay, EGL_CLIENT_APIS)); | 105 SkDebugf("APIS: %s\n", eglQueryString(fDisplay, EGL_CLIENT_APIS)); |
| 106 SkDebugf("VERSION: %s\n", eglQueryString(fDisplay, EGL_VERSION)); | 106 SkDebugf("VERSION: %s\n", eglQueryString(fDisplay, EGL_VERSION)); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 126 if (!eglChooseConfig(fDisplay, configAttribs, &surfaceConfig, 1, &numCon
figs)) { | 126 if (!eglChooseConfig(fDisplay, configAttribs, &surfaceConfig, 1, &numCon
figs)) { |
| 127 SkDebugf("eglChooseConfig failed. EGL Error: 0x%08x\n", eglGetError(
)); | 127 SkDebugf("eglChooseConfig failed. EGL Error: 0x%08x\n", eglGetError(
)); |
| 128 continue; | 128 continue; |
| 129 } | 129 } |
| 130 | 130 |
| 131 if (0 == numConfigs) { | 131 if (0 == numConfigs) { |
| 132 SkDebugf("No suitable EGL config found.\n"); | 132 SkDebugf("No suitable EGL config found.\n"); |
| 133 continue; | 133 continue; |
| 134 } | 134 } |
| 135 | 135 |
| 136 fContext = eglCreateContext(fDisplay, surfaceConfig, NULL, kAPIs[api].fC
ontextAttribs); | 136 fContext = eglCreateContext(fDisplay, surfaceConfig, nullptr, kAPIs[api]
.fContextAttribs); |
| 137 if (EGL_NO_CONTEXT == fContext) { | 137 if (EGL_NO_CONTEXT == fContext) { |
| 138 SkDebugf("eglCreateContext failed. EGL Error: 0x%08x\n", eglGetErro
r()); | 138 SkDebugf("eglCreateContext failed. EGL Error: 0x%08x\n", eglGetErro
r()); |
| 139 continue; | 139 continue; |
| 140 } | 140 } |
| 141 | 141 |
| 142 static const EGLint kSurfaceAttribs[] = { | 142 static const EGLint kSurfaceAttribs[] = { |
| 143 EGL_WIDTH, 1, | 143 EGL_WIDTH, 1, |
| 144 EGL_HEIGHT, 1, | 144 EGL_HEIGHT, 1, |
| 145 EGL_NONE | 145 EGL_NONE |
| 146 }; | 146 }; |
| 147 | 147 |
| 148 fSurface = eglCreatePbufferSurface(fDisplay, surfaceConfig, kSurfaceAttr
ibs); | 148 fSurface = eglCreatePbufferSurface(fDisplay, surfaceConfig, kSurfaceAttr
ibs); |
| 149 if (EGL_NO_SURFACE == fSurface) { | 149 if (EGL_NO_SURFACE == fSurface) { |
| 150 SkDebugf("eglCreatePbufferSurface failed. EGL Error: 0x%08x\n", eglG
etError()); | 150 SkDebugf("eglCreatePbufferSurface failed. EGL Error: 0x%08x\n", eglG
etError()); |
| 151 this->destroyGLContext(); | 151 this->destroyGLContext(); |
| 152 continue; | 152 continue; |
| 153 } | 153 } |
| 154 | 154 |
| 155 if (!eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) { | 155 if (!eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) { |
| 156 SkDebugf("eglMakeCurrent failed. EGL Error: 0x%08x\n", eglGetError(
)); | 156 SkDebugf("eglMakeCurrent failed. EGL Error: 0x%08x\n", eglGetError(
)); |
| 157 this->destroyGLContext(); | 157 this->destroyGLContext(); |
| 158 continue; | 158 continue; |
| 159 } | 159 } |
| 160 | 160 |
| 161 gl.reset(GrGLCreateNativeInterface()); | 161 gl.reset(GrGLCreateNativeInterface()); |
| 162 if (NULL == gl.get()) { | 162 if (nullptr == gl.get()) { |
| 163 SkDebugf("Failed to create gl interface.\n"); | 163 SkDebugf("Failed to create gl interface.\n"); |
| 164 this->destroyGLContext(); | 164 this->destroyGLContext(); |
| 165 continue; | 165 continue; |
| 166 } | 166 } |
| 167 | 167 |
| 168 if (!gl->validate()) { | 168 if (!gl->validate()) { |
| 169 SkDebugf("Failed to validate gl interface.\n"); | 169 SkDebugf("Failed to validate gl interface.\n"); |
| 170 this->destroyGLContext(); | 170 this->destroyGLContext(); |
| 171 continue; | 171 continue; |
| 172 } | 172 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 (match[extensionLength] == ' ' || match[extensionLength] == '\0')) { | 227 (match[extensionLength] == ' ' || match[extensionLength] == '\0')) { |
| 228 return true; | 228 return true; |
| 229 } | 229 } |
| 230 extensionsStr = match + extensionLength; | 230 extensionsStr = match + extensionLength; |
| 231 } | 231 } |
| 232 return false; | 232 return false; |
| 233 } | 233 } |
| 234 | 234 |
| 235 SkEGLFenceSync* SkEGLFenceSync::CreateIfSupported(EGLDisplay display) { | 235 SkEGLFenceSync* SkEGLFenceSync::CreateIfSupported(EGLDisplay display) { |
| 236 if (!display || !supports_egl_extension(display, "EGL_KHR_fence_sync")) { | 236 if (!display || !supports_egl_extension(display, "EGL_KHR_fence_sync")) { |
| 237 return NULL; | 237 return nullptr; |
| 238 } | 238 } |
| 239 return new SkEGLFenceSync(display); | 239 return new SkEGLFenceSync(display); |
| 240 } | 240 } |
| 241 | 241 |
| 242 SkPlatformGpuFence SkEGLFenceSync::insertFence() const { | 242 SkPlatformGpuFence SkEGLFenceSync::insertFence() const { |
| 243 return eglCreateSyncKHR(fDisplay, EGL_SYNC_FENCE_KHR, NULL); | 243 return eglCreateSyncKHR(fDisplay, EGL_SYNC_FENCE_KHR, nullptr); |
| 244 } | 244 } |
| 245 | 245 |
| 246 bool SkEGLFenceSync::flushAndWaitFence(SkPlatformGpuFence platformFence) const { | 246 bool SkEGLFenceSync::flushAndWaitFence(SkPlatformGpuFence platformFence) const { |
| 247 EGLSyncKHR eglsync = static_cast<EGLSyncKHR>(platformFence); | 247 EGLSyncKHR eglsync = static_cast<EGLSyncKHR>(platformFence); |
| 248 return EGL_CONDITION_SATISFIED_KHR == eglClientWaitSyncKHR(fDisplay, | 248 return EGL_CONDITION_SATISFIED_KHR == eglClientWaitSyncKHR(fDisplay, |
| 249 eglsync, | 249 eglsync, |
| 250 EGL_SYNC_FLUSH_CO
MMANDS_BIT_KHR, | 250 EGL_SYNC_FLUSH_CO
MMANDS_BIT_KHR, |
| 251 EGL_FOREVER_KHR); | 251 EGL_FOREVER_KHR); |
| 252 } | 252 } |
| 253 | 253 |
| 254 void SkEGLFenceSync::deleteFence(SkPlatformGpuFence platformFence) const { | 254 void SkEGLFenceSync::deleteFence(SkPlatformGpuFence platformFence) const { |
| 255 EGLSyncKHR eglsync = static_cast<EGLSyncKHR>(platformFence); | 255 EGLSyncKHR eglsync = static_cast<EGLSyncKHR>(platformFence); |
| 256 eglDestroySyncKHR(fDisplay, eglsync); | 256 eglDestroySyncKHR(fDisplay, eglsync); |
| 257 } | 257 } |
| 258 | 258 |
| 259 } // anonymous namespace | 259 } // anonymous namespace |
| 260 | 260 |
| 261 SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI) { | 261 SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI) { |
| 262 EGLGLContext* ctx = new EGLGLContext(forcedGpuAPI); | 262 EGLGLContext* ctx = new EGLGLContext(forcedGpuAPI); |
| 263 if (!ctx->isValid()) { | 263 if (!ctx->isValid()) { |
| 264 delete ctx; | 264 delete ctx; |
| 265 return NULL; | 265 return nullptr; |
| 266 } | 266 } |
| 267 return ctx; | 267 return ctx; |
| 268 } | 268 } |
| 269 | 269 |
| OLD | NEW |