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

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: 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_ozone.cc ('k') | ui/gl/gl_implementation_x11.cc » ('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/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 GL surface and get some functions needed for the context
271 InitializeGLBindingsWGL(); 271 // creation below.
272 if (!GLSurfaceWGL::InitializeOneOff()) {
273 LOG(ERROR) << "GLSurfaceWGL::InitializeOneOff failed.";
274 return false;
275 }
276 wglCreateContextProc wglCreateContextFn =
277 reinterpret_cast<wglCreateContextProc>(
278 GetGLProcAddress("wglCreateContext"));
279 wglDeleteContextProc wglDeleteContextFn =
280 reinterpret_cast<wglDeleteContextProc>(
281 GetGLProcAddress("wglDeleteContext"));
282 wglMakeCurrentProc wglMakeCurrentFn =
283 reinterpret_cast<wglMakeCurrentProc>(
284 GetGLProcAddress("wglMakeCurrent"));
285
286 // Create a temporary GL context to bind to entry points. This is needed
287 // because wglGetProcAddress is specified to return NULL for all queries
288 // if a context is not current in MSDN documentation, and the static
289 // bindings may contain functions that need to be queried with
290 // wglGetProcAddress. OpenGL wiki further warns that other error values
291 // than NULL could also be returned from wglGetProcAddress on some
292 // implementations, so we need to clear the WGL bindings and reinitialize
293 // them after the context creation.
294 HGLRC gl_context = wglCreateContextFn(GLSurfaceWGL::GetDisplayDC());
295 if (!gl_context) {
296 LOG(ERROR) << "Failed to create temporary context.";
297 return false;
298 }
299 if (!wglMakeCurrentFn(GLSurfaceWGL::GetDisplayDC(), gl_context)) {
300 LOG(ERROR) << "Failed to make temporary GL context current.";
301 wglDeleteContextFn(gl_context);
302 return false;
303 }
304
305 InitializeStaticGLBindingsGL();
306 InitializeStaticGLBindingsWGL();
307
308 wglMakeCurrent(NULL, NULL);
309 wglDeleteContext(gl_context);
310
272 break; 311 break;
273 } 312 }
274 case kGLImplementationMockGL: { 313 case kGLImplementationMockGL: {
275 SetGLGetProcAddressProc(GetMockGLProcAddress); 314 SetGLGetProcAddressProc(GetMockGLProcAddress);
276 SetGLImplementation(kGLImplementationMockGL); 315 SetGLImplementation(kGLImplementationMockGL);
277 InitializeGLBindingsGL(); 316 InitializeStaticGLBindingsGL();
278 break; 317 break;
279 } 318 }
280 default: 319 default:
281 return false; 320 return false;
282 } 321 }
283 322
284 return true; 323 return true;
285 } 324 }
286 325
287 bool InitializeGLExtensionBindings(GLImplementation implementation, 326 bool InitializeDynamicGLBindings(GLImplementation implementation,
288 GLContext* context) { 327 GLContext* context) {
289 switch (implementation) { 328 switch (implementation) {
290 case kGLImplementationOSMesaGL: 329 case kGLImplementationOSMesaGL:
291 InitializeGLExtensionBindingsGL(context); 330 InitializeDynamicGLBindingsGL(context);
292 InitializeGLExtensionBindingsOSMESA(context); 331 InitializeDynamicGLBindingsOSMESA(context);
293 break; 332 break;
294 case kGLImplementationEGLGLES2: 333 case kGLImplementationEGLGLES2:
295 InitializeGLExtensionBindingsGL(context); 334 InitializeDynamicGLBindingsGL(context);
296 InitializeGLExtensionBindingsEGL(context); 335 InitializeDynamicGLBindingsEGL(context);
297 break; 336 break;
298 case kGLImplementationDesktopGL: 337 case kGLImplementationDesktopGL:
299 InitializeGLExtensionBindingsGL(context); 338 InitializeDynamicGLBindingsGL(context);
300 InitializeGLExtensionBindingsWGL(context); 339 InitializeDynamicGLBindingsWGL(context);
301 break; 340 break;
302 case kGLImplementationMockGL: 341 case kGLImplementationMockGL:
303 InitializeGLExtensionBindingsGL(context); 342 if (!context) {
343 scoped_refptr<GLContextStubWithExtensions> mock_context(
344 new GLContextStubWithExtensions());
345 mock_context->SetGLVersionString("3.0");
346 InitializeDynamicGLBindingsGL(mock_context.get());
347 } else
348 InitializeDynamicGLBindingsGL(context);
304 break; 349 break;
305 default: 350 default:
306 return false; 351 return false;
307 } 352 }
308 353
309 return true; 354 return true;
310 } 355 }
311 356
312 void InitializeDebugGLBindings() { 357 void InitializeDebugGLBindings() {
313 InitializeDebugGLBindingsEGL(); 358 InitializeDebugGLBindingsEGL();
(...skipping 17 matching lines...) Expand all
331 return GetGLWindowSystemBindingInfoWGL(info); 376 return GetGLWindowSystemBindingInfoWGL(info);
332 case kGLImplementationEGLGLES2: 377 case kGLImplementationEGLGLES2:
333 return GetGLWindowSystemBindingInfoEGL(info); 378 return GetGLWindowSystemBindingInfoEGL(info);
334 default: 379 default:
335 return false; 380 return false;
336 } 381 }
337 return false; 382 return false;
338 } 383 }
339 384
340 } // namespace gfx 385 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gl/gl_implementation_ozone.cc ('k') | ui/gl/gl_implementation_x11.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698