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 |
Vangelis Kokkevis
2011/01/24 20:55:21
As the blacklist is getting more and more full fea
Zhenyao Mo
2011/01/24 22:38:22
Done.
| |
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). |
Vangelis Kokkevis
2011/01/24 20:55:21
"defined later": Where?
Zhenyao Mo
2011/01/24 22:38:22
It's at the end of this comments. I will change i
| |
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). | |
Vangelis Kokkevis
2011/01/24 20:55:21
"defined later": Where?
Zhenyao Mo
2011/01/24 22:38:22
See comment above.
On 2011/01/24 20:55:21, Vangel
| |
32 // 7. "blacklist" is a list of gpu feature strings, valid values include | |
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 // DetermineGpuFeatureFlags() call. This tells which entries are responsible | |
86 // for raising a certain flag, i.e, for blacklisting a certain feature. | |
87 // Examples of "feature": | |
88 // kGpuFeatureAll - all supported features combined; | |
Vangelis Kokkevis
2011/01/24 20:55:21
I guess in this case kGpuFeatureAll really means "
Zhenyao Mo
2011/01/24 22:38:22
Done.
| |
89 // kGpuFeatureWebgl - a single feature; | |
90 // kGpuFeatureWebgl | kGpuFeatureAcceleratedCompositing - two features. | |
91 void GetGpuFeatureFlagEntries(GpuFeatureFlags::GpuFeatureType feature, | |
92 std::vector<uint32>& entry_ids) const; | |
93 | |
94 // Return the largest entry id. This is used for histogram purpose. | |
Vangelis Kokkevis
2011/01/24 20:55:21
nit: "used for histogram purpose" -> "used for his
Zhenyao Mo
2011/01/24 22:38:22
Done.
| |
95 uint32 max_entry_id() const; | |
96 | |
97 // Collects the version of the current blacklist. Return false and set major | |
Vangelis Kokkevis
2011/01/24 20:55:21
Return -> Returns . set -> sets
Zhenyao Mo
2011/01/24 22:38:22
Done.
| |
98 // and minor to 0 on failure. | |
99 bool GetVersion(uint16* major, uint16* monir) const; | |
78 | 100 |
79 private: | 101 private: |
80 class VersionInfo { | 102 class VersionInfo { |
81 public: | 103 public: |
82 VersionInfo(const std::string& version_op, | 104 VersionInfo(const std::string& version_op, |
83 const std::string& version_string, | 105 const std::string& version_string, |
84 const std::string& version_string2); | 106 const std::string& version_string2); |
85 ~VersionInfo(); | 107 ~VersionInfo(); |
86 | 108 |
87 // Determines if a given version is included in the VersionInfo range. | 109 // 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; | 149 OsType type() const; |
128 | 150 |
129 // Maps string to OsType; returns kOsUnknown if it's not a valid os. | 151 // Maps string to OsType; returns kOsUnknown if it's not a valid os. |
130 static OsType StringToOsType(const std::string& os); | 152 static OsType StringToOsType(const std::string& os); |
131 | 153 |
132 private: | 154 private: |
133 OsType type_; | 155 OsType type_; |
134 scoped_ptr<VersionInfo> version_info_; | 156 scoped_ptr<VersionInfo> version_info_; |
135 }; | 157 }; |
136 | 158 |
159 class StringInfo { | |
160 public: | |
161 StringInfo(const std::string& string_op, const std::string& string_value); | |
162 ~StringInfo(); | |
163 | |
164 // Determines if a given string is included in the StringInfo. | |
165 bool Contains(const std::string& value) const; | |
166 | |
167 // Determines if the StringInfo contains valid information. | |
168 bool IsValid() const; | |
169 | |
170 private: | |
171 enum Op { | |
172 kContains, // contains | |
Vangelis Kokkevis
2011/01/24 20:55:21
nit: I don't think the inline comments add useful
Zhenyao Mo
2011/01/24 22:38:22
Removed.
On 2011/01/24 20:55:21, Vangelis Kokkevis
| |
173 kBeginWith, // beginwith | |
174 kEndWith, // endwith | |
175 kEQ, // = | |
176 kUnknown // Indicates StringInfo data is invalid. | |
177 }; | |
178 | |
179 // Maps string to Op; returns kUnknown if it's not a valid Op. | |
180 static Op StringToOp(const std::string& string_op); | |
181 | |
182 Op op_; | |
183 std::string value_; | |
184 }; | |
185 | |
137 class GpuBlacklistEntry { | 186 class GpuBlacklistEntry { |
138 public: | 187 public: |
139 // Constructs GpuBlacklistEntry from DictionaryValue loaded from json. | 188 // Constructs GpuBlacklistEntry from DictionaryValue loaded from json. |
140 static GpuBlacklistEntry* GetGpuBlacklistEntryFromValue( | 189 static GpuBlacklistEntry* GetGpuBlacklistEntryFromValue( |
141 DictionaryValue* value); | 190 DictionaryValue* value); |
142 | 191 |
143 // Determines if a given os/gc/driver is included in the Entry set. | 192 // Determines if a given os/gc/driver is included in the Entry set. |
144 bool Contains(OsType os_type, const Version& os_version, | 193 bool Contains(OsType os_type, const Version& os_version, |
145 uint32 vendor_id, uint32 device_id, | 194 uint32 vendor_id, uint32 device_id, |
146 const Version& driver_version) const; | 195 const std::string& driver_vendor, |
196 const Version& driver_version, | |
197 const std::string& gl_renderer) const; | |
147 | 198 |
148 // Returns the OsType. | 199 // Returns the OsType. |
149 OsType GetOsType() const; | 200 OsType GetOsType() const; |
150 | 201 |
202 // Returns the entry's unique id. 0 is preserved. | |
Vangelis Kokkevis
2011/01/24 20:55:21
preserved -> reserved (?)
Zhenyao Mo
2011/01/24 22:38:22
Done.
| |
203 uint32 id() const; | |
204 | |
151 // Returns the GpuFeatureFlags. | 205 // Returns the GpuFeatureFlags. |
152 GpuFeatureFlags GetGpuFeatureFlags() const; | 206 GpuFeatureFlags GetGpuFeatureFlags() const; |
153 | 207 |
154 ~GpuBlacklistEntry(); | 208 ~GpuBlacklistEntry(); |
155 | 209 |
156 private: | 210 private: |
157 GpuBlacklistEntry(); | 211 GpuBlacklistEntry(); |
158 | 212 |
213 bool SetId(const std::string& id_string); | |
214 | |
159 bool SetOsInfo(const std::string& os, | 215 bool SetOsInfo(const std::string& os, |
160 const std::string& version_op, | 216 const std::string& version_op, |
161 const std::string& version_string, | 217 const std::string& version_string, |
162 const std::string& version_string2); | 218 const std::string& version_string2); |
163 | 219 |
164 bool SetVendorId(const std::string& vendor_id_string); | 220 bool SetVendorId(const std::string& vendor_id_string); |
165 | 221 |
166 bool SetDeviceId(const std::string& device_id_string); | 222 bool SetDeviceId(const std::string& device_id_string); |
167 | 223 |
224 bool SetDriverVendorInfo(const std::string& vendor_op, | |
225 const std::string& vendor_value); | |
226 | |
168 bool SetDriverVersionInfo(const std::string& version_op, | 227 bool SetDriverVersionInfo(const std::string& version_op, |
169 const std::string& version_string, | 228 const std::string& version_string, |
170 const std::string& version_string2); | 229 const std::string& version_string2); |
171 | 230 |
231 bool SetGLRendererInfo(const std::string& renderer_op, | |
232 const std::string& renderer_value); | |
233 | |
172 bool SetBlacklistedFeatures( | 234 bool SetBlacklistedFeatures( |
173 const std::vector<std::string>& blacklisted_features); | 235 const std::vector<std::string>& blacklisted_features); |
174 | 236 |
237 uint32 id_; | |
175 scoped_ptr<OsInfo> os_info_; | 238 scoped_ptr<OsInfo> os_info_; |
176 uint32 vendor_id_; | 239 uint32 vendor_id_; |
177 uint32 device_id_; | 240 uint32 device_id_; |
241 scoped_ptr<StringInfo> driver_vendor_info_; | |
178 scoped_ptr<VersionInfo> driver_version_info_; | 242 scoped_ptr<VersionInfo> driver_version_info_; |
243 scoped_ptr<StringInfo> gl_renderer_info_; | |
179 scoped_ptr<GpuFeatureFlags> feature_flags_; | 244 scoped_ptr<GpuFeatureFlags> feature_flags_; |
180 }; | 245 }; |
181 | 246 |
182 // Gets the current OS type. | 247 // Gets the current OS type. |
183 static OsType GetOsType(); | 248 static OsType GetOsType(); |
184 | 249 |
185 void Clear(); | 250 void Clear(); |
186 | 251 |
252 scoped_ptr<Version> version_; | |
187 std::vector<GpuBlacklistEntry*> blacklist_; | 253 std::vector<GpuBlacklistEntry*> blacklist_; |
188 | 254 |
255 // These two vectors are updated everytime DetermineGpuFeatureFlags() is | |
256 // called. They are used by GetGpuFeatureFlagEntries(). | |
257 // Two vectors should always have the same number of elements. | |
258 std::vector<uint32> features_; | |
Vangelis Kokkevis
2011/01/24 20:55:21
Does it make sense to turn the feature/id pair int
Zhenyao Mo
2011/01/24 22:38:22
I switch to record GpuBlacklistEntry instead and l
| |
259 std::vector<uint32> entry_ids_; | |
260 | |
261 uint32 max_entry_id_; | |
262 | |
189 DISALLOW_COPY_AND_ASSIGN(GpuBlacklist); | 263 DISALLOW_COPY_AND_ASSIGN(GpuBlacklist); |
190 }; | 264 }; |
191 | 265 |
192 #endif // CHROME_BROWSER_GPU_BLACKLIST_H_ | 266 #endif // CHROME_BROWSER_GPU_BLACKLIST_H_ |
193 | 267 |
OLD | NEW |