[email protected] | 8173208 | 2011-02-14 10:36:59 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | d9f3793 | 2011-05-09 20:09:24 | [diff] [blame] | 5 | #include "content/browser/gpu/gpu_blacklist.h" |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 6 | |
| 7 | #include "base/json/json_reader.h" |
| 8 | #include "base/logging.h" |
| 9 | #include "base/string_number_conversions.h" |
[email protected] | f0221ea | 2011-03-01 22:09:49 | [diff] [blame] | 10 | #include "base/string_piece.h" |
| 11 | #include "base/string_split.h" |
[email protected] | 36ee032 | 2010-12-23 21:27:12 | [diff] [blame] | 12 | #include "base/string_util.h" |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 13 | #include "base/stringprintf.h" |
| 14 | #include "base/sys_info.h" |
| 15 | #include "base/values.h" |
| 16 | #include "base/version.h" |
[email protected] | f24a1e2b | 2011-04-08 01:48:48 | [diff] [blame] | 17 | #include "content/common/gpu/gpu_info.h" |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 18 | |
[email protected] | f0221ea | 2011-03-01 22:09:49 | [diff] [blame] | 19 | namespace { |
| 20 | |
| 21 | // Encode a date as Version, where [0] is year, [1] is month, and [2] is day. |
| 22 | Version* GetDateFromString(const std::string& date_string) { |
| 23 | // TODO(zmo): verify if in Windows registry, driver dates are always in the |
| 24 | // format of "mm-dd-yyyy". |
| 25 | std::vector<std::string> pieces; |
| 26 | base::SplitString(date_string, '-', &pieces); |
[email protected] | cf74694 | 2011-03-02 00:50:55 | [diff] [blame] | 27 | if (pieces.size() != 3) |
[email protected] | f0221ea | 2011-03-01 22:09:49 | [diff] [blame] | 28 | return NULL; |
[email protected] | cf74694 | 2011-03-02 00:50:55 | [diff] [blame] | 29 | std::string date_as_version_string = pieces[2]; |
| 30 | for (size_t i = 0; i < 2; ++i) { |
[email protected] | f0221ea | 2011-03-01 22:09:49 | [diff] [blame] | 31 | date_as_version_string += "."; |
| 32 | date_as_version_string += pieces[i]; |
| 33 | } |
| 34 | return Version::GetVersionFromString(date_as_version_string); |
| 35 | } |
| 36 | |
[email protected] | 198b5007 | 2011-04-18 17:00:45 | [diff] [blame] | 37 | Value* NewStatusValue(const char* name, const char* status) |
| 38 | { |
| 39 | DictionaryValue* value = new DictionaryValue(); |
| 40 | value->SetString("name", name); |
| 41 | value->SetString("status", status); |
| 42 | return value; |
| 43 | } |
| 44 | |
[email protected] | f0221ea | 2011-03-01 22:09:49 | [diff] [blame] | 45 | } // namespace anonymous |
| 46 | |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 47 | GpuBlacklist::VersionInfo::VersionInfo(const std::string& version_op, |
| 48 | const std::string& version_string, |
| 49 | const std::string& version_string2) { |
| 50 | op_ = StringToOp(version_op); |
| 51 | if (op_ == kUnknown || op_ == kAny) |
| 52 | return; |
| 53 | version_.reset(Version::GetVersionFromString(version_string)); |
| 54 | if (version_.get() == NULL) { |
| 55 | op_ = kUnknown; |
| 56 | return; |
| 57 | } |
| 58 | if (op_ == kBetween) { |
| 59 | version2_.reset(Version::GetVersionFromString(version_string2)); |
| 60 | if (version2_.get() == NULL) |
| 61 | op_ = kUnknown; |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | GpuBlacklist::VersionInfo::~VersionInfo() { |
| 66 | } |
| 67 | |
| 68 | bool GpuBlacklist::VersionInfo::Contains(const Version& version) const { |
| 69 | if (op_ == kUnknown) |
| 70 | return false; |
| 71 | if (op_ == kAny) |
| 72 | return true; |
| 73 | if (op_ == kEQ) { |
| 74 | // Handles cases where 10.6 is considered as containing 10.6.*. |
| 75 | const std::vector<uint16>& components_reference = version_->components(); |
| 76 | const std::vector<uint16>& components = version.components(); |
| 77 | for (size_t i = 0; i < components_reference.size(); ++i) { |
| 78 | if (i >= components.size() && components_reference[i] != 0) |
| 79 | return false; |
| 80 | if (components[i] != components_reference[i]) |
| 81 | return false; |
| 82 | } |
| 83 | return true; |
| 84 | } |
| 85 | int relation = version.CompareTo(*version_); |
| 86 | if (op_ == kEQ) |
| 87 | return (relation == 0); |
| 88 | else if (op_ == kLT) |
| 89 | return (relation < 0); |
| 90 | else if (op_ == kLE) |
| 91 | return (relation <= 0); |
| 92 | else if (op_ == kGT) |
| 93 | return (relation > 0); |
| 94 | else if (op_ == kGE) |
| 95 | return (relation >= 0); |
| 96 | // op_ == kBetween |
| 97 | if (relation < 0) |
| 98 | return false; |
| 99 | return version.CompareTo(*version2_) <= 0; |
| 100 | } |
| 101 | |
| 102 | bool GpuBlacklist::VersionInfo::IsValid() const { |
| 103 | return op_ != kUnknown; |
| 104 | } |
| 105 | |
| 106 | GpuBlacklist::VersionInfo::Op GpuBlacklist::VersionInfo::StringToOp( |
| 107 | const std::string& version_op) { |
| 108 | if (version_op == "=") |
| 109 | return kEQ; |
| 110 | else if (version_op == "<") |
| 111 | return kLT; |
| 112 | else if (version_op == "<=") |
| 113 | return kLE; |
| 114 | else if (version_op == ">") |
| 115 | return kGT; |
| 116 | else if (version_op == ">=") |
| 117 | return kGE; |
| 118 | else if (version_op == "any") |
| 119 | return kAny; |
| 120 | else if (version_op == "between") |
| 121 | return kBetween; |
| 122 | return kUnknown; |
| 123 | } |
| 124 | |
| 125 | GpuBlacklist::OsInfo::OsInfo(const std::string& os, |
| 126 | const std::string& version_op, |
| 127 | const std::string& version_string, |
| 128 | const std::string& version_string2) { |
| 129 | type_ = StringToOsType(os); |
| 130 | if (type_ != kOsUnknown) { |
| 131 | version_info_.reset( |
| 132 | new VersionInfo(version_op, version_string, version_string2)); |
| 133 | } |
| 134 | } |
| 135 | |
[email protected] | 1e60547 | 2010-12-16 21:41:40 | [diff] [blame] | 136 | GpuBlacklist::OsInfo::~OsInfo() {} |
| 137 | |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 138 | bool GpuBlacklist::OsInfo::Contains(OsType type, |
| 139 | const Version& version) const { |
| 140 | if (!IsValid()) |
| 141 | return false; |
| 142 | if (type_ != type && type_ != kOsAny) |
| 143 | return false; |
| 144 | return version_info_->Contains(version); |
| 145 | } |
| 146 | |
| 147 | bool GpuBlacklist::OsInfo::IsValid() const { |
| 148 | return type_ != kOsUnknown && version_info_->IsValid(); |
| 149 | } |
| 150 | |
| 151 | GpuBlacklist::OsType GpuBlacklist::OsInfo::type() const { |
| 152 | return type_; |
| 153 | } |
| 154 | |
| 155 | GpuBlacklist::OsType GpuBlacklist::OsInfo::StringToOsType( |
| 156 | const std::string& os) { |
| 157 | if (os == "win") |
| 158 | return kOsWin; |
| 159 | else if (os == "macosx") |
| 160 | return kOsMacosx; |
| 161 | else if (os == "linux") |
| 162 | return kOsLinux; |
[email protected] | f0db0ee | 2011-03-22 21:42:42 | [diff] [blame] | 163 | else if (os == "chromeos") |
| 164 | return kOsChromeOS; |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 165 | else if (os == "any") |
| 166 | return kOsAny; |
| 167 | return kOsUnknown; |
| 168 | } |
| 169 | |
[email protected] | 61ce18f | 2011-01-25 17:16:10 | [diff] [blame] | 170 | GpuBlacklist::StringInfo::StringInfo(const std::string& string_op, |
| 171 | const std::string& string_value) { |
| 172 | op_ = StringToOp(string_op); |
| 173 | value_ = StringToLowerASCII(string_value); |
| 174 | } |
| 175 | |
| 176 | bool GpuBlacklist::StringInfo::Contains(const std::string& value) const { |
| 177 | std::string my_value = StringToLowerASCII(value); |
| 178 | switch (op_) { |
| 179 | case kContains: |
| 180 | return strstr(my_value.c_str(), value_.c_str()) != NULL; |
| 181 | case kBeginWith: |
| 182 | return StartsWithASCII(my_value, value_, false); |
| 183 | case kEndWith: |
| 184 | return EndsWith(my_value, value_, false); |
| 185 | case kEQ: |
| 186 | return value_ == my_value; |
| 187 | default: |
| 188 | return false; |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | bool GpuBlacklist::StringInfo::IsValid() const { |
| 193 | return op_ != kUnknown; |
| 194 | } |
| 195 | |
| 196 | GpuBlacklist::StringInfo::Op GpuBlacklist::StringInfo::StringToOp( |
| 197 | const std::string& string_op) { |
| 198 | if (string_op == "=") |
| 199 | return kEQ; |
| 200 | else if (string_op == "contains") |
| 201 | return kContains; |
| 202 | else if (string_op == "beginwith") |
| 203 | return kBeginWith; |
| 204 | else if (string_op == "endwith") |
| 205 | return kEndWith; |
| 206 | return kUnknown; |
| 207 | } |
| 208 | |
[email protected] | 7f2f351 | 2011-08-25 01:27:54 | [diff] [blame] | 209 | // static |
[email protected] | 863d566 | 2011-08-25 23:15:10 | [diff] [blame] | 210 | GpuBlacklist::ScopedGpuBlacklistEntry |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 211 | GpuBlacklist::GpuBlacklistEntry::GetGpuBlacklistEntryFromValue( |
[email protected] | 88a9e784 | 2011-03-01 16:48:39 | [diff] [blame] | 212 | DictionaryValue* value, bool top_level) { |
[email protected] | c6540e2 | 2011-04-06 16:23:49 | [diff] [blame] | 213 | DCHECK(value); |
[email protected] | 7f2f351 | 2011-08-25 01:27:54 | [diff] [blame] | 214 | ScopedGpuBlacklistEntry entry(new GpuBlacklistEntry()); |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 215 | |
[email protected] | 005d0cf | 2011-05-31 18:13:53 | [diff] [blame] | 216 | size_t dictionary_entry_count = 0; |
| 217 | |
[email protected] | 88a9e784 | 2011-03-01 16:48:39 | [diff] [blame] | 218 | if (top_level) { |
[email protected] | 4bf0a52d | 2011-03-04 01:09:05 | [diff] [blame] | 219 | uint32 id; |
| 220 | if (!value->GetInteger("id", reinterpret_cast<int*>(&id)) || |
| 221 | !entry->SetId(id)) { |
| 222 | LOG(WARNING) << "Malformed id entry " << entry->id(); |
[email protected] | 88a9e784 | 2011-03-01 16:48:39 | [diff] [blame] | 223 | return NULL; |
| 224 | } |
[email protected] | 005d0cf | 2011-05-31 18:13:53 | [diff] [blame] | 225 | dictionary_entry_count++; |
[email protected] | 61ce18f | 2011-01-25 17:16:10 | [diff] [blame] | 226 | } |
| 227 | |
[email protected] | 47847e9c | 2011-03-03 01:17:41 | [diff] [blame] | 228 | std::string description; |
| 229 | if (value->GetString("description", &description)) { |
| 230 | entry->description_ = description; |
[email protected] | 005d0cf | 2011-05-31 18:13:53 | [diff] [blame] | 231 | dictionary_entry_count++; |
[email protected] | 47847e9c | 2011-03-03 01:17:41 | [diff] [blame] | 232 | } else { |
| 233 | entry->description_ = "The GPU is unavailable for an unexplained reason."; |
| 234 | } |
| 235 | |
| 236 | ListValue* cr_bugs; |
| 237 | if (value->GetList("cr_bugs", &cr_bugs)) { |
[email protected] | 4bf0a52d | 2011-03-04 01:09:05 | [diff] [blame] | 238 | for (size_t i = 0; i < cr_bugs->GetSize(); ++i) { |
[email protected] | 47847e9c | 2011-03-03 01:17:41 | [diff] [blame] | 239 | int bug_id; |
[email protected] | 4bf0a52d | 2011-03-04 01:09:05 | [diff] [blame] | 240 | if (cr_bugs->GetInteger(i, &bug_id)) { |
[email protected] | 47847e9c | 2011-03-03 01:17:41 | [diff] [blame] | 241 | entry->cr_bugs_.push_back(bug_id); |
[email protected] | 4bf0a52d | 2011-03-04 01:09:05 | [diff] [blame] | 242 | } else { |
[email protected] | 47847e9c | 2011-03-03 01:17:41 | [diff] [blame] | 243 | LOG(WARNING) << "Malformed cr_bugs entry " << entry->id(); |
[email protected] | 4bf0a52d | 2011-03-04 01:09:05 | [diff] [blame] | 244 | return NULL; |
| 245 | } |
[email protected] | 47847e9c | 2011-03-03 01:17:41 | [diff] [blame] | 246 | } |
[email protected] | 005d0cf | 2011-05-31 18:13:53 | [diff] [blame] | 247 | dictionary_entry_count++; |
[email protected] | 47847e9c | 2011-03-03 01:17:41 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | ListValue* webkit_bugs; |
| 251 | if (value->GetList("webkit_bugs", &webkit_bugs)) { |
[email protected] | 4bf0a52d | 2011-03-04 01:09:05 | [diff] [blame] | 252 | for (size_t i = 0; i < webkit_bugs->GetSize(); ++i) { |
[email protected] | 47847e9c | 2011-03-03 01:17:41 | [diff] [blame] | 253 | int bug_id; |
[email protected] | 4bf0a52d | 2011-03-04 01:09:05 | [diff] [blame] | 254 | if (webkit_bugs->GetInteger(i, &bug_id)) { |
[email protected] | 47847e9c | 2011-03-03 01:17:41 | [diff] [blame] | 255 | entry->webkit_bugs_.push_back(bug_id); |
[email protected] | 4bf0a52d | 2011-03-04 01:09:05 | [diff] [blame] | 256 | } else { |
[email protected] | 47847e9c | 2011-03-03 01:17:41 | [diff] [blame] | 257 | LOG(WARNING) << "Malformed webkit_bugs entry " << entry->id(); |
[email protected] | 4bf0a52d | 2011-03-04 01:09:05 | [diff] [blame] | 258 | return NULL; |
| 259 | } |
[email protected] | 47847e9c | 2011-03-03 01:17:41 | [diff] [blame] | 260 | } |
[email protected] | 005d0cf | 2011-05-31 18:13:53 | [diff] [blame] | 261 | dictionary_entry_count++; |
[email protected] | 47847e9c | 2011-03-03 01:17:41 | [diff] [blame] | 262 | } |
| 263 | |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 264 | DictionaryValue* os_value = NULL; |
| 265 | if (value->GetDictionary("os", &os_value)) { |
| 266 | std::string os_type; |
| 267 | std::string os_version_op = "any"; |
| 268 | std::string os_version_string; |
| 269 | std::string os_version_string2; |
| 270 | os_value->GetString("type", &os_type); |
| 271 | DictionaryValue* os_version_value = NULL; |
| 272 | if (os_value->GetDictionary("version", &os_version_value)) { |
| 273 | os_version_value->GetString("op", &os_version_op); |
| 274 | os_version_value->GetString("number", &os_version_string); |
| 275 | os_version_value->GetString("number2", &os_version_string2); |
| 276 | } |
| 277 | if (!entry->SetOsInfo(os_type, os_version_op, os_version_string, |
| 278 | os_version_string2)) { |
[email protected] | 4bf0a52d | 2011-03-04 01:09:05 | [diff] [blame] | 279 | LOG(WARNING) << "Malformed os entry " << entry->id(); |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 280 | return NULL; |
| 281 | } |
[email protected] | 005d0cf | 2011-05-31 18:13:53 | [diff] [blame] | 282 | dictionary_entry_count++; |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | std::string vendor_id; |
| 286 | if (value->GetString("vendor_id", &vendor_id)) { |
| 287 | if (!entry->SetVendorId(vendor_id)) { |
[email protected] | 4bf0a52d | 2011-03-04 01:09:05 | [diff] [blame] | 288 | LOG(WARNING) << "Malformed vendor_id entry " << entry->id(); |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 289 | return NULL; |
| 290 | } |
[email protected] | 005d0cf | 2011-05-31 18:13:53 | [diff] [blame] | 291 | dictionary_entry_count++; |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 292 | } |
| 293 | |
[email protected] | 4bf0a52d | 2011-03-04 01:09:05 | [diff] [blame] | 294 | ListValue* device_id_list; |
| 295 | if (value->GetList("device_id", &device_id_list)) { |
| 296 | for (size_t i = 0; i < device_id_list->GetSize(); ++i) { |
| 297 | std::string device_id; |
| 298 | if (!device_id_list->GetString(i, &device_id) || |
| 299 | !entry->AddDeviceId(device_id)) { |
| 300 | LOG(WARNING) << "Malformed device_id entry " << entry->id(); |
| 301 | return NULL; |
| 302 | } |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 303 | } |
[email protected] | 005d0cf | 2011-05-31 18:13:53 | [diff] [blame] | 304 | dictionary_entry_count++; |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 305 | } |
| 306 | |
[email protected] | 61ce18f | 2011-01-25 17:16:10 | [diff] [blame] | 307 | DictionaryValue* driver_vendor_value = NULL; |
| 308 | if (value->GetDictionary("driver_vendor", &driver_vendor_value)) { |
| 309 | std::string vendor_op; |
| 310 | std::string vendor_value; |
| 311 | driver_vendor_value->GetString("op", &vendor_op); |
| 312 | driver_vendor_value->GetString("value", &vendor_value); |
| 313 | if (!entry->SetDriverVendorInfo(vendor_op, vendor_value)) { |
[email protected] | f055be71 | 2011-03-23 21:18:27 | [diff] [blame] | 314 | LOG(WARNING) << "Malformed driver_vendor entry " << entry->id(); |
[email protected] | 61ce18f | 2011-01-25 17:16:10 | [diff] [blame] | 315 | return NULL; |
| 316 | } |
[email protected] | 005d0cf | 2011-05-31 18:13:53 | [diff] [blame] | 317 | dictionary_entry_count++; |
[email protected] | 61ce18f | 2011-01-25 17:16:10 | [diff] [blame] | 318 | } |
| 319 | |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 320 | DictionaryValue* driver_version_value = NULL; |
| 321 | if (value->GetDictionary("driver_version", &driver_version_value)) { |
| 322 | std::string driver_version_op = "any"; |
| 323 | std::string driver_version_string; |
| 324 | std::string driver_version_string2; |
| 325 | driver_version_value->GetString("op", &driver_version_op); |
| 326 | driver_version_value->GetString("number", &driver_version_string); |
| 327 | driver_version_value->GetString("number2", &driver_version_string2); |
| 328 | if (!entry->SetDriverVersionInfo(driver_version_op, driver_version_string, |
| 329 | driver_version_string2)) { |
[email protected] | f055be71 | 2011-03-23 21:18:27 | [diff] [blame] | 330 | LOG(WARNING) << "Malformed driver_version entry " << entry->id(); |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 331 | return NULL; |
| 332 | } |
[email protected] | 005d0cf | 2011-05-31 18:13:53 | [diff] [blame] | 333 | dictionary_entry_count++; |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 334 | } |
| 335 | |
[email protected] | f0221ea | 2011-03-01 22:09:49 | [diff] [blame] | 336 | DictionaryValue* driver_date_value = NULL; |
| 337 | if (value->GetDictionary("driver_date", &driver_date_value)) { |
| 338 | std::string driver_date_op = "any"; |
| 339 | std::string driver_date_string; |
| 340 | std::string driver_date_string2; |
| 341 | driver_date_value->GetString("op", &driver_date_op); |
| 342 | driver_date_value->GetString("number", &driver_date_string); |
| 343 | driver_date_value->GetString("number2", &driver_date_string2); |
| 344 | if (!entry->SetDriverDateInfo(driver_date_op, driver_date_string, |
| 345 | driver_date_string2)) { |
[email protected] | f055be71 | 2011-03-23 21:18:27 | [diff] [blame] | 346 | LOG(WARNING) << "Malformed driver_date entry " << entry->id(); |
[email protected] | f0221ea | 2011-03-01 22:09:49 | [diff] [blame] | 347 | return NULL; |
| 348 | } |
[email protected] | 005d0cf | 2011-05-31 18:13:53 | [diff] [blame] | 349 | dictionary_entry_count++; |
[email protected] | f0221ea | 2011-03-01 22:09:49 | [diff] [blame] | 350 | } |
| 351 | |
[email protected] | 916b977f | 2011-09-04 02:50:38 | [diff] [blame^] | 352 | DictionaryValue* gl_vendor_value = NULL; |
| 353 | if (value->GetDictionary("gl_vendor", &gl_vendor_value)) { |
| 354 | std::string vendor_op; |
| 355 | std::string vendor_value; |
| 356 | gl_vendor_value->GetString("op", &vendor_op); |
| 357 | gl_vendor_value->GetString("value", &vendor_value); |
| 358 | if (!entry->SetGLVendorInfo(vendor_op, vendor_value)) { |
| 359 | LOG(WARNING) << "Malformed gl_vendor entry " << entry->id(); |
| 360 | return NULL; |
| 361 | } |
| 362 | dictionary_entry_count++; |
| 363 | } |
| 364 | |
[email protected] | 61ce18f | 2011-01-25 17:16:10 | [diff] [blame] | 365 | DictionaryValue* gl_renderer_value = NULL; |
| 366 | if (value->GetDictionary("gl_renderer", &gl_renderer_value)) { |
| 367 | std::string renderer_op; |
| 368 | std::string renderer_value; |
| 369 | gl_renderer_value->GetString("op", &renderer_op); |
| 370 | gl_renderer_value->GetString("value", &renderer_value); |
| 371 | if (!entry->SetGLRendererInfo(renderer_op, renderer_value)) { |
[email protected] | 4bf0a52d | 2011-03-04 01:09:05 | [diff] [blame] | 372 | LOG(WARNING) << "Malformed gl_renderer entry " << entry->id(); |
[email protected] | 61ce18f | 2011-01-25 17:16:10 | [diff] [blame] | 373 | return NULL; |
| 374 | } |
[email protected] | 005d0cf | 2011-05-31 18:13:53 | [diff] [blame] | 375 | dictionary_entry_count++; |
[email protected] | 61ce18f | 2011-01-25 17:16:10 | [diff] [blame] | 376 | } |
| 377 | |
[email protected] | 88a9e784 | 2011-03-01 16:48:39 | [diff] [blame] | 378 | if (top_level) { |
| 379 | ListValue* blacklist_value = NULL; |
| 380 | if (!value->GetList("blacklist", &blacklist_value)) { |
[email protected] | 4bf0a52d | 2011-03-04 01:09:05 | [diff] [blame] | 381 | LOG(WARNING) << "Malformed blacklist entry " << entry->id(); |
[email protected] | 88a9e784 | 2011-03-01 16:48:39 | [diff] [blame] | 382 | return NULL; |
| 383 | } |
| 384 | std::vector<std::string> blacklist; |
| 385 | for (size_t i = 0; i < blacklist_value->GetSize(); ++i) { |
| 386 | std::string feature; |
| 387 | if (blacklist_value->GetString(i, &feature)) { |
| 388 | blacklist.push_back(feature); |
| 389 | } else { |
[email protected] | 4bf0a52d | 2011-03-04 01:09:05 | [diff] [blame] | 390 | LOG(WARNING) << "Malformed blacklist entry " << entry->id(); |
[email protected] | 88a9e784 | 2011-03-01 16:48:39 | [diff] [blame] | 391 | return NULL; |
| 392 | } |
| 393 | } |
| 394 | if (!entry->SetBlacklistedFeatures(blacklist)) { |
[email protected] | 4bf0a52d | 2011-03-04 01:09:05 | [diff] [blame] | 395 | LOG(WARNING) << "Malformed blacklist entry " << entry->id(); |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 396 | return NULL; |
| 397 | } |
[email protected] | 005d0cf | 2011-05-31 18:13:53 | [diff] [blame] | 398 | dictionary_entry_count++; |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 399 | } |
[email protected] | 88a9e784 | 2011-03-01 16:48:39 | [diff] [blame] | 400 | |
| 401 | if (top_level) { |
| 402 | ListValue* exception_list_value = NULL; |
| 403 | if (value->GetList("exceptions", &exception_list_value)) { |
| 404 | for (size_t i = 0; i < exception_list_value->GetSize(); ++i) { |
| 405 | DictionaryValue* exception_value = NULL; |
[email protected] | 4bf0a52d | 2011-03-04 01:09:05 | [diff] [blame] | 406 | if (!exception_list_value->GetDictionary(i, &exception_value)) { |
| 407 | LOG(WARNING) << "Malformed exceptions entry " << entry->id(); |
| 408 | return NULL; |
| 409 | } |
[email protected] | 7f2f351 | 2011-08-25 01:27:54 | [diff] [blame] | 410 | ScopedGpuBlacklistEntry exception( |
| 411 | GetGpuBlacklistEntryFromValue(exception_value, false)); |
[email protected] | 4bf0a52d | 2011-03-04 01:09:05 | [diff] [blame] | 412 | if (exception == NULL) { |
| 413 | LOG(WARNING) << "Malformed exceptions entry " << entry->id(); |
| 414 | return NULL; |
| 415 | } |
[email protected] | 7f2f351 | 2011-08-25 01:27:54 | [diff] [blame] | 416 | if (exception->contains_unknown_fields_) { |
| 417 | LOG(WARNING) << "Exception with unknown fields " << entry->id(); |
| 418 | entry->contains_unknown_fields_ = true; |
| 419 | } else { |
| 420 | entry->AddException(exception); |
| 421 | } |
[email protected] | 88a9e784 | 2011-03-01 16:48:39 | [diff] [blame] | 422 | } |
[email protected] | 005d0cf | 2011-05-31 18:13:53 | [diff] [blame] | 423 | dictionary_entry_count++; |
[email protected] | 88a9e784 | 2011-03-01 16:48:39 | [diff] [blame] | 424 | } |
[email protected] | 005d0cf | 2011-05-31 18:13:53 | [diff] [blame] | 425 | |
| 426 | DictionaryValue* browser_version_value = NULL; |
| 427 | // browser_version is processed in LoadGpuBlacklist(). |
| 428 | if (value->GetDictionary("browser_version", &browser_version_value)) |
| 429 | dictionary_entry_count++; |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 430 | } |
| 431 | |
[email protected] | 916b977f | 2011-09-04 02:50:38 | [diff] [blame^] | 432 | ListValue* channel_list_value = NULL; |
| 433 | if (value->GetList("browser_channels", &channel_list_value)) { |
| 434 | for (size_t i = 0; i < channel_list_value->GetSize(); ++i) { |
| 435 | std::string channel_value; |
| 436 | if (!channel_list_value->GetString(i, &channel_value)) { |
| 437 | LOG(WARNING) << "Malformed browser_channels entry " << entry->id(); |
| 438 | return NULL; |
| 439 | } |
| 440 | BrowserChannel channel = StringToBrowserChannel(channel_value); |
| 441 | if (channel == kUnknown) { |
| 442 | LOG(WARNING) << "Malformed browser_channels entry " << entry->id(); |
| 443 | return NULL; |
| 444 | } |
| 445 | entry->AddBrowserChannel(channel); |
| 446 | } |
| 447 | dictionary_entry_count++; |
| 448 | } |
| 449 | |
[email protected] | 005d0cf | 2011-05-31 18:13:53 | [diff] [blame] | 450 | if (value->size() != dictionary_entry_count) { |
[email protected] | 7f2f351 | 2011-08-25 01:27:54 | [diff] [blame] | 451 | LOG(WARNING) << "Entry with unknown fields " << entry->id(); |
| 452 | entry->contains_unknown_fields_ = true; |
[email protected] | 005d0cf | 2011-05-31 18:13:53 | [diff] [blame] | 453 | } |
[email protected] | 863d566 | 2011-08-25 23:15:10 | [diff] [blame] | 454 | return entry; |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | GpuBlacklist::GpuBlacklistEntry::GpuBlacklistEntry() |
[email protected] | 65708af | 2011-01-29 02:30:27 | [diff] [blame] | 458 | : id_(0), |
[email protected] | 7f2f351 | 2011-08-25 01:27:54 | [diff] [blame] | 459 | vendor_id_(0), |
| 460 | contains_unknown_fields_(false), |
| 461 | contains_unknown_features_(false) { |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 462 | } |
| 463 | |
[email protected] | 4bf0a52d | 2011-03-04 01:09:05 | [diff] [blame] | 464 | bool GpuBlacklist::GpuBlacklistEntry::SetId(uint32 id) { |
| 465 | if (id != 0) { |
| 466 | id_ = id; |
[email protected] | 61ce18f | 2011-01-25 17:16:10 | [diff] [blame] | 467 | return true; |
| 468 | } |
| 469 | return false; |
| 470 | } |
| 471 | |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 472 | bool GpuBlacklist::GpuBlacklistEntry::SetOsInfo( |
| 473 | const std::string& os, |
| 474 | const std::string& version_op, |
| 475 | const std::string& version_string, |
| 476 | const std::string& version_string2) { |
| 477 | os_info_.reset(new OsInfo(os, version_op, version_string, version_string2)); |
| 478 | return os_info_->IsValid(); |
| 479 | } |
| 480 | |
| 481 | bool GpuBlacklist::GpuBlacklistEntry::SetVendorId( |
| 482 | const std::string& vendor_id_string) { |
| 483 | vendor_id_ = 0; |
| 484 | return base::HexStringToInt(vendor_id_string, |
| 485 | reinterpret_cast<int*>(&vendor_id_)); |
| 486 | } |
| 487 | |
[email protected] | 4bf0a52d | 2011-03-04 01:09:05 | [diff] [blame] | 488 | bool GpuBlacklist::GpuBlacklistEntry::AddDeviceId( |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 489 | const std::string& device_id_string) { |
[email protected] | 4bf0a52d | 2011-03-04 01:09:05 | [diff] [blame] | 490 | uint32 device_id = 0; |
| 491 | if (base::HexStringToInt(device_id_string, |
| 492 | reinterpret_cast<int*>(&device_id))) { |
| 493 | device_id_list_.push_back(device_id); |
| 494 | return true; |
| 495 | } |
| 496 | return false; |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 497 | } |
| 498 | |
[email protected] | 61ce18f | 2011-01-25 17:16:10 | [diff] [blame] | 499 | bool GpuBlacklist::GpuBlacklistEntry::SetDriverVendorInfo( |
| 500 | const std::string& vendor_op, |
| 501 | const std::string& vendor_value) { |
| 502 | driver_vendor_info_.reset( |
| 503 | new StringInfo(vendor_op, vendor_value)); |
| 504 | return driver_vendor_info_->IsValid(); |
| 505 | } |
| 506 | |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 507 | bool GpuBlacklist::GpuBlacklistEntry::SetDriverVersionInfo( |
| 508 | const std::string& version_op, |
| 509 | const std::string& version_string, |
| 510 | const std::string& version_string2) { |
| 511 | driver_version_info_.reset( |
| 512 | new VersionInfo(version_op, version_string, version_string2)); |
| 513 | return driver_version_info_->IsValid(); |
| 514 | } |
| 515 | |
[email protected] | f0221ea | 2011-03-01 22:09:49 | [diff] [blame] | 516 | bool GpuBlacklist::GpuBlacklistEntry::SetDriverDateInfo( |
| 517 | const std::string& date_op, |
| 518 | const std::string& date_string, |
| 519 | const std::string& date_string2) { |
| 520 | driver_date_info_.reset( |
| 521 | new VersionInfo(date_op, date_string, date_string2)); |
| 522 | return driver_date_info_->IsValid(); |
| 523 | } |
| 524 | |
[email protected] | 916b977f | 2011-09-04 02:50:38 | [diff] [blame^] | 525 | bool GpuBlacklist::GpuBlacklistEntry::SetGLVendorInfo( |
| 526 | const std::string& vendor_op, |
| 527 | const std::string& vendor_value) { |
| 528 | gl_vendor_info_.reset( |
| 529 | new StringInfo(vendor_op, vendor_value)); |
| 530 | return gl_vendor_info_->IsValid(); |
| 531 | } |
| 532 | |
[email protected] | 61ce18f | 2011-01-25 17:16:10 | [diff] [blame] | 533 | bool GpuBlacklist::GpuBlacklistEntry::SetGLRendererInfo( |
| 534 | const std::string& renderer_op, |
| 535 | const std::string& renderer_value) { |
| 536 | gl_renderer_info_.reset( |
| 537 | new StringInfo(renderer_op, renderer_value)); |
| 538 | return gl_renderer_info_->IsValid(); |
| 539 | } |
| 540 | |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 541 | bool GpuBlacklist::GpuBlacklistEntry::SetBlacklistedFeatures( |
| 542 | const std::vector<std::string>& blacklisted_features) { |
| 543 | size_t size = blacklisted_features.size(); |
| 544 | if (size == 0) |
| 545 | return false; |
| 546 | uint32 flags = 0; |
| 547 | for (size_t i = 0; i < size; ++i) { |
| 548 | GpuFeatureFlags::GpuFeatureType type = |
| 549 | GpuFeatureFlags::StringToGpuFeatureType(blacklisted_features[i]); |
| 550 | switch (type) { |
| 551 | case GpuFeatureFlags::kGpuFeatureAccelerated2dCanvas: |
| 552 | case GpuFeatureFlags::kGpuFeatureAcceleratedCompositing: |
| 553 | case GpuFeatureFlags::kGpuFeatureWebgl: |
[email protected] | 4bf0a52d | 2011-03-04 01:09:05 | [diff] [blame] | 554 | case GpuFeatureFlags::kGpuFeatureMultisampling: |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 555 | case GpuFeatureFlags::kGpuFeatureAll: |
| 556 | flags |= type; |
| 557 | break; |
| 558 | case GpuFeatureFlags::kGpuFeatureUnknown: |
[email protected] | 7f2f351 | 2011-08-25 01:27:54 | [diff] [blame] | 559 | contains_unknown_features_ = true; |
| 560 | break; |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 561 | } |
| 562 | } |
| 563 | feature_flags_.reset(new GpuFeatureFlags()); |
| 564 | feature_flags_->set_flags(flags); |
| 565 | return true; |
| 566 | } |
| 567 | |
[email protected] | 88a9e784 | 2011-03-01 16:48:39 | [diff] [blame] | 568 | void GpuBlacklist::GpuBlacklistEntry::AddException( |
[email protected] | 863d566 | 2011-08-25 23:15:10 | [diff] [blame] | 569 | ScopedGpuBlacklistEntry exception) { |
[email protected] | 88a9e784 | 2011-03-01 16:48:39 | [diff] [blame] | 570 | exceptions_.push_back(exception); |
| 571 | } |
| 572 | |
[email protected] | 916b977f | 2011-09-04 02:50:38 | [diff] [blame^] | 573 | void GpuBlacklist::GpuBlacklistEntry::AddBrowserChannel( |
| 574 | BrowserChannel channel) { |
| 575 | DCHECK(channel != kUnknown); |
| 576 | browser_channels_.push_back(channel); |
| 577 | } |
| 578 | |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 579 | bool GpuBlacklist::GpuBlacklistEntry::Contains( |
[email protected] | 916b977f | 2011-09-04 02:50:38 | [diff] [blame^] | 580 | OsType os_type, const Version& os_version, BrowserChannel channel, |
| 581 | const GPUInfo& gpu_info) const { |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 582 | DCHECK(os_type != kOsAny); |
| 583 | if (os_info_.get() != NULL && !os_info_->Contains(os_type, os_version)) |
| 584 | return false; |
[email protected] | a61508e5 | 2011-03-08 17:59:42 | [diff] [blame] | 585 | if (vendor_id_ != 0 && vendor_id_ != gpu_info.vendor_id) |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 586 | return false; |
[email protected] | 4bf0a52d | 2011-03-04 01:09:05 | [diff] [blame] | 587 | if (device_id_list_.size() > 0) { |
| 588 | bool found = false; |
| 589 | for (size_t i = 0; i < device_id_list_.size(); ++i) { |
[email protected] | a61508e5 | 2011-03-08 17:59:42 | [diff] [blame] | 590 | if (device_id_list_[i] == gpu_info.device_id) { |
[email protected] | 4bf0a52d | 2011-03-04 01:09:05 | [diff] [blame] | 591 | found = true; |
| 592 | break; |
| 593 | } |
| 594 | } |
| 595 | if (!found) |
| 596 | return false; |
| 597 | } |
[email protected] | 61ce18f | 2011-01-25 17:16:10 | [diff] [blame] | 598 | if (driver_vendor_info_.get() != NULL && |
[email protected] | a61508e5 | 2011-03-08 17:59:42 | [diff] [blame] | 599 | !driver_vendor_info_->Contains(gpu_info.driver_vendor)) |
[email protected] | 61ce18f | 2011-01-25 17:16:10 | [diff] [blame] | 600 | return false; |
[email protected] | 079c4ad | 2011-02-19 00:05:57 | [diff] [blame] | 601 | if (driver_version_info_.get() != NULL) { |
| 602 | scoped_ptr<Version> driver_version( |
[email protected] | a61508e5 | 2011-03-08 17:59:42 | [diff] [blame] | 603 | Version::GetVersionFromString(gpu_info.driver_version)); |
[email protected] | 079c4ad | 2011-02-19 00:05:57 | [diff] [blame] | 604 | if (driver_version.get() == NULL || |
| 605 | !driver_version_info_->Contains(*driver_version)) |
| 606 | return false; |
| 607 | } |
[email protected] | f0221ea | 2011-03-01 22:09:49 | [diff] [blame] | 608 | if (driver_date_info_.get() != NULL) { |
[email protected] | a61508e5 | 2011-03-08 17:59:42 | [diff] [blame] | 609 | scoped_ptr<Version> driver_date(GetDateFromString(gpu_info.driver_date)); |
[email protected] | f0221ea | 2011-03-01 22:09:49 | [diff] [blame] | 610 | if (driver_date.get() == NULL || |
| 611 | !driver_date_info_->Contains(*driver_date)) |
| 612 | return false; |
| 613 | } |
[email protected] | 916b977f | 2011-09-04 02:50:38 | [diff] [blame^] | 614 | if (gl_vendor_info_.get() != NULL && |
| 615 | !gl_vendor_info_->Contains(gpu_info.gl_vendor)) |
| 616 | return false; |
[email protected] | 61ce18f | 2011-01-25 17:16:10 | [diff] [blame] | 617 | if (gl_renderer_info_.get() != NULL && |
[email protected] | a61508e5 | 2011-03-08 17:59:42 | [diff] [blame] | 618 | !gl_renderer_info_->Contains(gpu_info.gl_renderer)) |
[email protected] | 61ce18f | 2011-01-25 17:16:10 | [diff] [blame] | 619 | return false; |
[email protected] | 88a9e784 | 2011-03-01 16:48:39 | [diff] [blame] | 620 | for (size_t i = 0; i < exceptions_.size(); ++i) { |
[email protected] | 916b977f | 2011-09-04 02:50:38 | [diff] [blame^] | 621 | if (exceptions_[i]->Contains(os_type, os_version, channel, gpu_info)) |
| 622 | return false; |
[email protected] | 88a9e784 | 2011-03-01 16:48:39 | [diff] [blame] | 623 | } |
[email protected] | 916b977f | 2011-09-04 02:50:38 | [diff] [blame^] | 624 | bool rt = true; |
| 625 | if (browser_channels_.size() > 0) { |
| 626 | rt = false; |
| 627 | for (size_t i = 0; i < browser_channels_.size(); ++i) { |
| 628 | if (browser_channels_[i] == channel) { |
| 629 | rt = true; |
| 630 | break; |
| 631 | } |
| 632 | } |
| 633 | } |
| 634 | return rt; |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | GpuBlacklist::OsType GpuBlacklist::GpuBlacklistEntry::GetOsType() const { |
| 638 | if (os_info_.get() == NULL) |
[email protected] | fa26995 | 2011-02-12 20:23:11 | [diff] [blame] | 639 | return kOsAny; |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 640 | return os_info_->type(); |
| 641 | } |
| 642 | |
[email protected] | 61ce18f | 2011-01-25 17:16:10 | [diff] [blame] | 643 | uint32 GpuBlacklist::GpuBlacklistEntry::id() const { |
| 644 | return id_; |
| 645 | } |
| 646 | |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 647 | GpuFeatureFlags GpuBlacklist::GpuBlacklistEntry::GetGpuFeatureFlags() const { |
| 648 | return *feature_flags_; |
| 649 | } |
| 650 | |
[email protected] | 916b977f | 2011-09-04 02:50:38 | [diff] [blame^] | 651 | GpuBlacklist::GpuBlacklist(const std::string& browser_info_string) |
[email protected] | 7f2f351 | 2011-08-25 01:27:54 | [diff] [blame] | 652 | : max_entry_id_(0), |
| 653 | contains_unknown_fields_(false) { |
[email protected] | 916b977f | 2011-09-04 02:50:38 | [diff] [blame^] | 654 | SetBrowserInfo(browser_info_string); |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | GpuBlacklist::~GpuBlacklist() { |
| 658 | Clear(); |
| 659 | } |
| 660 | |
[email protected] | 7f2f351 | 2011-08-25 01:27:54 | [diff] [blame] | 661 | bool GpuBlacklist::LoadGpuBlacklist( |
| 662 | const std::string& json_context, GpuBlacklist::OsFilter os_filter) { |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 663 | scoped_ptr<Value> root; |
| 664 | root.reset(base::JSONReader::Read(json_context, false)); |
| 665 | if (root.get() == NULL || !root->IsType(Value::TYPE_DICTIONARY)) |
| 666 | return false; |
| 667 | |
[email protected] | 61ce18f | 2011-01-25 17:16:10 | [diff] [blame] | 668 | DictionaryValue* root_dictionary = static_cast<DictionaryValue*>(root.get()); |
| 669 | DCHECK(root_dictionary); |
[email protected] | 7f2f351 | 2011-08-25 01:27:54 | [diff] [blame] | 670 | return LoadGpuBlacklist(*root_dictionary, os_filter); |
[email protected] | bb4bf9d7 | 2011-02-26 02:37:38 | [diff] [blame] | 671 | } |
| 672 | |
[email protected] | 7f2f351 | 2011-08-25 01:27:54 | [diff] [blame] | 673 | bool GpuBlacklist::LoadGpuBlacklist( |
| 674 | const DictionaryValue& parsed_json, GpuBlacklist::OsFilter os_filter) { |
| 675 | std::vector<ScopedGpuBlacklistEntry> entries; |
[email protected] | bb4bf9d7 | 2011-02-26 02:37:38 | [diff] [blame] | 676 | |
[email protected] | 61ce18f | 2011-01-25 17:16:10 | [diff] [blame] | 677 | std::string version_string; |
[email protected] | bb4bf9d7 | 2011-02-26 02:37:38 | [diff] [blame] | 678 | parsed_json.GetString("version", &version_string); |
[email protected] | 61ce18f | 2011-01-25 17:16:10 | [diff] [blame] | 679 | version_.reset(Version::GetVersionFromString(version_string)); |
| 680 | if (version_.get() == NULL) |
| 681 | return false; |
| 682 | |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 683 | ListValue* list = NULL; |
[email protected] | 49090b6 | 2011-03-11 03:38:06 | [diff] [blame] | 684 | if (!parsed_json.GetList("entries", &list)) |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 685 | return false; |
| 686 | |
[email protected] | 61ce18f | 2011-01-25 17:16:10 | [diff] [blame] | 687 | uint32 max_entry_id = 0; |
[email protected] | 7f2f351 | 2011-08-25 01:27:54 | [diff] [blame] | 688 | bool contains_unknown_fields = false; |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 689 | for (size_t i = 0; i < list->GetSize(); ++i) { |
| 690 | DictionaryValue* list_item = NULL; |
| 691 | bool valid = list->GetDictionary(i, &list_item); |
[email protected] | 7f2f351 | 2011-08-25 01:27:54 | [diff] [blame] | 692 | if (!valid || list_item == NULL) |
| 693 | return false; |
[email protected] | c6540e2 | 2011-04-06 16:23:49 | [diff] [blame] | 694 | // Check browser version compatibility: if the entry is not for the |
| 695 | // current browser version, don't process it. |
| 696 | BrowserVersionSupport browser_version_support = |
| 697 | IsEntrySupportedByCurrentBrowserVersion(list_item); |
| 698 | if (browser_version_support == kMalformed) |
[email protected] | 7f2f351 | 2011-08-25 01:27:54 | [diff] [blame] | 699 | return false; |
| 700 | if (browser_version_support == kUnsupported) |
[email protected] | c6540e2 | 2011-04-06 16:23:49 | [diff] [blame] | 701 | continue; |
[email protected] | c6540e2 | 2011-04-06 16:23:49 | [diff] [blame] | 702 | DCHECK(browser_version_support == kSupported); |
[email protected] | 7f2f351 | 2011-08-25 01:27:54 | [diff] [blame] | 703 | ScopedGpuBlacklistEntry entry( |
| 704 | GpuBlacklistEntry::GetGpuBlacklistEntryFromValue(list_item, true)); |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 705 | if (entry == NULL) |
[email protected] | 7f2f351 | 2011-08-25 01:27:54 | [diff] [blame] | 706 | return false; |
[email protected] | 61ce18f | 2011-01-25 17:16:10 | [diff] [blame] | 707 | if (entry->id() > max_entry_id) |
| 708 | max_entry_id = entry->id(); |
[email protected] | 7f2f351 | 2011-08-25 01:27:54 | [diff] [blame] | 709 | // If an unknown field is encountered, skip the entry; if an unknown |
| 710 | // feature is encountered, ignore the feature, but keep the entry. |
| 711 | if (entry->contains_unknown_fields()) { |
| 712 | contains_unknown_fields = true; |
| 713 | continue; |
| 714 | } |
| 715 | if (entry->contains_unknown_features()) |
| 716 | contains_unknown_fields = true; |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 717 | entries.push_back(entry); |
| 718 | } |
| 719 | |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 720 | Clear(); |
[email protected] | 7f2f351 | 2011-08-25 01:27:54 | [diff] [blame] | 721 | OsType my_os = GetOsType(); |
| 722 | for (size_t i = 0; i < entries.size(); ++i) { |
| 723 | OsType entry_os = entries[i]->GetOsType(); |
| 724 | if (os_filter == GpuBlacklist::kAllOs || |
| 725 | entry_os == kOsAny || entry_os == my_os) |
| 726 | blacklist_.push_back(entries[i]); |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 727 | } |
[email protected] | 61ce18f | 2011-01-25 17:16:10 | [diff] [blame] | 728 | max_entry_id_ = max_entry_id; |
[email protected] | 7f2f351 | 2011-08-25 01:27:54 | [diff] [blame] | 729 | contains_unknown_fields_ = contains_unknown_fields; |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 730 | return true; |
| 731 | } |
| 732 | |
| 733 | GpuFeatureFlags GpuBlacklist::DetermineGpuFeatureFlags( |
| 734 | GpuBlacklist::OsType os, |
| 735 | Version* os_version, |
[email protected] | 61ce18f | 2011-01-25 17:16:10 | [diff] [blame] | 736 | const GPUInfo& gpu_info) { |
| 737 | active_entries_.clear(); |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 738 | GpuFeatureFlags flags; |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 739 | |
| 740 | if (os == kOsAny) |
| 741 | os = GetOsType(); |
| 742 | scoped_ptr<Version> my_os_version; |
| 743 | if (os_version == NULL) { |
[email protected] | 6e001bb | 2011-05-25 20:53:18 | [diff] [blame] | 744 | std::string version_string = base::SysInfo::OperatingSystemVersion(); |
[email protected] | 7004d7eb | 2011-01-21 00:27:53 | [diff] [blame] | 745 | size_t pos = version_string.find_first_not_of("0123456789."); |
| 746 | if (pos != std::string::npos) |
| 747 | version_string = version_string.substr(0, pos); |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 748 | my_os_version.reset(Version::GetVersionFromString(version_string)); |
| 749 | os_version = my_os_version.get(); |
| 750 | } |
| 751 | DCHECK(os_version != NULL); |
| 752 | |
| 753 | for (size_t i = 0; i < blacklist_.size(); ++i) { |
[email protected] | 916b977f | 2011-09-04 02:50:38 | [diff] [blame^] | 754 | if (blacklist_[i]->Contains(os, *os_version, browser_channel_, gpu_info)) { |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 755 | flags.Combine(blacklist_[i]->GetGpuFeatureFlags()); |
[email protected] | 61ce18f | 2011-01-25 17:16:10 | [diff] [blame] | 756 | active_entries_.push_back(blacklist_[i]); |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 757 | } |
| 758 | } |
| 759 | return flags; |
| 760 | } |
| 761 | |
[email protected] | 61ce18f | 2011-01-25 17:16:10 | [diff] [blame] | 762 | void GpuBlacklist::GetGpuFeatureFlagEntries( |
| 763 | GpuFeatureFlags::GpuFeatureType feature, |
| 764 | std::vector<uint32>& entry_ids) const { |
| 765 | entry_ids.clear(); |
| 766 | for (size_t i = 0; i < active_entries_.size(); ++i) { |
| 767 | if ((feature & active_entries_[i]->GetGpuFeatureFlags().flags()) != 0) |
| 768 | entry_ids.push_back(active_entries_[i]->id()); |
| 769 | } |
| 770 | } |
| 771 | |
[email protected] | 198b5007 | 2011-04-18 17:00:45 | [diff] [blame] | 772 | bool GpuBlacklist::IsFeatureBlacklisted( |
| 773 | GpuFeatureFlags::GpuFeatureType feature) const |
| 774 | { |
| 775 | for (size_t i = 0; i < active_entries_.size(); ++i) { |
| 776 | if (active_entries_[i]->GetGpuFeatureFlags().flags() & feature) |
| 777 | return true; |
| 778 | } |
| 779 | return false; |
| 780 | } |
| 781 | |
[email protected] | 7a13325 | 2011-04-12 18:17:40 | [diff] [blame] | 782 | Value* GpuBlacklist::GetFeatureStatus(bool gpu_access_allowed, |
| 783 | bool disable_accelerated_compositing, |
[email protected] | 206f3f0 | 2011-06-13 14:59:25 | [diff] [blame] | 784 | bool disable_accelerated_2D_canvas, |
[email protected] | 7a13325 | 2011-04-12 18:17:40 | [diff] [blame] | 785 | bool disable_experimental_webgl, |
| 786 | bool disable_multisampling) const { |
| 787 | DictionaryValue* status = new DictionaryValue(); |
[email protected] | 47847e9c | 2011-03-03 01:17:41 | [diff] [blame] | 788 | |
[email protected] | 198b5007 | 2011-04-18 17:00:45 | [diff] [blame] | 789 | // Build the feature_status field. |
[email protected] | 7a13325 | 2011-04-12 18:17:40 | [diff] [blame] | 790 | { |
| 791 | ListValue* feature_status_list = new ListValue(); |
[email protected] | 47847e9c | 2011-03-03 01:17:41 | [diff] [blame] | 792 | |
[email protected] | 198b5007 | 2011-04-18 17:00:45 | [diff] [blame] | 793 | // 2d_canvas. |
| 794 | if (!gpu_access_allowed) { |
[email protected] | 206f3f0 | 2011-06-13 14:59:25 | [diff] [blame] | 795 | if (disable_accelerated_2D_canvas) |
[email protected] | 95ef1cf | 2011-06-10 00:39:53 | [diff] [blame] | 796 | feature_status_list->Append(NewStatusValue("2d_canvas", |
| 797 | "software")); |
[email protected] | 206f3f0 | 2011-06-13 14:59:25 | [diff] [blame] | 798 | else |
| 799 | feature_status_list->Append(NewStatusValue("2d_canvas", |
| 800 | "unavailable_software")); |
| 801 | } else if (!disable_accelerated_2D_canvas) { |
[email protected] | 198b5007 | 2011-04-18 17:00:45 | [diff] [blame] | 802 | if (IsFeatureBlacklisted( |
| 803 | GpuFeatureFlags::kGpuFeatureAccelerated2dCanvas)) |
| 804 | feature_status_list->Append(NewStatusValue("2d_canvas", |
| 805 | "unavailable_software")); |
[email protected] | ac8c1c3 | 2011-08-02 04:10:43 | [diff] [blame] | 806 | else if (disable_accelerated_compositing) |
| 807 | feature_status_list->Append(NewStatusValue("2d_canvas", |
| 808 | "disabled_software")); |
[email protected] | 198b5007 | 2011-04-18 17:00:45 | [diff] [blame] | 809 | else |
| 810 | feature_status_list->Append(NewStatusValue("2d_canvas", |
| 811 | "enabled")); |
| 812 | } else { |
| 813 | feature_status_list->Append(NewStatusValue("2d_canvas", |
| 814 | "software")); |
[email protected] | 7a13325 | 2011-04-12 18:17:40 | [diff] [blame] | 815 | } |
[email protected] | 198b5007 | 2011-04-18 17:00:45 | [diff] [blame] | 816 | |
| 817 | // 3d css and compositing. |
| 818 | if (!gpu_access_allowed) { |
| 819 | feature_status_list->Append(NewStatusValue("3d_css", |
| 820 | "unavailable_off")); |
| 821 | feature_status_list->Append(NewStatusValue("compositing", |
| 822 | "unavailable_software")); |
| 823 | } else if (disable_accelerated_compositing) { |
| 824 | feature_status_list->Append(NewStatusValue("3d_css", |
| 825 | "unavailable_off")); |
| 826 | feature_status_list->Append(NewStatusValue("compositing", |
| 827 | "disabled_software")); |
| 828 | } else if (IsFeatureBlacklisted( |
| 829 | GpuFeatureFlags::kGpuFeatureAcceleratedCompositing)) { |
| 830 | feature_status_list->Append(NewStatusValue("3d_css", |
| 831 | "unavailable_off")); |
| 832 | feature_status_list->Append(NewStatusValue("compositing", |
| 833 | "disabled_software")); |
| 834 | } else { |
| 835 | feature_status_list->Append(NewStatusValue("3d_css", |
| 836 | "enabled")); |
| 837 | feature_status_list->Append(NewStatusValue("compositing", |
| 838 | "enabled")); |
| 839 | } |
| 840 | |
| 841 | // webgl |
| 842 | if (!gpu_access_allowed) |
| 843 | feature_status_list->Append(NewStatusValue("webgl", |
| 844 | "unavailable_off")); |
| 845 | else if (disable_experimental_webgl) |
| 846 | feature_status_list->Append(NewStatusValue("webgl", |
| 847 | "disabled_off")); |
| 848 | else if (IsFeatureBlacklisted( |
| 849 | GpuFeatureFlags::kGpuFeatureWebgl)) |
| 850 | feature_status_list->Append(NewStatusValue("webgl", |
| 851 | "unavailable_off")); |
[email protected] | ac8c1c3 | 2011-08-02 04:10:43 | [diff] [blame] | 852 | else if (disable_accelerated_compositing) |
| 853 | feature_status_list->Append(NewStatusValue("webgl", |
| 854 | "enabled_readback")); |
[email protected] | 198b5007 | 2011-04-18 17:00:45 | [diff] [blame] | 855 | else |
| 856 | feature_status_list->Append(NewStatusValue("webgl", |
| 857 | "enabled")); |
| 858 | |
| 859 | // multisampling |
| 860 | if (!gpu_access_allowed) |
| 861 | feature_status_list->Append(NewStatusValue("multisampling", |
| 862 | "unavailable_off")); |
[email protected] | 206f3f0 | 2011-06-13 14:59:25 | [diff] [blame] | 863 | else if (disable_multisampling) |
[email protected] | 198b5007 | 2011-04-18 17:00:45 | [diff] [blame] | 864 | feature_status_list->Append(NewStatusValue("multisampling", |
| 865 | "disabled_off")); |
| 866 | else if (IsFeatureBlacklisted( |
| 867 | GpuFeatureFlags::kGpuFeatureMultisampling)) |
| 868 | feature_status_list->Append(NewStatusValue("multisampling", |
| 869 | "disabled_off")); |
| 870 | else |
| 871 | feature_status_list->Append(NewStatusValue("multisampling", |
| 872 | "enabled")); |
| 873 | |
[email protected] | 7a13325 | 2011-04-12 18:17:40 | [diff] [blame] | 874 | status->Set("featureStatus", feature_status_list); |
[email protected] | 47847e9c | 2011-03-03 01:17:41 | [diff] [blame] | 875 | } |
[email protected] | 7a13325 | 2011-04-12 18:17:40 | [diff] [blame] | 876 | |
[email protected] | 198b5007 | 2011-04-18 17:00:45 | [diff] [blame] | 877 | // Build the problems list. |
[email protected] | 7a13325 | 2011-04-12 18:17:40 | [diff] [blame] | 878 | { |
| 879 | ListValue* problem_list = new ListValue(); |
[email protected] | 206f3f0 | 2011-06-13 14:59:25 | [diff] [blame] | 880 | if (!gpu_access_allowed) { |
[email protected] | 7a13325 | 2011-04-12 18:17:40 | [diff] [blame] | 881 | DictionaryValue* problem = new DictionaryValue(); |
| 882 | problem->SetString("description", |
| 883 | "GPU process was unable to boot. Access to GPU disallowed."); |
| 884 | problem->Set("crBugs", new ListValue()); |
| 885 | problem->Set("webkitBugs", new ListValue()); |
| 886 | problem_list->Append(problem); |
| 887 | } |
[email protected] | 206f3f0 | 2011-06-13 14:59:25 | [diff] [blame] | 888 | if (disable_accelerated_2D_canvas) { |
[email protected] | 7a13325 | 2011-04-12 18:17:40 | [diff] [blame] | 889 | DictionaryValue* problem = new DictionaryValue(); |
| 890 | problem->SetString("description", |
[email protected] | 206f3f0 | 2011-06-13 14:59:25 | [diff] [blame] | 891 | "Accelerated 2D canvas has been disabled at the command line"); |
[email protected] | 7a13325 | 2011-04-12 18:17:40 | [diff] [blame] | 892 | problem->Set("crBugs", new ListValue()); |
| 893 | problem->Set("webkitBugs", new ListValue()); |
| 894 | problem_list->Append(problem); |
| 895 | } |
[email protected] | 206f3f0 | 2011-06-13 14:59:25 | [diff] [blame] | 896 | if (disable_accelerated_compositing) { |
[email protected] | 7a13325 | 2011-04-12 18:17:40 | [diff] [blame] | 897 | DictionaryValue* problem = new DictionaryValue(); |
| 898 | problem->SetString("description", |
| 899 | "Accelerated compositing has been disabled, either via about:flags " |
[email protected] | ac8c1c3 | 2011-08-02 04:10:43 | [diff] [blame] | 900 | "or command line. This adversely affects performance of all hardware " |
| 901 | " accelerated features."); |
[email protected] | 7a13325 | 2011-04-12 18:17:40 | [diff] [blame] | 902 | problem->Set("crBugs", new ListValue()); |
| 903 | problem->Set("webkitBugs", new ListValue()); |
| 904 | problem_list->Append(problem); |
| 905 | } |
[email protected] | 206f3f0 | 2011-06-13 14:59:25 | [diff] [blame] | 906 | if (disable_experimental_webgl) { |
[email protected] | 7a13325 | 2011-04-12 18:17:40 | [diff] [blame] | 907 | DictionaryValue* problem = new DictionaryValue(); |
| 908 | problem->SetString("description", |
| 909 | "WebGL has been disabled, either via about:flags " |
| 910 | "or command line"); |
| 911 | problem->Set("crBugs", new ListValue()); |
| 912 | problem->Set("webkitBugs", new ListValue()); |
| 913 | problem_list->Append(problem); |
| 914 | } |
[email protected] | 206f3f0 | 2011-06-13 14:59:25 | [diff] [blame] | 915 | if (disable_multisampling) { |
[email protected] | 7a13325 | 2011-04-12 18:17:40 | [diff] [blame] | 916 | DictionaryValue* problem = new DictionaryValue(); |
| 917 | problem->SetString("description", |
| 918 | "Multisampling has been disabled, either via about:flags " |
| 919 | "or command line"); |
| 920 | problem->Set("crBugs", new ListValue()); |
| 921 | problem->Set("webkitBugs", new ListValue()); |
| 922 | problem_list->Append(problem); |
| 923 | } |
| 924 | for (size_t i = 0; i < active_entries_.size(); ++i) { |
[email protected] | 7f2f351 | 2011-08-25 01:27:54 | [diff] [blame] | 925 | ScopedGpuBlacklistEntry entry = active_entries_[i]; |
[email protected] | 7a13325 | 2011-04-12 18:17:40 | [diff] [blame] | 926 | DictionaryValue* problem = new DictionaryValue(); |
| 927 | |
| 928 | problem->SetString("description", entry->description()); |
| 929 | |
| 930 | ListValue* cr_bugs = new ListValue(); |
| 931 | for (size_t j = 0; j < entry->cr_bugs().size(); ++j) |
| 932 | cr_bugs->Append(Value::CreateIntegerValue( |
| 933 | entry->cr_bugs()[j])); |
| 934 | problem->Set("crBugs", cr_bugs); |
| 935 | |
| 936 | ListValue* webkit_bugs = new ListValue(); |
| 937 | for (size_t j = 0; j < entry->webkit_bugs().size(); ++j) |
| 938 | webkit_bugs->Append(Value::CreateIntegerValue( |
| 939 | entry->webkit_bugs()[j])); |
| 940 | problem->Set("webkitBugs", webkit_bugs); |
| 941 | |
| 942 | problem_list->Append(problem); |
| 943 | } |
| 944 | status->Set("problems", problem_list); |
| 945 | } |
| 946 | return status; |
[email protected] | 47847e9c | 2011-03-03 01:17:41 | [diff] [blame] | 947 | } |
| 948 | |
[email protected] | 7f2f351 | 2011-08-25 01:27:54 | [diff] [blame] | 949 | size_t GpuBlacklist::num_entries() const { |
| 950 | return blacklist_.size(); |
| 951 | } |
| 952 | |
[email protected] | 61ce18f | 2011-01-25 17:16:10 | [diff] [blame] | 953 | uint32 GpuBlacklist::max_entry_id() const { |
| 954 | return max_entry_id_; |
| 955 | } |
| 956 | |
| 957 | bool GpuBlacklist::GetVersion(uint16* major, uint16* minor) const { |
| 958 | DCHECK(major && minor); |
| 959 | *major = 0; |
| 960 | *minor = 0; |
| 961 | if (version_.get() == NULL) |
| 962 | return false; |
| 963 | const std::vector<uint16>& components_reference = version_->components(); |
| 964 | if (components_reference.size() != 2) |
| 965 | return false; |
| 966 | *major = components_reference[0]; |
| 967 | *minor = components_reference[1]; |
| 968 | return true; |
| 969 | } |
| 970 | |
[email protected] | bb4bf9d7 | 2011-02-26 02:37:38 | [diff] [blame] | 971 | bool GpuBlacklist::GetVersion( |
| 972 | const DictionaryValue& parsed_json, uint16* major, uint16* minor) { |
| 973 | DCHECK(major && minor); |
| 974 | *major = 0; |
| 975 | *minor = 0; |
| 976 | std::string version_string; |
| 977 | if (!parsed_json.GetString("version", &version_string)) |
| 978 | return false; |
| 979 | scoped_ptr<Version> version(Version::GetVersionFromString(version_string)); |
| 980 | if (version.get() == NULL) |
| 981 | return false; |
| 982 | const std::vector<uint16>& components_reference = version->components(); |
| 983 | if (components_reference.size() != 2) |
| 984 | return false; |
| 985 | *major = components_reference[0]; |
| 986 | *minor = components_reference[1]; |
| 987 | return true; |
| 988 | } |
| 989 | |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 990 | GpuBlacklist::OsType GpuBlacklist::GetOsType() { |
[email protected] | f0db0ee | 2011-03-22 21:42:42 | [diff] [blame] | 991 | #if defined(OS_CHROMEOS) |
[email protected] | f0db0ee | 2011-03-22 21:42:42 | [diff] [blame] | 992 | return kOsChromeOS; |
| 993 | #elif defined(OS_WIN) |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 994 | return kOsWin; |
| 995 | #elif defined(OS_LINUX) |
| 996 | return kOsLinux; |
| 997 | #elif defined(OS_MACOSX) |
| 998 | return kOsMacosx; |
| 999 | #else |
| 1000 | return kOsUnknown; |
| 1001 | #endif |
| 1002 | } |
| 1003 | |
| 1004 | void GpuBlacklist::Clear() { |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 1005 | blacklist_.clear(); |
[email protected] | 61ce18f | 2011-01-25 17:16:10 | [diff] [blame] | 1006 | active_entries_.clear(); |
[email protected] | 7f2f351 | 2011-08-25 01:27:54 | [diff] [blame] | 1007 | max_entry_id_ = 0; |
| 1008 | contains_unknown_fields_ = false; |
[email protected] | 2efc3118 | 2010-12-11 21:07:18 | [diff] [blame] | 1009 | } |
[email protected] | c6540e2 | 2011-04-06 16:23:49 | [diff] [blame] | 1010 | |
| 1011 | GpuBlacklist::BrowserVersionSupport |
| 1012 | GpuBlacklist::IsEntrySupportedByCurrentBrowserVersion( |
| 1013 | DictionaryValue* value) { |
| 1014 | DCHECK(value); |
| 1015 | DictionaryValue* browser_version_value = NULL; |
| 1016 | if (value->GetDictionary("browser_version", &browser_version_value)) { |
| 1017 | std::string version_op = "any"; |
| 1018 | std::string version_string; |
| 1019 | std::string version_string2; |
| 1020 | browser_version_value->GetString("op", &version_op); |
| 1021 | browser_version_value->GetString("number", &version_string); |
| 1022 | browser_version_value->GetString("number2", &version_string2); |
| 1023 | scoped_ptr<VersionInfo> browser_version_info; |
| 1024 | browser_version_info.reset( |
| 1025 | new VersionInfo(version_op, version_string, version_string2)); |
| 1026 | if (!browser_version_info->IsValid()) |
| 1027 | return kMalformed; |
| 1028 | if (browser_version_info->Contains(*browser_version_)) |
| 1029 | return kSupported; |
| 1030 | return kUnsupported; |
| 1031 | } |
| 1032 | return kSupported; |
| 1033 | } |
[email protected] | 916b977f | 2011-09-04 02:50:38 | [diff] [blame^] | 1034 | |
| 1035 | void GpuBlacklist::SetBrowserInfo(const std::string& browser_info_string) { |
| 1036 | std::vector<std::string> pieces; |
| 1037 | base::SplitString(browser_info_string, ' ', &pieces); |
| 1038 | if (pieces.size() != 2) { |
| 1039 | pieces.resize(2); |
| 1040 | pieces[0] = "0"; |
| 1041 | pieces[1] = "unknown"; |
| 1042 | } |
| 1043 | |
| 1044 | browser_version_.reset(Version::GetVersionFromString(pieces[0])); |
| 1045 | DCHECK(browser_version_.get() != NULL); |
| 1046 | |
| 1047 | browser_channel_ = StringToBrowserChannel(pieces[1]); |
| 1048 | } |
| 1049 | |
| 1050 | // static |
| 1051 | GpuBlacklist::BrowserChannel GpuBlacklist::StringToBrowserChannel( |
| 1052 | const std::string& value) { |
| 1053 | if (value == "stable") |
| 1054 | return kStable; |
| 1055 | if (value == "beta") |
| 1056 | return kBeta; |
| 1057 | if (value == "dev") |
| 1058 | return kDev; |
| 1059 | if (value == "canary") |
| 1060 | return kCanary; |
| 1061 | return kUnknown; |
| 1062 | } |
| 1063 | |