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

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

Issue 5612002: Blacklist bad GPU drivers: currenly we disable all gpu related features if th... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Fixed the unittest issues. Created 10 years 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) 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 // A valid gpu_blacklist.json file are in the format of
11 // {
12 // "entries": [
13 // { // entry 1
14 // },
15 // ...
16 // { // entry n
17 // }
18 // ]
19 // }
20 // Each entry contains the following fields:
21 // "os", "vendor_id", "device_id", "driver_version", and "blacklist".
22 // Only "blacklist" is mandatory.
23 // 1. "os" contains "type" and an optional "version". "type" could be "macosx",
24 // "linux", "win", or "any". "any" is the same as not specifying "os".
25 // "version" is a VERSION structure (defined later).
26 // 2. "vendor_id" has the value of a string.
27 // 3. "device_id" has the value of a string.
28 // 4. "driver_version" is a VERSION structure (defined later).
29 // 5. "blacklist" is a list of gpu feature strings, valid values include
30 // "accelerated_2d_canvas", "accelerated_compositing", "webgl" (might be
31 // expanded in the future).
vangelis 2010/12/10 18:17:24 Should we add an "all" feature that turns off ever
32 // VERSION includes "op" "number", and "number2". "op" can be any of the
33 // following value: "=", "<", "<=", ">", ">=", "any", "between". "number2" is
34 // only used if "op" is "between". "number" is used for all "op" values except
35 // "any". "number" and "number2" are in the format of x, x.x, x.x.x, ect.
36 // Check out "gpu_blacklist_unittest.cc" for examples.
37
38 #include <string>
39 #include <vector>
40
41 #include "base/basictypes.h"
42 #include "base/scoped_ptr.h"
43 #include "chrome/common/gpu_feature_flags.h"
44
45 class DictionaryValue;
46 class GPUInfo;
47 class Version;
48
49 class GpuBlacklist {
50 public:
51 enum OsType {
52 kOsLinux,
53 kOsMacosx,
54 kOsWin,
55 kOsAny,
56 kOsUnknown
57 };
58
59 GpuBlacklist();
60 ~GpuBlacklist();
61
62 // Loads blacklist information from a json file.
63 // current_os_only==true indicates all blacklist entries that don't belong to
64 // the current OS are discarded; current_os_only==false should only be used
65 // for testing purpose.
66 // If failed, the current GpuBlacklist is un-touched.
67 bool LoadGpuBlacklist(const std::string& json_context,
68 bool current_os_only);
69
70 // Collects system information and combines them with gpu_info and blacklist
71 // information to determine gpu feature flags.
72 // If os is kOsAny, use the current OS; if os_version is null, use the
73 // current OS version.
74 GpuFeatureFlags DetermineGpuFeatureFlags(OsType os,
75 Version* os_version,
76 const GPUInfo& gpu_info) const;
77
78 private:
79 class VersionInfo {
80 public:
81 VersionInfo(const std::string& version_op,
82 const std::string& version_string,
83 const std::string& version_string2);
84 ~VersionInfo();
85
86 // Determines if a given version is included in the VersionInfo range.
87 bool Contains(const Version& version) const;
88
89 // Determines if the VersionInfo contains valid information.
90 bool IsValid() const;
91
92 private:
93 enum Op {
94 kBetween, // <= * <=
95 kEQ, // =
96 kLT, // <
97 kLE, // <=
98 kGT, // >
99 kGE, // >=
100 kAny,
101 kUnknown // Indicates VersionInfo data is invalid.
102 };
103
104 // Maps string to Op; returns kUnknown if it's not a valid Op.
105 static Op StringToOp(const std::string& version_op);
106
107 Op op_;
108 scoped_ptr<Version> version_;
109 scoped_ptr<Version> version2_;
110 };
111
112 class OsInfo {
113 public:
114 OsInfo(const std::string& os,
115 const std::string& version_op,
116 const std::string& version_string,
117 const std::string& version_string2);
118
119 // Determines if a given os/version is included in the OsInfo set.
120 bool Contains(OsType type, const Version& version) const;
121
122 // Determines if the VersionInfo contains valid information.
123 bool IsValid() const;
124
125 OsType type() const;
126
127 // Maps string to OsType; returns kOsUnknown if it's not a valid os.
128 static OsType StringToOsType(const std::string& os);
129
130 private:
131 OsType type_;
132 scoped_ptr<VersionInfo> version_info_;
133 };
134
135 class GpuBlacklistEntry {
136 public:
137 // Constructs GpuBlacklistEntry from DictionaryValue loaded from json.
138 static GpuBlacklistEntry* GetGpuBlacklistEntryFromValue(
139 DictionaryValue* value);
140
141 // Determines if a given os/gc/driver is included in the Entry set.
142 bool Contains(OsType os_type, const Version& os_version,
143 uint32 vendor_id, uint32 device_id,
144 const Version& driver_version) const;
145
146 // Returns the OsType.
147 OsType GetOsType() const;
148
149 // Returns the GpuFeatureFlags.
150 GpuFeatureFlags GetGpuFeatureFlags() const;
151
152 private:
153 GpuBlacklistEntry();
154
155 bool SetOsInfo(const std::string& os,
156 const std::string& version_op,
157 const std::string& version_string,
158 const std::string& version_string2);
159
160 bool SetVendorId(const std::string& vendor_id_string);
161
162 bool SetDeviceId(const std::string& device_id_string);
163
164 bool SetDriverVersionInfo(const std::string& version_op,
165 const std::string& version_string,
166 const std::string& version_string2);
167
168 bool SetBlacklistedFeatures(
169 const std::vector<std::string>& blacklisted_features);
170
171 scoped_ptr<OsInfo> os_info_;
172 uint32 vendor_id_;
173 uint32 device_id_;
174 scoped_ptr<VersionInfo> driver_version_info_;
175 scoped_ptr<GpuFeatureFlags> feature_flags_;
176 };
177
178 // Gets the current OS type.
179 static OsType GetOsType();
180
181 void Clear();
182
183 std::vector<GpuBlacklistEntry*> blacklist_;
184
185 DISALLOW_COPY_AND_ASSIGN(GpuBlacklist);
186 };
187
188 #endif // CHROME_BROWSER_GPU_BLACKLIST_H_
189
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698