Chromium Code Reviews| 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_factory.h" | 5 #include "ui/gl/init/gl_factory.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 | 22 |
| 23 DCHECK_EQ(kGLImplementationNone, GetGLImplementation()); | 23 DCHECK_EQ(kGLImplementationNone, GetGLImplementation()); |
| 24 | 24 |
| 25 std::vector<GLImplementation> allowed_impls = GetAllowedGLImplementations(); | 25 std::vector<GLImplementation> allowed_impls = GetAllowedGLImplementations(); |
| 26 DCHECK(!allowed_impls.empty()); | 26 DCHECK(!allowed_impls.empty()); |
| 27 | 27 |
| 28 base::CommandLine* cmd = base::CommandLine::ForCurrentProcess(); | 28 base::CommandLine* cmd = base::CommandLine::ForCurrentProcess(); |
| 29 | 29 |
| 30 // The default implementation is always the first one in list. | 30 // The default implementation is always the first one in list. |
| 31 GLImplementation impl = allowed_impls[0]; | 31 GLImplementation impl = allowed_impls[0]; |
| 32 bool fallback_to_osmesa = false; | 32 bool fallback_to_software_rendering = false; |
|
Ken Russell (switch to Gerrit)
2017/02/15 02:32:15
Could you call this fallback_to_software_gl?
| |
| 33 if (cmd->HasSwitch(switches::kOverrideUseGLWithOSMesaForTests)) { | 33 if (cmd->HasSwitch(switches::kOverrideUseSoftwareGLForTests)) { |
| 34 impl = kGLImplementationOSMesaGL; | 34 impl = GetSoftwareGLImplementation(); |
| 35 } else if (cmd->HasSwitch(switches::kUseGL)) { | 35 } else if (cmd->HasSwitch(switches::kUseGL)) { |
| 36 std::string requested_implementation_name = | 36 std::string requested_implementation_name = |
| 37 cmd->GetSwitchValueASCII(switches::kUseGL); | 37 cmd->GetSwitchValueASCII(switches::kUseGL); |
| 38 if (requested_implementation_name == "any") { | 38 if (requested_implementation_name == "any") { |
| 39 fallback_to_osmesa = true; | 39 fallback_to_software_rendering = true; |
| 40 } else if (requested_implementation_name == | 40 } else if (requested_implementation_name == |
| 41 kGLImplementationSwiftShaderName) { | 41 kGLImplementationSwiftShaderName) { |
| 42 impl = kGLImplementationSwiftShaderGL; | 42 impl = kGLImplementationSwiftShaderGL; |
| 43 } else if (requested_implementation_name == | 43 } else if (requested_implementation_name == |
| 44 kGLImplementationSwiftShaderForWebGLName || | 44 kGLImplementationSwiftShaderForWebGLName || |
| 45 requested_implementation_name == kGLImplementationANGLEName) { | 45 requested_implementation_name == kGLImplementationANGLEName) { |
| 46 impl = kGLImplementationEGLGLES2; | 46 impl = kGLImplementationEGLGLES2; |
| 47 } else { | 47 } else { |
| 48 impl = GetNamedGLImplementation(requested_implementation_name); | 48 impl = GetNamedGLImplementation(requested_implementation_name); |
| 49 if (!base::ContainsValue(allowed_impls, impl)) { | 49 if (!base::ContainsValue(allowed_impls, impl)) { |
| 50 LOG(ERROR) << "Requested GL implementation is not available."; | 50 LOG(ERROR) << "Requested GL implementation is not available."; |
| 51 return false; | 51 return false; |
| 52 } | 52 } |
| 53 } | 53 } |
| 54 } | 54 } |
| 55 | 55 |
| 56 bool gpu_service_logging = cmd->HasSwitch(switches::kEnableGPUServiceLogging); | 56 bool gpu_service_logging = cmd->HasSwitch(switches::kEnableGPUServiceLogging); |
| 57 bool disable_gl_drawing = cmd->HasSwitch(switches::kDisableGLDrawingForTests); | 57 bool disable_gl_drawing = cmd->HasSwitch(switches::kDisableGLDrawingForTests); |
| 58 | 58 |
| 59 return InitializeGLOneOffImplementation( | 59 return InitializeGLOneOffImplementation(impl, fallback_to_software_rendering, |
| 60 impl, fallback_to_osmesa, gpu_service_logging, disable_gl_drawing); | 60 gpu_service_logging, |
| 61 disable_gl_drawing); | |
| 61 } | 62 } |
| 62 | 63 |
| 63 bool InitializeGLOneOffImplementation(GLImplementation impl, | 64 bool InitializeGLOneOffImplementation(GLImplementation impl, |
| 64 bool fallback_to_osmesa, | 65 bool fallback_to_software_rendering, |
| 65 bool gpu_service_logging, | 66 bool gpu_service_logging, |
| 66 bool disable_gl_drawing) { | 67 bool disable_gl_drawing) { |
| 67 bool initialized = | 68 bool initialized = |
| 68 InitializeStaticGLBindings(impl) && InitializeGLOneOffPlatform(); | 69 InitializeStaticGLBindings(impl) && InitializeGLOneOffPlatform(); |
| 69 if (!initialized && fallback_to_osmesa) { | 70 if (!initialized && fallback_to_software_rendering) { |
| 70 ShutdownGL(); | 71 ShutdownGL(); |
| 71 initialized = InitializeStaticGLBindings(kGLImplementationOSMesaGL) && | 72 initialized = InitializeStaticGLBindings(GetSoftwareGLImplementation()) && |
| 72 InitializeGLOneOffPlatform(); | 73 InitializeGLOneOffPlatform(); |
| 73 } | 74 } |
| 74 if (!initialized) | 75 if (!initialized) |
| 75 ShutdownGL(); | 76 ShutdownGL(); |
| 76 | 77 |
| 77 if (initialized) { | 78 if (initialized) { |
| 78 DVLOG(1) << "Using " << GetGLImplementationName(GetGLImplementation()) | 79 DVLOG(1) << "Using " << GetGLImplementationName(GetGLImplementation()) |
| 79 << " GL implementation."; | 80 << " GL implementation."; |
| 80 if (gpu_service_logging) | 81 if (gpu_service_logging) |
| 81 InitializeDebugGLBindings(); | 82 InitializeDebugGLBindings(); |
| 82 if (disable_gl_drawing) | 83 if (disable_gl_drawing) |
| 83 InitializeNullDrawGLBindings(); | 84 InitializeNullDrawGLBindings(); |
| 84 } | 85 } |
| 85 return initialized; | 86 return initialized; |
| 86 } | 87 } |
| 87 | 88 |
| 88 void ShutdownGL() { | 89 void ShutdownGL() { |
| 89 ShutdownGLPlatform(); | 90 ShutdownGLPlatform(); |
| 90 | 91 |
| 91 SetGLImplementation(kGLImplementationNone); | 92 SetGLImplementation(kGLImplementationNone); |
| 92 UnloadGLNativeLibraries(); | 93 UnloadGLNativeLibraries(); |
| 93 } | 94 } |
| 94 | 95 |
| 95 scoped_refptr<GLSurface> CreateOffscreenGLSurface(const gfx::Size& size) { | 96 scoped_refptr<GLSurface> CreateOffscreenGLSurface(const gfx::Size& size) { |
| 96 return CreateOffscreenGLSurfaceWithFormat(size, GLSurfaceFormat()); | 97 return CreateOffscreenGLSurfaceWithFormat(size, GLSurfaceFormat()); |
| 97 } | 98 } |
| 98 | 99 |
| 99 } // namespace init | 100 } // namespace init |
| 100 } // namespace gl | 101 } // namespace gl |
| OLD | NEW |