| 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/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/logging.h" | 10 #include "base/logging.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 return library; | 41 return library; |
| 42 } | 42 } |
| 43 | 43 |
| 44 base::NativeLibrary LoadLibrary(const char* filename) { | 44 base::NativeLibrary LoadLibrary(const char* filename) { |
| 45 return LoadLibrary(FilePath(filename)); | 45 return LoadLibrary(FilePath(filename)); |
| 46 } | 46 } |
| 47 | 47 |
| 48 } // namespace anonymous | 48 } // namespace anonymous |
| 49 | 49 |
| 50 void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) { | 50 void GetAllowedGLImplementations(std::vector<GLImplementation>* impls) { |
| 51 #if !defined(USE_WAYLAND) | |
| 52 impls->push_back(kGLImplementationDesktopGL); | 51 impls->push_back(kGLImplementationDesktopGL); |
| 53 #endif | |
| 54 impls->push_back(kGLImplementationEGLGLES2); | 52 impls->push_back(kGLImplementationEGLGLES2); |
| 55 #if !defined(USE_WAYLAND) | |
| 56 impls->push_back(kGLImplementationOSMesaGL); | 53 impls->push_back(kGLImplementationOSMesaGL); |
| 57 #endif | |
| 58 } | 54 } |
| 59 | 55 |
| 60 bool InitializeGLBindings(GLImplementation implementation) { | 56 bool InitializeGLBindings(GLImplementation implementation) { |
| 61 // Prevent reinitialization with a different implementation. Once the gpu | 57 // Prevent reinitialization with a different implementation. Once the gpu |
| 62 // unit tests have initialized with kGLImplementationMock, we don't want to | 58 // unit tests have initialized with kGLImplementationMock, we don't want to |
| 63 // later switch to another GL implementation. | 59 // later switch to another GL implementation. |
| 64 if (GetGLImplementation() != kGLImplementationNone) | 60 if (GetGLImplementation() != kGLImplementationNone) |
| 65 return true; | 61 return true; |
| 66 | 62 |
| 67 // Allow the main thread or another to initialize these bindings | 63 // Allow the main thread or another to initialize these bindings |
| 68 // after instituting restrictions on I/O. Going forward they will | 64 // after instituting restrictions on I/O. Going forward they will |
| 69 // likely be used in the browser process on most platforms. The | 65 // likely be used in the browser process on most platforms. The |
| 70 // one-time initialization cost is small, between 2 and 5 ms. | 66 // one-time initialization cost is small, between 2 and 5 ms. |
| 71 base::ThreadRestrictions::ScopedAllowIO allow_io; | 67 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 72 | 68 |
| 73 switch (implementation) { | 69 switch (implementation) { |
| 74 #if !defined(USE_WAYLAND) | |
| 75 case kGLImplementationOSMesaGL: { | 70 case kGLImplementationOSMesaGL: { |
| 76 FilePath module_path; | 71 FilePath module_path; |
| 77 if (!PathService::Get(base::DIR_MODULE, &module_path)) { | 72 if (!PathService::Get(base::DIR_MODULE, &module_path)) { |
| 78 LOG(ERROR) << "PathService::Get failed."; | 73 LOG(ERROR) << "PathService::Get failed."; |
| 79 return false; | 74 return false; |
| 80 } | 75 } |
| 81 | 76 |
| 82 base::NativeLibrary library = LoadLibrary( | 77 base::NativeLibrary library = LoadLibrary( |
| 83 module_path.Append("libosmesa.so")); | 78 module_path.Append("libosmesa.so")); |
| 84 if (!library) | 79 if (!library) |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 } | 127 } |
| 133 | 128 |
| 134 SetGLGetProcAddressProc(get_proc_address); | 129 SetGLGetProcAddressProc(get_proc_address); |
| 135 AddGLNativeLibrary(library); | 130 AddGLNativeLibrary(library); |
| 136 SetGLImplementation(kGLImplementationDesktopGL); | 131 SetGLImplementation(kGLImplementationDesktopGL); |
| 137 | 132 |
| 138 InitializeGLBindingsGL(); | 133 InitializeGLBindingsGL(); |
| 139 InitializeGLBindingsGLX(); | 134 InitializeGLBindingsGLX(); |
| 140 break; | 135 break; |
| 141 } | 136 } |
| 142 #endif // !defined(USE_WAYLAND) | |
| 143 case kGLImplementationEGLGLES2: { | 137 case kGLImplementationEGLGLES2: { |
| 144 base::NativeLibrary gles_library = LoadLibrary("libGLESv2.so.2"); | 138 base::NativeLibrary gles_library = LoadLibrary("libGLESv2.so.2"); |
| 145 if (!gles_library) | 139 if (!gles_library) |
| 146 return false; | 140 return false; |
| 147 base::NativeLibrary egl_library = LoadLibrary("libEGL.so.1"); | 141 base::NativeLibrary egl_library = LoadLibrary("libEGL.so.1"); |
| 148 if (!egl_library) { | 142 if (!egl_library) { |
| 149 base::UnloadNativeLibrary(gles_library); | 143 base::UnloadNativeLibrary(gles_library); |
| 150 return false; | 144 return false; |
| 151 } | 145 } |
| 152 | 146 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 return false; | 179 return false; |
| 186 } | 180 } |
| 187 | 181 |
| 188 | 182 |
| 189 return true; | 183 return true; |
| 190 } | 184 } |
| 191 | 185 |
| 192 bool InitializeGLExtensionBindings(GLImplementation implementation, | 186 bool InitializeGLExtensionBindings(GLImplementation implementation, |
| 193 GLContext* context) { | 187 GLContext* context) { |
| 194 switch (implementation) { | 188 switch (implementation) { |
| 195 #if !defined(USE_WAYLAND) | |
| 196 case kGLImplementationOSMesaGL: | 189 case kGLImplementationOSMesaGL: |
| 197 InitializeGLExtensionBindingsGL(context); | 190 InitializeGLExtensionBindingsGL(context); |
| 198 InitializeGLExtensionBindingsOSMESA(context); | 191 InitializeGLExtensionBindingsOSMESA(context); |
| 199 break; | 192 break; |
| 200 case kGLImplementationDesktopGL: | 193 case kGLImplementationDesktopGL: |
| 201 InitializeGLExtensionBindingsGL(context); | 194 InitializeGLExtensionBindingsGL(context); |
| 202 InitializeGLExtensionBindingsGLX(context); | 195 InitializeGLExtensionBindingsGLX(context); |
| 203 break; | 196 break; |
| 204 #endif | |
| 205 case kGLImplementationEGLGLES2: | 197 case kGLImplementationEGLGLES2: |
| 206 InitializeGLExtensionBindingsGL(context); | 198 InitializeGLExtensionBindingsGL(context); |
| 207 InitializeGLExtensionBindingsEGL(context); | 199 InitializeGLExtensionBindingsEGL(context); |
| 208 break; | 200 break; |
| 209 case kGLImplementationMockGL: | 201 case kGLImplementationMockGL: |
| 210 InitializeGLExtensionBindingsGL(context); | 202 InitializeGLExtensionBindingsGL(context); |
| 211 break; | 203 break; |
| 212 default: | 204 default: |
| 213 return false; | 205 return false; |
| 214 } | 206 } |
| 215 | 207 |
| 216 return true; | 208 return true; |
| 217 } | 209 } |
| 218 | 210 |
| 219 void InitializeDebugGLBindings() { | 211 void InitializeDebugGLBindings() { |
| 220 InitializeDebugGLBindingsEGL(); | 212 InitializeDebugGLBindingsEGL(); |
| 221 InitializeDebugGLBindingsGL(); | 213 InitializeDebugGLBindingsGL(); |
| 222 #if !defined(USE_WAYLAND) | |
| 223 InitializeDebugGLBindingsGLX(); | 214 InitializeDebugGLBindingsGLX(); |
| 224 InitializeDebugGLBindingsOSMESA(); | 215 InitializeDebugGLBindingsOSMESA(); |
| 225 #endif | |
| 226 } | 216 } |
| 227 | 217 |
| 228 void ClearGLBindings() { | 218 void ClearGLBindings() { |
| 229 ClearGLBindingsEGL(); | 219 ClearGLBindingsEGL(); |
| 230 ClearGLBindingsGL(); | 220 ClearGLBindingsGL(); |
| 231 #if !defined(USE_WAYLAND) | |
| 232 ClearGLBindingsGLX(); | 221 ClearGLBindingsGLX(); |
| 233 ClearGLBindingsOSMESA(); | 222 ClearGLBindingsOSMESA(); |
| 234 #endif | |
| 235 SetGLImplementation(kGLImplementationNone); | 223 SetGLImplementation(kGLImplementationNone); |
| 236 | 224 |
| 237 UnloadGLNativeLibraries(); | 225 UnloadGLNativeLibraries(); |
| 238 } | 226 } |
| 239 | 227 |
| 240 } // namespace gfx | 228 } // namespace gfx |
| OLD | NEW |