Chromium Code Reviews| 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/GLTestContext.h" | 8 #include "gl/GLTestContext.h" |
| 9 | 9 |
| 10 #define GL_GLEXT_PROTOTYPES | 10 #define GL_GLEXT_PROTOTYPES |
| 11 #include <GLES2/gl2.h> | 11 #include <GLES2/gl2.h> |
| 12 | 12 |
| 13 #define EGL_EGLEXT_PROTOTYPES | 13 #define EGL_EGLEXT_PROTOTYPES |
| 14 #include <EGL/egl.h> | 14 #include <EGL/egl.h> |
| 15 #include <EGL/eglext.h> | 15 #include <EGL/eglext.h> |
| 16 | 16 |
| 17 #include "gl/GrGLDefines.h" | 17 #include "gl/GrGLDefines.h" |
| 18 #include "gl/GrGLUtil.h" | 18 #include "gl/GrGLUtil.h" |
| 19 | 19 |
| 20 namespace sk_gpu_test { | |
| 21 | |
| 20 namespace { | 22 namespace { |
|
bsalomon
2016/10/03 19:16:20
why nested? AFAIK we only ever use top level anony
| |
| 21 | 23 |
| 22 // TODO: Share this class with ANGLE if/when it gets support for EGL_KHR_fence_s ync. | 24 // TODO: Share this class with ANGLE if/when it gets support for EGL_KHR_fence_s ync. |
| 23 class EGLFenceSync : public SkGpuFenceSync { | 25 class EGLFenceSync : public FenceSync { |
| 24 public: | 26 public: |
| 25 static EGLFenceSync* CreateIfSupported(EGLDisplay); | 27 static EGLFenceSync* CreateIfSupported(EGLDisplay); |
| 26 | 28 |
| 27 SkPlatformGpuFence SK_WARN_UNUSED_RESULT insertFence() const override; | 29 PlatformFence SK_WARN_UNUSED_RESULT insertFence() const override; |
| 28 bool waitFence(SkPlatformGpuFence fence) const override; | 30 bool waitFence(PlatformFence fence) const override; |
| 29 void deleteFence(SkPlatformGpuFence fence) const override; | 31 void deleteFence(PlatformFence fence) const override; |
| 30 | 32 |
| 31 private: | 33 private: |
| 32 EGLFenceSync(EGLDisplay display) : fDisplay(display) {} | 34 EGLFenceSync(EGLDisplay display) : fDisplay(display) {} |
| 33 | 35 |
| 34 EGLDisplay fDisplay; | 36 EGLDisplay fDisplay; |
| 35 | 37 |
| 36 typedef SkGpuFenceSync INHERITED; | 38 typedef FenceSync INHERITED; |
| 37 }; | 39 }; |
| 38 | 40 |
| 41 bool supports_egl_extension(EGLDisplay display, const char* extension) { | |
| 42 size_t extensionLength = strlen(extension); | |
| 43 const char* extensionsStr = eglQueryString(display, EGL_EXTENSIONS); | |
| 44 while (const char* match = strstr(extensionsStr, extension)) { | |
| 45 // Ensure the string we found is its own extension, not a substring of a larger extension | |
| 46 // (e.g. GL_ARB_occlusion_query / GL_ARB_occlusion_query2). | |
| 47 if ((match == extensionsStr || match[-1] == ' ') && | |
| 48 (match[extensionLength] == ' ' || match[extensionLength] == '\0')) { | |
| 49 return true; | |
| 50 } | |
| 51 extensionsStr = match + extensionLength; | |
| 52 } | |
| 53 return false; | |
| 54 } | |
| 55 | |
| 56 EGLFenceSync* EGLFenceSync::CreateIfSupported(EGLDisplay display) { | |
| 57 if (!display || !supports_egl_extension(display, "EGL_KHR_fence_sync")) { | |
| 58 return nullptr; | |
| 59 } | |
| 60 return new EGLFenceSync(display); | |
| 61 } | |
| 62 | |
| 63 PlatformFence EGLFenceSync::insertFence() const { | |
| 64 return reinterpret_cast<PlatformFence>(eglCreateSyncKHR(fDisplay, EGL_SYNC_F ENCE_KHR, nullptr)); | |
| 65 } | |
| 66 | |
| 67 bool EGLFenceSync::waitFence(PlatformFence platformFence) const { | |
| 68 EGLSyncKHR eglsync = reinterpret_cast<EGLSyncKHR>(platformFence); | |
| 69 return EGL_CONDITION_SATISFIED_KHR == | |
| 70 eglClientWaitSyncKHR(fDisplay, | |
| 71 eglsync, | |
| 72 EGL_SYNC_FLUSH_COMMANDS_BIT_KHR, | |
| 73 EGL_FOREVER_KHR); | |
| 74 } | |
| 75 | |
| 76 void EGLFenceSync::deleteFence(PlatformFence platformFence) const { | |
| 77 EGLSyncKHR eglsync = reinterpret_cast<EGLSyncKHR>(platformFence); | |
| 78 eglDestroySyncKHR(fDisplay, eglsync); | |
| 79 } | |
| 80 | |
| 81 } // anonymous namespace | |
| 82 | |
| 39 class EGLGLTestContext : public sk_gpu_test::GLTestContext { | 83 class EGLGLTestContext : public sk_gpu_test::GLTestContext { |
| 40 public: | 84 public: |
| 41 EGLGLTestContext(GrGLStandard forcedGpuAPI); | 85 EGLGLTestContext(GrGLStandard forcedGpuAPI); |
| 42 ~EGLGLTestContext() override; | 86 ~EGLGLTestContext() override; |
| 43 | 87 |
| 44 GrEGLImage texture2DToEGLImage(GrGLuint texID) const override; | 88 GrEGLImage texture2DToEGLImage(GrGLuint texID) const override; |
| 45 void destroyEGLImage(GrEGLImage) const override; | 89 void destroyEGLImage(GrEGLImage) const override; |
| 46 GrGLuint eglImageToExternalTexture(GrEGLImage) const override; | 90 GrGLuint eglImageToExternalTexture(GrEGLImage) const override; |
| 47 sk_gpu_test::GLTestContext* createNew() const override; | 91 sk_gpu_test::GLTestContext* createNew() const override; |
| 48 | 92 |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 272 void EGLGLTestContext::onPlatformSwapBuffers() const { | 316 void EGLGLTestContext::onPlatformSwapBuffers() const { |
| 273 if (!eglSwapBuffers(fDisplay, fSurface)) { | 317 if (!eglSwapBuffers(fDisplay, fSurface)) { |
| 274 SkDebugf("Could not complete eglSwapBuffers.\n"); | 318 SkDebugf("Could not complete eglSwapBuffers.\n"); |
| 275 } | 319 } |
| 276 } | 320 } |
| 277 | 321 |
| 278 GrGLFuncPtr EGLGLTestContext::onPlatformGetProcAddress(const char* procName) con st { | 322 GrGLFuncPtr EGLGLTestContext::onPlatformGetProcAddress(const char* procName) con st { |
| 279 return eglGetProcAddress(procName); | 323 return eglGetProcAddress(procName); |
| 280 } | 324 } |
| 281 | 325 |
| 282 static bool supports_egl_extension(EGLDisplay display, const char* extension) { | |
| 283 size_t extensionLength = strlen(extension); | |
| 284 const char* extensionsStr = eglQueryString(display, EGL_EXTENSIONS); | |
| 285 while (const char* match = strstr(extensionsStr, extension)) { | |
| 286 // Ensure the string we found is its own extension, not a substring of a larger extension | |
| 287 // (e.g. GL_ARB_occlusion_query / GL_ARB_occlusion_query2). | |
| 288 if ((match == extensionsStr || match[-1] == ' ') && | |
| 289 (match[extensionLength] == ' ' || match[extensionLength] == '\0')) { | |
| 290 return true; | |
| 291 } | |
| 292 extensionsStr = match + extensionLength; | |
| 293 } | |
| 294 return false; | |
| 295 } | |
| 296 | |
| 297 EGLFenceSync* EGLFenceSync::CreateIfSupported(EGLDisplay display) { | |
| 298 if (!display || !supports_egl_extension(display, "EGL_KHR_fence_sync")) { | |
| 299 return nullptr; | |
| 300 } | |
| 301 return new EGLFenceSync(display); | |
| 302 } | |
| 303 | |
| 304 SkPlatformGpuFence EGLFenceSync::insertFence() const { | |
| 305 return eglCreateSyncKHR(fDisplay, EGL_SYNC_FENCE_KHR, nullptr); | |
| 306 } | |
| 307 | |
| 308 bool EGLFenceSync::waitFence(SkPlatformGpuFence platformFence) const { | |
| 309 EGLSyncKHR eglsync = static_cast<EGLSyncKHR>(platformFence); | |
| 310 return EGL_CONDITION_SATISFIED_KHR == | |
| 311 eglClientWaitSyncKHR(fDisplay, | |
| 312 eglsync, | |
| 313 EGL_SYNC_FLUSH_COMMANDS_BIT_KHR, | |
| 314 EGL_FOREVER_KHR); | |
| 315 } | |
| 316 | |
| 317 void EGLFenceSync::deleteFence(SkPlatformGpuFence platformFence) const { | |
| 318 EGLSyncKHR eglsync = static_cast<EGLSyncKHR>(platformFence); | |
| 319 eglDestroySyncKHR(fDisplay, eglsync); | |
| 320 } | |
| 321 | |
| 322 } // anonymous namespace | |
| 323 | |
| 324 namespace sk_gpu_test { | |
| 325 GLTestContext *CreatePlatformGLTestContext(GrGLStandard forcedGpuAPI, | 326 GLTestContext *CreatePlatformGLTestContext(GrGLStandard forcedGpuAPI, |
| 326 GLTestContext *shareContext) { | 327 GLTestContext *shareContext) { |
| 327 SkASSERT(!shareContext); | 328 SkASSERT(!shareContext); |
| 328 if (shareContext) { | 329 if (shareContext) { |
| 329 return nullptr; | 330 return nullptr; |
| 330 } | 331 } |
| 331 EGLGLTestContext *ctx = new EGLGLTestContext(forcedGpuAPI); | 332 EGLGLTestContext *ctx = new EGLGLTestContext(forcedGpuAPI); |
| 332 if (!ctx->isValid()) { | 333 if (!ctx->isValid()) { |
| 333 delete ctx; | 334 delete ctx; |
| 334 return nullptr; | 335 return nullptr; |
| 335 } | 336 } |
| 336 return ctx; | 337 return ctx; |
| 337 } | 338 } |
| 338 } // namespace sk_gpu_test | 339 } // namespace sk_gpu_test |
| 339 | 340 |
| OLD | NEW |