1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/gl/gl_fence_egl.h"
7 #include "ui/gl/egl_util.h"
8 #include "ui/gl/gl_bindings.h"
14 bool g_ignore_egl_sync_failures
= false;
19 void GLFenceEGL::SetIgnoreFailures() {
20 g_ignore_egl_sync_failures
= true;
23 GLFenceEGL::GLFenceEGL() {
24 display_
= eglGetCurrentDisplay();
25 sync_
= eglCreateSyncKHR(display_
, EGL_SYNC_FENCE_KHR
, NULL
);
26 DCHECK(sync_
!= EGL_NO_SYNC_KHR
);
30 bool GLFenceEGL::HasCompleted() {
32 if (eglGetSyncAttribKHR(display_
, sync_
, EGL_SYNC_STATUS_KHR
, &value
) !=
34 LOG(ERROR
) << "Failed to get EGLSync attribute. error code:"
39 DCHECK(value
== EGL_SIGNALED_KHR
|| value
== EGL_UNSIGNALED_KHR
);
40 return !value
|| value
== EGL_SIGNALED_KHR
;
43 void GLFenceEGL::ClientWait() {
45 EGLTimeKHR time
= EGL_FOREVER_KHR
;
46 EGLint result
= eglClientWaitSyncKHR(display_
, sync_
, flags
, time
);
47 DCHECK_IMPLIES(!g_ignore_egl_sync_failures
,
48 EGL_TIMEOUT_EXPIRED_KHR
!= result
);
49 if (result
== EGL_FALSE
) {
50 LOG(ERROR
) << "Failed to wait for EGLSync. error:"
51 << ui::GetLastEGLErrorString();
52 CHECK(g_ignore_egl_sync_failures
);
56 void GLFenceEGL::ServerWait() {
57 if (!gfx::g_driver_egl
.ext
.b_EGL_KHR_wait_sync
) {
62 if (eglWaitSyncKHR(display_
, sync_
, flags
) == EGL_FALSE
) {
63 LOG(ERROR
) << "Failed to wait for EGLSync. error:"
64 << ui::GetLastEGLErrorString();
65 CHECK(g_ignore_egl_sync_failures
);
69 GLFenceEGL::~GLFenceEGL() {
70 eglDestroySyncKHR(display_
, sync_
);