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 "ui/gl/gl_implementation.h" | 5 #include "ui/gl/gl_implementation.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/at_exit.h" | 12 #include "base/at_exit.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/stl_util.h" |
16 #include "base/strings/string_split.h" | 17 #include "base/strings/string_split.h" |
17 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
18 #include "build/build_config.h" | 19 #include "build/build_config.h" |
19 #include "ui/gl/gl_bindings.h" | 20 #include "ui/gl/gl_bindings.h" |
20 #include "ui/gl/gl_gl_api_implementation.h" | 21 #include "ui/gl/gl_gl_api_implementation.h" |
21 #include "ui/gl/gl_version_info.h" | 22 #include "ui/gl/gl_version_info.h" |
22 | 23 |
23 namespace gl { | 24 namespace gl { |
24 | 25 |
25 namespace { | 26 namespace { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 } | 90 } |
90 | 91 |
91 void SetGLImplementation(GLImplementation implementation) { | 92 void SetGLImplementation(GLImplementation implementation) { |
92 g_gl_implementation = implementation; | 93 g_gl_implementation = implementation; |
93 } | 94 } |
94 | 95 |
95 GLImplementation GetGLImplementation() { | 96 GLImplementation GetGLImplementation() { |
96 return g_gl_implementation; | 97 return g_gl_implementation; |
97 } | 98 } |
98 | 99 |
| 100 bool SelectGLImplementation(const std::vector<GLImplementation>& allowed_impls, |
| 101 GLImplementation* out_impl, |
| 102 bool* out_fallback_to_osmesa) { |
| 103 DCHECK(out_impl); |
| 104 DCHECK(out_fallback_to_osmesa); |
| 105 DCHECK(!allowed_impls.empty()); |
| 106 |
| 107 base::CommandLine* cmd = base::CommandLine::ForCurrentProcess(); |
| 108 |
| 109 // The default implementation is always the first one in list. |
| 110 GLImplementation impl = allowed_impls[0]; |
| 111 bool fallback_to_osmesa = false; |
| 112 if (cmd->HasSwitch(switches::kOverrideUseGLWithOSMesaForTests)) { |
| 113 impl = kGLImplementationOSMesaGL; |
| 114 } else if (cmd->HasSwitch(switches::kUseGL)) { |
| 115 std::string requested_implementation_name = |
| 116 cmd->GetSwitchValueASCII(switches::kUseGL); |
| 117 if (requested_implementation_name == "any") { |
| 118 fallback_to_osmesa = true; |
| 119 } else if (requested_implementation_name == |
| 120 kGLImplementationSwiftShaderName || |
| 121 requested_implementation_name == kGLImplementationANGLEName) { |
| 122 impl = kGLImplementationEGLGLES2; |
| 123 } else { |
| 124 impl = GetNamedGLImplementation(requested_implementation_name); |
| 125 if (!base::ContainsValue(allowed_impls, impl)) { |
| 126 LOG(ERROR) << "Requested GL implementation is not available."; |
| 127 return false; |
| 128 } |
| 129 } |
| 130 } |
| 131 |
| 132 *out_impl = impl; |
| 133 *out_fallback_to_osmesa = fallback_to_osmesa; |
| 134 |
| 135 return true; |
| 136 } |
| 137 |
99 bool HasDesktopGLFeatures() { | 138 bool HasDesktopGLFeatures() { |
100 return kGLImplementationDesktopGL == g_gl_implementation || | 139 return kGLImplementationDesktopGL == g_gl_implementation || |
101 kGLImplementationDesktopGLCoreProfile == g_gl_implementation || | 140 kGLImplementationDesktopGLCoreProfile == g_gl_implementation || |
102 kGLImplementationOSMesaGL == g_gl_implementation || | 141 kGLImplementationOSMesaGL == g_gl_implementation || |
103 kGLImplementationAppleGL == g_gl_implementation; | 142 kGLImplementationAppleGL == g_gl_implementation; |
104 } | 143 } |
105 | 144 |
106 void AddGLNativeLibrary(base::NativeLibrary library) { | 145 void AddGLNativeLibrary(base::NativeLibrary library) { |
107 DCHECK(library); | 146 DCHECK(library); |
108 | 147 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 base::NativeLibrary library = base::LoadNativeLibrary(filename, &error); | 260 base::NativeLibrary library = base::LoadNativeLibrary(filename, &error); |
222 if (!library) { | 261 if (!library) { |
223 LOG(ERROR) << "Failed to load " << filename.MaybeAsASCII() << ": " | 262 LOG(ERROR) << "Failed to load " << filename.MaybeAsASCII() << ": " |
224 << error.ToString(); | 263 << error.ToString(); |
225 return NULL; | 264 return NULL; |
226 } | 265 } |
227 return library; | 266 return library; |
228 } | 267 } |
229 | 268 |
230 } // namespace gl | 269 } // namespace gl |
OLD | NEW |