1 //
2 // Copyright (c) 2013-2017 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 
7 // SystemInfo_x11.cpp: implementation of the X11-specific parts of SystemInfo.h
8 
9 #include "gpu_info_util/SystemInfo_internal.h"
10 
11 #include <X11/Xlib.h>
12 
13 #include "common/debug.h"
14 #include "third_party/libXNVCtrl/NVCtrl.h"
15 #include "third_party/libXNVCtrl/NVCtrlLib.h"
16 
17 #if !defined(GPU_INFO_USE_X11)
18 #error SystemInfo_x11.cpp compiled without GPU_INFO_USE_X11
19 #endif
20 
21 namespace angle
22 {
23 
GetNvidiaDriverVersionWithXNVCtrl(std::string * version)24 bool GetNvidiaDriverVersionWithXNVCtrl(std::string *version)
25 {
26     *version = "";
27 
28     int eventBase = 0;
29     int errorBase = 0;
30 
31     Display *display = XOpenDisplay(nullptr);
32 
33     if (XNVCTRLQueryExtension(display, &eventBase, &errorBase))
34     {
35         int screenCount = ScreenCount(display);
36         for (int screen = 0; screen < screenCount; ++screen)
37         {
38             char *buffer = nullptr;
39             if (XNVCTRLIsNvScreen(display, screen) &&
40                 XNVCTRLQueryStringAttribute(display, screen, 0,
41                                             NV_CTRL_STRING_NVIDIA_DRIVER_VERSION, &buffer))
42             {
43                 ASSERT(buffer != nullptr);
44                 *version = buffer;
45                 XFree(buffer);
46                 return true;
47             }
48         }
49     }
50 
51     return false;
52 }
53 }
54