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"
21 GLFence
* CreateFence(bool flush
) {
22 DCHECK(GLContext::GetCurrent())
23 << "Trying to create fence with no context";
25 scoped_ptr
<GLFence
> fence
;
26 // Prefer ARB_sync which supports server-side wait.
27 if (g_driver_gl
.ext
.b_GL_ARB_sync
||
28 GetGLVersionInfo()->is_es3
) {
29 fence
.reset(new GLFenceARB(flush
));
30 #if !defined(OS_MACOSX)
31 } else if (g_driver_egl
.ext
.b_EGL_KHR_fence_sync
) {
32 fence
.reset(new GLFenceEGL(flush
));
34 } else if (g_driver_gl
.ext
.b_GL_NV_fence
) {
35 fence
.reset(new GLFenceNV(flush
));
38 DCHECK_EQ(!!fence
.get(), GLFence::IsSupported());
39 return fence
.release();
50 bool GLFence::IsSupported() {
51 DCHECK(GetGLVersionInfo());
52 return g_driver_gl
.ext
.b_GL_ARB_sync
|| GetGLVersionInfo()->is_es3
||
53 #if !defined(OS_MACOSX)
54 g_driver_egl
.ext
.b_EGL_KHR_fence_sync
||
56 g_driver_gl
.ext
.b_GL_NV_fence
;
59 GLFence
* GLFence::Create() {
60 return CreateFence(true);
63 GLFence
* GLFence::CreateWithoutFlush() {
64 return CreateFence(false);