OOPIF: Allow navigations on a RFH without a site to stay in same process.
[chromium-blink-merge.git] / ui / gl / gl_fence_arb.cc
blobda13f107880d8ae0c996218af9d75fad46470932
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_arb.h"
7 #include "ui/gl/gl_bindings.h"
8 #include "ui/gl/gl_context.h"
10 namespace gfx {
12 GLFenceARB::GLFenceARB(bool flush) {
13 sync_ = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
14 DCHECK_EQ(GL_TRUE, glIsSync(sync_));
15 if (flush) {
16 glFlush();
17 } else {
18 flush_event_ = GLContext::GetCurrent()->SignalFlush();
22 bool GLFenceARB::HasCompleted() {
23 // Handle the case where FenceSync failed.
24 if (!sync_)
25 return true;
27 DCHECK_EQ(GL_TRUE, glIsSync(sync_));
28 // We could potentially use glGetSynciv here, but it doesn't work
29 // on OSX 10.7 (always says the fence is not signaled yet).
30 // glClientWaitSync works better, so let's use that instead.
31 return glClientWaitSync(sync_, 0, 0) != GL_TIMEOUT_EXPIRED;
34 void GLFenceARB::ClientWait() {
35 DCHECK_EQ(GL_TRUE, glIsSync(sync_));
36 if (!flush_event_.get() || flush_event_->IsSignaled()) {
37 glClientWaitSync(sync_, GL_SYNC_FLUSH_COMMANDS_BIT, GL_TIMEOUT_IGNORED);
38 } else {
39 LOG(ERROR) << "Trying to wait for uncommitted fence. Skipping...";
43 void GLFenceARB::ServerWait() {
44 DCHECK_EQ(GL_TRUE, glIsSync(sync_));
45 if (!flush_event_.get() || flush_event_->IsSignaled()) {
46 glWaitSync(sync_, 0, GL_TIMEOUT_IGNORED);
47 } else {
48 LOG(ERROR) << "Trying to wait for uncommitted fence. Skipping...";
52 GLFenceARB::~GLFenceARB() {
53 DCHECK_EQ(GL_TRUE, glIsSync(sync_));
54 glDeleteSync(sync_);
57 } // namespace gfx