Initialize CompositorDependencies in RenderWidget's constructor.
[chromium-blink-merge.git] / gpu / config / gpu_test_config.cc
blobc062c4da73c040fe95b4d1cf88e8ff2e94f43db0
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 #elif defined(OS_MACOSX)
43 int32 major_version = 0;
44 int32 minor_version = 0;
45 int32 bugfix_version = 0;
46 base::SysInfo::OperatingSystemVersionNumbers(
47 &major_version, &minor_version, &bugfix_version);
48 if (major_version == 10) {
49 switch (minor_version) {
50 case 5:
51 return GPUTestConfig::kOsMacLeopard;
52 case 6:
53 return GPUTestConfig::kOsMacSnowLeopard;
54 case 7:
55 return GPUTestConfig::kOsMacLion;
56 case 8:
57 return GPUTestConfig::kOsMacMountainLion;
58 case 9:
59 return GPUTestConfig::kOsMacMavericks;
60 case 10:
61 return GPUTestConfig::kOsMacYosemite;
64 #elif defined(OS_ANDROID)
65 return GPUTestConfig::kOsAndroid;
66 #endif
67 return GPUTestConfig::kOsUnknown;
70 } // namespace anonymous
72 GPUTestConfig::GPUTestConfig()
73 : validate_gpu_info_(true),
74 os_(kOsUnknown),
75 gpu_device_id_(0),
76 build_type_(kBuildTypeUnknown) {
79 GPUTestConfig::~GPUTestConfig() {
82 void GPUTestConfig::set_os(int32 os) {
83 DCHECK_EQ(0, os & ~(kOsAndroid | kOsWin | kOsMac | kOsLinux | kOsChromeOS));
84 os_ = os;
87 void GPUTestConfig::AddGPUVendor(uint32 gpu_vendor) {
88 DCHECK_NE(0u, gpu_vendor);
89 for (size_t i = 0; i < gpu_vendor_.size(); ++i)
90 DCHECK_NE(gpu_vendor_[i], gpu_vendor);
91 gpu_vendor_.push_back(gpu_vendor);
94 void GPUTestConfig::set_gpu_device_id(uint32 id) {
95 gpu_device_id_ = id;
98 void GPUTestConfig::set_build_type(int32 build_type) {
99 DCHECK_EQ(0, build_type & ~(kBuildTypeRelease | kBuildTypeDebug));
100 build_type_ = build_type;
103 bool GPUTestConfig::IsValid() const {
104 if (!validate_gpu_info_)
105 return true;
106 if (gpu_device_id_ != 0 && (gpu_vendor_.size() != 1 || gpu_vendor_[0] == 0))
107 return false;
108 return true;
111 bool GPUTestConfig::OverlapsWith(const GPUTestConfig& config) const {
112 DCHECK(IsValid());
113 DCHECK(config.IsValid());
114 if (config.os_ != kOsUnknown && os_ != kOsUnknown &&
115 (os_ & config.os_) == 0)
116 return false;
117 if (config.gpu_vendor_.size() > 0 && gpu_vendor_.size() > 0) {
118 bool shared = false;
119 for (size_t i = 0; i < config.gpu_vendor_.size() && !shared; ++i) {
120 for (size_t j = 0; j < gpu_vendor_.size(); ++j) {
121 if (config.gpu_vendor_[i] == gpu_vendor_[j]) {
122 shared = true;
123 break;
127 if (!shared)
128 return false;
130 if (config.gpu_device_id_ != 0 && gpu_device_id_ != 0 &&
131 gpu_device_id_ != config.gpu_device_id_)
132 return false;
133 if (config.build_type_ != kBuildTypeUnknown &&
134 build_type_ != kBuildTypeUnknown &&
135 (build_type_ & config.build_type_) == 0)
136 return false;
137 return true;
140 void GPUTestConfig::DisableGPUInfoValidation() {
141 validate_gpu_info_ = false;
144 void GPUTestConfig::ClearGPUVendor() {
145 gpu_vendor_.clear();
148 GPUTestBotConfig::~GPUTestBotConfig() {
151 void GPUTestBotConfig::AddGPUVendor(uint32 gpu_vendor) {
152 DCHECK_EQ(0u, GPUTestConfig::gpu_vendor().size());
153 GPUTestConfig::AddGPUVendor(gpu_vendor);
156 bool GPUTestBotConfig::SetGPUInfo(const GPUInfo& gpu_info) {
157 DCHECK(validate_gpu_info_);
158 if (gpu_info.gpu.device_id == 0 || gpu_info.gpu.vendor_id == 0)
159 return false;
160 ClearGPUVendor();
161 AddGPUVendor(gpu_info.gpu.vendor_id);
162 set_gpu_device_id(gpu_info.gpu.device_id);
163 return true;
166 bool GPUTestBotConfig::IsValid() const {
167 switch (os()) {
168 case kOsWinXP:
169 case kOsWinVista:
170 case kOsWin7:
171 case kOsWin8:
172 case kOsMacLeopard:
173 case kOsMacSnowLeopard:
174 case kOsMacLion:
175 case kOsMacMountainLion:
176 case kOsMacMavericks:
177 case kOsMacYosemite:
178 case kOsLinux:
179 case kOsChromeOS:
180 case kOsAndroid:
181 break;
182 default:
183 return false;
185 if (validate_gpu_info_) {
186 if (gpu_vendor().size() != 1 || gpu_vendor()[0] == 0)
187 return false;
188 if (gpu_device_id() == 0)
189 return false;
191 switch (build_type()) {
192 case kBuildTypeRelease:
193 case kBuildTypeDebug:
194 break;
195 default:
196 return false;
198 return true;
201 bool GPUTestBotConfig::Matches(const GPUTestConfig& config) const {
202 DCHECK(IsValid());
203 DCHECK(config.IsValid());
204 if (config.os() != kOsUnknown && (os() & config.os()) == 0)
205 return false;
206 if (config.gpu_vendor().size() > 0) {
207 bool contained = false;
208 for (size_t i = 0; i < config.gpu_vendor().size(); ++i) {
209 if (config.gpu_vendor()[i] == gpu_vendor()[0]) {
210 contained = true;
211 break;
214 if (!contained)
215 return false;
217 if (config.gpu_device_id() != 0 &&
218 gpu_device_id() != config.gpu_device_id())
219 return false;
220 if (config.build_type() != kBuildTypeUnknown &&
221 (build_type() & config.build_type()) == 0)
222 return false;
223 return true;
226 bool GPUTestBotConfig::Matches(const std::string& config_data) const {
227 GPUTestExpectationsParser parser;
228 GPUTestConfig config;
230 if (!parser.ParseConfig(config_data, &config))
231 return false;
232 return Matches(config);
235 bool GPUTestBotConfig::LoadCurrentConfig(const GPUInfo* gpu_info) {
236 bool rt;
237 if (gpu_info == NULL) {
238 GPUInfo my_gpu_info;
239 CollectInfoResult result = CollectGpuID(
240 &my_gpu_info.gpu.vendor_id, &my_gpu_info.gpu.device_id);
241 if (result != kCollectInfoSuccess) {
242 LOG(ERROR) << "Fail to identify GPU";
243 DisableGPUInfoValidation();
244 rt = true;
245 } else {
246 rt = SetGPUInfo(my_gpu_info);
248 } else {
249 rt = SetGPUInfo(*gpu_info);
251 set_os(GetCurrentOS());
252 if (os() == kOsUnknown) {
253 LOG(ERROR) << "Unknown OS";
254 rt = false;
256 #if defined(NDEBUG)
257 set_build_type(kBuildTypeRelease);
258 #else
259 set_build_type(kBuildTypeDebug);
260 #endif
261 return rt;
264 // static
265 bool GPUTestBotConfig::CurrentConfigMatches(const std::string& config_data) {
266 GPUTestBotConfig my_config;
267 if (!my_config.LoadCurrentConfig(NULL))
268 return false;
269 return my_config.Matches(config_data);
272 // static
273 bool GPUTestBotConfig::CurrentConfigMatches(
274 const std::vector<std::string>& configs) {
275 GPUTestBotConfig my_config;
276 if (!my_config.LoadCurrentConfig(NULL))
277 return false;
278 for (size_t i = 0 ; i < configs.size(); ++i) {
279 if (my_config.Matches(configs[i]))
280 return true;
282 return false;
285 // static
286 bool GPUTestBotConfig::GpuBlacklistedOnBot() {
287 #if defined(OS_MACOSX)
288 // Blacklist rule #81 disables all Gpu acceleration on Mac < 10.8 bots.
289 if (CurrentConfigMatches("MAC VMWARE") && base::mac::IsOSLionOrEarlier()) {
290 return true;
292 #elif defined(OS_WIN)
293 // Blacklist rule #79 disables all Gpu acceleration before Windows 7.
294 if (base::win::GetVersion() <= base::win::VERSION_VISTA) {
295 return true;
297 #endif
298 return false;
301 } // namespace gpu