OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_GPU_BLACKLIST_H_ | 5 #ifndef CHROME_BROWSER_GPU_BLACKLIST_H_ |
6 #define CHROME_BROWSER_GPU_BLACKLIST_H_ | 6 #define CHROME_BROWSER_GPU_BLACKLIST_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 // TODO(jam): remove this file when all files have been converted. |
10 #include <vector> | 10 #include "content/browser/gpu_blacklist.h" |
11 | |
12 #include "base/basictypes.h" | |
13 #include "base/scoped_ptr.h" | |
14 #include "chrome/common/gpu_feature_flags.h" | |
15 | |
16 class DictionaryValue; | |
17 class GPUInfo; | |
18 class Version; | |
19 | |
20 class GpuBlacklist { | |
21 public: | |
22 enum OsType { | |
23 kOsLinux, | |
24 kOsMacosx, | |
25 kOsWin, | |
26 kOsAny, | |
27 kOsUnknown | |
28 }; | |
29 | |
30 GpuBlacklist(); | |
31 ~GpuBlacklist(); | |
32 | |
33 // Loads blacklist information from a json file. | |
34 // current_os_only==true indicates all blacklist entries that don't belong to | |
35 // the current OS are discarded; current_os_only==false should only be used | |
36 // for testing purpose. | |
37 // If failed, the current GpuBlacklist is un-touched. | |
38 bool LoadGpuBlacklist(const std::string& json_context, | |
39 bool current_os_only); | |
40 | |
41 // Collects system information and combines them with gpu_info and blacklist | |
42 // information to determine gpu feature flags. | |
43 // If os is kOsAny, use the current OS; if os_version is null, use the | |
44 // current OS version. | |
45 GpuFeatureFlags DetermineGpuFeatureFlags(OsType os, | |
46 Version* os_version, | |
47 const GPUInfo& gpu_info); | |
48 | |
49 // Collects the entries that set the "feature" flag from the last | |
50 // DetermineGpuFeatureFlags() call. This tells which entries are responsible | |
51 // for raising a certain flag, i.e, for blacklisting a certain feature. | |
52 // Examples of "feature": | |
53 // kGpuFeatureAll - any of the supported features; | |
54 // kGpuFeatureWebgl - a single feature; | |
55 // kGpuFeatureWebgl | kGpuFeatureAcceleratedCompositing - two features. | |
56 void GetGpuFeatureFlagEntries(GpuFeatureFlags::GpuFeatureType feature, | |
57 std::vector<uint32>& entry_ids) const; | |
58 | |
59 // Return the largest entry id. This is used for histogramming. | |
60 uint32 max_entry_id() const; | |
61 | |
62 // Collects the version of the current blacklist. Returns false and sets | |
63 // major and minor to 0 on failure. | |
64 bool GetVersion(uint16* major, uint16* monir) const; | |
65 | |
66 private: | |
67 class VersionInfo { | |
68 public: | |
69 VersionInfo(const std::string& version_op, | |
70 const std::string& version_string, | |
71 const std::string& version_string2); | |
72 ~VersionInfo(); | |
73 | |
74 // Determines if a given version is included in the VersionInfo range. | |
75 bool Contains(const Version& version) const; | |
76 | |
77 // Determines if the VersionInfo contains valid information. | |
78 bool IsValid() const; | |
79 | |
80 private: | |
81 enum Op { | |
82 kBetween, // <= * <= | |
83 kEQ, // = | |
84 kLT, // < | |
85 kLE, // <= | |
86 kGT, // > | |
87 kGE, // >= | |
88 kAny, | |
89 kUnknown // Indicates VersionInfo data is invalid. | |
90 }; | |
91 | |
92 // Maps string to Op; returns kUnknown if it's not a valid Op. | |
93 static Op StringToOp(const std::string& version_op); | |
94 | |
95 Op op_; | |
96 scoped_ptr<Version> version_; | |
97 scoped_ptr<Version> version2_; | |
98 }; | |
99 | |
100 class OsInfo { | |
101 public: | |
102 OsInfo(const std::string& os, | |
103 const std::string& version_op, | |
104 const std::string& version_string, | |
105 const std::string& version_string2); | |
106 ~OsInfo(); | |
107 | |
108 // Determines if a given os/version is included in the OsInfo set. | |
109 bool Contains(OsType type, const Version& version) const; | |
110 | |
111 // Determines if the VersionInfo contains valid information. | |
112 bool IsValid() const; | |
113 | |
114 OsType type() const; | |
115 | |
116 // Maps string to OsType; returns kOsUnknown if it's not a valid os. | |
117 static OsType StringToOsType(const std::string& os); | |
118 | |
119 private: | |
120 OsType type_; | |
121 scoped_ptr<VersionInfo> version_info_; | |
122 }; | |
123 | |
124 class StringInfo { | |
125 public: | |
126 StringInfo(const std::string& string_op, const std::string& string_value); | |
127 | |
128 // Determines if a given string is included in the StringInfo. | |
129 bool Contains(const std::string& value) const; | |
130 | |
131 // Determines if the StringInfo contains valid information. | |
132 bool IsValid() const; | |
133 | |
134 private: | |
135 enum Op { | |
136 kContains, | |
137 kBeginWith, | |
138 kEndWith, | |
139 kEQ, // = | |
140 kUnknown // Indicates StringInfo data is invalid. | |
141 }; | |
142 | |
143 // Maps string to Op; returns kUnknown if it's not a valid Op. | |
144 static Op StringToOp(const std::string& string_op); | |
145 | |
146 Op op_; | |
147 std::string value_; | |
148 }; | |
149 | |
150 class GpuBlacklistEntry { | |
151 public: | |
152 // Constructs GpuBlacklistEntry from DictionaryValue loaded from json. | |
153 static GpuBlacklistEntry* GetGpuBlacklistEntryFromValue( | |
154 DictionaryValue* value); | |
155 | |
156 // Determines if a given os/gc/driver is included in the Entry set. | |
157 bool Contains(OsType os_type, | |
158 const Version& os_version, | |
159 const GPUInfo& gpu_info) const; | |
160 | |
161 // Returns the OsType. | |
162 OsType GetOsType() const; | |
163 | |
164 // Returns the entry's unique id. 0 is reserved. | |
165 uint32 id() const; | |
166 | |
167 // Returns the GpuFeatureFlags. | |
168 GpuFeatureFlags GetGpuFeatureFlags() const; | |
169 | |
170 ~GpuBlacklistEntry(); | |
171 | |
172 private: | |
173 GpuBlacklistEntry(); | |
174 | |
175 bool SetId(const std::string& id_string); | |
176 | |
177 bool SetOsInfo(const std::string& os, | |
178 const std::string& version_op, | |
179 const std::string& version_string, | |
180 const std::string& version_string2); | |
181 | |
182 bool SetVendorId(const std::string& vendor_id_string); | |
183 | |
184 bool SetDeviceId(const std::string& device_id_string); | |
185 | |
186 bool SetDriverVendorInfo(const std::string& vendor_op, | |
187 const std::string& vendor_value); | |
188 | |
189 bool SetDriverVersionInfo(const std::string& version_op, | |
190 const std::string& version_string, | |
191 const std::string& version_string2); | |
192 | |
193 bool SetGLRendererInfo(const std::string& renderer_op, | |
194 const std::string& renderer_value); | |
195 | |
196 bool SetBlacklistedFeatures( | |
197 const std::vector<std::string>& blacklisted_features); | |
198 | |
199 uint32 id_; | |
200 scoped_ptr<OsInfo> os_info_; | |
201 uint32 vendor_id_; | |
202 uint32 device_id_; | |
203 scoped_ptr<StringInfo> driver_vendor_info_; | |
204 scoped_ptr<VersionInfo> driver_version_info_; | |
205 scoped_ptr<StringInfo> gl_renderer_info_; | |
206 scoped_ptr<GpuFeatureFlags> feature_flags_; | |
207 }; | |
208 | |
209 // Gets the current OS type. | |
210 static OsType GetOsType(); | |
211 | |
212 void Clear(); | |
213 | |
214 scoped_ptr<Version> version_; | |
215 std::vector<GpuBlacklistEntry*> blacklist_; | |
216 | |
217 // This records all the blacklist entries that are appliable to the current | |
218 // user machine. It is updated everytime DetermineGpuFeatureFlags() is | |
219 // called and is used later by GetGpuFeatureFlagEntries(). | |
220 std::vector<GpuBlacklistEntry*> active_entries_; | |
221 | |
222 uint32 max_entry_id_; | |
223 | |
224 DISALLOW_COPY_AND_ASSIGN(GpuBlacklist); | |
225 }; | |
226 | 11 |
227 #endif // CHROME_BROWSER_GPU_BLACKLIST_H_ | 12 #endif // CHROME_BROWSER_GPU_BLACKLIST_H_ |
228 | 13 |
OLD | NEW |