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 "content/browser/gpu/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" |
11 #include "base/string_split.h" | 11 #include "base/string_split.h" |
12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
13 #include "base/sys_info.h" | 13 #include "base/sys_info.h" |
14 #include "base/version.h" | 14 #include "base/version.h" |
15 #include "chrome/browser/gpu_util.h" | 15 #include "content/browser/gpu/gpu_util.h" |
16 #include "chrome/common/chrome_version_info.h" | |
17 #include "content/public/browser/gpu_data_manager.h" | |
18 #include "content/public/common/content_switches.h" | 16 #include "content/public/common/content_switches.h" |
19 #include "content/public/common/gpu_info.h" | 17 #include "content/public/common/gpu_info.h" |
20 | 18 |
21 using content::GpuDataManager; | |
22 using content::GpuFeatureType; | 19 using content::GpuFeatureType; |
23 | 20 |
24 namespace { | 21 namespace { |
25 | 22 |
26 // Encode a date as Version, where [0] is year, [1] is month, and [2] is day. | 23 // Encode a date as Version, where [0] is year, [1] is month, and [2] is day. |
27 void GetDateFromString(const std::string& date_string, Version* version) { | 24 void GetDateFromString(const std::string& date_string, Version* version) { |
28 // TODO(zmo): verify if in Windows registry, driver dates are always in the | 25 // TODO(zmo): verify if in Windows registry, driver dates are always in the |
29 // format of "mm-dd-yyyy". | 26 // format of "mm-dd-yyyy". |
30 std::vector<std::string> pieces; | 27 std::vector<std::string> pieces; |
31 base::SplitString(date_string, '-', &pieces); | 28 base::SplitString(date_string, '-', &pieces); |
(...skipping 880 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
912 } | 909 } |
913 | 910 |
914 bool GpuBlacklist::GpuBlacklistEntry::disabled() const { | 911 bool GpuBlacklist::GpuBlacklistEntry::disabled() const { |
915 return disabled_; | 912 return disabled_; |
916 } | 913 } |
917 | 914 |
918 GpuFeatureType GpuBlacklist::GpuBlacklistEntry::GetGpuFeatureType() const { | 915 GpuFeatureType GpuBlacklist::GpuBlacklistEntry::GetGpuFeatureType() const { |
919 return feature_type_; | 916 return feature_type_; |
920 } | 917 } |
921 | 918 |
922 // static | |
923 GpuBlacklist* GpuBlacklist::GetInstance() { | |
924 return Singleton<GpuBlacklist>::get(); | |
925 } | |
926 | |
927 GpuBlacklist::GpuBlacklist() | 919 GpuBlacklist::GpuBlacklist() |
928 : max_entry_id_(0), | 920 : max_entry_id_(0), |
929 contains_unknown_fields_(false) { | 921 contains_unknown_fields_(false) { |
930 GpuDataManager::GetInstance()->AddObserver(this); | |
931 } | 922 } |
932 | 923 |
933 GpuBlacklist::~GpuBlacklist() { | 924 GpuBlacklist::~GpuBlacklist() { |
934 Clear(); | 925 Clear(); |
935 GpuDataManager::GetInstance()->RemoveObserver(this); | |
936 } | 926 } |
937 | 927 |
938 bool GpuBlacklist::LoadGpuBlacklist( | 928 bool GpuBlacklist::LoadGpuBlacklist( |
939 const std::string& json_context, GpuBlacklist::OsFilter os_filter) { | 929 const std::string& json_context, GpuBlacklist::OsFilter os_filter) { |
940 chrome::VersionInfo chrome_version_info; | 930 const std::string browser_version_string = "0"; |
941 std::string chrome_version_string = | 931 return LoadGpuBlacklist(browser_version_string, json_context, os_filter); |
942 chrome_version_info.is_valid() ? chrome_version_info.Version() : "0"; | |
943 return LoadGpuBlacklist(chrome_version_string, json_context, os_filter); | |
944 } | 932 } |
945 | 933 |
946 bool GpuBlacklist::LoadGpuBlacklist( | 934 bool GpuBlacklist::LoadGpuBlacklist( |
947 const std::string& browser_version_string, | 935 const std::string& browser_version_string, |
948 const std::string& json_context, | 936 const std::string& json_context, |
949 GpuBlacklist::OsFilter os_filter) { | 937 GpuBlacklist::OsFilter os_filter) { |
950 browser_version_.reset(new Version(browser_version_string)); | 938 browser_version_.reset(new Version(browser_version_string)); |
951 DCHECK(browser_version_->IsValid()); | 939 DCHECK(browser_version_->IsValid()); |
952 | 940 |
953 scoped_ptr<Value> root; | 941 scoped_ptr<Value> root; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1043 for (size_t i = 0; i < blacklist_.size(); ++i) { | 1031 for (size_t i = 0; i < blacklist_.size(); ++i) { |
1044 if (blacklist_[i]->Contains(os, *os_version, gpu_info)) { | 1032 if (blacklist_[i]->Contains(os, *os_version, gpu_info)) { |
1045 if (!blacklist_[i]->disabled()) | 1033 if (!blacklist_[i]->disabled()) |
1046 type |= blacklist_[i]->GetGpuFeatureType(); | 1034 type |= blacklist_[i]->GetGpuFeatureType(); |
1047 active_entries_.push_back(blacklist_[i]); | 1035 active_entries_.push_back(blacklist_[i]); |
1048 } | 1036 } |
1049 } | 1037 } |
1050 return static_cast<GpuFeatureType>(type); | 1038 return static_cast<GpuFeatureType>(type); |
1051 } | 1039 } |
1052 | 1040 |
1053 void GpuBlacklist::UpdateGpuDataManager() { | |
1054 content::GpuFeatureType feature_type = DetermineGpuFeatureType( | |
1055 GpuBlacklist::kOsAny, NULL, GpuDataManager::GetInstance()->GetGPUInfo()); | |
1056 GpuDataManager::GetInstance()->SetPreliminaryBlacklistedFeatures( | |
1057 feature_type); | |
1058 gpu_util::UpdateStats(); | |
1059 } | |
1060 | |
1061 void GpuBlacklist::GetGpuFeatureTypeEntries( | 1041 void GpuBlacklist::GetGpuFeatureTypeEntries( |
1062 content::GpuFeatureType feature, | 1042 content::GpuFeatureType feature, |
1063 std::vector<uint32>& entry_ids, | 1043 std::vector<uint32>& entry_ids, |
1064 bool disabled) const { | 1044 bool disabled) const { |
1065 entry_ids.clear(); | 1045 entry_ids.clear(); |
1066 for (size_t i = 0; i < active_entries_.size(); ++i) { | 1046 for (size_t i = 0; i < active_entries_.size(); ++i) { |
1067 if (((feature & active_entries_[i]->GetGpuFeatureType()) != 0) && | 1047 if (((feature & active_entries_[i]->GetGpuFeatureType()) != 0) && |
1068 disabled == active_entries_[i]->disabled()) | 1048 disabled == active_entries_[i]->disabled()) |
1069 entry_ids.push_back(active_entries_[i]->id()); | 1049 entry_ids.push_back(active_entries_[i]->id()); |
1070 } | 1050 } |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1156 new VersionInfo(version_op, "", version_string, version_string2)); | 1136 new VersionInfo(version_op, "", version_string, version_string2)); |
1157 if (!browser_version_info->IsValid()) | 1137 if (!browser_version_info->IsValid()) |
1158 return kMalformed; | 1138 return kMalformed; |
1159 if (browser_version_info->Contains(*browser_version_)) | 1139 if (browser_version_info->Contains(*browser_version_)) |
1160 return kSupported; | 1140 return kSupported; |
1161 return kUnsupported; | 1141 return kUnsupported; |
1162 } | 1142 } |
1163 return kSupported; | 1143 return kSupported; |
1164 } | 1144 } |
1165 | 1145 |
1166 void GpuBlacklist::OnGpuInfoUpdate() { | |
1167 UpdateGpuDataManager(); | |
1168 } | |
1169 | |
1170 // static | 1146 // static |
1171 GpuBlacklist::NumericOp GpuBlacklist::StringToNumericOp( | 1147 GpuBlacklist::NumericOp GpuBlacklist::StringToNumericOp( |
1172 const std::string& op) { | 1148 const std::string& op) { |
1173 if (op == "=") | 1149 if (op == "=") |
1174 return kEQ; | 1150 return kEQ; |
1175 if (op == "<") | 1151 if (op == "<") |
1176 return kLT; | 1152 return kLT; |
1177 if (op == "<=") | 1153 if (op == "<=") |
1178 return kLE; | 1154 return kLE; |
1179 if (op == ">") | 1155 if (op == ">") |
1180 return kGT; | 1156 return kGT; |
1181 if (op == ">=") | 1157 if (op == ">=") |
1182 return kGE; | 1158 return kGE; |
1183 if (op == "any") | 1159 if (op == "any") |
1184 return kAny; | 1160 return kAny; |
1185 if (op == "between") | 1161 if (op == "between") |
1186 return kBetween; | 1162 return kBetween; |
1187 return kUnknown; | 1163 return kUnknown; |
1188 } | 1164 } |
OLD | NEW |