| OLD | NEW |
| 1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_GPU_BLACKLIST_H_ | 5 #ifndef CONTENT_BROWSER_GPU_GPU_BLACKLIST_H_ |
| 6 #define CHROME_BROWSER_GPU_BLACKLIST_H_ | 6 #define CONTENT_BROWSER_GPU_GPU_BLACKLIST_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/memory/singleton.h" | |
| 16 #include "base/values.h" | 15 #include "base/values.h" |
| 17 #include "content/public/browser/gpu_data_manager_observer.h" | |
| 18 #include "content/public/common/gpu_feature_type.h" | 16 #include "content/public/common/gpu_feature_type.h" |
| 19 | 17 |
| 20 class Version; | 18 class Version; |
| 21 | 19 |
| 22 namespace content { | 20 namespace content { |
| 23 struct GPUInfo; | 21 struct GPUInfo; |
| 24 } | 22 } |
| 25 | 23 |
| 26 class GpuBlacklist : public content::GpuDataManagerObserver { | 24 class GpuBlacklist { |
| 27 public: | 25 public: |
| 28 enum OsType { | 26 enum OsType { |
| 29 kOsLinux, | 27 kOsLinux, |
| 30 kOsMacosx, | 28 kOsMacosx, |
| 31 kOsWin, | 29 kOsWin, |
| 32 kOsChromeOS, | 30 kOsChromeOS, |
| 33 kOsAny, | 31 kOsAny, |
| 34 kOsUnknown | 32 kOsUnknown |
| 35 }; | 33 }; |
| 36 | 34 |
| 37 enum OsFilter { | 35 enum OsFilter { |
| 38 // In loading, ignore all entries that belong to other OS. | 36 // In loading, ignore all entries that belong to other OS. |
| 39 kCurrentOsOnly, | 37 kCurrentOsOnly, |
| 40 // In loading, keep all entries. This is for testing only. | 38 // In loading, keep all entries. This is for testing only. |
| 41 kAllOs | 39 kAllOs |
| 42 }; | 40 }; |
| 43 | 41 |
| 44 // Getter for the singleton. This will return NULL on failure. | 42 GpuBlacklist(); |
| 45 static GpuBlacklist* GetInstance(); | |
| 46 | |
| 47 virtual ~GpuBlacklist(); | 43 virtual ~GpuBlacklist(); |
| 48 | 44 |
| 49 // Loads blacklist information from a json file. | 45 // Loads blacklist information from a json file. |
| 50 // If failed, the current GpuBlacklist is un-touched. | 46 // If failed, the current GpuBlacklist is un-touched. |
| 51 bool LoadGpuBlacklist(const std::string& json_context, | 47 bool LoadGpuBlacklist(const std::string& json_context, OsFilter os_filter); |
| 48 bool LoadGpuBlacklist(const std::string& browser_version_string, |
| 49 const std::string& json_context, |
| 52 OsFilter os_filter); | 50 OsFilter os_filter); |
| 53 | 51 |
| 54 // Collects system information and combines them with gpu_info and blacklist | 52 // Collects system information and combines them with gpu_info and blacklist |
| 55 // information to determine gpu feature flags. | 53 // information to determine gpu feature flags. |
| 56 // If os is kOsAny, use the current OS; if os_version is null, use the | 54 // If os is kOsAny, use the current OS; if os_version is null, use the |
| 57 // current OS version. | 55 // current OS version. |
| 58 content::GpuFeatureType DetermineGpuFeatureType( | 56 content::GpuFeatureType DetermineGpuFeatureType( |
| 59 OsType os, Version* os_version, const content::GPUInfo& gpu_info); | 57 OsType os, Version* os_version, const content::GPUInfo& gpu_info); |
| 60 | 58 |
| 61 // Helper function that calls DetermineGpuFeatureType and sets the updated | |
| 62 // features on GpuDataManager. | |
| 63 void UpdateGpuDataManager(); | |
| 64 | |
| 65 // Collects the active entries that set the "feature" flag from the last | 59 // Collects the active entries that set the "feature" flag from the last |
| 66 // DetermineGpuFeatureType() call. This tells which entries are responsible | 60 // DetermineGpuFeatureType() call. This tells which entries are responsible |
| 67 // for raising a certain flag, i.e, for blacklisting a certain feature. | 61 // for raising a certain flag, i.e, for blacklisting a certain feature. |
| 68 // Examples of "feature": | 62 // Examples of "feature": |
| 69 // GPU_FEATURE_TYPE_ALL - any of the supported features; | 63 // GPU_FEATURE_TYPE_ALL - any of the supported features; |
| 70 // GPU_FEATURE_TYPE_WEBGL - a single feature; | 64 // GPU_FEATURE_TYPE_WEBGL - a single feature; |
| 71 // GPU_FEATURE_TYPE_WEBGL | GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING | 65 // GPU_FEATURE_TYPE_WEBGL | GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING |
| 72 // - two features. | 66 // - two features. |
| 73 // If disabled set to true, return entries that are disabled; otherwise, | 67 // If disabled set to true, return entries that are disabled; otherwise, |
| 74 // return enabled entries. | 68 // return enabled entries. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 88 void GetBlacklistReasons(ListValue* problem_list) const; | 82 void GetBlacklistReasons(ListValue* problem_list) const; |
| 89 | 83 |
| 90 // Return the largest entry id. This is used for histogramming. | 84 // Return the largest entry id. This is used for histogramming. |
| 91 uint32 max_entry_id() const; | 85 uint32 max_entry_id() const; |
| 92 | 86 |
| 93 // Returns the version of the current blacklist. | 87 // Returns the version of the current blacklist. |
| 94 std::string GetVersion() const; | 88 std::string GetVersion() const; |
| 95 | 89 |
| 96 private: | 90 private: |
| 97 friend class GpuBlacklistTest; | 91 friend class GpuBlacklistTest; |
| 98 friend struct DefaultSingletonTraits<GpuBlacklist>; | |
| 99 FRIEND_TEST_ALL_PREFIXES(GpuBlacklistTest, ChromeVersionEntry); | 92 FRIEND_TEST_ALL_PREFIXES(GpuBlacklistTest, ChromeVersionEntry); |
| 100 FRIEND_TEST_ALL_PREFIXES(GpuBlacklistTest, CurrentBlacklistValidation); | 93 FRIEND_TEST_ALL_PREFIXES(GpuBlacklistTest, CurrentBlacklistValidation); |
| 101 FRIEND_TEST_ALL_PREFIXES(GpuBlacklistTest, UnknownField); | 94 FRIEND_TEST_ALL_PREFIXES(GpuBlacklistTest, UnknownField); |
| 102 FRIEND_TEST_ALL_PREFIXES(GpuBlacklistTest, UnknownExceptionField); | 95 FRIEND_TEST_ALL_PREFIXES(GpuBlacklistTest, UnknownExceptionField); |
| 103 FRIEND_TEST_ALL_PREFIXES(GpuBlacklistTest, UnknownFeature); | 96 FRIEND_TEST_ALL_PREFIXES(GpuBlacklistTest, UnknownFeature); |
| 104 | 97 |
| 105 enum BrowserVersionSupport { | 98 enum BrowserVersionSupport { |
| 106 kSupported, | 99 kSupported, |
| 107 kUnsupported, | 100 kUnsupported, |
| 108 kMalformed | 101 kMalformed |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 scoped_ptr<FloatInfo> perf_overall_info_; | 352 scoped_ptr<FloatInfo> perf_overall_info_; |
| 360 content::GpuFeatureType feature_type_; | 353 content::GpuFeatureType feature_type_; |
| 361 std::vector<ScopedGpuBlacklistEntry> exceptions_; | 354 std::vector<ScopedGpuBlacklistEntry> exceptions_; |
| 362 bool contains_unknown_fields_; | 355 bool contains_unknown_fields_; |
| 363 bool contains_unknown_features_; | 356 bool contains_unknown_features_; |
| 364 }; | 357 }; |
| 365 | 358 |
| 366 // Gets the current OS type. | 359 // Gets the current OS type. |
| 367 static OsType GetOsType(); | 360 static OsType GetOsType(); |
| 368 | 361 |
| 369 GpuBlacklist(); | |
| 370 | |
| 371 bool LoadGpuBlacklist(const std::string& browser_version_string, | |
| 372 const std::string& json_context, | |
| 373 OsFilter os_filter); | |
| 374 | |
| 375 bool LoadGpuBlacklist(const base::DictionaryValue& parsed_json, | 362 bool LoadGpuBlacklist(const base::DictionaryValue& parsed_json, |
| 376 OsFilter os_filter); | 363 OsFilter os_filter); |
| 377 | 364 |
| 378 void Clear(); | 365 void Clear(); |
| 379 | 366 |
| 380 // Check if the entry is supported by the current version of browser. | 367 // Check if the entry is supported by the current version of browser. |
| 381 // By default, if there is no browser version information in the entry, | 368 // By default, if there is no browser version information in the entry, |
| 382 // return kSupported; | 369 // return kSupported; |
| 383 BrowserVersionSupport IsEntrySupportedByCurrentBrowserVersion( | 370 BrowserVersionSupport IsEntrySupportedByCurrentBrowserVersion( |
| 384 const base::DictionaryValue* value); | 371 const base::DictionaryValue* value); |
| 385 | 372 |
| 386 // GpuDataManager::Observer implementation. | |
| 387 virtual void OnGpuInfoUpdate() OVERRIDE; | |
| 388 virtual void OnVideoMemoryUsageStatsUpdate( | |
| 389 const content::GPUVideoMemoryUsageStats& video_memory) OVERRIDE {} | |
| 390 | |
| 391 // Returns the number of entries. This is only for tests. | 373 // Returns the number of entries. This is only for tests. |
| 392 size_t num_entries() const; | 374 size_t num_entries() const; |
| 393 | 375 |
| 394 // Check if any entries contain unknown fields. This is only for tests. | 376 // Check if any entries contain unknown fields. This is only for tests. |
| 395 bool contains_unknown_fields() const { return contains_unknown_fields_; } | 377 bool contains_unknown_fields() const { return contains_unknown_fields_; } |
| 396 | 378 |
| 397 static NumericOp StringToNumericOp(const std::string& op); | 379 static NumericOp StringToNumericOp(const std::string& op); |
| 398 | 380 |
| 399 scoped_ptr<Version> version_; | 381 scoped_ptr<Version> version_; |
| 400 std::vector<ScopedGpuBlacklistEntry> blacklist_; | 382 std::vector<ScopedGpuBlacklistEntry> blacklist_; |
| 401 | 383 |
| 402 scoped_ptr<Version> browser_version_; | 384 scoped_ptr<Version> browser_version_; |
| 403 | 385 |
| 404 // This records all the blacklist entries that are appliable to the current | 386 // This records all the blacklist entries that are appliable to the current |
| 405 // user machine. It is updated everytime DetermineGpuFeatureType() is | 387 // user machine. It is updated everytime DetermineGpuFeatureType() is |
| 406 // called and is used later by GetGpuFeatureTypeEntries(). | 388 // called and is used later by GetGpuFeatureTypeEntries(). |
| 407 std::vector<ScopedGpuBlacklistEntry> active_entries_; | 389 std::vector<ScopedGpuBlacklistEntry> active_entries_; |
| 408 | 390 |
| 409 uint32 max_entry_id_; | 391 uint32 max_entry_id_; |
| 410 | 392 |
| 411 bool contains_unknown_fields_; | 393 bool contains_unknown_fields_; |
| 412 | 394 |
| 413 DISALLOW_COPY_AND_ASSIGN(GpuBlacklist); | 395 DISALLOW_COPY_AND_ASSIGN(GpuBlacklist); |
| 414 }; | 396 }; |
| 415 | 397 |
| 416 #endif // CHROME_BROWSER_GPU_BLACKLIST_H_ | 398 #endif // CONTENT_BROWSER_GPU_GPU_BLACKLIST_H_ |
| 399 |
| OLD | NEW |