Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(322)

Side by Side Diff: chrome/browser/gpu_blacklist.h

Issue 10908110: Move gpu blacklist to content side. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 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
8 #include <string>
9 #include <vector>
10
11 #include "base/basictypes.h"
12 #include "base/gtest_prod_util.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/singleton.h"
16 #include "base/values.h"
17 #include "content/public/browser/gpu_data_manager_observer.h"
18 #include "content/public/common/gpu_feature_type.h"
19
20 class Version;
21
22 namespace content {
23 struct GPUInfo;
24 }
25
26 class GpuBlacklist : public content::GpuDataManagerObserver {
27 public:
28 enum OsType {
29 kOsLinux,
30 kOsMacosx,
31 kOsWin,
32 kOsChromeOS,
33 kOsAny,
34 kOsUnknown
35 };
36
37 enum OsFilter {
38 // In loading, ignore all entries that belong to other OS.
39 kCurrentOsOnly,
40 // In loading, keep all entries. This is for testing only.
41 kAllOs
42 };
43
44 // Getter for the singleton. This will return NULL on failure.
45 static GpuBlacklist* GetInstance();
46
47 virtual ~GpuBlacklist();
48
49 // Loads blacklist information from a json file.
50 // If failed, the current GpuBlacklist is un-touched.
51 bool LoadGpuBlacklist(const std::string& json_context,
52 OsFilter os_filter);
53
54 // Collects system information and combines them with gpu_info and blacklist
55 // information to determine gpu feature flags.
56 // If os is kOsAny, use the current OS; if os_version is null, use the
57 // current OS version.
58 content::GpuFeatureType DetermineGpuFeatureType(
59 OsType os, Version* os_version, const content::GPUInfo& gpu_info);
60
61 // Helper function that calls DetermineGpuFeatureType and sets the updated
62 // features on GpuDataManager.
63 void UpdateGpuDataManager();
64
65 // Collects the active entries that set the "feature" flag from the last
66 // DetermineGpuFeatureType() call. This tells which entries are responsible
67 // for raising a certain flag, i.e, for blacklisting a certain feature.
68 // Examples of "feature":
69 // GPU_FEATURE_TYPE_ALL - any of the supported features;
70 // GPU_FEATURE_TYPE_WEBGL - a single feature;
71 // GPU_FEATURE_TYPE_WEBGL | GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING
72 // - two features.
73 // If disabled set to true, return entries that are disabled; otherwise,
74 // return enabled entries.
75 void GetGpuFeatureTypeEntries(content::GpuFeatureType feature,
76 std::vector<uint32>& entry_ids,
77 bool disabled) const;
78
79 // Returns the description and bugs from active entries from the last
80 // DetermineGpuFeatureType() call.
81 //
82 // Each problems has:
83 // {
84 // "description": "Your GPU is too old",
85 // "crBugs": [1234],
86 // "webkitBugs": []
87 // }
88 void GetBlacklistReasons(ListValue* problem_list) const;
89
90 // Return the largest entry id. This is used for histogramming.
91 uint32 max_entry_id() const;
92
93 // Returns the version of the current blacklist.
94 std::string GetVersion() const;
95
96 private:
97 friend class GpuBlacklistTest;
98 friend struct DefaultSingletonTraits<GpuBlacklist>;
99 FRIEND_TEST_ALL_PREFIXES(GpuBlacklistTest, ChromeVersionEntry);
100 FRIEND_TEST_ALL_PREFIXES(GpuBlacklistTest, CurrentBlacklistValidation);
101 FRIEND_TEST_ALL_PREFIXES(GpuBlacklistTest, UnknownField);
102 FRIEND_TEST_ALL_PREFIXES(GpuBlacklistTest, UnknownExceptionField);
103 FRIEND_TEST_ALL_PREFIXES(GpuBlacklistTest, UnknownFeature);
104
105 enum BrowserVersionSupport {
106 kSupported,
107 kUnsupported,
108 kMalformed
109 };
110
111 enum NumericOp {
112 kBetween, // <= * <=
113 kEQ, // =
114 kLT, // <
115 kLE, // <=
116 kGT, // >
117 kGE, // >=
118 kAny,
119 kUnknown // Indicates the data is invalid.
120 };
121
122 class VersionInfo {
123 public:
124 // If version_style is empty, it defaults to kNumerical.
125 VersionInfo(const std::string& version_op,
126 const std::string& version_style,
127 const std::string& version_string,
128 const std::string& version_string2);
129 ~VersionInfo();
130
131 // Determines if a given version is included in the VersionInfo range.
132 bool Contains(const Version& version) const;
133
134 // Determine if the version_style is lexical.
135 bool IsLexical() const;
136
137 // Determines if the VersionInfo contains valid information.
138 bool IsValid() const;
139
140 private:
141 enum VersionStyle {
142 kVersionStyleNumerical,
143 kVersionStyleLexical,
144 kVersionStyleUnknown
145 };
146
147 static VersionStyle StringToVersionStyle(const std::string& version_style);
148
149 NumericOp op_;
150 VersionStyle version_style_;
151 scoped_ptr<Version> version_;
152 scoped_ptr<Version> version2_;
153 };
154
155 class OsInfo {
156 public:
157 OsInfo(const std::string& os,
158 const std::string& version_op,
159 const std::string& version_string,
160 const std::string& version_string2);
161 ~OsInfo();
162
163 // Determines if a given os/version is included in the OsInfo set.
164 bool Contains(OsType type, const Version& version) const;
165
166 // Determines if the VersionInfo contains valid information.
167 bool IsValid() const;
168
169 OsType type() const;
170
171 // Maps string to OsType; returns kOsUnknown if it's not a valid os.
172 static OsType StringToOsType(const std::string& os);
173
174 private:
175 OsType type_;
176 scoped_ptr<VersionInfo> version_info_;
177 };
178
179 class StringInfo {
180 public:
181 StringInfo(const std::string& string_op, const std::string& string_value);
182
183 // Determines if a given string is included in the StringInfo.
184 bool Contains(const std::string& value) const;
185
186 // Determines if the StringInfo contains valid information.
187 bool IsValid() const;
188
189 private:
190 enum Op {
191 kContains,
192 kBeginWith,
193 kEndWith,
194 kEQ, // =
195 kUnknown // Indicates StringInfo data is invalid.
196 };
197
198 // Maps string to Op; returns kUnknown if it's not a valid Op.
199 static Op StringToOp(const std::string& string_op);
200
201 Op op_;
202 std::string value_;
203 };
204
205 class FloatInfo {
206 public:
207 FloatInfo(const std::string& float_op,
208 const std::string& float_value,
209 const std::string& float_value2);
210
211 // Determines if a given float is included in the FloatInfo.
212 bool Contains(float value) const;
213
214 // Determines if the FloatInfo contains valid information.
215 bool IsValid() const;
216
217 private:
218 NumericOp op_;
219 float value_;
220 float value2_;
221 };
222
223 class GpuBlacklistEntry;
224 typedef scoped_refptr<GpuBlacklistEntry> ScopedGpuBlacklistEntry;
225
226 class GpuBlacklistEntry : public base::RefCounted<GpuBlacklistEntry> {
227 public:
228 // Constructs GpuBlacklistEntry from DictionaryValue loaded from json.
229 // Top-level entry must have an id number. Others are exceptions.
230 static ScopedGpuBlacklistEntry GetGpuBlacklistEntryFromValue(
231 const base::DictionaryValue* value, bool top_level);
232
233 // Determines if a given os/gc/driver is included in the Entry set.
234 bool Contains(OsType os_type,
235 const Version& os_version,
236 const content::GPUInfo& gpu_info) const;
237
238 // Returns the OsType.
239 OsType GetOsType() const;
240
241 // Returns the entry's unique id. 0 is reserved.
242 uint32 id() const;
243
244 // Returns whether the entry is disabled.
245 bool disabled() const;
246
247 // Returns the description of the entry
248 const std::string& description() const { return description_; }
249
250 // Returns a list of Chromium and Webkit bugs applicable to this entry
251 const std::vector<int>& cr_bugs() const { return cr_bugs_; }
252 const std::vector<int>& webkit_bugs() const { return webkit_bugs_; }
253
254 // Returns the GpuFeatureType.
255 content::GpuFeatureType GetGpuFeatureType() const;
256
257 // Returns true if an unknown field is encountered.
258 bool contains_unknown_fields() const {
259 return contains_unknown_fields_;
260 }
261 // Returns true if an unknown blacklist feature is encountered.
262 bool contains_unknown_features() const {
263 return contains_unknown_features_;
264 }
265
266 private:
267 friend class base::RefCounted<GpuBlacklistEntry>;
268
269 enum MultiGpuStyle {
270 kMultiGpuStyleOptimus,
271 kMultiGpuStyleAMDSwitchable,
272 kMultiGpuStyleNone
273 };
274
275 enum MultiGpuCategory {
276 kMultiGpuCategoryPrimary,
277 kMultiGpuCategorySecondary,
278 kMultiGpuCategoryAny,
279 kMultiGpuCategoryNone
280 };
281
282 GpuBlacklistEntry();
283 ~GpuBlacklistEntry();
284
285 bool SetId(uint32 id);
286
287 void SetDisabled(bool disabled);
288
289 bool SetOsInfo(const std::string& os,
290 const std::string& version_op,
291 const std::string& version_string,
292 const std::string& version_string2);
293
294 bool SetVendorId(const std::string& vendor_id_string);
295
296 bool AddDeviceId(const std::string& device_id_string);
297
298 bool SetMultiGpuStyle(const std::string& multi_gpu_style_string);
299
300 bool SetMultiGpuCategory(const std::string& multi_gpu_category_string);
301
302 bool SetDriverVendorInfo(const std::string& vendor_op,
303 const std::string& vendor_value);
304
305 bool SetDriverVersionInfo(const std::string& version_op,
306 const std::string& version_style,
307 const std::string& version_string,
308 const std::string& version_string2);
309
310 bool SetDriverDateInfo(const std::string& date_op,
311 const std::string& date_string,
312 const std::string& date_string2);
313
314 bool SetGLVendorInfo(const std::string& vendor_op,
315 const std::string& vendor_value);
316
317 bool SetGLRendererInfo(const std::string& renderer_op,
318 const std::string& renderer_value);
319
320 bool SetPerfGraphicsInfo(const std::string& op,
321 const std::string& float_string,
322 const std::string& float_string2);
323
324 bool SetPerfGamingInfo(const std::string& op,
325 const std::string& float_string,
326 const std::string& float_string2);
327
328 bool SetPerfOverallInfo(const std::string& op,
329 const std::string& float_string,
330 const std::string& float_string2);
331
332 bool SetBlacklistedFeatures(
333 const std::vector<std::string>& blacklisted_features);
334
335 void AddException(ScopedGpuBlacklistEntry exception);
336
337 static MultiGpuStyle StringToMultiGpuStyle(const std::string& style);
338
339 static MultiGpuCategory StringToMultiGpuCategory(
340 const std::string& category);
341
342 uint32 id_;
343 bool disabled_;
344 std::string description_;
345 std::vector<int> cr_bugs_;
346 std::vector<int> webkit_bugs_;
347 scoped_ptr<OsInfo> os_info_;
348 uint32 vendor_id_;
349 std::vector<uint32> device_id_list_;
350 MultiGpuStyle multi_gpu_style_;
351 MultiGpuCategory multi_gpu_category_;
352 scoped_ptr<StringInfo> driver_vendor_info_;
353 scoped_ptr<VersionInfo> driver_version_info_;
354 scoped_ptr<VersionInfo> driver_date_info_;
355 scoped_ptr<StringInfo> gl_vendor_info_;
356 scoped_ptr<StringInfo> gl_renderer_info_;
357 scoped_ptr<FloatInfo> perf_graphics_info_;
358 scoped_ptr<FloatInfo> perf_gaming_info_;
359 scoped_ptr<FloatInfo> perf_overall_info_;
360 content::GpuFeatureType feature_type_;
361 std::vector<ScopedGpuBlacklistEntry> exceptions_;
362 bool contains_unknown_fields_;
363 bool contains_unknown_features_;
364 };
365
366 // Gets the current OS type.
367 static OsType GetOsType();
368
369 GpuBlacklist();
370
371 bool LoadGpuBlacklist(const std::string& browser_version_string,
372 const std::string& json_context,
373 OsFilter os_filter);
374
375 bool LoadGpuBlacklist(const base::DictionaryValue& parsed_json,
376 OsFilter os_filter);
377
378 void Clear();
379
380 // Check if the entry is supported by the current version of browser.
381 // By default, if there is no browser version information in the entry,
382 // return kSupported;
383 BrowserVersionSupport IsEntrySupportedByCurrentBrowserVersion(
384 const base::DictionaryValue* value);
385
386 // GpuDataManager::Observer implementation.
387 virtual void OnGpuInfoUpdate() OVERRIDE;
388 virtual void OnVideoMemoryUsageStatsUpdate(
389 const content::GPUVideoMemoryUsageStats& video_memory) OVERRIDE {}
390
391 // Returns the number of entries. This is only for tests.
392 size_t num_entries() const;
393
394 // Check if any entries contain unknown fields. This is only for tests.
395 bool contains_unknown_fields() const { return contains_unknown_fields_; }
396
397 static NumericOp StringToNumericOp(const std::string& op);
398
399 scoped_ptr<Version> version_;
400 std::vector<ScopedGpuBlacklistEntry> blacklist_;
401
402 scoped_ptr<Version> browser_version_;
403
404 // This records all the blacklist entries that are appliable to the current
405 // user machine. It is updated everytime DetermineGpuFeatureType() is
406 // called and is used later by GetGpuFeatureTypeEntries().
407 std::vector<ScopedGpuBlacklistEntry> active_entries_;
408
409 uint32 max_entry_id_;
410
411 bool contains_unknown_fields_;
412
413 DISALLOW_COPY_AND_ASSIGN(GpuBlacklist);
414 };
415
416 #endif // CHROME_BROWSER_GPU_BLACKLIST_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/webstore_private/webstore_private_apitest.cc ('k') | chrome/browser/gpu_blacklist.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698