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