| OLD | NEW |
| 1 // Copyright (c) 2011 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 "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" |
| 11 #include "base/string_split.h" | 11 #include "base/string_split.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 32 date_as_version_string += pieces[i]; | 32 date_as_version_string += pieces[i]; |
| 33 } | 33 } |
| 34 return Version::GetVersionFromString(date_as_version_string); | 34 return Version::GetVersionFromString(date_as_version_string); |
| 35 } | 35 } |
| 36 | 36 |
| 37 } // namespace anonymous | 37 } // namespace anonymous |
| 38 | 38 |
| 39 GpuBlacklist::VersionInfo::VersionInfo(const std::string& version_op, | 39 GpuBlacklist::VersionInfo::VersionInfo(const std::string& version_op, |
| 40 const std::string& version_string, | 40 const std::string& version_string, |
| 41 const std::string& version_string2) { | 41 const std::string& version_string2) { |
| 42 op_ = StringToOp(version_op); | 42 op_ = StringToNumericOp(version_op); |
| 43 if (op_ == kUnknown || op_ == kAny) | 43 if (op_ == kUnknown || op_ == kAny) |
| 44 return; | 44 return; |
| 45 version_.reset(Version::GetVersionFromString(version_string)); | 45 version_.reset(Version::GetVersionFromString(version_string)); |
| 46 if (version_.get() == NULL) { | 46 if (version_.get() == NULL) { |
| 47 op_ = kUnknown; | 47 op_ = kUnknown; |
| 48 return; | 48 return; |
| 49 } | 49 } |
| 50 if (op_ == kBetween) { | 50 if (op_ == kBetween) { |
| 51 version2_.reset(Version::GetVersionFromString(version_string2)); | 51 version2_.reset(Version::GetVersionFromString(version_string2)); |
| 52 if (version2_.get() == NULL) | 52 if (version2_.get() == NULL) |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 // op_ == kBetween | 88 // op_ == kBetween |
| 89 if (relation < 0) | 89 if (relation < 0) |
| 90 return false; | 90 return false; |
| 91 return version.CompareTo(*version2_) <= 0; | 91 return version.CompareTo(*version2_) <= 0; |
| 92 } | 92 } |
| 93 | 93 |
| 94 bool GpuBlacklist::VersionInfo::IsValid() const { | 94 bool GpuBlacklist::VersionInfo::IsValid() const { |
| 95 return op_ != kUnknown; | 95 return op_ != kUnknown; |
| 96 } | 96 } |
| 97 | 97 |
| 98 GpuBlacklist::VersionInfo::Op GpuBlacklist::VersionInfo::StringToOp( | |
| 99 const std::string& version_op) { | |
| 100 if (version_op == "=") | |
| 101 return kEQ; | |
| 102 else if (version_op == "<") | |
| 103 return kLT; | |
| 104 else if (version_op == "<=") | |
| 105 return kLE; | |
| 106 else if (version_op == ">") | |
| 107 return kGT; | |
| 108 else if (version_op == ">=") | |
| 109 return kGE; | |
| 110 else if (version_op == "any") | |
| 111 return kAny; | |
| 112 else if (version_op == "between") | |
| 113 return kBetween; | |
| 114 return kUnknown; | |
| 115 } | |
| 116 | |
| 117 GpuBlacklist::OsInfo::OsInfo(const std::string& os, | 98 GpuBlacklist::OsInfo::OsInfo(const std::string& os, |
| 118 const std::string& version_op, | 99 const std::string& version_op, |
| 119 const std::string& version_string, | 100 const std::string& version_string, |
| 120 const std::string& version_string2) { | 101 const std::string& version_string2) { |
| 121 type_ = StringToOsType(os); | 102 type_ = StringToOsType(os); |
| 122 if (type_ != kOsUnknown) { | 103 if (type_ != kOsUnknown) { |
| 123 version_info_.reset( | 104 version_info_.reset( |
| 124 new VersionInfo(version_op, version_string, version_string2)); | 105 new VersionInfo(version_op, version_string, version_string2)); |
| 125 } | 106 } |
| 126 } | 107 } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 return kEQ; | 172 return kEQ; |
| 192 else if (string_op == "contains") | 173 else if (string_op == "contains") |
| 193 return kContains; | 174 return kContains; |
| 194 else if (string_op == "beginwith") | 175 else if (string_op == "beginwith") |
| 195 return kBeginWith; | 176 return kBeginWith; |
| 196 else if (string_op == "endwith") | 177 else if (string_op == "endwith") |
| 197 return kEndWith; | 178 return kEndWith; |
| 198 return kUnknown; | 179 return kUnknown; |
| 199 } | 180 } |
| 200 | 181 |
| 182 GpuBlacklist::FloatInfo::FloatInfo(const std::string& float_op, |
| 183 const std::string& float_value, |
| 184 const std::string& float_value2) |
| 185 : op_(kUnknown), |
| 186 value_(0.f), |
| 187 value2_(0.f) { |
| 188 double dvalue = 0; |
| 189 if (!base::StringToDouble(float_value, &dvalue)) { |
| 190 op_ = kUnknown; |
| 191 return; |
| 192 } |
| 193 value_ = static_cast<float>(dvalue); |
| 194 op_ = StringToNumericOp(float_op); |
| 195 if (op_ == kBetween) { |
| 196 if (!base::StringToDouble(float_value2, &dvalue)) { |
| 197 op_ = kUnknown; |
| 198 return; |
| 199 } |
| 200 value2_ = static_cast<float>(dvalue); |
| 201 } |
| 202 } |
| 203 |
| 204 bool GpuBlacklist::FloatInfo::Contains(float value) const { |
| 205 if (op_ == kUnknown) |
| 206 return false; |
| 207 if (op_ == kAny) |
| 208 return true; |
| 209 if (op_ == kEQ) |
| 210 return (value == value_); |
| 211 if (op_ == kLT) |
| 212 return (value < value_); |
| 213 if (op_ == kLE) |
| 214 return (value <= value_); |
| 215 if (op_ == kGT) |
| 216 return (value > value_); |
| 217 if (op_ == kGE) |
| 218 return (value >= value_); |
| 219 DCHECK(op_ == kBetween); |
| 220 return ((value_ <= value && value <= value2_) || |
| 221 (value2_ <= value && value <= value_)); |
| 222 } |
| 223 |
| 224 bool GpuBlacklist::FloatInfo::IsValid() const { |
| 225 return op_ != kUnknown; |
| 226 } |
| 227 |
| 201 // static | 228 // static |
| 202 GpuBlacklist::ScopedGpuBlacklistEntry | 229 GpuBlacklist::ScopedGpuBlacklistEntry |
| 203 GpuBlacklist::GpuBlacklistEntry::GetGpuBlacklistEntryFromValue( | 230 GpuBlacklist::GpuBlacklistEntry::GetGpuBlacklistEntryFromValue( |
| 204 DictionaryValue* value, bool top_level) { | 231 DictionaryValue* value, bool top_level) { |
| 205 DCHECK(value); | 232 DCHECK(value); |
| 206 ScopedGpuBlacklistEntry entry(new GpuBlacklistEntry()); | 233 ScopedGpuBlacklistEntry entry(new GpuBlacklistEntry()); |
| 207 | 234 |
| 208 size_t dictionary_entry_count = 0; | 235 size_t dictionary_entry_count = 0; |
| 209 | 236 |
| 210 if (top_level) { | 237 if (top_level) { |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 std::string renderer_value; | 393 std::string renderer_value; |
| 367 gl_renderer_value->GetString("op", &renderer_op); | 394 gl_renderer_value->GetString("op", &renderer_op); |
| 368 gl_renderer_value->GetString("value", &renderer_value); | 395 gl_renderer_value->GetString("value", &renderer_value); |
| 369 if (!entry->SetGLRendererInfo(renderer_op, renderer_value)) { | 396 if (!entry->SetGLRendererInfo(renderer_op, renderer_value)) { |
| 370 LOG(WARNING) << "Malformed gl_renderer entry " << entry->id(); | 397 LOG(WARNING) << "Malformed gl_renderer entry " << entry->id(); |
| 371 return NULL; | 398 return NULL; |
| 372 } | 399 } |
| 373 dictionary_entry_count++; | 400 dictionary_entry_count++; |
| 374 } | 401 } |
| 375 | 402 |
| 403 DictionaryValue* perf_graphics_value = NULL; |
| 404 if (value->GetDictionary("perf_graphics", &perf_graphics_value)) { |
| 405 std::string op; |
| 406 std::string float_value; |
| 407 std::string float_value2; |
| 408 perf_graphics_value->GetString("op", &op); |
| 409 perf_graphics_value->GetString("value", &float_value); |
| 410 perf_graphics_value->GetString("value2", &float_value2); |
| 411 if (!entry->SetPerfGraphicsInfo(op, float_value, float_value2)) { |
| 412 LOG(WARNING) << "Malformed perf_graphics entry " << entry->id(); |
| 413 return NULL; |
| 414 } |
| 415 dictionary_entry_count++; |
| 416 } |
| 417 |
| 418 DictionaryValue* perf_gaming_value = NULL; |
| 419 if (value->GetDictionary("perf_gaming", &perf_gaming_value)) { |
| 420 std::string op; |
| 421 std::string float_value; |
| 422 std::string float_value2; |
| 423 perf_gaming_value->GetString("op", &op); |
| 424 perf_gaming_value->GetString("value", &float_value); |
| 425 perf_gaming_value->GetString("value2", &float_value2); |
| 426 if (!entry->SetPerfGamingInfo(op, float_value, float_value2)) { |
| 427 LOG(WARNING) << "Malformed perf_gaming entry " << entry->id(); |
| 428 return NULL; |
| 429 } |
| 430 dictionary_entry_count++; |
| 431 } |
| 432 |
| 433 DictionaryValue* perf_overall_value = NULL; |
| 434 if (value->GetDictionary("perf_overall", &perf_overall_value)) { |
| 435 std::string op; |
| 436 std::string float_value; |
| 437 std::string float_value2; |
| 438 perf_overall_value->GetString("op", &op); |
| 439 perf_overall_value->GetString("value", &float_value); |
| 440 perf_overall_value->GetString("value2", &float_value2); |
| 441 if (!entry->SetPerfOverallInfo(op, float_value, float_value2)) { |
| 442 LOG(WARNING) << "Malformed perf_overall entry " << entry->id(); |
| 443 return NULL; |
| 444 } |
| 445 dictionary_entry_count++; |
| 446 } |
| 447 |
| 376 if (top_level) { | 448 if (top_level) { |
| 377 ListValue* blacklist_value = NULL; | 449 ListValue* blacklist_value = NULL; |
| 378 if (!value->GetList("blacklist", &blacklist_value)) { | 450 if (!value->GetList("blacklist", &blacklist_value)) { |
| 379 LOG(WARNING) << "Malformed blacklist entry " << entry->id(); | 451 LOG(WARNING) << "Malformed blacklist entry " << entry->id(); |
| 380 return NULL; | 452 return NULL; |
| 381 } | 453 } |
| 382 std::vector<std::string> blacklist; | 454 std::vector<std::string> blacklist; |
| 383 for (size_t i = 0; i < blacklist_value->GetSize(); ++i) { | 455 for (size_t i = 0; i < blacklist_value->GetSize(); ++i) { |
| 384 std::string feature; | 456 std::string feature; |
| 385 if (blacklist_value->GetString(i, &feature)) { | 457 if (blacklist_value->GetString(i, &feature)) { |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 } | 588 } |
| 517 | 589 |
| 518 bool GpuBlacklist::GpuBlacklistEntry::SetGLRendererInfo( | 590 bool GpuBlacklist::GpuBlacklistEntry::SetGLRendererInfo( |
| 519 const std::string& renderer_op, | 591 const std::string& renderer_op, |
| 520 const std::string& renderer_value) { | 592 const std::string& renderer_value) { |
| 521 gl_renderer_info_.reset( | 593 gl_renderer_info_.reset( |
| 522 new StringInfo(renderer_op, renderer_value)); | 594 new StringInfo(renderer_op, renderer_value)); |
| 523 return gl_renderer_info_->IsValid(); | 595 return gl_renderer_info_->IsValid(); |
| 524 } | 596 } |
| 525 | 597 |
| 598 bool GpuBlacklist::GpuBlacklistEntry::SetPerfGraphicsInfo( |
| 599 const std::string& op, |
| 600 const std::string& float_string, |
| 601 const std::string& float_string2) { |
| 602 perf_graphics_info_.reset( |
| 603 new FloatInfo(op, float_string, float_string2)); |
| 604 return perf_graphics_info_->IsValid(); |
| 605 } |
| 606 |
| 607 bool GpuBlacklist::GpuBlacklistEntry::SetPerfGamingInfo( |
| 608 const std::string& op, |
| 609 const std::string& float_string, |
| 610 const std::string& float_string2) { |
| 611 perf_gaming_info_.reset( |
| 612 new FloatInfo(op, float_string, float_string2)); |
| 613 return perf_gaming_info_->IsValid(); |
| 614 } |
| 615 |
| 616 bool GpuBlacklist::GpuBlacklistEntry::SetPerfOverallInfo( |
| 617 const std::string& op, |
| 618 const std::string& float_string, |
| 619 const std::string& float_string2) { |
| 620 perf_overall_info_.reset( |
| 621 new FloatInfo(op, float_string, float_string2)); |
| 622 return perf_overall_info_->IsValid(); |
| 623 } |
| 624 |
| 526 bool GpuBlacklist::GpuBlacklistEntry::SetBlacklistedFeatures( | 625 bool GpuBlacklist::GpuBlacklistEntry::SetBlacklistedFeatures( |
| 527 const std::vector<std::string>& blacklisted_features) { | 626 const std::vector<std::string>& blacklisted_features) { |
| 528 size_t size = blacklisted_features.size(); | 627 size_t size = blacklisted_features.size(); |
| 529 if (size == 0) | 628 if (size == 0) |
| 530 return false; | 629 return false; |
| 531 uint32 flags = 0; | 630 uint32 flags = 0; |
| 532 for (size_t i = 0; i < size; ++i) { | 631 for (size_t i = 0; i < size; ++i) { |
| 533 GpuFeatureFlags::GpuFeatureType type = | 632 GpuFeatureFlags::GpuFeatureType type = |
| 534 GpuFeatureFlags::StringToGpuFeatureType(blacklisted_features[i]); | 633 GpuFeatureFlags::StringToGpuFeatureType(blacklisted_features[i]); |
| 535 switch (type) { | 634 switch (type) { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 if (driver_date.get() == NULL || | 688 if (driver_date.get() == NULL || |
| 590 !driver_date_info_->Contains(*driver_date)) | 689 !driver_date_info_->Contains(*driver_date)) |
| 591 return false; | 690 return false; |
| 592 } | 691 } |
| 593 if (gl_vendor_info_.get() != NULL && | 692 if (gl_vendor_info_.get() != NULL && |
| 594 !gl_vendor_info_->Contains(gpu_info.gl_vendor)) | 693 !gl_vendor_info_->Contains(gpu_info.gl_vendor)) |
| 595 return false; | 694 return false; |
| 596 if (gl_renderer_info_.get() != NULL && | 695 if (gl_renderer_info_.get() != NULL && |
| 597 !gl_renderer_info_->Contains(gpu_info.gl_renderer)) | 696 !gl_renderer_info_->Contains(gpu_info.gl_renderer)) |
| 598 return false; | 697 return false; |
| 698 if (perf_graphics_info_.get() != NULL && |
| 699 (gpu_info.performance_stats.graphics == 0.0 || |
| 700 !perf_graphics_info_->Contains(gpu_info.performance_stats.graphics))) |
| 701 return false; |
| 702 if (perf_gaming_info_.get() != NULL && |
| 703 (gpu_info.performance_stats.gaming == 0.0 || |
| 704 !perf_gaming_info_->Contains(gpu_info.performance_stats.gaming))) |
| 705 return false; |
| 706 if (perf_overall_info_.get() != NULL && |
| 707 (gpu_info.performance_stats.overall == 0.0 || |
| 708 !perf_overall_info_->Contains(gpu_info.performance_stats.overall))) |
| 709 return false; |
| 599 for (size_t i = 0; i < exceptions_.size(); ++i) { | 710 for (size_t i = 0; i < exceptions_.size(); ++i) { |
| 600 if (exceptions_[i]->Contains(os_type, os_version, gpu_info)) | 711 if (exceptions_[i]->Contains(os_type, os_version, gpu_info)) |
| 601 return false; | 712 return false; |
| 602 } | 713 } |
| 603 return true; | 714 return true; |
| 604 } | 715 } |
| 605 | 716 |
| 606 GpuBlacklist::OsType GpuBlacklist::GpuBlacklistEntry::GetOsType() const { | 717 GpuBlacklist::OsType GpuBlacklist::GpuBlacklistEntry::GetOsType() const { |
| 607 if (os_info_.get() == NULL) | 718 if (os_info_.get() == NULL) |
| 608 return kOsAny; | 719 return kOsAny; |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 855 return kUnsupported; | 966 return kUnsupported; |
| 856 } | 967 } |
| 857 return kSupported; | 968 return kSupported; |
| 858 } | 969 } |
| 859 | 970 |
| 860 void GpuBlacklist::SetBrowserVersion(const std::string& version_string) { | 971 void GpuBlacklist::SetBrowserVersion(const std::string& version_string) { |
| 861 browser_version_.reset(Version::GetVersionFromString(version_string)); | 972 browser_version_.reset(Version::GetVersionFromString(version_string)); |
| 862 DCHECK(browser_version_.get() != NULL); | 973 DCHECK(browser_version_.get() != NULL); |
| 863 } | 974 } |
| 864 | 975 |
| 976 // static |
| 977 GpuBlacklist::NumericOp GpuBlacklist::StringToNumericOp( |
| 978 const std::string& op) { |
| 979 if (op == "=") |
| 980 return kEQ; |
| 981 if (op == "<") |
| 982 return kLT; |
| 983 if (op == "<=") |
| 984 return kLE; |
| 985 if (op == ">") |
| 986 return kGT; |
| 987 if (op == ">=") |
| 988 return kGE; |
| 989 if (op == "any") |
| 990 return kAny; |
| 991 if (op == "between") |
| 992 return kBetween; |
| 993 return kUnknown; |
| 994 } |
| 995 |
| OLD | NEW |