Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 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 #ifndef CONTENT_BROWSER_GPU_GPU_BLACKLIST_H_ | 5 #ifndef CONTENT_BROWSER_GPU_GPU_BLACKLIST_H_ |
| 6 #define CONTENT_BROWSER_GPU_GPU_BLACKLIST_H_ | 6 #define CONTENT_BROWSER_GPU_GPU_BLACKLIST_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/gtest_prod_util.h" | |
| 14 #include "base/memory/ref_counted.h" | |
| 13 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/values.h" | 16 #include "base/values.h" |
| 15 #include "content/common/gpu/gpu_feature_flags.h" | 17 #include "content/common/gpu/gpu_feature_flags.h" |
| 16 | 18 |
| 17 class Version; | 19 class Version; |
| 18 struct GPUInfo; | 20 struct GPUInfo; |
| 19 | 21 |
| 20 namespace base { | 22 namespace base { |
| 21 class DictionaryValue; | 23 class DictionaryValue; |
| 22 } | 24 } |
| 23 | 25 |
| 24 class GpuBlacklist { | 26 class GpuBlacklist { |
| 25 public: | 27 public: |
| 26 enum OsType { | 28 enum OsType { |
| 27 kOsLinux, | 29 kOsLinux, |
| 28 kOsMacosx, | 30 kOsMacosx, |
| 29 kOsWin, | 31 kOsWin, |
| 30 kOsChromeOS, | 32 kOsChromeOS, |
| 31 kOsAny, | 33 kOsAny, |
| 32 kOsUnknown | 34 kOsUnknown |
| 33 }; | 35 }; |
| 34 | 36 |
| 37 enum OsFilter { | |
| 38 // In loading, ignore all entries that belong to other OS. | |
| 39 kCurrentOsOnly, | |
| 40 // In loading, keep all entries. This is for testing only. | |
| 41 kAllOs | |
| 42 }; | |
| 43 | |
| 35 explicit GpuBlacklist(const std::string& browser_version_string); | 44 explicit GpuBlacklist(const std::string& browser_version_string); |
| 36 ~GpuBlacklist(); | 45 ~GpuBlacklist(); |
| 37 | 46 |
| 38 // Loads blacklist information from a json file. | 47 // Loads blacklist information from a json file. |
| 39 // current_os_only==true indicates all blacklist entries that don't belong to | |
| 40 // the current OS are discarded; current_os_only==false should only be used | |
| 41 // for testing purpose. | |
| 42 // If failed, the current GpuBlacklist is un-touched. | 48 // If failed, the current GpuBlacklist is un-touched. |
| 43 bool LoadGpuBlacklist(const std::string& json_context, | 49 bool LoadGpuBlacklist(const std::string& json_context, OsFilter os_filter); |
| 44 bool current_os_only); | |
| 45 bool LoadGpuBlacklist(const base::DictionaryValue& parsed_json, | 50 bool LoadGpuBlacklist(const base::DictionaryValue& parsed_json, |
| 46 bool current_os_only); | 51 OsFilter os_filter); |
| 47 | 52 |
| 48 // Collects system information and combines them with gpu_info and blacklist | 53 // Collects system information and combines them with gpu_info and blacklist |
| 49 // information to determine gpu feature flags. | 54 // information to determine gpu feature flags. |
| 50 // If os is kOsAny, use the current OS; if os_version is null, use the | 55 // If os is kOsAny, use the current OS; if os_version is null, use the |
| 51 // current OS version. | 56 // current OS version. |
| 52 GpuFeatureFlags DetermineGpuFeatureFlags(OsType os, | 57 GpuFeatureFlags DetermineGpuFeatureFlags(OsType os, |
| 53 Version* os_version, | 58 Version* os_version, |
| 54 const GPUInfo& gpu_info); | 59 const GPUInfo& gpu_info); |
| 55 | 60 |
| 56 // Collects the entries that set the "feature" flag from the last | 61 // Collects the entries that set the "feature" flag from the last |
| 57 // DetermineGpuFeatureFlags() call. This tells which entries are responsible | 62 // DetermineGpuFeatureFlags() call. This tells which entries are responsible |
| 58 // for raising a certain flag, i.e, for blacklisting a certain feature. | 63 // for raising a certain flag, i.e, for blacklisting a certain feature. |
| 59 // Examples of "feature": | 64 // Examples of "feature": |
| 60 // kGpuFeatureAll - any of the supported features; | 65 // kGpuFeatureAll - any of the supported features; |
| 61 // kGpuFeatureWebgl - a single feature; | 66 // kGpuFeatureWebgl - a single feature; |
| 62 // kGpuFeatureWebgl | kGpuFeatureAcceleratedCompositing - two features. | 67 // kGpuFeatureWebgl | kGpuFeatureAcceleratedCompositing - two features. |
| 63 void GetGpuFeatureFlagEntries(GpuFeatureFlags::GpuFeatureType feature, | 68 void GetGpuFeatureFlagEntries(GpuFeatureFlags::GpuFeatureType feature, |
| 64 std::vector<uint32>& entry_ids) const; | 69 std::vector<uint32>& entry_ids) const; |
| 65 | 70 |
| 66 | |
| 67 // Returns status information on the blacklist. This is two parted: | 71 // Returns status information on the blacklist. This is two parted: |
| 68 // { | 72 // { |
| 69 // featureStatus: [] | 73 // featureStatus: [] |
| 70 // problems: [] | 74 // problems: [] |
| 71 // } | 75 // } |
| 72 // | 76 // |
| 73 // Each entry in feature_status has: | 77 // Each entry in feature_status has: |
| 74 // { | 78 // { |
| 75 // name: "name of feature" | 79 // name: "name of feature" |
| 76 // status: "enabled" | "unavailable_software" | "unavailable_off" | | 80 // status: "enabled" | "unavailable_software" | "unavailable_off" | |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 102 // Collects the version of the current blacklist. Returns false and sets | 106 // Collects the version of the current blacklist. Returns false and sets |
| 103 // major and minor to 0 on failure. | 107 // major and minor to 0 on failure. |
| 104 bool GetVersion(uint16* major, uint16* monir) const; | 108 bool GetVersion(uint16* major, uint16* monir) const; |
| 105 | 109 |
| 106 // Collects the version of the current blacklist from a parsed json file. | 110 // Collects the version of the current blacklist from a parsed json file. |
| 107 // Returns false and sets major and minor to 0 on failure. | 111 // Returns false and sets major and minor to 0 on failure. |
| 108 static bool GetVersion( | 112 static bool GetVersion( |
| 109 const base::DictionaryValue& parsed_json, uint16* major, uint16* minor); | 113 const base::DictionaryValue& parsed_json, uint16* major, uint16* minor); |
| 110 | 114 |
| 111 private: | 115 private: |
| 116 FRIEND_TEST_ALL_PREFIXES(GpuBlacklistTest, CurrentBlacklistValidation); | |
| 117 FRIEND_TEST_ALL_PREFIXES(GpuBlacklistTest, UnknownField); | |
| 118 FRIEND_TEST_ALL_PREFIXES(GpuBlacklistTest, UnknownExceptionField); | |
| 119 FRIEND_TEST_ALL_PREFIXES(GpuBlacklistTest, UnknownFeature); | |
| 120 | |
| 112 class VersionInfo { | 121 class VersionInfo { |
| 113 public: | 122 public: |
| 114 VersionInfo(const std::string& version_op, | 123 VersionInfo(const std::string& version_op, |
| 115 const std::string& version_string, | 124 const std::string& version_string, |
| 116 const std::string& version_string2); | 125 const std::string& version_string2); |
| 117 ~VersionInfo(); | 126 ~VersionInfo(); |
| 118 | 127 |
| 119 // Determines if a given version is included in the VersionInfo range. | 128 // Determines if a given version is included in the VersionInfo range. |
| 120 bool Contains(const Version& version) const; | 129 bool Contains(const Version& version) const; |
| 121 | 130 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 185 kUnknown // Indicates StringInfo data is invalid. | 194 kUnknown // Indicates StringInfo data is invalid. |
| 186 }; | 195 }; |
| 187 | 196 |
| 188 // Maps string to Op; returns kUnknown if it's not a valid Op. | 197 // Maps string to Op; returns kUnknown if it's not a valid Op. |
| 189 static Op StringToOp(const std::string& string_op); | 198 static Op StringToOp(const std::string& string_op); |
| 190 | 199 |
| 191 Op op_; | 200 Op op_; |
| 192 std::string value_; | 201 std::string value_; |
| 193 }; | 202 }; |
| 194 | 203 |
| 195 class GpuBlacklistEntry { | 204 class GpuBlacklistEntry; |
| 205 typedef scoped_refptr<GpuBlacklistEntry> ScopedGpuBlacklistEntry; | |
| 206 | |
| 207 class GpuBlacklistEntry : public base::RefCounted<GpuBlacklistEntry> { | |
| 196 public: | 208 public: |
| 197 // Constructs GpuBlacklistEntry from DictionaryValue loaded from json. | 209 // Constructs GpuBlacklistEntry from DictionaryValue loaded from json. |
| 198 // Top-level entry must have an id number. Others are exceptions. | 210 // Top-level entry must have an id number. Others are exceptions. |
| 199 static GpuBlacklistEntry* GetGpuBlacklistEntryFromValue( | 211 static GpuBlacklistEntry* GetGpuBlacklistEntryFromValue( |
| 200 base::DictionaryValue* value, bool top_level); | 212 base::DictionaryValue* value, bool top_level); |
| 201 | 213 |
| 202 // Determines if a given os/gc/driver is included in the Entry set. | 214 // Determines if a given os/gc/driver is included in the Entry set. |
| 203 bool Contains(OsType os_type, | 215 bool Contains(OsType os_type, |
| 204 const Version& os_version, | 216 const Version& os_version, |
| 205 const GPUInfo& gpu_info) const; | 217 const GPUInfo& gpu_info) const; |
| 206 | 218 |
| 207 // Returns the OsType. | 219 // Returns the OsType. |
| 208 OsType GetOsType() const; | 220 OsType GetOsType() const; |
| 209 | 221 |
| 210 // Returns the entry's unique id. 0 is reserved. | 222 // Returns the entry's unique id. 0 is reserved. |
| 211 uint32 id() const; | 223 uint32 id() const; |
| 212 | 224 |
| 213 // Returns the description of the entry | 225 // Returns the description of the entry |
| 214 const std::string& description() const { return description_; } | 226 const std::string& description() const { return description_; } |
| 215 | 227 |
| 216 // Returs a list of Chromium and Webkit bugs applicable to this entry | 228 // Returns a list of Chromium and Webkit bugs applicable to this entry |
| 217 const std::vector<int>& cr_bugs() const { return cr_bugs_; } | 229 const std::vector<int>& cr_bugs() const { return cr_bugs_; } |
| 218 const std::vector<int>& webkit_bugs() const { return webkit_bugs_; } | 230 const std::vector<int>& webkit_bugs() const { return webkit_bugs_; } |
| 219 | 231 |
| 220 // Returns the GpuFeatureFlags. | 232 // Returns the GpuFeatureFlags. |
| 221 GpuFeatureFlags GetGpuFeatureFlags() const; | 233 GpuFeatureFlags GetGpuFeatureFlags() const; |
| 222 | 234 |
| 223 ~GpuBlacklistEntry(); | 235 // Returns true if an unknown field is encountered. |
| 236 bool contains_unknown_fields() const { | |
| 237 return contains_unknown_fields_; | |
| 238 } | |
| 239 // Returns true if an unknown blacklist feature is encountered. | |
| 240 bool contains_unknown_features() const { | |
| 241 return contains_unknown_features_; | |
| 242 } | |
| 224 | 243 |
| 225 private: | 244 private: |
| 245 friend class base::RefCounted<GpuBlacklistEntry>; | |
| 246 | |
| 226 GpuBlacklistEntry(); | 247 GpuBlacklistEntry(); |
| 248 ~GpuBlacklistEntry() { } | |
| 227 | 249 |
| 228 bool SetId(uint32 id); | 250 bool SetId(uint32 id); |
| 229 | 251 |
| 230 bool SetOsInfo(const std::string& os, | 252 bool SetOsInfo(const std::string& os, |
| 231 const std::string& version_op, | 253 const std::string& version_op, |
| 232 const std::string& version_string, | 254 const std::string& version_string, |
| 233 const std::string& version_string2); | 255 const std::string& version_string2); |
| 234 | 256 |
| 235 bool SetVendorId(const std::string& vendor_id_string); | 257 bool SetVendorId(const std::string& vendor_id_string); |
| 236 | 258 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 260 std::vector<int> cr_bugs_; | 282 std::vector<int> cr_bugs_; |
| 261 std::vector<int> webkit_bugs_; | 283 std::vector<int> webkit_bugs_; |
| 262 scoped_ptr<OsInfo> os_info_; | 284 scoped_ptr<OsInfo> os_info_; |
| 263 uint32 vendor_id_; | 285 uint32 vendor_id_; |
| 264 std::vector<uint32> device_id_list_; | 286 std::vector<uint32> device_id_list_; |
| 265 scoped_ptr<StringInfo> driver_vendor_info_; | 287 scoped_ptr<StringInfo> driver_vendor_info_; |
| 266 scoped_ptr<VersionInfo> driver_version_info_; | 288 scoped_ptr<VersionInfo> driver_version_info_; |
| 267 scoped_ptr<VersionInfo> driver_date_info_; | 289 scoped_ptr<VersionInfo> driver_date_info_; |
| 268 scoped_ptr<StringInfo> gl_renderer_info_; | 290 scoped_ptr<StringInfo> gl_renderer_info_; |
| 269 scoped_ptr<GpuFeatureFlags> feature_flags_; | 291 scoped_ptr<GpuFeatureFlags> feature_flags_; |
| 270 std::vector<GpuBlacklistEntry*> exceptions_; | 292 std::vector<ScopedGpuBlacklistEntry> exceptions_; |
| 293 bool contains_unknown_fields_; | |
| 294 bool contains_unknown_features_; | |
| 271 }; | 295 }; |
| 272 | 296 |
| 273 enum BrowserVersionSupport { | 297 enum BrowserVersionSupport { |
| 274 kSupported, | 298 kSupported, |
| 275 kUnsupported, | 299 kUnsupported, |
| 276 kMalformed | 300 kMalformed |
| 277 }; | 301 }; |
| 278 | 302 |
| 279 // Gets the current OS type. | 303 // Gets the current OS type. |
| 280 static OsType GetOsType(); | 304 static OsType GetOsType(); |
| 281 | 305 |
| 282 void Clear(); | 306 void Clear(); |
| 283 | 307 |
| 284 bool IsFeatureBlacklisted(GpuFeatureFlags::GpuFeatureType feature) const; | 308 bool IsFeatureBlacklisted(GpuFeatureFlags::GpuFeatureType feature) const; |
| 285 | 309 |
| 286 // Check if the entry is supported by the current version of browser. | 310 // Check if the entry is supported by the current version of browser. |
| 287 // By default, if there is no browser version information in the entry, | 311 // By default, if there is no browser version information in the entry, |
| 288 // return kSupported; | 312 // return kSupported; |
| 289 BrowserVersionSupport IsEntrySupportedByCurrentBrowserVersion( | 313 BrowserVersionSupport IsEntrySupportedByCurrentBrowserVersion( |
| 290 base::DictionaryValue* value); | 314 base::DictionaryValue* value); |
| 291 | 315 |
| 316 // Returns the number of entries. This is only for tests. | |
| 317 size_t num_entries() const; | |
| 318 | |
| 319 // Check if any entries contain unknown field. This is only for tests. | |
|
vangelis
2011/08/25 01:18:52
typo: field -> fields
| |
| 320 bool contains_unknown_fields() const { return contains_unknown_fields_; } | |
| 321 | |
| 292 scoped_ptr<Version> version_; | 322 scoped_ptr<Version> version_; |
| 293 std::vector<GpuBlacklistEntry*> blacklist_; | 323 std::vector<ScopedGpuBlacklistEntry> blacklist_; |
| 294 | 324 |
| 295 scoped_ptr<Version> browser_version_; | 325 scoped_ptr<Version> browser_version_; |
| 296 | 326 |
| 297 // This records all the blacklist entries that are appliable to the current | 327 // This records all the blacklist entries that are appliable to the current |
| 298 // user machine. It is updated everytime DetermineGpuFeatureFlags() is | 328 // user machine. It is updated everytime DetermineGpuFeatureFlags() is |
| 299 // called and is used later by GetGpuFeatureFlagEntries(). | 329 // called and is used later by GetGpuFeatureFlagEntries(). |
| 300 std::vector<GpuBlacklistEntry*> active_entries_; | 330 std::vector<ScopedGpuBlacklistEntry> active_entries_; |
| 301 | 331 |
| 302 uint32 max_entry_id_; | 332 uint32 max_entry_id_; |
| 303 | 333 |
| 334 bool contains_unknown_fields_; | |
| 335 | |
| 304 DISALLOW_COPY_AND_ASSIGN(GpuBlacklist); | 336 DISALLOW_COPY_AND_ASSIGN(GpuBlacklist); |
| 305 }; | 337 }; |
| 306 | 338 |
| 307 #endif // CONTENT_BROWSER_GPU_GPU_BLACKLIST_H_ | 339 #endif // CONTENT_BROWSER_GPU_GPU_BLACKLIST_H_ |
| OLD | NEW |