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. | 9 // Determines whether certain gpu-related features are blacklisted or not. |
10 // A valid gpu_blacklist.json file are in the format of | 10 // A valid gpu_blacklist.json file are in the format of |
11 // { | 11 // { |
12 // "version": "x.y", | |
12 // "entries": [ | 13 // "entries": [ |
13 // { // entry 1 | 14 // { // entry 1 |
14 // }, | 15 // }, |
15 // ... | 16 // ... |
16 // { // entry n | 17 // { // entry n |
17 // } | 18 // } |
18 // ] | 19 // ] |
19 // } | 20 // } |
20 // Each entry contains the following fields: | 21 // Each entry contains the following fields: |
21 // "os", "vendor_id", "device_id", "driver_version", and "blacklist". | 22 // "os", "vendor_id", "device_id", "driver_version", and "blacklist". |
22 // Only "blacklist" is mandatory. | 23 // Only "blacklist" is mandatory. |
23 // 1. "os" contains "type" and an optional "version". "type" could be "macosx", | 24 // 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 // "linux", "win", or "any". "any" is the same as not specifying "os". |
25 // "version" is a VERSION structure (defined later). | 26 // "version" is a VERSION structure (defined later). |
26 // 2. "vendor_id" has the value of a string. | 27 // 2. "vendor_id" has the value of a string. |
27 // 3. "device_id" has the value of a string. | 28 // 3. "device_id" has the value of a string. |
28 // 4. "driver_version" is a VERSION structure (defined later). | 29 // 4. "driver_vendor" is a STRING structure (defined later). |
29 // 5. "blacklist" is a list of gpu feature strings, valid values include | 30 // 5. "driver_version" is a VERSION structure (defined later). |
31 // 6. "gl_renderer" is a STRING structure (defined later). | |
32 // 6. "blacklist" is a list of gpu feature strings, valid values include | |
Ken Russell (switch to Gerrit)
2011/01/21 19:57:52
6 -> 7
Zhenyao Mo
2011/01/21 21:51:40
Done.
| |
30 // "accelerated_2d_canvas", "accelerated_compositing", "webgl", and "all". | 33 // "accelerated_2d_canvas", "accelerated_compositing", "webgl", and "all". |
31 // Currently whatever feature is selected, the effect is the same as "all", | 34 // 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. | 35 // 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 | 36 // VERSION includes "op" "number", and "number2". "op" can be any of the |
34 // following value: "=", "<", "<=", ">", ">=", "any", "between". "number2" is | 37 // following values: "=", "<", "<=", ">", ">=", "any", "between". "number2" is |
35 // only used if "op" is "between". "number" is used for all "op" values except | 38 // 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. | 39 // "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. | 40 // Check out "gpu_blacklist_unittest.cc" for examples. |
41 // STRING includes "op" and "value". "op" can be any of the following values: | |
42 // "contains", "beginwith", "endwith", "=". "value" is a string. | |
38 | 43 |
39 #include <string> | 44 #include <string> |
40 #include <vector> | 45 #include <vector> |
41 | 46 |
42 #include "base/basictypes.h" | 47 #include "base/basictypes.h" |
43 #include "base/scoped_ptr.h" | 48 #include "base/scoped_ptr.h" |
44 #include "chrome/common/gpu_feature_flags.h" | 49 #include "chrome/common/gpu_feature_flags.h" |
45 | 50 |
46 class DictionaryValue; | 51 class DictionaryValue; |
47 class GPUInfo; | 52 class GPUInfo; |
(...skipping 19 matching lines...) Expand all Loading... | |
67 // If failed, the current GpuBlacklist is un-touched. | 72 // If failed, the current GpuBlacklist is un-touched. |
68 bool LoadGpuBlacklist(const std::string& json_context, | 73 bool LoadGpuBlacklist(const std::string& json_context, |
69 bool current_os_only); | 74 bool current_os_only); |
70 | 75 |
71 // Collects system information and combines them with gpu_info and blacklist | 76 // Collects system information and combines them with gpu_info and blacklist |
72 // information to determine gpu feature flags. | 77 // information to determine gpu feature flags. |
73 // If os is kOsAny, use the current OS; if os_version is null, use the | 78 // If os is kOsAny, use the current OS; if os_version is null, use the |
74 // current OS version. | 79 // current OS version. |
75 GpuFeatureFlags DetermineGpuFeatureFlags(OsType os, | 80 GpuFeatureFlags DetermineGpuFeatureFlags(OsType os, |
76 Version* os_version, | 81 Version* os_version, |
77 const GPUInfo& gpu_info) const; | 82 const GPUInfo& gpu_info); |
83 | |
84 // Collects the entries that set the "feature" flag from the last | |
85 // DeterminGpuFeatureFlags() call. This tells which entries are responsible | |
Ken Russell (switch to Gerrit)
2011/01/21 19:57:52
Determin -> Determine
Zhenyao Mo
2011/01/21 21:51:40
Done.
| |
86 // for raising a certain flag. | |
87 // The "feature" could be a single feature or a combination of multiple ones. | |
Ken Russell (switch to Gerrit)
2011/01/21 19:57:52
Could you improve this comment? It talks about fea
Zhenyao Mo
2011/01/21 21:51:40
Done.
| |
88 void GetGpuFeatureFlagEntries(GpuFeatureFlags::GpuFeatureType feature, | |
89 std::vector<uint32>& entry_ids) const; | |
90 | |
91 // Return the largest entry id. This is used for histogram purpose. | |
92 uint32 max_entry_id() const; | |
93 | |
94 // Collects the version of the current blacklist. Return false and set major | |
95 // and minor to 0 on failure. | |
96 bool GetVersion(uint16* major, uint16* monir) const; | |
78 | 97 |
79 private: | 98 private: |
80 class VersionInfo { | 99 class VersionInfo { |
81 public: | 100 public: |
82 VersionInfo(const std::string& version_op, | 101 VersionInfo(const std::string& version_op, |
83 const std::string& version_string, | 102 const std::string& version_string, |
84 const std::string& version_string2); | 103 const std::string& version_string2); |
85 ~VersionInfo(); | 104 ~VersionInfo(); |
86 | 105 |
87 // Determines if a given version is included in the VersionInfo range. | 106 // 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; | 146 OsType type() const; |
128 | 147 |
129 // Maps string to OsType; returns kOsUnknown if it's not a valid os. | 148 // Maps string to OsType; returns kOsUnknown if it's not a valid os. |
130 static OsType StringToOsType(const std::string& os); | 149 static OsType StringToOsType(const std::string& os); |
131 | 150 |
132 private: | 151 private: |
133 OsType type_; | 152 OsType type_; |
134 scoped_ptr<VersionInfo> version_info_; | 153 scoped_ptr<VersionInfo> version_info_; |
135 }; | 154 }; |
136 | 155 |
156 class StringInfo { | |
157 public: | |
158 StringInfo(const std::string& string_op, const std::string& string_value); | |
159 ~StringInfo(); | |
160 | |
161 // Determines if a given string is included in the StringInfo. | |
162 bool Contains(const std::string& value) const; | |
163 | |
164 // Determines if the StringInfo contains valid information. | |
165 bool IsValid() const; | |
166 | |
167 private: | |
168 enum Op { | |
169 kContains, // contains | |
170 kBeginWith, // beginwith | |
171 kEndWith, // endwith | |
172 kEQ, // = | |
173 kUnknown // Indicates StringInfo data is invalid. | |
174 }; | |
175 | |
176 // Maps string to Op; returns kUnknown if it's not a valid Op. | |
177 static Op StringToOp(const std::string& string_op); | |
178 | |
179 Op op_; | |
180 std::string value_; | |
181 }; | |
182 | |
137 class GpuBlacklistEntry { | 183 class GpuBlacklistEntry { |
138 public: | 184 public: |
139 // Constructs GpuBlacklistEntry from DictionaryValue loaded from json. | 185 // Constructs GpuBlacklistEntry from DictionaryValue loaded from json. |
140 static GpuBlacklistEntry* GetGpuBlacklistEntryFromValue( | 186 static GpuBlacklistEntry* GetGpuBlacklistEntryFromValue( |
141 DictionaryValue* value); | 187 DictionaryValue* value); |
142 | 188 |
143 // Determines if a given os/gc/driver is included in the Entry set. | 189 // Determines if a given os/gc/driver is included in the Entry set. |
144 bool Contains(OsType os_type, const Version& os_version, | 190 bool Contains(OsType os_type, const Version& os_version, |
145 uint32 vendor_id, uint32 device_id, | 191 uint32 vendor_id, uint32 device_id, |
146 const Version& driver_version) const; | 192 const std::string& driver_vendor, |
193 const Version& driver_version, | |
194 const std::string& gl_renderer) const; | |
147 | 195 |
148 // Returns the OsType. | 196 // Returns the OsType. |
149 OsType GetOsType() const; | 197 OsType GetOsType() const; |
150 | 198 |
199 // Returns the entry's unique id. 0 is preserved. | |
200 uint32 id() const; | |
201 | |
151 // Returns the GpuFeatureFlags. | 202 // Returns the GpuFeatureFlags. |
152 GpuFeatureFlags GetGpuFeatureFlags() const; | 203 GpuFeatureFlags GetGpuFeatureFlags() const; |
153 | 204 |
154 ~GpuBlacklistEntry(); | 205 ~GpuBlacklistEntry(); |
155 | 206 |
156 private: | 207 private: |
157 GpuBlacklistEntry(); | 208 GpuBlacklistEntry(); |
158 | 209 |
210 bool SetId(const std::string& id_string); | |
211 | |
159 bool SetOsInfo(const std::string& os, | 212 bool SetOsInfo(const std::string& os, |
160 const std::string& version_op, | 213 const std::string& version_op, |
161 const std::string& version_string, | 214 const std::string& version_string, |
162 const std::string& version_string2); | 215 const std::string& version_string2); |
163 | 216 |
164 bool SetVendorId(const std::string& vendor_id_string); | 217 bool SetVendorId(const std::string& vendor_id_string); |
165 | 218 |
166 bool SetDeviceId(const std::string& device_id_string); | 219 bool SetDeviceId(const std::string& device_id_string); |
167 | 220 |
221 bool SetDriverVendorInfo(const std::string& vendor_op, | |
222 const std::string& vendor_value); | |
223 | |
168 bool SetDriverVersionInfo(const std::string& version_op, | 224 bool SetDriverVersionInfo(const std::string& version_op, |
169 const std::string& version_string, | 225 const std::string& version_string, |
170 const std::string& version_string2); | 226 const std::string& version_string2); |
171 | 227 |
228 bool SetGlRendererInfo(const std::string& renderer_op, | |
Ken Russell (switch to Gerrit)
2011/01/21 19:57:52
Gl -> GL
Zhenyao Mo
2011/01/21 21:51:40
Done.
| |
229 const std::string& renderer_value); | |
230 | |
172 bool SetBlacklistedFeatures( | 231 bool SetBlacklistedFeatures( |
173 const std::vector<std::string>& blacklisted_features); | 232 const std::vector<std::string>& blacklisted_features); |
174 | 233 |
234 uint32 id_; | |
175 scoped_ptr<OsInfo> os_info_; | 235 scoped_ptr<OsInfo> os_info_; |
176 uint32 vendor_id_; | 236 uint32 vendor_id_; |
177 uint32 device_id_; | 237 uint32 device_id_; |
238 scoped_ptr<StringInfo> driver_vendor_info_; | |
178 scoped_ptr<VersionInfo> driver_version_info_; | 239 scoped_ptr<VersionInfo> driver_version_info_; |
240 scoped_ptr<StringInfo> gl_renderer_info_; | |
179 scoped_ptr<GpuFeatureFlags> feature_flags_; | 241 scoped_ptr<GpuFeatureFlags> feature_flags_; |
180 }; | 242 }; |
181 | 243 |
182 // Gets the current OS type. | 244 // Gets the current OS type. |
183 static OsType GetOsType(); | 245 static OsType GetOsType(); |
184 | 246 |
185 void Clear(); | 247 void Clear(); |
186 | 248 |
249 scoped_ptr<Version> version_; | |
187 std::vector<GpuBlacklistEntry*> blacklist_; | 250 std::vector<GpuBlacklistEntry*> blacklist_; |
188 | 251 |
252 // These two vectors are updated everytime DetermineGpuFeatureFlags() is | |
253 // called. They are used by GetGpuFeatureFlagEntries(). | |
254 // Two vectors should always have the same number of elements. | |
255 std::vector<uint32> features_; | |
256 std::vector<uint32> entry_ids_; | |
257 | |
258 uint32 max_entry_id_; | |
259 | |
189 DISALLOW_COPY_AND_ASSIGN(GpuBlacklist); | 260 DISALLOW_COPY_AND_ASSIGN(GpuBlacklist); |
190 }; | 261 }; |
191 | 262 |
192 #endif // CHROME_BROWSER_GPU_BLACKLIST_H_ | 263 #endif // CHROME_BROWSER_GPU_BLACKLIST_H_ |
193 | 264 |
OLD | NEW |