OLD | NEW |
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 "base/cpu.h" | 7 #include "base/cpu.h" |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 return kOsAndroid; | 236 return kOsAndroid; |
237 else if (os == "linux") | 237 else if (os == "linux") |
238 return kOsLinux; | 238 return kOsLinux; |
239 else if (os == "chromeos") | 239 else if (os == "chromeos") |
240 return kOsChromeOS; | 240 return kOsChromeOS; |
241 else if (os == "any") | 241 else if (os == "any") |
242 return kOsAny; | 242 return kOsAny; |
243 return kOsUnknown; | 243 return kOsUnknown; |
244 } | 244 } |
245 | 245 |
246 GpuControlList::MachineModelInfo::MachineModelInfo( | |
247 const std::string& name_op, | |
248 const std::string& name_value, | |
249 const std::string& version_op, | |
250 const std::string& version_string, | |
251 const std::string& version_string2) { | |
252 name_info_.reset(new StringInfo(name_op, name_value)); | |
253 version_info_.reset(new VersionInfo( | |
254 version_op, std::string(), version_string, version_string2)); | |
255 } | |
256 | |
257 GpuControlList::MachineModelInfo::~MachineModelInfo() {} | |
258 | |
259 bool GpuControlList::MachineModelInfo::Contains( | |
260 const std::string& name, const std::string& version) const { | |
261 if (!IsValid()) | |
262 return false; | |
263 if (!name_info_->Contains(name)) | |
264 return false; | |
265 return version_info_->Contains(version); | |
266 } | |
267 | |
268 bool GpuControlList::MachineModelInfo::IsValid() const { | |
269 return name_info_->IsValid() && version_info_->IsValid(); | |
270 } | |
271 | |
272 GpuControlList::StringInfo::StringInfo(const std::string& string_op, | 246 GpuControlList::StringInfo::StringInfo(const std::string& string_op, |
273 const std::string& string_value) { | 247 const std::string& string_value) { |
274 op_ = StringToOp(string_op); | 248 op_ = StringToOp(string_op); |
275 value_ = StringToLowerASCII(string_value); | 249 value_ = StringToLowerASCII(string_value); |
276 } | 250 } |
277 | 251 |
278 bool GpuControlList::StringInfo::Contains(const std::string& value) const { | 252 bool GpuControlList::StringInfo::Contains(const std::string& value) const { |
279 std::string my_value = StringToLowerASCII(value); | 253 std::string my_value = StringToLowerASCII(value); |
280 switch (op_) { | 254 switch (op_) { |
281 case kContains: | 255 case kContains: |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 if (!entry->SetVendorId(vendor_id)) { | 467 if (!entry->SetVendorId(vendor_id)) { |
494 LOG(WARNING) << "Malformed vendor_id entry " << entry->id(); | 468 LOG(WARNING) << "Malformed vendor_id entry " << entry->id(); |
495 return NULL; | 469 return NULL; |
496 } | 470 } |
497 dictionary_entry_count++; | 471 dictionary_entry_count++; |
498 } | 472 } |
499 | 473 |
500 const base::ListValue* device_id_list; | 474 const base::ListValue* device_id_list; |
501 if (value->GetList("device_id", &device_id_list)) { | 475 if (value->GetList("device_id", &device_id_list)) { |
502 for (size_t i = 0; i < device_id_list->GetSize(); ++i) { | 476 for (size_t i = 0; i < device_id_list->GetSize(); ++i) { |
503 std::string device_id; | 477 std::string device_id; |
504 if (!device_id_list->GetString(i, &device_id) || | 478 if (!device_id_list->GetString(i, &device_id) || |
505 !entry->AddDeviceId(device_id)) { | 479 !entry->AddDeviceId(device_id)) { |
506 LOG(WARNING) << "Malformed device_id entry " << entry->id(); | 480 LOG(WARNING) << "Malformed device_id entry " << entry->id(); |
507 return NULL; | 481 return NULL; |
508 } | 482 } |
509 } | 483 } |
510 dictionary_entry_count++; | 484 dictionary_entry_count++; |
511 } | 485 } |
512 | 486 |
513 std::string multi_gpu_style; | 487 std::string multi_gpu_style; |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 perf_overall_value->GetString(kOp, &op); | 659 perf_overall_value->GetString(kOp, &op); |
686 perf_overall_value->GetString("value", &float_value); | 660 perf_overall_value->GetString("value", &float_value); |
687 perf_overall_value->GetString("value2", &float_value2); | 661 perf_overall_value->GetString("value2", &float_value2); |
688 if (!entry->SetPerfOverallInfo(op, float_value, float_value2)) { | 662 if (!entry->SetPerfOverallInfo(op, float_value, float_value2)) { |
689 LOG(WARNING) << "Malformed perf_overall entry " << entry->id(); | 663 LOG(WARNING) << "Malformed perf_overall entry " << entry->id(); |
690 return NULL; | 664 return NULL; |
691 } | 665 } |
692 dictionary_entry_count++; | 666 dictionary_entry_count++; |
693 } | 667 } |
694 | 668 |
695 const base::DictionaryValue* machine_model_value = NULL; | 669 const base::ListValue* machine_model_name_list; |
696 if (value->GetDictionary("machine_model", &machine_model_value)) { | 670 if (value->GetList("machine_model_name", &machine_model_name_list)) { |
697 std::string name_op; | 671 for (size_t i = 0; i < machine_model_name_list->GetSize(); ++i) { |
698 std::string name_value; | 672 std::string model_name; |
699 const base::DictionaryValue* name = NULL; | 673 if (!machine_model_name_list->GetString(i, &model_name) || |
700 if (machine_model_value->GetDictionary("name", &name)) { | 674 !entry->AddMachineModelName(model_name)) { |
701 name->GetString(kOp, &name_op); | 675 LOG(WARNING) << "Malformed machine_model_name entry " << entry->id(); |
702 name->GetString("value", &name_value); | 676 return NULL; |
| 677 } |
703 } | 678 } |
| 679 dictionary_entry_count++; |
| 680 } |
704 | 681 |
| 682 const base::DictionaryValue* machine_model_version_value = NULL; |
| 683 if (value->GetDictionary( |
| 684 "machine_model_version", &machine_model_version_value)) { |
705 std::string version_op = "any"; | 685 std::string version_op = "any"; |
706 std::string version_string; | 686 std::string version_string; |
707 std::string version_string2; | 687 std::string version_string2; |
708 const base::DictionaryValue* version_value = NULL; | 688 machine_model_version_value->GetString(kOp, &version_op); |
709 if (machine_model_value->GetDictionary("version", &version_value)) { | 689 machine_model_version_value->GetString("value", &version_string); |
710 version_value->GetString(kOp, &version_op); | 690 machine_model_version_value->GetString("value2", &version_string2); |
711 version_value->GetString("value", &version_string); | 691 if (!entry->SetMachineModelVersionInfo( |
712 version_value->GetString("value2", &version_string2); | 692 version_op, version_string, version_string2)) { |
713 } | 693 LOG(WARNING) << "Malformed machine_model_version entry " << entry->id(); |
714 if (!entry->SetMachineModelInfo( | |
715 name_op, name_value, version_op, version_string, version_string2)) { | |
716 LOG(WARNING) << "Malformed machine_model entry " << entry->id(); | |
717 return NULL; | 694 return NULL; |
718 } | 695 } |
719 dictionary_entry_count++; | 696 dictionary_entry_count++; |
720 } | 697 } |
721 | 698 |
722 const base::DictionaryValue* gpu_count_value = NULL; | 699 const base::DictionaryValue* gpu_count_value = NULL; |
723 if (value->GetDictionary("gpu_count", &gpu_count_value)) { | 700 if (value->GetDictionary("gpu_count", &gpu_count_value)) { |
724 std::string op; | 701 std::string op; |
725 std::string int_value; | 702 std::string int_value; |
726 std::string int_value2; | 703 std::string int_value2; |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
941 } | 918 } |
942 | 919 |
943 bool GpuControlList::GpuControlListEntry::SetPerfOverallInfo( | 920 bool GpuControlList::GpuControlListEntry::SetPerfOverallInfo( |
944 const std::string& op, | 921 const std::string& op, |
945 const std::string& float_string, | 922 const std::string& float_string, |
946 const std::string& float_string2) { | 923 const std::string& float_string2) { |
947 perf_overall_info_.reset(new FloatInfo(op, float_string, float_string2)); | 924 perf_overall_info_.reset(new FloatInfo(op, float_string, float_string2)); |
948 return perf_overall_info_->IsValid(); | 925 return perf_overall_info_->IsValid(); |
949 } | 926 } |
950 | 927 |
951 bool GpuControlList::GpuControlListEntry::SetMachineModelInfo( | 928 bool GpuControlList::GpuControlListEntry::AddMachineModelName( |
952 const std::string& name_op, | 929 const std::string& model_name) { |
953 const std::string& name_value, | 930 if (model_name.empty()) |
| 931 return false; |
| 932 machine_model_name_list_.push_back(model_name); |
| 933 return true; |
| 934 } |
| 935 |
| 936 bool GpuControlList::GpuControlListEntry::SetMachineModelVersionInfo( |
954 const std::string& version_op, | 937 const std::string& version_op, |
955 const std::string& version_string, | 938 const std::string& version_string, |
956 const std::string& version_string2) { | 939 const std::string& version_string2) { |
957 machine_model_info_.reset(new MachineModelInfo( | 940 machine_model_version_info_.reset(new VersionInfo( |
958 name_op, name_value, version_op, version_string, version_string2)); | 941 version_op, std::string(), version_string, version_string2)); |
959 return machine_model_info_->IsValid(); | 942 return machine_model_version_info_->IsValid(); |
960 } | 943 } |
961 | 944 |
962 bool GpuControlList::GpuControlListEntry::SetGpuCountInfo( | 945 bool GpuControlList::GpuControlListEntry::SetGpuCountInfo( |
963 const std::string& op, | 946 const std::string& op, |
964 const std::string& int_string, | 947 const std::string& int_string, |
965 const std::string& int_string2) { | 948 const std::string& int_string2) { |
966 gpu_count_info_.reset(new IntInfo(op, int_string, int_string2)); | 949 gpu_count_info_.reset(new IntInfo(op, int_string, int_string2)); |
967 return gpu_count_info_->IsValid(); | 950 return gpu_count_info_->IsValid(); |
968 } | 951 } |
969 | 952 |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1131 !perf_graphics_info_->Contains(gpu_info.performance_stats.graphics))) | 1114 !perf_graphics_info_->Contains(gpu_info.performance_stats.graphics))) |
1132 return false; | 1115 return false; |
1133 if (perf_gaming_info_.get() != NULL && | 1116 if (perf_gaming_info_.get() != NULL && |
1134 (gpu_info.performance_stats.gaming == 0.0 || | 1117 (gpu_info.performance_stats.gaming == 0.0 || |
1135 !perf_gaming_info_->Contains(gpu_info.performance_stats.gaming))) | 1118 !perf_gaming_info_->Contains(gpu_info.performance_stats.gaming))) |
1136 return false; | 1119 return false; |
1137 if (perf_overall_info_.get() != NULL && | 1120 if (perf_overall_info_.get() != NULL && |
1138 (gpu_info.performance_stats.overall == 0.0 || | 1121 (gpu_info.performance_stats.overall == 0.0 || |
1139 !perf_overall_info_->Contains(gpu_info.performance_stats.overall))) | 1122 !perf_overall_info_->Contains(gpu_info.performance_stats.overall))) |
1140 return false; | 1123 return false; |
1141 if (machine_model_info_.get() != NULL) { | 1124 if (!machine_model_name_list_.empty() && |
1142 std::vector<std::string> name_version; | 1125 !gpu_info.machine_model_name.empty()) { |
1143 base::SplitString(gpu_info.machine_model, ' ', &name_version); | 1126 bool found_match = false; |
1144 if (name_version.size() == 2 && | 1127 for (size_t ii = 0; ii < machine_model_name_list_.size(); ++ii) { |
1145 !machine_model_info_->Contains(name_version[0], name_version[1])) | 1128 if (machine_model_name_list_[ii] == gpu_info.machine_model_name) { |
| 1129 found_match = true; |
| 1130 break; |
| 1131 } |
| 1132 } |
| 1133 if (!found_match) |
1146 return false; | 1134 return false; |
1147 } | 1135 } |
| 1136 if (machine_model_version_info_.get() != NULL && |
| 1137 !gpu_info.machine_model_version.empty() && |
| 1138 !machine_model_version_info_->Contains(gpu_info.machine_model_version)) |
| 1139 return false; |
1148 if (gpu_count_info_.get() != NULL && | 1140 if (gpu_count_info_.get() != NULL && |
1149 !gpu_count_info_->Contains(gpu_info.secondary_gpus.size() + 1)) | 1141 !gpu_count_info_->Contains(gpu_info.secondary_gpus.size() + 1)) |
1150 return false; | 1142 return false; |
1151 if (direct_rendering_info_.get() != NULL && | 1143 if (direct_rendering_info_.get() != NULL && |
1152 !direct_rendering_info_->Contains(gpu_info.direct_rendering)) | 1144 !direct_rendering_info_->Contains(gpu_info.direct_rendering)) |
1153 return false; | 1145 return false; |
1154 if (cpu_brand_.get() != NULL) { | 1146 if (cpu_brand_.get() != NULL) { |
1155 base::CPU cpu_info; | 1147 base::CPU cpu_info; |
1156 if (!cpu_brand_->Contains(cpu_info.cpu_brand())) | 1148 if (!cpu_brand_->Contains(cpu_info.cpu_brand())) |
1157 return false; | 1149 return false; |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1439 const std::string& feature_name, int feature_id) { | 1431 const std::string& feature_name, int feature_id) { |
1440 feature_map_[feature_name] = feature_id; | 1432 feature_map_[feature_name] = feature_id; |
1441 } | 1433 } |
1442 | 1434 |
1443 void GpuControlList::set_supports_feature_type_all(bool supported) { | 1435 void GpuControlList::set_supports_feature_type_all(bool supported) { |
1444 supports_feature_type_all_ = supported; | 1436 supports_feature_type_all_ = supported; |
1445 } | 1437 } |
1446 | 1438 |
1447 } // namespace gpu | 1439 } // namespace gpu |
1448 | 1440 |
OLD | NEW |