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"
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"
22 GLImplementation implementation
;
23 } kGLImplementationNamePairs
[] = {
24 { kGLImplementationDesktopName
, kGLImplementationDesktopGL
},
25 { kGLImplementationOSMesaName
, kGLImplementationOSMesaGL
},
26 #if defined(OS_MACOSX)
27 { kGLImplementationAppleName
, kGLImplementationAppleGL
},
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
) {
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.
51 base::ThreadLocalPointer
<GLApi
>* g_current_gl_context_tls
= NULL
;
52 OSMESAApi
* g_current_osmesa_context
;
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
;
74 GLImplementation
GetNamedGLImplementation(const std::string
& name
) {
75 for (size_t i
= 0; i
< ARRAYSIZE_UNSAFE(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_UNSAFE(kGLImplementationNamePairs
); ++i
) {
85 if (implementation
== kGLImplementationNamePairs
[i
].implementation
)
86 return kGLImplementationNamePairs
[i
].name
;
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 kGLImplementationOSMesaGL
== g_gl_implementation
||
103 kGLImplementationAppleGL
== g_gl_implementation
;
106 void AddGLNativeLibrary(base::NativeLibrary library
) {
110 g_libraries
= new LibraryArray
;
111 base::AtExitManager::RegisterCallback(CleanupNativeLibraries
, NULL
);
114 g_libraries
->push_back(library
);
117 void UnloadGLNativeLibraries() {
118 CleanupNativeLibraries(NULL
);
121 void SetGLGetProcAddressProc(GLGetProcAddressProc proc
) {
123 g_get_proc_address
= proc
;
126 void* GetGLProcAddress(const char* name
) {
127 DCHECK(g_gl_implementation
!= kGLImplementationNone
);
130 for (size_t i
= 0; i
< g_libraries
->size(); ++i
) {
131 void* proc
= base::GetFunctionPointerFromNativeLibrary((*g_libraries
)[i
],
137 if (g_get_proc_address
) {
138 void* proc
= g_get_proc_address(name
);
146 void InitializeNullDrawGLBindings() {
147 // This is platform independent, so it does not need to live in a platform
148 // specific implementation file.
149 InitializeNullDrawGLBindingsGL();
152 bool HasInitializedNullDrawGLBindings() {
153 return HasInitializedNullDrawGLBindingsGL();
156 DisableNullDrawGLBindings::DisableNullDrawGLBindings() {
157 initial_enabled_
= SetNullDrawGLBindingsEnabledGL(false);
160 DisableNullDrawGLBindings::~DisableNullDrawGLBindings() {
161 SetNullDrawGLBindingsEnabledGL(initial_enabled_
);
164 GLWindowSystemBindingInfo::GLWindowSystemBindingInfo()
165 : direct_rendering(true) {}