| 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 | 135 |
| 132 // This close the dynamically opened libpci and delete the interface. | 136 // This close the dynamically opened libpci and delete the interface. |
| 133 void FinalizeLibPci(PciInterface** interface) { | 137 void FinalizeLibPci(PciInterface** interface) { |
| 134 DCHECK(interface && *interface && (*interface)->lib_handle); | 138 DCHECK(interface && *interface && (*interface)->lib_handle); |
| 135 dlclose((*interface)->lib_handle); | 139 dlclose((*interface)->lib_handle); |
| 136 delete (*interface); | 140 delete (*interface); |
| 137 *interface = NULL; | 141 *interface = NULL; |
| 138 } | 142 } |
| 139 | 143 |
| 140 // Scan /etc/ati/amdpcsdb.default for "ReleaseVersion". | 144 // Scan /etc/ati/amdpcsdb.default for "ReleaseVersion". |
| 141 // Return "" on failing. | 145 // Return empty string on failing. |
| 142 std::string CollectDriverVersionATI() { | 146 std::string CollectDriverVersionATI() { |
| 143 const FilePath::CharType kATIFileName[] = | 147 const FilePath::CharType kATIFileName[] = |
| 144 FILE_PATH_LITERAL("/etc/ati/amdpcsdb.default"); | 148 FILE_PATH_LITERAL("/etc/ati/amdpcsdb.default"); |
| 145 FilePath ati_file_path(kATIFileName); | 149 FilePath ati_file_path(kATIFileName); |
| 146 if (!file_util::PathExists(ati_file_path)) | 150 if (!file_util::PathExists(ati_file_path)) |
| 147 return ""; | 151 return std::string(); |
| 148 std::string contents; | 152 std::string contents; |
| 149 if (!file_util::ReadFileToString(ati_file_path, &contents)) | 153 if (!file_util::ReadFileToString(ati_file_path, &contents)) |
| 150 return ""; | 154 return std::string(); |
| 151 StringTokenizer t(contents, "\r\n"); | 155 StringTokenizer t(contents, "\r\n"); |
| 152 while (t.GetNext()) { | 156 while (t.GetNext()) { |
| 153 std::string line = t.token(); | 157 std::string line = t.token(); |
| 154 if (StartsWithASCII(line, "ReleaseVersion=", true)) { | 158 if (StartsWithASCII(line, "ReleaseVersion=", true)) { |
| 155 size_t begin = line.find_first_of("0123456789"); | 159 size_t begin = line.find_first_of("0123456789"); |
| 156 if (begin != std::string::npos) { | 160 if (begin != std::string::npos) { |
| 157 size_t end = line.find_first_not_of("0123456789.", begin); | 161 size_t end = line.find_first_not_of("0123456789.", begin); |
| 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 std::string(); |
| 170 } |
| 171 |
| 172 // Use NVCtrl extention to query NV driver version. |
| 173 // Return empty string on failing. |
| 174 std::string CollectDriverVersionNVidia() { |
| 175 Display* display = base::MessagePumpForUI::GetDefaultXDisplay(); |
| 176 if (!display) { |
| 177 LOG(ERROR) << "XOpenDisplay failed."; |
| 178 return std::string(); |
| 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 std::string(); |
| 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 std::string(); |
| 166 } | 198 } |
| 167 | 199 |
| 168 const uint32 kVendorIDIntel = 0x8086; | 200 const uint32 kVendorIDIntel = 0x8086; |
| 169 const uint32 kVendorIDNVidia = 0x10de; | 201 const uint32 kVendorIDNVidia = 0x10de; |
| 170 const uint32 kVendorIDAMD = 0x1002; | 202 const uint32 kVendorIDAMD = 0x1002; |
| 171 | 203 |
| 172 } // namespace anonymous | 204 } // namespace anonymous |
| 173 | 205 |
| 174 namespace gpu_info_collector { | 206 namespace gpu_info_collector { |
| 175 | 207 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 192 bool rt = CollectGraphicsInfoGL(gpu_info); | 224 bool rt = CollectGraphicsInfoGL(gpu_info); |
| 193 | 225 |
| 194 return rt; | 226 return rt; |
| 195 } | 227 } |
| 196 | 228 |
| 197 bool CollectPreliminaryGraphicsInfo(content::GPUInfo* gpu_info) { | 229 bool CollectPreliminaryGraphicsInfo(content::GPUInfo* gpu_info) { |
| 198 DCHECK(gpu_info); | 230 DCHECK(gpu_info); |
| 199 | 231 |
| 200 bool rt = CollectVideoCardInfo(gpu_info); | 232 bool rt = CollectVideoCardInfo(gpu_info); |
| 201 | 233 |
| 202 if (gpu_info->gpu.vendor_id == kVendorIDAMD) { | 234 std::string driver_version; |
| 203 std::string ati_driver_version = CollectDriverVersionATI(); | 235 switch (gpu_info->gpu.vendor_id) { |
| 204 if (!ati_driver_version.empty()) { | 236 case kVendorIDAMD: |
| 205 gpu_info->driver_vendor = "ATI / AMD"; | 237 driver_version = CollectDriverVersionATI(); |
| 206 gpu_info->driver_version = ati_driver_version; | 238 if (!driver_version.empty()) { |
| 207 } | 239 gpu_info->driver_vendor = "ATI / AMD"; |
| 240 gpu_info->driver_version = driver_version; |
| 241 } |
| 242 break; |
| 243 case kVendorIDNVidia: |
| 244 driver_version = CollectDriverVersionNVidia(); |
| 245 if (!driver_version.empty()) { |
| 246 gpu_info->driver_vendor = "NVIDIA"; |
| 247 gpu_info->driver_version = driver_version; |
| 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 |