Add ICU message format support
[chromium-blink-merge.git] / ui / gl / gl_fence_arb.cc
blob5c6b3371108bc8ba0823d405958ba19ab78b6b4c
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 "base/strings/stringprintf.h"
8 #include "ui/gl/gl_bindings.h"
10 namespace gfx {
12 namespace {
14 std::string GetGLErrors() {
15 // Clears and logs all current gl errors.
16 std::string accumulated_errors;
17 GLenum error;
18 while ((error = glGetError()) != GL_NO_ERROR) {
19 accumulated_errors += base::StringPrintf("0x%x ", error);
21 return accumulated_errors;
24 } // namespace
26 GLFenceARB::GLFenceARB() {
27 sync_ = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
28 DCHECK_EQ(GL_TRUE, glIsSync(sync_));
29 glFlush();
32 bool GLFenceARB::HasCompleted() {
33 // Handle the case where FenceSync failed.
34 if (!sync_)
35 return true;
37 DCHECK_EQ(GL_TRUE, glIsSync(sync_));
38 // We could potentially use glGetSynciv here, but it doesn't work
39 // on OSX 10.7 (always says the fence is not signaled yet).
40 // glClientWaitSync works better, so let's use that instead.
41 GLenum result = glClientWaitSync(sync_, 0, 0);
42 if (result == GL_WAIT_FAILED) {
43 LOG(FATAL) << "Failed to wait for GLFence. error code:" << GetGLErrors();
45 return result != GL_TIMEOUT_EXPIRED;
48 void GLFenceARB::ClientWait() {
49 DCHECK_EQ(GL_TRUE, glIsSync(sync_));
50 GLenum result =
51 glClientWaitSync(sync_, GL_SYNC_FLUSH_COMMANDS_BIT, GL_TIMEOUT_IGNORED);
52 DCHECK_NE(static_cast<GLenum>(GL_TIMEOUT_EXPIRED), result);
53 if (result == GL_WAIT_FAILED) {
54 LOG(FATAL) << "Failed to wait for GLFence. error code:" << GetGLErrors();
58 void GLFenceARB::ServerWait() {
59 DCHECK_EQ(GL_TRUE, glIsSync(sync_));
60 glWaitSync(sync_, 0, GL_TIMEOUT_IGNORED);
63 GLFenceARB::~GLFenceARB() {
64 DCHECK_EQ(GL_TRUE, glIsSync(sync_));
65 glDeleteSync(sync_);
68 } // namespace gfx