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
3 // found in the LICENSE file.
5 #include "gpu/config/gpu_control_list.h"
8 #include "base/json/json_reader.h"
9 #include "base/logging.h"
10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_split.h"
12 #include "base/strings/string_util.h"
13 #include "base/strings/stringprintf.h"
14 #include "base/sys_info.h"
15 #include "gpu/config/gpu_info.h"
16 #include "gpu/config/gpu_util.h"
17 #include "third_party/re2/re2/re2.h"
22 // Break a version string into segments. Return true if each segment is
23 // a valid number, and not all segment is 0.
24 bool ProcessVersionString(const std::string
& version_string
,
26 std::vector
<std::string
>* version
) {
28 *version
= base::SplitString(
29 version_string
, std::string(1, splitter
),
30 base::TRIM_WHITESPACE
, base::SPLIT_WANT_ALL
);
31 if (version
->size() == 0)
33 // If the splitter is '-', we assume it's a date with format "mm-dd-yyyy";
34 // we split it into the order of "yyyy", "mm", "dd".
35 if (splitter
== '-') {
36 std::string year
= (*version
)[version
->size() - 1];
37 for (int i
= version
->size() - 1; i
> 0; --i
) {
38 (*version
)[i
] = (*version
)[i
- 1];
43 for (size_t i
= 0; i
< version
->size(); ++i
) {
45 if (!base::StringToUint((*version
)[i
], &num
))
53 // Compare two number strings using numerical ordering.
54 // Return 0 if number = number_ref,
55 // 1 if number > number_ref,
56 // -1 if number < number_ref.
57 int CompareNumericalNumberStrings(
58 const std::string
& number
, const std::string
& number_ref
) {
61 bool valid
= base::StringToUint(number
, &value1
);
63 valid
= base::StringToUint(number_ref
, &value2
);
72 // Compare two number strings using lexical ordering.
73 // Return 0 if number = number_ref,
74 // 1 if number > number_ref,
75 // -1 if number < number_ref.
76 // We only compare as many digits as number_ref contains.
77 // If number_ref is xxx, it's considered as xxx*
78 // For example: CompareLexicalNumberStrings("121", "12") returns 0,
79 // CompareLexicalNumberStrings("12", "121") returns -1.
80 int CompareLexicalNumberStrings(
81 const std::string
& number
, const std::string
& number_ref
) {
82 for (size_t i
= 0; i
< number_ref
.length(); ++i
) {
84 if (i
< number
.length())
85 value1
= number
[i
] - '0';
86 unsigned value2
= number_ref
[i
] - '0';
95 // A mismatch is identified only if both |input| and |pattern| are not empty.
96 bool StringMismatch(const std::string
& input
, const std::string
& pattern
) {
97 if (input
.empty() || pattern
.empty())
99 return !RE2::FullMatch(input
, pattern
);
102 const char kMultiGpuStyleStringAMDSwitchable
[] = "amd_switchable";
103 const char kMultiGpuStyleStringAMDSwitchableDiscrete
[] =
104 "amd_switchable_discrete";
105 const char kMultiGpuStyleStringAMDSwitchableIntegrated
[] =
106 "amd_switchable_integrated";
107 const char kMultiGpuStyleStringOptimus
[] = "optimus";
109 const char kMultiGpuCategoryStringPrimary
[] = "primary";
110 const char kMultiGpuCategoryStringSecondary
[] = "secondary";
111 const char kMultiGpuCategoryStringActive
[] = "active";
112 const char kMultiGpuCategoryStringAny
[] = "any";
114 const char kGLTypeStringGL
[] = "gl";
115 const char kGLTypeStringGLES
[] = "gles";
116 const char kGLTypeStringANGLE
[] = "angle";
118 const char kVersionStyleStringNumerical
[] = "numerical";
119 const char kVersionStyleStringLexical
[] = "lexical";
121 const char kOp
[] = "op";
123 } // namespace anonymous
125 GpuControlList::VersionInfo::VersionInfo(
126 const std::string
& version_op
,
127 const std::string
& version_style
,
128 const std::string
& version_string
,
129 const std::string
& version_string2
)
130 : version_style_(kVersionStyleNumerical
) {
131 op_
= StringToNumericOp(version_op
);
132 if (op_
== kUnknown
|| op_
== kAny
)
134 version_style_
= StringToVersionStyle(version_style
);
135 if (!ProcessVersionString(version_string
, '.', &version_
)) {
139 if (op_
== kBetween
) {
140 if (!ProcessVersionString(version_string2
, '.', &version2_
))
145 GpuControlList::VersionInfo::~VersionInfo() {
148 bool GpuControlList::VersionInfo::Contains(
149 const std::string
& version_string
) const {
150 return Contains(version_string
, '.');
153 bool GpuControlList::VersionInfo::Contains(
154 const std::string
& version_string
, char splitter
) const {
159 std::vector
<std::string
> version
;
160 if (!ProcessVersionString(version_string
, splitter
, &version
))
162 int relation
= Compare(version
, version_
, version_style_
);
164 return (relation
== 0);
166 return (relation
< 0);
168 return (relation
<= 0);
170 return (relation
> 0);
172 return (relation
>= 0);
176 return Compare(version
, version2_
, version_style_
) <= 0;
179 bool GpuControlList::VersionInfo::IsValid() const {
180 return (op_
!= kUnknown
&& version_style_
!= kVersionStyleUnknown
);
183 bool GpuControlList::VersionInfo::IsLexical() const {
184 return version_style_
== kVersionStyleLexical
;
188 int GpuControlList::VersionInfo::Compare(
189 const std::vector
<std::string
>& version
,
190 const std::vector
<std::string
>& version_ref
,
191 VersionStyle version_style
) {
192 DCHECK(version
.size() > 0 && version_ref
.size() > 0);
193 DCHECK(version_style
!= kVersionStyleUnknown
);
194 for (size_t i
= 0; i
< version_ref
.size(); ++i
) {
195 if (i
>= version
.size())
198 // We assume both versions are checked by ProcessVersionString().
199 if (i
> 0 && version_style
== kVersionStyleLexical
)
200 ret
= CompareLexicalNumberStrings(version
[i
], version_ref
[i
]);
202 ret
= CompareNumericalNumberStrings(version
[i
], version_ref
[i
]);
210 GpuControlList::VersionInfo::VersionStyle
211 GpuControlList::VersionInfo::StringToVersionStyle(
212 const std::string
& version_style
) {
213 if (version_style
.empty() || version_style
== kVersionStyleStringNumerical
)
214 return kVersionStyleNumerical
;
215 if (version_style
== kVersionStyleStringLexical
)
216 return kVersionStyleLexical
;
217 return kVersionStyleUnknown
;
220 GpuControlList::OsInfo::OsInfo(const std::string
& os
,
221 const std::string
& version_op
,
222 const std::string
& version_string
,
223 const std::string
& version_string2
) {
224 type_
= StringToOsType(os
);
225 if (type_
!= kOsUnknown
) {
226 version_info_
.reset(new VersionInfo(
227 version_op
, std::string(), version_string
, version_string2
));
231 GpuControlList::OsInfo::~OsInfo() {}
233 bool GpuControlList::OsInfo::Contains(
234 OsType type
, const std::string
& version
) const {
237 if (type_
!= type
&& type_
!= kOsAny
)
239 std::string processed_version
;
240 size_t pos
= version
.find_first_not_of("0123456789.");
241 if (pos
!= std::string::npos
)
242 processed_version
= version
.substr(0, pos
);
244 processed_version
= version
;
246 return version_info_
->Contains(processed_version
);
249 bool GpuControlList::OsInfo::IsValid() const {
250 return type_
!= kOsUnknown
&& version_info_
->IsValid();
253 GpuControlList::OsType
GpuControlList::OsInfo::type() const {
257 GpuControlList::OsType
GpuControlList::OsInfo::StringToOsType(
258 const std::string
& os
) {
261 else if (os
== "macosx")
263 else if (os
== "android")
265 else if (os
== "linux")
267 else if (os
== "chromeos")
269 else if (os
== "any")
274 GpuControlList::FloatInfo::FloatInfo(const std::string
& float_op
,
275 const std::string
& float_value
,
276 const std::string
& float_value2
)
280 op_
= StringToNumericOp(float_op
);
284 if (!base::StringToDouble(float_value
, &dvalue
)) {
288 value_
= static_cast<float>(dvalue
);
289 if (op_
== kBetween
) {
290 if (!base::StringToDouble(float_value2
, &dvalue
)) {
294 value2_
= static_cast<float>(dvalue
);
298 bool GpuControlList::FloatInfo::Contains(float value
) const {
304 return (value
== value_
);
306 return (value
< value_
);
308 return (value
<= value_
);
310 return (value
> value_
);
312 return (value
>= value_
);
313 DCHECK(op_
== kBetween
);
314 return ((value_
<= value
&& value
<= value2_
) ||
315 (value2_
<= value
&& value
<= value_
));
318 bool GpuControlList::FloatInfo::IsValid() const {
319 return op_
!= kUnknown
;
322 GpuControlList::IntInfo::IntInfo(const std::string
& int_op
,
323 const std::string
& int_value
,
324 const std::string
& int_value2
)
328 op_
= StringToNumericOp(int_op
);
331 if (!base::StringToInt(int_value
, &value_
)) {
335 if (op_
== kBetween
&&
336 !base::StringToInt(int_value2
, &value2_
))
340 bool GpuControlList::IntInfo::Contains(int value
) const {
346 return (value
== value_
);
348 return (value
< value_
);
350 return (value
<= value_
);
352 return (value
> value_
);
354 return (value
>= value_
);
355 DCHECK(op_
== kBetween
);
356 return ((value_
<= value
&& value
<= value2_
) ||
357 (value2_
<= value
&& value
<= value_
));
360 bool GpuControlList::IntInfo::IsValid() const {
361 return op_
!= kUnknown
;
364 GpuControlList::BoolInfo::BoolInfo(bool value
) : value_(value
) {}
366 bool GpuControlList::BoolInfo::Contains(bool value
) const {
367 return value_
== value
;
371 GpuControlList::ScopedGpuControlListEntry
372 GpuControlList::GpuControlListEntry::GetEntryFromValue(
373 const base::DictionaryValue
* value
, bool top_level
,
374 const FeatureMap
& feature_map
,
375 bool supports_feature_type_all
) {
377 ScopedGpuControlListEntry
entry(new GpuControlListEntry());
379 size_t dictionary_entry_count
= 0;
383 if (!value
->GetInteger("id", reinterpret_cast<int*>(&id
)) ||
385 LOG(WARNING
) << "Malformed id entry " << entry
->id();
388 dictionary_entry_count
++;
391 if (value
->GetBoolean("disabled", &disabled
)) {
392 entry
->SetDisabled(disabled
);
393 dictionary_entry_count
++;
397 std::string description
;
398 if (value
->GetString("description", &description
)) {
399 entry
->description_
= description
;
400 dictionary_entry_count
++;
402 entry
->description_
= "The GPU is unavailable for an unexplained reason.";
405 const base::ListValue
* cr_bugs
;
406 if (value
->GetList("cr_bugs", &cr_bugs
)) {
407 for (size_t i
= 0; i
< cr_bugs
->GetSize(); ++i
) {
409 if (cr_bugs
->GetInteger(i
, &bug_id
)) {
410 entry
->cr_bugs_
.push_back(bug_id
);
412 LOG(WARNING
) << "Malformed cr_bugs entry " << entry
->id();
416 dictionary_entry_count
++;
419 const base::ListValue
* webkit_bugs
;
420 if (value
->GetList("webkit_bugs", &webkit_bugs
)) {
421 for (size_t i
= 0; i
< webkit_bugs
->GetSize(); ++i
) {
423 if (webkit_bugs
->GetInteger(i
, &bug_id
)) {
424 entry
->webkit_bugs_
.push_back(bug_id
);
426 LOG(WARNING
) << "Malformed webkit_bugs entry " << entry
->id();
430 dictionary_entry_count
++;
433 const base::ListValue
* disabled_extensions
;
434 if (value
->GetList("disabled_extensions", &disabled_extensions
)) {
435 for (size_t i
= 0; i
< disabled_extensions
->GetSize(); ++i
) {
436 std::string disabled_extension
;
437 if (disabled_extensions
->GetString(i
, &disabled_extension
)) {
438 entry
->disabled_extensions_
.push_back(disabled_extension
);
440 LOG(WARNING
) << "Malformed disabled_extensions entry " << entry
->id();
444 dictionary_entry_count
++;
447 const base::DictionaryValue
* os_value
= NULL
;
448 if (value
->GetDictionary("os", &os_value
)) {
450 std::string os_version_op
= "any";
451 std::string os_version_string
;
452 std::string os_version_string2
;
453 os_value
->GetString("type", &os_type
);
454 const base::DictionaryValue
* os_version_value
= NULL
;
455 if (os_value
->GetDictionary("version", &os_version_value
)) {
456 os_version_value
->GetString(kOp
, &os_version_op
);
457 os_version_value
->GetString("value", &os_version_string
);
458 os_version_value
->GetString("value2", &os_version_string2
);
460 if (!entry
->SetOsInfo(os_type
, os_version_op
, os_version_string
,
461 os_version_string2
)) {
462 LOG(WARNING
) << "Malformed os entry " << entry
->id();
465 dictionary_entry_count
++;
468 std::string vendor_id
;
469 if (value
->GetString("vendor_id", &vendor_id
)) {
470 if (!entry
->SetVendorId(vendor_id
)) {
471 LOG(WARNING
) << "Malformed vendor_id entry " << entry
->id();
474 dictionary_entry_count
++;
477 const base::ListValue
* device_id_list
;
478 if (value
->GetList("device_id", &device_id_list
)) {
479 for (size_t i
= 0; i
< device_id_list
->GetSize(); ++i
) {
480 std::string device_id
;
481 if (!device_id_list
->GetString(i
, &device_id
) ||
482 !entry
->AddDeviceId(device_id
)) {
483 LOG(WARNING
) << "Malformed device_id entry " << entry
->id();
487 dictionary_entry_count
++;
490 std::string multi_gpu_style
;
491 if (value
->GetString("multi_gpu_style", &multi_gpu_style
)) {
492 if (!entry
->SetMultiGpuStyle(multi_gpu_style
)) {
493 LOG(WARNING
) << "Malformed multi_gpu_style entry " << entry
->id();
496 dictionary_entry_count
++;
499 std::string multi_gpu_category
;
500 if (value
->GetString("multi_gpu_category", &multi_gpu_category
)) {
501 if (!entry
->SetMultiGpuCategory(multi_gpu_category
)) {
502 LOG(WARNING
) << "Malformed multi_gpu_category entry " << entry
->id();
505 dictionary_entry_count
++;
508 std::string driver_vendor_value
;
509 if (value
->GetString("driver_vendor", &driver_vendor_value
)) {
510 if (!entry
->SetDriverVendorInfo(driver_vendor_value
)) {
511 LOG(WARNING
) << "Malformed driver_vendor entry " << entry
->id();
514 dictionary_entry_count
++;
517 const base::DictionaryValue
* driver_version_value
= NULL
;
518 if (value
->GetDictionary("driver_version", &driver_version_value
)) {
519 std::string driver_version_op
= "any";
520 std::string driver_version_style
;
521 std::string driver_version_string
;
522 std::string driver_version_string2
;
523 driver_version_value
->GetString(kOp
, &driver_version_op
);
524 driver_version_value
->GetString("style", &driver_version_style
);
525 driver_version_value
->GetString("value", &driver_version_string
);
526 driver_version_value
->GetString("value2", &driver_version_string2
);
527 if (!entry
->SetDriverVersionInfo(driver_version_op
,
528 driver_version_style
,
529 driver_version_string
,
530 driver_version_string2
)) {
531 LOG(WARNING
) << "Malformed driver_version entry " << entry
->id();
534 dictionary_entry_count
++;
537 const base::DictionaryValue
* driver_date_value
= NULL
;
538 if (value
->GetDictionary("driver_date", &driver_date_value
)) {
539 std::string driver_date_op
= "any";
540 std::string driver_date_string
;
541 std::string driver_date_string2
;
542 driver_date_value
->GetString(kOp
, &driver_date_op
);
543 driver_date_value
->GetString("value", &driver_date_string
);
544 driver_date_value
->GetString("value2", &driver_date_string2
);
545 if (!entry
->SetDriverDateInfo(driver_date_op
, driver_date_string
,
546 driver_date_string2
)) {
547 LOG(WARNING
) << "Malformed driver_date entry " << entry
->id();
550 dictionary_entry_count
++;
554 if (value
->GetString("gl_type", &gl_type
)) {
555 if (!entry
->SetGLType(gl_type
)) {
556 LOG(WARNING
) << "Malformed gl_type entry " << entry
->id();
559 dictionary_entry_count
++;
562 const base::DictionaryValue
* gl_version_value
= NULL
;
563 if (value
->GetDictionary("gl_version", &gl_version_value
)) {
564 std::string version_op
= "any";
565 std::string version_string
;
566 std::string version_string2
;
567 gl_version_value
->GetString(kOp
, &version_op
);
568 gl_version_value
->GetString("value", &version_string
);
569 gl_version_value
->GetString("value2", &version_string2
);
570 if (!entry
->SetGLVersionInfo(
571 version_op
, version_string
, version_string2
)) {
572 LOG(WARNING
) << "Malformed gl_version entry " << entry
->id();
575 dictionary_entry_count
++;
578 std::string gl_vendor_value
;
579 if (value
->GetString("gl_vendor", &gl_vendor_value
)) {
580 if (!entry
->SetGLVendorInfo(gl_vendor_value
)) {
581 LOG(WARNING
) << "Malformed gl_vendor entry " << entry
->id();
584 dictionary_entry_count
++;
587 std::string gl_renderer_value
;
588 if (value
->GetString("gl_renderer", &gl_renderer_value
)) {
589 if (!entry
->SetGLRendererInfo(gl_renderer_value
)) {
590 LOG(WARNING
) << "Malformed gl_renderer entry " << entry
->id();
593 dictionary_entry_count
++;
596 std::string gl_extensions_value
;
597 if (value
->GetString("gl_extensions", &gl_extensions_value
)) {
598 if (!entry
->SetGLExtensionsInfo(gl_extensions_value
)) {
599 LOG(WARNING
) << "Malformed gl_extensions entry " << entry
->id();
602 dictionary_entry_count
++;
605 const base::DictionaryValue
* gl_reset_notification_strategy_value
= NULL
;
606 if (value
->GetDictionary("gl_reset_notification_strategy",
607 &gl_reset_notification_strategy_value
)) {
609 std::string int_value
;
610 std::string int_value2
;
611 gl_reset_notification_strategy_value
->GetString(kOp
, &op
);
612 gl_reset_notification_strategy_value
->GetString("value", &int_value
);
613 gl_reset_notification_strategy_value
->GetString("value2", &int_value2
);
614 if (!entry
->SetGLResetNotificationStrategyInfo(
615 op
, int_value
, int_value2
)) {
616 LOG(WARNING
) << "Malformed gl_reset_notification_strategy entry "
620 dictionary_entry_count
++;
623 std::string cpu_brand_value
;
624 if (value
->GetString("cpu_info", &cpu_brand_value
)) {
625 if (!entry
->SetCpuBrand(cpu_brand_value
)) {
626 LOG(WARNING
) << "Malformed cpu_brand entry " << entry
->id();
629 dictionary_entry_count
++;
632 const base::DictionaryValue
* perf_graphics_value
= NULL
;
633 if (value
->GetDictionary("perf_graphics", &perf_graphics_value
)) {
635 std::string float_value
;
636 std::string float_value2
;
637 perf_graphics_value
->GetString(kOp
, &op
);
638 perf_graphics_value
->GetString("value", &float_value
);
639 perf_graphics_value
->GetString("value2", &float_value2
);
640 if (!entry
->SetPerfGraphicsInfo(op
, float_value
, float_value2
)) {
641 LOG(WARNING
) << "Malformed perf_graphics entry " << entry
->id();
644 dictionary_entry_count
++;
647 const base::DictionaryValue
* perf_gaming_value
= NULL
;
648 if (value
->GetDictionary("perf_gaming", &perf_gaming_value
)) {
650 std::string float_value
;
651 std::string float_value2
;
652 perf_gaming_value
->GetString(kOp
, &op
);
653 perf_gaming_value
->GetString("value", &float_value
);
654 perf_gaming_value
->GetString("value2", &float_value2
);
655 if (!entry
->SetPerfGamingInfo(op
, float_value
, float_value2
)) {
656 LOG(WARNING
) << "Malformed perf_gaming entry " << entry
->id();
659 dictionary_entry_count
++;
662 const base::DictionaryValue
* perf_overall_value
= NULL
;
663 if (value
->GetDictionary("perf_overall", &perf_overall_value
)) {
665 std::string float_value
;
666 std::string float_value2
;
667 perf_overall_value
->GetString(kOp
, &op
);
668 perf_overall_value
->GetString("value", &float_value
);
669 perf_overall_value
->GetString("value2", &float_value2
);
670 if (!entry
->SetPerfOverallInfo(op
, float_value
, float_value2
)) {
671 LOG(WARNING
) << "Malformed perf_overall entry " << entry
->id();
674 dictionary_entry_count
++;
677 const base::ListValue
* machine_model_name_list
;
678 if (value
->GetList("machine_model_name", &machine_model_name_list
)) {
679 for (size_t i
= 0; i
< machine_model_name_list
->GetSize(); ++i
) {
680 std::string model_name
;
681 if (!machine_model_name_list
->GetString(i
, &model_name
) ||
682 !entry
->AddMachineModelName(model_name
)) {
683 LOG(WARNING
) << "Malformed machine_model_name entry " << entry
->id();
687 dictionary_entry_count
++;
690 const base::DictionaryValue
* machine_model_version_value
= NULL
;
691 if (value
->GetDictionary(
692 "machine_model_version", &machine_model_version_value
)) {
693 std::string version_op
= "any";
694 std::string version_string
;
695 std::string version_string2
;
696 machine_model_version_value
->GetString(kOp
, &version_op
);
697 machine_model_version_value
->GetString("value", &version_string
);
698 machine_model_version_value
->GetString("value2", &version_string2
);
699 if (!entry
->SetMachineModelVersionInfo(
700 version_op
, version_string
, version_string2
)) {
701 LOG(WARNING
) << "Malformed machine_model_version entry " << entry
->id();
704 dictionary_entry_count
++;
707 const base::DictionaryValue
* gpu_count_value
= NULL
;
708 if (value
->GetDictionary("gpu_count", &gpu_count_value
)) {
710 std::string int_value
;
711 std::string int_value2
;
712 gpu_count_value
->GetString(kOp
, &op
);
713 gpu_count_value
->GetString("value", &int_value
);
714 gpu_count_value
->GetString("value2", &int_value2
);
715 if (!entry
->SetGpuCountInfo(op
, int_value
, int_value2
)) {
716 LOG(WARNING
) << "Malformed gpu_count entry " << entry
->id();
719 dictionary_entry_count
++;
722 bool direct_rendering
;
723 if (value
->GetBoolean("direct_rendering", &direct_rendering
)) {
724 entry
->SetDirectRenderingInfo(direct_rendering
);
725 dictionary_entry_count
++;
729 if (value
->GetBoolean("in_process_gpu", &in_process_gpu
)) {
730 entry
->SetInProcessGPUInfo(in_process_gpu
);
731 dictionary_entry_count
++;
735 const base::ListValue
* feature_value
= NULL
;
736 if (value
->GetList("features", &feature_value
)) {
737 std::vector
<std::string
> feature_list
;
738 for (size_t i
= 0; i
< feature_value
->GetSize(); ++i
) {
740 if (feature_value
->GetString(i
, &feature
)) {
741 feature_list
.push_back(feature
);
743 LOG(WARNING
) << "Malformed feature entry " << entry
->id();
747 if (!entry
->SetFeatures(
748 feature_list
, feature_map
, supports_feature_type_all
)) {
749 LOG(WARNING
) << "Malformed feature entry " << entry
->id();
752 dictionary_entry_count
++;
757 const base::ListValue
* exception_list_value
= NULL
;
758 if (value
->GetList("exceptions", &exception_list_value
)) {
759 for (size_t i
= 0; i
< exception_list_value
->GetSize(); ++i
) {
760 const base::DictionaryValue
* exception_value
= NULL
;
761 if (!exception_list_value
->GetDictionary(i
, &exception_value
)) {
762 LOG(WARNING
) << "Malformed exceptions entry " << entry
->id();
765 ScopedGpuControlListEntry
exception(GetEntryFromValue(
766 exception_value
, false, feature_map
, supports_feature_type_all
));
767 if (exception
.get() == NULL
) {
768 LOG(WARNING
) << "Malformed exceptions entry " << entry
->id();
771 // Exception should inherit vendor_id from parent, otherwise if only
772 // device_ids are specified in Exception, the info will be incomplete.
773 if (exception
->vendor_id_
== 0 && entry
->vendor_id_
!= 0)
774 exception
->vendor_id_
= entry
->vendor_id_
;
775 entry
->AddException(exception
);
777 dictionary_entry_count
++;
781 if (value
->size() != dictionary_entry_count
) {
782 LOG(WARNING
) << "Entry with unknown fields " << entry
->id();
786 // If GL_VERSION is specified, but no info about whether it's GL or GLES,
787 // we use the default for the platform. See GLType enum declaration.
788 if (entry
->gl_version_info_
.get() != NULL
&& entry
->gl_type_
== kGLTypeNone
)
789 entry
->gl_type_
= GetDefaultGLType();
794 GpuControlList::GpuControlListEntry::GpuControlListEntry()
798 multi_gpu_style_(kMultiGpuStyleNone
),
799 multi_gpu_category_(kMultiGpuCategoryPrimary
),
800 gl_type_(kGLTypeNone
) {
803 GpuControlList::GpuControlListEntry::~GpuControlListEntry() { }
805 bool GpuControlList::GpuControlListEntry::SetId(uint32 id
) {
813 void GpuControlList::GpuControlListEntry::SetDisabled(bool disabled
) {
814 disabled_
= disabled
;
817 bool GpuControlList::GpuControlListEntry::SetOsInfo(
818 const std::string
& os
,
819 const std::string
& version_op
,
820 const std::string
& version_string
,
821 const std::string
& version_string2
) {
822 os_info_
.reset(new OsInfo(os
, version_op
, version_string
, version_string2
));
823 return os_info_
->IsValid();
826 bool GpuControlList::GpuControlListEntry::SetVendorId(
827 const std::string
& vendor_id_string
) {
829 return base::HexStringToUInt(vendor_id_string
, &vendor_id_
) &&
833 bool GpuControlList::GpuControlListEntry::AddDeviceId(
834 const std::string
& device_id_string
) {
835 uint32 device_id
= 0;
836 if (base::HexStringToUInt(device_id_string
, &device_id
) && device_id
!= 0) {
837 device_id_list_
.push_back(device_id
);
843 bool GpuControlList::GpuControlListEntry::SetMultiGpuStyle(
844 const std::string
& multi_gpu_style_string
) {
845 MultiGpuStyle style
= StringToMultiGpuStyle(multi_gpu_style_string
);
846 if (style
== kMultiGpuStyleNone
)
848 multi_gpu_style_
= style
;
852 bool GpuControlList::GpuControlListEntry::SetMultiGpuCategory(
853 const std::string
& multi_gpu_category_string
) {
854 MultiGpuCategory category
=
855 StringToMultiGpuCategory(multi_gpu_category_string
);
856 if (category
== kMultiGpuCategoryNone
)
858 multi_gpu_category_
= category
;
862 bool GpuControlList::GpuControlListEntry::SetGLType(
863 const std::string
& gl_type_string
) {
864 GLType gl_type
= StringToGLType(gl_type_string
);
865 if (gl_type
== kGLTypeNone
)
871 bool GpuControlList::GpuControlListEntry::SetDriverVendorInfo(
872 const std::string
& vendor_value
) {
873 driver_vendor_info_
= vendor_value
;
874 return !driver_vendor_info_
.empty();
877 bool GpuControlList::GpuControlListEntry::SetDriverVersionInfo(
878 const std::string
& version_op
,
879 const std::string
& version_style
,
880 const std::string
& version_string
,
881 const std::string
& version_string2
) {
882 driver_version_info_
.reset(new VersionInfo(
883 version_op
, version_style
, version_string
, version_string2
));
884 return driver_version_info_
->IsValid();
887 bool GpuControlList::GpuControlListEntry::SetDriverDateInfo(
888 const std::string
& date_op
,
889 const std::string
& date_string
,
890 const std::string
& date_string2
) {
891 driver_date_info_
.reset(
892 new VersionInfo(date_op
, std::string(), date_string
, date_string2
));
893 return driver_date_info_
->IsValid();
896 bool GpuControlList::GpuControlListEntry::SetGLVersionInfo(
897 const std::string
& version_op
,
898 const std::string
& version_string
,
899 const std::string
& version_string2
) {
900 gl_version_info_
.reset(new VersionInfo(
901 version_op
, std::string(), version_string
, version_string2
));
902 return gl_version_info_
->IsValid();
905 bool GpuControlList::GpuControlListEntry::SetGLVendorInfo(
906 const std::string
& vendor_value
) {
907 gl_vendor_info_
= vendor_value
;
908 return !gl_vendor_info_
.empty();
911 bool GpuControlList::GpuControlListEntry::SetGLRendererInfo(
912 const std::string
& renderer_value
) {
913 gl_renderer_info_
= renderer_value
;
914 return !gl_renderer_info_
.empty();
917 bool GpuControlList::GpuControlListEntry::SetGLExtensionsInfo(
918 const std::string
& extensions_value
) {
919 gl_extensions_info_
= extensions_value
;
920 return !gl_extensions_info_
.empty();
923 bool GpuControlList::GpuControlListEntry::SetGLResetNotificationStrategyInfo(
924 const std::string
& op
,
925 const std::string
& int_string
,
926 const std::string
& int_string2
) {
927 gl_reset_notification_strategy_info_
.reset(
928 new IntInfo(op
, int_string
, int_string2
));
929 return gl_reset_notification_strategy_info_
->IsValid();
932 bool GpuControlList::GpuControlListEntry::SetCpuBrand(
933 const std::string
& cpu_value
) {
934 cpu_brand_
= cpu_value
;
935 return !cpu_brand_
.empty();
938 bool GpuControlList::GpuControlListEntry::SetPerfGraphicsInfo(
939 const std::string
& op
,
940 const std::string
& float_string
,
941 const std::string
& float_string2
) {
942 perf_graphics_info_
.reset(new FloatInfo(op
, float_string
, float_string2
));
943 return perf_graphics_info_
->IsValid();
946 bool GpuControlList::GpuControlListEntry::SetPerfGamingInfo(
947 const std::string
& op
,
948 const std::string
& float_string
,
949 const std::string
& float_string2
) {
950 perf_gaming_info_
.reset(new FloatInfo(op
, float_string
, float_string2
));
951 return perf_gaming_info_
->IsValid();
954 bool GpuControlList::GpuControlListEntry::SetPerfOverallInfo(
955 const std::string
& op
,
956 const std::string
& float_string
,
957 const std::string
& float_string2
) {
958 perf_overall_info_
.reset(new FloatInfo(op
, float_string
, float_string2
));
959 return perf_overall_info_
->IsValid();
962 bool GpuControlList::GpuControlListEntry::AddMachineModelName(
963 const std::string
& model_name
) {
964 if (model_name
.empty())
966 machine_model_name_list_
.push_back(model_name
);
970 bool GpuControlList::GpuControlListEntry::SetMachineModelVersionInfo(
971 const std::string
& version_op
,
972 const std::string
& version_string
,
973 const std::string
& version_string2
) {
974 machine_model_version_info_
.reset(new VersionInfo(
975 version_op
, std::string(), version_string
, version_string2
));
976 return machine_model_version_info_
->IsValid();
979 bool GpuControlList::GpuControlListEntry::SetGpuCountInfo(
980 const std::string
& op
,
981 const std::string
& int_string
,
982 const std::string
& int_string2
) {
983 gpu_count_info_
.reset(new IntInfo(op
, int_string
, int_string2
));
984 return gpu_count_info_
->IsValid();
987 void GpuControlList::GpuControlListEntry::SetDirectRenderingInfo(bool value
) {
988 direct_rendering_info_
.reset(new BoolInfo(value
));
991 void GpuControlList::GpuControlListEntry::SetInProcessGPUInfo(bool value
) {
992 in_process_gpu_info_
.reset(new BoolInfo(value
));
995 bool GpuControlList::GpuControlListEntry::SetFeatures(
996 const std::vector
<std::string
>& feature_strings
,
997 const FeatureMap
& feature_map
,
998 bool supports_feature_type_all
) {
999 size_t size
= feature_strings
.size();
1003 for (size_t i
= 0; i
< size
; ++i
) {
1005 if (supports_feature_type_all
&& feature_strings
[i
] == "all") {
1006 for (FeatureMap::const_iterator iter
= feature_map
.begin();
1007 iter
!= feature_map
.end(); ++iter
)
1008 features_
.insert(iter
->second
);
1011 if (!StringToFeature(feature_strings
[i
], &feature
, feature_map
)) {
1015 features_
.insert(feature
);
1020 void GpuControlList::GpuControlListEntry::AddException(
1021 ScopedGpuControlListEntry exception
) {
1022 exceptions_
.push_back(exception
);
1025 bool GpuControlList::GpuControlListEntry::GLVersionInfoMismatch(
1026 const std::string
& gl_version
) const {
1027 if (gl_version
.empty())
1030 if (gl_version_info_
.get() == NULL
&& gl_type_
== kGLTypeNone
)
1033 std::vector
<std::string
> segments
= base::SplitString(
1034 gl_version
, " ", base::TRIM_WHITESPACE
, base::SPLIT_WANT_ALL
);
1036 GLType gl_type
= kGLTypeNone
;
1037 if (segments
.size() > 2 &&
1038 segments
[0] == "OpenGL" && segments
[1] == "ES") {
1039 bool full_match
= RE2::FullMatch(segments
[2], "([\\d.]+).*", &number
);
1042 gl_type
= kGLTypeGLES
;
1043 if (segments
.size() > 3 &&
1044 base::StartsWith(segments
[3], "(ANGLE",
1045 base::CompareCase::INSENSITIVE_ASCII
)) {
1046 gl_type
= kGLTypeANGLE
;
1049 number
= segments
[0];
1050 gl_type
= kGLTypeGL
;
1053 if (gl_type_
!= kGLTypeNone
&& gl_type_
!= gl_type
)
1055 if (gl_version_info_
.get() != NULL
&& !gl_version_info_
->Contains(number
))
1061 GpuControlList::GpuControlListEntry::MultiGpuStyle
1062 GpuControlList::GpuControlListEntry::StringToMultiGpuStyle(
1063 const std::string
& style
) {
1064 if (style
== kMultiGpuStyleStringOptimus
)
1065 return kMultiGpuStyleOptimus
;
1066 if (style
== kMultiGpuStyleStringAMDSwitchable
)
1067 return kMultiGpuStyleAMDSwitchable
;
1068 if (style
== kMultiGpuStyleStringAMDSwitchableIntegrated
)
1069 return kMultiGpuStyleAMDSwitchableIntegrated
;
1070 if (style
== kMultiGpuStyleStringAMDSwitchableDiscrete
)
1071 return kMultiGpuStyleAMDSwitchableDiscrete
;
1072 return kMultiGpuStyleNone
;
1076 GpuControlList::GpuControlListEntry::MultiGpuCategory
1077 GpuControlList::GpuControlListEntry::StringToMultiGpuCategory(
1078 const std::string
& category
) {
1079 if (category
== kMultiGpuCategoryStringPrimary
)
1080 return kMultiGpuCategoryPrimary
;
1081 if (category
== kMultiGpuCategoryStringSecondary
)
1082 return kMultiGpuCategorySecondary
;
1083 if (category
== kMultiGpuCategoryStringActive
)
1084 return kMultiGpuCategoryActive
;
1085 if (category
== kMultiGpuCategoryStringAny
)
1086 return kMultiGpuCategoryAny
;
1087 return kMultiGpuCategoryNone
;
1091 GpuControlList::GpuControlListEntry::GLType
1092 GpuControlList::GpuControlListEntry::StringToGLType(
1093 const std::string
& gl_type
) {
1094 if (gl_type
== kGLTypeStringGL
)
1096 if (gl_type
== kGLTypeStringGLES
)
1098 if (gl_type
== kGLTypeStringANGLE
)
1099 return kGLTypeANGLE
;
1104 GpuControlList::GpuControlListEntry::GLType
1105 GpuControlList::GpuControlListEntry::GetDefaultGLType() {
1106 #if defined(OS_CHROMEOS)
1108 #elif defined(OS_LINUX) || defined(OS_OPENBSD)
1110 #elif defined(OS_MACOSX)
1112 #elif defined(OS_WIN)
1113 return kGLTypeANGLE
;
1114 #elif defined(OS_ANDROID)
1121 void GpuControlList::GpuControlListEntry::LogControlListMatch(
1122 const std::string
& control_list_logging_name
) const {
1123 static const char kControlListMatchMessage
[] =
1124 "Control list match for rule #%u in %s.";
1125 VLOG(1) << base::StringPrintf(kControlListMatchMessage
, id_
,
1126 control_list_logging_name
.c_str());
1129 bool GpuControlList::GpuControlListEntry::Contains(
1130 OsType os_type
, const std::string
& os_version
,
1131 const GPUInfo
& gpu_info
) const {
1132 DCHECK(os_type
!= kOsAny
);
1133 if (os_info_
.get() != NULL
&& !os_info_
->Contains(os_type
, os_version
))
1135 if (vendor_id_
!= 0) {
1136 std::vector
<GPUInfo::GPUDevice
> candidates
;
1137 switch (multi_gpu_category_
) {
1138 case kMultiGpuCategoryPrimary
:
1139 candidates
.push_back(gpu_info
.gpu
);
1141 case kMultiGpuCategorySecondary
:
1142 candidates
= gpu_info
.secondary_gpus
;
1144 case kMultiGpuCategoryAny
:
1145 candidates
= gpu_info
.secondary_gpus
;
1146 candidates
.push_back(gpu_info
.gpu
);
1148 case kMultiGpuCategoryActive
:
1149 if (gpu_info
.gpu
.active
)
1150 candidates
.push_back(gpu_info
.gpu
);
1151 for (size_t ii
= 0; ii
< gpu_info
.secondary_gpus
.size(); ++ii
) {
1152 if (gpu_info
.secondary_gpus
[ii
].active
)
1153 candidates
.push_back(gpu_info
.secondary_gpus
[ii
]);
1159 GPUInfo::GPUDevice gpu
;
1160 gpu
.vendor_id
= vendor_id_
;
1162 if (device_id_list_
.empty()) {
1163 for (size_t ii
= 0; ii
< candidates
.size(); ++ii
) {
1164 if (gpu
.vendor_id
== candidates
[ii
].vendor_id
) {
1170 for (size_t ii
= 0; ii
< device_id_list_
.size(); ++ii
) {
1171 gpu
.device_id
= device_id_list_
[ii
];
1172 for (size_t jj
= 0; jj
< candidates
.size(); ++jj
) {
1173 if (gpu
.vendor_id
== candidates
[jj
].vendor_id
&&
1174 gpu
.device_id
== candidates
[jj
].device_id
) {
1184 switch (multi_gpu_style_
) {
1185 case kMultiGpuStyleOptimus
:
1186 if (!gpu_info
.optimus
)
1189 case kMultiGpuStyleAMDSwitchable
:
1190 if (!gpu_info
.amd_switchable
)
1193 case kMultiGpuStyleAMDSwitchableDiscrete
:
1194 if (!gpu_info
.amd_switchable
)
1196 // The discrete GPU is always the primary GPU.
1197 // This is guaranteed by GpuInfoCollector.
1198 if (!gpu_info
.gpu
.active
)
1201 case kMultiGpuStyleAMDSwitchableIntegrated
:
1202 if (!gpu_info
.amd_switchable
)
1204 // Assume the integrated GPU is the first in the secondary GPU list.
1205 if (gpu_info
.secondary_gpus
.size() == 0 ||
1206 !gpu_info
.secondary_gpus
[0].active
)
1209 case kMultiGpuStyleNone
:
1212 if (StringMismatch(gpu_info
.driver_vendor
, driver_vendor_info_
))
1214 if (driver_version_info_
.get() != NULL
&& !gpu_info
.driver_version
.empty()) {
1215 if (!driver_version_info_
->Contains(gpu_info
.driver_version
))
1218 if (driver_date_info_
.get() != NULL
&& !gpu_info
.driver_date
.empty()) {
1219 if (!driver_date_info_
->Contains(gpu_info
.driver_date
, '-'))
1222 if (GLVersionInfoMismatch(gpu_info
.gl_version
))
1224 if (StringMismatch(gpu_info
.gl_vendor
, gl_vendor_info_
))
1226 if (StringMismatch(gpu_info
.gl_renderer
, gl_renderer_info_
))
1228 if (StringMismatch(gpu_info
.gl_extensions
, gl_extensions_info_
))
1230 if (gl_reset_notification_strategy_info_
.get() != NULL
&&
1231 !gl_reset_notification_strategy_info_
->Contains(
1232 gpu_info
.gl_reset_notification_strategy
))
1234 if (!machine_model_name_list_
.empty()) {
1235 if (gpu_info
.machine_model_name
.empty())
1237 bool found_match
= false;
1238 for (size_t ii
= 0; ii
< machine_model_name_list_
.size(); ++ii
) {
1239 if (RE2::FullMatch(gpu_info
.machine_model_name
,
1240 machine_model_name_list_
[ii
])) {
1248 if (machine_model_version_info_
.get() != NULL
&&
1249 (gpu_info
.machine_model_version
.empty() ||
1250 !machine_model_version_info_
->Contains(gpu_info
.machine_model_version
)))
1252 if (gpu_count_info_
.get() != NULL
&&
1253 !gpu_count_info_
->Contains(gpu_info
.secondary_gpus
.size() + 1))
1255 if (direct_rendering_info_
.get() != NULL
&&
1256 !direct_rendering_info_
->Contains(gpu_info
.direct_rendering
))
1258 if (in_process_gpu_info_
.get() != NULL
&&
1259 !in_process_gpu_info_
->Contains(gpu_info
.in_process_gpu
))
1261 if (!cpu_brand_
.empty()) {
1263 if (StringMismatch(cpu_info
.cpu_brand(), cpu_brand_
))
1267 for (size_t i
= 0; i
< exceptions_
.size(); ++i
) {
1268 if (exceptions_
[i
]->Contains(os_type
, os_version
, gpu_info
) &&
1269 !exceptions_
[i
]->NeedsMoreInfo(gpu_info
, true))
1275 bool GpuControlList::GpuControlListEntry::NeedsMoreInfo(
1276 const GPUInfo
& gpu_info
,
1277 bool consider_exceptions
) const {
1278 // We only check for missing info that might be collected with a gl context.
1279 // If certain info is missing due to some error, say, we fail to collect
1280 // vendor_id/device_id, then even if we launch GPU process and create a gl
1281 // context, we won't gather such missing info, so we still return false.
1282 if (!driver_vendor_info_
.empty() && gpu_info
.driver_vendor
.empty())
1284 if (driver_version_info_
.get() && gpu_info
.driver_version
.empty())
1286 if (!gl_vendor_info_
.empty() && gpu_info
.gl_vendor
.empty())
1288 if (!gl_renderer_info_
.empty() && gpu_info
.gl_renderer
.empty())
1291 if (consider_exceptions
) {
1292 for (size_t i
= 0; i
< exceptions_
.size(); ++i
) {
1293 if (exceptions_
[i
]->NeedsMoreInfo(gpu_info
, consider_exceptions
))
1301 GpuControlList::OsType
GpuControlList::GpuControlListEntry::GetOsType() const {
1302 if (os_info_
.get() == NULL
)
1304 return os_info_
->type();
1307 uint32
GpuControlList::GpuControlListEntry::id() const {
1311 bool GpuControlList::GpuControlListEntry::disabled() const {
1315 const std::set
<int>& GpuControlList::GpuControlListEntry::features() const {
1319 void GpuControlList::GpuControlListEntry::GetFeatureNames(
1320 base::ListValue
* feature_names
,
1321 const FeatureMap
& feature_map
,
1322 bool supports_feature_type_all
) const {
1323 DCHECK(feature_names
);
1324 if (supports_feature_type_all
&& features_
.size() == feature_map
.size()) {
1325 feature_names
->AppendString("all");
1328 for (FeatureMap::const_iterator iter
= feature_map
.begin();
1329 iter
!= feature_map
.end(); ++iter
) {
1330 if (features_
.count(iter
->second
) > 0)
1331 feature_names
->AppendString(iter
->first
);
1336 bool GpuControlList::GpuControlListEntry::StringToFeature(
1337 const std::string
& feature_name
, int* feature_id
,
1338 const FeatureMap
& feature_map
) {
1339 FeatureMap::const_iterator iter
= feature_map
.find(feature_name
);
1340 if (iter
!= feature_map
.end()) {
1341 *feature_id
= iter
->second
;
1347 GpuControlList::GpuControlList()
1349 needs_more_info_(false),
1350 supports_feature_type_all_(false),
1351 control_list_logging_enabled_(false) {
1354 GpuControlList::~GpuControlList() {
1358 bool GpuControlList::LoadList(
1359 const std::string
& json_context
,
1360 GpuControlList::OsFilter os_filter
) {
1361 scoped_ptr
<base::Value
> root
= base::JSONReader::Read(json_context
);
1362 if (root
.get() == NULL
|| !root
->IsType(base::Value::TYPE_DICTIONARY
))
1365 base::DictionaryValue
* root_dictionary
=
1366 static_cast<base::DictionaryValue
*>(root
.get());
1367 DCHECK(root_dictionary
);
1368 return LoadList(*root_dictionary
, os_filter
);
1371 bool GpuControlList::LoadList(const base::DictionaryValue
& parsed_json
,
1372 GpuControlList::OsFilter os_filter
) {
1373 std::vector
<ScopedGpuControlListEntry
> entries
;
1375 parsed_json
.GetString("version", &version_
);
1376 std::vector
<std::string
> pieces
;
1377 if (!ProcessVersionString(version_
, '.', &pieces
))
1380 const base::ListValue
* list
= NULL
;
1381 if (!parsed_json
.GetList("entries", &list
))
1384 uint32 max_entry_id
= 0;
1385 for (size_t i
= 0; i
< list
->GetSize(); ++i
) {
1386 const base::DictionaryValue
* list_item
= NULL
;
1387 bool valid
= list
->GetDictionary(i
, &list_item
);
1388 if (!valid
|| list_item
== NULL
)
1390 ScopedGpuControlListEntry
entry(GpuControlListEntry::GetEntryFromValue(
1391 list_item
, true, feature_map_
, supports_feature_type_all_
));
1392 if (entry
.get() == NULL
)
1394 if (entry
->id() > max_entry_id
)
1395 max_entry_id
= entry
->id();
1396 entries
.push_back(entry
);
1400 OsType my_os
= GetOsType();
1401 for (size_t i
= 0; i
< entries
.size(); ++i
) {
1402 OsType entry_os
= entries
[i
]->GetOsType();
1403 if (os_filter
== GpuControlList::kAllOs
||
1404 entry_os
== kOsAny
|| entry_os
== my_os
)
1405 entries_
.push_back(entries
[i
]);
1407 max_entry_id_
= max_entry_id
;
1411 std::set
<int> GpuControlList::MakeDecision(
1412 GpuControlList::OsType os
,
1413 std::string os_version
,
1414 const GPUInfo
& gpu_info
) {
1415 active_entries_
.clear();
1416 std::set
<int> features
;
1418 needs_more_info_
= false;
1419 // Has all features permanently in the list without any possibility of
1420 // removal in the future (subset of "features" set).
1421 std::set
<int> permanent_features
;
1422 // Has all features absent from "features" set that could potentially be
1423 // included later with more information.
1424 std::set
<int> potential_features
;
1428 if (os_version
.empty())
1429 os_version
= base::SysInfo::OperatingSystemVersion();
1431 for (size_t i
= 0; i
< entries_
.size(); ++i
) {
1432 ScopedGpuControlListEntry entry
= entries_
[i
];
1433 if (entry
->Contains(os
, os_version
, gpu_info
)) {
1434 bool needs_more_info_main
= entry
->NeedsMoreInfo(gpu_info
, false);
1435 bool needs_more_info_exception
= entry
->NeedsMoreInfo(gpu_info
, true);
1437 if (!entry
->disabled()) {
1438 if (control_list_logging_enabled_
)
1439 entry
->LogControlListMatch(control_list_logging_name_
);
1440 // Only look at main entry info when deciding what to add to "features"
1441 // set. If we don't have enough info for an exception, it's safer if we
1442 // just ignore the exception and assume the exception doesn't apply.
1443 for (std::set
<int>::const_iterator iter
= entry
->features().begin();
1444 iter
!= entry
->features().end(); ++iter
) {
1445 if (needs_more_info_main
) {
1446 if (!features
.count(*iter
))
1447 potential_features
.insert(*iter
);
1449 features
.insert(*iter
);
1450 potential_features
.erase(*iter
);
1451 if (!needs_more_info_exception
)
1452 permanent_features
.insert(*iter
);
1457 if (!needs_more_info_main
)
1458 active_entries_
.push_back(entry
);
1462 needs_more_info_
= permanent_features
.size() < features
.size() ||
1463 !potential_features
.empty();
1467 void GpuControlList::GetDecisionEntries(
1468 std::vector
<uint32
>* entry_ids
, bool disabled
) const {
1471 for (size_t i
= 0; i
< active_entries_
.size(); ++i
) {
1472 if (disabled
== active_entries_
[i
]->disabled())
1473 entry_ids
->push_back(active_entries_
[i
]->id());
1477 std::vector
<std::string
> GpuControlList::GetDisabledExtensions() {
1478 std::set
<std::string
> disabled_extensions
;
1479 for (size_t i
= 0; i
< active_entries_
.size(); ++i
) {
1480 GpuControlListEntry
* entry
= active_entries_
[i
].get();
1482 if (entry
->disabled())
1485 disabled_extensions
.insert(entry
->disabled_extensions().begin(),
1486 entry
->disabled_extensions().end());
1488 return std::vector
<std::string
>(disabled_extensions
.begin(),
1489 disabled_extensions
.end());
1492 void GpuControlList::GetReasons(base::ListValue
* problem_list
,
1493 const std::string
& tag
) const {
1494 DCHECK(problem_list
);
1495 for (size_t i
= 0; i
< active_entries_
.size(); ++i
) {
1496 GpuControlListEntry
* entry
= active_entries_
[i
].get();
1497 if (entry
->disabled())
1499 base::DictionaryValue
* problem
= new base::DictionaryValue();
1501 problem
->SetString("description", entry
->description());
1503 base::ListValue
* cr_bugs
= new base::ListValue();
1504 for (size_t j
= 0; j
< entry
->cr_bugs().size(); ++j
)
1505 cr_bugs
->Append(new base::FundamentalValue(entry
->cr_bugs()[j
]));
1506 problem
->Set("crBugs", cr_bugs
);
1508 base::ListValue
* webkit_bugs
= new base::ListValue();
1509 for (size_t j
= 0; j
< entry
->webkit_bugs().size(); ++j
) {
1510 webkit_bugs
->Append(new base::FundamentalValue(entry
->webkit_bugs()[j
]));
1512 problem
->Set("webkitBugs", webkit_bugs
);
1514 base::ListValue
* features
= new base::ListValue();
1515 entry
->GetFeatureNames(features
, feature_map_
, supports_feature_type_all_
);
1516 problem
->Set("affectedGpuSettings", features
);
1518 DCHECK(tag
== "workarounds" || tag
== "disabledFeatures");
1519 problem
->SetString("tag", tag
);
1521 problem_list
->Append(problem
);
1525 size_t GpuControlList::num_entries() const {
1526 return entries_
.size();
1529 uint32
GpuControlList::max_entry_id() const {
1530 return max_entry_id_
;
1533 std::string
GpuControlList::version() const {
1537 GpuControlList::OsType
GpuControlList::GetOsType() {
1538 #if defined(OS_CHROMEOS)
1540 #elif defined(OS_WIN)
1542 #elif defined(OS_ANDROID)
1544 #elif defined(OS_LINUX) || defined(OS_OPENBSD)
1546 #elif defined(OS_MACOSX)
1553 void GpuControlList::Clear() {
1555 active_entries_
.clear();
1560 GpuControlList::NumericOp
GpuControlList::StringToNumericOp(
1561 const std::string
& op
) {
1574 if (op
== "between")
1579 void GpuControlList::AddSupportedFeature(
1580 const std::string
& feature_name
, int feature_id
) {
1581 feature_map_
[feature_name
] = feature_id
;
1584 void GpuControlList::set_supports_feature_type_all(bool supported
) {
1585 supports_feature_type_all_
= supported
;