[chromedriver] Disable ChromeDriverTest.testShouldHandleNewWindowLoadingProperly.
[chromium-blink-merge.git] / ui / gl / gl_implementation.cc
blob96921bcae5a16a7997fed5cc92726eee31f4485c
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_implementation.h"
7 #include <algorithm>
8 #include <string>
10 #include "base/at_exit.h"
11 #include "base/command_line.h"
12 #include "base/logging.h"
13 #include "base/strings/string_split.h"
14 #include "base/strings/string_util.h"
15 #include "ui/gl/gl_bindings.h"
16 #include "ui/gl/gl_gl_api_implementation.h"
18 namespace gfx {
20 namespace {
22 const struct {
23 const char* name;
24 GLImplementation implementation;
25 } kGLImplementationNamePairs[] = {
26 { kGLImplementationDesktopName, kGLImplementationDesktopGL },
27 { kGLImplementationOSMesaName, kGLImplementationOSMesaGL },
28 #if defined(OS_MACOSX)
29 { kGLImplementationAppleName, kGLImplementationAppleGL },
30 #endif
31 { kGLImplementationEGLName, kGLImplementationEGLGLES2 },
32 { kGLImplementationMockName, kGLImplementationMockGL }
35 typedef std::vector<base::NativeLibrary> LibraryArray;
37 GLImplementation g_gl_implementation = kGLImplementationNone;
38 LibraryArray* g_libraries;
39 GLGetProcAddressProc g_get_proc_address;
41 void CleanupNativeLibraries(void* unused) {
42 if (g_libraries) {
43 // We do not call base::UnloadNativeLibrary() for these libraries as
44 // unloading libGL without closing X display is not allowed. See
45 // crbug.com/250813 for details.
46 delete g_libraries;
47 g_libraries = NULL;
53 base::ThreadLocalPointer<GLApi>* g_current_gl_context_tls = NULL;
54 OSMESAApi* g_current_osmesa_context;
56 #if defined(OS_WIN)
58 EGLApi* g_current_egl_context;
59 WGLApi* g_current_wgl_context;
61 #elif defined(USE_X11)
63 EGLApi* g_current_egl_context;
64 GLXApi* g_current_glx_context;
66 #elif defined(USE_OZONE)
68 EGLApi* g_current_egl_context;
70 #elif defined(OS_ANDROID)
72 EGLApi* g_current_egl_context;
74 #endif
76 GLImplementation GetNamedGLImplementation(const std::string& name) {
77 for (size_t i = 0; i < arraysize(kGLImplementationNamePairs); ++i) {
78 if (name == kGLImplementationNamePairs[i].name)
79 return kGLImplementationNamePairs[i].implementation;
82 return kGLImplementationNone;
85 const char* GetGLImplementationName(GLImplementation implementation) {
86 for (size_t i = 0; i < arraysize(kGLImplementationNamePairs); ++i) {
87 if (implementation == kGLImplementationNamePairs[i].implementation)
88 return kGLImplementationNamePairs[i].name;
91 return "unknown";
94 void SetGLImplementation(GLImplementation implementation) {
95 g_gl_implementation = implementation;
98 GLImplementation GetGLImplementation() {
99 return g_gl_implementation;
102 bool HasDesktopGLFeatures() {
103 return kGLImplementationDesktopGL == g_gl_implementation ||
104 kGLImplementationDesktopGLCoreProfile == g_gl_implementation ||
105 kGLImplementationOSMesaGL == g_gl_implementation ||
106 kGLImplementationAppleGL == g_gl_implementation;
109 void AddGLNativeLibrary(base::NativeLibrary library) {
110 DCHECK(library);
112 if (!g_libraries) {
113 g_libraries = new LibraryArray;
114 base::AtExitManager::RegisterCallback(CleanupNativeLibraries, NULL);
117 g_libraries->push_back(library);
120 void UnloadGLNativeLibraries() {
121 CleanupNativeLibraries(NULL);
124 void SetGLGetProcAddressProc(GLGetProcAddressProc proc) {
125 DCHECK(proc);
126 g_get_proc_address = proc;
129 void* GetGLProcAddress(const char* name) {
130 DCHECK(g_gl_implementation != kGLImplementationNone);
132 if (g_libraries) {
133 for (size_t i = 0; i < g_libraries->size(); ++i) {
134 void* proc = base::GetFunctionPointerFromNativeLibrary((*g_libraries)[i],
135 name);
136 if (proc)
137 return proc;
140 if (g_get_proc_address) {
141 void* proc = g_get_proc_address(name);
142 if (proc)
143 return proc;
146 return NULL;
149 void InitializeNullDrawGLBindings() {
150 // This is platform independent, so it does not need to live in a platform
151 // specific implementation file.
152 InitializeNullDrawGLBindingsGL();
155 bool HasInitializedNullDrawGLBindings() {
156 return HasInitializedNullDrawGLBindingsGL();
159 std::string FilterGLExtensionList(
160 const char* extensions,
161 const std::vector<std::string>& disabled_extensions) {
162 if (extensions == NULL)
163 return "";
165 std::vector<std::string> extension_vec;
166 base::SplitString(extensions, ' ', &extension_vec);
168 auto is_disabled = [&disabled_extensions](const std::string& ext) {
169 return std::find(disabled_extensions.begin(), disabled_extensions.end(),
170 ext) != disabled_extensions.end();
172 extension_vec.erase(
173 std::remove_if(extension_vec.begin(), extension_vec.end(), is_disabled),
174 extension_vec.end());
176 return base::JoinString(extension_vec, " ");
179 DisableNullDrawGLBindings::DisableNullDrawGLBindings() {
180 initial_enabled_ = SetNullDrawGLBindingsEnabledGL(false);
183 DisableNullDrawGLBindings::~DisableNullDrawGLBindings() {
184 SetNullDrawGLBindingsEnabledGL(initial_enabled_);
187 GLWindowSystemBindingInfo::GLWindowSystemBindingInfo()
188 : direct_rendering(true) {}
190 } // namespace gfx