| OLD | NEW |
| 1 // Copyright (c) 2012 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" |
| 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_ = StringToNumericOp(version_op); | 42 op_ = StringToOp(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 |
| 98 GpuBlacklist::OsInfo::OsInfo(const std::string& os, | 117 GpuBlacklist::OsInfo::OsInfo(const std::string& os, |
| 99 const std::string& version_op, | 118 const std::string& version_op, |
| 100 const std::string& version_string, | 119 const std::string& version_string, |
| 101 const std::string& version_string2) { | 120 const std::string& version_string2) { |
| 102 type_ = StringToOsType(os); | 121 type_ = StringToOsType(os); |
| 103 if (type_ != kOsUnknown) { | 122 if (type_ != kOsUnknown) { |
| 104 version_info_.reset( | 123 version_info_.reset( |
| 105 new VersionInfo(version_op, version_string, version_string2)); | 124 new VersionInfo(version_op, version_string, version_string2)); |
| 106 } | 125 } |
| 107 } | 126 } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 return kEQ; | 191 return kEQ; |
| 173 else if (string_op == "contains") | 192 else if (string_op == "contains") |
| 174 return kContains; | 193 return kContains; |
| 175 else if (string_op == "beginwith") | 194 else if (string_op == "beginwith") |
| 176 return kBeginWith; | 195 return kBeginWith; |
| 177 else if (string_op == "endwith") | 196 else if (string_op == "endwith") |
| 178 return kEndWith; | 197 return kEndWith; |
| 179 return kUnknown; | 198 return kUnknown; |
| 180 } | 199 } |
| 181 | 200 |
| 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 | |
| 228 // static | 201 // static |
| 229 GpuBlacklist::ScopedGpuBlacklistEntry | 202 GpuBlacklist::ScopedGpuBlacklistEntry |
| 230 GpuBlacklist::GpuBlacklistEntry::GetGpuBlacklistEntryFromValue( | 203 GpuBlacklist::GpuBlacklistEntry::GetGpuBlacklistEntryFromValue( |
| 231 DictionaryValue* value, bool top_level) { | 204 DictionaryValue* value, bool top_level) { |
| 232 DCHECK(value); | 205 DCHECK(value); |
| 233 ScopedGpuBlacklistEntry entry(new GpuBlacklistEntry()); | 206 ScopedGpuBlacklistEntry entry(new GpuBlacklistEntry()); |
| 234 | 207 |
| 235 size_t dictionary_entry_count = 0; | 208 size_t dictionary_entry_count = 0; |
| 236 | 209 |
| 237 if (top_level) { | 210 if (top_level) { |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 std::string renderer_value; | 366 std::string renderer_value; |
| 394 gl_renderer_value->GetString("op", &renderer_op); | 367 gl_renderer_value->GetString("op", &renderer_op); |
| 395 gl_renderer_value->GetString("value", &renderer_value); | 368 gl_renderer_value->GetString("value", &renderer_value); |
| 396 if (!entry->SetGLRendererInfo(renderer_op, renderer_value)) { | 369 if (!entry->SetGLRendererInfo(renderer_op, renderer_value)) { |
| 397 LOG(WARNING) << "Malformed gl_renderer entry " << entry->id(); | 370 LOG(WARNING) << "Malformed gl_renderer entry " << entry->id(); |
| 398 return NULL; | 371 return NULL; |
| 399 } | 372 } |
| 400 dictionary_entry_count++; | 373 dictionary_entry_count++; |
| 401 } | 374 } |
| 402 | 375 |
| 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 | |
| 448 if (top_level) { | 376 if (top_level) { |
| 449 ListValue* blacklist_value = NULL; | 377 ListValue* blacklist_value = NULL; |
| 450 if (!value->GetList("blacklist", &blacklist_value)) { | 378 if (!value->GetList("blacklist", &blacklist_value)) { |
| 451 LOG(WARNING) << "Malformed blacklist entry " << entry->id(); | 379 LOG(WARNING) << "Malformed blacklist entry " << entry->id(); |
| 452 return NULL; | 380 return NULL; |
| 453 } | 381 } |
| 454 std::vector<std::string> blacklist; | 382 std::vector<std::string> blacklist; |
| 455 for (size_t i = 0; i < blacklist_value->GetSize(); ++i) { | 383 for (size_t i = 0; i < blacklist_value->GetSize(); ++i) { |
| 456 std::string feature; | 384 std::string feature; |
| 457 if (blacklist_value->GetString(i, &feature)) { | 385 if (blacklist_value->GetString(i, &feature)) { |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 } | 516 } |
| 589 | 517 |
| 590 bool GpuBlacklist::GpuBlacklistEntry::SetGLRendererInfo( | 518 bool GpuBlacklist::GpuBlacklistEntry::SetGLRendererInfo( |
| 591 const std::string& renderer_op, | 519 const std::string& renderer_op, |
| 592 const std::string& renderer_value) { | 520 const std::string& renderer_value) { |
| 593 gl_renderer_info_.reset( | 521 gl_renderer_info_.reset( |
| 594 new StringInfo(renderer_op, renderer_value)); | 522 new StringInfo(renderer_op, renderer_value)); |
| 595 return gl_renderer_info_->IsValid(); | 523 return gl_renderer_info_->IsValid(); |
| 596 } | 524 } |
| 597 | 525 |
| 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 | |
| 625 bool GpuBlacklist::GpuBlacklistEntry::SetBlacklistedFeatures( | 526 bool GpuBlacklist::GpuBlacklistEntry::SetBlacklistedFeatures( |
| 626 const std::vector<std::string>& blacklisted_features) { | 527 const std::vector<std::string>& blacklisted_features) { |
| 627 size_t size = blacklisted_features.size(); | 528 size_t size = blacklisted_features.size(); |
| 628 if (size == 0) | 529 if (size == 0) |
| 629 return false; | 530 return false; |
| 630 uint32 flags = 0; | 531 uint32 flags = 0; |
| 631 for (size_t i = 0; i < size; ++i) { | 532 for (size_t i = 0; i < size; ++i) { |
| 632 GpuFeatureFlags::GpuFeatureType type = | 533 GpuFeatureFlags::GpuFeatureType type = |
| 633 GpuFeatureFlags::StringToGpuFeatureType(blacklisted_features[i]); | 534 GpuFeatureFlags::StringToGpuFeatureType(blacklisted_features[i]); |
| 634 switch (type) { | 535 switch (type) { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 if (driver_date.get() == NULL || | 589 if (driver_date.get() == NULL || |
| 689 !driver_date_info_->Contains(*driver_date)) | 590 !driver_date_info_->Contains(*driver_date)) |
| 690 return false; | 591 return false; |
| 691 } | 592 } |
| 692 if (gl_vendor_info_.get() != NULL && | 593 if (gl_vendor_info_.get() != NULL && |
| 693 !gl_vendor_info_->Contains(gpu_info.gl_vendor)) | 594 !gl_vendor_info_->Contains(gpu_info.gl_vendor)) |
| 694 return false; | 595 return false; |
| 695 if (gl_renderer_info_.get() != NULL && | 596 if (gl_renderer_info_.get() != NULL && |
| 696 !gl_renderer_info_->Contains(gpu_info.gl_renderer)) | 597 !gl_renderer_info_->Contains(gpu_info.gl_renderer)) |
| 697 return false; | 598 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; | |
| 710 for (size_t i = 0; i < exceptions_.size(); ++i) { | 599 for (size_t i = 0; i < exceptions_.size(); ++i) { |
| 711 if (exceptions_[i]->Contains(os_type, os_version, gpu_info)) | 600 if (exceptions_[i]->Contains(os_type, os_version, gpu_info)) |
| 712 return false; | 601 return false; |
| 713 } | 602 } |
| 714 return true; | 603 return true; |
| 715 } | 604 } |
| 716 | 605 |
| 717 GpuBlacklist::OsType GpuBlacklist::GpuBlacklistEntry::GetOsType() const { | 606 GpuBlacklist::OsType GpuBlacklist::GpuBlacklistEntry::GetOsType() const { |
| 718 if (os_info_.get() == NULL) | 607 if (os_info_.get() == NULL) |
| 719 return kOsAny; | 608 return kOsAny; |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 966 return kUnsupported; | 855 return kUnsupported; |
| 967 } | 856 } |
| 968 return kSupported; | 857 return kSupported; |
| 969 } | 858 } |
| 970 | 859 |
| 971 void GpuBlacklist::SetBrowserVersion(const std::string& version_string) { | 860 void GpuBlacklist::SetBrowserVersion(const std::string& version_string) { |
| 972 browser_version_.reset(Version::GetVersionFromString(version_string)); | 861 browser_version_.reset(Version::GetVersionFromString(version_string)); |
| 973 DCHECK(browser_version_.get() != NULL); | 862 DCHECK(browser_version_.get() != NULL); |
| 974 } | 863 } |
| 975 | 864 |
| 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 |