cc: Remove noisy UpdateTiles traces.
[chromium-blink-merge.git] / ui / gl / gl_fence_egl.cc
blobc96d6d8157dea1b5c9c5f1915e6149d5379ca316
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"
11 namespace gfx {
13 GLFenceEGL::GLFenceEGL(bool flush) {
14 display_ = eglGetCurrentDisplay();
15 sync_ = eglCreateSyncKHR(display_, EGL_SYNC_FENCE_KHR, NULL);
16 DCHECK(sync_ != EGL_NO_SYNC_KHR);
17 if (flush) {
18 glFlush();
19 } else {
20 flush_event_ = GLContext::GetCurrent()->SignalFlush();
24 bool GLFenceEGL::HasCompleted() {
25 EGLint value = 0;
26 if (eglGetSyncAttribKHR(display_, sync_, EGL_SYNC_STATUS_KHR, &value) !=
27 EGL_TRUE) {
28 LOG(ERROR) << "Failed to get EGLSync attribute. error code:"
29 << eglGetError();
30 return true;
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()) {
39 EGLint flags = 0;
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();
47 } else {
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) {
54 ClientWait();
55 return;
57 if (!flush_event_.get() || flush_event_->IsSignaled()) {
58 EGLint flags = 0;
59 if (eglWaitSyncKHR(display_, sync_, flags) == EGL_FALSE) {
60 LOG(FATAL) << "Failed to wait for EGLSync. error:"
61 << ui::GetLastEGLErrorString();
63 } else {
64 LOG(ERROR) << "Trying to wait for uncommitted fence. Skipping...";
68 GLFenceEGL::~GLFenceEGL() {
69 eglDestroySyncKHR(display_, sync_);
72 } // namespace gfx