[Sync] Componentize UIModelWorker.
[chromium-blink-merge.git] / gpu / config / gpu_test_config.cc
blob4605f8987f5aefcdba98738dd1ea6a17fb3b3dff
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.
5 #include "gpu/config/gpu_test_config.h"
7 #include "base/logging.h"
8 #include "base/sys_info.h"
9 #include "gpu/config/gpu_info.h"
10 #include "gpu/config/gpu_info_collector.h"
11 #include "gpu/config/gpu_test_expectations_parser.h"
13 #if defined(OS_MACOSX)
14 #include "base/mac/mac_util.h"
15 #elif defined(OS_WIN)
16 #include "base/win/windows_version.h"
17 #endif
19 namespace gpu {
21 namespace {
23 GPUTestConfig::OS GetCurrentOS() {
24 #if defined(OS_CHROMEOS)
25 return GPUTestConfig::kOsChromeOS;
26 #elif defined(OS_LINUX) || defined(OS_OPENBSD)
27 return GPUTestConfig::kOsLinux;
28 #elif defined(OS_WIN)
29 int32 major_version = 0;
30 int32 minor_version = 0;
31 int32 bugfix_version = 0;
32 base::SysInfo::OperatingSystemVersionNumbers(
33 &major_version, &minor_version, &bugfix_version);
34 if (major_version == 5)
35 return GPUTestConfig::kOsWinXP;
36 if (major_version == 6 && minor_version == 0)
37 return GPUTestConfig::kOsWinVista;
38 if (major_version == 6 && minor_version == 1)
39 return GPUTestConfig::kOsWin7;
40 if (major_version == 6 && (minor_version == 2 || minor_version == 3))
41 return GPUTestConfig::kOsWin8;
42 if (major_version == 10)
43 return GPUTestConfig::kOsWin10;
44 #elif defined(OS_MACOSX)
45 int32 major_version = 0;
46 int32 minor_version = 0;
47 int32 bugfix_version = 0;
48 base::SysInfo::OperatingSystemVersionNumbers(
49 &major_version, &minor_version, &bugfix_version);
50 if (major_version == 10) {
51 switch (minor_version) {
52 case 5:
53 return GPUTestConfig::kOsMacLeopard;
54 case 6:
55 return GPUTestConfig::kOsMacSnowLeopard;
56 case 7:
57 return GPUTestConfig::kOsMacLion;
58 case 8:
59 return GPUTestConfig::kOsMacMountainLion;
60 case 9:
61 return GPUTestConfig::kOsMacMavericks;
62 case 10:
63 return GPUTestConfig::kOsMacYosemite;
66 #elif defined(OS_ANDROID)
67 return GPUTestConfig::kOsAndroid;
68 #endif
69 return GPUTestConfig::kOsUnknown;
72 } // namespace anonymous
74 GPUTestConfig::GPUTestConfig()
75 : validate_gpu_info_(true),
76 os_(kOsUnknown),
77 gpu_device_id_(0),
78 build_type_(kBuildTypeUnknown),
79 api_(kAPIUnknown) {}
81 GPUTestConfig::~GPUTestConfig() {
84 void GPUTestConfig::set_os(int32 os) {
85 DCHECK_EQ(0, os & ~(kOsAndroid | kOsWin | kOsMac | kOsLinux | kOsChromeOS));
86 os_ = os;
89 void GPUTestConfig::AddGPUVendor(uint32 gpu_vendor) {
90 DCHECK_NE(0u, gpu_vendor);
91 for (size_t i = 0; i < gpu_vendor_.size(); ++i)
92 DCHECK_NE(gpu_vendor_[i], gpu_vendor);
93 gpu_vendor_.push_back(gpu_vendor);
96 void GPUTestConfig::set_gpu_device_id(uint32 id) {
97 gpu_device_id_ = id;
100 void GPUTestConfig::set_build_type(int32 build_type) {
101 DCHECK_EQ(0, build_type & ~(kBuildTypeRelease | kBuildTypeDebug));
102 build_type_ = build_type;
105 void GPUTestConfig::set_api(int32 api) {
106 DCHECK_EQ(0, api & ~(kAPID3D9 | kAPID3D11 | kAPIGLDesktop | kAPIGLES));
107 api_ = api;
110 bool GPUTestConfig::IsValid() const {
111 if (!validate_gpu_info_)
112 return true;
113 if (gpu_device_id_ != 0 && (gpu_vendor_.size() != 1 || gpu_vendor_[0] == 0))
114 return false;
115 return true;
118 bool GPUTestConfig::OverlapsWith(const GPUTestConfig& config) const {
119 DCHECK(IsValid());
120 DCHECK(config.IsValid());
121 if (config.os_ != kOsUnknown && os_ != kOsUnknown &&
122 (os_ & config.os_) == 0)
123 return false;
124 if (config.gpu_vendor_.size() > 0 && gpu_vendor_.size() > 0) {
125 bool shared = false;
126 for (size_t i = 0; i < config.gpu_vendor_.size() && !shared; ++i) {
127 for (size_t j = 0; j < gpu_vendor_.size(); ++j) {
128 if (config.gpu_vendor_[i] == gpu_vendor_[j]) {
129 shared = true;
130 break;
134 if (!shared)
135 return false;
137 if (config.gpu_device_id_ != 0 && gpu_device_id_ != 0 &&
138 gpu_device_id_ != config.gpu_device_id_)
139 return false;
140 if (config.build_type_ != kBuildTypeUnknown &&
141 build_type_ != kBuildTypeUnknown &&
142 (build_type_ & config.build_type_) == 0)
143 return false;
144 return true;
147 void GPUTestConfig::DisableGPUInfoValidation() {
148 validate_gpu_info_ = false;
151 void GPUTestConfig::ClearGPUVendor() {
152 gpu_vendor_.clear();
155 GPUTestBotConfig::~GPUTestBotConfig() {
158 void GPUTestBotConfig::AddGPUVendor(uint32 gpu_vendor) {
159 DCHECK_EQ(0u, GPUTestConfig::gpu_vendor().size());
160 GPUTestConfig::AddGPUVendor(gpu_vendor);
163 bool GPUTestBotConfig::SetGPUInfo(const GPUInfo& gpu_info) {
164 DCHECK(validate_gpu_info_);
165 if (gpu_info.gpu.device_id == 0 || gpu_info.gpu.vendor_id == 0)
166 return false;
167 ClearGPUVendor();
168 AddGPUVendor(gpu_info.gpu.vendor_id);
169 set_gpu_device_id(gpu_info.gpu.device_id);
170 return true;
173 bool GPUTestBotConfig::IsValid() const {
174 switch (os()) {
175 case kOsWinXP:
176 case kOsWinVista:
177 case kOsWin7:
178 case kOsWin8:
179 case kOsWin10:
180 case kOsMacLeopard:
181 case kOsMacSnowLeopard:
182 case kOsMacLion:
183 case kOsMacMountainLion:
184 case kOsMacMavericks:
185 case kOsMacYosemite:
186 case kOsLinux:
187 case kOsChromeOS:
188 case kOsAndroid:
189 break;
190 default:
191 return false;
193 if (validate_gpu_info_) {
194 if (gpu_vendor().size() != 1 || gpu_vendor()[0] == 0)
195 return false;
196 if (gpu_device_id() == 0)
197 return false;
199 switch (build_type()) {
200 case kBuildTypeRelease:
201 case kBuildTypeDebug:
202 break;
203 default:
204 return false;
206 return true;
209 bool GPUTestBotConfig::Matches(const GPUTestConfig& config) const {
210 DCHECK(IsValid());
211 DCHECK(config.IsValid());
212 if (config.os() != kOsUnknown && (os() & config.os()) == 0)
213 return false;
214 if (config.gpu_vendor().size() > 0) {
215 bool contained = false;
216 for (size_t i = 0; i < config.gpu_vendor().size(); ++i) {
217 if (config.gpu_vendor()[i] == gpu_vendor()[0]) {
218 contained = true;
219 break;
222 if (!contained)
223 return false;
225 if (config.gpu_device_id() != 0 &&
226 gpu_device_id() != config.gpu_device_id())
227 return false;
228 if (config.build_type() != kBuildTypeUnknown &&
229 (build_type() & config.build_type()) == 0)
230 return false;
231 if (config.api() != 0 && (api() & config.api()) == 0)
232 return false;
233 return true;
236 bool GPUTestBotConfig::Matches(const std::string& config_data) const {
237 GPUTestExpectationsParser parser;
238 GPUTestConfig config;
240 if (!parser.ParseConfig(config_data, &config))
241 return false;
242 return Matches(config);
245 bool GPUTestBotConfig::LoadCurrentConfig(const GPUInfo* gpu_info) {
246 bool rt;
247 if (gpu_info == NULL) {
248 GPUInfo my_gpu_info;
249 CollectInfoResult result = CollectGpuID(
250 &my_gpu_info.gpu.vendor_id, &my_gpu_info.gpu.device_id);
251 if (result != kCollectInfoSuccess) {
252 LOG(ERROR) << "Fail to identify GPU";
253 DisableGPUInfoValidation();
254 rt = true;
255 } else {
256 rt = SetGPUInfo(my_gpu_info);
258 } else {
259 rt = SetGPUInfo(*gpu_info);
261 set_os(GetCurrentOS());
262 if (os() == kOsUnknown) {
263 LOG(ERROR) << "Unknown OS";
264 rt = false;
266 #if defined(NDEBUG)
267 set_build_type(kBuildTypeRelease);
268 #else
269 set_build_type(kBuildTypeDebug);
270 #endif
271 return rt;
274 // static
275 bool GPUTestBotConfig::CurrentConfigMatches(const std::string& config_data) {
276 GPUTestBotConfig my_config;
277 if (!my_config.LoadCurrentConfig(NULL))
278 return false;
279 return my_config.Matches(config_data);
282 // static
283 bool GPUTestBotConfig::CurrentConfigMatches(
284 const std::vector<std::string>& configs) {
285 GPUTestBotConfig my_config;
286 if (!my_config.LoadCurrentConfig(NULL))
287 return false;
288 for (size_t i = 0 ; i < configs.size(); ++i) {
289 if (my_config.Matches(configs[i]))
290 return true;
292 return false;
295 // static
296 bool GPUTestBotConfig::GpuBlacklistedOnBot() {
297 #if defined(OS_MACOSX)
298 // Blacklist rule #81 disables all Gpu acceleration on Mac < 10.8 bots.
299 if (CurrentConfigMatches("MAC VMWARE") && base::mac::IsOSLionOrEarlier()) {
300 return true;
302 #elif defined(OS_WIN)
303 // Blacklist rule #79 disables all Gpu acceleration before Windows 7.
304 if (base::win::GetVersion() <= base::win::VERSION_VISTA) {
305 return true;
307 #endif
308 return false;
311 } // namespace gpu