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_
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"
24 class GPU_EXPORT GpuControlList
{
37 // In loading, ignore all entries that belong to other OS.
39 // In loading, keep all entries. This is for testing only.
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
);
50 // Collects system information and combines them with gpu_info and control
51 // list information to decide which entries are applied to the current
52 // system and returns the union of features specified in each entry.
53 // If os is kOsAny, use the current OS; if os_version is empty, use the
54 // current OS version.
55 std::set
<int> MakeDecision(
56 OsType os
, std::string os_version
, const GPUInfo
& gpu_info
);
58 // Collects the active entries from the last MakeDecision() call.
59 // If disabled set to true, return entries that are disabled; otherwise,
60 // return enabled entries.
61 void GetDecisionEntries(std::vector
<uint32
>* entry_ids
,
64 // Collects all disabled extensions.
65 std::vector
<std::string
> GetDisabledExtensions();
67 // Returns the description and bugs from active entries from the last
68 // MakeDecision() call.
72 // "description": "Your GPU is too old",
77 base::ListValue
* problem_list
, const std::string
& tag
) const;
79 // Return the largest entry id. This is used for histogramming.
80 uint32
max_entry_id() const;
82 // Returns the version of the control list.
83 std::string
version() const;
85 // Check if we need more gpu info to make the decisions.
86 // This is computed from the last MakeDecision() call.
87 // If yes, we should create a gl context and do a full gpu info collection.
88 bool needs_more_info() const { return needs_more_info_
; }
90 // Returns the number of entries. This is only for tests.
91 size_t num_entries() const;
93 // Register a feature to FeatureMap - used to construct a GpuControlList.
94 void AddSupportedFeature(const std::string
& feature_name
, int feature_id
);
95 // Register whether "all" is recognized as all features.
96 void set_supports_feature_type_all(bool supported
);
98 // Enables logging of control list decisions.
99 void enable_control_list_logging(
100 const std::string
& control_list_logging_name
) {
101 control_list_logging_enabled_
= true;
102 control_list_logging_name_
= control_list_logging_name
;
106 friend class GpuControlListEntryTest
;
107 friend class MachineModelInfoTest
;
108 friend class NumberInfoTest
;
109 friend class OsInfoTest
;
110 friend class StringInfoTest
;
111 friend class VersionInfoTest
;
121 kUnknown
// Indicates the data is invalid.
124 class GPU_EXPORT VersionInfo
{
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
);
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;
147 kVersionStyleNumerical
,
148 kVersionStyleLexical
,
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
);
169 VersionStyle version_style_
;
170 std::vector
<std::string
> version_
;
171 std::vector
<std::string
> version2_
;
174 class GPU_EXPORT OsInfo
{
176 OsInfo(const std::string
& os
,
177 const std::string
& version_op
,
178 const std::string
& version_string
,
179 const std::string
& version_string2
);
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;
190 // Maps string to OsType; returns kOsUnknown if it's not a valid os.
191 static OsType
StringToOsType(const std::string
& os
);
195 scoped_ptr
<VersionInfo
> version_info_
;
198 class GPU_EXPORT FloatInfo
{
200 FloatInfo(const std::string
& float_op
,
201 const std::string
& float_value
,
202 const std::string
& float_value2
);
204 // Determines if a given float is included in the FloatInfo.
205 bool Contains(float value
) const;
207 // Determines if the FloatInfo contains valid information.
208 bool IsValid() const;
216 class GPU_EXPORT IntInfo
{
218 IntInfo(const std::string
& int_op
,
219 const std::string
& int_value
,
220 const std::string
& int_value2
);
222 // Determines if a given int is included in the IntInfo.
223 bool Contains(int value
) const;
225 // Determines if the IntInfo contains valid information.
226 bool IsValid() const;
234 class GPU_EXPORT BoolInfo
{
236 explicit BoolInfo(bool value
);
238 // Determines if a given bool is included in the BoolInfo.
239 bool Contains(bool value
) const;
245 class GpuControlListEntry
;
246 typedef scoped_refptr
<GpuControlListEntry
> ScopedGpuControlListEntry
;
248 typedef base::hash_map
<std::string
, int> FeatureMap
;
250 class GPU_EXPORT GpuControlListEntry
251 : public base::RefCounted
<GpuControlListEntry
> {
253 // Constructs GpuControlListEntry from DictionaryValue loaded from json.
254 // Top-level entry must have an id number. Others are exceptions.
255 static ScopedGpuControlListEntry
GetEntryFromValue(
256 const base::DictionaryValue
* value
, bool top_level
,
257 const FeatureMap
& feature_map
,
258 bool supports_feature_type_all
);
260 // Logs a control list match for this rule in the list identified by
261 // |control_list_logging_name|.
262 void LogControlListMatch(
263 const std::string
& control_list_logging_name
) const;
265 // Determines if a given os/gc/machine_model/driver is included in the
267 bool Contains(OsType os_type
, const std::string
& os_version
,
268 const GPUInfo
& gpu_info
) const;
270 // Determines whether we needs more gpu info to make the blacklisting
271 // decision. It should only be checked if Contains() returns true.
272 bool NeedsMoreInfo(const GPUInfo
& gpu_info
, bool consider_exceptions
) const;
274 // Returns the OsType.
275 OsType
GetOsType() const;
277 // Returns the entry's unique id. 0 is reserved.
280 // Returns whether the entry is disabled.
281 bool disabled() const;
283 // Returns the description of the entry
284 const std::string
& description() const { return description_
; }
286 // Returns a list of Chromium and Webkit bugs applicable to this entry
287 const std::vector
<int>& cr_bugs() const { return cr_bugs_
; }
288 const std::vector
<int>& webkit_bugs() const { return webkit_bugs_
; }
289 const std::vector
<std::string
>& disabled_extensions() const {
290 return disabled_extensions_
;
293 // Returns the blacklisted features in this entry.
294 const std::set
<int>& features() const;
296 // Returns a list of blacklisted feature names in this entry.
297 void GetFeatureNames(base::ListValue
* feature_names
,
298 const FeatureMap
& feature_map
,
299 bool supports_feature_type_all
) const;
302 friend class base::RefCounted
<GpuControlListEntry
>;
305 kMultiGpuStyleOptimus
,
306 kMultiGpuStyleAMDSwitchable
,
307 kMultiGpuStyleAMDSwitchableIntegrated
,
308 kMultiGpuStyleAMDSwitchableDiscrete
,
312 enum MultiGpuCategory
{
313 // This entry applies if this is the primary GPU on the system.
314 kMultiGpuCategoryPrimary
,
315 // This entry applies if this is a secondary GPU on the system.
316 kMultiGpuCategorySecondary
,
317 // This entry applies if this is the active GPU on the system.
318 kMultiGpuCategoryActive
,
319 // This entry applies if this is any of the GPUs on the system.
320 kMultiGpuCategoryAny
,
321 kMultiGpuCategoryNone
325 kGLTypeGL
, // This is default on MacOSX, Linux, ChromeOS
326 kGLTypeGLES
, // This is default on Android
327 kGLTypeANGLE
, // This is default on Windows
331 GpuControlListEntry();
332 ~GpuControlListEntry();
334 bool SetId(uint32 id
);
336 void SetDisabled(bool disabled
);
338 bool SetOsInfo(const std::string
& os
,
339 const std::string
& version_op
,
340 const std::string
& version_string
,
341 const std::string
& version_string2
);
343 bool SetVendorId(const std::string
& vendor_id_string
);
345 bool AddDeviceId(const std::string
& device_id_string
);
347 bool SetMultiGpuStyle(const std::string
& multi_gpu_style_string
);
349 bool SetMultiGpuCategory(const std::string
& multi_gpu_category_string
);
351 bool SetGLType(const std::string
& gl_type_string
);
353 bool SetDriverVendorInfo(const std::string
& vendor_value
);
355 bool SetDriverVersionInfo(const std::string
& version_op
,
356 const std::string
& version_style
,
357 const std::string
& version_string
,
358 const std::string
& version_string2
);
360 bool SetDriverDateInfo(const std::string
& date_op
,
361 const std::string
& date_string
,
362 const std::string
& date_string2
);
364 bool SetGLVersionInfo(const std::string
& version_op
,
365 const std::string
& version_string
,
366 const std::string
& version_string2
);
368 bool SetGLVendorInfo(const std::string
& vendor_value
);
370 bool SetGLRendererInfo(const std::string
& renderer_value
);
372 bool SetGLExtensionsInfo(const std::string
& extensions_value
);
374 bool SetGLResetNotificationStrategyInfo(const std::string
& op
,
375 const std::string
& int_string
,
376 const std::string
& int_string2
);
378 bool SetCpuBrand(const std::string
& cpu_value
);
380 bool SetPerfGraphicsInfo(const std::string
& op
,
381 const std::string
& float_string
,
382 const std::string
& float_string2
);
384 bool SetPerfGamingInfo(const std::string
& op
,
385 const std::string
& float_string
,
386 const std::string
& float_string2
);
388 bool SetPerfOverallInfo(const std::string
& op
,
389 const std::string
& float_string
,
390 const std::string
& float_string2
);
392 bool AddMachineModelName(const std::string
& model_name
);
394 bool SetMachineModelVersionInfo(const std::string
& version_op
,
395 const std::string
& version_string
,
396 const std::string
& version_string2
);
398 bool SetGpuCountInfo(const std::string
& op
,
399 const std::string
& int_string
,
400 const std::string
& int_string2
);
402 void SetDirectRenderingInfo(bool value
);
404 bool SetFeatures(const std::vector
<std::string
>& features
,
405 const FeatureMap
& feature_map
,
406 bool supports_feature_type_all
);
408 void AddException(ScopedGpuControlListEntry exception
);
410 // Return true if GL_VERSION string does not fit the entry info
411 // on GL type and GL version.
412 bool GLVersionInfoMismatch(const std::string
& gl_version
) const;
414 static MultiGpuStyle
StringToMultiGpuStyle(const std::string
& style
);
416 static MultiGpuCategory
StringToMultiGpuCategory(
417 const std::string
& category
);
419 static GLType
StringToGLType(const std::string
& gl_type
);
421 // map a feature_name to feature_id. If the string is not a registered
422 // feature name, return false.
423 static bool StringToFeature(const std::string
& feature_name
,
425 const FeatureMap
& feature_map
);
427 // Return the default GL type, depending on the OS.
428 // See GLType declaration.
429 static GLType
GetDefaultGLType();
433 std::string description_
;
434 std::vector
<int> cr_bugs_
;
435 std::vector
<int> webkit_bugs_
;
436 std::vector
<std::string
> disabled_extensions_
;
437 scoped_ptr
<OsInfo
> os_info_
;
439 std::vector
<uint32
> device_id_list_
;
440 MultiGpuStyle multi_gpu_style_
;
441 MultiGpuCategory multi_gpu_category_
;
443 std::string driver_vendor_info_
;
444 scoped_ptr
<VersionInfo
> driver_version_info_
;
445 scoped_ptr
<VersionInfo
> driver_date_info_
;
446 scoped_ptr
<VersionInfo
> gl_version_info_
;
447 std::string gl_vendor_info_
;
448 std::string gl_renderer_info_
;
449 std::string gl_extensions_info_
;
450 scoped_ptr
<IntInfo
> gl_reset_notification_strategy_info_
;
451 std::string cpu_brand_
;
452 scoped_ptr
<FloatInfo
> perf_graphics_info_
;
453 scoped_ptr
<FloatInfo
> perf_gaming_info_
;
454 scoped_ptr
<FloatInfo
> perf_overall_info_
;
455 std::vector
<std::string
> machine_model_name_list_
;
456 scoped_ptr
<VersionInfo
> machine_model_version_info_
;
457 scoped_ptr
<IntInfo
> gpu_count_info_
;
458 scoped_ptr
<BoolInfo
> direct_rendering_info_
;
459 std::set
<int> features_
;
460 std::vector
<ScopedGpuControlListEntry
> exceptions_
;
463 // Gets the current OS type.
464 static OsType
GetOsType();
466 bool LoadList(const base::DictionaryValue
& parsed_json
, OsFilter os_filter
);
470 static NumericOp
StringToNumericOp(const std::string
& op
);
472 std::string version_
;
473 std::vector
<ScopedGpuControlListEntry
> entries_
;
475 // This records all the blacklist entries that are appliable to the current
476 // user machine. It is updated everytime MakeDecision() is called and is
477 // used later by GetDecisionEntries().
478 std::vector
<ScopedGpuControlListEntry
> active_entries_
;
480 uint32 max_entry_id_
;
482 bool needs_more_info_
;
484 // The features a GpuControlList recognizes and handles.
485 FeatureMap feature_map_
;
486 bool supports_feature_type_all_
;
488 bool control_list_logging_enabled_
;
489 std::string control_list_logging_name_
;
494 #endif // GPU_CONFIG_GPU_CONTROL_LIST_H_