1 // Copyright (c) 2012 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.h"
7 #include "base/compiler_specific.h"
8 #include "ui/gl/gl_bindings.h"
9 #include "ui/gl/gl_context.h"
13 class GLFenceNVFence
: public gfx::GLFence
{
16 // What if either of these GL calls fails? TestFenceNV will return true.
18 // http://www.opengl.org/registry/specs/NV/fence.txt
20 // What should happen if TestFenceNV is called for a name before SetFenceNV
22 // We generate an INVALID_OPERATION error, and return TRUE.
23 // This follows the semantics for texture object names before
24 // they are bound, in that they acquire their state upon binding.
25 // We will arbitrarily return TRUE for consistency.
26 glGenFencesNV(1, &fence_
);
27 glSetFenceNV(fence_
, GL_ALL_COMPLETED_NV
);
31 virtual bool HasCompleted() OVERRIDE
{
32 return !!glTestFenceNV(fence_
);
36 virtual ~GLFenceNVFence() {
37 glDeleteFencesNV(1, &fence_
);
43 class GLFenceARBSync
: public gfx::GLFence
{
46 sync_
= glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE
, 0);
50 virtual bool HasCompleted() OVERRIDE
{
51 // Handle the case where FenceSync failed.
62 return length
== 1 && value
== GL_SIGNALED
;
66 virtual ~GLFenceARBSync() {
84 GLFence
* GLFence::Create() {
85 if (gfx::g_driver_gl
.ext
.b_GL_NV_fence
) {
86 return new GLFenceNVFence();
87 } else if (gfx::g_driver_gl
.ext
.b_GL_ARB_sync
) {
88 return new GLFenceARBSync();