| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 CHROME_BROWSER_GPU_BLACKLIST_H_ |
| 6 #define CHROME_BROWSER_GPU_BLACKLIST_H_ | 6 #define CHROME_BROWSER_GPU_BLACKLIST_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 // Determines whether certain gpu-related features are blacklisted or not. | |
| 10 // A valid gpu_blacklist.json file are in the format of | |
| 11 // { | |
| 12 // "entries": [ | |
| 13 // { // entry 1 | |
| 14 // }, | |
| 15 // ... | |
| 16 // { // entry n | |
| 17 // } | |
| 18 // ] | |
| 19 // } | |
| 20 // Each entry contains the following fields: | |
| 21 // "os", "vendor_id", "device_id", "driver_version", and "blacklist". | |
| 22 // Only "blacklist" is mandatory. | |
| 23 // 1. "os" contains "type" and an optional "version". "type" could be "macosx", | |
| 24 // "linux", "win", or "any". "any" is the same as not specifying "os". | |
| 25 // "version" is a VERSION structure (defined later). | |
| 26 // 2. "vendor_id" has the value of a string. | |
| 27 // 3. "device_id" has the value of a string. | |
| 28 // 4. "driver_version" is a VERSION structure (defined later). | |
| 29 // 5. "blacklist" is a list of gpu feature strings, valid values include | |
| 30 // "accelerated_2d_canvas", "accelerated_compositing", "webgl", and "all". | |
| 31 // Currently whatever feature is selected, the effect is the same as "all", | |
| 32 // i.e., it's not supported to turn off one GPU feature and not the others. | |
| 33 // VERSION includes "op" "number", and "number2". "op" can be any of the | |
| 34 // following value: "=", "<", "<=", ">", ">=", "any", "between". "number2" is | |
| 35 // only used if "op" is "between". "number" is used for all "op" values except | |
| 36 // "any". "number" and "number2" are in the format of x, x.x, x.x.x, ect. | |
| 37 // Check out "gpu_blacklist_unittest.cc" for examples. | |
| 38 | |
| 39 #include <string> | 9 #include <string> |
| 40 #include <vector> | 10 #include <vector> |
| 41 | 11 |
| 42 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 43 #include "base/scoped_ptr.h" | 13 #include "base/scoped_ptr.h" |
| 44 #include "chrome/common/gpu_feature_flags.h" | 14 #include "chrome/common/gpu_feature_flags.h" |
| 45 | 15 |
| 46 class DictionaryValue; | 16 class DictionaryValue; |
| 47 class GPUInfo; | 17 class GPUInfo; |
| 48 class Version; | 18 class Version; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 67 // If failed, the current GpuBlacklist is un-touched. | 37 // If failed, the current GpuBlacklist is un-touched. |
| 68 bool LoadGpuBlacklist(const std::string& json_context, | 38 bool LoadGpuBlacklist(const std::string& json_context, |
| 69 bool current_os_only); | 39 bool current_os_only); |
| 70 | 40 |
| 71 // Collects system information and combines them with gpu_info and blacklist | 41 // Collects system information and combines them with gpu_info and blacklist |
| 72 // information to determine gpu feature flags. | 42 // information to determine gpu feature flags. |
| 73 // If os is kOsAny, use the current OS; if os_version is null, use the | 43 // If os is kOsAny, use the current OS; if os_version is null, use the |
| 74 // current OS version. | 44 // current OS version. |
| 75 GpuFeatureFlags DetermineGpuFeatureFlags(OsType os, | 45 GpuFeatureFlags DetermineGpuFeatureFlags(OsType os, |
| 76 Version* os_version, | 46 Version* os_version, |
| 77 const GPUInfo& gpu_info) const; | 47 const GPUInfo& gpu_info); |
| 48 |
| 49 // Collects the entries that set the "feature" flag from the last |
| 50 // DetermineGpuFeatureFlags() call. This tells which entries are responsible |
| 51 // for raising a certain flag, i.e, for blacklisting a certain feature. |
| 52 // Examples of "feature": |
| 53 // kGpuFeatureAll - any of the supported features; |
| 54 // kGpuFeatureWebgl - a single feature; |
| 55 // kGpuFeatureWebgl | kGpuFeatureAcceleratedCompositing - two features. |
| 56 void GetGpuFeatureFlagEntries(GpuFeatureFlags::GpuFeatureType feature, |
| 57 std::vector<uint32>& entry_ids) const; |
| 58 |
| 59 // Return the largest entry id. This is used for histogramming. |
| 60 uint32 max_entry_id() const; |
| 61 |
| 62 // Collects the version of the current blacklist. Returns false and sets |
| 63 // major and minor to 0 on failure. |
| 64 bool GetVersion(uint16* major, uint16* monir) const; |
| 78 | 65 |
| 79 private: | 66 private: |
| 80 class VersionInfo { | 67 class VersionInfo { |
| 81 public: | 68 public: |
| 82 VersionInfo(const std::string& version_op, | 69 VersionInfo(const std::string& version_op, |
| 83 const std::string& version_string, | 70 const std::string& version_string, |
| 84 const std::string& version_string2); | 71 const std::string& version_string2); |
| 85 ~VersionInfo(); | 72 ~VersionInfo(); |
| 86 | 73 |
| 87 // Determines if a given version is included in the VersionInfo range. | 74 // Determines if a given version is included in the VersionInfo range. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 OsType type() const; | 114 OsType type() const; |
| 128 | 115 |
| 129 // Maps string to OsType; returns kOsUnknown if it's not a valid os. | 116 // Maps string to OsType; returns kOsUnknown if it's not a valid os. |
| 130 static OsType StringToOsType(const std::string& os); | 117 static OsType StringToOsType(const std::string& os); |
| 131 | 118 |
| 132 private: | 119 private: |
| 133 OsType type_; | 120 OsType type_; |
| 134 scoped_ptr<VersionInfo> version_info_; | 121 scoped_ptr<VersionInfo> version_info_; |
| 135 }; | 122 }; |
| 136 | 123 |
| 124 class StringInfo { |
| 125 public: |
| 126 StringInfo(const std::string& string_op, const std::string& string_value); |
| 127 |
| 128 // Determines if a given string is included in the StringInfo. |
| 129 bool Contains(const std::string& value) const; |
| 130 |
| 131 // Determines if the StringInfo contains valid information. |
| 132 bool IsValid() const; |
| 133 |
| 134 private: |
| 135 enum Op { |
| 136 kContains, |
| 137 kBeginWith, |
| 138 kEndWith, |
| 139 kEQ, // = |
| 140 kUnknown // Indicates StringInfo data is invalid. |
| 141 }; |
| 142 |
| 143 // Maps string to Op; returns kUnknown if it's not a valid Op. |
| 144 static Op StringToOp(const std::string& string_op); |
| 145 |
| 146 Op op_; |
| 147 std::string value_; |
| 148 }; |
| 149 |
| 137 class GpuBlacklistEntry { | 150 class GpuBlacklistEntry { |
| 138 public: | 151 public: |
| 139 // Constructs GpuBlacklistEntry from DictionaryValue loaded from json. | 152 // Constructs GpuBlacklistEntry from DictionaryValue loaded from json. |
| 140 static GpuBlacklistEntry* GetGpuBlacklistEntryFromValue( | 153 static GpuBlacklistEntry* GetGpuBlacklistEntryFromValue( |
| 141 DictionaryValue* value); | 154 DictionaryValue* value); |
| 142 | 155 |
| 143 // Determines if a given os/gc/driver is included in the Entry set. | 156 // Determines if a given os/gc/driver is included in the Entry set. |
| 144 bool Contains(OsType os_type, const Version& os_version, | 157 bool Contains(OsType os_type, const Version& os_version, |
| 145 uint32 vendor_id, uint32 device_id, | 158 uint32 vendor_id, uint32 device_id, |
| 146 const Version& driver_version) const; | 159 const std::string& driver_vendor, |
| 160 const Version& driver_version, |
| 161 const std::string& gl_renderer) const; |
| 147 | 162 |
| 148 // Returns the OsType. | 163 // Returns the OsType. |
| 149 OsType GetOsType() const; | 164 OsType GetOsType() const; |
| 150 | 165 |
| 166 // Returns the entry's unique id. 0 is reserved. |
| 167 uint32 id() const; |
| 168 |
| 151 // Returns the GpuFeatureFlags. | 169 // Returns the GpuFeatureFlags. |
| 152 GpuFeatureFlags GetGpuFeatureFlags() const; | 170 GpuFeatureFlags GetGpuFeatureFlags() const; |
| 153 | 171 |
| 154 ~GpuBlacklistEntry(); | 172 ~GpuBlacklistEntry(); |
| 155 | 173 |
| 156 private: | 174 private: |
| 157 GpuBlacklistEntry(); | 175 GpuBlacklistEntry(); |
| 158 | 176 |
| 177 bool SetId(const std::string& id_string); |
| 178 |
| 159 bool SetOsInfo(const std::string& os, | 179 bool SetOsInfo(const std::string& os, |
| 160 const std::string& version_op, | 180 const std::string& version_op, |
| 161 const std::string& version_string, | 181 const std::string& version_string, |
| 162 const std::string& version_string2); | 182 const std::string& version_string2); |
| 163 | 183 |
| 164 bool SetVendorId(const std::string& vendor_id_string); | 184 bool SetVendorId(const std::string& vendor_id_string); |
| 165 | 185 |
| 166 bool SetDeviceId(const std::string& device_id_string); | 186 bool SetDeviceId(const std::string& device_id_string); |
| 167 | 187 |
| 188 bool SetDriverVendorInfo(const std::string& vendor_op, |
| 189 const std::string& vendor_value); |
| 190 |
| 168 bool SetDriverVersionInfo(const std::string& version_op, | 191 bool SetDriverVersionInfo(const std::string& version_op, |
| 169 const std::string& version_string, | 192 const std::string& version_string, |
| 170 const std::string& version_string2); | 193 const std::string& version_string2); |
| 171 | 194 |
| 195 bool SetGLRendererInfo(const std::string& renderer_op, |
| 196 const std::string& renderer_value); |
| 197 |
| 172 bool SetBlacklistedFeatures( | 198 bool SetBlacklistedFeatures( |
| 173 const std::vector<std::string>& blacklisted_features); | 199 const std::vector<std::string>& blacklisted_features); |
| 174 | 200 |
| 201 uint32 id_; |
| 175 scoped_ptr<OsInfo> os_info_; | 202 scoped_ptr<OsInfo> os_info_; |
| 176 uint32 vendor_id_; | 203 uint32 vendor_id_; |
| 177 uint32 device_id_; | 204 uint32 device_id_; |
| 205 scoped_ptr<StringInfo> driver_vendor_info_; |
| 178 scoped_ptr<VersionInfo> driver_version_info_; | 206 scoped_ptr<VersionInfo> driver_version_info_; |
| 207 scoped_ptr<StringInfo> gl_renderer_info_; |
| 179 scoped_ptr<GpuFeatureFlags> feature_flags_; | 208 scoped_ptr<GpuFeatureFlags> feature_flags_; |
| 180 }; | 209 }; |
| 181 | 210 |
| 182 // Gets the current OS type. | 211 // Gets the current OS type. |
| 183 static OsType GetOsType(); | 212 static OsType GetOsType(); |
| 184 | 213 |
| 185 void Clear(); | 214 void Clear(); |
| 186 | 215 |
| 216 scoped_ptr<Version> version_; |
| 187 std::vector<GpuBlacklistEntry*> blacklist_; | 217 std::vector<GpuBlacklistEntry*> blacklist_; |
| 188 | 218 |
| 219 // This records all the blacklist entries that are appliable to the current |
| 220 // user machine. It is updated everytime DetermineGpuFeatureFlags() is |
| 221 // called and is used later by GetGpuFeatureFlagEntries(). |
| 222 std::vector<GpuBlacklistEntry*> active_entries_; |
| 223 |
| 224 uint32 max_entry_id_; |
| 225 |
| 189 DISALLOW_COPY_AND_ASSIGN(GpuBlacklist); | 226 DISALLOW_COPY_AND_ASSIGN(GpuBlacklist); |
| 190 }; | 227 }; |
| 191 | 228 |
| 192 #endif // CHROME_BROWSER_GPU_BLACKLIST_H_ | 229 #endif // CHROME_BROWSER_GPU_BLACKLIST_H_ |
| 193 | 230 |
| OLD | NEW |