Chromium Code Reviews
|
| OLD | NEW |
|---|---|
| (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 make the control list decision. | |
| 53 // If os is kOsAny, use the current OS; if os_version is empty, use the | |
| 54 // current OS version. | |
| 55 int MakeDecision( | |
|
greggman
2013/03/22 00:30:51
nit: I hope this isn't bikeshedding but the descri
Zhenyao Mo
2013/03/22 20:00:10
Revised to make it clearer.
| |
| 56 OsType os, std::string os_version, const GPUInfo& gpu_info); | |
| 57 | |
| 58 // Collects the active entries from the last MakeBlacklistDecision() call. | |
|
greggman
2013/03/22 00:30:51
s/MakeBlacklistDecision/MakeDecision/?
Zhenyao Mo
2013/03/22 20:00:10
Done.
| |
| 59 // If disabled set to true, return entries that are disabled; otherwise, | |
| 60 // return enabled entries. | |
| 61 void GetDecisionEntries(std::vector<uint32>* entry_ids, | |
| 62 bool disabled) const; | |
| 63 | |
| 64 // Returns the description and bugs from active entries from the last | |
| 65 // MakeDecision() call. | |
| 66 // | |
| 67 // Each problems has: | |
| 68 // { | |
| 69 // "description": "Your GPU is too old", | |
| 70 // "crBugs": [1234], | |
| 71 // "webkitBugs": [] | |
| 72 // } | |
| 73 void GetReasons(base::ListValue* problem_list) const; | |
| 74 | |
| 75 // Return the largest entry id. This is used for histogramming. | |
| 76 uint32 max_entry_id() const; | |
| 77 | |
| 78 // Returns the version of the current blacklist. | |
| 79 std::string GetVersion() const; | |
| 80 | |
| 81 // Check if we needs more gpu info to make the decisions. | |
|
greggman
2013/03/22 00:30:51
s/needs/need/
Zhenyao Mo
2013/03/22 20:00:10
Done.
| |
| 82 // This is computed from the last MakeDecision() call. | |
| 83 // If yes, we should create a gl context and do a full gpu info collection. | |
| 84 bool needs_more_info() const { return needs_more_info_; } | |
| 85 | |
| 86 // Check if any entries contain unknown fields. This is only for tests. | |
| 87 bool contains_unknown_fields() const { return contains_unknown_fields_; } | |
| 88 | |
| 89 // Returns the number of entries. This is only for tests. | |
| 90 size_t num_entries() const; | |
| 91 | |
| 92 // Register a feature to FeatureMap - used to construct a GpuControlList. | |
| 93 void AddFeature(const std::string& feature_name, int feature_id); | |
| 94 | |
| 95 private: | |
| 96 enum BrowserVersionSupport { | |
| 97 kSupported, | |
| 98 kUnsupported, | |
| 99 kMalformed | |
| 100 }; | |
| 101 | |
| 102 enum NumericOp { | |
| 103 kBetween, // <= * <= | |
| 104 kEQ, // = | |
| 105 kLT, // < | |
| 106 kLE, // <= | |
| 107 kGT, // > | |
| 108 kGE, // >= | |
| 109 kAny, | |
| 110 kUnknown // Indicates the data is invalid. | |
| 111 }; | |
| 112 | |
| 113 class VersionInfo { | |
|
greggman
2013/03/22 00:30:51
It seems like these classes should have unit tests
Zhenyao Mo
2013/03/22 20:00:10
Sure. Will add tests for this class in a follow-u
| |
| 114 public: | |
| 115 // If version_style is empty, it defaults to kNumerical. | |
| 116 VersionInfo(const std::string& version_op, | |
| 117 const std::string& version_style, | |
| 118 const std::string& version_string, | |
| 119 const std::string& version_string2); | |
| 120 ~VersionInfo(); | |
| 121 | |
| 122 // Determines if a given version is included in the VersionInfo range. | |
| 123 // "splitter" divides version string into segments. | |
| 124 bool Contains(const std::string& version, char splitter) const; | |
| 125 // Same as above, using '.' as splitter. | |
| 126 bool Contains(const std::string& version) const; | |
| 127 | |
| 128 // Determine if the version_style is lexical. | |
| 129 bool IsLexical() const; | |
| 130 | |
| 131 // Determines if the VersionInfo contains valid information. | |
| 132 bool IsValid() const; | |
| 133 | |
| 134 private: | |
| 135 enum VersionStyle { | |
| 136 kVersionStyleNumerical, | |
| 137 kVersionStyleLexical, | |
| 138 kVersionStyleUnknown | |
| 139 }; | |
| 140 | |
| 141 static VersionStyle StringToVersionStyle(const std::string& version_style); | |
| 142 | |
| 143 // Compare two version strings. | |
| 144 // Return 1 if version > version_ref, | |
| 145 // 0 if version = version_ref, | |
| 146 // -1 if version < version_ref. | |
| 147 // Note that we only compare as many as segments as version_ref contains. | |
| 148 // If version_ref is xxx.yyy, it's considered as xxx.yyy.* | |
| 149 // For example: Compare("10.3.1", "10.3") returns 0, | |
| 150 // Compare("10.3", "10.3.1") returns -1. | |
| 151 // If "version_style" is Lexical, the first segment is compared | |
| 152 // numerically, all other segments are compared lexically. | |
| 153 // Lexical is used for AMD Linux driver versions only. | |
| 154 static int Compare(const std::vector<std::string>& version, | |
| 155 const std::vector<std::string>& version_ref, | |
| 156 VersionStyle version_style); | |
| 157 | |
| 158 NumericOp op_; | |
| 159 VersionStyle version_style_; | |
| 160 std::vector<std::string> version_; | |
| 161 std::vector<std::string> version2_; | |
| 162 }; | |
| 163 | |
| 164 class OsInfo { | |
|
greggman
2013/03/22 00:30:51
same as above. Seems like a few simple tests would
| |
| 165 public: | |
| 166 OsInfo(const std::string& os, | |
| 167 const std::string& version_op, | |
| 168 const std::string& version_string, | |
| 169 const std::string& version_string2); | |
| 170 ~OsInfo(); | |
| 171 | |
| 172 // Determines if a given os/version is included in the OsInfo set. | |
| 173 bool Contains(OsType type, const std::string& version) const; | |
| 174 | |
| 175 // Determines if the VersionInfo contains valid information. | |
| 176 bool IsValid() const; | |
| 177 | |
| 178 OsType type() const; | |
| 179 | |
| 180 // Maps string to OsType; returns kOsUnknown if it's not a valid os. | |
| 181 static OsType StringToOsType(const std::string& os); | |
| 182 | |
| 183 private: | |
| 184 OsType type_; | |
| 185 scoped_ptr<VersionInfo> version_info_; | |
| 186 }; | |
| 187 | |
| 188 class StringInfo { | |
|
greggman
2013/03/22 00:30:51
same as above. Seems like a few simple tests would
| |
| 189 public: | |
| 190 StringInfo(const std::string& string_op, const std::string& string_value); | |
| 191 | |
| 192 // Determines if a given string is included in the StringInfo. | |
| 193 bool Contains(const std::string& value) const; | |
| 194 | |
| 195 // Determines if the StringInfo contains valid information. | |
| 196 bool IsValid() const; | |
| 197 | |
| 198 private: | |
| 199 enum Op { | |
| 200 kContains, | |
| 201 kBeginWith, | |
| 202 kEndWith, | |
| 203 kEQ, // = | |
| 204 kUnknown // Indicates StringInfo data is invalid. | |
| 205 }; | |
| 206 | |
| 207 // Maps string to Op; returns kUnknown if it's not a valid Op. | |
| 208 static Op StringToOp(const std::string& string_op); | |
| 209 | |
| 210 Op op_; | |
| 211 std::string value_; | |
| 212 }; | |
| 213 | |
| 214 class FloatInfo { | |
|
greggman
2013/03/22 00:30:51
same as above. Seems like a few simple tests would
| |
| 215 public: | |
| 216 FloatInfo(const std::string& float_op, | |
| 217 const std::string& float_value, | |
| 218 const std::string& float_value2); | |
| 219 | |
| 220 // Determines if a given float is included in the FloatInfo. | |
| 221 bool Contains(float value) const; | |
| 222 | |
| 223 // Determines if the FloatInfo contains valid information. | |
| 224 bool IsValid() const; | |
| 225 | |
| 226 private: | |
| 227 NumericOp op_; | |
| 228 float value_; | |
| 229 float value2_; | |
| 230 }; | |
| 231 | |
| 232 class IntInfo { | |
|
greggman
2013/03/22 00:30:51
same as above. Seems like a few simple tests would
| |
| 233 public: | |
| 234 IntInfo(const std::string& int_op, | |
| 235 const std::string& int_value, | |
| 236 const std::string& int_value2); | |
| 237 | |
| 238 // Determines if a given int is included in the IntInfo. | |
| 239 bool Contains(int value) const; | |
| 240 | |
| 241 // Determines if the IntInfo contains valid information. | |
| 242 bool IsValid() const; | |
| 243 | |
| 244 private: | |
| 245 NumericOp op_; | |
| 246 int value_; | |
| 247 int value2_; | |
| 248 }; | |
| 249 | |
| 250 class MachineModelInfo { | |
|
greggman
2013/03/22 00:30:51
same as above. Seems like a few simple tests would
| |
| 251 public: | |
| 252 MachineModelInfo(const std::string& name_op, | |
| 253 const std::string& name_value, | |
| 254 const std::string& version_op, | |
| 255 const std::string& version_string, | |
| 256 const std::string& version_string2); | |
| 257 ~MachineModelInfo(); | |
| 258 | |
| 259 // Determines if a given name/version is included in the MachineModelInfo. | |
| 260 bool Contains(const std::string& name, const std::string& version) const; | |
| 261 | |
| 262 // Determines if the MachineModelInfo contains valid information. | |
| 263 bool IsValid() const; | |
| 264 | |
| 265 private: | |
| 266 scoped_ptr<StringInfo> name_info_; | |
| 267 scoped_ptr<VersionInfo> version_info_; | |
| 268 }; | |
| 269 | |
| 270 class GpuControlListEntry; | |
| 271 typedef scoped_refptr<GpuControlListEntry> ScopedGpuControlListEntry; | |
| 272 | |
| 273 typedef base::hash_map<std::string, int> FeatureMap; | |
| 274 | |
| 275 class GpuControlListEntry : public base::RefCounted<GpuControlListEntry> { | |
|
greggman
2013/03/22 00:30:51
same as above. Seems like a few simple tests would
| |
| 276 public: | |
| 277 // Constructs GpuControlListEntry from DictionaryValue loaded from json. | |
| 278 // Top-level entry must have an id number. Others are exceptions. | |
| 279 static ScopedGpuControlListEntry GetEntryFromValue( | |
| 280 const base::DictionaryValue* value, bool top_level, | |
| 281 const FeatureMap& feature_map); | |
| 282 | |
| 283 // Determines if a given os/gc/machine_model/driver is included in the | |
| 284 // Entry set. | |
| 285 bool Contains(OsType os_type, const std::string& os_version, | |
| 286 const GPUInfo& gpu_info) const; | |
| 287 | |
| 288 // Determines whether we needs more gpu info to make the blacklisting | |
| 289 // decision. It should only be checked if Contains() returns true. | |
| 290 bool NeedsMoreInfo(const GPUInfo& gpu_info) const; | |
| 291 | |
| 292 // Returns the OsType. | |
| 293 OsType GetOsType() const; | |
| 294 | |
| 295 // Returns the entry's unique id. 0 is reserved. | |
| 296 uint32 id() const; | |
| 297 | |
| 298 // Returns whether the entry is disabled. | |
| 299 bool disabled() const; | |
| 300 | |
| 301 // Returns the description of the entry | |
| 302 const std::string& description() const { return description_; } | |
| 303 | |
| 304 // Returns a list of Chromium and Webkit bugs applicable to this entry | |
| 305 const std::vector<int>& cr_bugs() const { return cr_bugs_; } | |
| 306 const std::vector<int>& webkit_bugs() const { return webkit_bugs_; } | |
| 307 | |
| 308 // Returns the features. | |
| 309 int GetFeatures() const; | |
| 310 | |
| 311 // Returns true if an unknown field is encountered. | |
| 312 bool contains_unknown_fields() const { | |
| 313 return contains_unknown_fields_; | |
| 314 } | |
| 315 // Returns true if an unknown blacklist feature is encountered. | |
| 316 bool contains_unknown_features() const { | |
| 317 return contains_unknown_features_; | |
| 318 } | |
| 319 | |
| 320 private: | |
| 321 friend class base::RefCounted<GpuControlListEntry>; | |
| 322 | |
| 323 enum MultiGpuStyle { | |
| 324 kMultiGpuStyleOptimus, | |
| 325 kMultiGpuStyleAMDSwitchable, | |
| 326 kMultiGpuStyleNone | |
| 327 }; | |
| 328 | |
| 329 enum MultiGpuCategory { | |
| 330 kMultiGpuCategoryPrimary, | |
| 331 kMultiGpuCategorySecondary, | |
| 332 kMultiGpuCategoryAny, | |
| 333 kMultiGpuCategoryNone | |
| 334 }; | |
| 335 | |
| 336 GpuControlListEntry(); | |
| 337 ~GpuControlListEntry(); | |
| 338 | |
| 339 bool SetId(uint32 id); | |
| 340 | |
| 341 void SetDisabled(bool disabled); | |
| 342 | |
| 343 bool SetOsInfo(const std::string& os, | |
| 344 const std::string& version_op, | |
| 345 const std::string& version_string, | |
| 346 const std::string& version_string2); | |
| 347 | |
| 348 bool SetVendorId(const std::string& vendor_id_string); | |
| 349 | |
| 350 bool AddDeviceId(const std::string& device_id_string); | |
| 351 | |
| 352 bool SetMultiGpuStyle(const std::string& multi_gpu_style_string); | |
| 353 | |
| 354 bool SetMultiGpuCategory(const std::string& multi_gpu_category_string); | |
| 355 | |
| 356 bool SetDriverVendorInfo(const std::string& vendor_op, | |
| 357 const std::string& vendor_value); | |
| 358 | |
| 359 bool SetDriverVersionInfo(const std::string& version_op, | |
| 360 const std::string& version_style, | |
| 361 const std::string& version_string, | |
| 362 const std::string& version_string2); | |
| 363 | |
| 364 bool SetDriverDateInfo(const std::string& date_op, | |
| 365 const std::string& date_string, | |
| 366 const std::string& date_string2); | |
| 367 | |
| 368 bool SetGLVendorInfo(const std::string& vendor_op, | |
| 369 const std::string& vendor_value); | |
| 370 | |
| 371 bool SetGLRendererInfo(const std::string& renderer_op, | |
| 372 const std::string& renderer_value); | |
| 373 | |
| 374 bool SetCpuBrand(const std::string& cpu_op, | |
| 375 const std::string& cpu_value); | |
| 376 | |
| 377 bool SetPerfGraphicsInfo(const std::string& op, | |
| 378 const std::string& float_string, | |
| 379 const std::string& float_string2); | |
| 380 | |
| 381 bool SetPerfGamingInfo(const std::string& op, | |
| 382 const std::string& float_string, | |
| 383 const std::string& float_string2); | |
| 384 | |
| 385 bool SetPerfOverallInfo(const std::string& op, | |
| 386 const std::string& float_string, | |
| 387 const std::string& float_string2); | |
| 388 | |
| 389 bool SetMachineModelInfo(const std::string& name_op, | |
| 390 const std::string& name_value, | |
| 391 const std::string& version_op, | |
| 392 const std::string& version_string, | |
| 393 const std::string& version_string2); | |
| 394 | |
| 395 bool SetGpuCountInfo(const std::string& op, | |
| 396 const std::string& int_string, | |
| 397 const std::string& int_string2); | |
| 398 | |
| 399 bool SetFeatures(const std::vector<std::string>& features, | |
| 400 const FeatureMap& feature_map); | |
| 401 | |
| 402 void AddException(ScopedGpuControlListEntry exception); | |
| 403 | |
| 404 static MultiGpuStyle StringToMultiGpuStyle(const std::string& style); | |
| 405 | |
| 406 static MultiGpuCategory StringToMultiGpuCategory( | |
| 407 const std::string& category); | |
| 408 | |
| 409 // map a feature_name to feature_id. If the string is not a registered | |
| 410 // feature name, return false. | |
| 411 static bool StringToFeature(const std::string& feature_name, | |
| 412 int* feature_id, | |
| 413 const FeatureMap& feature_map); | |
| 414 | |
| 415 uint32 id_; | |
| 416 bool disabled_; | |
| 417 std::string description_; | |
| 418 std::vector<int> cr_bugs_; | |
| 419 std::vector<int> webkit_bugs_; | |
| 420 scoped_ptr<OsInfo> os_info_; | |
| 421 uint32 vendor_id_; | |
| 422 std::vector<uint32> device_id_list_; | |
| 423 MultiGpuStyle multi_gpu_style_; | |
| 424 MultiGpuCategory multi_gpu_category_; | |
| 425 scoped_ptr<StringInfo> driver_vendor_info_; | |
| 426 scoped_ptr<VersionInfo> driver_version_info_; | |
| 427 scoped_ptr<VersionInfo> driver_date_info_; | |
| 428 scoped_ptr<StringInfo> gl_vendor_info_; | |
| 429 scoped_ptr<StringInfo> gl_renderer_info_; | |
| 430 scoped_ptr<StringInfo> cpu_brand_; | |
| 431 scoped_ptr<FloatInfo> perf_graphics_info_; | |
| 432 scoped_ptr<FloatInfo> perf_gaming_info_; | |
| 433 scoped_ptr<FloatInfo> perf_overall_info_; | |
| 434 scoped_ptr<MachineModelInfo> machine_model_info_; | |
| 435 scoped_ptr<IntInfo> gpu_count_info_; | |
| 436 int features_; | |
| 437 std::vector<ScopedGpuControlListEntry> exceptions_; | |
| 438 bool contains_unknown_fields_; | |
| 439 bool contains_unknown_features_; | |
| 440 }; | |
| 441 | |
| 442 // Gets the current OS type. | |
| 443 static OsType GetOsType(); | |
| 444 | |
| 445 bool LoadList(const base::DictionaryValue& parsed_json, OsFilter os_filter); | |
| 446 | |
| 447 void Clear(); | |
| 448 | |
| 449 // Check if the entry is supported by the current version of browser. | |
| 450 // By default, if there is no browser version information in the entry, | |
| 451 // return kSupported; | |
| 452 BrowserVersionSupport IsEntrySupportedByCurrentBrowserVersion( | |
| 453 const base::DictionaryValue* value); | |
| 454 | |
| 455 static NumericOp StringToNumericOp(const std::string& op); | |
| 456 | |
| 457 std::string version_; | |
| 458 std::vector<ScopedGpuControlListEntry> feature_list_; | |
| 459 | |
| 460 std::string browser_version_; | |
| 461 | |
| 462 // This records all the blacklist entries that are appliable to the current | |
| 463 // user machine. It is updated everytime MakeBlacklistDecision() is | |
| 464 // called and is used later by GetDecisionEntries(). | |
| 465 std::vector<ScopedGpuControlListEntry> active_entries_; | |
| 466 | |
| 467 uint32 max_entry_id_; | |
| 468 | |
| 469 bool contains_unknown_fields_; | |
| 470 | |
| 471 bool needs_more_info_; | |
| 472 | |
| 473 // The features a GpuControlList recognizes and handles. | |
| 474 FeatureMap feature_map_; | |
| 475 }; | |
| 476 | |
| 477 } // namespace content | |
| 478 | |
| 479 #endif // CONTENT_BROWSER_GPU_GPU_CONTROL_LIST_H_ | |
| 480 | |
| OLD | NEW |