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. 4 5#include "ui/gl/gl_fence.h" 6 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" 15 16namespace gfx { 17 18namespace { 19 20// static 21GLFence* CreateFence(bool flush) { 22 DCHECK(GLContext::GetCurrent()) 23 << "Trying to create fence with no context"; 24 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)); 33#endif 34 } else if (g_driver_gl.ext.b_GL_NV_fence) { 35 fence.reset(new GLFenceNV(flush)); 36 } 37 38 DCHECK_EQ(!!fence.get(), GLFence::IsSupported()); 39 return fence.release(); 40} 41 42} // namespace 43 44GLFence::GLFence() { 45} 46 47GLFence::~GLFence() { 48} 49 50bool 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 || 55#endif 56 g_driver_gl.ext.b_GL_NV_fence; 57} 58 59GLFence* GLFence::Create() { 60 return CreateFence(true); 61} 62 63GLFence* GLFence::CreateWithoutFlush() { 64 return CreateFence(false); 65} 66 67} // namespace gfx 68