Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(412)

Side by Side Diff: ui/gl/gl_implementation.cc

Issue 1542013005: Add a new driver bug workaround SANDBOX_START_EARLY Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and remove gyp support Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
23 #include "ui/gl/init/gl_factory.h"
22 24
23 namespace gl { 25 namespace gl {
24 26
25 namespace { 27 namespace {
26 28
27 const struct { 29 const struct {
28 const char* name; 30 const char* name;
29 GLImplementation implementation; 31 GLImplementation implementation;
30 } kGLImplementationNamePairs[] = { 32 } kGLImplementationNamePairs[] = {
31 { kGLImplementationDesktopName, kGLImplementationDesktopGL }, 33 { kGLImplementationDesktopName, kGLImplementationDesktopGL },
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 } 91 }
90 92
91 void SetGLImplementation(GLImplementation implementation) { 93 void SetGLImplementation(GLImplementation implementation) {
92 g_gl_implementation = implementation; 94 g_gl_implementation = implementation;
93 } 95 }
94 96
95 GLImplementation GetGLImplementation() { 97 GLImplementation GetGLImplementation() {
96 return g_gl_implementation; 98 return g_gl_implementation;
97 } 99 }
98 100
101 bool SelectGLImplementation(const std::vector<GLImplementation>& allowed_impls,
102 GLImplementation* out_impl,
103 bool* out_fallback_to_osmesa) {
104 DCHECK(out_impl);
105 DCHECK(out_fallback_to_osmesa);
106 DCHECK(!allowed_impls.empty());
107
108 base::CommandLine* cmd = base::CommandLine::ForCurrentProcess();
109
110 // The default implementation is always the first one in list.
111 GLImplementation impl = allowed_impls[0];
112 bool fallback_to_osmesa = false;
113 if (cmd->HasSwitch(switches::kOverrideUseGLWithOSMesaForTests)) {
114 impl = kGLImplementationOSMesaGL;
115 } else if (cmd->HasSwitch(switches::kUseGL)) {
116 std::string requested_implementation_name =
117 cmd->GetSwitchValueASCII(switches::kUseGL);
118 if (requested_implementation_name == "any") {
119 fallback_to_osmesa = true;
120 } else if (requested_implementation_name ==
121 kGLImplementationSwiftShaderName ||
122 requested_implementation_name == kGLImplementationANGLEName) {
123 impl = kGLImplementationEGLGLES2;
124 } else {
125 impl = GetNamedGLImplementation(requested_implementation_name);
126 if (!base::ContainsValue(allowed_impls, impl)) {
127 LOG(ERROR) << "Requested GL implementation is not available.";
128 return false;
129 }
130 }
131 }
132
133 *out_impl = impl;
134 *out_fallback_to_osmesa = fallback_to_osmesa;
135
136 return true;
137 }
138
99 bool HasDesktopGLFeatures() { 139 bool HasDesktopGLFeatures() {
100 return kGLImplementationDesktopGL == g_gl_implementation || 140 return kGLImplementationDesktopGL == g_gl_implementation ||
101 kGLImplementationDesktopGLCoreProfile == g_gl_implementation || 141 kGLImplementationDesktopGLCoreProfile == g_gl_implementation ||
102 kGLImplementationOSMesaGL == g_gl_implementation || 142 kGLImplementationOSMesaGL == g_gl_implementation ||
103 kGLImplementationAppleGL == g_gl_implementation; 143 kGLImplementationAppleGL == g_gl_implementation;
104 } 144 }
105 145
106 void AddGLNativeLibrary(base::NativeLibrary library) { 146 void AddGLNativeLibrary(base::NativeLibrary library) {
107 DCHECK(library); 147 DCHECK(library);
108 148
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 base::NativeLibrary library = base::LoadNativeLibrary(filename, &error); 261 base::NativeLibrary library = base::LoadNativeLibrary(filename, &error);
222 if (!library) { 262 if (!library) {
223 LOG(ERROR) << "Failed to load " << filename.MaybeAsASCII() << ": " 263 LOG(ERROR) << "Failed to load " << filename.MaybeAsASCII() << ": "
224 << error.ToString(); 264 << error.ToString();
225 return NULL; 265 return NULL;
226 } 266 }
227 return library; 267 return library;
228 } 268 }
229 269
230 } // namespace gl 270 } // namespace gl
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698