Chromium Code Reviews| 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/libXNVCtrl/NVCtrl.h" | |
| 22 #include "third_party/libXNVCtrl/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(); | |
| 175 if (!display) { | |
| 176 LOG(ERROR) << "XOpenDisplay failed."; | |
| 177 return ""; | |
|
jam
2012/06/21 21:33:57
nit: here and below, prefer return std::string()
Zhenyao Mo
2012/06/21 22:30:51
Done.
| |
| 178 } | |
| 179 int event_base = 0, error_base = 0; | |
| 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 = NULL; | |
| 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 fprintf(stderr, "%s\n\n\n", driver_version.c_str()); | |
|
jam
2012/06/21 21:33:57
nit: spacing
Zhenyao Mo
2012/06/21 22:30:51
this line is for local debugging purpose. removed
| |
| 248 } | |
| 249 break; | |
| 208 } | 250 } |
| 209 | 251 |
| 210 return rt; | 252 return rt; |
| 211 } | 253 } |
| 212 | 254 |
| 213 bool CollectVideoCardInfo(content::GPUInfo* gpu_info) { | 255 bool CollectVideoCardInfo(content::GPUInfo* gpu_info) { |
| 214 DCHECK(gpu_info); | 256 DCHECK(gpu_info); |
| 215 | 257 |
| 216 if (IsPciSupported() == false) { | 258 if (IsPciSupported() == false) { |
| 217 VLOG(1) << "PCI bus scanning is not supported"; | 259 VLOG(1) << "PCI bus scanning is not supported"; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 321 return false; | 363 return false; |
| 322 if (pos != std::string::npos) | 364 if (pos != std::string::npos) |
| 323 driver_version = driver_version.substr(0, pos); | 365 driver_version = driver_version.substr(0, pos); |
| 324 | 366 |
| 325 gpu_info->driver_vendor = pieces[1]; | 367 gpu_info->driver_vendor = pieces[1]; |
| 326 gpu_info->driver_version = driver_version; | 368 gpu_info->driver_version = driver_version; |
| 327 return true; | 369 return true; |
| 328 } | 370 } |
| 329 | 371 |
| 330 } // namespace gpu_info_collector | 372 } // namespace gpu_info_collector |
| OLD | NEW |