OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/base_paths.h" | 7 #include "base/base_paths.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/lazy_instance.h" | |
11 #include "base/logging.h" | 10 #include "base/logging.h" |
12 #include "base/native_library.h" | 11 #include "base/native_library.h" |
13 #include "base/path_service.h" | 12 #include "base/path_service.h" |
14 #include "base/synchronization/lock.h" | |
15 #include "base/threading/thread_restrictions.h" | 13 #include "base/threading/thread_restrictions.h" |
16 #include "ui/gfx/gl/gl_bindings.h" | 14 #include "ui/gfx/gl/gl_bindings.h" |
17 #include "ui/gfx/gl/gl_implementation.h" | 15 #include "ui/gfx/gl/gl_implementation.h" |
18 | 16 |
19 namespace gfx { | 17 namespace gfx { |
20 namespace { | 18 namespace { |
21 | 19 |
22 // TODO(piman): it should be Desktop GL marshalling from double to float. Today | 20 // TODO(piman): it should be Desktop GL marshalling from double to float. Today |
23 // on native GLES, we do float->double->float. | 21 // on native GLES, we do float->double->float. |
24 void GL_BINDING_CALL MarshalClearDepthToClearDepthf(GLclampd depth) { | 22 void GL_BINDING_CALL MarshalClearDepthToClearDepthf(GLclampd depth) { |
(...skipping 14 matching lines...) Expand all Loading... |
39 VLOG(1) << "Failed to load " << filename.MaybeAsASCII() << ": " << error; | 37 VLOG(1) << "Failed to load " << filename.MaybeAsASCII() << ": " << error; |
40 return NULL; | 38 return NULL; |
41 } | 39 } |
42 return library; | 40 return library; |
43 } | 41 } |
44 | 42 |
45 base::NativeLibrary LoadLibrary(const char* filename) { | 43 base::NativeLibrary LoadLibrary(const char* filename) { |
46 return LoadLibrary(FilePath(filename)); | 44 return LoadLibrary(FilePath(filename)); |
47 } | 45 } |
48 | 46 |
49 // TODO(backer): Find a more principled (less heavy handed) way to prevent a | |
50 // race in the bindings initialization. | |
51 #if (defined(TOOLKIT_VIEWS) && !defined(OS_CHROMEOS)) || defined(TOUCH_UI) | |
52 base::LazyInstance<base::Lock, | |
53 base::LeakyLazyInstanceTraits<base::Lock> > | |
54 g_lock = LAZY_INSTANCE_INITIALIZER; | |
55 #endif | |
56 | |
57 } // namespace anonymous | 47 } // namespace anonymous |
58 | 48 |
59 void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) { | 49 void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) { |
60 impls->push_back(kGLImplementationDesktopGL); | 50 impls->push_back(kGLImplementationDesktopGL); |
61 impls->push_back(kGLImplementationEGLGLES2); | 51 impls->push_back(kGLImplementationEGLGLES2); |
62 impls->push_back(kGLImplementationOSMesaGL); | 52 impls->push_back(kGLImplementationOSMesaGL); |
63 } | 53 } |
64 | 54 |
65 bool InitializeGLBindings(GLImplementation implementation) { | 55 bool InitializeGLBindings(GLImplementation implementation) { |
66 #if (defined(TOOLKIT_VIEWS) && !defined(OS_CHROMEOS)) || defined(TOUCH_UI) | |
67 base::AutoLock locked(g_lock.Get()); | |
68 #endif | |
69 // Prevent reinitialization with a different implementation. Once the gpu | 56 // Prevent reinitialization with a different implementation. Once the gpu |
70 // unit tests have initialized with kGLImplementationMock, we don't want to | 57 // unit tests have initialized with kGLImplementationMock, we don't want to |
71 // later switch to another GL implementation. | 58 // later switch to another GL implementation. |
72 if (GetGLImplementation() != kGLImplementationNone) | 59 if (GetGLImplementation() != kGLImplementationNone) |
73 return true; | 60 return true; |
74 | 61 |
75 // Allow the main thread or another to initialize these bindings | 62 // Allow the main thread or another to initialize these bindings |
76 // after instituting restrictions on I/O. Going forward they will | 63 // after instituting restrictions on I/O. Going forward they will |
77 // likely be used in the browser process on most platforms. The | 64 // likely be used in the browser process on most platforms. The |
78 // one-time initialization cost is small, between 2 and 5 ms. | 65 // one-time initialization cost is small, between 2 and 5 ms. |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 #if !defined(USE_WAYLAND) | 214 #if !defined(USE_WAYLAND) |
228 ClearGLBindingsGLX(); | 215 ClearGLBindingsGLX(); |
229 ClearGLBindingsOSMESA(); | 216 ClearGLBindingsOSMESA(); |
230 #endif | 217 #endif |
231 SetGLImplementation(kGLImplementationNone); | 218 SetGLImplementation(kGLImplementationNone); |
232 | 219 |
233 UnloadGLNativeLibraries(); | 220 UnloadGLNativeLibraries(); |
234 } | 221 } |
235 | 222 |
236 } // namespace gfx | 223 } // namespace gfx |
OLD | NEW |