OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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> |
| 6 |
5 #include "base/base_paths.h" | 7 #include "base/base_paths.h" |
6 #include "base/command_line.h" | 8 #include "base/command_line.h" |
7 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
8 #include "base/logging.h" | 10 #include "base/logging.h" |
9 #include "base/native_library.h" | 11 #include "base/native_library.h" |
10 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/threading/thread_restrictions.h" |
11 #include "ui/gl/gl_bindings.h" | 14 #include "ui/gl/gl_bindings.h" |
12 #include "ui/gl/gl_egl_api_implementation.h" | 15 #include "ui/gl/gl_egl_api_implementation.h" |
13 #include "ui/gl/gl_gl_api_implementation.h" | 16 #include "ui/gl/gl_gl_api_implementation.h" |
14 #include "ui/gl/gl_implementation.h" | 17 #include "ui/gl/gl_implementation.h" |
15 #include "ui/gl/gl_osmesa_api_implementation.h" | 18 #include "ui/gl/gl_switches.h" |
16 | 19 |
17 namespace gfx { | 20 namespace gfx { |
18 | |
19 namespace { | 21 namespace { |
20 | 22 |
| 23 // TODO(piman): it should be Desktop GL marshalling from double to float. Today |
| 24 // on native GLES, we do float->double->float. |
21 void GL_BINDING_CALL MarshalClearDepthToClearDepthf(GLclampd depth) { | 25 void GL_BINDING_CALL MarshalClearDepthToClearDepthf(GLclampd depth) { |
22 glClearDepthf(static_cast<GLclampf>(depth)); | 26 glClearDepthf(static_cast<GLclampf>(depth)); |
23 } | 27 } |
24 | 28 |
25 void GL_BINDING_CALL MarshalDepthRangeToDepthRangef(GLclampd z_near, | 29 void GL_BINDING_CALL MarshalDepthRangeToDepthRangef(GLclampd z_near, |
26 GLclampd z_far) { | 30 GLclampd z_far) { |
27 glDepthRangef(static_cast<GLclampf>(z_near), static_cast<GLclampf>(z_far)); | 31 glDepthRangef(static_cast<GLclampf>(z_near), static_cast<GLclampf>(z_far)); |
28 } | 32 } |
29 | 33 |
| 34 // Load a library, printing an error message on failure. |
30 base::NativeLibrary LoadLibrary(const base::FilePath& filename) { | 35 base::NativeLibrary LoadLibrary(const base::FilePath& filename) { |
31 std::string error; | 36 std::string error; |
32 base::NativeLibrary library = base::LoadNativeLibrary(filename, &error); | 37 base::NativeLibrary library = base::LoadNativeLibrary(filename, |
| 38 &error); |
33 if (!library) { | 39 if (!library) { |
34 DVLOG(1) << "Failed to load " << filename.MaybeAsASCII() << ": " << error; | 40 DVLOG(1) << "Failed to load " << filename.MaybeAsASCII() << ": " << error; |
35 return NULL; | 41 return NULL; |
36 } | 42 } |
37 return library; | 43 return library; |
38 } | 44 } |
39 | 45 |
40 base::NativeLibrary LoadLibrary(const char* filename) { | 46 base::NativeLibrary LoadLibrary(const char* filename) { |
41 return LoadLibrary(base::FilePath(filename)); | 47 return LoadLibrary(base::FilePath(filename)); |
42 } | 48 } |
43 | 49 |
44 } // namespace | 50 } // namespace |
45 | 51 |
46 void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) { | 52 void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) { |
47 impls->push_back(kGLImplementationEGLGLES2); | 53 impls->push_back(kGLImplementationEGLGLES2); |
48 } | 54 } |
49 | 55 |
50 bool InitializeGLBindings(GLImplementation implementation) { | 56 bool InitializeGLBindings(GLImplementation implementation) { |
51 // Prevent reinitialization with a different implementation. Once the gpu | 57 // Prevent reinitialization with a different implementation. Once the gpu |
52 // unit tests have initialized with kGLImplementationMock, we don't want to | 58 // unit tests have initialized with kGLImplementationMock, we don't want to |
53 // later switch to another GL implementation. | 59 // later switch to another GL implementation. |
54 if (GetGLImplementation() != kGLImplementationNone) | 60 if (GetGLImplementation() != kGLImplementationNone) |
55 return true; | 61 return true; |
56 | 62 |
| 63 // Allow the main thread or another to initialize these bindings |
| 64 // after instituting restrictions on I/O. Going forward they will |
| 65 // likely be used in the browser process on most platforms. The |
| 66 // one-time initialization cost is small, between 2 and 5 ms. |
| 67 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 68 |
57 switch (implementation) { | 69 switch (implementation) { |
58 case kGLImplementationEGLGLES2: { | 70 case kGLImplementationEGLGLES2: { |
59 base::NativeLibrary gles_library = LoadLibrary("libGLESv2.so"); | 71 base::NativeLibrary gles_library = LoadLibrary("libGLESv2.so.2"); |
60 if (!gles_library) | 72 if (!gles_library) |
61 return false; | 73 return false; |
62 base::NativeLibrary egl_library = LoadLibrary("libEGL.so"); | 74 base::NativeLibrary egl_library = LoadLibrary("libEGL.so.1"); |
63 if (!egl_library) { | 75 if (!egl_library) { |
64 base::UnloadNativeLibrary(gles_library); | 76 base::UnloadNativeLibrary(gles_library); |
65 return false; | 77 return false; |
66 } | 78 } |
67 | 79 |
68 GLGetProcAddressProc get_proc_address = | 80 GLGetProcAddressProc get_proc_address = |
69 reinterpret_cast<GLGetProcAddressProc>( | 81 reinterpret_cast<GLGetProcAddressProc>( |
70 base::GetFunctionPointerFromNativeLibrary( | 82 base::GetFunctionPointerFromNativeLibrary( |
71 egl_library, "eglGetProcAddress")); | 83 egl_library, "eglGetProcAddress")); |
72 if (!get_proc_address) { | 84 if (!get_proc_address) { |
(...skipping 17 matching lines...) Expand all Loading... |
90 ::gfx::g_driver_gl.fn.glDepthRangeFn = MarshalDepthRangeToDepthRangef; | 102 ::gfx::g_driver_gl.fn.glDepthRangeFn = MarshalDepthRangeToDepthRangef; |
91 break; | 103 break; |
92 } | 104 } |
93 case kGLImplementationMockGL: { | 105 case kGLImplementationMockGL: { |
94 SetGLGetProcAddressProc(GetMockGLProcAddress); | 106 SetGLGetProcAddressProc(GetMockGLProcAddress); |
95 SetGLImplementation(kGLImplementationMockGL); | 107 SetGLImplementation(kGLImplementationMockGL); |
96 InitializeGLBindingsGL(); | 108 InitializeGLBindingsGL(); |
97 break; | 109 break; |
98 } | 110 } |
99 default: | 111 default: |
100 NOTIMPLEMENTED() << "InitializeGLBindings on Android"; | |
101 return false; | 112 return false; |
102 } | 113 } |
103 | 114 |
| 115 |
104 return true; | 116 return true; |
105 } | 117 } |
106 | 118 |
107 bool InitializeGLExtensionBindings(GLImplementation implementation, | 119 bool InitializeGLExtensionBindings(GLImplementation implementation, |
108 GLContext* context) { | 120 GLContext* context) { |
109 switch (implementation) { | 121 switch (implementation) { |
110 case kGLImplementationEGLGLES2: | 122 case kGLImplementationEGLGLES2: |
111 InitializeGLExtensionBindingsGL(context); | 123 InitializeGLExtensionBindingsGL(context); |
112 InitializeGLExtensionBindingsEGL(context); | 124 InitializeGLExtensionBindingsEGL(context); |
113 break; | 125 break; |
114 case kGLImplementationMockGL: | 126 case kGLImplementationMockGL: |
115 InitializeGLExtensionBindingsGL(context); | 127 InitializeGLExtensionBindingsGL(context); |
116 break; | 128 break; |
117 default: | 129 default: |
118 return false; | 130 return false; |
119 } | 131 } |
120 | 132 |
121 return true; | 133 return true; |
122 } | 134 } |
123 | 135 |
124 void InitializeDebugGLBindings() { | 136 void InitializeDebugGLBindings() { |
| 137 InitializeDebugGLBindingsEGL(); |
| 138 InitializeDebugGLBindingsGL(); |
125 } | 139 } |
126 | 140 |
127 void ClearGLBindings() { | 141 void ClearGLBindings() { |
128 ClearGLBindingsEGL(); | 142 ClearGLBindingsEGL(); |
129 ClearGLBindingsGL(); | 143 ClearGLBindingsGL(); |
130 SetGLImplementation(kGLImplementationNone); | 144 SetGLImplementation(kGLImplementationNone); |
131 | 145 |
132 UnloadGLNativeLibraries(); | 146 UnloadGLNativeLibraries(); |
133 } | 147 } |
134 | 148 |
135 bool GetGLWindowSystemBindingInfo(GLWindowSystemBindingInfo* info) { | 149 bool GetGLWindowSystemBindingInfo(GLWindowSystemBindingInfo* info) { |
136 switch (GetGLImplementation()) { | 150 switch (GetGLImplementation()) { |
137 case kGLImplementationEGLGLES2: | 151 case kGLImplementationEGLGLES2: |
138 return GetGLWindowSystemBindingInfoEGL(info); | 152 return GetGLWindowSystemBindingInfoEGL(info); |
139 default: | 153 default: |
140 return false; | 154 return false; |
141 } | 155 } |
142 return false; | 156 return false; |
143 } | 157 } |
144 | 158 |
145 } // namespace gfx | 159 } // namespace gfx |
OLD | NEW |