Fix WindowAndroid leak in Android WebView
[chromium-blink-merge.git] / ui / gl / gl_fence.cc
blob0fb3a743309c588cf688e13915b83a420179b0c3
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"
18 #endif
20 namespace gfx {
22 GLFence::GLFence() {
25 GLFence::~GLFence() {
28 bool GLFence::IsSupported() {
29 DCHECK(GetGLVersionInfo());
30 return g_driver_gl.ext.b_GL_ARB_sync || GetGLVersionInfo()->is_es3 ||
31 #if defined(OS_MACOSX)
32 g_driver_gl.ext.b_GL_APPLE_fence ||
33 #else
34 g_driver_egl.ext.b_EGL_KHR_fence_sync ||
35 #endif
36 g_driver_gl.ext.b_GL_NV_fence;
39 GLFence* GLFence::Create() {
40 DCHECK(GLContext::GetCurrent())
41 << "Trying to create fence with no context";
43 scoped_ptr<GLFence> fence;
44 // Prefer ARB_sync which supports server-side wait.
45 if (g_driver_gl.ext.b_GL_ARB_sync ||
46 GetGLVersionInfo()->is_es3) {
47 fence.reset(new GLFenceARB);
48 #if defined(OS_MACOSX)
49 } else if (g_driver_gl.ext.b_GL_APPLE_fence) {
50 fence.reset(new GLFenceAPPLE);
51 #else
52 } else if (g_driver_egl.ext.b_EGL_KHR_fence_sync) {
53 fence.reset(new GLFenceEGL);
54 #endif
55 } else if (g_driver_gl.ext.b_GL_NV_fence) {
56 fence.reset(new GLFenceNV);
59 DCHECK_EQ(!!fence.get(), GLFence::IsSupported());
60 return fence.release();
63 } // namespace gfx