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