Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/browser/gpu/gpu_blacklist.h" | 5 #include "content/browser/gpu/gpu_blacklist.h" |
| 6 | 6 |
| 7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "base/string_piece.h" | 10 #include "base/string_piece.h" |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 216 size_t dictionary_entry_count = 0; | 216 size_t dictionary_entry_count = 0; |
| 217 | 217 |
| 218 if (top_level) { | 218 if (top_level) { |
| 219 uint32 id; | 219 uint32 id; |
| 220 if (!value->GetInteger("id", reinterpret_cast<int*>(&id)) || | 220 if (!value->GetInteger("id", reinterpret_cast<int*>(&id)) || |
| 221 !entry->SetId(id)) { | 221 !entry->SetId(id)) { |
| 222 LOG(WARNING) << "Malformed id entry " << entry->id(); | 222 LOG(WARNING) << "Malformed id entry " << entry->id(); |
| 223 return NULL; | 223 return NULL; |
| 224 } | 224 } |
| 225 dictionary_entry_count++; | 225 dictionary_entry_count++; |
| 226 | |
| 227 bool disabled; | |
| 228 if (value->GetBoolean("disabled", &disabled)) { | |
| 229 entry->SetDisabled(disabled); | |
| 230 dictionary_entry_count++; | |
| 231 } | |
| 226 } | 232 } |
| 227 | 233 |
| 228 std::string description; | 234 std::string description; |
| 229 if (value->GetString("description", &description)) { | 235 if (value->GetString("description", &description)) { |
| 230 entry->description_ = description; | 236 entry->description_ = description; |
| 231 dictionary_entry_count++; | 237 dictionary_entry_count++; |
| 232 } else { | 238 } else { |
| 233 entry->description_ = "The GPU is unavailable for an unexplained reason."; | 239 entry->description_ = "The GPU is unavailable for an unexplained reason."; |
| 234 } | 240 } |
| 235 | 241 |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 449 | 455 |
| 450 if (value->size() != dictionary_entry_count) { | 456 if (value->size() != dictionary_entry_count) { |
| 451 LOG(WARNING) << "Entry with unknown fields " << entry->id(); | 457 LOG(WARNING) << "Entry with unknown fields " << entry->id(); |
| 452 entry->contains_unknown_fields_ = true; | 458 entry->contains_unknown_fields_ = true; |
| 453 } | 459 } |
| 454 return entry; | 460 return entry; |
| 455 } | 461 } |
| 456 | 462 |
| 457 GpuBlacklist::GpuBlacklistEntry::GpuBlacklistEntry() | 463 GpuBlacklist::GpuBlacklistEntry::GpuBlacklistEntry() |
| 458 : id_(0), | 464 : id_(0), |
| 465 disabled_(false), | |
| 459 vendor_id_(0), | 466 vendor_id_(0), |
| 460 contains_unknown_fields_(false), | 467 contains_unknown_fields_(false), |
| 461 contains_unknown_features_(false) { | 468 contains_unknown_features_(false) { |
| 462 } | 469 } |
| 463 | 470 |
| 464 bool GpuBlacklist::GpuBlacklistEntry::SetId(uint32 id) { | 471 bool GpuBlacklist::GpuBlacklistEntry::SetId(uint32 id) { |
| 465 if (id != 0) { | 472 if (id != 0) { |
| 466 id_ = id; | 473 id_ = id; |
| 467 return true; | 474 return true; |
| 468 } | 475 } |
| 469 return false; | 476 return false; |
| 470 } | 477 } |
| 471 | 478 |
| 479 void GpuBlacklist::GpuBlacklistEntry::SetDisabled(bool disabled) { | |
| 480 disabled_ = disabled; | |
| 481 } | |
| 482 | |
| 472 bool GpuBlacklist::GpuBlacklistEntry::SetOsInfo( | 483 bool GpuBlacklist::GpuBlacklistEntry::SetOsInfo( |
| 473 const std::string& os, | 484 const std::string& os, |
| 474 const std::string& version_op, | 485 const std::string& version_op, |
| 475 const std::string& version_string, | 486 const std::string& version_string, |
| 476 const std::string& version_string2) { | 487 const std::string& version_string2) { |
| 477 os_info_.reset(new OsInfo(os, version_op, version_string, version_string2)); | 488 os_info_.reset(new OsInfo(os, version_op, version_string, version_string2)); |
| 478 return os_info_->IsValid(); | 489 return os_info_->IsValid(); |
| 479 } | 490 } |
| 480 | 491 |
| 481 bool GpuBlacklist::GpuBlacklistEntry::SetVendorId( | 492 bool GpuBlacklist::GpuBlacklistEntry::SetVendorId( |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 637 GpuBlacklist::OsType GpuBlacklist::GpuBlacklistEntry::GetOsType() const { | 648 GpuBlacklist::OsType GpuBlacklist::GpuBlacklistEntry::GetOsType() const { |
| 638 if (os_info_.get() == NULL) | 649 if (os_info_.get() == NULL) |
| 639 return kOsAny; | 650 return kOsAny; |
| 640 return os_info_->type(); | 651 return os_info_->type(); |
| 641 } | 652 } |
| 642 | 653 |
| 643 uint32 GpuBlacklist::GpuBlacklistEntry::id() const { | 654 uint32 GpuBlacklist::GpuBlacklistEntry::id() const { |
| 644 return id_; | 655 return id_; |
| 645 } | 656 } |
| 646 | 657 |
| 658 bool GpuBlacklist::GpuBlacklistEntry::disabled() const { | |
| 659 return disabled_; | |
| 660 } | |
| 661 | |
| 647 GpuFeatureFlags GpuBlacklist::GpuBlacklistEntry::GetGpuFeatureFlags() const { | 662 GpuFeatureFlags GpuBlacklist::GpuBlacklistEntry::GetGpuFeatureFlags() const { |
| 648 return *feature_flags_; | 663 return *feature_flags_; |
| 649 } | 664 } |
| 650 | 665 |
| 651 GpuBlacklist::GpuBlacklist(const std::string& browser_info_string) | 666 GpuBlacklist::GpuBlacklist(const std::string& browser_info_string) |
| 652 : max_entry_id_(0), | 667 : max_entry_id_(0), |
| 653 contains_unknown_fields_(false) { | 668 contains_unknown_fields_(false) { |
| 654 SetBrowserInfo(browser_info_string); | 669 SetBrowserInfo(browser_info_string); |
| 655 } | 670 } |
| 656 | 671 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 745 size_t pos = version_string.find_first_not_of("0123456789."); | 760 size_t pos = version_string.find_first_not_of("0123456789."); |
| 746 if (pos != std::string::npos) | 761 if (pos != std::string::npos) |
| 747 version_string = version_string.substr(0, pos); | 762 version_string = version_string.substr(0, pos); |
| 748 my_os_version.reset(Version::GetVersionFromString(version_string)); | 763 my_os_version.reset(Version::GetVersionFromString(version_string)); |
| 749 os_version = my_os_version.get(); | 764 os_version = my_os_version.get(); |
| 750 } | 765 } |
| 751 DCHECK(os_version != NULL); | 766 DCHECK(os_version != NULL); |
| 752 | 767 |
| 753 for (size_t i = 0; i < blacklist_.size(); ++i) { | 768 for (size_t i = 0; i < blacklist_.size(); ++i) { |
| 754 if (blacklist_[i]->Contains(os, *os_version, browser_channel_, gpu_info)) { | 769 if (blacklist_[i]->Contains(os, *os_version, browser_channel_, gpu_info)) { |
| 755 flags.Combine(blacklist_[i]->GetGpuFeatureFlags()); | 770 if (blacklist_[i]->disabled()) { |
| 756 active_entries_.push_back(blacklist_[i]); | 771 active_disabled_entries_.push_back(blacklist_[i]); |
|
vangelis
2011/09/21 21:27:17
nit: active_disabled_ is somewhat contradicting.
Zhenyao Mo
2011/09/22 17:10:39
removed active_disabled_emtries_
| |
| 772 } else { | |
| 773 flags.Combine(blacklist_[i]->GetGpuFeatureFlags()); | |
|
vangelis
2011/09/21 21:27:17
Wouldn't it be simpler to add a disabled_ field in
Zhenyao Mo
2011/09/22 17:10:39
Done.
| |
| 774 active_entries_.push_back(blacklist_[i]); | |
| 775 } | |
| 757 } | 776 } |
| 758 } | 777 } |
| 759 return flags; | 778 return flags; |
| 760 } | 779 } |
| 761 | 780 |
| 762 void GpuBlacklist::GetGpuFeatureFlagEntries( | 781 void GpuBlacklist::GetGpuFeatureFlagEntries( |
| 763 GpuFeatureFlags::GpuFeatureType feature, | 782 GpuFeatureFlags::GpuFeatureType feature, |
| 764 std::vector<uint32>& entry_ids) const { | 783 std::vector<uint32>& entry_ids) const { |
| 765 entry_ids.clear(); | 784 entry_ids.clear(); |
| 766 for (size_t i = 0; i < active_entries_.size(); ++i) { | 785 for (size_t i = 0; i < active_entries_.size(); ++i) { |
| 767 if ((feature & active_entries_[i]->GetGpuFeatureFlags().flags()) != 0) | 786 if ((feature & active_entries_[i]->GetGpuFeatureFlags().flags()) != 0) |
| 768 entry_ids.push_back(active_entries_[i]->id()); | 787 entry_ids.push_back(active_entries_[i]->id()); |
| 769 } | 788 } |
| 770 } | 789 } |
| 771 | 790 |
| 791 void GpuBlacklist::GetGpuFeatureFlagDisabledEntries( | |
|
vangelis
2011/09/21 21:27:17
Instead of replicating the code here, this functio
Zhenyao Mo
2011/09/22 17:10:39
Done. I used a consolidated array to store the en
| |
| 792 GpuFeatureFlags::GpuFeatureType feature, | |
| 793 std::vector<uint32>& entry_ids) const { | |
| 794 entry_ids.clear(); | |
| 795 for (size_t i = 0; i < active_disabled_entries_.size(); ++i) { | |
| 796 if ((feature & | |
| 797 active_disabled_entries_[i]->GetGpuFeatureFlags().flags()) != 0) | |
| 798 entry_ids.push_back(active_disabled_entries_[i]->id()); | |
| 799 } | |
| 800 } | |
| 801 | |
| 772 bool GpuBlacklist::IsFeatureBlacklisted( | 802 bool GpuBlacklist::IsFeatureBlacklisted( |
| 773 GpuFeatureFlags::GpuFeatureType feature) const | 803 GpuFeatureFlags::GpuFeatureType feature) const |
| 774 { | 804 { |
| 775 for (size_t i = 0; i < active_entries_.size(); ++i) { | 805 for (size_t i = 0; i < active_entries_.size(); ++i) { |
| 776 if (active_entries_[i]->GetGpuFeatureFlags().flags() & feature) | 806 if (active_entries_[i]->GetGpuFeatureFlags().flags() & feature) |
| 777 return true; | 807 return true; |
| 778 } | 808 } |
| 779 return false; | 809 return false; |
| 780 } | 810 } |
| 781 | 811 |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1054 return kStable; | 1084 return kStable; |
| 1055 if (value == "beta") | 1085 if (value == "beta") |
| 1056 return kBeta; | 1086 return kBeta; |
| 1057 if (value == "dev") | 1087 if (value == "dev") |
| 1058 return kDev; | 1088 return kDev; |
| 1059 if (value == "canary") | 1089 if (value == "canary") |
| 1060 return kCanary; | 1090 return kCanary; |
| 1061 return kUnknown; | 1091 return kUnknown; |
| 1062 } | 1092 } |
| 1063 | 1093 |
| OLD | NEW |