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

Unified Diff: content/gpu/gpu_info_collector_linux.cc

Issue 10641006: Use nv contrl x extension to query nvidia driver version. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/gpu/DEPS ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/gpu/gpu_info_collector_linux.cc
===================================================================
--- content/gpu/gpu_info_collector_linux.cc (revision 143407)
+++ content/gpu/gpu_info_collector_linux.cc (working copy)
@@ -5,6 +5,7 @@
#include "content/gpu/gpu_info_collector.h"
#include <dlfcn.h>
+#include <X11/Xlib.h>
#include <vector>
#include "base/command_line.h"
@@ -12,10 +13,13 @@
#include "base/file_util.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
+#include "base/message_loop.h"
#include "base/string_piece.h"
#include "base/string_split.h"
#include "base/string_tokenizer.h"
#include "base/string_util.h"
+#include "third_party/libXNVCtrl/NVCtrl.h"
+#include "third_party/libXNVCtrl/NVCtrlLib.h"
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_context.h"
#include "ui/gl/gl_implementation.h"
@@ -138,16 +142,16 @@
}
// Scan /etc/ati/amdpcsdb.default for "ReleaseVersion".
-// Return "" on failing.
+// Return empty string on failing.
std::string CollectDriverVersionATI() {
const FilePath::CharType kATIFileName[] =
FILE_PATH_LITERAL("/etc/ati/amdpcsdb.default");
FilePath ati_file_path(kATIFileName);
if (!file_util::PathExists(ati_file_path))
- return "";
+ return std::string();
std::string contents;
if (!file_util::ReadFileToString(ati_file_path, &contents))
- return "";
+ return std::string();
StringTokenizer t(contents, "\r\n");
while (t.GetNext()) {
std::string line = t.token();
@@ -162,9 +166,37 @@
}
}
}
- return "";
+ return std::string();
}
+// Use NVCtrl extention to query NV driver version.
+// Return empty string on failing.
+std::string CollectDriverVersionNVidia() {
+ Display* display = base::MessagePumpForUI::GetDefaultXDisplay();
+ if (!display) {
+ LOG(ERROR) << "XOpenDisplay failed.";
+ return std::string();
+ }
+ int event_base = 0, error_base = 0;
+ if (!XNVCTRLQueryExtension(display, &event_base, &error_base)) {
+ LOG(INFO) << "NVCtrl extension does not exits.";
+ return std::string();
+ }
+ int screen_count = ScreenCount(display);
+ for (int screen = 0; screen < screen_count; ++screen) {
+ char* buffer = NULL;
+ if (XNVCTRLIsNvScreen(display, screen) &&
+ XNVCTRLQueryStringAttribute(display, screen, 0,
+ NV_CTRL_STRING_NVIDIA_DRIVER_VERSION,
+ &buffer)) {
+ std::string driver_version(buffer);
+ XFree(buffer);
+ return driver_version;
+ }
+ }
+ return std::string();
+}
+
const uint32 kVendorIDIntel = 0x8086;
const uint32 kVendorIDNVidia = 0x10de;
const uint32 kVendorIDAMD = 0x1002;
@@ -199,12 +231,22 @@
bool rt = CollectVideoCardInfo(gpu_info);
- if (gpu_info->gpu.vendor_id == kVendorIDAMD) {
- std::string ati_driver_version = CollectDriverVersionATI();
- if (!ati_driver_version.empty()) {
- gpu_info->driver_vendor = "ATI / AMD";
- gpu_info->driver_version = ati_driver_version;
- }
+ std::string driver_version;
+ switch (gpu_info->gpu.vendor_id) {
+ case kVendorIDAMD:
+ driver_version = CollectDriverVersionATI();
+ if (!driver_version.empty()) {
+ gpu_info->driver_vendor = "ATI / AMD";
+ gpu_info->driver_version = driver_version;
+ }
+ break;
+ case kVendorIDNVidia:
+ driver_version = CollectDriverVersionNVidia();
+ if (!driver_version.empty()) {
+ gpu_info->driver_vendor = "NVIDIA";
+ gpu_info->driver_version = driver_version;
+ }
+ break;
}
return rt;
« no previous file with comments | « content/gpu/DEPS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698