Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2010 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 CHROME_BROWSER_GPU_BLACKLIST_H_ | |
| 6 #define CHROME_BROWSER_GPU_BLACKLIST_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 // Determines whether certain gpu-related features are blacklisted or not. | |
| 10 | |
| 11 #include <string> | |
| 12 #include <vector> | |
| 13 | |
| 14 #include "base/basictypes.h" | |
| 15 #include "base/scoped_ptr.h" | |
| 16 #include "chrome/common/gpu_feature_flags.h" | |
| 17 | |
| 18 class DictionaryValue; | |
| 19 class GPUInfo; | |
| 20 class Version; | |
| 21 | |
| 22 class GpuBlacklist { | |
| 23 public: | |
| 24 enum OsType { | |
| 25 kOsLinux, | |
| 26 kOsMacosx, | |
| 27 kOsWin, | |
| 28 kOsAny, | |
| 29 kOsUnknown | |
| 30 }; | |
| 31 | |
| 32 GpuBlacklist(); | |
| 33 ~GpuBlacklist(); | |
| 34 | |
| 35 // Loads blacklist information from a json file. | |
| 36 // current_os_only==true indicates all blacklist entries that don't belong to | |
| 37 // the current OS are discarded; current_os_only==false should only be used | |
| 38 // for testing purpose. | |
| 39 // If failed, the current GpuBlacklist is un-touched. | |
| 40 bool LoadGpuBlacklist(const std::string& json_context, | |
| 41 bool current_os_only); | |
| 42 | |
| 43 // Collects system information and combines them with gpu_info and blacklist | |
| 44 // information to determine gpu feature flags. | |
| 45 // If os is kOsAny, use the current OS; if os_version is null, use the | |
| 46 // current OS version. | |
| 47 GpuFeatureFlags DetermineGpuFeatureFlags(OsType os, | |
| 48 Version* os_version, | |
| 49 const GPUInfo& gpu_info) const; | |
| 50 | |
| 51 private: | |
| 52 class VersionInfo { | |
| 53 public: | |
| 54 VersionInfo(const std::string& version_op, | |
| 55 const std::string& version_string, | |
| 56 const std::string& version_string2); | |
| 57 ~VersionInfo(); | |
| 58 | |
| 59 // Determines if a given version is included in the VersionInfo range. | |
| 60 bool Contains(const Version& version) const; | |
| 61 | |
| 62 // Determines if the VersionInfo contains valid information. | |
| 63 bool IsValid() const; | |
| 64 | |
| 65 private: | |
| 66 enum Op { | |
| 67 kBetween, // <= * <= | |
| 68 kEQ, // = | |
| 69 kLT, // < | |
| 70 kLE, // <= | |
| 71 kGT, // > | |
| 72 kGE, // >= | |
| 73 kAny, | |
| 74 kUnknown // Indicates VersionInfo data is invalid. | |
| 75 }; | |
| 76 | |
| 77 // Maps string to Op; returns kUnknown if it's not a valid Op. | |
| 78 static Op StringToOp(const std::string& version_op); | |
| 79 | |
| 80 Op op_; | |
| 81 scoped_ptr<Version> version_; | |
| 82 scoped_ptr<Version> version2_; | |
| 83 }; | |
| 84 | |
| 85 class OsInfo { | |
| 86 public: | |
| 87 OsInfo(const std::string& os, | |
| 88 const std::string& version_op, | |
| 89 const std::string& version_string, | |
| 90 const std::string& version_string2); | |
| 91 | |
| 92 // Determines if a given os/version is included in the OsInfo set. | |
| 93 bool Contains(OsType type, const Version& version) const; | |
| 94 | |
| 95 // Determines if the VersionInfo contains valid information. | |
| 96 bool IsValid() const; | |
| 97 | |
| 98 OsType type() const; | |
| 99 | |
| 100 private: | |
| 101 OsType type_; | |
| 102 scoped_ptr<VersionInfo> version_info_; | |
| 103 }; | |
| 104 | |
| 105 class GpuBlacklistEntry { | |
| 106 public: | |
| 107 // Constructs GpuBlacklistEntry from DictionaryValue loaded from json. | |
| 108 static GpuBlacklistEntry* GetGpuBlacklistEntryFromValue( | |
| 109 DictionaryValue* value); | |
| 110 | |
| 111 // Determines if a given os/gc/driver is included in the Entry set. | |
| 112 bool Contains(OsType os_type, const Version& os_version, | |
| 113 uint32 vendor_id, uint32 device_id, | |
| 114 const Version& driver_version) const; | |
| 115 | |
| 116 // Returns the OsType. | |
| 117 OsType GetOsType() const; | |
| 118 | |
| 119 // Returns the GpuFeatureFlags. | |
| 120 GpuFeatureFlags GetGpuFeatureFlags() const; | |
| 121 | |
| 122 private: | |
| 123 GpuBlacklistEntry(); | |
| 124 | |
| 125 bool SetOsInfo(const std::string& os, | |
| 126 const std::string& version_op, | |
| 127 const std::string& version_string, | |
| 128 const std::string& version_string2); | |
| 129 | |
| 130 bool SetVendorId(const std::string& vendor_id_string); | |
| 131 | |
| 132 bool SetDeviceId(const std::string& device_id_string); | |
| 133 | |
| 134 bool SetDriverVersionInfo(const std::string& version_op, | |
| 135 const std::string& version_string, | |
| 136 const std::string& version_string2); | |
| 137 | |
| 138 bool SetBlacklistedFeatures( | |
| 139 const std::vector<std::string>& blacklisted_features); | |
| 140 | |
| 141 scoped_ptr<OsInfo> os_info_; | |
| 142 uint32 vendor_id_; | |
| 143 uint32 device_id_; | |
| 144 scoped_ptr<VersionInfo> driver_version_info_; | |
| 145 scoped_ptr<GpuFeatureFlags> feature_flags_; | |
| 146 }; | |
| 147 | |
| 148 // Maps string to OsType; returns kOsUnknown if it's not a valid os. | |
| 149 static OsType StringToOsType(const std::string& os); | |
|
vangelis
2010/12/08 00:17:38
nit: it might make more sense to define this as a
Zhenyao Mo
2010/12/09 00:06:06
Done.
| |
| 150 | |
| 151 // Gets the current OS type. | |
| 152 static OsType GetOsType(); | |
| 153 | |
| 154 void Clear(); | |
| 155 | |
| 156 std::vector<GpuBlacklistEntry*> blacklist_; | |
| 157 | |
| 158 DISALLOW_COPY_AND_ASSIGN(GpuBlacklist); | |
| 159 }; | |
| 160 | |
| 161 #endif // CHROME_BROWSER_GPU_BLACKLIST_H_ | |
| 162 | |
| OLD | NEW |