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

Side by Side Diff: content/test/gpu/gpu_test_config.cc

Issue 15827008: Move gpu_test_config stuff from content/ to gpu/ (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 6 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
« no previous file with comments | « content/test/gpu/gpu_test_config.h ('k') | content/test/gpu/gpu_test_config_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "content/test/gpu/gpu_test_config.h"
6
7 #include "base/logging.h"
8 #include "base/sys_info.h"
9 #include "content/test/gpu/gpu_test_expectations_parser.h"
10 #include "gpu/config/gpu_info.h"
11 #include "gpu/config/gpu_info_collector.h"
12
13 namespace {
14
15 GPUTestConfig::OS GetCurrentOS() {
16 #if defined(OS_CHROMEOS)
17 return GPUTestConfig::kOsChromeOS;
18 #elif defined(OS_LINUX) || defined(OS_OPENBSD)
19 return GPUTestConfig::kOsLinux;
20 #elif defined(OS_WIN)
21 int32 major_version = 0;
22 int32 minor_version = 0;
23 int32 bugfix_version = 0;
24 base::SysInfo::OperatingSystemVersionNumbers(
25 &major_version, &minor_version, &bugfix_version);
26 if (major_version == 5)
27 return GPUTestConfig::kOsWinXP;
28 if (major_version == 6 && minor_version == 0)
29 return GPUTestConfig::kOsWinVista;
30 if (major_version == 6 && minor_version == 1)
31 return GPUTestConfig::kOsWin7;
32 if (major_version == 6 && minor_version == 2)
33 return GPUTestConfig::kOsWin8;
34 #elif defined(OS_MACOSX)
35 int32 major_version = 0;
36 int32 minor_version = 0;
37 int32 bugfix_version = 0;
38 base::SysInfo::OperatingSystemVersionNumbers(
39 &major_version, &minor_version, &bugfix_version);
40 if (major_version == 10) {
41 switch (minor_version) {
42 case 5:
43 return GPUTestConfig::kOsMacLeopard;
44 case 6:
45 return GPUTestConfig::kOsMacSnowLeopard;
46 case 7:
47 return GPUTestConfig::kOsMacLion;
48 case 8:
49 return GPUTestConfig::kOsMacMountainLion;
50 }
51 }
52 #elif defined(OS_ANDROID)
53 return GPUTestConfig::kOsAndroid;
54 #endif
55 return GPUTestConfig::kOsUnknown;
56 }
57
58 } // namespace anonymous
59
60 GPUTestConfig::GPUTestConfig()
61 : validate_gpu_info_(true),
62 os_(kOsUnknown),
63 gpu_device_id_(0),
64 build_type_(kBuildTypeUnknown) {
65 }
66
67 GPUTestConfig::~GPUTestConfig() {
68 }
69
70 void GPUTestConfig::set_os(int32 os) {
71 DCHECK_EQ(0, os & ~(kOsAndroid | kOsWin | kOsMac | kOsLinux | kOsChromeOS));
72 os_ = os;
73 }
74
75 void GPUTestConfig::AddGPUVendor(uint32 gpu_vendor) {
76 DCHECK_NE(0u, gpu_vendor);
77 for (size_t i = 0; i < gpu_vendor_.size(); ++i)
78 DCHECK_NE(gpu_vendor_[i], gpu_vendor);
79 gpu_vendor_.push_back(gpu_vendor);
80 }
81
82 void GPUTestConfig::set_gpu_device_id(uint32 id) {
83 gpu_device_id_ = id;
84 }
85
86 void GPUTestConfig::set_build_type(int32 build_type) {
87 DCHECK_EQ(0, build_type & ~(kBuildTypeRelease | kBuildTypeDebug));
88 build_type_ = build_type;
89 }
90
91 bool GPUTestConfig::IsValid() const {
92 if (!validate_gpu_info_)
93 return true;
94 if (gpu_device_id_ != 0 && (gpu_vendor_.size() != 1 || gpu_vendor_[0] == 0))
95 return false;
96 return true;
97 }
98
99 bool GPUTestConfig::OverlapsWith(const GPUTestConfig& config) const {
100 DCHECK(IsValid());
101 DCHECK(config.IsValid());
102 if (config.os_ != kOsUnknown && os_ != kOsUnknown &&
103 (os_ & config.os_) == 0)
104 return false;
105 if (config.gpu_vendor_.size() > 0 && gpu_vendor_.size() > 0) {
106 bool shared = false;
107 for (size_t i = 0; i < config.gpu_vendor_.size() && !shared; ++i) {
108 for (size_t j = 0; j < gpu_vendor_.size(); ++j) {
109 if (config.gpu_vendor_[i] == gpu_vendor_[j]) {
110 shared = true;
111 break;
112 }
113 }
114 }
115 if (!shared)
116 return false;
117 }
118 if (config.gpu_device_id_ != 0 && gpu_device_id_ != 0 &&
119 gpu_device_id_ != config.gpu_device_id_)
120 return false;
121 if (config.build_type_ != kBuildTypeUnknown &&
122 build_type_ != kBuildTypeUnknown &&
123 (build_type_ & config.build_type_) == 0)
124 return false;
125 return true;
126 }
127
128 void GPUTestConfig::DisableGPUInfoValidation() {
129 validate_gpu_info_ = false;
130 }
131
132 void GPUTestConfig::ClearGPUVendor() {
133 gpu_vendor_.clear();
134 }
135
136 GPUTestBotConfig::~GPUTestBotConfig() {
137 }
138
139 void GPUTestBotConfig::AddGPUVendor(uint32 gpu_vendor) {
140 DCHECK_EQ(0u, GPUTestConfig::gpu_vendor().size());
141 GPUTestConfig::AddGPUVendor(gpu_vendor);
142 }
143
144 bool GPUTestBotConfig::SetGPUInfo(const gpu::GPUInfo& gpu_info) {
145 DCHECK(validate_gpu_info_);
146 if (gpu_info.gpu.device_id == 0 || gpu_info.gpu.vendor_id == 0)
147 return false;
148 ClearGPUVendor();
149 AddGPUVendor(gpu_info.gpu.vendor_id);
150 set_gpu_device_id(gpu_info.gpu.device_id);
151 return true;
152 }
153
154 bool GPUTestBotConfig::IsValid() const {
155 switch (os()) {
156 case kOsWinXP:
157 case kOsWinVista:
158 case kOsWin7:
159 case kOsWin8:
160 case kOsMacLeopard:
161 case kOsMacSnowLeopard:
162 case kOsMacLion:
163 case kOsMacMountainLion:
164 case kOsLinux:
165 case kOsChromeOS:
166 case kOsAndroid:
167 break;
168 default:
169 return false;
170 }
171 if (validate_gpu_info_) {
172 if (gpu_vendor().size() != 1 || gpu_vendor()[0] == 0)
173 return false;
174 if (gpu_device_id() == 0)
175 return false;
176 }
177 switch (build_type()) {
178 case kBuildTypeRelease:
179 case kBuildTypeDebug:
180 break;
181 default:
182 return false;
183 }
184 return true;
185 }
186
187 bool GPUTestBotConfig::Matches(const GPUTestConfig& config) const {
188 DCHECK(IsValid());
189 DCHECK(config.IsValid());
190 if (config.os() != kOsUnknown && (os() & config.os()) == 0)
191 return false;
192 if (config.gpu_vendor().size() > 0) {
193 bool contained = false;
194 for (size_t i = 0; i < config.gpu_vendor().size(); ++i) {
195 if (config.gpu_vendor()[i] == gpu_vendor()[0]) {
196 contained = true;
197 break;
198 }
199 }
200 if (!contained)
201 return false;
202 }
203 if (config.gpu_device_id() != 0 &&
204 gpu_device_id() != config.gpu_device_id())
205 return false;
206 if (config.build_type() != kBuildTypeUnknown &&
207 (build_type() & config.build_type()) == 0)
208 return false;
209 return true;
210 }
211
212 bool GPUTestBotConfig::Matches(const std::string& config_data) const {
213 GPUTestExpectationsParser parser;
214 GPUTestConfig config;
215
216 if (!parser.ParseConfig(config_data, &config))
217 return false;
218 return Matches(config);
219 }
220
221 bool GPUTestBotConfig::LoadCurrentConfig(const gpu::GPUInfo* gpu_info) {
222 bool rt;
223 if (gpu_info == NULL) {
224 gpu::GPUInfo my_gpu_info;
225 gpu::GpuIDResult result;
226 result = gpu::CollectGpuID(&my_gpu_info.gpu.vendor_id,
227 &my_gpu_info.gpu.device_id);
228 if (result == gpu::kGpuIDNotSupported) {
229 DisableGPUInfoValidation();
230 rt = true;
231 } else {
232 rt = SetGPUInfo(my_gpu_info);
233 }
234 } else {
235 rt = SetGPUInfo(*gpu_info);
236 }
237 set_os(GetCurrentOS());
238 if (os() == kOsUnknown)
239 rt = false;
240 #if defined(NDEBUG)
241 set_build_type(kBuildTypeRelease);
242 #else
243 set_build_type(kBuildTypeDebug);
244 #endif
245 return rt;
246 }
247
248 // static
249 bool GPUTestBotConfig::CurrentConfigMatches(const std::string& config_data) {
250 GPUTestBotConfig my_config;
251 if (!my_config.LoadCurrentConfig(NULL))
252 return false;
253 return my_config.Matches(config_data);
254 }
255
256 // static
257 bool GPUTestBotConfig::CurrentConfigMatches(
258 const std::vector<std::string>& configs) {
259 GPUTestBotConfig my_config;
260 if (!my_config.LoadCurrentConfig(NULL))
261 return false;
262 for (size_t i = 0 ; i < configs.size(); ++i) {
263 if (my_config.Matches(configs[i]))
264 return true;
265 }
266 return false;
267 }
268
OLDNEW
« no previous file with comments | « content/test/gpu/gpu_test_config.h ('k') | content/test/gpu/gpu_test_config_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698