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"
10 #include "ui/gl/gl_fence_arb.h"
11 #include "ui/gl/gl_fence_egl.h"
12 #include "ui/gl/gl_fence_nv.h"
13 #include "ui/gl/gl_gl_api_implementation.h"
14 #include "ui/gl/gl_version_info.h"
16 #if defined(OS_MACOSX)
17 #include "ui/gl/gl_fence_apple.h"
25 GLFence
* CreateFence(bool flush
) {
26 DCHECK(GLContext::GetCurrent())
27 << "Trying to create fence with no context";
29 scoped_ptr
<GLFence
> fence
;
30 // Prefer ARB_sync which supports server-side wait.
31 if (g_driver_gl
.ext
.b_GL_ARB_sync
||
32 GetGLVersionInfo()->is_es3
) {
33 fence
.reset(new GLFenceARB(flush
));
34 #if defined(OS_MACOSX)
35 } else if (g_driver_gl
.ext
.b_GL_APPLE_fence
) {
36 fence
.reset(new GLFenceAPPLE(flush
));
38 } else if (g_driver_egl
.ext
.b_EGL_KHR_fence_sync
) {
39 fence
.reset(new GLFenceEGL(flush
));
41 } else if (g_driver_gl
.ext
.b_GL_NV_fence
) {
42 fence
.reset(new GLFenceNV(flush
));
45 DCHECK_EQ(!!fence
.get(), GLFence::IsSupported());
46 return fence
.release();
57 bool GLFence::IsSupported() {
58 DCHECK(GetGLVersionInfo());
59 return g_driver_gl
.ext
.b_GL_ARB_sync
|| GetGLVersionInfo()->is_es3
||
60 #if defined(OS_MACOSX)
61 g_driver_gl
.ext
.b_GL_APPLE_fence
||
63 g_driver_egl
.ext
.b_EGL_KHR_fence_sync
||
65 g_driver_gl
.ext
.b_GL_NV_fence
;
68 GLFence
* GLFence::Create() {
69 return CreateFence(true);
72 GLFence
* GLFence::CreateWithoutFlush() {
73 return CreateFence(false);