Remove invocation of WebSettings::setFontRenderingNormal, which is a no-op.
[chromium-blink-merge.git] / gpu / config / gpu_control_list.h
blob3e1f18216793c1f66eaf176c0af0057f31fed99d
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.
5 #ifndef GPU_CONFIG_GPU_CONTROL_LIST_H_
6 #define GPU_CONFIG_GPU_CONTROL_LIST_H_
8 #include <set>
9 #include <string>
10 #include <vector>
12 #include "base/basictypes.h"
13 #include "base/containers/hash_tables.h"
14 #include "base/gtest_prod_util.h"
15 #include "base/memory/ref_counted.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "base/values.h"
18 #include "build/build_config.h"
19 #include "gpu/gpu_export.h"
21 namespace gpu {
22 struct GPUInfo;
24 class GPU_EXPORT GpuControlList {
25 public:
26 enum OsType {
27 kOsLinux,
28 kOsMacosx,
29 kOsWin,
30 kOsChromeOS,
31 kOsAndroid,
32 kOsAny,
33 kOsUnknown
36 enum OsFilter {
37 // In loading, ignore all entries that belong to other OS.
38 kCurrentOsOnly,
39 // In loading, keep all entries. This is for testing only.
40 kAllOs
43 GpuControlList();
44 virtual ~GpuControlList();
46 // Loads control list information from a json file.
47 // If failed, the current GpuControlList is un-touched.
48 bool LoadList(const std::string& json_context, OsFilter os_filter);
49 bool LoadList(const std::string& browser_version_string,
50 const std::string& json_context, OsFilter os_filter);
52 // Collects system information and combines them with gpu_info and control
53 // list information to decide which entries are applied to the current
54 // system and returns the union of features specified in each entry.
55 // If os is kOsAny, use the current OS; if os_version is empty, use the
56 // current OS version.
57 std::set<int> MakeDecision(
58 OsType os, std::string os_version, const GPUInfo& gpu_info);
60 // Collects the active entries from the last MakeDecision() call.
61 // If disabled set to true, return entries that are disabled; otherwise,
62 // return enabled entries.
63 void GetDecisionEntries(std::vector<uint32>* entry_ids,
64 bool disabled) const;
66 // Returns the description and bugs from active entries from the last
67 // MakeDecision() call.
69 // Each problems has:
70 // {
71 // "description": "Your GPU is too old",
72 // "crBugs": [1234],
73 // "webkitBugs": []
74 // }
75 void GetReasons(base::ListValue* problem_list) const;
77 // Return the largest entry id. This is used for histogramming.
78 uint32 max_entry_id() const;
80 // Returns the version of the control list.
81 std::string version() const;
83 // Check if we need more gpu info to make the decisions.
84 // This is computed from the last MakeDecision() call.
85 // If yes, we should create a gl context and do a full gpu info collection.
86 bool needs_more_info() const { return needs_more_info_; }
88 // Check if any entries contain unknown fields. This is only for tests.
89 bool contains_unknown_fields() const { return contains_unknown_fields_; }
91 // Returns the number of entries. This is only for tests.
92 size_t num_entries() const;
94 // Register a feature to FeatureMap - used to construct a GpuControlList.
95 void AddSupportedFeature(const std::string& feature_name, int feature_id);
96 // Register whether "all" is recognized as all features.
97 void set_supports_feature_type_all(bool supported);
99 private:
100 friend class GpuControlListEntryTest;
101 friend class MachineModelInfoTest;
102 friend class NumberInfoTest;
103 friend class OsInfoTest;
104 friend class StringInfoTest;
105 friend class VersionInfoTest;
107 enum BrowserVersionSupport {
108 kSupported,
109 kUnsupported,
110 kMalformed
113 enum NumericOp {
114 kBetween, // <= * <=
115 kEQ, // =
116 kLT, // <
117 kLE, // <=
118 kGT, // >
119 kGE, // >=
120 kAny,
121 kUnknown // Indicates the data is invalid.
124 class GPU_EXPORT VersionInfo {
125 public:
126 // If version_style is empty, it defaults to kNumerical.
127 VersionInfo(const std::string& version_op,
128 const std::string& version_style,
129 const std::string& version_string,
130 const std::string& version_string2);
131 ~VersionInfo();
133 // Determines if a given version is included in the VersionInfo range.
134 // "splitter" divides version string into segments.
135 bool Contains(const std::string& version, char splitter) const;
136 // Same as above, using '.' as splitter.
137 bool Contains(const std::string& version) const;
139 // Determine if the version_style is lexical.
140 bool IsLexical() const;
142 // Determines if the VersionInfo contains valid information.
143 bool IsValid() const;
145 private:
146 enum VersionStyle {
147 kVersionStyleNumerical,
148 kVersionStyleLexical,
149 kVersionStyleUnknown
152 static VersionStyle StringToVersionStyle(const std::string& version_style);
154 // Compare two version strings.
155 // Return 1 if version > version_ref,
156 // 0 if version = version_ref,
157 // -1 if version < version_ref.
158 // Note that we only compare as many segments as both versions contain.
159 // For example: Compare("10.3.1", "10.3") returns 0,
160 // Compare("10.3", "10.3.1") returns 0.
161 // If "version_style" is Lexical, the first segment is compared
162 // numerically, all other segments are compared lexically.
163 // Lexical is used for AMD Linux driver versions only.
164 static int Compare(const std::vector<std::string>& version,
165 const std::vector<std::string>& version_ref,
166 VersionStyle version_style);
168 NumericOp op_;
169 VersionStyle version_style_;
170 std::vector<std::string> version_;
171 std::vector<std::string> version2_;
174 class GPU_EXPORT OsInfo {
175 public:
176 OsInfo(const std::string& os,
177 const std::string& version_op,
178 const std::string& version_string,
179 const std::string& version_string2);
180 ~OsInfo();
182 // Determines if a given os/version is included in the OsInfo set.
183 bool Contains(OsType type, const std::string& version) const;
185 // Determines if the VersionInfo contains valid information.
186 bool IsValid() const;
188 OsType type() const;
190 // Maps string to OsType; returns kOsUnknown if it's not a valid os.
191 static OsType StringToOsType(const std::string& os);
193 private:
194 OsType type_;
195 scoped_ptr<VersionInfo> version_info_;
198 class GPU_EXPORT StringInfo {
199 public:
200 StringInfo(const std::string& string_op, const std::string& string_value);
202 // Determines if a given string is included in the StringInfo.
203 bool Contains(const std::string& value) const;
205 // Determines if the StringInfo contains valid information.
206 bool IsValid() const;
208 private:
209 enum Op {
210 kContains,
211 kBeginWith,
212 kEndWith,
213 kEQ, // =
214 kUnknown // Indicates StringInfo data is invalid.
217 // Maps string to Op; returns kUnknown if it's not a valid Op.
218 static Op StringToOp(const std::string& string_op);
220 Op op_;
221 std::string value_;
224 class GPU_EXPORT FloatInfo {
225 public:
226 FloatInfo(const std::string& float_op,
227 const std::string& float_value,
228 const std::string& float_value2);
230 // Determines if a given float is included in the FloatInfo.
231 bool Contains(float value) const;
233 // Determines if the FloatInfo contains valid information.
234 bool IsValid() const;
236 private:
237 NumericOp op_;
238 float value_;
239 float value2_;
242 class GPU_EXPORT IntInfo {
243 public:
244 IntInfo(const std::string& int_op,
245 const std::string& int_value,
246 const std::string& int_value2);
248 // Determines if a given int is included in the IntInfo.
249 bool Contains(int value) const;
251 // Determines if the IntInfo contains valid information.
252 bool IsValid() const;
254 private:
255 NumericOp op_;
256 int value_;
257 int value2_;
260 class GPU_EXPORT MachineModelInfo {
261 public:
262 MachineModelInfo(const std::string& name_op,
263 const std::string& name_value,
264 const std::string& version_op,
265 const std::string& version_string,
266 const std::string& version_string2);
267 ~MachineModelInfo();
269 // Determines if a given name/version is included in the MachineModelInfo.
270 bool Contains(const std::string& name, const std::string& version) const;
272 // Determines if the MachineModelInfo contains valid information.
273 bool IsValid() const;
275 private:
276 scoped_ptr<StringInfo> name_info_;
277 scoped_ptr<VersionInfo> version_info_;
280 class GpuControlListEntry;
281 typedef scoped_refptr<GpuControlListEntry> ScopedGpuControlListEntry;
283 typedef base::hash_map<std::string, int> FeatureMap;
285 class GPU_EXPORT GpuControlListEntry
286 : public base::RefCounted<GpuControlListEntry> {
287 public:
288 // Constructs GpuControlListEntry from DictionaryValue loaded from json.
289 // Top-level entry must have an id number. Others are exceptions.
290 static ScopedGpuControlListEntry GetEntryFromValue(
291 const base::DictionaryValue* value, bool top_level,
292 const FeatureMap& feature_map,
293 bool supports_feature_type_all);
295 // Determines if a given os/gc/machine_model/driver is included in the
296 // Entry set.
297 bool Contains(OsType os_type, const std::string& os_version,
298 const GPUInfo& gpu_info) const;
300 // Determines whether we needs more gpu info to make the blacklisting
301 // decision. It should only be checked if Contains() returns true.
302 bool NeedsMoreInfo(const GPUInfo& gpu_info) const;
304 // Returns the OsType.
305 OsType GetOsType() const;
307 // Returns the entry's unique id. 0 is reserved.
308 uint32 id() const;
310 // Returns whether the entry is disabled.
311 bool disabled() const;
313 // Returns the description of the entry
314 const std::string& description() const { return description_; }
316 // Returns a list of Chromium and Webkit bugs applicable to this entry
317 const std::vector<int>& cr_bugs() const { return cr_bugs_; }
318 const std::vector<int>& webkit_bugs() const { return webkit_bugs_; }
320 // Returns the blacklisted features in this entry.
321 const std::set<int>& features() const;
323 // Returns true if an unknown field is encountered.
324 bool contains_unknown_fields() const {
325 return contains_unknown_fields_;
327 // Returns true if an unknown blacklist feature is encountered.
328 bool contains_unknown_features() const {
329 return contains_unknown_features_;
332 private:
333 friend class base::RefCounted<GpuControlListEntry>;
335 enum MultiGpuStyle {
336 kMultiGpuStyleOptimus,
337 kMultiGpuStyleAMDSwitchable,
338 kMultiGpuStyleNone
341 enum MultiGpuCategory {
342 kMultiGpuCategoryPrimary,
343 kMultiGpuCategorySecondary,
344 kMultiGpuCategoryAny,
345 kMultiGpuCategoryNone
348 GpuControlListEntry();
349 ~GpuControlListEntry();
351 bool SetId(uint32 id);
353 void SetDisabled(bool disabled);
355 bool SetOsInfo(const std::string& os,
356 const std::string& version_op,
357 const std::string& version_string,
358 const std::string& version_string2);
360 bool SetVendorId(const std::string& vendor_id_string);
362 bool AddDeviceId(const std::string& device_id_string);
364 bool SetMultiGpuStyle(const std::string& multi_gpu_style_string);
366 bool SetMultiGpuCategory(const std::string& multi_gpu_category_string);
368 bool SetDriverVendorInfo(const std::string& vendor_op,
369 const std::string& vendor_value);
371 bool SetDriverVersionInfo(const std::string& version_op,
372 const std::string& version_style,
373 const std::string& version_string,
374 const std::string& version_string2);
376 bool SetDriverDateInfo(const std::string& date_op,
377 const std::string& date_string,
378 const std::string& date_string2);
380 bool SetGLVendorInfo(const std::string& vendor_op,
381 const std::string& vendor_value);
383 bool SetGLRendererInfo(const std::string& renderer_op,
384 const std::string& renderer_value);
386 bool SetGLExtensionsInfo(const std::string& extensions_op,
387 const std::string& extensions_value);
389 bool SetCpuBrand(const std::string& cpu_op,
390 const std::string& cpu_value);
392 bool SetPerfGraphicsInfo(const std::string& op,
393 const std::string& float_string,
394 const std::string& float_string2);
396 bool SetPerfGamingInfo(const std::string& op,
397 const std::string& float_string,
398 const std::string& float_string2);
400 bool SetPerfOverallInfo(const std::string& op,
401 const std::string& float_string,
402 const std::string& float_string2);
404 bool SetMachineModelInfo(const std::string& name_op,
405 const std::string& name_value,
406 const std::string& version_op,
407 const std::string& version_string,
408 const std::string& version_string2);
410 bool SetGpuCountInfo(const std::string& op,
411 const std::string& int_string,
412 const std::string& int_string2);
414 bool SetFeatures(const std::vector<std::string>& features,
415 const FeatureMap& feature_map,
416 bool supports_feature_type_all);
418 void AddException(ScopedGpuControlListEntry exception);
420 static MultiGpuStyle StringToMultiGpuStyle(const std::string& style);
422 static MultiGpuCategory StringToMultiGpuCategory(
423 const std::string& category);
425 // map a feature_name to feature_id. If the string is not a registered
426 // feature name, return false.
427 static bool StringToFeature(const std::string& feature_name,
428 int* feature_id,
429 const FeatureMap& feature_map);
431 uint32 id_;
432 bool disabled_;
433 std::string description_;
434 std::vector<int> cr_bugs_;
435 std::vector<int> webkit_bugs_;
436 scoped_ptr<OsInfo> os_info_;
437 uint32 vendor_id_;
438 std::vector<uint32> device_id_list_;
439 MultiGpuStyle multi_gpu_style_;
440 MultiGpuCategory multi_gpu_category_;
441 scoped_ptr<StringInfo> driver_vendor_info_;
442 scoped_ptr<VersionInfo> driver_version_info_;
443 scoped_ptr<VersionInfo> driver_date_info_;
444 scoped_ptr<StringInfo> gl_vendor_info_;
445 scoped_ptr<StringInfo> gl_renderer_info_;
446 scoped_ptr<StringInfo> gl_extensions_info_;
447 scoped_ptr<StringInfo> cpu_brand_;
448 scoped_ptr<FloatInfo> perf_graphics_info_;
449 scoped_ptr<FloatInfo> perf_gaming_info_;
450 scoped_ptr<FloatInfo> perf_overall_info_;
451 scoped_ptr<MachineModelInfo> machine_model_info_;
452 scoped_ptr<IntInfo> gpu_count_info_;
453 std::set<int> features_;
454 std::vector<ScopedGpuControlListEntry> exceptions_;
455 bool contains_unknown_fields_;
456 bool contains_unknown_features_;
459 // Gets the current OS type.
460 static OsType GetOsType();
462 bool LoadList(const base::DictionaryValue& parsed_json, OsFilter os_filter);
464 void Clear();
466 // Check if the entry is supported by the current version of browser.
467 // By default, if there is no browser version information in the entry,
468 // return kSupported;
469 BrowserVersionSupport IsEntrySupportedByCurrentBrowserVersion(
470 const base::DictionaryValue* value);
472 static NumericOp StringToNumericOp(const std::string& op);
474 std::string version_;
475 std::vector<ScopedGpuControlListEntry> entries_;
477 std::string browser_version_;
479 // This records all the blacklist entries that are appliable to the current
480 // user machine. It is updated everytime MakeDecision() is called and is
481 // used later by GetDecisionEntries().
482 std::vector<ScopedGpuControlListEntry> active_entries_;
484 uint32 max_entry_id_;
486 bool contains_unknown_fields_;
488 bool needs_more_info_;
490 // The features a GpuControlList recognizes and handles.
491 FeatureMap feature_map_;
492 bool supports_feature_type_all_;
495 } // namespace gpu
497 #endif // GPU_CONFIG_GPU_CONTROL_LIST_H_