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

Side by Side Diff: ui/gl/gl_implementation_win.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: Clarify code in generate_bindings.py according to feedback 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
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/at_exit.h" 7 #include "base/at_exit.h"
8 #include "base/base_paths.h" 8 #include "base/base_paths.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/debug/trace_event.h" 11 #include "base/debug/trace_event.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/native_library.h" 14 #include "base/native_library.h"
15 #include "base/path_service.h" 15 #include "base/path_service.h"
16 #include "base/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
17 #include "base/threading/thread_restrictions.h" 17 #include "base/threading/thread_restrictions.h"
18 #include "base/win/windows_version.h" 18 #include "base/win/windows_version.h"
19 #include "ui/gl/gl_bindings.h" 19 #include "ui/gl/gl_bindings.h"
20 #include "ui/gl/gl_context_stub_with_extensions.h"
20 #include "ui/gl/gl_egl_api_implementation.h" 21 #include "ui/gl/gl_egl_api_implementation.h"
21 #include "ui/gl/gl_gl_api_implementation.h" 22 #include "ui/gl/gl_gl_api_implementation.h"
22 #include "ui/gl/gl_implementation.h" 23 #include "ui/gl/gl_implementation.h"
23 #include "ui/gl/gl_osmesa_api_implementation.h" 24 #include "ui/gl/gl_osmesa_api_implementation.h"
25 #include "ui/gl/gl_surface_wgl.h"
24 #include "ui/gl/gl_wgl_api_implementation.h" 26 #include "ui/gl/gl_wgl_api_implementation.h"
25 27
26 #if defined(ENABLE_SWIFTSHADER) 28 #if defined(ENABLE_SWIFTSHADER)
27 #include "software_renderer.h" 29 #include "software_renderer.h"
28 #endif 30 #endif
29 31
30 namespace gfx { 32 namespace gfx {
31 33
32 namespace { 34 namespace {
33 35
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 AddTraceEventFunc add_trace_event_func); 101 AddTraceEventFunc add_trace_event_func);
100 102
101 } // namespace 103 } // namespace
102 104
103 void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) { 105 void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) {
104 impls->push_back(kGLImplementationEGLGLES2); 106 impls->push_back(kGLImplementationEGLGLES2);
105 impls->push_back(kGLImplementationDesktopGL); 107 impls->push_back(kGLImplementationDesktopGL);
106 impls->push_back(kGLImplementationOSMesaGL); 108 impls->push_back(kGLImplementationOSMesaGL);
107 } 109 }
108 110
109 bool InitializeGLBindings(GLImplementation implementation) { 111 bool InitializeStaticGLBindings(GLImplementation implementation) {
110 // Prevent reinitialization with a different implementation. Once the gpu 112 // Prevent reinitialization with a different implementation. Once the gpu
111 // unit tests have initialized with kGLImplementationMock, we don't want to 113 // unit tests have initialized with kGLImplementationMock, we don't want to
112 // later switch to another GL implementation. 114 // later switch to another GL implementation.
113 if (GetGLImplementation() != kGLImplementationNone) 115 if (GetGLImplementation() != kGLImplementationNone)
114 return true; 116 return true;
115 117
116 // Allow the main thread or another to initialize these bindings 118 // Allow the main thread or another to initialize these bindings
117 // after instituting restrictions on I/O. Going forward they will 119 // after instituting restrictions on I/O. Going forward they will
118 // likely be used in the browser process on most platforms. The 120 // likely be used in the browser process on most platforms. The
119 // one-time initialization cost is small, between 2 and 5 ms. 121 // one-time initialization cost is small, between 2 and 5 ms.
(...skipping 21 matching lines...) Expand all
141 if (!get_proc_address) { 143 if (!get_proc_address) {
142 DLOG(ERROR) << "OSMesaGetProcAddress not found."; 144 DLOG(ERROR) << "OSMesaGetProcAddress not found.";
143 base::UnloadNativeLibrary(library); 145 base::UnloadNativeLibrary(library);
144 return false; 146 return false;
145 } 147 }
146 148
147 SetGLGetProcAddressProc(get_proc_address); 149 SetGLGetProcAddressProc(get_proc_address);
148 AddGLNativeLibrary(library); 150 AddGLNativeLibrary(library);
149 SetGLImplementation(kGLImplementationOSMesaGL); 151 SetGLImplementation(kGLImplementationOSMesaGL);
150 152
151 InitializeGLBindingsGL(); 153 InitializeStaticGLBindingsGL();
152 InitializeGLBindingsOSMESA(); 154 InitializeStaticGLBindingsOSMESA();
153 break; 155 break;
154 } 156 }
155 case kGLImplementationEGLGLES2: { 157 case kGLImplementationEGLGLES2: {
156 base::FilePath module_path; 158 base::FilePath module_path;
157 if (!PathService::Get(base::DIR_MODULE, &module_path)) 159 if (!PathService::Get(base::DIR_MODULE, &module_path))
158 return false; 160 return false;
159 161
160 // Attempt to load the D3DX shader compiler using the default search path 162 // Attempt to load the D3DX shader compiler using the default search path
161 // and if that fails, using an absolute path. This is to ensure these DLLs 163 // and if that fails, using an absolute path. This is to ensure these DLLs
162 // are loaded before ANGLE is loaded in case they are not in the default 164 // are loaded before ANGLE is loaded in case they are not in the default
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 base::UnloadNativeLibrary(egl_library); 229 base::UnloadNativeLibrary(egl_library);
228 base::UnloadNativeLibrary(gles_library); 230 base::UnloadNativeLibrary(gles_library);
229 return false; 231 return false;
230 } 232 }
231 233
232 SetGLGetProcAddressProc(get_proc_address); 234 SetGLGetProcAddressProc(get_proc_address);
233 AddGLNativeLibrary(egl_library); 235 AddGLNativeLibrary(egl_library);
234 AddGLNativeLibrary(gles_library); 236 AddGLNativeLibrary(gles_library);
235 SetGLImplementation(kGLImplementationEGLGLES2); 237 SetGLImplementation(kGLImplementationEGLGLES2);
236 238
237 InitializeGLBindingsGL(); 239 InitializeStaticGLBindingsGL();
238 InitializeGLBindingsEGL(); 240 InitializeStaticGLBindingsEGL();
239 241
240 // These two functions take single precision float rather than double 242 // These two functions take single precision float rather than double
241 // precision float parameters in GLES. 243 // precision float parameters in GLES.
242 ::gfx::g_driver_gl.fn.glClearDepthFn = MarshalClearDepthToClearDepthf; 244 ::gfx::g_driver_gl.fn.glClearDepthFn = MarshalClearDepthToClearDepthf;
243 ::gfx::g_driver_gl.fn.glDepthRangeFn = MarshalDepthRangeToDepthRangef; 245 ::gfx::g_driver_gl.fn.glDepthRangeFn = MarshalDepthRangeToDepthRangef;
244 break; 246 break;
245 } 247 }
246 case kGLImplementationDesktopGL: { 248 case kGLImplementationDesktopGL: {
247 // When using Windows OpenGL, first try wglGetProcAddress and then
248 // Windows GetProcAddress.
249 base::NativeLibrary library = base::LoadNativeLibrary( 249 base::NativeLibrary library = base::LoadNativeLibrary(
250 base::FilePath(L"opengl32.dll"), NULL); 250 base::FilePath(L"opengl32.dll"), NULL);
251 if (!library) { 251 if (!library) {
252 DVLOG(1) << "opengl32.dll not found"; 252 DVLOG(1) << "opengl32.dll not found";
253 return false; 253 return false;
254 } 254 }
255 255
256 GLGetProcAddressProc get_proc_address = 256 GLGetProcAddressProc get_proc_address =
257 reinterpret_cast<GLGetProcAddressProc>( 257 reinterpret_cast<GLGetProcAddressProc>(
258 base::GetFunctionPointerFromNativeLibrary( 258 base::GetFunctionPointerFromNativeLibrary(
259 library, "wglGetProcAddress")); 259 library, "wglGetProcAddress"));
260 if (!get_proc_address) { 260 if (!get_proc_address) {
261 LOG(ERROR) << "wglGetProcAddress not found."; 261 LOG(ERROR) << "wglGetProcAddress not found.";
262 base::UnloadNativeLibrary(library); 262 base::UnloadNativeLibrary(library);
263 return false; 263 return false;
264 } 264 }
265 265
266 SetGLGetProcAddressProc(get_proc_address); 266 SetGLGetProcAddressProc(get_proc_address);
267 AddGLNativeLibrary(library); 267 AddGLNativeLibrary(library);
268 SetGLImplementation(kGLImplementationDesktopGL); 268 SetGLImplementation(kGLImplementationDesktopGL);
269 269
270 InitializeGLBindingsGL(); 270 // Initialize WGL bindings to be able to create a context.
271 InitializeGLBindingsWGL(); 271 InitializeStaticGLBindingsWGL();
no sievers 2014/01/14 23:16:01 How about only looking up the symbol for wglCreate
oetuaho-nv 2014/01/15 15:50:25 True. Done.
272
273 // Create a temporary GL context to bind to entry points. This is needed
274 // because wglGetProcAddress is specified to return NULL for all queries
275 // if a context is not current in MSDN documentation, and the static
276 // bindings may contain functions that need to be queried with
277 // wglGetProcAddress. OpenGL wiki further warns that other error values
278 // than NULL could also be returned from wglGetProcAddress on some
279 // implementations, so we need to clear the WGL bindings and reinitialize
280 // them after the context creation.
281 HGLRC gl_context = wglCreateContext(GLSurfaceWGL::GetDisplayDC());
282 if (!gl_context) {
283 LOG(ERROR) << "Failed to create temporary context.";
284 return false;
285 }
286 if (!wglMakeCurrent(GLSurfaceWGL::GetDisplayDC(), gl_context)) {
287 LOG(ERROR) << "Failed to make temporary GL context current.";
288 wglDeleteContext(gl_context);
289 return false;
290 }
291
292 ClearGLBindingsWGL();
293 InitializeStaticGLBindingsGL();
294 InitializeStaticGLBindingsWGL();
295
296 wglMakeCurrent(NULL, NULL);
297 wglDeleteContext(gl_context);
298
272 break; 299 break;
273 } 300 }
274 case kGLImplementationMockGL: { 301 case kGLImplementationMockGL: {
275 SetGLGetProcAddressProc(GetMockGLProcAddress); 302 SetGLGetProcAddressProc(GetMockGLProcAddress);
276 SetGLImplementation(kGLImplementationMockGL); 303 SetGLImplementation(kGLImplementationMockGL);
277 InitializeGLBindingsGL(); 304 InitializeStaticGLBindingsGL();
278 break; 305 break;
279 } 306 }
280 default: 307 default:
281 return false; 308 return false;
282 } 309 }
283 310
284 return true; 311 return true;
285 } 312 }
286 313
287 bool InitializeGLExtensionBindings(GLImplementation implementation, 314 bool InitializeDynamicGLBindings(GLImplementation implementation,
288 GLContext* context) { 315 GLContext* context) {
289 switch (implementation) { 316 switch (implementation) {
290 case kGLImplementationOSMesaGL: 317 case kGLImplementationOSMesaGL:
291 InitializeGLExtensionBindingsGL(context); 318 InitializeDynamicGLBindingsGL(context);
292 InitializeGLExtensionBindingsOSMESA(context); 319 InitializeDynamicGLBindingsOSMESA(context);
293 break; 320 break;
294 case kGLImplementationEGLGLES2: 321 case kGLImplementationEGLGLES2:
295 InitializeGLExtensionBindingsGL(context); 322 InitializeDynamicGLBindingsGL(context);
296 InitializeGLExtensionBindingsEGL(context); 323 InitializeDynamicGLBindingsEGL(context);
297 break; 324 break;
298 case kGLImplementationDesktopGL: 325 case kGLImplementationDesktopGL:
299 InitializeGLExtensionBindingsGL(context); 326 InitializeDynamicGLBindingsGL(context);
300 InitializeGLExtensionBindingsWGL(context); 327 InitializeDynamicGLBindingsWGL(context);
301 break; 328 break;
302 case kGLImplementationMockGL: 329 case kGLImplementationMockGL:
303 InitializeGLExtensionBindingsGL(context); 330 if (!context) {
331 scoped_refptr<GLContextStubWithExtensions> mock_context(
332 new GLContextStubWithExtensions());
333 mock_context->SetGLVersionString("3.0");
334 InitializeDynamicGLBindingsGL(mock_context.get());
335 } else
336 InitializeDynamicGLBindingsGL(context);
304 break; 337 break;
305 default: 338 default:
306 return false; 339 return false;
307 } 340 }
308 341
309 return true; 342 return true;
310 } 343 }
311 344
312 void InitializeDebugGLBindings() { 345 void InitializeDebugGLBindings() {
313 InitializeDebugGLBindingsEGL(); 346 InitializeDebugGLBindingsEGL();
(...skipping 17 matching lines...) Expand all
331 return GetGLWindowSystemBindingInfoWGL(info); 364 return GetGLWindowSystemBindingInfoWGL(info);
332 case kGLImplementationEGLGLES2: 365 case kGLImplementationEGLGLES2:
333 return GetGLWindowSystemBindingInfoEGL(info); 366 return GetGLWindowSystemBindingInfoEGL(info);
334 default: 367 default:
335 return false; 368 return false;
336 } 369 }
337 return false; 370 return false;
338 } 371 }
339 372
340 } // namespace gfx 373 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698