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"
9 #include "ui/gl/gl_context.h"
13 GLFenceEGL::GLFenceEGL(bool flush
) {
14 display_
= eglGetCurrentDisplay();
15 sync_
= eglCreateSyncKHR(display_
, EGL_SYNC_FENCE_KHR
, NULL
);
16 DCHECK(sync_
!= EGL_NO_SYNC_KHR
);
20 flush_event_
= GLContext::GetCurrent()->SignalFlush();
24 bool GLFenceEGL::HasCompleted() {
26 if (eglGetSyncAttribKHR(display_
, sync_
, EGL_SYNC_STATUS_KHR
, &value
) !=
28 LOG(ERROR
) << "Failed to get EGLSync attribute. error code:"
33 DCHECK(value
== EGL_SIGNALED_KHR
|| value
== EGL_UNSIGNALED_KHR
);
34 return !value
|| value
== EGL_SIGNALED_KHR
;
37 void GLFenceEGL::ClientWait() {
38 if (!flush_event_
.get() || flush_event_
->IsSignaled()) {
40 EGLTimeKHR time
= EGL_FOREVER_KHR
;
41 EGLint result
= eglClientWaitSyncKHR(display_
, sync_
, flags
, time
);
42 DCHECK_NE(EGL_TIMEOUT_EXPIRED_KHR
, result
);
43 if (result
== EGL_FALSE
) {
44 LOG(FATAL
) << "Failed to wait for EGLSync. error:"
45 << ui::GetLastEGLErrorString();
48 LOG(ERROR
) << "Trying to wait for uncommitted fence. Skipping...";
52 void GLFenceEGL::ServerWait() {
53 if (!gfx::g_driver_egl
.ext
.b_EGL_KHR_wait_sync
) {
57 if (!flush_event_
.get() || flush_event_
->IsSignaled()) {
59 if (eglWaitSyncKHR(display_
, sync_
, flags
) == EGL_FALSE
) {
60 LOG(FATAL
) << "Failed to wait for EGLSync. error:"
61 << ui::GetLastEGLErrorString();
64 LOG(ERROR
) << "Trying to wait for uncommitted fence. Skipping...";
68 GLFenceEGL::~GLFenceEGL() {
69 eglDestroySyncKHR(display_
, sync_
);