| 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/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/lazy_instance.h" | |
| 13 #include "base/logging.h" | 12 #include "base/logging.h" |
| 14 #include "base/native_library.h" | 13 #include "base/native_library.h" |
| 15 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 16 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 17 #include "base/threading/thread_restrictions.h" | 16 #include "base/threading/thread_restrictions.h" |
| 18 #include "base/trace_event/trace_event.h" | 17 #include "base/trace_event/trace_event.h" |
| 19 #include "base/win/windows_version.h" | 18 #include "base/win/windows_version.h" |
| 20 // TODO(jmadill): Apply to all platforms eventually | |
| 21 #include "ui/gl/angle_platform_impl.h" | |
| 22 #include "ui/gl/gl_bindings.h" | 19 #include "ui/gl/gl_bindings.h" |
| 23 #include "ui/gl/gl_context_stub_with_extensions.h" | 20 #include "ui/gl/gl_context_stub_with_extensions.h" |
| 24 #include "ui/gl/gl_egl_api_implementation.h" | 21 #include "ui/gl/gl_egl_api_implementation.h" |
| 25 #include "ui/gl/gl_gl_api_implementation.h" | 22 #include "ui/gl/gl_gl_api_implementation.h" |
| 26 #include "ui/gl/gl_implementation.h" | 23 #include "ui/gl/gl_implementation.h" |
| 27 #include "ui/gl/gl_osmesa_api_implementation.h" | 24 #include "ui/gl/gl_osmesa_api_implementation.h" |
| 28 #include "ui/gl/gl_surface_wgl.h" | 25 #include "ui/gl/gl_surface_wgl.h" |
| 29 #include "ui/gl/gl_wgl_api_implementation.h" | 26 #include "ui/gl/gl_wgl_api_implementation.h" |
| 30 | 27 |
| 31 #if defined(ENABLE_SWIFTSHADER) | 28 #if defined(ENABLE_SWIFTSHADER) |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 unsigned long long id, | 90 unsigned long long id, |
| 94 int numArgs, | 91 int numArgs, |
| 95 const char** argNames, | 92 const char** argNames, |
| 96 const unsigned char* argTypes, | 93 const unsigned char* argTypes, |
| 97 const unsigned long long* argValues, | 94 const unsigned long long* argValues, |
| 98 unsigned char flags); | 95 unsigned char flags); |
| 99 typedef void (__stdcall *SetTraceFunctionPointersFunc)( | 96 typedef void (__stdcall *SetTraceFunctionPointersFunc)( |
| 100 GetCategoryEnabledFlagFunc get_category_enabled_flag, | 97 GetCategoryEnabledFlagFunc get_category_enabled_flag, |
| 101 AddTraceEventFunc add_trace_event_func); | 98 AddTraceEventFunc add_trace_event_func); |
| 102 | 99 |
| 103 // TODO(jmadill): Apply to all platforms eventually | |
| 104 base::LazyInstance<ANGLEPlatformImpl> g_angle_platform_impl = | |
| 105 LAZY_INSTANCE_INITIALIZER; | |
| 106 | |
| 107 } // namespace | 100 } // namespace |
| 108 | 101 |
| 109 void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) { | 102 void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) { |
| 110 impls->push_back(kGLImplementationEGLGLES2); | 103 impls->push_back(kGLImplementationEGLGLES2); |
| 111 impls->push_back(kGLImplementationDesktopGL); | 104 impls->push_back(kGLImplementationDesktopGL); |
| 112 impls->push_back(kGLImplementationOSMesaGL); | 105 impls->push_back(kGLImplementationOSMesaGL); |
| 113 } | 106 } |
| 114 | 107 |
| 115 bool InitializeStaticGLBindings(GLImplementation implementation) { | 108 bool InitializeStaticGLBindings(GLImplementation implementation) { |
| 116 // Prevent reinitialization with a different implementation. Once the gpu | 109 // Prevent reinitialization with a different implementation. Once the gpu |
| 117 // unit tests have initialized with kGLImplementationMock, we don't want to | 110 // unit tests have initialized with kGLImplementationMock, we don't want to |
| 118 // later switch to another GL implementation. | 111 // later switch to another GL implementation. |
| 119 DCHECK_EQ(kGLImplementationNone, GetGLImplementation()); | 112 DCHECK_EQ(kGLImplementationNone, GetGLImplementation()); |
| 120 | 113 |
| 121 // Init ANGLE platform here, before we call GetPlatformDisplay(). | |
| 122 // TODO(jmadill): Apply to all platforms eventually | |
| 123 angle::Platform::initialize(&g_angle_platform_impl.Get()); | |
| 124 | |
| 125 // Allow the main thread or another to initialize these bindings | 114 // Allow the main thread or another to initialize these bindings |
| 126 // after instituting restrictions on I/O. Going forward they will | 115 // after instituting restrictions on I/O. Going forward they will |
| 127 // likely be used in the browser process on most platforms. The | 116 // likely be used in the browser process on most platforms. The |
| 128 // one-time initialization cost is small, between 2 and 5 ms. | 117 // one-time initialization cost is small, between 2 and 5 ms. |
| 129 base::ThreadRestrictions::ScopedAllowIO allow_io; | 118 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 130 | 119 |
| 131 switch (implementation) { | 120 switch (implementation) { |
| 132 case kGLImplementationOSMesaGL: { | 121 case kGLImplementationOSMesaGL: { |
| 133 base::FilePath module_path; | 122 base::FilePath module_path; |
| 134 if (!PathService::Get(base::DIR_MODULE, &module_path)) { | 123 if (!PathService::Get(base::DIR_MODULE, &module_path)) { |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 } | 341 } |
| 353 | 342 |
| 354 void InitializeDebugGLBindings() { | 343 void InitializeDebugGLBindings() { |
| 355 InitializeDebugGLBindingsEGL(); | 344 InitializeDebugGLBindingsEGL(); |
| 356 InitializeDebugGLBindingsGL(); | 345 InitializeDebugGLBindingsGL(); |
| 357 InitializeDebugGLBindingsOSMESA(); | 346 InitializeDebugGLBindingsOSMESA(); |
| 358 InitializeDebugGLBindingsWGL(); | 347 InitializeDebugGLBindingsWGL(); |
| 359 } | 348 } |
| 360 | 349 |
| 361 void ClearGLBindings() { | 350 void ClearGLBindings() { |
| 362 // TODO(jmadill): Apply to all platforms eventually | |
| 363 angle::Platform::shutdown(); | |
| 364 | |
| 365 ClearGLBindingsEGL(); | 351 ClearGLBindingsEGL(); |
| 366 ClearGLBindingsGL(); | 352 ClearGLBindingsGL(); |
| 367 ClearGLBindingsOSMESA(); | 353 ClearGLBindingsOSMESA(); |
| 368 ClearGLBindingsWGL(); | 354 ClearGLBindingsWGL(); |
| 369 SetGLImplementation(kGLImplementationNone); | 355 SetGLImplementation(kGLImplementationNone); |
| 370 UnloadGLNativeLibraries(); | 356 UnloadGLNativeLibraries(); |
| 371 } | 357 } |
| 372 | 358 |
| 373 bool GetGLWindowSystemBindingInfo(GLWindowSystemBindingInfo* info) { | 359 bool GetGLWindowSystemBindingInfo(GLWindowSystemBindingInfo* info) { |
| 374 switch (GetGLImplementation()) { | 360 switch (GetGLImplementation()) { |
| 375 case kGLImplementationDesktopGL: | 361 case kGLImplementationDesktopGL: |
| 376 return GetGLWindowSystemBindingInfoWGL(info); | 362 return GetGLWindowSystemBindingInfoWGL(info); |
| 377 case kGLImplementationEGLGLES2: | 363 case kGLImplementationEGLGLES2: |
| 378 return GetGLWindowSystemBindingInfoEGL(info); | 364 return GetGLWindowSystemBindingInfoEGL(info); |
| 379 default: | 365 default: |
| 380 return false; | 366 return false; |
| 381 } | 367 } |
| 382 } | 368 } |
| 383 | 369 |
| 384 } // namespace gfx | 370 } // namespace gfx |
| OLD | NEW |