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

Side by Side Diff: gpu/config/gpu_control_list.cc

Issue 2756793003: Move GPU blacklist and driver bug workaround list from json to data struct. (Closed)
Patch Set: Switch to use arraysize Created 3 years, 8 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "gpu/config/gpu_control_list.h" 5 #include "gpu/config/gpu_control_list.h"
6 6
7 #include <stddef.h>
8 #include <stdint.h>
9
10 #include <utility>
11
12 #include "base/cpu.h"
13 #include "base/json/json_reader.h"
14 #include "base/logging.h" 7 #include "base/logging.h"
15 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
16 #include "base/strings/string_split.h" 9 #include "base/strings/string_split.h"
17 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
18 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
19 #include "base/sys_info.h" 12 #include "base/sys_info.h"
20 #include "gpu/config/gpu_info.h" 13 #include "gpu/config/gpu_info.h"
21 #include "gpu/config/gpu_util.h"
22 #include "third_party/re2/src/re2/re2.h" 14 #include "third_party/re2/src/re2/re2.h"
23 15
24 namespace gpu { 16 namespace gpu {
25 namespace { 17 namespace {
26 18
27 // Break a version string into segments. Return true if each segment is 19 // Break a version string into segments. Return true if each segment is
28 // a valid number, and not all segment is 0. 20 // a valid number, and not all segment is 0.
29 bool ProcessVersionString(const std::string& version_string, 21 bool ProcessVersionString(const std::string& version_string,
30 char splitter, 22 char splitter,
31 std::vector<std::string>* version) { 23 std::vector<std::string>* version) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 return 0; 89 return 0;
98 } 90 }
99 91
100 // A mismatch is identified only if both |input| and |pattern| are not empty. 92 // A mismatch is identified only if both |input| and |pattern| are not empty.
101 bool StringMismatch(const std::string& input, const std::string& pattern) { 93 bool StringMismatch(const std::string& input, const std::string& pattern) {
102 if (input.empty() || pattern.empty()) 94 if (input.empty() || pattern.empty())
103 return false; 95 return false;
104 return !RE2::FullMatch(input, pattern); 96 return !RE2::FullMatch(input, pattern);
105 } 97 }
106 98
107 const char kMultiGpuStyleStringAMDSwitchable[] = "amd_switchable"; 99 bool StringMismatch(const std::string& input, const char* pattern) {
108 const char kMultiGpuStyleStringAMDSwitchableDiscrete[] = 100 if (!pattern)
109 "amd_switchable_discrete"; 101 return false;
110 const char kMultiGpuStyleStringAMDSwitchableIntegrated[] = 102 std::string pattern_string(pattern);
111 "amd_switchable_integrated"; 103 return StringMismatch(input, pattern_string);
112 const char kMultiGpuStyleStringOptimus[] = "optimus"; 104 }
113
114 const char kMultiGpuCategoryStringPrimary[] = "primary";
115 const char kMultiGpuCategoryStringSecondary[] = "secondary";
116 const char kMultiGpuCategoryStringActive[] = "active";
117 const char kMultiGpuCategoryStringAny[] = "any";
118
119 const char kGLTypeStringGL[] = "gl";
120 const char kGLTypeStringGLES[] = "gles";
121 const char kGLTypeStringANGLE[] = "angle";
122
123 const char kVersionStyleStringNumerical[] = "numerical";
124 const char kVersionStyleStringLexical[] = "lexical";
125
126 const char kOp[] = "op";
127 105
128 } // namespace 106 } // namespace
129 107
130 GpuControlList::VersionInfo::VersionInfo( 108 bool GpuControlList::Version::Contains(const std::string& version_string,
131 const std::string& version_op, 109 char splitter) const {
132 const std::string& version_style, 110 if (op == kUnknown)
133 const std::string& version_string,
134 const std::string& version_string2)
135 : version_style_(kVersionStyleNumerical) {
136 op_ = StringToNumericOp(version_op);
137 if (op_ == kUnknown || op_ == kAny)
138 return;
139 version_style_ = StringToVersionStyle(version_style);
140 if (!ProcessVersionString(version_string, '.', &version_)) {
141 op_ = kUnknown;
142 return;
143 }
144 if (op_ == kBetween) {
145 if (!ProcessVersionString(version_string2, '.', &version2_))
146 op_ = kUnknown;
147 }
148 }
149
150 GpuControlList::VersionInfo::~VersionInfo() {
151 }
152
153 bool GpuControlList::VersionInfo::Contains(
154 const std::string& version_string) const {
155 return Contains(version_string, '.');
156 }
157
158 bool GpuControlList::VersionInfo::Contains(
159 const std::string& version_string, char splitter) const {
160 if (op_ == kUnknown)
161 return false; 111 return false;
162 if (op_ == kAny) 112 if (op == kAny)
163 return true; 113 return true;
164 std::vector<std::string> version; 114 std::vector<std::string> version;
165 if (!ProcessVersionString(version_string, splitter, &version)) 115 if (!ProcessVersionString(version_string, splitter, &version))
166 return false; 116 return false;
167 int relation = Compare(version, version_, version_style_); 117 std::vector<std::string> ref_version;
168 if (op_ == kEQ) 118 bool valid = ProcessVersionString(value1, '.', &ref_version);
119 DCHECK(valid);
120 int relation = Version::Compare(version, ref_version, style);
121 if (op == kEQ)
Ken Russell (switch to Gerrit) 2017/03/31 02:37:07 Nit: think this would be better expressed as a swi
Zhenyao Mo 2017/03/31 19:14:14 Done.
169 return (relation == 0); 122 return (relation == 0);
170 else if (op_ == kLT) 123 else if (op == kLT)
171 return (relation < 0); 124 return (relation < 0);
172 else if (op_ == kLE) 125 else if (op == kLE)
173 return (relation <= 0); 126 return (relation <= 0);
174 else if (op_ == kGT) 127 else if (op == kGT)
175 return (relation > 0); 128 return (relation > 0);
176 else if (op_ == kGE) 129 else if (op == kGE)
177 return (relation >= 0); 130 return (relation >= 0);
178 // op_ == kBetween 131 // op_ == kBetween
179 if (relation < 0) 132 if (relation < 0)
180 return false; 133 return false;
181 return Compare(version, version2_, version_style_) <= 0; 134 ref_version.clear();
182 } 135 valid = ProcessVersionString(value2, '.', &ref_version);
183 136 DCHECK(valid);
184 bool GpuControlList::VersionInfo::IsValid() const { 137 return Compare(version, ref_version, style) <= 0;
185 return (op_ != kUnknown && version_style_ != kVersionStyleUnknown);
186 }
187
188 bool GpuControlList::VersionInfo::IsLexical() const {
189 return version_style_ == kVersionStyleLexical;
190 } 138 }
191 139
192 // static 140 // static
193 int GpuControlList::VersionInfo::Compare( 141 int GpuControlList::Version::Compare(
194 const std::vector<std::string>& version, 142 const std::vector<std::string>& version,
195 const std::vector<std::string>& version_ref, 143 const std::vector<std::string>& version_ref,
196 VersionStyle version_style) { 144 VersionStyle version_style) {
197 DCHECK(version.size() > 0 && version_ref.size() > 0); 145 DCHECK(version.size() > 0 && version_ref.size() > 0);
198 DCHECK(version_style != kVersionStyleUnknown); 146 DCHECK(version_style != kVersionStyleUnknown);
199 for (size_t i = 0; i < version_ref.size(); ++i) { 147 for (size_t i = 0; i < version_ref.size(); ++i) {
200 if (i >= version.size()) 148 if (i >= version.size())
201 return 0; 149 return 0;
202 int ret = 0; 150 int ret = 0;
203 // We assume both versions are checked by ProcessVersionString(). 151 // We assume both versions are checked by ProcessVersionString().
204 if (i > 0 && version_style == kVersionStyleLexical) 152 if (i > 0 && version_style == kVersionStyleLexical)
205 ret = CompareLexicalNumberStrings(version[i], version_ref[i]); 153 ret = CompareLexicalNumberStrings(version[i], version_ref[i]);
206 else 154 else
207 ret = CompareNumericalNumberStrings(version[i], version_ref[i]); 155 ret = CompareNumericalNumberStrings(version[i], version_ref[i]);
208 if (ret != 0) 156 if (ret != 0)
209 return ret; 157 return ret;
210 } 158 }
211 return 0; 159 return 0;
212 } 160 }
213 161
214 // static 162 bool GpuControlList::More::GLVersionInfoMismatch(
215 GpuControlList::VersionInfo::VersionStyle 163 const std::string& gl_version_string) const {
216 GpuControlList::VersionInfo::StringToVersionStyle( 164 if (gl_version_string.empty())
217 const std::string& version_style) { 165 return false;
218 if (version_style.empty() || version_style == kVersionStyleStringNumerical) 166 if (!gl_version.IsSpecified() && gl_type == kGLTypeNone)
219 return kVersionStyleNumerical; 167 return false;
220 if (version_style == kVersionStyleStringLexical) 168 std::vector<std::string> segments = base::SplitString(
221 return kVersionStyleLexical; 169 gl_version_string, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
222 return kVersionStyleUnknown; 170 std::string number;
223 } 171 GLType target_gl_type = kGLTypeNone;
172 if (segments.size() > 2 &&
173 segments[0] == "OpenGL" && segments[1] == "ES") {
174 bool full_match = RE2::FullMatch(segments[2], "([\\d.]+).*", &number);
175 DCHECK(full_match);
224 176
225 GpuControlList::OsInfo::OsInfo(const std::string& os, 177 target_gl_type = kGLTypeGLES;
226 const std::string& version_op, 178 if (segments.size() > 3 &&
227 const std::string& version_string, 179 base::StartsWith(segments[3], "(ANGLE",
228 const std::string& version_string2) { 180 base::CompareCase::INSENSITIVE_ASCII)) {
229 type_ = StringToOsType(os); 181 target_gl_type = kGLTypeANGLE;
230 if (type_ != kOsUnknown) {
231 version_info_.reset(new VersionInfo(
232 version_op, std::string(), version_string, version_string2));
233 }
234 }
235
236 GpuControlList::OsInfo::~OsInfo() {}
237
238 bool GpuControlList::OsInfo::Contains(
239 OsType type, const std::string& version) const {
240 if (!IsValid())
241 return false;
242 if (type_ != type && type_ != kOsAny)
243 return false;
244 std::string processed_version;
245 size_t pos = version.find_first_not_of("0123456789.");
246 if (pos != std::string::npos)
247 processed_version = version.substr(0, pos);
248 else
249 processed_version = version;
250
251 return version_info_->Contains(processed_version);
252 }
253
254 bool GpuControlList::OsInfo::IsValid() const {
255 return type_ != kOsUnknown && version_info_->IsValid();
256 }
257
258 GpuControlList::OsType GpuControlList::OsInfo::type() const {
259 return type_;
260 }
261
262 GpuControlList::OsType GpuControlList::OsInfo::StringToOsType(
263 const std::string& os) {
264 if (os == "win")
265 return kOsWin;
266 else if (os == "macosx")
267 return kOsMacosx;
268 else if (os == "android")
269 return kOsAndroid;
270 else if (os == "linux")
271 return kOsLinux;
272 else if (os == "chromeos")
273 return kOsChromeOS;
274 else if (os == "any")
275 return kOsAny;
276 return kOsUnknown;
277 }
278
279 GpuControlList::FloatInfo::FloatInfo(const std::string& float_op,
280 const std::string& float_value,
281 const std::string& float_value2)
282 : op_(kUnknown),
283 value_(0.f),
284 value2_(0.f) {
285 op_ = StringToNumericOp(float_op);
286 if (op_ == kAny)
287 return;
288 double dvalue = 0;
289 if (!base::StringToDouble(float_value, &dvalue)) {
290 op_ = kUnknown;
291 return;
292 }
293 value_ = static_cast<float>(dvalue);
294 if (op_ == kBetween) {
295 if (!base::StringToDouble(float_value2, &dvalue)) {
296 op_ = kUnknown;
297 return;
298 } 182 }
299 value2_ = static_cast<float>(dvalue); 183 } else {
300 } 184 number = segments[0];
301 } 185 target_gl_type = kGLTypeGL;
302
303 bool GpuControlList::FloatInfo::Contains(float value) const {
304 if (op_ == kUnknown)
305 return false;
306 if (op_ == kAny)
307 return true;
308 if (op_ == kEQ)
309 return (value == value_);
310 if (op_ == kLT)
311 return (value < value_);
312 if (op_ == kLE)
313 return (value <= value_);
314 if (op_ == kGT)
315 return (value > value_);
316 if (op_ == kGE)
317 return (value >= value_);
318 DCHECK(op_ == kBetween);
319 return ((value_ <= value && value <= value2_) ||
320 (value2_ <= value && value <= value_));
321 }
322
323 bool GpuControlList::FloatInfo::IsValid() const {
324 return op_ != kUnknown;
325 }
326
327 GpuControlList::IntInfo::IntInfo(const std::string& int_op,
328 const std::string& int_value,
329 const std::string& int_value2)
330 : op_(kUnknown),
331 value_(0),
332 value2_(0) {
333 op_ = StringToNumericOp(int_op);
334 if (op_ == kAny)
335 return;
336 if (!base::StringToInt(int_value, &value_)) {
337 op_ = kUnknown;
338 return;
339 }
340 if (op_ == kBetween &&
341 !base::StringToInt(int_value2, &value2_))
342 op_ = kUnknown;
343 }
344
345 bool GpuControlList::IntInfo::Contains(int value) const {
346 if (op_ == kUnknown)
347 return false;
348 if (op_ == kAny)
349 return true;
350 if (op_ == kEQ)
351 return (value == value_);
352 if (op_ == kLT)
353 return (value < value_);
354 if (op_ == kLE)
355 return (value <= value_);
356 if (op_ == kGT)
357 return (value > value_);
358 if (op_ == kGE)
359 return (value >= value_);
360 DCHECK(op_ == kBetween);
361 return ((value_ <= value && value <= value2_) ||
362 (value2_ <= value && value <= value_));
363 }
364
365 bool GpuControlList::IntInfo::IsValid() const {
366 return op_ != kUnknown;
367 }
368
369 GpuControlList::BoolInfo::BoolInfo(bool value) : value_(value) {}
370
371 bool GpuControlList::BoolInfo::Contains(bool value) const {
372 return value_ == value;
373 }
374
375 // static
376 GpuControlList::ScopedGpuControlListEntry
377 GpuControlList::GpuControlListEntry::GetEntryFromValue(
378 const base::DictionaryValue* value, bool top_level,
379 const FeatureMap& feature_map,
380 bool supports_feature_type_all) {
381 DCHECK(value);
382 ScopedGpuControlListEntry entry(new GpuControlListEntry());
383
384 size_t dictionary_entry_count = 0;
385
386 if (top_level) {
387 uint32_t id;
388 if (!value->GetInteger("id", reinterpret_cast<int*>(&id)) ||
389 !entry->SetId(id)) {
390 LOG(WARNING) << "Malformed id entry " << entry->id();
391 return NULL;
392 }
393 dictionary_entry_count++;
394
395 bool disabled;
396 if (value->GetBoolean("disabled", &disabled)) {
397 entry->SetDisabled(disabled);
398 dictionary_entry_count++;
399 }
400 } 186 }
401 187
402 std::string description; 188 GLType entry_gl_type = gl_type;
403 if (value->GetString("description", &description)) { 189 if (entry_gl_type == kGLTypeNone && gl_version.IsSpecified()) {
404 entry->description_ = description; 190 entry_gl_type = GetDefaultGLType();
405 dictionary_entry_count++;
406 } else {
407 entry->description_ = "The GPU is unavailable for an unexplained reason.";
408 } 191 }
409 192 if (entry_gl_type != kGLTypeNone && entry_gl_type != target_gl_type) {
410 const base::ListValue* cr_bugs; 193 return true;
411 if (value->GetList("cr_bugs", &cr_bugs)) {
412 for (size_t i = 0; i < cr_bugs->GetSize(); ++i) {
413 int bug_id;
414 if (cr_bugs->GetInteger(i, &bug_id)) {
415 entry->cr_bugs_.push_back(bug_id);
416 } else {
417 LOG(WARNING) << "Malformed cr_bugs entry " << entry->id();
418 return NULL;
419 }
420 }
421 dictionary_entry_count++;
422 } 194 }
423 195 if (gl_version.IsSpecified() && !gl_version.Contains(number)) {
424 const base::ListValue* webkit_bugs;
425 if (value->GetList("webkit_bugs", &webkit_bugs)) {
426 for (size_t i = 0; i < webkit_bugs->GetSize(); ++i) {
427 int bug_id;
428 if (webkit_bugs->GetInteger(i, &bug_id)) {
429 entry->webkit_bugs_.push_back(bug_id);
430 } else {
431 LOG(WARNING) << "Malformed webkit_bugs entry " << entry->id();
432 return NULL;
433 }
434 }
435 dictionary_entry_count++;
436 }
437
438 const base::ListValue* disabled_extensions;
439 if (value->GetList("disabled_extensions", &disabled_extensions)) {
440 for (size_t i = 0; i < disabled_extensions->GetSize(); ++i) {
441 std::string disabled_extension;
442 if (disabled_extensions->GetString(i, &disabled_extension)) {
443 entry->disabled_extensions_.push_back(disabled_extension);
444 } else {
445 LOG(WARNING) << "Malformed disabled_extensions entry " << entry->id();
446 return NULL;
447 }
448 }
449 dictionary_entry_count++;
450 }
451
452 const base::DictionaryValue* os_value = NULL;
453 if (value->GetDictionary("os", &os_value)) {
454 std::string os_type;
455 std::string os_version_op = "any";
456 std::string os_version_string;
457 std::string os_version_string2;
458 os_value->GetString("type", &os_type);
459 const base::DictionaryValue* os_version_value = NULL;
460 if (os_value->GetDictionary("version", &os_version_value)) {
461 os_version_value->GetString(kOp, &os_version_op);
462 os_version_value->GetString("value", &os_version_string);
463 os_version_value->GetString("value2", &os_version_string2);
464 }
465 if (!entry->SetOsInfo(os_type, os_version_op, os_version_string,
466 os_version_string2)) {
467 LOG(WARNING) << "Malformed os entry " << entry->id();
468 return NULL;
469 }
470 dictionary_entry_count++;
471 }
472
473 std::string vendor_id;
474 if (value->GetString("vendor_id", &vendor_id)) {
475 if (!entry->SetVendorId(vendor_id)) {
476 LOG(WARNING) << "Malformed vendor_id entry " << entry->id();
477 return NULL;
478 }
479 dictionary_entry_count++;
480 }
481
482 const base::ListValue* device_id_list;
483 if (value->GetList("device_id", &device_id_list)) {
484 for (size_t i = 0; i < device_id_list->GetSize(); ++i) {
485 std::string device_id;
486 if (!device_id_list->GetString(i, &device_id) ||
487 !entry->AddDeviceId(device_id)) {
488 LOG(WARNING) << "Malformed device_id entry " << entry->id();
489 return NULL;
490 }
491 }
492 dictionary_entry_count++;
493 }
494
495 std::string multi_gpu_style;
496 if (value->GetString("multi_gpu_style", &multi_gpu_style)) {
497 if (!entry->SetMultiGpuStyle(multi_gpu_style)) {
498 LOG(WARNING) << "Malformed multi_gpu_style entry " << entry->id();
499 return NULL;
500 }
501 dictionary_entry_count++;
502 }
503
504 std::string multi_gpu_category;
505 if (value->GetString("multi_gpu_category", &multi_gpu_category)) {
506 if (!entry->SetMultiGpuCategory(multi_gpu_category)) {
507 LOG(WARNING) << "Malformed multi_gpu_category entry " << entry->id();
508 return NULL;
509 }
510 dictionary_entry_count++;
511 }
512
513 std::string driver_vendor_value;
514 if (value->GetString("driver_vendor", &driver_vendor_value)) {
515 if (!entry->SetDriverVendorInfo(driver_vendor_value)) {
516 LOG(WARNING) << "Malformed driver_vendor entry " << entry->id();
517 return NULL;
518 }
519 dictionary_entry_count++;
520 }
521
522 const base::DictionaryValue* driver_version_value = NULL;
523 if (value->GetDictionary("driver_version", &driver_version_value)) {
524 std::string driver_version_op = "any";
525 std::string driver_version_style;
526 std::string driver_version_string;
527 std::string driver_version_string2;
528 driver_version_value->GetString(kOp, &driver_version_op);
529 driver_version_value->GetString("style", &driver_version_style);
530 driver_version_value->GetString("value", &driver_version_string);
531 driver_version_value->GetString("value2", &driver_version_string2);
532 if (!entry->SetDriverVersionInfo(driver_version_op,
533 driver_version_style,
534 driver_version_string,
535 driver_version_string2)) {
536 LOG(WARNING) << "Malformed driver_version entry " << entry->id();
537 return NULL;
538 }
539 dictionary_entry_count++;
540 }
541
542 const base::DictionaryValue* driver_date_value = NULL;
543 if (value->GetDictionary("driver_date", &driver_date_value)) {
544 std::string driver_date_op = "any";
545 std::string driver_date_string;
546 std::string driver_date_string2;
547 driver_date_value->GetString(kOp, &driver_date_op);
548 driver_date_value->GetString("value", &driver_date_string);
549 driver_date_value->GetString("value2", &driver_date_string2);
550 if (!entry->SetDriverDateInfo(driver_date_op, driver_date_string,
551 driver_date_string2)) {
552 LOG(WARNING) << "Malformed driver_date entry " << entry->id();
553 return NULL;
554 }
555 dictionary_entry_count++;
556 }
557
558 std::string gl_type;
559 if (value->GetString("gl_type", &gl_type)) {
560 if (!entry->SetGLType(gl_type)) {
561 LOG(WARNING) << "Malformed gl_type entry " << entry->id();
562 return NULL;
563 }
564 dictionary_entry_count++;
565 }
566
567 const base::DictionaryValue* gl_version_value = NULL;
568 if (value->GetDictionary("gl_version", &gl_version_value)) {
569 std::string version_op = "any";
570 std::string version_string;
571 std::string version_string2;
572 gl_version_value->GetString(kOp, &version_op);
573 gl_version_value->GetString("value", &version_string);
574 gl_version_value->GetString("value2", &version_string2);
575 if (!entry->SetGLVersionInfo(
576 version_op, version_string, version_string2)) {
577 LOG(WARNING) << "Malformed gl_version entry " << entry->id();
578 return NULL;
579 }
580 dictionary_entry_count++;
581 }
582
583 std::string gl_version_string_value;
584 if (value->GetString("gl_version_string", &gl_version_string_value)) {
585 if (!entry->SetGLVersionStringInfo(gl_version_string_value)) {
586 LOG(WARNING) << "Malformed gl_version_string entry " << entry->id();
587 return NULL;
588 }
589 dictionary_entry_count++;
590 }
591
592 std::string gl_vendor_value;
593 if (value->GetString("gl_vendor", &gl_vendor_value)) {
594 if (!entry->SetGLVendorInfo(gl_vendor_value)) {
595 LOG(WARNING) << "Malformed gl_vendor entry " << entry->id();
596 return NULL;
597 }
598 dictionary_entry_count++;
599 }
600
601 std::string gl_renderer_value;
602 if (value->GetString("gl_renderer", &gl_renderer_value)) {
603 if (!entry->SetGLRendererInfo(gl_renderer_value)) {
604 LOG(WARNING) << "Malformed gl_renderer entry " << entry->id();
605 return NULL;
606 }
607 dictionary_entry_count++;
608 }
609
610 std::string gl_extensions_value;
611 if (value->GetString("gl_extensions", &gl_extensions_value)) {
612 if (!entry->SetGLExtensionsInfo(gl_extensions_value)) {
613 LOG(WARNING) << "Malformed gl_extensions entry " << entry->id();
614 return NULL;
615 }
616 dictionary_entry_count++;
617 }
618
619 const base::DictionaryValue* gl_reset_notification_strategy_value = NULL;
620 if (value->GetDictionary("gl_reset_notification_strategy",
621 &gl_reset_notification_strategy_value)) {
622 std::string op;
623 std::string int_value;
624 std::string int_value2;
625 gl_reset_notification_strategy_value->GetString(kOp, &op);
626 gl_reset_notification_strategy_value->GetString("value", &int_value);
627 gl_reset_notification_strategy_value->GetString("value2", &int_value2);
628 if (!entry->SetGLResetNotificationStrategyInfo(
629 op, int_value, int_value2)) {
630 LOG(WARNING) << "Malformed gl_reset_notification_strategy entry "
631 << entry->id();
632 return NULL;
633 }
634 dictionary_entry_count++;
635 }
636
637 std::string cpu_brand_value;
638 if (value->GetString("cpu_info", &cpu_brand_value)) {
639 if (!entry->SetCpuBrand(cpu_brand_value)) {
640 LOG(WARNING) << "Malformed cpu_brand entry " << entry->id();
641 return NULL;
642 }
643 dictionary_entry_count++;
644 }
645
646 const base::DictionaryValue* perf_graphics_value = NULL;
647 if (value->GetDictionary("perf_graphics", &perf_graphics_value)) {
648 std::string op;
649 std::string float_value;
650 std::string float_value2;
651 perf_graphics_value->GetString(kOp, &op);
652 perf_graphics_value->GetString("value", &float_value);
653 perf_graphics_value->GetString("value2", &float_value2);
654 if (!entry->SetPerfGraphicsInfo(op, float_value, float_value2)) {
655 LOG(WARNING) << "Malformed perf_graphics entry " << entry->id();
656 return NULL;
657 }
658 dictionary_entry_count++;
659 }
660
661 const base::DictionaryValue* perf_gaming_value = NULL;
662 if (value->GetDictionary("perf_gaming", &perf_gaming_value)) {
663 std::string op;
664 std::string float_value;
665 std::string float_value2;
666 perf_gaming_value->GetString(kOp, &op);
667 perf_gaming_value->GetString("value", &float_value);
668 perf_gaming_value->GetString("value2", &float_value2);
669 if (!entry->SetPerfGamingInfo(op, float_value, float_value2)) {
670 LOG(WARNING) << "Malformed perf_gaming entry " << entry->id();
671 return NULL;
672 }
673 dictionary_entry_count++;
674 }
675
676 const base::DictionaryValue* perf_overall_value = NULL;
677 if (value->GetDictionary("perf_overall", &perf_overall_value)) {
678 std::string op;
679 std::string float_value;
680 std::string float_value2;
681 perf_overall_value->GetString(kOp, &op);
682 perf_overall_value->GetString("value", &float_value);
683 perf_overall_value->GetString("value2", &float_value2);
684 if (!entry->SetPerfOverallInfo(op, float_value, float_value2)) {
685 LOG(WARNING) << "Malformed perf_overall entry " << entry->id();
686 return NULL;
687 }
688 dictionary_entry_count++;
689 }
690
691 const base::ListValue* machine_model_name_list;
692 if (value->GetList("machine_model_name", &machine_model_name_list)) {
693 for (size_t i = 0; i < machine_model_name_list->GetSize(); ++i) {
694 std::string model_name;
695 if (!machine_model_name_list->GetString(i, &model_name) ||
696 !entry->AddMachineModelName(model_name)) {
697 LOG(WARNING) << "Malformed machine_model_name entry " << entry->id();
698 return NULL;
699 }
700 }
701 dictionary_entry_count++;
702 }
703
704 const base::DictionaryValue* machine_model_version_value = NULL;
705 if (value->GetDictionary(
706 "machine_model_version", &machine_model_version_value)) {
707 std::string version_op = "any";
708 std::string version_string;
709 std::string version_string2;
710 machine_model_version_value->GetString(kOp, &version_op);
711 machine_model_version_value->GetString("value", &version_string);
712 machine_model_version_value->GetString("value2", &version_string2);
713 if (!entry->SetMachineModelVersionInfo(
714 version_op, version_string, version_string2)) {
715 LOG(WARNING) << "Malformed machine_model_version entry " << entry->id();
716 return NULL;
717 }
718 dictionary_entry_count++;
719 }
720
721 const base::DictionaryValue* gpu_count_value = NULL;
722 if (value->GetDictionary("gpu_count", &gpu_count_value)) {
723 std::string op;
724 std::string int_value;
725 std::string int_value2;
726 gpu_count_value->GetString(kOp, &op);
727 gpu_count_value->GetString("value", &int_value);
728 gpu_count_value->GetString("value2", &int_value2);
729 if (!entry->SetGpuCountInfo(op, int_value, int_value2)) {
730 LOG(WARNING) << "Malformed gpu_count entry " << entry->id();
731 return NULL;
732 }
733 dictionary_entry_count++;
734 }
735
736 bool direct_rendering;
737 if (value->GetBoolean("direct_rendering", &direct_rendering)) {
738 entry->SetDirectRenderingInfo(direct_rendering);
739 dictionary_entry_count++;
740 }
741
742 bool in_process_gpu;
743 if (value->GetBoolean("in_process_gpu", &in_process_gpu)) {
744 entry->SetInProcessGPUInfo(in_process_gpu);
745 dictionary_entry_count++;
746 }
747
748 const base::DictionaryValue* pixel_shader_version_value = NULL;
749 if (value->GetDictionary("pixel_shader_version",
750 &pixel_shader_version_value)) {
751 std::string pixel_shader_version_op = "any";
752 std::string pixel_shader_version_string;
753 std::string pixel_shader_version_string2;
754 pixel_shader_version_value->GetString(kOp, &pixel_shader_version_op);
755 pixel_shader_version_value->GetString("value",
756 &pixel_shader_version_string);
757 pixel_shader_version_value->GetString("value2",
758 &pixel_shader_version_string2);
759 if (!entry->SetPixelShaderVersionInfo(pixel_shader_version_op,
760 pixel_shader_version_string,
761 pixel_shader_version_string2)) {
762 LOG(WARNING) << "Malformed pixel shader version entry " << entry->id();
763 return NULL;
764 }
765 dictionary_entry_count++;
766 }
767
768 if (top_level) {
769 const base::ListValue* feature_value = NULL;
770 if (value->GetList("features", &feature_value)) {
771 std::vector<std::string> feature_list;
772 std::vector<std::string> feature_exception_list;
773 for (size_t i = 0; i < feature_value->GetSize(); ++i) {
774 std::string feature;
775 const base::DictionaryValue* features_info_value = NULL;
776 if (feature_value->GetString(i, &feature)) {
777 feature_list.push_back(feature);
778 } else if (feature_value->GetDictionary(i, &features_info_value)) {
779 const base::ListValue* exception_list_value = NULL;
780 if (features_info_value->size() > 1) {
781 LOG(WARNING) << "Malformed feature entry " << entry->id();
782 return NULL;
783 }
784 if (features_info_value->GetList("exceptions",
785 &exception_list_value)) {
786 for (size_t i = 0; i < exception_list_value->GetSize(); ++i) {
787 std::string exception_feature;
788 if (exception_list_value->GetString(i, &exception_feature)) {
789 feature_exception_list.push_back(exception_feature);
790 } else {
791 LOG(WARNING) << "Malformed feature entry " << entry->id();
792 return NULL;
793 }
794 }
795 } else {
796 LOG(WARNING) << "Malformed feature entry " << entry->id();
797 return NULL;
798 }
799 } else {
800 LOG(WARNING) << "Malformed feature entry " << entry->id();
801 return NULL;
802 }
803 }
804 if (!entry->SetFeatures(feature_list, feature_exception_list, feature_map,
805 supports_feature_type_all)) {
806 LOG(WARNING) << "Malformed feature entry " << entry->id();
807 return NULL;
808 }
809 dictionary_entry_count++;
810 }
811 }
812
813 if (top_level) {
814 const base::ListValue* exception_list_value = NULL;
815 if (value->GetList("exceptions", &exception_list_value)) {
816 for (size_t i = 0; i < exception_list_value->GetSize(); ++i) {
817 const base::DictionaryValue* exception_value = NULL;
818 if (!exception_list_value->GetDictionary(i, &exception_value)) {
819 LOG(WARNING) << "Malformed exceptions entry " << entry->id();
820 return NULL;
821 }
822 ScopedGpuControlListEntry exception(GetEntryFromValue(
823 exception_value, false, feature_map, supports_feature_type_all));
824 if (exception.get() == NULL) {
825 LOG(WARNING) << "Malformed exceptions entry " << entry->id();
826 return NULL;
827 }
828 // Exception should inherit vendor_id from parent, otherwise if only
829 // device_ids are specified in Exception, the info will be incomplete.
830 if (exception->vendor_id_ == 0 && entry->vendor_id_ != 0)
831 exception->vendor_id_ = entry->vendor_id_;
832 entry->AddException(exception);
833 }
834 dictionary_entry_count++;
835 }
836 }
837
838 if (value->size() != dictionary_entry_count) {
839 LOG(WARNING) << "Entry with unknown fields " << entry->id();
840 return NULL;
841 }
842
843 // If GL_VERSION is specified, but no info about whether it's GL or GLES,
844 // we use the default for the platform. See GLType enum declaration.
845 if (entry->gl_version_info_.get() != NULL && entry->gl_type_ == kGLTypeNone)
846 entry->gl_type_ = GetDefaultGLType();
847
848 return entry;
849 }
850
851 GpuControlList::GpuControlListEntry::GpuControlListEntry()
852 : id_(0),
853 disabled_(false),
854 vendor_id_(0),
855 multi_gpu_style_(kMultiGpuStyleNone),
856 multi_gpu_category_(kMultiGpuCategoryActive),
857 gl_type_(kGLTypeNone) {
858 }
859
860 GpuControlList::GpuControlListEntry::~GpuControlListEntry() { }
861
862 bool GpuControlList::GpuControlListEntry::SetId(uint32_t id) {
863 if (id != 0) {
864 id_ = id;
865 return true; 196 return true;
866 } 197 }
867 return false; 198 return false;
868 } 199 }
869 200
870 void GpuControlList::GpuControlListEntry::SetDisabled(bool disabled) {
871 disabled_ = disabled;
872 }
873
874 bool GpuControlList::GpuControlListEntry::SetOsInfo(
875 const std::string& os,
876 const std::string& version_op,
877 const std::string& version_string,
878 const std::string& version_string2) {
879 os_info_.reset(new OsInfo(os, version_op, version_string, version_string2));
880 return os_info_->IsValid();
881 }
882
883 bool GpuControlList::GpuControlListEntry::SetVendorId(
884 const std::string& vendor_id_string) {
885 vendor_id_ = 0;
886 return base::HexStringToUInt(vendor_id_string, &vendor_id_) &&
887 vendor_id_ != 0;
888 }
889
890 bool GpuControlList::GpuControlListEntry::AddDeviceId(
891 const std::string& device_id_string) {
892 uint32_t device_id = 0;
893 if (base::HexStringToUInt(device_id_string, &device_id) && device_id != 0) {
894 device_id_list_.push_back(device_id);
895 return true;
896 }
897 return false;
898 }
899
900 bool GpuControlList::GpuControlListEntry::SetMultiGpuStyle(
901 const std::string& multi_gpu_style_string) {
902 MultiGpuStyle style = StringToMultiGpuStyle(multi_gpu_style_string);
903 if (style == kMultiGpuStyleNone)
904 return false;
905 multi_gpu_style_ = style;
906 return true;
907 }
908
909 bool GpuControlList::GpuControlListEntry::SetMultiGpuCategory(
910 const std::string& multi_gpu_category_string) {
911 MultiGpuCategory category =
912 StringToMultiGpuCategory(multi_gpu_category_string);
913 if (category == kMultiGpuCategoryNone)
914 return false;
915 multi_gpu_category_ = category;
916 return true;
917 }
918
919 bool GpuControlList::GpuControlListEntry::SetGLType(
920 const std::string& gl_type_string) {
921 GLType gl_type = StringToGLType(gl_type_string);
922 if (gl_type == kGLTypeNone)
923 return false;
924 gl_type_ = gl_type;
925 return true;
926 }
927
928 bool GpuControlList::GpuControlListEntry::SetDriverVendorInfo(
929 const std::string& vendor_value) {
930 driver_vendor_info_ = vendor_value;
931 return !driver_vendor_info_.empty();
932 }
933
934 bool GpuControlList::GpuControlListEntry::SetDriverVersionInfo(
935 const std::string& version_op,
936 const std::string& version_style,
937 const std::string& version_string,
938 const std::string& version_string2) {
939 driver_version_info_.reset(new VersionInfo(
940 version_op, version_style, version_string, version_string2));
941 return driver_version_info_->IsValid();
942 }
943
944 bool GpuControlList::GpuControlListEntry::SetDriverDateInfo(
945 const std::string& date_op,
946 const std::string& date_string,
947 const std::string& date_string2) {
948 driver_date_info_.reset(
949 new VersionInfo(date_op, std::string(), date_string, date_string2));
950 return driver_date_info_->IsValid();
951 }
952
953 bool GpuControlList::GpuControlListEntry::SetGLVersionInfo(
954 const std::string& version_op,
955 const std::string& version_string,
956 const std::string& version_string2) {
957 gl_version_info_.reset(new VersionInfo(
958 version_op, std::string(), version_string, version_string2));
959 return gl_version_info_->IsValid();
960 }
961
962 bool GpuControlList::GpuControlListEntry::SetGLVersionStringInfo(
963 const std::string& version_string_value) {
964 gl_version_string_info_ = version_string_value;
965 return !gl_version_string_info_.empty();
966 }
967
968 bool GpuControlList::GpuControlListEntry::SetGLVendorInfo(
969 const std::string& vendor_value) {
970 gl_vendor_info_ = vendor_value;
971 return !gl_vendor_info_.empty();
972 }
973
974 bool GpuControlList::GpuControlListEntry::SetGLRendererInfo(
975 const std::string& renderer_value) {
976 gl_renderer_info_ = renderer_value;
977 return !gl_renderer_info_.empty();
978 }
979
980 bool GpuControlList::GpuControlListEntry::SetGLExtensionsInfo(
981 const std::string& extensions_value) {
982 gl_extensions_info_ = extensions_value;
983 return !gl_extensions_info_.empty();
984 }
985
986 bool GpuControlList::GpuControlListEntry::SetGLResetNotificationStrategyInfo(
987 const std::string& op,
988 const std::string& int_string,
989 const std::string& int_string2) {
990 gl_reset_notification_strategy_info_.reset(
991 new IntInfo(op, int_string, int_string2));
992 return gl_reset_notification_strategy_info_->IsValid();
993 }
994
995 bool GpuControlList::GpuControlListEntry::SetCpuBrand(
996 const std::string& cpu_value) {
997 cpu_brand_ = cpu_value;
998 return !cpu_brand_.empty();
999 }
1000
1001 bool GpuControlList::GpuControlListEntry::SetPerfGraphicsInfo(
1002 const std::string& op,
1003 const std::string& float_string,
1004 const std::string& float_string2) {
1005 perf_graphics_info_.reset(new FloatInfo(op, float_string, float_string2));
1006 return perf_graphics_info_->IsValid();
1007 }
1008
1009 bool GpuControlList::GpuControlListEntry::SetPerfGamingInfo(
1010 const std::string& op,
1011 const std::string& float_string,
1012 const std::string& float_string2) {
1013 perf_gaming_info_.reset(new FloatInfo(op, float_string, float_string2));
1014 return perf_gaming_info_->IsValid();
1015 }
1016
1017 bool GpuControlList::GpuControlListEntry::SetPerfOverallInfo(
1018 const std::string& op,
1019 const std::string& float_string,
1020 const std::string& float_string2) {
1021 perf_overall_info_.reset(new FloatInfo(op, float_string, float_string2));
1022 return perf_overall_info_->IsValid();
1023 }
1024
1025 bool GpuControlList::GpuControlListEntry::AddMachineModelName(
1026 const std::string& model_name) {
1027 if (model_name.empty())
1028 return false;
1029 machine_model_name_list_.push_back(model_name);
1030 return true;
1031 }
1032
1033 bool GpuControlList::GpuControlListEntry::SetMachineModelVersionInfo(
1034 const std::string& version_op,
1035 const std::string& version_string,
1036 const std::string& version_string2) {
1037 machine_model_version_info_.reset(new VersionInfo(
1038 version_op, std::string(), version_string, version_string2));
1039 return machine_model_version_info_->IsValid();
1040 }
1041
1042 bool GpuControlList::GpuControlListEntry::SetGpuCountInfo(
1043 const std::string& op,
1044 const std::string& int_string,
1045 const std::string& int_string2) {
1046 gpu_count_info_.reset(new IntInfo(op, int_string, int_string2));
1047 return gpu_count_info_->IsValid();
1048 }
1049
1050 void GpuControlList::GpuControlListEntry::SetDirectRenderingInfo(bool value) {
1051 direct_rendering_info_.reset(new BoolInfo(value));
1052 }
1053
1054 void GpuControlList::GpuControlListEntry::SetInProcessGPUInfo(bool value) {
1055 in_process_gpu_info_.reset(new BoolInfo(value));
1056 }
1057
1058 bool GpuControlList::GpuControlListEntry::SetFeatures(
1059 const std::vector<std::string>& feature_strings,
1060 const std::vector<std::string>& exception_strings,
1061 const FeatureMap& feature_map,
1062 bool supports_feature_type_all) {
1063 size_t size = feature_strings.size();
1064 if (size == 0)
1065 return false;
1066 features_.clear();
1067 for (size_t i = 0; i < size; ++i) {
1068 int feature = 0;
1069 if (supports_feature_type_all && feature_strings[i] == "all") {
1070 for (FeatureMap::const_iterator iter = feature_map.begin();
1071 iter != feature_map.end(); ++iter) {
1072 if (std::find(exception_strings.begin(), exception_strings.end(),
1073 iter->first) == exception_strings.end())
1074 features_.insert(iter->second);
1075 }
1076 continue;
1077 }
1078 if (!StringToFeature(feature_strings[i], &feature, feature_map)) {
1079 features_.clear();
1080 return false;
1081 }
1082 if (std::find(exception_strings.begin(), exception_strings.end(),
1083 feature_strings[i]) == exception_strings.end())
1084 features_.insert(feature);
1085 }
1086 return true;
1087 }
1088
1089 bool GpuControlList::GpuControlListEntry::SetPixelShaderVersionInfo(
1090 const std::string& version_op,
1091 const std::string& version_string,
1092 const std::string& version_string2) {
1093 pixel_shader_version_info_.reset(new VersionInfo(
1094 version_op, std::string(), version_string, version_string2));
1095 return pixel_shader_version_info_->IsValid();
1096 }
1097
1098 void GpuControlList::GpuControlListEntry::AddException(
1099 ScopedGpuControlListEntry exception) {
1100 exceptions_.push_back(exception);
1101 }
1102
1103 bool GpuControlList::GpuControlListEntry::GLVersionInfoMismatch(
1104 const std::string& gl_version) const {
1105 if (gl_version.empty())
1106 return false;
1107
1108 if (gl_version_info_.get() == NULL && gl_type_ == kGLTypeNone)
1109 return false;
1110
1111 std::vector<std::string> segments = base::SplitString(
1112 gl_version, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
1113 std::string number;
1114 GLType gl_type = kGLTypeNone;
1115 if (segments.size() > 2 &&
1116 segments[0] == "OpenGL" && segments[1] == "ES") {
1117 bool full_match = RE2::FullMatch(segments[2], "([\\d.]+).*", &number);
1118 DCHECK(full_match);
1119
1120 gl_type = kGLTypeGLES;
1121 if (segments.size() > 3 &&
1122 base::StartsWith(segments[3], "(ANGLE",
1123 base::CompareCase::INSENSITIVE_ASCII)) {
1124 gl_type = kGLTypeANGLE;
1125 }
1126 } else {
1127 number = segments[0];
1128 gl_type = kGLTypeGL;
1129 }
1130
1131 if (gl_type_ != kGLTypeNone && gl_type_ != gl_type)
1132 return true;
1133 if (gl_version_info_.get() != NULL && !gl_version_info_->Contains(number))
1134 return true;
1135 return false;
1136 }
1137
1138 // static 201 // static
1139 GpuControlList::GpuControlListEntry::MultiGpuStyle 202 GpuControlList::GLType GpuControlList::More::GetDefaultGLType() {
1140 GpuControlList::GpuControlListEntry::StringToMultiGpuStyle(
1141 const std::string& style) {
1142 if (style == kMultiGpuStyleStringOptimus)
1143 return kMultiGpuStyleOptimus;
1144 if (style == kMultiGpuStyleStringAMDSwitchable)
1145 return kMultiGpuStyleAMDSwitchable;
1146 if (style == kMultiGpuStyleStringAMDSwitchableIntegrated)
1147 return kMultiGpuStyleAMDSwitchableIntegrated;
1148 if (style == kMultiGpuStyleStringAMDSwitchableDiscrete)
1149 return kMultiGpuStyleAMDSwitchableDiscrete;
1150 return kMultiGpuStyleNone;
1151 }
1152
1153 // static
1154 GpuControlList::GpuControlListEntry::MultiGpuCategory
1155 GpuControlList::GpuControlListEntry::StringToMultiGpuCategory(
1156 const std::string& category) {
1157 if (category == kMultiGpuCategoryStringPrimary)
1158 return kMultiGpuCategoryPrimary;
1159 if (category == kMultiGpuCategoryStringSecondary)
1160 return kMultiGpuCategorySecondary;
1161 if (category == kMultiGpuCategoryStringActive)
1162 return kMultiGpuCategoryActive;
1163 if (category == kMultiGpuCategoryStringAny)
1164 return kMultiGpuCategoryAny;
1165 return kMultiGpuCategoryNone;
1166 }
1167
1168 // static
1169 GpuControlList::GpuControlListEntry::GLType
1170 GpuControlList::GpuControlListEntry::StringToGLType(
1171 const std::string& gl_type) {
1172 if (gl_type == kGLTypeStringGL)
1173 return kGLTypeGL;
1174 if (gl_type == kGLTypeStringGLES)
1175 return kGLTypeGLES;
1176 if (gl_type == kGLTypeStringANGLE)
1177 return kGLTypeANGLE;
1178 return kGLTypeNone;
1179 }
1180
1181 // static
1182 GpuControlList::GpuControlListEntry::GLType
1183 GpuControlList::GpuControlListEntry::GetDefaultGLType() {
1184 #if defined(OS_CHROMEOS) 203 #if defined(OS_CHROMEOS)
1185 return kGLTypeGL; 204 return kGLTypeGL;
1186 #elif defined(OS_LINUX) || defined(OS_OPENBSD) 205 #elif defined(OS_LINUX) || defined(OS_OPENBSD)
1187 return kGLTypeGL; 206 return kGLTypeGL;
1188 #elif defined(OS_MACOSX) 207 #elif defined(OS_MACOSX)
1189 return kGLTypeGL; 208 return kGLTypeGL;
1190 #elif defined(OS_WIN) 209 #elif defined(OS_WIN)
1191 return kGLTypeANGLE; 210 return kGLTypeANGLE;
1192 #elif defined(OS_ANDROID) 211 #elif defined(OS_ANDROID)
1193 return kGLTypeGLES; 212 return kGLTypeGLES;
1194 #else 213 #else
1195 return kGLTypeNone; 214 return kGLTypeNone;
1196 #endif 215 #endif
1197 } 216 }
1198 217
1199 void GpuControlList::GpuControlListEntry::LogControlListMatch( 218 void GpuControlList::Entry::LogControlListMatch(
1200 const std::string& control_list_logging_name) const { 219 const std::string& control_list_logging_name) const {
1201 static const char kControlListMatchMessage[] = 220 static const char kControlListMatchMessage[] =
1202 "Control list match for rule #%u in %s."; 221 "Control list match for rule #%u in %s.";
1203 VLOG(1) << base::StringPrintf(kControlListMatchMessage, id_, 222 VLOG(1) << base::StringPrintf(kControlListMatchMessage, id,
1204 control_list_logging_name.c_str()); 223 control_list_logging_name.c_str());
1205 } 224 }
1206 225
1207 bool GpuControlList::GpuControlListEntry::Contains( 226 bool GpuControlList::DriverInfo::Contains(const GPUInfo& gpu_info) const {
Ken Russell (switch to Gerrit) 2017/03/31 02:37:07 Nice refactoring here and throughout of the previo
Zhenyao Mo 2017/03/31 19:14:14 Acknowledged.
1208 OsType os_type, const std::string& os_version, 227 if (StringMismatch(gpu_info.driver_vendor, driver_vendor)) {
1209 const GPUInfo& gpu_info) const {
1210 DCHECK(os_type != kOsAny);
1211 if (os_info_.get() != NULL && !os_info_->Contains(os_type, os_version))
1212 return false; 228 return false;
1213 if (vendor_id_ != 0) { 229 }
230 if (driver_version.IsSpecified() && !gpu_info.driver_version.empty() &&
231 !driver_version.Contains(gpu_info.driver_version)) {
232 return false;
233 }
234 if (driver_date.IsSpecified() && !gpu_info.driver_date.empty() &&
235 !driver_date.Contains(gpu_info.driver_date, '-')) {
236 return false;
237 }
238 return true;
239 }
240
241 bool GpuControlList::GLStrings::Contains(const GPUInfo& gpu_info) const {
242 if (StringMismatch(gpu_info.gl_version, gl_version))
243 return false;
244 if (StringMismatch(gpu_info.gl_vendor, gl_vendor))
245 return false;
246 if (StringMismatch(gpu_info.gl_renderer, gl_renderer))
247 return false;
248 if (StringMismatch(gpu_info.gl_extensions, gl_extensions))
249 return false;
250 return true;
251 }
252
253 bool GpuControlList::MachineModelInfo::Contains(const GPUInfo& gpu_info) const {
254 if (machine_model_name_size > 0) {
255 if (gpu_info.machine_model_name.empty())
256 return false;
257 bool found_match = false;
258 for (size_t ii = 0; ii < machine_model_name_size; ++ii) {
259 if (RE2::FullMatch(gpu_info.machine_model_name,
260 machine_model_names[ii])) {
261 found_match = true;
262 break;
263 }
264 }
265 if (!found_match)
266 return false;
267 }
268 if (machine_model_version.IsSpecified() &&
269 (gpu_info.machine_model_version.empty() ||
270 !machine_model_version.Contains(gpu_info.machine_model_version))) {
271 return false;
272 }
273 return true;
274 }
275
276 bool GpuControlList::More::Contains(const GPUInfo& gpu_info) const {
277 if (GLVersionInfoMismatch(gpu_info.gl_version)) {
278 return false;
279 }
280 if (gl_reset_notification_strategy != 0 &&
281 gl_reset_notification_strategy !=
282 gpu_info.gl_reset_notification_strategy) {
283 return false;
284 }
285 if (gpu_count.IsSpecified()) {
286 size_t count = gpu_info.secondary_gpus.size() + 1;
287 if (!gpu_count.Contains(std::to_string(count))) {
288 return false;
289 }
290 }
291 if (!direct_rendering && gpu_info.direct_rendering) {
292 return false;
293 }
294 if (in_process_gpu && !gpu_info.in_process_gpu) {
295 return false;
296 }
297 if (pixel_shader_version.IsSpecified() &&
298 !pixel_shader_version.Contains(gpu_info.pixel_shader_version)) {
299 return false;
300 }
301 return true;
302 }
303
304 bool GpuControlList::Conditions::Contains(OsType target_os_type,
305 const std::string& target_os_version,
306 const GPUInfo& gpu_info) const {
307 DCHECK(target_os_type != kOsAny);
308 if (os_type != kOsAny) {
309 if (os_type != target_os_type)
310 return false;
311 if (os_version.IsSpecified() && !os_version.Contains(target_os_version))
312 return false;
313 }
314 if (vendor_id != 0) {
1214 std::vector<GPUInfo::GPUDevice> candidates; 315 std::vector<GPUInfo::GPUDevice> candidates;
1215 switch (multi_gpu_category_) { 316 switch (multi_gpu_category) {
1216 case kMultiGpuCategoryPrimary: 317 case kMultiGpuCategoryPrimary:
1217 candidates.push_back(gpu_info.gpu); 318 candidates.push_back(gpu_info.gpu);
1218 break; 319 break;
1219 case kMultiGpuCategorySecondary: 320 case kMultiGpuCategorySecondary:
1220 candidates = gpu_info.secondary_gpus; 321 candidates = gpu_info.secondary_gpus;
1221 break; 322 break;
1222 case kMultiGpuCategoryAny: 323 case kMultiGpuCategoryAny:
1223 candidates = gpu_info.secondary_gpus; 324 candidates = gpu_info.secondary_gpus;
1224 candidates.push_back(gpu_info.gpu); 325 candidates.push_back(gpu_info.gpu);
1225 break; 326 break;
1226 case kMultiGpuCategoryActive: 327 case kMultiGpuCategoryActive:
328 case kMultiGpuCategoryNone:
329 // If gpu catemory is not specified, default to the active gpu.
Ken Russell (switch to Gerrit) 2017/03/31 02:37:06 typo: catemory -> category
Zhenyao Mo 2017/03/31 19:14:14 Done.
1227 if (gpu_info.gpu.active || gpu_info.secondary_gpus.empty()) 330 if (gpu_info.gpu.active || gpu_info.secondary_gpus.empty())
1228 candidates.push_back(gpu_info.gpu); 331 candidates.push_back(gpu_info.gpu);
1229 for (size_t ii = 0; ii < gpu_info.secondary_gpus.size(); ++ii) { 332 for (size_t ii = 0; ii < gpu_info.secondary_gpus.size(); ++ii) {
1230 if (gpu_info.secondary_gpus[ii].active) 333 if (gpu_info.secondary_gpus[ii].active)
1231 candidates.push_back(gpu_info.secondary_gpus[ii]); 334 candidates.push_back(gpu_info.secondary_gpus[ii]);
1232 } 335 }
1233 if (candidates.empty()) 336 if (candidates.empty())
1234 candidates.push_back(gpu_info.gpu); 337 candidates.push_back(gpu_info.gpu);
1235 default:
1236 break;
1237 } 338 }
1238 339
1239 GPUInfo::GPUDevice gpu; 340 GPUInfo::GPUDevice gpu;
1240 gpu.vendor_id = vendor_id_; 341 gpu.vendor_id = vendor_id;
1241 bool found = false; 342 bool found = false;
1242 if (device_id_list_.empty()) { 343 if (device_id_size == 0) {
1243 for (size_t ii = 0; ii < candidates.size(); ++ii) { 344 for (size_t ii = 0; ii < candidates.size(); ++ii) {
1244 if (gpu.vendor_id == candidates[ii].vendor_id) { 345 if (gpu.vendor_id == candidates[ii].vendor_id) {
1245 found = true; 346 found = true;
1246 break; 347 break;
1247 } 348 }
1248 } 349 }
1249 } else { 350 } else {
1250 for (size_t ii = 0; ii < device_id_list_.size(); ++ii) { 351 for (size_t ii = 0; ii < device_id_size; ++ii) {
1251 gpu.device_id = device_id_list_[ii]; 352 gpu.device_id = device_ids[ii];
1252 for (size_t jj = 0; jj < candidates.size(); ++jj) { 353 for (size_t jj = 0; jj < candidates.size(); ++jj) {
1253 if (gpu.vendor_id == candidates[jj].vendor_id && 354 if (gpu.vendor_id == candidates[jj].vendor_id &&
1254 gpu.device_id == candidates[jj].device_id) { 355 gpu.device_id == candidates[jj].device_id) {
1255 found = true; 356 found = true;
1256 break; 357 break;
1257 } 358 }
1258 } 359 }
1259 } 360 }
1260 } 361 }
1261 if (!found) 362 if (!found)
1262 return false; 363 return false;
1263 } 364 }
1264 switch (multi_gpu_style_) { 365 switch (multi_gpu_style) {
1265 case kMultiGpuStyleOptimus: 366 case kMultiGpuStyleOptimus:
1266 if (!gpu_info.optimus) 367 if (!gpu_info.optimus)
1267 return false; 368 return false;
1268 break; 369 break;
1269 case kMultiGpuStyleAMDSwitchable: 370 case kMultiGpuStyleAMDSwitchable:
1270 if (!gpu_info.amd_switchable) 371 if (!gpu_info.amd_switchable)
1271 return false; 372 return false;
1272 break; 373 break;
1273 case kMultiGpuStyleAMDSwitchableDiscrete: 374 case kMultiGpuStyleAMDSwitchableDiscrete:
1274 if (!gpu_info.amd_switchable) 375 if (!gpu_info.amd_switchable)
1275 return false; 376 return false;
1276 // The discrete GPU is always the primary GPU. 377 // The discrete GPU is always the primary GPU.
1277 // This is guaranteed by GpuInfoCollector. 378 // This is guaranteed by GpuInfoCollector.
1278 if (!gpu_info.gpu.active) 379 if (!gpu_info.gpu.active)
1279 return false; 380 return false;
1280 break; 381 break;
1281 case kMultiGpuStyleAMDSwitchableIntegrated: 382 case kMultiGpuStyleAMDSwitchableIntegrated:
1282 if (!gpu_info.amd_switchable) 383 if (!gpu_info.amd_switchable)
1283 return false; 384 return false;
1284 // Assume the integrated GPU is the first in the secondary GPU list. 385 // Assume the integrated GPU is the first in the secondary GPU list.
1285 if (gpu_info.secondary_gpus.size() == 0 || 386 if (gpu_info.secondary_gpus.size() == 0 ||
1286 !gpu_info.secondary_gpus[0].active) 387 !gpu_info.secondary_gpus[0].active)
1287 return false; 388 return false;
1288 break; 389 break;
1289 case kMultiGpuStyleNone: 390 case kMultiGpuStyleNone:
1290 break; 391 break;
1291 } 392 }
1292 if (StringMismatch(gpu_info.driver_vendor, driver_vendor_info_)) 393 if (driver_info && !driver_info->Contains(gpu_info)) {
1293 return false; 394 return false;
1294 if (driver_version_info_.get() != NULL && !gpu_info.driver_version.empty()) {
1295 if (!driver_version_info_->Contains(gpu_info.driver_version))
1296 return false;
1297 } 395 }
1298 if (driver_date_info_.get() != NULL && !gpu_info.driver_date.empty()) { 396 if (gl_strings && !gl_strings->Contains(gpu_info)) {
1299 if (!driver_date_info_->Contains(gpu_info.driver_date, '-')) 397 return false;
1300 return false;
1301 } 398 }
1302 if (GLVersionInfoMismatch(gpu_info.gl_version)) 399 if (machine_model_info && !machine_model_info->Contains(gpu_info)) {
1303 return false; 400 return false;
1304 if (StringMismatch(gpu_info.gl_version, gl_version_string_info_)) 401 }
402 if (more && !more->Contains(gpu_info)) {
1305 return false; 403 return false;
1306 if (StringMismatch(gpu_info.gl_vendor, gl_vendor_info_))
1307 return false;
1308 if (StringMismatch(gpu_info.gl_renderer, gl_renderer_info_))
1309 return false;
1310 if (StringMismatch(gpu_info.gl_extensions, gl_extensions_info_))
1311 return false;
1312 if (gl_reset_notification_strategy_info_.get() != NULL &&
1313 !gl_reset_notification_strategy_info_->Contains(
1314 gpu_info.gl_reset_notification_strategy))
1315 return false;
1316 if (!machine_model_name_list_.empty()) {
1317 if (gpu_info.machine_model_name.empty())
1318 return false;
1319 bool found_match = false;
1320 for (size_t ii = 0; ii < machine_model_name_list_.size(); ++ii) {
1321 if (RE2::FullMatch(gpu_info.machine_model_name,
1322 machine_model_name_list_[ii])) {
1323 found_match = true;
1324 break;
1325 }
1326 }
1327 if (!found_match)
1328 return false;
1329 }
1330 if (machine_model_version_info_.get() != NULL &&
1331 (gpu_info.machine_model_version.empty() ||
1332 !machine_model_version_info_->Contains(gpu_info.machine_model_version)))
1333 return false;
1334 if (gpu_count_info_.get() != NULL &&
1335 !gpu_count_info_->Contains(gpu_info.secondary_gpus.size() + 1))
1336 return false;
1337 if (direct_rendering_info_.get() != NULL &&
1338 !direct_rendering_info_->Contains(gpu_info.direct_rendering))
1339 return false;
1340 if (in_process_gpu_info_.get() != NULL &&
1341 !in_process_gpu_info_->Contains(gpu_info.in_process_gpu))
1342 return false;
1343 if (!cpu_brand_.empty()) {
1344 base::CPU cpu_info;
1345 if (StringMismatch(cpu_info.cpu_brand(), cpu_brand_))
1346 return false;
1347 }
1348 if (pixel_shader_version_info_.get() != NULL) {
1349 if (!pixel_shader_version_info_->Contains(gpu_info.pixel_shader_version))
1350 return false;
1351 }
1352
1353 for (size_t i = 0; i < exceptions_.size(); ++i) {
1354 if (exceptions_[i]->Contains(os_type, os_version, gpu_info) &&
1355 !exceptions_[i]->NeedsMoreInfo(gpu_info, true))
1356 return false;
1357 } 404 }
1358 return true; 405 return true;
1359 } 406 }
1360 407
1361 bool GpuControlList::GpuControlListEntry::NeedsMoreInfo( 408 bool GpuControlList::Entry::Contains(OsType target_os_type,
1362 const GPUInfo& gpu_info, 409 const std::string& target_os_version,
1363 bool consider_exceptions) const { 410 const GPUInfo& gpu_info) const {
411 if (!conditions.Contains(target_os_type, target_os_version, gpu_info)) {
412 return false;
413 }
414 for (size_t ii = 0; ii < exception_size; ++ii) {
415 if (exceptions[ii].Contains(target_os_type, target_os_version, gpu_info) &&
416 !exceptions[ii].NeedsMoreInfo(gpu_info)) {
417 return false;
418 }
419 }
420 return true;
421 }
422
423 bool GpuControlList::Conditions::NeedsMoreInfo(const GPUInfo& gpu_info) const {
1364 // We only check for missing info that might be collected with a gl context. 424 // We only check for missing info that might be collected with a gl context.
1365 // If certain info is missing due to some error, say, we fail to collect 425 // If certain info is missing due to some error, say, we fail to collect
1366 // vendor_id/device_id, then even if we launch GPU process and create a gl 426 // vendor_id/device_id, then even if we launch GPU process and create a gl
1367 // context, we won't gather such missing info, so we still return false. 427 // context, we won't gather such missing info, so we still return false.
1368 if (!driver_vendor_info_.empty() && gpu_info.driver_vendor.empty()) 428 if (driver_info) {
1369 return true; 429 if (driver_info->driver_vendor && gpu_info.driver_vendor.empty()) {
1370 if (driver_version_info_.get() && gpu_info.driver_version.empty()) 430 return true;
1371 return true; 431 }
1372 if ((gl_version_info_.get() || !gl_version_string_info_.empty()) && 432 if (driver_info->driver_version.IsSpecified() &&
433 gpu_info.driver_version.empty()) {
434 return true;
435 }
436 }
437 if (((more && more->gl_version.IsSpecified()) ||
438 (gl_strings && gl_strings->gl_version)) &&
1373 gpu_info.gl_version.empty()) { 439 gpu_info.gl_version.empty()) {
Ken Russell (switch to Gerrit) 2017/03/31 02:37:06 It's a little hard to look at this updated conditi
Zhenyao Mo 2017/03/31 19:14:14 I think the confusion comes from we have More::gl_
1374 return true; 440 return true;
1375 } 441 }
1376 if (!gl_vendor_info_.empty() && gpu_info.gl_vendor.empty()) 442 if (gl_strings && gl_strings->gl_vendor && gpu_info.gl_vendor.empty())
1377 return true; 443 return true;
1378 if (!gl_renderer_info_.empty() && gpu_info.gl_renderer.empty()) 444 if (gl_strings && gl_strings->gl_renderer && gpu_info.gl_renderer.empty())
1379 return true; 445 return true;
1380 if (pixel_shader_version_info_.get() != NULL && 446 if (more && more->pixel_shader_version.IsSpecified() &&
1381 gpu_info.pixel_shader_version.empty()) 447 gpu_info.pixel_shader_version.empty()) {
1382 return true;
1383
1384 if (consider_exceptions) {
1385 for (size_t i = 0; i < exceptions_.size(); ++i) {
1386 if (exceptions_[i]->NeedsMoreInfo(gpu_info, consider_exceptions))
1387 return true;
1388 }
1389 }
1390
1391 return false;
1392 }
1393
1394 GpuControlList::OsType GpuControlList::GpuControlListEntry::GetOsType() const {
1395 if (os_info_.get() == NULL)
1396 return kOsAny;
1397 return os_info_->type();
1398 }
1399
1400 uint32_t GpuControlList::GpuControlListEntry::id() const {
1401 return id_;
1402 }
1403
1404 bool GpuControlList::GpuControlListEntry::disabled() const {
1405 return disabled_;
1406 }
1407
1408 const std::set<int>& GpuControlList::GpuControlListEntry::features() const {
1409 return features_;
1410 }
1411
1412 void GpuControlList::GpuControlListEntry::GetFeatureNames(
1413 base::ListValue* feature_names,
1414 const FeatureMap& feature_map,
1415 bool supports_feature_type_all) const {
1416 DCHECK(feature_names);
1417 if (supports_feature_type_all && features_.size() == feature_map.size()) {
1418 feature_names->AppendString("all");
1419 return;
1420 }
1421 for (FeatureMap::const_iterator iter = feature_map.begin();
1422 iter != feature_map.end(); ++iter) {
1423 if (features_.count(iter->second) > 0)
1424 feature_names->AppendString(iter->first);
1425 }
1426 }
1427
1428 // static
1429 bool GpuControlList::GpuControlListEntry::StringToFeature(
1430 const std::string& feature_name, int* feature_id,
1431 const FeatureMap& feature_map) {
1432 FeatureMap::const_iterator iter = feature_map.find(feature_name);
1433 if (iter != feature_map.end()) {
1434 *feature_id = iter->second;
1435 return true; 448 return true;
1436 } 449 }
1437 return false; 450 return false;
1438 } 451 }
1439 452
1440 GpuControlList::GpuControlList() 453 bool GpuControlList::Entry::NeedsMoreInfo(const GPUInfo& gpu_info,
1441 : max_entry_id_(0), 454 bool consider_exceptions) const {
455 if (conditions.NeedsMoreInfo(gpu_info))
456 return true;
457 if (consider_exceptions) {
458 for (size_t ii = 0; ii < exception_size; ++ii) {
459 if (exceptions[ii].NeedsMoreInfo(gpu_info))
460 return true;
461 }
462 }
463 return false;
464 }
465
466 void GpuControlList::Entry::GetFeatureNames(
467 base::ListValue* feature_names,
468 const FeatureMap& feature_map) const {
469 DCHECK(feature_names);
470 for (size_t ii = 0; ii < feature_size; ++ii) {
471 auto iter = feature_map.find(features[ii]);
472 DCHECK(iter != feature_map.end());
473 feature_names->AppendString(iter->second);
474 }
475 }
476
477 GpuControlList::GpuControlList(const GpuControlListData& data)
478 : version_(data.version),
479 entry_count_(data.entry_count),
480 entries_(data.entries),
481 max_entry_id_(0),
1442 needs_more_info_(false), 482 needs_more_info_(false),
1443 supports_feature_type_all_(false),
1444 control_list_logging_enabled_(false) { 483 control_list_logging_enabled_(false) {
484 DCHECK_LT(0u, entry_count_);
485 // Assume the newly last added entry has the largest ID.
486 max_entry_id_ = entries_[entry_count_ - 1].id;
1445 } 487 }
1446 488
1447 GpuControlList::~GpuControlList() { 489 GpuControlList::~GpuControlList() {
1448 Clear();
1449 } 490 }
1450 491
1451 bool GpuControlList::LoadList( 492 std::set<int> GpuControlList::MakeDecision(GpuControlList::OsType os,
1452 const std::string& json_context, 493 const std::string& os_version,
1453 GpuControlList::OsFilter os_filter) { 494 const GPUInfo& gpu_info) {
1454 std::unique_ptr<base::DictionaryValue> root =
1455 base::DictionaryValue::From(base::JSONReader::Read(json_context));
1456 if (!root)
1457 return false;
1458 return LoadList(*root, os_filter);
1459 }
1460
1461 bool GpuControlList::LoadList(const base::DictionaryValue& parsed_json,
1462 GpuControlList::OsFilter os_filter) {
1463 std::vector<ScopedGpuControlListEntry> entries;
1464
1465 parsed_json.GetString("version", &version_);
1466 std::vector<std::string> pieces;
1467 if (!ProcessVersionString(version_, '.', &pieces))
1468 return false;
1469
1470 const base::ListValue* list = NULL;
1471 if (!parsed_json.GetList("entries", &list))
1472 return false;
1473
1474 uint32_t max_entry_id = 0;
1475 for (size_t i = 0; i < list->GetSize(); ++i) {
1476 const base::DictionaryValue* list_item = NULL;
1477 bool valid = list->GetDictionary(i, &list_item);
1478 if (!valid || list_item == NULL)
1479 return false;
1480 ScopedGpuControlListEntry entry(GpuControlListEntry::GetEntryFromValue(
1481 list_item, true, feature_map_, supports_feature_type_all_));
1482 if (entry.get() == NULL)
1483 return false;
1484 if (entry->id() > max_entry_id)
1485 max_entry_id = entry->id();
1486 entries.push_back(entry);
1487 }
1488
1489 Clear();
1490 OsType my_os = GetOsType();
1491 for (size_t i = 0; i < entries.size(); ++i) {
1492 OsType entry_os = entries[i]->GetOsType();
1493 if (os_filter == GpuControlList::kAllOs ||
1494 entry_os == kOsAny || entry_os == my_os)
1495 entries_.push_back(entries[i]);
1496 }
1497 max_entry_id_ = max_entry_id;
1498 return true;
1499 }
1500
1501 std::set<int> GpuControlList::MakeDecision(
1502 GpuControlList::OsType os,
1503 std::string os_version,
1504 const GPUInfo& gpu_info) {
1505 active_entries_.clear(); 495 active_entries_.clear();
1506 std::set<int> features; 496 std::set<int> features;
1507 497
1508 needs_more_info_ = false; 498 needs_more_info_ = false;
1509 // Has all features permanently in the list without any possibility of 499 // Has all features permanently in the list without any possibility of
1510 // removal in the future (subset of "features" set). 500 // removal in the future (subset of "features" set).
1511 std::set<int> permanent_features; 501 std::set<int> permanent_features;
1512 // Has all features absent from "features" set that could potentially be 502 // Has all features absent from "features" set that could potentially be
1513 // included later with more information. 503 // included later with more information.
1514 std::set<int> potential_features; 504 std::set<int> potential_features;
1515 505
1516 if (os == kOsAny) 506 if (os == kOsAny)
1517 os = GetOsType(); 507 os = GetOsType();
1518 if (os_version.empty()) 508 std::string processed_os_version = os_version;
1519 os_version = base::SysInfo::OperatingSystemVersion(); 509 if (processed_os_version.empty())
510 processed_os_version = base::SysInfo::OperatingSystemVersion();
511 size_t pos = processed_os_version.find_first_not_of("0123456789.");
512 if (pos != std::string::npos)
513 processed_os_version = processed_os_version.substr(0, pos);
Ken Russell (switch to Gerrit) 2017/03/31 02:37:06 Slightly tricky to recognize that this came from O
Zhenyao Mo 2017/03/31 19:14:14 Done.
1520 514
1521 for (size_t i = 0; i < entries_.size(); ++i) { 515 for (size_t ii = 0; ii < entry_count_; ++ii) {
1522 ScopedGpuControlListEntry entry = entries_[i]; 516 const Entry& entry = entries_[ii];
1523 if (entry->Contains(os, os_version, gpu_info)) { 517 DCHECK_NE(0u, entry.id);
1524 bool needs_more_info_main = entry->NeedsMoreInfo(gpu_info, false); 518 if (entry.Contains(os, processed_os_version, gpu_info)) {
1525 bool needs_more_info_exception = entry->NeedsMoreInfo(gpu_info, true); 519 bool needs_more_info_main = entry.NeedsMoreInfo(gpu_info, false);
520 bool needs_more_info_exception = entry.NeedsMoreInfo(gpu_info, true);
1526 521
1527 if (!entry->disabled()) { 522 if (control_list_logging_enabled_)
1528 if (control_list_logging_enabled_) 523 entry.LogControlListMatch(control_list_logging_name_);
1529 entry->LogControlListMatch(control_list_logging_name_); 524 // Only look at main entry info when deciding what to add to "features"
1530 // Only look at main entry info when deciding what to add to "features" 525 // set. If we don't have enough info for an exception, it's safer if we
1531 // set. If we don't have enough info for an exception, it's safer if we 526 // just ignore the exception and assume the exception doesn't apply.
1532 // just ignore the exception and assume the exception doesn't apply. 527 for (size_t jj = 0; jj < entry.feature_size; ++jj) {
1533 for (std::set<int>::const_iterator iter = entry->features().begin(); 528 int feature = entry.features[jj];
1534 iter != entry->features().end(); ++iter) { 529 if (needs_more_info_main) {
1535 if (needs_more_info_main) { 530 if (!features.count(feature))
1536 if (!features.count(*iter)) 531 potential_features.insert(feature);
1537 potential_features.insert(*iter); 532 } else {
1538 } else { 533 features.insert(feature);
1539 features.insert(*iter); 534 potential_features.erase(feature);
1540 potential_features.erase(*iter); 535 if (!needs_more_info_exception)
1541 if (!needs_more_info_exception) 536 permanent_features.insert(feature);
1542 permanent_features.insert(*iter);
1543 }
1544 } 537 }
1545 } 538 }
1546 539
1547 if (!needs_more_info_main) 540 if (!needs_more_info_main)
1548 active_entries_.push_back(entry); 541 active_entries_.push_back(ii);
1549 } 542 }
1550 } 543 }
1551 544
1552 needs_more_info_ = permanent_features.size() < features.size() || 545 needs_more_info_ = permanent_features.size() < features.size() ||
1553 !potential_features.empty(); 546 !potential_features.empty();
1554 return features; 547 return features;
1555 } 548 }
1556 549
1557 void GpuControlList::GetDecisionEntries(std::vector<uint32_t>* entry_ids, 550 void GpuControlList::GetDecisionEntries(
1558 bool disabled) const { 551 std::vector<uint32_t>* entry_ids) const {
1559 DCHECK(entry_ids); 552 DCHECK(entry_ids);
1560 entry_ids->clear(); 553 entry_ids->clear();
1561 for (size_t i = 0; i < active_entries_.size(); ++i) { 554 for (auto index : active_entries_) {
1562 if (disabled == active_entries_[i]->disabled()) 555 DCHECK_LT(index, entry_count_);
1563 entry_ids->push_back(active_entries_[i]->id()); 556 entry_ids->push_back(entries_[index].id);
1564 } 557 }
1565 } 558 }
1566 559
1567 std::vector<std::string> GpuControlList::GetDisabledExtensions() { 560 std::vector<std::string> GpuControlList::GetDisabledExtensions() {
1568 std::set<std::string> disabled_extensions; 561 std::set<std::string> disabled_extensions;
1569 for (size_t i = 0; i < active_entries_.size(); ++i) { 562 for (auto index : active_entries_) {
1570 GpuControlListEntry* entry = active_entries_[i].get(); 563 DCHECK_LT(index, entry_count_);
1571 564 const Entry& entry = entries_[index];
1572 if (entry->disabled()) 565 for (size_t ii = 0; ii < entry.disabled_extension_size; ++ii) {
1573 continue; 566 disabled_extensions.insert(entry.disabled_extensions[ii]);
1574 567 }
1575 disabled_extensions.insert(entry->disabled_extensions().begin(),
1576 entry->disabled_extensions().end());
1577 } 568 }
1578 return std::vector<std::string>(disabled_extensions.begin(), 569 return std::vector<std::string>(disabled_extensions.begin(),
1579 disabled_extensions.end()); 570 disabled_extensions.end());
1580 } 571 }
1581 572
1582 void GpuControlList::GetReasons(base::ListValue* problem_list, 573 void GpuControlList::GetReasons(base::ListValue* problem_list,
1583 const std::string& tag) const { 574 const std::string& tag) const {
1584 DCHECK(problem_list); 575 DCHECK(problem_list);
1585 for (size_t i = 0; i < active_entries_.size(); ++i) { 576 for (auto index : active_entries_) {
1586 GpuControlListEntry* entry = active_entries_[i].get(); 577 const Entry& entry = entries_[index];
1587 if (entry->disabled())
1588 continue;
1589 std::unique_ptr<base::DictionaryValue> problem(new base::DictionaryValue()); 578 std::unique_ptr<base::DictionaryValue> problem(new base::DictionaryValue());
1590 579
1591 problem->SetString("description", entry->description()); 580 problem->SetString("description", entry.description);
1592 581
1593 base::ListValue* cr_bugs = new base::ListValue(); 582 base::ListValue* cr_bugs = new base::ListValue();
1594 for (size_t j = 0; j < entry->cr_bugs().size(); ++j) 583 for (size_t jj = 0; jj < entry.cr_bug_size; ++jj)
1595 cr_bugs->AppendInteger(entry->cr_bugs()[j]); 584 cr_bugs->AppendInteger(entry.cr_bugs[jj]);
1596 problem->Set("crBugs", cr_bugs); 585 problem->Set("crBugs", cr_bugs);
1597 586
587 // TODO(XXX): Remove this
piman 2017/03/30 23:44:41 nit: can we? :) Otherwise, can you add your userna
Zhenyao Mo 2017/03/31 19:14:14 Done.
1598 base::ListValue* webkit_bugs = new base::ListValue(); 588 base::ListValue* webkit_bugs = new base::ListValue();
1599 for (size_t j = 0; j < entry->webkit_bugs().size(); ++j) {
1600 webkit_bugs->AppendInteger(entry->webkit_bugs()[j]);
1601 }
1602 problem->Set("webkitBugs", webkit_bugs); 589 problem->Set("webkitBugs", webkit_bugs);
1603 590
1604 base::ListValue* features = new base::ListValue(); 591 base::ListValue* features = new base::ListValue();
1605 entry->GetFeatureNames(features, feature_map_, supports_feature_type_all_); 592 entry.GetFeatureNames(features, feature_map_);
1606 problem->Set("affectedGpuSettings", features); 593 problem->Set("affectedGpuSettings", features);
1607 594
1608 DCHECK(tag == "workarounds" || tag == "disabledFeatures"); 595 DCHECK(tag == "workarounds" || tag == "disabledFeatures");
1609 problem->SetString("tag", tag); 596 problem->SetString("tag", tag);
1610 597
1611 problem_list->Append(std::move(problem)); 598 problem_list->Append(std::move(problem));
1612 } 599 }
1613 } 600 }
1614 601
1615 size_t GpuControlList::num_entries() const { 602 size_t GpuControlList::num_entries() const {
1616 return entries_.size(); 603 return entry_count_;
1617 }
1618
1619 bool GpuControlList::has_duplicated_entry_id() const {
1620 std::set<int> ids;
1621 for (size_t i = 0; i < entries_.size(); ++i) {
1622 if (ids.count(entries_[i]->id()) == 0)
1623 ids.insert(entries_[i]->id());
1624 else
1625 return true;
1626 }
1627 return false;
1628 } 604 }
1629 605
1630 uint32_t GpuControlList::max_entry_id() const { 606 uint32_t GpuControlList::max_entry_id() const {
1631 return max_entry_id_; 607 return max_entry_id_;
1632 } 608 }
1633 609
1634 std::string GpuControlList::version() const { 610 std::string GpuControlList::version() const {
1635 return version_; 611 return version_;
1636 } 612 }
1637 613
614 // static
1638 GpuControlList::OsType GpuControlList::GetOsType() { 615 GpuControlList::OsType GpuControlList::GetOsType() {
1639 #if defined(OS_CHROMEOS) 616 #if defined(OS_CHROMEOS)
1640 return kOsChromeOS; 617 return kOsChromeOS;
1641 #elif defined(OS_WIN) 618 #elif defined(OS_WIN)
1642 return kOsWin; 619 return kOsWin;
1643 #elif defined(OS_ANDROID) 620 #elif defined(OS_ANDROID)
1644 return kOsAndroid; 621 return kOsAndroid;
1645 #elif defined(OS_LINUX) || defined(OS_OPENBSD) 622 #elif defined(OS_LINUX) || defined(OS_OPENBSD)
1646 return kOsLinux; 623 return kOsLinux;
1647 #elif defined(OS_MACOSX) 624 #elif defined(OS_MACOSX)
1648 return kOsMacosx; 625 return kOsMacosx;
1649 #else 626 #else
1650 return kOsUnknown; 627 return kOsAny;
1651 #endif 628 #endif
1652 } 629 }
1653 630
1654 void GpuControlList::Clear() {
1655 entries_.clear();
1656 active_entries_.clear();
1657 max_entry_id_ = 0;
1658 }
1659
1660 // static
1661 GpuControlList::NumericOp GpuControlList::StringToNumericOp(
1662 const std::string& op) {
1663 if (op == "=")
1664 return kEQ;
1665 if (op == "<")
1666 return kLT;
1667 if (op == "<=")
1668 return kLE;
1669 if (op == ">")
1670 return kGT;
1671 if (op == ">=")
1672 return kGE;
1673 if (op == "any")
1674 return kAny;
1675 if (op == "between")
1676 return kBetween;
1677 return kUnknown;
1678 }
1679
1680 void GpuControlList::AddSupportedFeature( 631 void GpuControlList::AddSupportedFeature(
1681 const std::string& feature_name, int feature_id) { 632 const std::string& feature_name, int feature_id) {
1682 feature_map_[feature_name] = feature_id; 633 feature_map_[feature_id] = feature_name;
1683 }
1684
1685 void GpuControlList::set_supports_feature_type_all(bool supported) {
1686 supports_feature_type_all_ = supported;
1687 } 634 }
1688 635
1689 } // namespace gpu 636 } // namespace gpu
1690
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698