OLD | NEW |
---|---|
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_mock_version.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" |
24 #include "ui/gl/gl_wgl_api_implementation.h" | 25 #include "ui/gl/gl_wgl_api_implementation.h" |
25 | 26 |
26 #if defined(ENABLE_SWIFTSHADER) | 27 #if defined(ENABLE_SWIFTSHADER) |
27 #include "software_renderer.h" | 28 #include "software_renderer.h" |
28 #endif | 29 #endif |
29 | 30 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
99 AddTraceEventFunc add_trace_event_func); | 100 AddTraceEventFunc add_trace_event_func); |
100 | 101 |
101 } // namespace | 102 } // namespace |
102 | 103 |
103 void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) { | 104 void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) { |
104 impls->push_back(kGLImplementationEGLGLES2); | 105 impls->push_back(kGLImplementationEGLGLES2); |
105 impls->push_back(kGLImplementationDesktopGL); | 106 impls->push_back(kGLImplementationDesktopGL); |
106 impls->push_back(kGLImplementationOSMesaGL); | 107 impls->push_back(kGLImplementationOSMesaGL); |
107 } | 108 } |
108 | 109 |
109 bool InitializeGLBindings(GLImplementation implementation) { | 110 bool InitializeStaticGLBindings(GLImplementation implementation) { |
110 // Prevent reinitialization with a different implementation. Once the gpu | 111 // Prevent reinitialization with a different implementation. Once the gpu |
111 // unit tests have initialized with kGLImplementationMock, we don't want to | 112 // unit tests have initialized with kGLImplementationMock, we don't want to |
112 // later switch to another GL implementation. | 113 // later switch to another GL implementation. |
113 if (GetGLImplementation() != kGLImplementationNone) | 114 if (GetGLImplementation() != kGLImplementationNone) |
114 return true; | 115 return true; |
115 | 116 |
116 // Allow the main thread or another to initialize these bindings | 117 // Allow the main thread or another to initialize these bindings |
117 // after instituting restrictions on I/O. Going forward they will | 118 // after instituting restrictions on I/O. Going forward they will |
118 // likely be used in the browser process on most platforms. The | 119 // likely be used in the browser process on most platforms. The |
119 // one-time initialization cost is small, between 2 and 5 ms. | 120 // one-time initialization cost is small, between 2 and 5 ms. |
(...skipping 21 matching lines...) Expand all Loading... | |
141 if (!get_proc_address) { | 142 if (!get_proc_address) { |
142 DLOG(ERROR) << "OSMesaGetProcAddress not found."; | 143 DLOG(ERROR) << "OSMesaGetProcAddress not found."; |
143 base::UnloadNativeLibrary(library); | 144 base::UnloadNativeLibrary(library); |
144 return false; | 145 return false; |
145 } | 146 } |
146 | 147 |
147 SetGLGetProcAddressProc(get_proc_address); | 148 SetGLGetProcAddressProc(get_proc_address); |
148 AddGLNativeLibrary(library); | 149 AddGLNativeLibrary(library); |
149 SetGLImplementation(kGLImplementationOSMesaGL); | 150 SetGLImplementation(kGLImplementationOSMesaGL); |
150 | 151 |
151 InitializeGLBindingsGL(); | 152 InitializeStaticGLBindingsGL(); |
152 InitializeGLBindingsOSMESA(); | 153 InitializeStaticGLBindingsOSMESA(); |
153 break; | 154 break; |
154 } | 155 } |
155 case kGLImplementationEGLGLES2: { | 156 case kGLImplementationEGLGLES2: { |
156 base::FilePath module_path; | 157 base::FilePath module_path; |
157 if (!PathService::Get(base::DIR_MODULE, &module_path)) | 158 if (!PathService::Get(base::DIR_MODULE, &module_path)) |
158 return false; | 159 return false; |
159 | 160 |
160 // Attempt to load the D3DX shader compiler using the default search path | 161 // 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 | 162 // 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 | 163 // 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 Loading... | |
227 base::UnloadNativeLibrary(egl_library); | 228 base::UnloadNativeLibrary(egl_library); |
228 base::UnloadNativeLibrary(gles_library); | 229 base::UnloadNativeLibrary(gles_library); |
229 return false; | 230 return false; |
230 } | 231 } |
231 | 232 |
232 SetGLGetProcAddressProc(get_proc_address); | 233 SetGLGetProcAddressProc(get_proc_address); |
233 AddGLNativeLibrary(egl_library); | 234 AddGLNativeLibrary(egl_library); |
234 AddGLNativeLibrary(gles_library); | 235 AddGLNativeLibrary(gles_library); |
235 SetGLImplementation(kGLImplementationEGLGLES2); | 236 SetGLImplementation(kGLImplementationEGLGLES2); |
236 | 237 |
237 InitializeGLBindingsGL(); | 238 InitializeStaticGLBindingsGL(); |
238 InitializeGLBindingsEGL(); | 239 InitializeStaticGLBindingsEGL(); |
239 | 240 |
240 // These two functions take single precision float rather than double | 241 // These two functions take single precision float rather than double |
241 // precision float parameters in GLES. | 242 // precision float parameters in GLES. |
242 ::gfx::g_driver_gl.fn.glClearDepthFn = MarshalClearDepthToClearDepthf; | 243 ::gfx::g_driver_gl.fn.glClearDepthFn = MarshalClearDepthToClearDepthf; |
243 ::gfx::g_driver_gl.fn.glDepthRangeFn = MarshalDepthRangeToDepthRangef; | 244 ::gfx::g_driver_gl.fn.glDepthRangeFn = MarshalDepthRangeToDepthRangef; |
244 break; | 245 break; |
245 } | 246 } |
246 case kGLImplementationDesktopGL: { | 247 case kGLImplementationDesktopGL: { |
247 // When using Windows OpenGL, first try wglGetProcAddress and then | 248 // When using Windows OpenGL, first try wglGetProcAddress and then |
248 // Windows GetProcAddress. | 249 // Windows GetProcAddress. |
no sievers
2013/12/05 20:51:57
This comment doesn't seem right. Fore both core an
oetuaho
2013/12/09 17:17:07
Yep, I'll just remove the comment, it has no reaso
| |
249 base::NativeLibrary library = base::LoadNativeLibrary( | 250 base::NativeLibrary library = base::LoadNativeLibrary( |
250 base::FilePath(L"opengl32.dll"), NULL); | 251 base::FilePath(L"opengl32.dll"), NULL); |
251 if (!library) { | 252 if (!library) { |
252 DVLOG(1) << "opengl32.dll not found"; | 253 DVLOG(1) << "opengl32.dll not found"; |
253 return false; | 254 return false; |
254 } | 255 } |
255 | 256 |
256 GLGetProcAddressProc get_proc_address = | 257 GLGetProcAddressProc get_proc_address = |
257 reinterpret_cast<GLGetProcAddressProc>( | 258 reinterpret_cast<GLGetProcAddressProc>( |
258 base::GetFunctionPointerFromNativeLibrary( | 259 base::GetFunctionPointerFromNativeLibrary( |
259 library, "wglGetProcAddress")); | 260 library, "wglGetProcAddress")); |
260 if (!get_proc_address) { | 261 if (!get_proc_address) { |
261 LOG(ERROR) << "wglGetProcAddress not found."; | 262 LOG(ERROR) << "wglGetProcAddress not found."; |
262 base::UnloadNativeLibrary(library); | 263 base::UnloadNativeLibrary(library); |
263 return false; | 264 return false; |
264 } | 265 } |
265 | 266 |
266 SetGLGetProcAddressProc(get_proc_address); | 267 SetGLGetProcAddressProc(get_proc_address); |
267 AddGLNativeLibrary(library); | 268 AddGLNativeLibrary(library); |
268 SetGLImplementation(kGLImplementationDesktopGL); | 269 SetGLImplementation(kGLImplementationDesktopGL); |
269 | 270 |
270 InitializeGLBindingsGL(); | 271 InitializeStaticGLBindingsGL(); |
271 InitializeGLBindingsWGL(); | 272 InitializeStaticGLBindingsWGL(); |
272 break; | 273 break; |
273 } | 274 } |
274 case kGLImplementationMockGL: { | 275 case kGLImplementationMockGL: { |
275 SetGLGetProcAddressProc(GetMockGLProcAddress); | 276 SetGLGetProcAddressProc(GetMockGLProcAddress); |
276 SetGLImplementation(kGLImplementationMockGL); | 277 SetGLImplementation(kGLImplementationMockGL); |
277 InitializeGLBindingsGL(); | 278 InitializeStaticGLBindingsGL(); |
278 break; | 279 break; |
279 } | 280 } |
280 default: | 281 default: |
281 return false; | 282 return false; |
282 } | 283 } |
283 | 284 |
284 return true; | 285 return true; |
285 } | 286 } |
286 | 287 |
287 bool InitializeGLExtensionBindings(GLImplementation implementation, | 288 bool InitializeDynamicGLBindings(GLImplementation implementation, |
288 GLContext* context) { | 289 GLContext* context) { |
289 switch (implementation) { | 290 switch (implementation) { |
290 case kGLImplementationOSMesaGL: | 291 case kGLImplementationOSMesaGL: |
291 InitializeGLExtensionBindingsGL(context); | 292 InitializeDynamicGLBindingsGL(context); |
292 InitializeGLExtensionBindingsOSMESA(context); | 293 InitializeDynamicGLBindingsOSMESA(context); |
293 break; | 294 break; |
294 case kGLImplementationEGLGLES2: | 295 case kGLImplementationEGLGLES2: |
295 InitializeGLExtensionBindingsGL(context); | 296 InitializeDynamicGLBindingsGL(context); |
296 InitializeGLExtensionBindingsEGL(context); | 297 InitializeDynamicGLBindingsEGL(context); |
297 break; | 298 break; |
298 case kGLImplementationDesktopGL: | 299 case kGLImplementationDesktopGL: |
299 InitializeGLExtensionBindingsGL(context); | 300 InitializeDynamicGLBindingsGL(context); |
300 InitializeGLExtensionBindingsWGL(context); | 301 InitializeDynamicGLBindingsWGL(context); |
301 break; | 302 break; |
302 case kGLImplementationMockGL: | 303 case kGLImplementationMockGL: |
303 InitializeGLExtensionBindingsGL(context); | 304 { |
305 scoped_refptr<GLContextMockVersion> mock_context( | |
306 new GLContextMockVersion("3.0")); | |
307 InitializeDynamicGLBindingsGL(mock_context.get()); | |
308 } | |
304 break; | 309 break; |
305 default: | 310 default: |
306 return false; | 311 return false; |
307 } | 312 } |
308 | 313 |
309 return true; | 314 return true; |
310 } | 315 } |
311 | 316 |
312 void InitializeDebugGLBindings() { | 317 void InitializeDebugGLBindings() { |
313 InitializeDebugGLBindingsEGL(); | 318 InitializeDebugGLBindingsEGL(); |
(...skipping 17 matching lines...) Expand all Loading... | |
331 return GetGLWindowSystemBindingInfoWGL(info); | 336 return GetGLWindowSystemBindingInfoWGL(info); |
332 case kGLImplementationEGLGLES2: | 337 case kGLImplementationEGLGLES2: |
333 return GetGLWindowSystemBindingInfoEGL(info); | 338 return GetGLWindowSystemBindingInfoEGL(info); |
334 default: | 339 default: |
335 return false; | 340 return false; |
336 } | 341 } |
337 return false; | 342 return false; |
338 } | 343 } |
339 | 344 |
340 } // namespace gfx | 345 } // namespace gfx |
OLD | NEW |