Index: ui/gl/gl_implementation.cc |
diff --git a/ui/gl/gl_implementation.cc b/ui/gl/gl_implementation.cc |
index c0c531746e5852ba9d6ec670dd3b0ba033213ed6..1d808b5346630d5e06537df0b5bfa55c97a9aa66 100644 |
--- a/ui/gl/gl_implementation.cc |
+++ b/ui/gl/gl_implementation.cc |
@@ -13,6 +13,7 @@ |
#include "base/command_line.h" |
#include "base/logging.h" |
#include "base/macros.h" |
+#include "base/stl_util.h" |
#include "base/strings/string_split.h" |
#include "base/strings/string_util.h" |
#include "build/build_config.h" |
@@ -96,6 +97,44 @@ GLImplementation GetGLImplementation() { |
return g_gl_implementation; |
} |
+bool SelectGLImplementation(const std::vector<GLImplementation>& allowed_impls, |
+ GLImplementation* out_impl, |
+ bool* out_fallback_to_osmesa) { |
+ DCHECK(out_impl); |
+ DCHECK(out_fallback_to_osmesa); |
+ DCHECK(!allowed_impls.empty()); |
+ |
+ base::CommandLine* cmd = base::CommandLine::ForCurrentProcess(); |
+ |
+ // The default implementation is always the first one in list. |
+ GLImplementation impl = allowed_impls[0]; |
+ bool fallback_to_osmesa = false; |
+ if (cmd->HasSwitch(switches::kOverrideUseGLWithOSMesaForTests)) { |
+ impl = kGLImplementationOSMesaGL; |
+ } else if (cmd->HasSwitch(switches::kUseGL)) { |
+ std::string requested_implementation_name = |
+ cmd->GetSwitchValueASCII(switches::kUseGL); |
+ if (requested_implementation_name == "any") { |
+ fallback_to_osmesa = true; |
+ } else if (requested_implementation_name == |
+ kGLImplementationSwiftShaderName || |
+ requested_implementation_name == kGLImplementationANGLEName) { |
+ impl = kGLImplementationEGLGLES2; |
+ } else { |
+ impl = GetNamedGLImplementation(requested_implementation_name); |
+ if (!base::ContainsValue(allowed_impls, impl)) { |
+ LOG(ERROR) << "Requested GL implementation is not available."; |
+ return false; |
+ } |
+ } |
+ } |
+ |
+ *out_impl = impl; |
+ *out_fallback_to_osmesa = fallback_to_osmesa; |
+ |
+ return true; |
+} |
+ |
bool HasDesktopGLFeatures() { |
return kGLImplementationDesktopGL == g_gl_implementation || |
kGLImplementationDesktopGLCoreProfile == g_gl_implementation || |