Roll src/third_party/skia 7ef63c8:164d5b0
[chromium-blink-merge.git] / gpu / config / gpu_info_collector_x11.cc
blob38fa72f74dc82b18a573c12810e08ae18c7c50b8
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include <X11/Xlib.h>
7 #include "base/logging.h"
8 #include "gpu/config/gpu_info_collector_linux.h"
9 #include "third_party/libXNVCtrl/NVCtrl.h"
10 #include "third_party/libXNVCtrl/NVCtrlLib.h"
11 #include "ui/gfx/x/x11_types.h"
13 namespace gpu {
15 // Use NVCtrl extention to query NV driver version.
16 // Return empty string on failing.
17 std::string CollectDriverVersionNVidia() {
18 Display* display = gfx::GetXDisplay();
19 if (!display) {
20 LOG(ERROR) << "XOpenDisplay failed.";
21 return std::string();
23 int event_base = 0, error_base = 0;
24 if (!XNVCTRLQueryExtension(display, &event_base, &error_base)) {
25 VLOG(1) << "NVCtrl extension does not exist.";
26 return std::string();
28 int screen_count = ScreenCount(display);
29 for (int screen = 0; screen < screen_count; ++screen) {
30 char* buffer = NULL;
31 if (XNVCTRLIsNvScreen(display, screen) &&
32 XNVCTRLQueryStringAttribute(display, screen, 0,
33 NV_CTRL_STRING_NVIDIA_DRIVER_VERSION,
34 &buffer)) {
35 std::string driver_version(buffer);
36 XFree(buffer);
37 return driver_version;
40 return std::string();
43 } // namespace gpu