Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Side by Side Diff: content/browser/gpu/gpu_control_list.h

Issue 12976004: Generalzie GpuBlacklist to GpuControlList. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/browser/gpu/gpu_blacklist_unittest.cc ('k') | content/browser/gpu/gpu_control_list.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2013 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_CONTROL_LIST_H_
6 #define CONTENT_BROWSER_GPU_GPU_CONTROL_LIST_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/basictypes.h"
12 #include "base/gtest_prod_util.h"
13 #include "base/hash_tables.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/values.h"
17 #include "build/build_config.h"
18 #include "content/common/content_export.h"
19
20 namespace content {
21 struct GPUInfo;
22
23 class CONTENT_EXPORT GpuControlList {
24 public:
25 enum OsType {
26 kOsLinux,
27 kOsMacosx,
28 kOsWin,
29 kOsChromeOS,
30 kOsAndroid,
31 kOsAny,
32 kOsUnknown
33 };
34
35 enum OsFilter {
36 // In loading, ignore all entries that belong to other OS.
37 kCurrentOsOnly,
38 // In loading, keep all entries. This is for testing only.
39 kAllOs
40 };
41
42 GpuControlList();
43 virtual ~GpuControlList();
44
45 // Loads control list information from a json file.
46 // If failed, the current GpuControlList is un-touched.
47 bool LoadList(const std::string& json_context, OsFilter os_filter);
48 bool LoadList(const std::string& browser_version_string,
49 const std::string& json_context, OsFilter os_filter);
50
51 // Collects system information and combines them with gpu_info and control
52 // list information to decide which entries are applied to the current
53 // system and returns the union of features specified in each entry.
54 // If os is kOsAny, use the current OS; if os_version is empty, use the
55 // current OS version.
56 int MakeDecision(
57 OsType os, std::string os_version, const GPUInfo& gpu_info);
58
59 // Collects the active entries from the last MakeDecision() call.
60 // If disabled set to true, return entries that are disabled; otherwise,
61 // return enabled entries.
62 void GetDecisionEntries(std::vector<uint32>* entry_ids,
63 bool disabled) const;
64
65 // Returns the description and bugs from active entries from the last
66 // MakeDecision() call.
67 //
68 // Each problems has:
69 // {
70 // "description": "Your GPU is too old",
71 // "crBugs": [1234],
72 // "webkitBugs": []
73 // }
74 void GetReasons(base::ListValue* problem_list) const;
75
76 // Return the largest entry id. This is used for histogramming.
77 uint32 max_entry_id() const;
78
79 // Returns the version of the current blacklist.
80 std::string GetVersion() const;
81
82 // Check if we need more gpu info to make the decisions.
83 // This is computed from the last MakeDecision() call.
84 // If yes, we should create a gl context and do a full gpu info collection.
85 bool needs_more_info() const { return needs_more_info_; }
86
87 // Check if any entries contain unknown fields. This is only for tests.
88 bool contains_unknown_fields() const { return contains_unknown_fields_; }
89
90 // Returns the number of entries. This is only for tests.
91 size_t num_entries() const;
92
93 // Register a feature to FeatureMap - used to construct a GpuControlList.
94 void AddFeature(const std::string& feature_name, int feature_id);
95
96 private:
97 enum BrowserVersionSupport {
98 kSupported,
99 kUnsupported,
100 kMalformed
101 };
102
103 enum NumericOp {
104 kBetween, // <= * <=
105 kEQ, // =
106 kLT, // <
107 kLE, // <=
108 kGT, // >
109 kGE, // >=
110 kAny,
111 kUnknown // Indicates the data is invalid.
112 };
113
114 class VersionInfo {
115 public:
116 // If version_style is empty, it defaults to kNumerical.
117 VersionInfo(const std::string& version_op,
118 const std::string& version_style,
119 const std::string& version_string,
120 const std::string& version_string2);
121 ~VersionInfo();
122
123 // Determines if a given version is included in the VersionInfo range.
124 // "splitter" divides version string into segments.
125 bool Contains(const std::string& version, char splitter) const;
126 // Same as above, using '.' as splitter.
127 bool Contains(const std::string& 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 // Compare two version strings.
145 // Return 1 if version > version_ref,
146 // 0 if version = version_ref,
147 // -1 if version < version_ref.
148 // Note that we only compare as many as segments as version_ref contains.
149 // If version_ref is xxx.yyy, it's considered as xxx.yyy.*
150 // For example: Compare("10.3.1", "10.3") returns 0,
151 // Compare("10.3", "10.3.1") returns -1.
152 // If "version_style" is Lexical, the first segment is compared
153 // numerically, all other segments are compared lexically.
154 // Lexical is used for AMD Linux driver versions only.
155 static int Compare(const std::vector<std::string>& version,
156 const std::vector<std::string>& version_ref,
157 VersionStyle version_style);
158
159 NumericOp op_;
160 VersionStyle version_style_;
161 std::vector<std::string> version_;
162 std::vector<std::string> version2_;
163 };
164
165 class OsInfo {
166 public:
167 OsInfo(const std::string& os,
168 const std::string& version_op,
169 const std::string& version_string,
170 const std::string& version_string2);
171 ~OsInfo();
172
173 // Determines if a given os/version is included in the OsInfo set.
174 bool Contains(OsType type, const std::string& version) const;
175
176 // Determines if the VersionInfo contains valid information.
177 bool IsValid() const;
178
179 OsType type() const;
180
181 // Maps string to OsType; returns kOsUnknown if it's not a valid os.
182 static OsType StringToOsType(const std::string& os);
183
184 private:
185 OsType type_;
186 scoped_ptr<VersionInfo> version_info_;
187 };
188
189 class StringInfo {
190 public:
191 StringInfo(const std::string& string_op, const std::string& string_value);
192
193 // Determines if a given string is included in the StringInfo.
194 bool Contains(const std::string& value) const;
195
196 // Determines if the StringInfo contains valid information.
197 bool IsValid() const;
198
199 private:
200 enum Op {
201 kContains,
202 kBeginWith,
203 kEndWith,
204 kEQ, // =
205 kUnknown // Indicates StringInfo data is invalid.
206 };
207
208 // Maps string to Op; returns kUnknown if it's not a valid Op.
209 static Op StringToOp(const std::string& string_op);
210
211 Op op_;
212 std::string value_;
213 };
214
215 class FloatInfo {
216 public:
217 FloatInfo(const std::string& float_op,
218 const std::string& float_value,
219 const std::string& float_value2);
220
221 // Determines if a given float is included in the FloatInfo.
222 bool Contains(float value) const;
223
224 // Determines if the FloatInfo contains valid information.
225 bool IsValid() const;
226
227 private:
228 NumericOp op_;
229 float value_;
230 float value2_;
231 };
232
233 class IntInfo {
234 public:
235 IntInfo(const std::string& int_op,
236 const std::string& int_value,
237 const std::string& int_value2);
238
239 // Determines if a given int is included in the IntInfo.
240 bool Contains(int value) const;
241
242 // Determines if the IntInfo contains valid information.
243 bool IsValid() const;
244
245 private:
246 NumericOp op_;
247 int value_;
248 int value2_;
249 };
250
251 class MachineModelInfo {
252 public:
253 MachineModelInfo(const std::string& name_op,
254 const std::string& name_value,
255 const std::string& version_op,
256 const std::string& version_string,
257 const std::string& version_string2);
258 ~MachineModelInfo();
259
260 // Determines if a given name/version is included in the MachineModelInfo.
261 bool Contains(const std::string& name, const std::string& version) const;
262
263 // Determines if the MachineModelInfo contains valid information.
264 bool IsValid() const;
265
266 private:
267 scoped_ptr<StringInfo> name_info_;
268 scoped_ptr<VersionInfo> version_info_;
269 };
270
271 class GpuControlListEntry;
272 typedef scoped_refptr<GpuControlListEntry> ScopedGpuControlListEntry;
273
274 typedef base::hash_map<std::string, int> FeatureMap;
275
276 class GpuControlListEntry : public base::RefCounted<GpuControlListEntry> {
277 public:
278 // Constructs GpuControlListEntry from DictionaryValue loaded from json.
279 // Top-level entry must have an id number. Others are exceptions.
280 static ScopedGpuControlListEntry GetEntryFromValue(
281 const base::DictionaryValue* value, bool top_level,
282 const FeatureMap& feature_map);
283
284 // Determines if a given os/gc/machine_model/driver is included in the
285 // Entry set.
286 bool Contains(OsType os_type, const std::string& os_version,
287 const GPUInfo& gpu_info) const;
288
289 // Determines whether we needs more gpu info to make the blacklisting
290 // decision. It should only be checked if Contains() returns true.
291 bool NeedsMoreInfo(const GPUInfo& gpu_info) const;
292
293 // Returns the OsType.
294 OsType GetOsType() const;
295
296 // Returns the entry's unique id. 0 is reserved.
297 uint32 id() const;
298
299 // Returns whether the entry is disabled.
300 bool disabled() const;
301
302 // Returns the description of the entry
303 const std::string& description() const { return description_; }
304
305 // Returns a list of Chromium and Webkit bugs applicable to this entry
306 const std::vector<int>& cr_bugs() const { return cr_bugs_; }
307 const std::vector<int>& webkit_bugs() const { return webkit_bugs_; }
308
309 // Returns the features.
310 int GetFeatures() const;
311
312 // Returns true if an unknown field is encountered.
313 bool contains_unknown_fields() const {
314 return contains_unknown_fields_;
315 }
316 // Returns true if an unknown blacklist feature is encountered.
317 bool contains_unknown_features() const {
318 return contains_unknown_features_;
319 }
320
321 private:
322 friend class base::RefCounted<GpuControlListEntry>;
323
324 enum MultiGpuStyle {
325 kMultiGpuStyleOptimus,
326 kMultiGpuStyleAMDSwitchable,
327 kMultiGpuStyleNone
328 };
329
330 enum MultiGpuCategory {
331 kMultiGpuCategoryPrimary,
332 kMultiGpuCategorySecondary,
333 kMultiGpuCategoryAny,
334 kMultiGpuCategoryNone
335 };
336
337 GpuControlListEntry();
338 ~GpuControlListEntry();
339
340 bool SetId(uint32 id);
341
342 void SetDisabled(bool disabled);
343
344 bool SetOsInfo(const std::string& os,
345 const std::string& version_op,
346 const std::string& version_string,
347 const std::string& version_string2);
348
349 bool SetVendorId(const std::string& vendor_id_string);
350
351 bool AddDeviceId(const std::string& device_id_string);
352
353 bool SetMultiGpuStyle(const std::string& multi_gpu_style_string);
354
355 bool SetMultiGpuCategory(const std::string& multi_gpu_category_string);
356
357 bool SetDriverVendorInfo(const std::string& vendor_op,
358 const std::string& vendor_value);
359
360 bool SetDriverVersionInfo(const std::string& version_op,
361 const std::string& version_style,
362 const std::string& version_string,
363 const std::string& version_string2);
364
365 bool SetDriverDateInfo(const std::string& date_op,
366 const std::string& date_string,
367 const std::string& date_string2);
368
369 bool SetGLVendorInfo(const std::string& vendor_op,
370 const std::string& vendor_value);
371
372 bool SetGLRendererInfo(const std::string& renderer_op,
373 const std::string& renderer_value);
374
375 bool SetCpuBrand(const std::string& cpu_op,
376 const std::string& cpu_value);
377
378 bool SetPerfGraphicsInfo(const std::string& op,
379 const std::string& float_string,
380 const std::string& float_string2);
381
382 bool SetPerfGamingInfo(const std::string& op,
383 const std::string& float_string,
384 const std::string& float_string2);
385
386 bool SetPerfOverallInfo(const std::string& op,
387 const std::string& float_string,
388 const std::string& float_string2);
389
390 bool SetMachineModelInfo(const std::string& name_op,
391 const std::string& name_value,
392 const std::string& version_op,
393 const std::string& version_string,
394 const std::string& version_string2);
395
396 bool SetGpuCountInfo(const std::string& op,
397 const std::string& int_string,
398 const std::string& int_string2);
399
400 bool SetFeatures(const std::vector<std::string>& features,
401 const FeatureMap& feature_map);
402
403 void AddException(ScopedGpuControlListEntry exception);
404
405 static MultiGpuStyle StringToMultiGpuStyle(const std::string& style);
406
407 static MultiGpuCategory StringToMultiGpuCategory(
408 const std::string& category);
409
410 // map a feature_name to feature_id. If the string is not a registered
411 // feature name, return false.
412 static bool StringToFeature(const std::string& feature_name,
413 int* feature_id,
414 const FeatureMap& feature_map);
415
416 uint32 id_;
417 bool disabled_;
418 std::string description_;
419 std::vector<int> cr_bugs_;
420 std::vector<int> webkit_bugs_;
421 scoped_ptr<OsInfo> os_info_;
422 uint32 vendor_id_;
423 std::vector<uint32> device_id_list_;
424 MultiGpuStyle multi_gpu_style_;
425 MultiGpuCategory multi_gpu_category_;
426 scoped_ptr<StringInfo> driver_vendor_info_;
427 scoped_ptr<VersionInfo> driver_version_info_;
428 scoped_ptr<VersionInfo> driver_date_info_;
429 scoped_ptr<StringInfo> gl_vendor_info_;
430 scoped_ptr<StringInfo> gl_renderer_info_;
431 scoped_ptr<StringInfo> cpu_brand_;
432 scoped_ptr<FloatInfo> perf_graphics_info_;
433 scoped_ptr<FloatInfo> perf_gaming_info_;
434 scoped_ptr<FloatInfo> perf_overall_info_;
435 scoped_ptr<MachineModelInfo> machine_model_info_;
436 scoped_ptr<IntInfo> gpu_count_info_;
437 int features_;
438 std::vector<ScopedGpuControlListEntry> exceptions_;
439 bool contains_unknown_fields_;
440 bool contains_unknown_features_;
441 };
442
443 // Gets the current OS type.
444 static OsType GetOsType();
445
446 bool LoadList(const base::DictionaryValue& parsed_json, OsFilter os_filter);
447
448 void Clear();
449
450 // Check if the entry is supported by the current version of browser.
451 // By default, if there is no browser version information in the entry,
452 // return kSupported;
453 BrowserVersionSupport IsEntrySupportedByCurrentBrowserVersion(
454 const base::DictionaryValue* value);
455
456 static NumericOp StringToNumericOp(const std::string& op);
457
458 std::string version_;
459 std::vector<ScopedGpuControlListEntry> feature_list_;
460
461 std::string browser_version_;
462
463 // This records all the blacklist entries that are appliable to the current
464 // user machine. It is updated everytime MakeBlacklistDecision() is
465 // called and is used later by GetDecisionEntries().
466 std::vector<ScopedGpuControlListEntry> active_entries_;
467
468 uint32 max_entry_id_;
469
470 bool contains_unknown_fields_;
471
472 bool needs_more_info_;
473
474 // The features a GpuControlList recognizes and handles.
475 FeatureMap feature_map_;
476 };
477
478 } // namespace content
479
480 #endif // CONTENT_BROWSER_GPU_GPU_CONTROL_LIST_H_
481
OLDNEW
« no previous file with comments | « content/browser/gpu/gpu_blacklist_unittest.cc ('k') | content/browser/gpu/gpu_control_list.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698