Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / ui / gl / gl_implementation.cc
bloba307fb0ae774823a8c9c6be61955e4b9803c7f1d
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 "ui/gl/gl_bindings.h"
14 #include "ui/gl/gl_gl_api_implementation.h"
16 namespace gfx {
18 namespace {
20 const struct {
21 const char* name;
22 GLImplementation implementation;
23 } kGLImplementationNamePairs[] = {
24 { kGLImplementationDesktopName, kGLImplementationDesktopGL },
25 { kGLImplementationOSMesaName, kGLImplementationOSMesaGL },
26 #if defined(OS_MACOSX)
27 { kGLImplementationAppleName, kGLImplementationAppleGL },
28 #endif
29 { kGLImplementationEGLName, kGLImplementationEGLGLES2 },
30 { kGLImplementationMockName, kGLImplementationMockGL }
33 typedef std::vector<base::NativeLibrary> LibraryArray;
35 GLImplementation g_gl_implementation = kGLImplementationNone;
36 LibraryArray* g_libraries;
37 GLGetProcAddressProc g_get_proc_address;
39 void CleanupNativeLibraries(void* unused) {
40 if (g_libraries) {
41 // We do not call base::UnloadNativeLibrary() for these libraries as
42 // unloading libGL without closing X display is not allowed. See
43 // crbug.com/250813 for details.
44 delete g_libraries;
45 g_libraries = NULL;
51 base::ThreadLocalPointer<GLApi>* g_current_gl_context_tls = NULL;
52 OSMESAApi* g_current_osmesa_context;
54 #if defined(OS_WIN)
56 EGLApi* g_current_egl_context;
57 WGLApi* g_current_wgl_context;
59 #elif defined(USE_X11)
61 EGLApi* g_current_egl_context;
62 GLXApi* g_current_glx_context;
64 #elif defined(USE_OZONE)
66 EGLApi* g_current_egl_context;
68 #elif defined(OS_ANDROID)
70 EGLApi* g_current_egl_context;
72 #endif
74 GLImplementation GetNamedGLImplementation(const std::string& name) {
75 for (size_t i = 0; i < arraysize(kGLImplementationNamePairs); ++i) {
76 if (name == kGLImplementationNamePairs[i].name)
77 return kGLImplementationNamePairs[i].implementation;
80 return kGLImplementationNone;
83 const char* GetGLImplementationName(GLImplementation implementation) {
84 for (size_t i = 0; i < arraysize(kGLImplementationNamePairs); ++i) {
85 if (implementation == kGLImplementationNamePairs[i].implementation)
86 return kGLImplementationNamePairs[i].name;
89 return "unknown";
92 void SetGLImplementation(GLImplementation implementation) {
93 g_gl_implementation = implementation;
96 GLImplementation GetGLImplementation() {
97 return g_gl_implementation;
100 bool HasDesktopGLFeatures() {
101 return kGLImplementationDesktopGL == g_gl_implementation ||
102 kGLImplementationDesktopGLCoreProfile == g_gl_implementation ||
103 kGLImplementationOSMesaGL == g_gl_implementation ||
104 kGLImplementationAppleGL == g_gl_implementation;
107 void AddGLNativeLibrary(base::NativeLibrary library) {
108 DCHECK(library);
110 if (!g_libraries) {
111 g_libraries = new LibraryArray;
112 base::AtExitManager::RegisterCallback(CleanupNativeLibraries, NULL);
115 g_libraries->push_back(library);
118 void UnloadGLNativeLibraries() {
119 CleanupNativeLibraries(NULL);
122 void SetGLGetProcAddressProc(GLGetProcAddressProc proc) {
123 DCHECK(proc);
124 g_get_proc_address = proc;
127 void* GetGLProcAddress(const char* name) {
128 DCHECK(g_gl_implementation != kGLImplementationNone);
130 if (g_libraries) {
131 for (size_t i = 0; i < g_libraries->size(); ++i) {
132 void* proc = base::GetFunctionPointerFromNativeLibrary((*g_libraries)[i],
133 name);
134 if (proc)
135 return proc;
138 if (g_get_proc_address) {
139 void* proc = g_get_proc_address(name);
140 if (proc)
141 return proc;
144 return NULL;
147 void InitializeNullDrawGLBindings() {
148 // This is platform independent, so it does not need to live in a platform
149 // specific implementation file.
150 InitializeNullDrawGLBindingsGL();
153 bool HasInitializedNullDrawGLBindings() {
154 return HasInitializedNullDrawGLBindingsGL();
157 DisableNullDrawGLBindings::DisableNullDrawGLBindings() {
158 initial_enabled_ = SetNullDrawGLBindingsEnabledGL(false);
161 DisableNullDrawGLBindings::~DisableNullDrawGLBindings() {
162 SetNullDrawGLBindingsEnabledGL(initial_enabled_);
165 GLWindowSystemBindingInfo::GLWindowSystemBindingInfo()
166 : direct_rendering(true) {}
168 } // namespace gfx