OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/gpu/gpu_info_collector.h" | 5 #include "content/gpu/gpu_info_collector.h" |
6 | 6 |
7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
8 #include <X11/Xlib.h> | |
8 #include <vector> | 9 #include <vector> |
9 | 10 |
10 #include "base/command_line.h" | 11 #include "base/command_line.h" |
11 #include "base/debug/trace_event.h" | 12 #include "base/debug/trace_event.h" |
12 #include "base/file_util.h" | 13 #include "base/file_util.h" |
13 #include "base/logging.h" | 14 #include "base/logging.h" |
14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/message_loop.h" | |
15 #include "base/string_piece.h" | 17 #include "base/string_piece.h" |
16 #include "base/string_split.h" | 18 #include "base/string_split.h" |
17 #include "base/string_tokenizer.h" | 19 #include "base/string_tokenizer.h" |
18 #include "base/string_util.h" | 20 #include "base/string_util.h" |
21 #include "third_party/nvidia/NVCtrl.h" | |
22 #include "third_party/nvidia/NVCtrlLib.h" | |
19 #include "ui/gl/gl_bindings.h" | 23 #include "ui/gl/gl_bindings.h" |
20 #include "ui/gl/gl_context.h" | 24 #include "ui/gl/gl_context.h" |
21 #include "ui/gl/gl_implementation.h" | 25 #include "ui/gl/gl_implementation.h" |
22 #include "ui/gl/gl_surface.h" | 26 #include "ui/gl/gl_surface.h" |
23 #include "ui/gl/gl_switches.h" | 27 #include "ui/gl/gl_switches.h" |
24 | 28 |
25 namespace { | 29 namespace { |
26 | 30 |
27 // PciDevice and PciAccess are defined to access libpci functions. Their | 31 // PciDevice and PciAccess are defined to access libpci functions. Their |
28 // members match the corresponding structures defined by libpci in size up to | 32 // members match the corresponding structures defined by libpci in size up to |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
158 if (end == std::string::npos) | 162 if (end == std::string::npos) |
159 return line.substr(begin); | 163 return line.substr(begin); |
160 else | 164 else |
161 return line.substr(begin, end - begin); | 165 return line.substr(begin, end - begin); |
162 } | 166 } |
163 } | 167 } |
164 } | 168 } |
165 return ""; | 169 return ""; |
166 } | 170 } |
167 | 171 |
172 // Use NVCtrl extention to query NV driver version. | |
173 std::string CollectDriverVersionNVidia() { | |
174 Display* display = base::MessagePumpForUI::GetDefaultXDisplay(); | |
Ken Russell (switch to Gerrit)
2012/06/21 00:30:54
Please make sure there is an assertion somewhere (
Zhenyao Mo
2012/06/21 00:45:43
Done.
| |
175 if (!display) { | |
176 LOG(ERROR) << "XOpenDisplay failed."; | |
177 return ""; | |
178 } | |
179 int event_base, error_base; | |
piman
2012/06/21 00:08:32
nit: =0
Zhenyao Mo
2012/06/21 00:45:43
Done.
| |
180 if (!XNVCTRLQueryExtension(display, &event_base, &error_base)) { | |
181 LOG(INFO) << "NVCtrl extension does not exits."; | |
182 return ""; | |
183 } | |
184 int screen_count = ScreenCount(display); | |
185 for (int screen = 0; screen < screen_count; ++screen) { | |
186 char* buffer; | |
187 if (XNVCTRLIsNvScreen(display, screen) && | |
188 XNVCTRLQueryStringAttribute(display, screen, 0, | |
189 NV_CTRL_STRING_NVIDIA_DRIVER_VERSION, | |
190 &buffer)) { | |
191 std::string driver_version(buffer); | |
192 XFree(buffer); | |
193 return driver_version; | |
194 } | |
195 } | |
196 return ""; | |
197 } | |
198 | |
168 const uint32 kVendorIDIntel = 0x8086; | 199 const uint32 kVendorIDIntel = 0x8086; |
169 const uint32 kVendorIDNVidia = 0x10de; | 200 const uint32 kVendorIDNVidia = 0x10de; |
170 const uint32 kVendorIDAMD = 0x1002; | 201 const uint32 kVendorIDAMD = 0x1002; |
171 | 202 |
172 } // namespace anonymous | 203 } // namespace anonymous |
173 | 204 |
174 namespace gpu_info_collector { | 205 namespace gpu_info_collector { |
175 | 206 |
176 bool CollectGraphicsInfo(content::GPUInfo* gpu_info) { | 207 bool CollectGraphicsInfo(content::GPUInfo* gpu_info) { |
177 DCHECK(gpu_info); | 208 DCHECK(gpu_info); |
(...skipping 14 matching lines...) Expand all Loading... | |
192 bool rt = CollectGraphicsInfoGL(gpu_info); | 223 bool rt = CollectGraphicsInfoGL(gpu_info); |
193 | 224 |
194 return rt; | 225 return rt; |
195 } | 226 } |
196 | 227 |
197 bool CollectPreliminaryGraphicsInfo(content::GPUInfo* gpu_info) { | 228 bool CollectPreliminaryGraphicsInfo(content::GPUInfo* gpu_info) { |
198 DCHECK(gpu_info); | 229 DCHECK(gpu_info); |
199 | 230 |
200 bool rt = CollectVideoCardInfo(gpu_info); | 231 bool rt = CollectVideoCardInfo(gpu_info); |
201 | 232 |
202 if (gpu_info->gpu.vendor_id == kVendorIDAMD) { | 233 std::string driver_version; |
203 std::string ati_driver_version = CollectDriverVersionATI(); | 234 switch (gpu_info->gpu.vendor_id) { |
204 if (!ati_driver_version.empty()) { | 235 case kVendorIDAMD: |
205 gpu_info->driver_vendor = "ATI / AMD"; | 236 driver_version = CollectDriverVersionATI(); |
206 gpu_info->driver_version = ati_driver_version; | 237 if (!driver_version.empty()) { |
207 } | 238 gpu_info->driver_vendor = "ATI / AMD"; |
239 gpu_info->driver_version = driver_version; | |
240 } | |
241 break; | |
242 case kVendorIDNVidia: | |
243 driver_version = CollectDriverVersionNVidia(); | |
244 if (!driver_version.empty()) { | |
245 gpu_info->driver_vendor = "NVIDIA"; | |
246 gpu_info->driver_version = driver_version; | |
247 } | |
248 break; | |
208 } | 249 } |
209 | 250 |
210 return rt; | 251 return rt; |
211 } | 252 } |
212 | 253 |
213 bool CollectVideoCardInfo(content::GPUInfo* gpu_info) { | 254 bool CollectVideoCardInfo(content::GPUInfo* gpu_info) { |
214 DCHECK(gpu_info); | 255 DCHECK(gpu_info); |
215 | 256 |
216 if (IsPciSupported() == false) { | 257 if (IsPciSupported() == false) { |
217 VLOG(1) << "PCI bus scanning is not supported"; | 258 VLOG(1) << "PCI bus scanning is not supported"; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
321 return false; | 362 return false; |
322 if (pos != std::string::npos) | 363 if (pos != std::string::npos) |
323 driver_version = driver_version.substr(0, pos); | 364 driver_version = driver_version.substr(0, pos); |
324 | 365 |
325 gpu_info->driver_vendor = pieces[1]; | 366 gpu_info->driver_vendor = pieces[1]; |
326 gpu_info->driver_version = driver_version; | 367 gpu_info->driver_version = driver_version; |
327 return true; | 368 return true; |
328 } | 369 } |
329 | 370 |
330 } // namespace gpu_info_collector | 371 } // namespace gpu_info_collector |
OLD | NEW |