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> |
11 | 11 |
12 #define EGL_EGLEXT_PROTOTYPES | 12 #define EGL_EGLEXT_PROTOTYPES |
13 #include <EGL/egl.h> | 13 #include <EGL/egl.h> |
14 #include <EGL/eglext.h> | 14 #include <EGL/eglext.h> |
15 | 15 |
16 #include "gl/GrGLDefines.h" | 16 #include "gl/GrGLDefines.h" |
17 #include "gl/GrGLUtil.h" | 17 #include "gl/GrGLUtil.h" |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 // TODO: Share this class with ANGLE if/when it gets support for EGL_KHR_fence_s
ync. | 21 // TODO: Share this class with ANGLE if/when it gets support for EGL_KHR_fence_s
ync. |
22 class SkEGLFenceSync : public SkGpuFenceSync { | 22 class SkEGLFenceSync : public SkGpuFenceSync { |
23 public: | 23 public: |
24 static SkEGLFenceSync* CreateIfSupported(EGLDisplay); | 24 static SkEGLFenceSync* CreateIfSupported(EGLDisplay); |
25 | 25 |
26 SkPlatformGpuFence SK_WARN_UNUSED_RESULT insertFence() const override; | 26 SkPlatformGpuFence SK_WARN_UNUSED_RESULT insertFence() const override; |
27 bool flushAndWaitFence(SkPlatformGpuFence fence) const override; | 27 bool waitFence(SkPlatformGpuFence fence, bool flush) const override; |
28 void deleteFence(SkPlatformGpuFence fence) const override; | 28 void deleteFence(SkPlatformGpuFence fence) const override; |
29 | 29 |
30 private: | 30 private: |
31 SkEGLFenceSync(EGLDisplay display) : fDisplay(display) {} | 31 SkEGLFenceSync(EGLDisplay display) : fDisplay(display) {} |
32 | 32 |
33 EGLDisplay fDisplay; | 33 EGLDisplay fDisplay; |
34 | 34 |
35 typedef SkGpuFenceSync INHERITED; | 35 typedef SkGpuFenceSync INHERITED; |
36 }; | 36 }; |
37 | 37 |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 if (!display || !supports_egl_extension(display, "EGL_KHR_fence_sync")) { | 295 if (!display || !supports_egl_extension(display, "EGL_KHR_fence_sync")) { |
296 return nullptr; | 296 return nullptr; |
297 } | 297 } |
298 return new SkEGLFenceSync(display); | 298 return new SkEGLFenceSync(display); |
299 } | 299 } |
300 | 300 |
301 SkPlatformGpuFence SkEGLFenceSync::insertFence() const { | 301 SkPlatformGpuFence SkEGLFenceSync::insertFence() const { |
302 return eglCreateSyncKHR(fDisplay, EGL_SYNC_FENCE_KHR, nullptr); | 302 return eglCreateSyncKHR(fDisplay, EGL_SYNC_FENCE_KHR, nullptr); |
303 } | 303 } |
304 | 304 |
305 bool SkEGLFenceSync::flushAndWaitFence(SkPlatformGpuFence platformFence) const { | 305 bool SkEGLFenceSync::waitFence(SkPlatformGpuFence platformFence, bool flush) con
st { |
306 EGLSyncKHR eglsync = static_cast<EGLSyncKHR>(platformFence); | 306 EGLSyncKHR eglsync = static_cast<EGLSyncKHR>(platformFence); |
307 return EGL_CONDITION_SATISFIED_KHR == eglClientWaitSyncKHR(fDisplay, | 307 return EGL_CONDITION_SATISFIED_KHR == |
308 eglsync, | 308 eglClientWaitSyncKHR(fDisplay, |
309 EGL_SYNC_FLUSH_CO
MMANDS_BIT_KHR, | 309 eglsync, |
310 EGL_FOREVER_KHR); | 310 flush ? EGL_SYNC_FLUSH_COMMANDS_BIT_KHR : 0, |
| 311 EGL_FOREVER_KHR); |
311 } | 312 } |
312 | 313 |
313 void SkEGLFenceSync::deleteFence(SkPlatformGpuFence platformFence) const { | 314 void SkEGLFenceSync::deleteFence(SkPlatformGpuFence platformFence) const { |
314 EGLSyncKHR eglsync = static_cast<EGLSyncKHR>(platformFence); | 315 EGLSyncKHR eglsync = static_cast<EGLSyncKHR>(platformFence); |
315 eglDestroySyncKHR(fDisplay, eglsync); | 316 eglDestroySyncKHR(fDisplay, eglsync); |
316 } | 317 } |
317 | 318 |
318 } // anonymous namespace | 319 } // anonymous namespace |
319 | 320 |
320 SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI, SkGLContext* s
hareContext) { | 321 SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI, SkGLContext* s
hareContext) { |
321 SkASSERT(!shareContext); | 322 SkASSERT(!shareContext); |
322 if (shareContext) { | 323 if (shareContext) { |
323 return nullptr; | 324 return nullptr; |
324 } | 325 } |
325 EGLGLContext* ctx = new EGLGLContext(forcedGpuAPI); | 326 EGLGLContext* ctx = new EGLGLContext(forcedGpuAPI); |
326 if (!ctx->isValid()) { | 327 if (!ctx->isValid()) { |
327 delete ctx; | 328 delete ctx; |
328 return nullptr; | 329 return nullptr; |
329 } | 330 } |
330 return ctx; | 331 return ctx; |
331 } | 332 } |
332 | 333 |
OLD | NEW |