| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/gpu_blacklist.h" | 5 #include "chrome/browser/gpu_blacklist.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.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/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 lexical += numerical[i]; | 60 lexical += numerical[i]; |
| 61 } | 61 } |
| 62 } else { | 62 } else { |
| 63 valid = false; | 63 valid = false; |
| 64 } | 64 } |
| 65 if (valid) | 65 if (valid) |
| 66 return lexical; | 66 return lexical; |
| 67 return numerical; | 67 return numerical; |
| 68 } | 68 } |
| 69 | 69 |
| 70 bool GpuUnmatched(uint32 vendor_id, const std::vector<uint32>& device_id_list, |
| 71 const content::GPUInfo::GPUDevice& gpu) { |
| 72 if (vendor_id == 0) |
| 73 return false; |
| 74 if (vendor_id != gpu.vendor_id) |
| 75 return true; |
| 76 bool device_specified = false; |
| 77 for (size_t i = 0; i < device_id_list.size(); ++i) { |
| 78 if (device_id_list[i] == 0) |
| 79 continue; |
| 80 if (device_id_list[i] == gpu.device_id) |
| 81 return false; |
| 82 device_specified = true; |
| 83 } |
| 84 return device_specified; |
| 85 } |
| 86 |
| 70 const char kMultiGpuStyleStringAMDSwitchable[] = "amd_switchable"; | 87 const char kMultiGpuStyleStringAMDSwitchable[] = "amd_switchable"; |
| 71 const char kMultiGpuStyleStringOptimus[] = "optimus"; | 88 const char kMultiGpuStyleStringOptimus[] = "optimus"; |
| 72 | 89 |
| 90 const char kMultiGpuCategoryStringPrimary[] = "primary"; |
| 91 const char kMultiGpuCategoryStringSecondary[] = "secondary"; |
| 92 const char kMultiGpuCategoryStringAny[] = "any"; |
| 93 |
| 73 const char kVersionStyleStringNumerical[] = "numerical"; | 94 const char kVersionStyleStringNumerical[] = "numerical"; |
| 74 const char kVersionStyleStringLexical[] = "lexical"; | 95 const char kVersionStyleStringLexical[] = "lexical"; |
| 75 | 96 |
| 76 } // namespace anonymous | 97 } // namespace anonymous |
| 77 | 98 |
| 78 GpuBlacklist::VersionInfo::VersionInfo( | 99 GpuBlacklist::VersionInfo::VersionInfo( |
| 79 const std::string& version_op, | 100 const std::string& version_op, |
| 80 const std::string& version_style, | 101 const std::string& version_style, |
| 81 const std::string& version_string, | 102 const std::string& version_string, |
| 82 const std::string& version_string2) | 103 const std::string& version_string2) |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 | 418 |
| 398 std::string multi_gpu_style; | 419 std::string multi_gpu_style; |
| 399 if (value->GetString("multi_gpu_style", &multi_gpu_style)) { | 420 if (value->GetString("multi_gpu_style", &multi_gpu_style)) { |
| 400 if (!entry->SetMultiGpuStyle(multi_gpu_style)) { | 421 if (!entry->SetMultiGpuStyle(multi_gpu_style)) { |
| 401 LOG(WARNING) << "Malformed multi_gpu_style entry " << entry->id(); | 422 LOG(WARNING) << "Malformed multi_gpu_style entry " << entry->id(); |
| 402 return NULL; | 423 return NULL; |
| 403 } | 424 } |
| 404 dictionary_entry_count++; | 425 dictionary_entry_count++; |
| 405 } | 426 } |
| 406 | 427 |
| 428 std::string multi_gpu_category; |
| 429 if (value->GetString("multi_gpu_category", &multi_gpu_category)) { |
| 430 if (!entry->SetMultiGpuCategory(multi_gpu_category)) { |
| 431 LOG(WARNING) << "Malformed multi_gpu_category entry " << entry->id(); |
| 432 return NULL; |
| 433 } |
| 434 dictionary_entry_count++; |
| 435 } |
| 436 |
| 407 DictionaryValue* driver_vendor_value = NULL; | 437 DictionaryValue* driver_vendor_value = NULL; |
| 408 if (value->GetDictionary("driver_vendor", &driver_vendor_value)) { | 438 if (value->GetDictionary("driver_vendor", &driver_vendor_value)) { |
| 409 std::string vendor_op; | 439 std::string vendor_op; |
| 410 std::string vendor_value; | 440 std::string vendor_value; |
| 411 driver_vendor_value->GetString("op", &vendor_op); | 441 driver_vendor_value->GetString("op", &vendor_op); |
| 412 driver_vendor_value->GetString("value", &vendor_value); | 442 driver_vendor_value->GetString("value", &vendor_value); |
| 413 if (!entry->SetDriverVendorInfo(vendor_op, vendor_value)) { | 443 if (!entry->SetDriverVendorInfo(vendor_op, vendor_value)) { |
| 414 LOG(WARNING) << "Malformed driver_vendor entry " << entry->id(); | 444 LOG(WARNING) << "Malformed driver_vendor entry " << entry->id(); |
| 415 return NULL; | 445 return NULL; |
| 416 } | 446 } |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 entry->contains_unknown_fields_ = true; | 613 entry->contains_unknown_fields_ = true; |
| 584 } | 614 } |
| 585 return entry; | 615 return entry; |
| 586 } | 616 } |
| 587 | 617 |
| 588 GpuBlacklist::GpuBlacklistEntry::GpuBlacklistEntry() | 618 GpuBlacklist::GpuBlacklistEntry::GpuBlacklistEntry() |
| 589 : id_(0), | 619 : id_(0), |
| 590 disabled_(false), | 620 disabled_(false), |
| 591 vendor_id_(0), | 621 vendor_id_(0), |
| 592 multi_gpu_style_(kMultiGpuStyleNone), | 622 multi_gpu_style_(kMultiGpuStyleNone), |
| 623 multi_gpu_category_(kMultiGpuCategoryPrimary), |
| 593 feature_type_(content::GPU_FEATURE_TYPE_UNKNOWN), | 624 feature_type_(content::GPU_FEATURE_TYPE_UNKNOWN), |
| 594 contains_unknown_fields_(false), | 625 contains_unknown_fields_(false), |
| 595 contains_unknown_features_(false) { | 626 contains_unknown_features_(false) { |
| 596 } | 627 } |
| 597 | 628 |
| 598 bool GpuBlacklist::GpuBlacklistEntry::SetId(uint32 id) { | 629 bool GpuBlacklist::GpuBlacklistEntry::SetId(uint32 id) { |
| 599 if (id != 0) { | 630 if (id != 0) { |
| 600 id_ = id; | 631 id_ = id; |
| 601 return true; | 632 return true; |
| 602 } | 633 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 | 667 |
| 637 bool GpuBlacklist::GpuBlacklistEntry::SetMultiGpuStyle( | 668 bool GpuBlacklist::GpuBlacklistEntry::SetMultiGpuStyle( |
| 638 const std::string& multi_gpu_style_string) { | 669 const std::string& multi_gpu_style_string) { |
| 639 MultiGpuStyle style = StringToMultiGpuStyle(multi_gpu_style_string); | 670 MultiGpuStyle style = StringToMultiGpuStyle(multi_gpu_style_string); |
| 640 if (style == kMultiGpuStyleNone) | 671 if (style == kMultiGpuStyleNone) |
| 641 return false; | 672 return false; |
| 642 multi_gpu_style_ = style; | 673 multi_gpu_style_ = style; |
| 643 return true; | 674 return true; |
| 644 } | 675 } |
| 645 | 676 |
| 677 bool GpuBlacklist::GpuBlacklistEntry::SetMultiGpuCategory( |
| 678 const std::string& multi_gpu_category_string) { |
| 679 MultiGpuCategory category = |
| 680 StringToMultiGpuCategory(multi_gpu_category_string); |
| 681 if (category == kMultiGpuCategoryNone) |
| 682 return false; |
| 683 multi_gpu_category_ = category; |
| 684 return true; |
| 685 } |
| 686 |
| 646 bool GpuBlacklist::GpuBlacklistEntry::SetDriverVendorInfo( | 687 bool GpuBlacklist::GpuBlacklistEntry::SetDriverVendorInfo( |
| 647 const std::string& vendor_op, | 688 const std::string& vendor_op, |
| 648 const std::string& vendor_value) { | 689 const std::string& vendor_value) { |
| 649 driver_vendor_info_.reset( | 690 driver_vendor_info_.reset( |
| 650 new StringInfo(vendor_op, vendor_value)); | 691 new StringInfo(vendor_op, vendor_value)); |
| 651 return driver_vendor_info_->IsValid(); | 692 return driver_vendor_info_->IsValid(); |
| 652 } | 693 } |
| 653 | 694 |
| 654 bool GpuBlacklist::GpuBlacklistEntry::SetDriverVersionInfo( | 695 bool GpuBlacklist::GpuBlacklistEntry::SetDriverVersionInfo( |
| 655 const std::string& version_op, | 696 const std::string& version_op, |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 751 GpuBlacklist::GpuBlacklistEntry::MultiGpuStyle | 792 GpuBlacklist::GpuBlacklistEntry::MultiGpuStyle |
| 752 GpuBlacklist::GpuBlacklistEntry::StringToMultiGpuStyle( | 793 GpuBlacklist::GpuBlacklistEntry::StringToMultiGpuStyle( |
| 753 const std::string& style) { | 794 const std::string& style) { |
| 754 if (style == kMultiGpuStyleStringOptimus) | 795 if (style == kMultiGpuStyleStringOptimus) |
| 755 return kMultiGpuStyleOptimus; | 796 return kMultiGpuStyleOptimus; |
| 756 if (style == kMultiGpuStyleStringAMDSwitchable) | 797 if (style == kMultiGpuStyleStringAMDSwitchable) |
| 757 return kMultiGpuStyleAMDSwitchable; | 798 return kMultiGpuStyleAMDSwitchable; |
| 758 return kMultiGpuStyleNone; | 799 return kMultiGpuStyleNone; |
| 759 } | 800 } |
| 760 | 801 |
| 802 // static |
| 803 GpuBlacklist::GpuBlacklistEntry::MultiGpuCategory |
| 804 GpuBlacklist::GpuBlacklistEntry::StringToMultiGpuCategory( |
| 805 const std::string& category) { |
| 806 if (category == kMultiGpuCategoryStringPrimary) |
| 807 return kMultiGpuCategoryPrimary; |
| 808 if (category == kMultiGpuCategoryStringSecondary) |
| 809 return kMultiGpuCategorySecondary; |
| 810 if (category == kMultiGpuCategoryStringAny) |
| 811 return kMultiGpuCategoryAny; |
| 812 return kMultiGpuCategoryNone; |
| 813 } |
| 814 |
| 761 bool GpuBlacklist::GpuBlacklistEntry::Contains( | 815 bool GpuBlacklist::GpuBlacklistEntry::Contains( |
| 762 OsType os_type, const Version& os_version, | 816 OsType os_type, const Version& os_version, |
| 763 const content::GPUInfo& gpu_info) const { | 817 const content::GPUInfo& gpu_info) const { |
| 764 DCHECK(os_type != kOsAny); | 818 DCHECK(os_type != kOsAny); |
| 765 if (os_info_.get() != NULL && !os_info_->Contains(os_type, os_version)) | 819 if (os_info_.get() != NULL && !os_info_->Contains(os_type, os_version)) |
| 766 return false; | 820 return false; |
| 767 if (vendor_id_ != 0 && vendor_id_ != gpu_info.gpu.vendor_id) | 821 bool is_not_primary_gpu = |
| 768 return false; | 822 GpuUnmatched(vendor_id_, device_id_list_, gpu_info.gpu); |
| 769 if (device_id_list_.size() > 0) { | 823 bool is_not_secondary_gpu = true; |
| 770 bool found = false; | 824 for (size_t i = 0; i < gpu_info.secondary_gpus.size(); ++i) { |
| 771 for (size_t i = 0; i < device_id_list_.size(); ++i) { | 825 is_not_secondary_gpu = is_not_secondary_gpu && |
| 772 if (device_id_list_[i] == gpu_info.gpu.device_id) { | 826 GpuUnmatched(vendor_id_, device_id_list_, gpu_info.secondary_gpus[i]); |
| 773 found = true; | 827 } |
| 774 break; | 828 switch (multi_gpu_category_) { |
| 775 } | 829 case kMultiGpuCategoryPrimary: |
| 776 } | 830 if (is_not_primary_gpu) |
| 777 if (!found) | 831 return false; |
| 778 return false; | 832 break; |
| 833 case kMultiGpuCategorySecondary: |
| 834 if (is_not_secondary_gpu) |
| 835 return false; |
| 836 break; |
| 837 case kMultiGpuCategoryAny: |
| 838 if (is_not_primary_gpu && is_not_secondary_gpu) |
| 839 return false; |
| 840 break; |
| 841 default: |
| 842 break; |
| 779 } | 843 } |
| 780 switch (multi_gpu_style_) { | 844 switch (multi_gpu_style_) { |
| 781 case kMultiGpuStyleOptimus: | 845 case kMultiGpuStyleOptimus: |
| 782 if (!gpu_info.optimus) | 846 if (!gpu_info.optimus) |
| 783 return false; | 847 return false; |
| 784 break; | 848 break; |
| 785 case kMultiGpuStyleAMDSwitchable: | 849 case kMultiGpuStyleAMDSwitchable: |
| 786 if (!gpu_info.amd_switchable) | 850 if (!gpu_info.amd_switchable) |
| 787 return false; | 851 return false; |
| 788 break; | 852 break; |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1112 return kGT; | 1176 return kGT; |
| 1113 if (op == ">=") | 1177 if (op == ">=") |
| 1114 return kGE; | 1178 return kGE; |
| 1115 if (op == "any") | 1179 if (op == "any") |
| 1116 return kAny; | 1180 return kAny; |
| 1117 if (op == "between") | 1181 if (op == "between") |
| 1118 return kBetween; | 1182 return kBetween; |
| 1119 return kUnknown; | 1183 return kUnknown; |
| 1120 } | 1184 } |
| 1121 | 1185 |
| OLD | NEW |