Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: ui/gl/gl_implementation_x11.cc

Issue 98643013: Take GL version and extensions correctly into account when binding functions (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Accommodated changes in content tests Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/gl/gl_implementation_win.cc ('k') | ui/gl/gl_osmesa_api_implementation.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <vector> 5 #include <vector>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/threading/thread_restrictions.h" 9 #include "base/threading/thread_restrictions.h"
10 #include "ui/gl/gl_bindings.h" 10 #include "ui/gl/gl_bindings.h"
11 #include "ui/gl/gl_context_stub_with_extensions.h"
11 #include "ui/gl/gl_egl_api_implementation.h" 12 #include "ui/gl/gl_egl_api_implementation.h"
12 #include "ui/gl/gl_gl_api_implementation.h" 13 #include "ui/gl/gl_gl_api_implementation.h"
13 #include "ui/gl/gl_glx_api_implementation.h" 14 #include "ui/gl/gl_glx_api_implementation.h"
14 #include "ui/gl/gl_implementation.h" 15 #include "ui/gl/gl_implementation.h"
15 #include "ui/gl/gl_implementation_linux.h" 16 #include "ui/gl/gl_implementation_linux.h"
16 #include "ui/gl/gl_osmesa_api_implementation.h" 17 #include "ui/gl/gl_osmesa_api_implementation.h"
17 #include "ui/gl/gl_switches.h" 18 #include "ui/gl/gl_switches.h"
18 19
19 namespace gfx { 20 namespace gfx {
20 namespace { 21 namespace {
(...skipping 10 matching lines...) Expand all
31 } 32 }
32 33
33 } // namespace 34 } // namespace
34 35
35 void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) { 36 void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) {
36 impls->push_back(kGLImplementationDesktopGL); 37 impls->push_back(kGLImplementationDesktopGL);
37 impls->push_back(kGLImplementationEGLGLES2); 38 impls->push_back(kGLImplementationEGLGLES2);
38 impls->push_back(kGLImplementationOSMesaGL); 39 impls->push_back(kGLImplementationOSMesaGL);
39 } 40 }
40 41
41 bool InitializeGLBindings(GLImplementation implementation) { 42 bool InitializeStaticGLBindings(GLImplementation implementation) {
42 // Prevent reinitialization with a different implementation. Once the gpu 43 // Prevent reinitialization with a different implementation. Once the gpu
43 // unit tests have initialized with kGLImplementationMock, we don't want to 44 // unit tests have initialized with kGLImplementationMock, we don't want to
44 // later switch to another GL implementation. 45 // later switch to another GL implementation.
45 if (GetGLImplementation() != kGLImplementationNone) 46 if (GetGLImplementation() != kGLImplementationNone)
46 return true; 47 return true;
47 48
48 // Allow the main thread or another to initialize these bindings 49 // Allow the main thread or another to initialize these bindings
49 // after instituting restrictions on I/O. Going forward they will 50 // after instituting restrictions on I/O. Going forward they will
50 // likely be used in the browser process on most platforms. The 51 // likely be used in the browser process on most platforms. The
51 // one-time initialization cost is small, between 2 and 5 ms. 52 // one-time initialization cost is small, between 2 and 5 ms.
52 base::ThreadRestrictions::ScopedAllowIO allow_io; 53 base::ThreadRestrictions::ScopedAllowIO allow_io;
53 54
54 switch (implementation) { 55 switch (implementation) {
55 case kGLImplementationOSMesaGL: 56 case kGLImplementationOSMesaGL:
56 return InitializeGLBindingsOSMesaGL(); 57 return InitializeStaticGLBindingsOSMesaGL();
57 case kGLImplementationDesktopGL: { 58 case kGLImplementationDesktopGL: {
58 base::NativeLibrary library = NULL; 59 base::NativeLibrary library = NULL;
59 const CommandLine* command_line = CommandLine::ForCurrentProcess(); 60 const CommandLine* command_line = CommandLine::ForCurrentProcess();
60 61
61 if (command_line->HasSwitch(switches::kTestGLLib)) 62 if (command_line->HasSwitch(switches::kTestGLLib))
62 library = LoadLibrary(command_line->GetSwitchValueASCII( 63 library = LoadLibrary(command_line->GetSwitchValueASCII(
63 switches::kTestGLLib).c_str()); 64 switches::kTestGLLib).c_str());
64 65
65 if (!library) { 66 if (!library) {
66 #if defined(OS_OPENBSD) 67 #if defined(OS_OPENBSD)
(...skipping 13 matching lines...) Expand all
80 if (!get_proc_address) { 81 if (!get_proc_address) {
81 LOG(ERROR) << "glxGetProcAddress not found."; 82 LOG(ERROR) << "glxGetProcAddress not found.";
82 base::UnloadNativeLibrary(library); 83 base::UnloadNativeLibrary(library);
83 return false; 84 return false;
84 } 85 }
85 86
86 SetGLGetProcAddressProc(get_proc_address); 87 SetGLGetProcAddressProc(get_proc_address);
87 AddGLNativeLibrary(library); 88 AddGLNativeLibrary(library);
88 SetGLImplementation(kGLImplementationDesktopGL); 89 SetGLImplementation(kGLImplementationDesktopGL);
89 90
90 InitializeGLBindingsGL(); 91 InitializeStaticGLBindingsGL();
91 InitializeGLBindingsGLX(); 92 InitializeStaticGLBindingsGLX();
92 break; 93 break;
93 } 94 }
94 case kGLImplementationEGLGLES2: { 95 case kGLImplementationEGLGLES2: {
95 base::NativeLibrary gles_library = LoadLibrary("libGLESv2.so.2"); 96 base::NativeLibrary gles_library = LoadLibrary("libGLESv2.so.2");
96 if (!gles_library) 97 if (!gles_library)
97 return false; 98 return false;
98 base::NativeLibrary egl_library = LoadLibrary("libEGL.so.1"); 99 base::NativeLibrary egl_library = LoadLibrary("libEGL.so.1");
99 if (!egl_library) { 100 if (!egl_library) {
100 base::UnloadNativeLibrary(gles_library); 101 base::UnloadNativeLibrary(gles_library);
101 return false; 102 return false;
102 } 103 }
103 104
104 GLGetProcAddressProc get_proc_address = 105 GLGetProcAddressProc get_proc_address =
105 reinterpret_cast<GLGetProcAddressProc>( 106 reinterpret_cast<GLGetProcAddressProc>(
106 base::GetFunctionPointerFromNativeLibrary( 107 base::GetFunctionPointerFromNativeLibrary(
107 egl_library, "eglGetProcAddress")); 108 egl_library, "eglGetProcAddress"));
108 if (!get_proc_address) { 109 if (!get_proc_address) {
109 LOG(ERROR) << "eglGetProcAddress not found."; 110 LOG(ERROR) << "eglGetProcAddress not found.";
110 base::UnloadNativeLibrary(egl_library); 111 base::UnloadNativeLibrary(egl_library);
111 base::UnloadNativeLibrary(gles_library); 112 base::UnloadNativeLibrary(gles_library);
112 return false; 113 return false;
113 } 114 }
114 115
115 SetGLGetProcAddressProc(get_proc_address); 116 SetGLGetProcAddressProc(get_proc_address);
116 AddGLNativeLibrary(egl_library); 117 AddGLNativeLibrary(egl_library);
117 AddGLNativeLibrary(gles_library); 118 AddGLNativeLibrary(gles_library);
118 SetGLImplementation(kGLImplementationEGLGLES2); 119 SetGLImplementation(kGLImplementationEGLGLES2);
119 120
120 InitializeGLBindingsGL(); 121 InitializeStaticGLBindingsGL();
121 InitializeGLBindingsEGL(); 122 InitializeStaticGLBindingsEGL();
122 123
123 // These two functions take single precision float rather than double 124 // These two functions take single precision float rather than double
124 // precision float parameters in GLES. 125 // precision float parameters in GLES.
125 ::gfx::g_driver_gl.fn.glClearDepthFn = MarshalClearDepthToClearDepthf; 126 ::gfx::g_driver_gl.fn.glClearDepthFn = MarshalClearDepthToClearDepthf;
126 ::gfx::g_driver_gl.fn.glDepthRangeFn = MarshalDepthRangeToDepthRangef; 127 ::gfx::g_driver_gl.fn.glDepthRangeFn = MarshalDepthRangeToDepthRangef;
127 break; 128 break;
128 } 129 }
129 case kGLImplementationMockGL: { 130 case kGLImplementationMockGL: {
130 SetGLGetProcAddressProc(GetMockGLProcAddress); 131 SetGLGetProcAddressProc(GetMockGLProcAddress);
131 SetGLImplementation(kGLImplementationMockGL); 132 SetGLImplementation(kGLImplementationMockGL);
132 InitializeGLBindingsGL(); 133 InitializeStaticGLBindingsGL();
133 break; 134 break;
134 } 135 }
135 default: 136 default:
136 return false; 137 return false;
137 } 138 }
138 139
139 140
140 return true; 141 return true;
141 } 142 }
142 143
143 bool InitializeGLExtensionBindings(GLImplementation implementation, 144 bool InitializeDynamicGLBindings(GLImplementation implementation,
144 GLContext* context) { 145 GLContext* context) {
145 switch (implementation) { 146 switch (implementation) {
146 case kGLImplementationOSMesaGL: 147 case kGLImplementationOSMesaGL:
147 InitializeGLExtensionBindingsGL(context); 148 InitializeDynamicGLBindingsGL(context);
148 InitializeGLExtensionBindingsOSMESA(context); 149 InitializeDynamicGLBindingsOSMESA(context);
149 break; 150 break;
150 case kGLImplementationDesktopGL: 151 case kGLImplementationDesktopGL:
151 InitializeGLExtensionBindingsGL(context); 152 InitializeDynamicGLBindingsGL(context);
152 InitializeGLExtensionBindingsGLX(context); 153 InitializeDynamicGLBindingsGLX(context);
153 break; 154 break;
154 case kGLImplementationEGLGLES2: 155 case kGLImplementationEGLGLES2:
155 InitializeGLExtensionBindingsGL(context); 156 InitializeDynamicGLBindingsGL(context);
156 InitializeGLExtensionBindingsEGL(context); 157 InitializeDynamicGLBindingsEGL(context);
157 break; 158 break;
158 case kGLImplementationMockGL: 159 case kGLImplementationMockGL:
159 InitializeGLExtensionBindingsGL(context); 160 if (!context) {
161 scoped_refptr<GLContextStubWithExtensions> mock_context(
162 new GLContextStubWithExtensions());
163 mock_context->SetGLVersionString("3.0");
164 InitializeDynamicGLBindingsGL(mock_context.get());
165 } else
166 InitializeDynamicGLBindingsGL(context);
160 break; 167 break;
161 default: 168 default:
162 return false; 169 return false;
163 } 170 }
164 171
165 return true; 172 return true;
166 } 173 }
167 174
168 void InitializeDebugGLBindings() { 175 void InitializeDebugGLBindings() {
169 InitializeDebugGLBindingsEGL(); 176 InitializeDebugGLBindingsEGL();
(...skipping 18 matching lines...) Expand all
188 return GetGLWindowSystemBindingInfoGLX(info); 195 return GetGLWindowSystemBindingInfoGLX(info);
189 case kGLImplementationEGLGLES2: 196 case kGLImplementationEGLGLES2:
190 return GetGLWindowSystemBindingInfoEGL(info); 197 return GetGLWindowSystemBindingInfoEGL(info);
191 default: 198 default:
192 return false; 199 return false;
193 } 200 }
194 return false; 201 return false;
195 } 202 }
196 203
197 } // namespace gfx 204 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gl/gl_implementation_win.cc ('k') | ui/gl/gl_osmesa_api_implementation.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698