| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ui/gl/init/gl_initializer.h" | 5 #include "ui/gl/init/gl_initializer.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/threading/thread_restrictions.h" | 10 #include "base/threading/thread_restrictions.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #else | 32 #else |
| 33 const char kGLLibraryName[] = "libGL.so.1"; | 33 const char kGLLibraryName[] = "libGL.so.1"; |
| 34 #endif | 34 #endif |
| 35 | 35 |
| 36 const char kGLESv2LibraryName[] = "libGLESv2.so.2"; | 36 const char kGLESv2LibraryName[] = "libGLESv2.so.2"; |
| 37 const char kEGLLibraryName[] = "libEGL.so.1"; | 37 const char kEGLLibraryName[] = "libEGL.so.1"; |
| 38 | 38 |
| 39 const char kGLESv2ANGLELibraryName[] = "libGLESv2.so"; | 39 const char kGLESv2ANGLELibraryName[] = "libGLESv2.so"; |
| 40 const char kEGLANGLELibraryName[] = "libEGL.so"; | 40 const char kEGLANGLELibraryName[] = "libEGL.so"; |
| 41 | 41 |
| 42 const char kGLESv2SwiftShaderLibraryName[] = "libGLESv2.so"; |
| 43 const char kEGLSwiftShaderLibraryName[] = "libEGL.so"; |
| 44 |
| 42 bool InitializeStaticGLXInternal() { | 45 bool InitializeStaticGLXInternal() { |
| 43 base::NativeLibrary library = NULL; | 46 base::NativeLibrary library = NULL; |
| 44 const base::CommandLine* command_line = | 47 const base::CommandLine* command_line = |
| 45 base::CommandLine::ForCurrentProcess(); | 48 base::CommandLine::ForCurrentProcess(); |
| 46 | 49 |
| 47 if (command_line->HasSwitch(switches::kTestGLLib)) | 50 if (command_line->HasSwitch(switches::kTestGLLib)) |
| 48 library = LoadLibraryAndPrintError( | 51 library = LoadLibraryAndPrintError( |
| 49 command_line->GetSwitchValueASCII(switches::kTestGLLib).c_str()); | 52 command_line->GetSwitchValueASCII(switches::kTestGLLib).c_str()); |
| 50 | 53 |
| 51 if (!library) { | 54 if (!library) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 82 const base::CommandLine* command_line = | 85 const base::CommandLine* command_line = |
| 83 base::CommandLine::ForCurrentProcess(); | 86 base::CommandLine::ForCurrentProcess(); |
| 84 if (command_line->GetSwitchValueASCII(switches::kUseGL) == | 87 if (command_line->GetSwitchValueASCII(switches::kUseGL) == |
| 85 kGLImplementationANGLEName) { | 88 kGLImplementationANGLEName) { |
| 86 base::FilePath module_path; | 89 base::FilePath module_path; |
| 87 if (!PathService::Get(base::DIR_MODULE, &module_path)) | 90 if (!PathService::Get(base::DIR_MODULE, &module_path)) |
| 88 return false; | 91 return false; |
| 89 | 92 |
| 90 glesv2_path = module_path.Append(kGLESv2ANGLELibraryName); | 93 glesv2_path = module_path.Append(kGLESv2ANGLELibraryName); |
| 91 egl_path = module_path.Append(kEGLANGLELibraryName); | 94 egl_path = module_path.Append(kEGLANGLELibraryName); |
| 95 } else if (command_line->GetSwitchValueASCII(switches::kUseGL) == |
| 96 kGLImplementationSwiftShaderName) { |
| 97 base::FilePath module_path; |
| 98 if (!command_line->HasSwitch(switches::kSwiftShaderPath)) |
| 99 return false; |
| 100 module_path = command_line->GetSwitchValuePath(switches::kSwiftShaderPath); |
| 101 |
| 102 glesv2_path = module_path.Append(kGLESv2SwiftShaderLibraryName); |
| 103 egl_path = module_path.Append(kEGLSwiftShaderLibraryName); |
| 92 } | 104 } |
| 93 | 105 |
| 94 base::NativeLibrary gles_library = LoadLibraryAndPrintError(glesv2_path); | 106 base::NativeLibrary gles_library = LoadLibraryAndPrintError(glesv2_path); |
| 95 if (!gles_library) | 107 if (!gles_library) |
| 96 return false; | 108 return false; |
| 97 base::NativeLibrary egl_library = LoadLibraryAndPrintError(egl_path); | 109 base::NativeLibrary egl_library = LoadLibraryAndPrintError(egl_path); |
| 98 if (!egl_library) { | 110 if (!egl_library) { |
| 99 base::UnloadNativeLibrary(gles_library); | 111 base::UnloadNativeLibrary(gles_library); |
| 100 return false; | 112 return false; |
| 101 } | 113 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 LOG(ERROR) << "GLSurfaceGLX::InitializeOneOff failed."; | 148 LOG(ERROR) << "GLSurfaceGLX::InitializeOneOff failed."; |
| 137 return false; | 149 return false; |
| 138 } | 150 } |
| 139 return true; | 151 return true; |
| 140 case kGLImplementationOSMesaGL: | 152 case kGLImplementationOSMesaGL: |
| 141 if (!GLSurfaceOSMesaX11::InitializeOneOff()) { | 153 if (!GLSurfaceOSMesaX11::InitializeOneOff()) { |
| 142 LOG(ERROR) << "GLSurfaceOSMesaX11::InitializeOneOff failed."; | 154 LOG(ERROR) << "GLSurfaceOSMesaX11::InitializeOneOff failed."; |
| 143 return false; | 155 return false; |
| 144 } | 156 } |
| 145 return true; | 157 return true; |
| 158 case kGLImplementationSwiftShaderGL: |
| 146 case kGLImplementationEGLGLES2: | 159 case kGLImplementationEGLGLES2: |
| 147 if (!GLSurfaceEGL::InitializeOneOff(gfx::GetXDisplay())) { | 160 if (!GLSurfaceEGL::InitializeOneOff(gfx::GetXDisplay())) { |
| 148 LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed."; | 161 LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed."; |
| 149 return false; | 162 return false; |
| 150 } | 163 } |
| 151 return true; | 164 return true; |
| 152 default: | 165 default: |
| 153 return true; | 166 return true; |
| 154 } | 167 } |
| 155 } | 168 } |
| 156 | 169 |
| 157 bool InitializeStaticGLBindings(GLImplementation implementation) { | 170 bool InitializeStaticGLBindings(GLImplementation implementation) { |
| 158 // Prevent reinitialization with a different implementation. Once the gpu | 171 // Prevent reinitialization with a different implementation. Once the gpu |
| 159 // unit tests have initialized with kGLImplementationMock, we don't want to | 172 // unit tests have initialized with kGLImplementationMock, we don't want to |
| 160 // later switch to another GL implementation. | 173 // later switch to another GL implementation. |
| 161 DCHECK_EQ(kGLImplementationNone, GetGLImplementation()); | 174 DCHECK_EQ(kGLImplementationNone, GetGLImplementation()); |
| 162 | 175 |
| 163 // Allow the main thread or another to initialize these bindings | 176 // Allow the main thread or another to initialize these bindings |
| 164 // after instituting restrictions on I/O. Going forward they will | 177 // after instituting restrictions on I/O. Going forward they will |
| 165 // likely be used in the browser process on most platforms. The | 178 // likely be used in the browser process on most platforms. The |
| 166 // one-time initialization cost is small, between 2 and 5 ms. | 179 // one-time initialization cost is small, between 2 and 5 ms. |
| 167 base::ThreadRestrictions::ScopedAllowIO allow_io; | 180 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 168 | 181 |
| 169 switch (implementation) { | 182 switch (implementation) { |
| 170 case kGLImplementationOSMesaGL: | 183 case kGLImplementationOSMesaGL: |
| 171 return InitializeStaticGLBindingsOSMesaGL(); | 184 return InitializeStaticGLBindingsOSMesaGL(); |
| 172 case kGLImplementationDesktopGL: | 185 case kGLImplementationDesktopGL: |
| 173 return InitializeStaticGLXInternal(); | 186 return InitializeStaticGLXInternal(); |
| 187 case kGLImplementationSwiftShaderGL: |
| 174 case kGLImplementationEGLGLES2: | 188 case kGLImplementationEGLGLES2: |
| 175 return InitializeStaticEGLInternal(); | 189 return InitializeStaticEGLInternal(); |
| 176 case kGLImplementationMockGL: | 190 case kGLImplementationMockGL: |
| 177 case kGLImplementationStubGL: | 191 case kGLImplementationStubGL: |
| 178 SetGLImplementation(implementation); | 192 SetGLImplementation(implementation); |
| 179 InitializeStaticGLBindingsGL(); | 193 InitializeStaticGLBindingsGL(); |
| 180 return true; | 194 return true; |
| 181 default: | 195 default: |
| 182 NOTREACHED(); | 196 NOTREACHED(); |
| 183 } | 197 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 195 void ShutdownGLPlatform() { | 209 void ShutdownGLPlatform() { |
| 196 GLSurfaceEGL::ShutdownOneOff(); | 210 GLSurfaceEGL::ShutdownOneOff(); |
| 197 ClearBindingsEGL(); | 211 ClearBindingsEGL(); |
| 198 ClearBindingsGL(); | 212 ClearBindingsGL(); |
| 199 ClearBindingsGLX(); | 213 ClearBindingsGLX(); |
| 200 ClearBindingsOSMESA(); | 214 ClearBindingsOSMESA(); |
| 201 } | 215 } |
| 202 | 216 |
| 203 } // namespace init | 217 } // namespace init |
| 204 } // namespace gl | 218 } // namespace gl |
| OLD | NEW |