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/gl_bindings.h"
8 #include "ui/gl/gl_context.h"
12 GLFenceEGL::GLFenceEGL(bool flush) {
13 display_ = eglGetCurrentDisplay();
14 sync_ = eglCreateSyncKHR(display_, EGL_SYNC_FENCE_KHR, NULL);
15 DCHECK(sync_ != EGL_NO_SYNC_KHR);
19 flush_event_ = GLContext::GetCurrent()->SignalFlush();
23 bool GLFenceEGL::HasCompleted() {
25 if (eglGetSyncAttribKHR(display_, sync_, EGL_SYNC_STATUS_KHR, &value) !=
30 DCHECK(value == EGL_SIGNALED_KHR || value == EGL_UNSIGNALED_KHR);
31 return !value || value == EGL_SIGNALED_KHR;
34 void GLFenceEGL::ClientWait() {
35 if (!flush_event_.get() || flush_event_->IsSignaled()) {
37 EGLTimeKHR time = EGL_FOREVER_KHR;
38 eglClientWaitSyncKHR(display_, sync_, flags, time);
40 LOG(ERROR) << "Trying to wait for uncommitted fence. Skipping...";
44 void GLFenceEGL::ServerWait() {
45 if (!flush_event_.get() || flush_event_->IsSignaled()) {
47 eglWaitSyncKHR(display_, sync_, flags);
49 LOG(ERROR) << "Trying to wait for uncommitted fence. Skipping...";
53 GLFenceEGL::~GLFenceEGL() {
54 eglDestroySyncKHR(display_, sync_);