diff options
author | Kristian Monsen <kristianm@google.com> | 2011-05-31 20:30:28 +0100 |
---|---|---|
committer | Kristian Monsen <kristianm@google.com> | 2011-06-14 20:31:41 -0700 |
commit | 72a454cd3513ac24fbdd0e0cb9ad70b86a99b801 (patch) | |
tree | 382278a54ce7a744d62fa510a9a80688cc12434b /chrome/browser/gpu_blacklist.cc | |
parent | c4becdd46e31d261b930e4b5a539cbc1d45c23a6 (diff) | |
download | external_chromium-72a454cd3513ac24fbdd0e0cb9ad70b86a99b801.zip external_chromium-72a454cd3513ac24fbdd0e0cb9ad70b86a99b801.tar.gz external_chromium-72a454cd3513ac24fbdd0e0cb9ad70b86a99b801.tar.bz2 |
Merge Chromium.org at r11.0.672.0: Initial merge by git.
Change-Id: I8b4aaf611a2a405fe3fe10e8a94ea7658645c192
Diffstat (limited to 'chrome/browser/gpu_blacklist.cc')
-rw-r--r-- | chrome/browser/gpu_blacklist.cc | 184 |
1 files changed, 171 insertions, 13 deletions
diff --git a/chrome/browser/gpu_blacklist.cc b/chrome/browser/gpu_blacklist.cc index 85063a8..33511bd 100644 --- a/chrome/browser/gpu_blacklist.cc +++ b/chrome/browser/gpu_blacklist.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -135,6 +135,45 @@ GpuBlacklist::OsType GpuBlacklist::OsInfo::StringToOsType( return kOsUnknown; } +GpuBlacklist::StringInfo::StringInfo(const std::string& string_op, + const std::string& string_value) { + op_ = StringToOp(string_op); + value_ = StringToLowerASCII(string_value); +} + +bool GpuBlacklist::StringInfo::Contains(const std::string& value) const { + std::string my_value = StringToLowerASCII(value); + switch (op_) { + case kContains: + return strstr(my_value.c_str(), value_.c_str()) != NULL; + case kBeginWith: + return StartsWithASCII(my_value, value_, false); + case kEndWith: + return EndsWith(my_value, value_, false); + case kEQ: + return value_ == my_value; + default: + return false; + } +} + +bool GpuBlacklist::StringInfo::IsValid() const { + return op_ != kUnknown; +} + +GpuBlacklist::StringInfo::Op GpuBlacklist::StringInfo::StringToOp( + const std::string& string_op) { + if (string_op == "=") + return kEQ; + else if (string_op == "contains") + return kContains; + else if (string_op == "beginwith") + return kBeginWith; + else if (string_op == "endwith") + return kEndWith; + return kUnknown; +} + GpuBlacklist::GpuBlacklistEntry* GpuBlacklist::GpuBlacklistEntry::GetGpuBlacklistEntryFromValue( DictionaryValue* value) { @@ -143,6 +182,12 @@ GpuBlacklist::GpuBlacklistEntry::GetGpuBlacklistEntryFromValue( GpuBlacklistEntry* entry = new GpuBlacklistEntry(); + std::string id; + if (!value->GetString("id", &id) || !entry->SetId(id)) { + delete entry; + return NULL; + } + DictionaryValue* os_value = NULL; if (value->GetDictionary("os", &os_value)) { std::string os_type; @@ -179,6 +224,18 @@ GpuBlacklist::GpuBlacklistEntry::GetGpuBlacklistEntryFromValue( } } + DictionaryValue* driver_vendor_value = NULL; + if (value->GetDictionary("driver_vendor", &driver_vendor_value)) { + std::string vendor_op; + std::string vendor_value; + driver_vendor_value->GetString("op", &vendor_op); + driver_vendor_value->GetString("value", &vendor_value); + if (!entry->SetDriverVendorInfo(vendor_op, vendor_value)) { + delete entry; + return NULL; + } + } + DictionaryValue* driver_version_value = NULL; if (value->GetDictionary("driver_version", &driver_version_value)) { std::string driver_version_op = "any"; @@ -194,6 +251,18 @@ GpuBlacklist::GpuBlacklistEntry::GetGpuBlacklistEntryFromValue( } } + DictionaryValue* gl_renderer_value = NULL; + if (value->GetDictionary("gl_renderer", &gl_renderer_value)) { + std::string renderer_op; + std::string renderer_value; + gl_renderer_value->GetString("op", &renderer_op); + gl_renderer_value->GetString("value", &renderer_value); + if (!entry->SetGLRendererInfo(renderer_op, renderer_value)) { + delete entry; + return NULL; + } + } + ListValue* blacklist_value = NULL; if (!value->GetList("blacklist", &blacklist_value)) { delete entry; @@ -220,10 +289,21 @@ GpuBlacklist::GpuBlacklistEntry::GetGpuBlacklistEntryFromValue( GpuBlacklist::GpuBlacklistEntry::~GpuBlacklistEntry() {} GpuBlacklist::GpuBlacklistEntry::GpuBlacklistEntry() - : vendor_id_(0), + : id_(0), + vendor_id_(0), device_id_(0) { } +bool GpuBlacklist::GpuBlacklistEntry::SetId( + const std::string& id_string) { + int my_id; + if (base::HexStringToInt(id_string, &my_id) && my_id != 0) { + id_ = static_cast<uint32>(my_id); + return true; + } + return false; +} + bool GpuBlacklist::GpuBlacklistEntry::SetOsInfo( const std::string& os, const std::string& version_op, @@ -247,6 +327,14 @@ bool GpuBlacklist::GpuBlacklistEntry::SetDeviceId( reinterpret_cast<int*>(&device_id_)); } +bool GpuBlacklist::GpuBlacklistEntry::SetDriverVendorInfo( + const std::string& vendor_op, + const std::string& vendor_value) { + driver_vendor_info_.reset( + new StringInfo(vendor_op, vendor_value)); + return driver_vendor_info_->IsValid(); +} + bool GpuBlacklist::GpuBlacklistEntry::SetDriverVersionInfo( const std::string& version_op, const std::string& version_string, @@ -256,6 +344,14 @@ bool GpuBlacklist::GpuBlacklistEntry::SetDriverVersionInfo( return driver_version_info_->IsValid(); } +bool GpuBlacklist::GpuBlacklistEntry::SetGLRendererInfo( + const std::string& renderer_op, + const std::string& renderer_value) { + gl_renderer_info_.reset( + new StringInfo(renderer_op, renderer_value)); + return gl_renderer_info_->IsValid(); +} + bool GpuBlacklist::GpuBlacklistEntry::SetBlacklistedFeatures( const std::vector<std::string>& blacklisted_features) { size_t size = blacklisted_features.size(); @@ -284,7 +380,9 @@ bool GpuBlacklist::GpuBlacklistEntry::SetBlacklistedFeatures( bool GpuBlacklist::GpuBlacklistEntry::Contains( OsType os_type, const Version& os_version, uint32 vendor_id, uint32 device_id, - const Version& driver_version) const { + const std::string& driver_vendor, + const Version& driver_version, + const std::string& gl_renderer) const { DCHECK(os_type != kOsAny); if (os_info_.get() != NULL && !os_info_->Contains(os_type, os_version)) return false; @@ -292,22 +390,34 @@ bool GpuBlacklist::GpuBlacklistEntry::Contains( return false; if (device_id_ != 0 && device_id_ != device_id) return false; - if (driver_version_info_.get() == NULL) - return true; - return driver_version_info_->Contains(driver_version); + if (driver_vendor_info_.get() != NULL && + !driver_vendor_info_->Contains(driver_vendor)) + return false; + if (driver_version_info_.get() != NULL && + !driver_version_info_->Contains(driver_version)) + return false; + if (gl_renderer_info_.get() != NULL && + !gl_renderer_info_->Contains(gl_renderer)) + return false; + return true; } GpuBlacklist::OsType GpuBlacklist::GpuBlacklistEntry::GetOsType() const { if (os_info_.get() == NULL) - return kOsUnknown; + return kOsAny; return os_info_->type(); } +uint32 GpuBlacklist::GpuBlacklistEntry::id() const { + return id_; +} + GpuFeatureFlags GpuBlacklist::GpuBlacklistEntry::GetGpuFeatureFlags() const { return *feature_flags_; } -GpuBlacklist::GpuBlacklist() { +GpuBlacklist::GpuBlacklist() + : max_entry_id_(0) { } GpuBlacklist::~GpuBlacklist() { @@ -322,11 +432,20 @@ bool GpuBlacklist::LoadGpuBlacklist(const std::string& json_context, if (root.get() == NULL || !root->IsType(Value::TYPE_DICTIONARY)) return false; + DictionaryValue* root_dictionary = static_cast<DictionaryValue*>(root.get()); + DCHECK(root_dictionary); + std::string version_string; + root_dictionary->GetString("version", &version_string); + version_.reset(Version::GetVersionFromString(version_string)); + if (version_.get() == NULL) + return false; + ListValue* list = NULL; - static_cast<DictionaryValue*>(root.get())->GetList("entries", &list); + root_dictionary->GetList("entries", &list); if (list == NULL) return false; + uint32 max_entry_id = 0; for (size_t i = 0; i < list->GetSize(); ++i) { DictionaryValue* list_item = NULL; bool valid = list->GetDictionary(i, &list_item); @@ -336,6 +455,8 @@ bool GpuBlacklist::LoadGpuBlacklist(const std::string& json_context, GpuBlacklistEntry::GetGpuBlacklistEntryFromValue(list_item); if (entry == NULL) break; + if (entry->id() > max_entry_id) + max_entry_id = entry->id(); entries.push_back(entry); } @@ -358,19 +479,21 @@ bool GpuBlacklist::LoadGpuBlacklist(const std::string& json_context, delete entries[i]; } } + max_entry_id_ = max_entry_id; return true; } GpuFeatureFlags GpuBlacklist::DetermineGpuFeatureFlags( GpuBlacklist::OsType os, Version* os_version, - const GPUInfo& gpu_info) const { + const GPUInfo& gpu_info) { + active_entries_.clear(); GpuFeatureFlags flags; // No need to go through blacklist entries if GPUInfo isn't available. - if (gpu_info.progress() == GPUInfo::kUninitialized) + if (gpu_info.level() == GPUInfo::kUninitialized) return flags; scoped_ptr<Version> driver_version( - Version::GetVersionFromString(WideToASCII(gpu_info.driver_version()))); + Version::GetVersionFromString(gpu_info.driver_version())); if (driver_version.get() == NULL) return flags; @@ -391,6 +514,9 @@ GpuFeatureFlags GpuBlacklist::DetermineGpuFeatureFlags( version_bugfix); #else version_string = base::SysInfo::OperatingSystemVersion(); + size_t pos = version_string.find_first_not_of("0123456789."); + if (pos != std::string::npos) + version_string = version_string.substr(0, pos); #endif my_os_version.reset(Version::GetVersionFromString(version_string)); os_version = my_os_version.get(); @@ -400,13 +526,44 @@ GpuFeatureFlags GpuBlacklist::DetermineGpuFeatureFlags( for (size_t i = 0; i < blacklist_.size(); ++i) { if (blacklist_[i]->Contains(os, *os_version, gpu_info.vendor_id(), gpu_info.device_id(), - *driver_version)) { + gpu_info.driver_vendor(), + *driver_version, + gpu_info.gl_renderer())) { flags.Combine(blacklist_[i]->GetGpuFeatureFlags()); + active_entries_.push_back(blacklist_[i]); } } return flags; } +void GpuBlacklist::GetGpuFeatureFlagEntries( + GpuFeatureFlags::GpuFeatureType feature, + std::vector<uint32>& entry_ids) const { + entry_ids.clear(); + for (size_t i = 0; i < active_entries_.size(); ++i) { + if ((feature & active_entries_[i]->GetGpuFeatureFlags().flags()) != 0) + entry_ids.push_back(active_entries_[i]->id()); + } +} + +uint32 GpuBlacklist::max_entry_id() const { + return max_entry_id_; +} + +bool GpuBlacklist::GetVersion(uint16* major, uint16* minor) const { + DCHECK(major && minor); + *major = 0; + *minor = 0; + if (version_.get() == NULL) + return false; + const std::vector<uint16>& components_reference = version_->components(); + if (components_reference.size() != 2) + return false; + *major = components_reference[0]; + *minor = components_reference[1]; + return true; +} + GpuBlacklist::OsType GpuBlacklist::GetOsType() { #if defined(OS_WIN) return kOsWin; @@ -423,5 +580,6 @@ void GpuBlacklist::Clear() { for (size_t i = 0; i < blacklist_.size(); ++i) delete blacklist_[i]; blacklist_.clear(); + active_entries_.clear(); } |