cc: Add more eviction categories to picture layer impl.
[chromium-blink-merge.git] / ui / gl / gl_fence_egl.cc
blob71d3103311b794d7c95fae977e1780e541184bfe
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"
10 namespace gfx {
12 GLFenceEGL::GLFenceEGL(bool flush) {
13 display_ = eglGetCurrentDisplay();
14 sync_ = eglCreateSyncKHR(display_, EGL_SYNC_FENCE_KHR, NULL);
15 DCHECK(sync_ != EGL_NO_SYNC_KHR);
16 if (flush) {
17 glFlush();
18 } else {
19 flush_event_ = GLContext::GetCurrent()->SignalFlush();
23 bool GLFenceEGL::HasCompleted() {
24 EGLint value = 0;
25 eglGetSyncAttribKHR(display_, sync_, EGL_SYNC_STATUS_KHR, &value);
26 DCHECK(value == EGL_SIGNALED_KHR || value == EGL_UNSIGNALED_KHR);
27 return !value || value == EGL_SIGNALED_KHR;
30 void GLFenceEGL::ClientWait() {
31 if (!flush_event_ || flush_event_->IsSignaled()) {
32 EGLint flags = 0;
33 EGLTimeKHR time = EGL_FOREVER_KHR;
34 eglClientWaitSyncKHR(display_, sync_, flags, time);
35 } else {
36 LOG(ERROR) << "Trying to wait for uncommitted fence. Skipping...";
40 void GLFenceEGL::ServerWait() {
41 if (!flush_event_ || flush_event_->IsSignaled()) {
42 EGLint flags = 0;
43 eglWaitSyncKHR(display_, sync_, flags);
44 } else {
45 LOG(ERROR) << "Trying to wait for uncommitted fence. Skipping...";
49 GLFenceEGL::~GLFenceEGL() {
50 eglDestroySyncKHR(display_, sync_);
53 } // namespace gfx