OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CONTENT_BROWSER_GPU_GPU_BLACKLIST_H_ | |
6 #define CONTENT_BROWSER_GPU_GPU_BLACKLIST_H_ | |
7 | |
8 #include <string> | |
9 #include <vector> | |
10 | |
11 #include "base/basictypes.h" | |
12 #include "base/gtest_prod_util.h" | |
13 #include "base/memory/ref_counted.h" | |
14 #include "base/memory/scoped_ptr.h" | |
15 #include "base/values.h" | |
16 #include "build/build_config.h" | |
17 #include "content/common/content_export.h" | |
18 #include "content/public/common/gpu_feature_type.h" | |
19 | |
20 class Version; | |
21 | |
22 namespace content { | |
23 struct GPUInfo; | |
24 } | |
25 | |
26 class CONTENT_EXPORT GpuBlacklist { | |
27 public: | |
28 enum OsType { | |
29 kOsLinux, | |
30 kOsMacosx, | |
31 kOsWin, | |
32 kOsChromeOS, | |
33 kOsAny, | |
34 kOsUnknown | |
35 }; | |
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 | |
44 GpuBlacklist(); | |
45 virtual ~GpuBlacklist(); | |
46 | |
47 // Loads blacklist information from a json file. | |
48 // If failed, the current GpuBlacklist is un-touched. | |
49 bool LoadGpuBlacklist(const std::string& json_context, OsFilter os_filter); | |
50 bool LoadGpuBlacklist(const std::string& browser_version_string, | |
51 const std::string& json_context, | |
52 OsFilter os_filter); | |
53 | |
54 // Collects system information and combines them with gpu_info and blacklist | |
55 // information to determine gpu feature flags. | |
56 // If os is kOsAny, use the current OS; if os_version is null, use the | |
57 // current OS version. | |
58 content::GpuFeatureType DetermineGpuFeatureType( | |
59 OsType os, Version* os_version, const content::GPUInfo& gpu_info); | |
60 | |
61 // Collects the active entries that set the "feature" flag from the last | |
62 // DetermineGpuFeatureType() call. This tells which entries are responsible | |
63 // for raising a certain flag, i.e, for blacklisting a certain feature. | |
64 // Examples of "feature": | |
65 // GPU_FEATURE_TYPE_ALL - any of the supported features; | |
66 // GPU_FEATURE_TYPE_WEBGL - a single feature; | |
67 // GPU_FEATURE_TYPE_WEBGL | GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING | |
68 // - two features. | |
69 // If disabled set to true, return entries that are disabled; otherwise, | |
70 // return enabled entries. | |
71 void GetGpuFeatureTypeEntries(content::GpuFeatureType feature, | |
72 std::vector<uint32>& entry_ids, | |
73 bool disabled) const; | |
74 | |
75 // Returns the description and bugs from active entries from the last | |
76 // DetermineGpuFeatureType() call. | |
77 // | |
78 // Each problems has: | |
79 // { | |
80 // "description": "Your GPU is too old", | |
81 // "crBugs": [1234], | |
82 // "webkitBugs": [] | |
83 // } | |
84 void GetBlacklistReasons(ListValue* problem_list) const; | |
85 | |
86 // Return the largest entry id. This is used for histogramming. | |
87 uint32 max_entry_id() const; | |
88 | |
89 // Returns the version of the current blacklist. | |
90 std::string GetVersion() const; | |
91 | |
92 private: | |
93 friend class GpuBlacklistTest; | |
94 FRIEND_TEST_ALL_PREFIXES(GpuBlacklistTest, ChromeVersionEntry); | |
95 FRIEND_TEST_ALL_PREFIXES(GpuBlacklistTest, CurrentBlacklistValidation); | |
96 FRIEND_TEST_ALL_PREFIXES(GpuBlacklistTest, UnknownField); | |
97 FRIEND_TEST_ALL_PREFIXES(GpuBlacklistTest, UnknownExceptionField); | |
98 FRIEND_TEST_ALL_PREFIXES(GpuBlacklistTest, UnknownFeature); | |
99 | |
100 enum BrowserVersionSupport { | |
101 kSupported, | |
102 kUnsupported, | |
103 kMalformed | |
104 }; | |
105 | |
106 enum NumericOp { | |
107 kBetween, // <= * <= | |
108 kEQ, // = | |
109 kLT, // < | |
110 kLE, // <= | |
111 kGT, // > | |
112 kGE, // >= | |
113 kAny, | |
114 kUnknown // Indicates the data is invalid. | |
115 }; | |
116 | |
117 class VersionInfo { | |
118 public: | |
119 // If version_style is empty, it defaults to kNumerical. | |
120 VersionInfo(const std::string& version_op, | |
121 const std::string& version_style, | |
122 const std::string& version_string, | |
123 const std::string& version_string2); | |
124 ~VersionInfo(); | |
125 | |
126 // Determines if a given version is included in the VersionInfo range. | |
127 bool Contains(const Version& version) const; | |
128 | |
129 // Determine if the version_style is lexical. | |
130 bool IsLexical() const; | |
131 | |
132 // Determines if the VersionInfo contains valid information. | |
133 bool IsValid() const; | |
134 | |
135 private: | |
136 enum VersionStyle { | |
137 kVersionStyleNumerical, | |
138 kVersionStyleLexical, | |
139 kVersionStyleUnknown | |
140 }; | |
141 | |
142 static VersionStyle StringToVersionStyle(const std::string& version_style); | |
143 | |
144 NumericOp op_; | |
145 VersionStyle version_style_; | |
146 scoped_ptr<Version> version_; | |
147 scoped_ptr<Version> version2_; | |
148 }; | |
149 | |
150 class OsInfo { | |
151 public: | |
152 OsInfo(const std::string& os, | |
153 const std::string& version_op, | |
154 const std::string& version_string, | |
155 const std::string& version_string2); | |
156 ~OsInfo(); | |
157 | |
158 // Determines if a given os/version is included in the OsInfo set. | |
159 bool Contains(OsType type, const Version& version) const; | |
160 | |
161 // Determines if the VersionInfo contains valid information. | |
162 bool IsValid() const; | |
163 | |
164 OsType type() const; | |
165 | |
166 // Maps string to OsType; returns kOsUnknown if it's not a valid os. | |
167 static OsType StringToOsType(const std::string& os); | |
168 | |
169 private: | |
170 OsType type_; | |
171 scoped_ptr<VersionInfo> version_info_; | |
172 }; | |
173 | |
174 class StringInfo { | |
175 public: | |
176 StringInfo(const std::string& string_op, const std::string& string_value); | |
177 | |
178 // Determines if a given string is included in the StringInfo. | |
179 bool Contains(const std::string& value) const; | |
180 | |
181 // Determines if the StringInfo contains valid information. | |
182 bool IsValid() const; | |
183 | |
184 private: | |
185 enum Op { | |
186 kContains, | |
187 kBeginWith, | |
188 kEndWith, | |
189 kEQ, // = | |
190 kUnknown // Indicates StringInfo data is invalid. | |
191 }; | |
192 | |
193 // Maps string to Op; returns kUnknown if it's not a valid Op. | |
194 static Op StringToOp(const std::string& string_op); | |
195 | |
196 Op op_; | |
197 std::string value_; | |
198 }; | |
199 | |
200 class FloatInfo { | |
201 public: | |
202 FloatInfo(const std::string& float_op, | |
203 const std::string& float_value, | |
204 const std::string& float_value2); | |
205 | |
206 // Determines if a given float is included in the FloatInfo. | |
207 bool Contains(float value) const; | |
208 | |
209 // Determines if the FloatInfo contains valid information. | |
210 bool IsValid() const; | |
211 | |
212 private: | |
213 NumericOp op_; | |
214 float value_; | |
215 float value2_; | |
216 }; | |
217 | |
218 class GpuBlacklistEntry; | |
219 typedef scoped_refptr<GpuBlacklistEntry> ScopedGpuBlacklistEntry; | |
220 | |
221 class GpuBlacklistEntry : public base::RefCounted<GpuBlacklistEntry> { | |
222 public: | |
223 // Constructs GpuBlacklistEntry from DictionaryValue loaded from json. | |
224 // Top-level entry must have an id number. Others are exceptions. | |
225 static ScopedGpuBlacklistEntry GetGpuBlacklistEntryFromValue( | |
226 const base::DictionaryValue* value, bool top_level); | |
227 | |
228 // Determines if a given os/gc/driver is included in the Entry set. | |
229 bool Contains(OsType os_type, | |
230 const Version& os_version, | |
231 const content::GPUInfo& gpu_info) const; | |
232 | |
233 // Returns the OsType. | |
234 OsType GetOsType() const; | |
235 | |
236 // Returns the entry's unique id. 0 is reserved. | |
237 uint32 id() const; | |
238 | |
239 // Returns whether the entry is disabled. | |
240 bool disabled() const; | |
241 | |
242 // Returns the description of the entry | |
243 const std::string& description() const { return description_; } | |
244 | |
245 // Returns a list of Chromium and Webkit bugs applicable to this entry | |
246 const std::vector<int>& cr_bugs() const { return cr_bugs_; } | |
247 const std::vector<int>& webkit_bugs() const { return webkit_bugs_; } | |
248 | |
249 // Returns the GpuFeatureType. | |
250 content::GpuFeatureType GetGpuFeatureType() const; | |
251 | |
252 // Returns true if an unknown field is encountered. | |
253 bool contains_unknown_fields() const { | |
254 return contains_unknown_fields_; | |
255 } | |
256 // Returns true if an unknown blacklist feature is encountered. | |
257 bool contains_unknown_features() const { | |
258 return contains_unknown_features_; | |
259 } | |
260 | |
261 private: | |
262 friend class base::RefCounted<GpuBlacklistEntry>; | |
263 | |
264 enum MultiGpuStyle { | |
265 kMultiGpuStyleOptimus, | |
266 kMultiGpuStyleAMDSwitchable, | |
267 kMultiGpuStyleNone | |
268 }; | |
269 | |
270 enum MultiGpuCategory { | |
271 kMultiGpuCategoryPrimary, | |
272 kMultiGpuCategorySecondary, | |
273 kMultiGpuCategoryAny, | |
274 kMultiGpuCategoryNone | |
275 }; | |
276 | |
277 GpuBlacklistEntry(); | |
278 ~GpuBlacklistEntry(); | |
279 | |
280 bool SetId(uint32 id); | |
281 | |
282 void SetDisabled(bool disabled); | |
283 | |
284 bool SetOsInfo(const std::string& os, | |
285 const std::string& version_op, | |
286 const std::string& version_string, | |
287 const std::string& version_string2); | |
288 | |
289 bool SetVendorId(const std::string& vendor_id_string); | |
290 | |
291 bool AddDeviceId(const std::string& device_id_string); | |
292 | |
293 bool SetMultiGpuStyle(const std::string& multi_gpu_style_string); | |
294 | |
295 bool SetMultiGpuCategory(const std::string& multi_gpu_category_string); | |
296 | |
297 bool SetDriverVendorInfo(const std::string& vendor_op, | |
298 const std::string& vendor_value); | |
299 | |
300 bool SetDriverVersionInfo(const std::string& version_op, | |
301 const std::string& version_style, | |
302 const std::string& version_string, | |
303 const std::string& version_string2); | |
304 | |
305 bool SetDriverDateInfo(const std::string& date_op, | |
306 const std::string& date_string, | |
307 const std::string& date_string2); | |
308 | |
309 bool SetGLVendorInfo(const std::string& vendor_op, | |
310 const std::string& vendor_value); | |
311 | |
312 bool SetGLRendererInfo(const std::string& renderer_op, | |
313 const std::string& renderer_value); | |
314 | |
315 bool SetPerfGraphicsInfo(const std::string& op, | |
316 const std::string& float_string, | |
317 const std::string& float_string2); | |
318 | |
319 bool SetPerfGamingInfo(const std::string& op, | |
320 const std::string& float_string, | |
321 const std::string& float_string2); | |
322 | |
323 bool SetPerfOverallInfo(const std::string& op, | |
324 const std::string& float_string, | |
325 const std::string& float_string2); | |
326 | |
327 bool SetBlacklistedFeatures( | |
328 const std::vector<std::string>& blacklisted_features); | |
329 | |
330 void AddException(ScopedGpuBlacklistEntry exception); | |
331 | |
332 static MultiGpuStyle StringToMultiGpuStyle(const std::string& style); | |
333 | |
334 static MultiGpuCategory StringToMultiGpuCategory( | |
335 const std::string& category); | |
336 | |
337 uint32 id_; | |
338 bool disabled_; | |
339 std::string description_; | |
340 std::vector<int> cr_bugs_; | |
341 std::vector<int> webkit_bugs_; | |
342 scoped_ptr<OsInfo> os_info_; | |
343 uint32 vendor_id_; | |
344 std::vector<uint32> device_id_list_; | |
345 MultiGpuStyle multi_gpu_style_; | |
346 MultiGpuCategory multi_gpu_category_; | |
347 scoped_ptr<StringInfo> driver_vendor_info_; | |
348 scoped_ptr<VersionInfo> driver_version_info_; | |
349 scoped_ptr<VersionInfo> driver_date_info_; | |
350 scoped_ptr<StringInfo> gl_vendor_info_; | |
351 scoped_ptr<StringInfo> gl_renderer_info_; | |
352 scoped_ptr<FloatInfo> perf_graphics_info_; | |
353 scoped_ptr<FloatInfo> perf_gaming_info_; | |
354 scoped_ptr<FloatInfo> perf_overall_info_; | |
355 content::GpuFeatureType feature_type_; | |
356 std::vector<ScopedGpuBlacklistEntry> exceptions_; | |
357 bool contains_unknown_fields_; | |
358 bool contains_unknown_features_; | |
359 }; | |
360 | |
361 // Gets the current OS type. | |
362 static OsType GetOsType(); | |
363 | |
364 bool LoadGpuBlacklist(const base::DictionaryValue& parsed_json, | |
365 OsFilter os_filter); | |
366 | |
367 void Clear(); | |
368 | |
369 // Check if the entry is supported by the current version of browser. | |
370 // By default, if there is no browser version information in the entry, | |
371 // return kSupported; | |
372 BrowserVersionSupport IsEntrySupportedByCurrentBrowserVersion( | |
373 const base::DictionaryValue* value); | |
374 | |
375 // Returns the number of entries. This is only for tests. | |
376 size_t num_entries() const; | |
377 | |
378 // Check if any entries contain unknown fields. This is only for tests. | |
379 bool contains_unknown_fields() const { return contains_unknown_fields_; } | |
380 | |
381 static NumericOp StringToNumericOp(const std::string& op); | |
382 | |
383 scoped_ptr<Version> version_; | |
384 std::vector<ScopedGpuBlacklistEntry> blacklist_; | |
385 | |
386 scoped_ptr<Version> browser_version_; | |
387 | |
388 // This records all the blacklist entries that are appliable to the current | |
389 // user machine. It is updated everytime DetermineGpuFeatureType() is | |
390 // called and is used later by GetGpuFeatureTypeEntries(). | |
391 std::vector<ScopedGpuBlacklistEntry> active_entries_; | |
392 | |
393 uint32 max_entry_id_; | |
394 | |
395 bool contains_unknown_fields_; | |
396 | |
397 DISALLOW_COPY_AND_ASSIGN(GpuBlacklist); | |
398 }; | |
399 | |
400 #endif // CONTENT_BROWSER_GPU_GPU_BLACKLIST_H_ | |
401 | |
OLD | NEW |