Index: gpu/config/gpu_control_list.h |
diff --git a/gpu/config/gpu_control_list.h b/gpu/config/gpu_control_list.h |
index 3158e1bb37213a3f7014fa741e9881b6a6bbd55b..46199f41562ca1982f82969c1fd5fd41386e357a 100644 |
--- a/gpu/config/gpu_control_list.h |
+++ b/gpu/config/gpu_control_list.h |
@@ -6,33 +6,24 @@ |
#define GPU_CONFIG_GPU_CONTROL_LIST_H_ |
#include <stddef.h> |
-#include <stdint.h> |
-#include <memory> |
#include <set> |
#include <string> |
#include <vector> |
#include "base/containers/hash_tables.h" |
-#include "base/memory/ref_counted.h" |
#include "base/values.h" |
-#include "build/build_config.h" |
#include "gpu/gpu_export.h" |
namespace gpu { |
+struct GpuControlListData; |
struct GPUInfo; |
class GPU_EXPORT GpuControlList { |
public: |
- enum OsType { |
- kOsLinux, |
- kOsMacosx, |
- kOsWin, |
- kOsChromeOS, |
- kOsAndroid, |
- kOsAny, |
- kOsUnknown |
- }; |
+ typedef base::hash_map<int, std::string> FeatureMap; |
+ |
+ enum OsType { kOsLinux, kOsMacosx, kOsWin, kOsChromeOS, kOsAndroid, kOsAny }; |
enum OsFilter { |
// In loading, ignore all entries that belong to other OS. |
@@ -41,79 +32,6 @@ class GPU_EXPORT GpuControlList { |
kAllOs |
}; |
- GpuControlList(); |
- virtual ~GpuControlList(); |
- |
- // Loads control list information from a json file. |
- // If failed, the current GpuControlList is un-touched. |
- bool LoadList(const std::string& json_context, OsFilter os_filter); |
- |
- // Collects system information and combines them with gpu_info and control |
- // list information to decide which entries are applied to the current |
- // system and returns the union of features specified in each entry. |
- // If os is kOsAny, use the current OS; if os_version is empty, use the |
- // current OS version. |
- std::set<int> MakeDecision( |
- OsType os, std::string os_version, const GPUInfo& gpu_info); |
- |
- // Collects the active entries from the last MakeDecision() call. |
- // If disabled set to true, return entries that are disabled; otherwise, |
- // return enabled entries. |
- void GetDecisionEntries(std::vector<uint32_t>* entry_ids, |
- bool disabled) const; |
- |
- // Collects all disabled extensions. |
- std::vector<std::string> GetDisabledExtensions(); |
- |
- // Returns the description and bugs from active entries from the last |
- // MakeDecision() call. |
- // |
- // Each problems has: |
- // { |
- // "description": "Your GPU is too old", |
- // "crBugs": [1234], |
- // "webkitBugs": [] |
- // } |
- void GetReasons( |
- base::ListValue* problem_list, const std::string& tag) const; |
- |
- // Return the largest entry id. This is used for histogramming. |
- uint32_t max_entry_id() const; |
- |
- // Returns the version of the control list. |
- std::string version() const; |
- |
- // Check if we need more gpu info to make the decisions. |
- // This is computed from the last MakeDecision() call. |
- // If yes, we should create a gl context and do a full gpu info collection. |
- bool needs_more_info() const { return needs_more_info_; } |
- |
- // Returns the number of entries. This is only for tests. |
- size_t num_entries() const; |
- |
- // This is only for tests. |
- bool has_duplicated_entry_id() const; |
- |
- // Register a feature to FeatureMap - used to construct a GpuControlList. |
- void AddSupportedFeature(const std::string& feature_name, int feature_id); |
- // Register whether "all" is recognized as all features. |
- void set_supports_feature_type_all(bool supported); |
- |
- // Enables logging of control list decisions. |
- void enable_control_list_logging( |
- const std::string& control_list_logging_name) { |
- control_list_logging_enabled_ = true; |
- control_list_logging_name_ = control_list_logging_name; |
- } |
- |
- private: |
- friend class GpuControlListEntryTest; |
- friend class MachineModelInfoTest; |
- friend class NumberInfoTest; |
- friend class OsInfoTest; |
- friend class StringInfoTest; |
- friend class VersionInfoTest; |
- |
enum NumericOp { |
kBetween, // <= * <= |
kEQ, // = |
@@ -125,35 +43,52 @@ class GPU_EXPORT GpuControlList { |
kUnknown // Indicates the data is invalid. |
}; |
- class GPU_EXPORT VersionInfo { |
- public: |
- // If version_style is empty, it defaults to kNumerical. |
- VersionInfo(const std::string& version_op, |
- const std::string& version_style, |
- const std::string& version_string, |
- const std::string& version_string2); |
- ~VersionInfo(); |
+ enum MultiGpuStyle { |
+ kMultiGpuStyleOptimus, |
+ kMultiGpuStyleAMDSwitchable, |
+ kMultiGpuStyleAMDSwitchableIntegrated, |
+ kMultiGpuStyleAMDSwitchableDiscrete, |
+ kMultiGpuStyleNone |
+ }; |
- // Determines if a given version is included in the VersionInfo range. |
- // "splitter" divides version string into segments. |
- bool Contains(const std::string& version, char splitter) const; |
- // Same as above, using '.' as splitter. |
- bool Contains(const std::string& version) const; |
+ enum MultiGpuCategory { |
+ // This entry applies if this is the primary GPU on the system. |
+ kMultiGpuCategoryPrimary, |
+ // This entry applies if this is a secondary GPU on the system. |
+ kMultiGpuCategorySecondary, |
+ // This entry applies if this is the active GPU on the system. |
+ kMultiGpuCategoryActive, |
+ // This entry applies if this is any of the GPUs on the system. |
+ kMultiGpuCategoryAny, |
+ kMultiGpuCategoryNone |
+ }; |
- // Determine if the version_style is lexical. |
- bool IsLexical() const; |
+ enum GLType { |
+ kGLTypeGL, // This is default on MacOSX, Linux, ChromeOS |
+ kGLTypeGLES, // This is default on Android |
+ kGLTypeANGLE, // This is default on Windows |
+ kGLTypeNone |
+ }; |
- // Determines if the VersionInfo contains valid information. |
- bool IsValid() const; |
+ enum VersionStyle { |
+ kVersionStyleNumerical, |
+ kVersionStyleLexical, |
+ kVersionStyleUnknown |
+ }; |
+ |
+ struct GPU_EXPORT Version { |
+ NumericOp op; |
+ VersionStyle style; |
+ const char* value1; |
+ const char* value2; |
- private: |
- enum VersionStyle { |
- kVersionStyleNumerical, |
- kVersionStyleLexical, |
- kVersionStyleUnknown |
- }; |
+ bool IsSpecified() const { return op != kUnknown; } |
- static VersionStyle StringToVersionStyle(const std::string& version_style); |
+ bool Contains(const std::string& version_string, char splitter) const; |
+ |
+ bool Contains(const std::string& version_string) const { |
+ return Contains(version_string, '.'); |
+ } |
// Compare two version strings. |
// Return 1 if version > version_ref, |
@@ -168,329 +103,172 @@ class GPU_EXPORT GpuControlList { |
static int Compare(const std::vector<std::string>& version, |
const std::vector<std::string>& version_ref, |
VersionStyle version_style); |
- |
- NumericOp op_; |
- VersionStyle version_style_; |
- std::vector<std::string> version_; |
- std::vector<std::string> version2_; |
}; |
- class GPU_EXPORT OsInfo { |
- public: |
- OsInfo(const std::string& os, |
- const std::string& version_op, |
- const std::string& version_string, |
- const std::string& version_string2); |
- ~OsInfo(); |
+ struct GPU_EXPORT DriverInfo { |
+ const char* driver_vendor; |
+ Version driver_version; |
+ Version driver_date; |
- // Determines if a given os/version is included in the OsInfo set. |
- bool Contains(OsType type, const std::string& version) const; |
- |
- // Determines if the VersionInfo contains valid information. |
- bool IsValid() const; |
- |
- OsType type() const; |
- |
- // Maps string to OsType; returns kOsUnknown if it's not a valid os. |
- static OsType StringToOsType(const std::string& os); |
- |
- private: |
- OsType type_; |
- std::unique_ptr<VersionInfo> version_info_; |
+ bool Contains(const GPUInfo& gpu_info) const; |
}; |
- class GPU_EXPORT FloatInfo { |
- public: |
- FloatInfo(const std::string& float_op, |
- const std::string& float_value, |
- const std::string& float_value2); |
+ struct GPU_EXPORT GLStrings { |
+ const char* gl_vendor; |
+ const char* gl_renderer; |
+ const char* gl_extensions; |
+ const char* gl_version; |
- // Determines if a given float is included in the FloatInfo. |
- bool Contains(float value) const; |
+ bool Contains(const GPUInfo& gpu_info) const; |
+ }; |
- // Determines if the FloatInfo contains valid information. |
- bool IsValid() const; |
+ struct GPU_EXPORT MachineModelInfo { |
+ size_t machine_model_name_size; |
+ const char** machine_model_names; |
+ Version machine_model_version; |
- private: |
- NumericOp op_; |
- float value_; |
- float value2_; |
+ bool Contains(const GPUInfo& gpu_info) const; |
}; |
- class GPU_EXPORT IntInfo { |
- public: |
- IntInfo(const std::string& int_op, |
- const std::string& int_value, |
- const std::string& int_value2); |
+ struct GPU_EXPORT More { |
+ // These are just part of Entry fields that are less common. |
+ // Putting them to a separate struct to save Entry data size. |
+ GLType gl_type; |
+ Version gl_version; |
+ Version pixel_shader_version; |
+ bool in_process_gpu; |
+ uint32_t gl_reset_notification_strategy; |
+ bool direct_rendering; |
+ Version gpu_count; |
- // Determines if a given int is included in the IntInfo. |
- bool Contains(int value) const; |
+ // Return true if GL_VERSION string does not fit the entry info |
+ // on GL type and GL version. |
+ bool GLVersionInfoMismatch(const std::string& gl_version_string) const; |
- // Determines if the IntInfo contains valid information. |
- bool IsValid() const; |
+ bool Contains(const GPUInfo& gpu_info) const; |
- private: |
- NumericOp op_; |
- int value_; |
- int value2_; |
+ // Return the default GL type, depending on the OS. |
+ // See GLType declaration. |
+ static GLType GetDefaultGLType(); |
}; |
- class GPU_EXPORT BoolInfo { |
- public: |
- explicit BoolInfo(bool value); |
- |
- // Determines if a given bool is included in the BoolInfo. |
- bool Contains(bool value) const; |
+ struct GPU_EXPORT Conditions { |
+ OsType os_type; |
+ Version os_version; |
+ uint32_t vendor_id; |
+ size_t device_id_size; |
+ const uint32_t* device_ids; |
+ MultiGpuCategory multi_gpu_category; |
+ MultiGpuStyle multi_gpu_style; |
+ const DriverInfo* driver_info; |
+ const GLStrings* gl_strings; |
+ const MachineModelInfo* machine_model_info; |
+ const More* more; |
+ |
+ bool Contains(OsType os_type, |
+ const std::string& os_version, |
+ const GPUInfo& gpu_info) const; |
- private: |
- bool value_; |
+ // Determines whether we needs more gpu info to make the blacklisting |
+ // decision. It should only be checked if Contains() returns true. |
+ bool NeedsMoreInfo(const GPUInfo& gpu_info) const; |
}; |
- class GpuControlListEntry; |
- typedef scoped_refptr<GpuControlListEntry> ScopedGpuControlListEntry; |
- |
- typedef base::hash_map<std::string, int> FeatureMap; |
- |
- class GPU_EXPORT GpuControlListEntry |
- : public base::RefCounted<GpuControlListEntry> { |
- public: |
- // Constructs GpuControlListEntry from DictionaryValue loaded from json. |
- // Top-level entry must have an id number. Others are exceptions. |
- static ScopedGpuControlListEntry GetEntryFromValue( |
- const base::DictionaryValue* value, bool top_level, |
- const FeatureMap& feature_map, |
- bool supports_feature_type_all); |
- |
- // Logs a control list match for this rule in the list identified by |
- // |control_list_logging_name|. |
- void LogControlListMatch( |
- const std::string& control_list_logging_name) const; |
- |
- // Determines if a given os/gc/machine_model/driver is included in the |
- // Entry set. |
- bool Contains(OsType os_type, const std::string& os_version, |
+ struct GPU_EXPORT Entry { |
+ uint32_t id; |
+ const char* description; |
+ size_t feature_size; |
+ const int* features; |
+ size_t disabled_extension_size; |
+ const char** disabled_extensions; |
+ size_t cr_bug_size; |
+ const uint32_t* cr_bugs; |
+ Conditions conditions; |
+ size_t exception_size; |
+ const Conditions* exceptions; |
+ |
+ bool Contains(OsType os_type, |
+ const std::string& os_version, |
const GPUInfo& gpu_info) const; |
// Determines whether we needs more gpu info to make the blacklisting |
// decision. It should only be checked if Contains() returns true. |
bool NeedsMoreInfo(const GPUInfo& gpu_info, bool consider_exceptions) const; |
- // Returns the OsType. |
- OsType GetOsType() const; |
- |
- // Returns the entry's unique id. 0 is reserved. |
- uint32_t id() const; |
- |
- // Returns whether the entry is disabled. |
- bool disabled() const; |
- |
- // Returns the description of the entry |
- const std::string& description() const { return description_; } |
- |
- // Returns a list of Chromium and Webkit bugs applicable to this entry |
- const std::vector<int>& cr_bugs() const { return cr_bugs_; } |
- const std::vector<int>& webkit_bugs() const { return webkit_bugs_; } |
- const std::vector<std::string>& disabled_extensions() const { |
- return disabled_extensions_; |
- } |
- |
- // Returns the blacklisted features in this entry. |
- const std::set<int>& features() const; |
- |
- // Returns a list of blacklisted feature names in this entry. |
void GetFeatureNames(base::ListValue* feature_names, |
- const FeatureMap& feature_map, |
- bool supports_feature_type_all) const; |
- |
- private: |
- friend class base::RefCounted<GpuControlListEntry>; |
- |
- enum MultiGpuStyle { |
- kMultiGpuStyleOptimus, |
- kMultiGpuStyleAMDSwitchable, |
- kMultiGpuStyleAMDSwitchableIntegrated, |
- kMultiGpuStyleAMDSwitchableDiscrete, |
- kMultiGpuStyleNone |
- }; |
- |
- enum MultiGpuCategory { |
- // This entry applies if this is the primary GPU on the system. |
- kMultiGpuCategoryPrimary, |
- // This entry applies if this is a secondary GPU on the system. |
- kMultiGpuCategorySecondary, |
- // This entry applies if this is the active GPU on the system. |
- kMultiGpuCategoryActive, |
- // This entry applies if this is any of the GPUs on the system. |
- kMultiGpuCategoryAny, |
- kMultiGpuCategoryNone |
- }; |
- |
- enum GLType { |
- kGLTypeGL, // This is default on MacOSX, Linux, ChromeOS |
- kGLTypeGLES, // This is default on Android |
- kGLTypeANGLE, // This is default on Windows |
- kGLTypeNone |
- }; |
- |
- GpuControlListEntry(); |
- ~GpuControlListEntry(); |
- |
- bool SetId(uint32_t id); |
- |
- void SetDisabled(bool disabled); |
- |
- bool SetOsInfo(const std::string& os, |
- const std::string& version_op, |
- const std::string& version_string, |
- const std::string& version_string2); |
- |
- bool SetVendorId(const std::string& vendor_id_string); |
- |
- bool AddDeviceId(const std::string& device_id_string); |
- |
- bool SetMultiGpuStyle(const std::string& multi_gpu_style_string); |
- |
- bool SetMultiGpuCategory(const std::string& multi_gpu_category_string); |
- |
- bool SetGLType(const std::string& gl_type_string); |
- |
- bool SetDriverVendorInfo(const std::string& vendor_value); |
- |
- bool SetDriverVersionInfo(const std::string& version_op, |
- const std::string& version_style, |
- const std::string& version_string, |
- const std::string& version_string2); |
- |
- bool SetDriverDateInfo(const std::string& date_op, |
- const std::string& date_string, |
- const std::string& date_string2); |
- |
- bool SetGLVersionInfo(const std::string& version_op, |
- const std::string& version_string, |
- const std::string& version_string2); |
- |
- bool SetGLVersionStringInfo(const std::string& version_string_value); |
- |
- bool SetGLVendorInfo(const std::string& vendor_value); |
+ const FeatureMap& feature_map) const; |
- bool SetGLRendererInfo(const std::string& renderer_value); |
- |
- bool SetGLExtensionsInfo(const std::string& extensions_value); |
- |
- bool SetGLResetNotificationStrategyInfo(const std::string& op, |
- const std::string& int_string, |
- const std::string& int_string2); |
- |
- bool SetCpuBrand(const std::string& cpu_value); |
- |
- bool SetPerfGraphicsInfo(const std::string& op, |
- const std::string& float_string, |
- const std::string& float_string2); |
- |
- bool SetPerfGamingInfo(const std::string& op, |
- const std::string& float_string, |
- const std::string& float_string2); |
- |
- bool SetPerfOverallInfo(const std::string& op, |
- const std::string& float_string, |
- const std::string& float_string2); |
- |
- bool AddMachineModelName(const std::string& model_name); |
- |
- bool SetMachineModelVersionInfo(const std::string& version_op, |
- const std::string& version_string, |
- const std::string& version_string2); |
+ // Logs a control list match for this rule in the list identified by |
+ // |control_list_logging_name|. |
+ void LogControlListMatch( |
+ const std::string& control_list_logging_name) const; |
+ }; |
- bool SetGpuCountInfo(const std::string& op, |
- const std::string& int_string, |
- const std::string& int_string2); |
+ explicit GpuControlList(const GpuControlListData& data); |
+ virtual ~GpuControlList(); |
- void SetDirectRenderingInfo(bool value); |
- void SetInProcessGPUInfo(bool value); |
+ // Collects system information and combines them with gpu_info and control |
+ // list information to decide which entries are applied to the current |
+ // system and returns the union of features specified in each entry. |
+ // If os is kOsAny, use the current OS; if os_version is empty, use the |
+ // current OS version. |
+ std::set<int> MakeDecision(OsType os, |
+ const std::string& os_version, |
+ const GPUInfo& gpu_info); |
- bool SetPixelShaderVersionInfo(const std::string& version_op, |
- const std::string& version_string, |
- const std::string& version_string2); |
+ // Collects the active entries from the last MakeDecision() call. |
+ void GetDecisionEntries(std::vector<uint32_t>* entry_ids) const; |
- bool SetFeatures(const std::vector<std::string>& features, |
- const std::vector<std::string>& exceptions, |
- const FeatureMap& feature_map, |
- bool supports_feature_type_all); |
+ // Collects all disabled extensions. |
+ std::vector<std::string> GetDisabledExtensions(); |
- void AddException(ScopedGpuControlListEntry exception); |
+ // Returns the description and bugs from active entries from the last |
+ // MakeDecision() call. |
+ // |
+ // Each problems has: |
+ // { |
+ // "description": "Your GPU is too old", |
+ // "crBugs": [1234], |
+ // } |
+ void GetReasons(base::ListValue* problem_list, const std::string& tag) const; |
- // Return true if GL_VERSION string does not fit the entry info |
- // on GL type and GL version. |
- bool GLVersionInfoMismatch(const std::string& gl_version) const; |
+ // Return the largest entry id. This is used for histogramming. |
+ uint32_t max_entry_id() const; |
- static MultiGpuStyle StringToMultiGpuStyle(const std::string& style); |
+ // Returns the version of the control list. |
+ std::string version() const; |
- static MultiGpuCategory StringToMultiGpuCategory( |
- const std::string& category); |
+ // Check if we need more gpu info to make the decisions. |
+ // This is computed from the last MakeDecision() call. |
+ // If yes, we should create a gl context and do a full gpu info collection. |
+ bool needs_more_info() const { return needs_more_info_; } |
- static GLType StringToGLType(const std::string& gl_type); |
+ // Returns the number of entries. This is only for tests. |
+ size_t num_entries() const; |
- // map a feature_name to feature_id. If the string is not a registered |
- // feature name, return false. |
- static bool StringToFeature(const std::string& feature_name, |
- int* feature_id, |
- const FeatureMap& feature_map); |
+ // Register a feature to FeatureMap. |
+ void AddSupportedFeature(const std::string& feature_name, int feature_id); |
- // Return the default GL type, depending on the OS. |
- // See GLType declaration. |
- static GLType GetDefaultGLType(); |
+ // Enables logging of control list decisions. |
+ void EnableControlListLogging(const std::string& control_list_logging_name) { |
+ control_list_logging_enabled_ = true; |
+ control_list_logging_name_ = control_list_logging_name; |
+ } |
- uint32_t id_; |
- bool disabled_; |
- std::string description_; |
- std::vector<int> cr_bugs_; |
- std::vector<int> webkit_bugs_; |
- std::vector<std::string> disabled_extensions_; |
- std::unique_ptr<OsInfo> os_info_; |
- uint32_t vendor_id_; |
- std::vector<uint32_t> device_id_list_; |
- MultiGpuStyle multi_gpu_style_; |
- MultiGpuCategory multi_gpu_category_; |
- GLType gl_type_; |
- std::string driver_vendor_info_; |
- std::unique_ptr<VersionInfo> driver_version_info_; |
- std::unique_ptr<VersionInfo> driver_date_info_; |
- std::unique_ptr<VersionInfo> gl_version_info_; |
- std::string gl_version_string_info_; |
- std::string gl_vendor_info_; |
- std::string gl_renderer_info_; |
- std::string gl_extensions_info_; |
- std::unique_ptr<IntInfo> gl_reset_notification_strategy_info_; |
- std::string cpu_brand_; |
- std::unique_ptr<FloatInfo> perf_graphics_info_; |
- std::unique_ptr<FloatInfo> perf_gaming_info_; |
- std::unique_ptr<FloatInfo> perf_overall_info_; |
- std::vector<std::string> machine_model_name_list_; |
- std::unique_ptr<VersionInfo> machine_model_version_info_; |
- std::unique_ptr<IntInfo> gpu_count_info_; |
- std::unique_ptr<BoolInfo> direct_rendering_info_; |
- std::unique_ptr<BoolInfo> in_process_gpu_info_; |
- std::unique_ptr<VersionInfo> pixel_shader_version_info_; |
- std::set<int> features_; |
- std::vector<ScopedGpuControlListEntry> exceptions_; |
- }; |
+ private: |
+ friend class GpuControlListEntryTest; |
+ friend class VersionInfoTest; |
// Gets the current OS type. |
static OsType GetOsType(); |
- bool LoadList(const base::DictionaryValue& parsed_json, OsFilter os_filter); |
- |
- void Clear(); |
- |
- static NumericOp StringToNumericOp(const std::string& op); |
- |
std::string version_; |
- std::vector<ScopedGpuControlListEntry> entries_; |
- |
- // This records all the blacklist entries that are appliable to the current |
- // user machine. It is updated everytime MakeDecision() is called and is |
- // used later by GetDecisionEntries(). |
- std::vector<ScopedGpuControlListEntry> active_entries_; |
+ size_t entry_count_; |
+ const Entry* entries_; |
+ // This records all the entries that are appliable to the current user |
+ // machine. It is updated everytime MakeDecision() is called and is used |
+ // later by GetDecisionEntries(). |
+ std::vector<size_t> active_entries_; |
uint32_t max_entry_id_; |
@@ -498,13 +276,24 @@ class GPU_EXPORT GpuControlList { |
// The features a GpuControlList recognizes and handles. |
FeatureMap feature_map_; |
- bool supports_feature_type_all_; |
bool control_list_logging_enabled_; |
std::string control_list_logging_name_; |
}; |
+struct GPU_EXPORT GpuControlListData { |
+ const char* version; |
+ size_t entry_count; |
+ const GpuControlList::Entry* entries; |
+ |
+ GpuControlListData() : version(nullptr), entry_count(0u), entries(nullptr) {} |
+ |
+ GpuControlListData(const char* a_version, |
+ size_t a_entry_count, |
+ const GpuControlList::Entry* a_entries) |
+ : version(a_version), entry_count(a_entry_count), entries(a_entries) {} |
+}; |
+ |
} // namespace gpu |
#endif // GPU_CONFIG_GPU_CONTROL_LIST_H_ |
- |