From d64f10faa982595553581f71eceaa831b73e8d6d Mon Sep 17 00:00:00 2001 From: Grigori Goronzy Date: Sun, 27 Sep 2009 02:18:05 +0000 Subject: [PATCH] Split up video into vendor/renderer/version and acquire video adapter info via OpenGL/GLX on Unix. Originally committed to SVN as r3589. --- aegisub/reporter/include/platform.h | 17 +++++- aegisub/reporter/name_map.cpp | 3 + aegisub/reporter/platform_unix.cpp | 70 +++++++++++++++++++++++- aegisub/reporter/platform_unix.h | 11 +++- aegisub/reporter/platform_unix_bsd.cpp | 4 -- aegisub/reporter/platform_unix_bsd.h | 1 - aegisub/reporter/platform_unix_linux.cpp | 4 -- aegisub/reporter/platform_unix_linux.h | 1 - aegisub/reporter/report.cpp | 3 + 9 files changed, 101 insertions(+), 13 deletions(-) diff --git a/aegisub/reporter/include/platform.h b/aegisub/reporter/include/platform.h index d4a41a4c7..c6a28aa82 100644 --- a/aegisub/reporter/include/platform.h +++ b/aegisub/reporter/include/platform.h @@ -179,9 +179,24 @@ public: virtual wxString Memory()=0; /// Video card - /// @return Video card + /// @return Video card description /// @retval Any virtual wxString Video()=0; + + /// Video card + /// @return Video card vendor + /// @retval Any + virtual wxString VideoVendor()=0; + + /// Video card renderer + /// @return Video card renderer name + /// @retval Any + virtual wxString VideoRenderer()=0; + + /// Video card version + /// @return Video card renderer version + /// @retval Any + virtual wxString VideoVersion()=0; //@} /// @name Windows diff --git a/aegisub/reporter/name_map.cpp b/aegisub/reporter/name_map.cpp index 034687155..ccd254228 100644 --- a/aegisub/reporter/name_map.cpp +++ b/aegisub/reporter/name_map.cpp @@ -80,6 +80,9 @@ const Report::nameMap Report::HumanNames() { nMap.insert(nPair("thesauruslang", _TT("Thesaurus Language"))); nMap.insert(nPair("unix", _TT("Unix"))); nMap.insert(nPair("video", _TT("Video"))); + nMap.insert(nPair("videovendor", _TT("Video Vendor"))); + nMap.insert(nPair("videorenderer", _TT("Video Renderer"))); + nMap.insert(nPair("videoversion", _TT("Video Version"))); nMap.insert(nPair("videoprovider", _TT("Video Provider"))); nMap.insert(nPair("windows", _TT("Windows"))); nMap.insert(nPair("wxversion", _TT("wx Version"))); diff --git a/aegisub/reporter/platform_unix.cpp b/aegisub/reporter/platform_unix.cpp index bdc17b8e2..8a8765b8e 100644 --- a/aegisub/reporter/platform_unix.cpp +++ b/aegisub/reporter/platform_unix.cpp @@ -29,6 +29,62 @@ extern "C" { #include +#include "GL/glx.h" +#include "GL/gl.h" +} + +PlatformUnix::PlatformUnix() { + GetVideoInfo(); +} + +/** + * @brief Gather video adapter information via OpenGL/GLX. + * + */ +void PlatformUnix::GetVideoInfo() { + Display *dpy; + XVisualInfo *vi; + GLXContext cx; + Window root, win; + XSetWindowAttributes attr; + unsigned long mask; + int attList[] = { GLX_RGBA, GLX_DOUBLEBUFFER, None }; + + vendor = wxString(); + renderer = wxString(); + version = wxString(); + + // Like in glxinfo.c, but somewhat simpler and shorter. + dpy = XOpenDisplay(0); + if (!dpy) return; + vi = glXChooseVisual(dpy, DefaultScreen(dpy), attList); + if (!vi) return; + cx = glXCreateContext(dpy, vi, 0, GL_TRUE); + if (!cx) return; + + root = RootWindow(dpy, DefaultScreen(dpy)); + attr.background_pixel = 0; + attr.border_pixel = 0; + attr.colormap = XCreateColormap(dpy, root, vi->visual, AllocNone); + attr.event_mask = StructureNotifyMask | ExposureMask; + mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; + win = XCreateWindow(dpy, root, 0, 0, 100, 100, 0, vi->depth, + InputOutput, vi->visual, mask, &attr); + + if (!glXMakeCurrent(dpy, win, cx)) { + glXDestroyContext(dpy, cx); + XDestroyWindow(dpy, win); + XCloseDisplay(dpy); + return; + } + + vendor = wxString(glGetString(GL_VENDOR)); + renderer = wxString(glGetString(GL_RENDERER)); + version = wxString(glGetString(GL_VERSION)); + + glXDestroyContext(dpy, cx); + XDestroyWindow(dpy, win); + XCloseDisplay(dpy); } wxString PlatformUnix::OSVersion() { @@ -72,7 +128,19 @@ wxString PlatformUnix::Memory() { }; wxString PlatformUnix::Video() { - return ""; + return wxString::Format("%s %s (%s)", vendor, renderer, version); +} + +wxString PlatformUnix::VideoVendor() { + return vendor; +}; + +wxString PlatformUnix::VideoRenderer() { + return renderer; +}; + +wxString PlatformUnix::VideoVersion() { + return version; }; wxString PlatformUnix::UnixLibraries() { diff --git a/aegisub/reporter/platform_unix.h b/aegisub/reporter/platform_unix.h index e1ef579cd..f85ef9d9f 100644 --- a/aegisub/reporter/platform_unix.h +++ b/aegisub/reporter/platform_unix.h @@ -23,7 +23,7 @@ class Platform; /// @brief General Unix functions. class PlatformUnix : public Platform { public: - PlatformUnix() {}; + PlatformUnix(); virtual ~PlatformUnix() {}; wxString OSVersion(); wxString DesktopEnvironment(); @@ -37,7 +37,16 @@ public: virtual wxString CPUFeatures2(); virtual wxString Memory(); virtual wxString Video(); + virtual wxString VideoVendor(); + virtual wxString VideoRenderer(); + virtual wxString VideoVersion(); // Unix Specific virtual wxString UnixLibraries(); + +private: + virtual void GetVideoInfo(); + wxString vendor; + wxString renderer; + wxString version; }; diff --git a/aegisub/reporter/platform_unix_bsd.cpp b/aegisub/reporter/platform_unix_bsd.cpp index 185909f7a..5d184084a 100644 --- a/aegisub/reporter/platform_unix_bsd.cpp +++ b/aegisub/reporter/platform_unix_bsd.cpp @@ -70,10 +70,6 @@ wxString PlatformUnixBSD::Memory() { return ""; }; -wxString PlatformUnixBSD::Video() { - return ""; -}; - wxString PlatformUnixBSD::UnixLibraries() { return ""; }; diff --git a/aegisub/reporter/platform_unix_bsd.h b/aegisub/reporter/platform_unix_bsd.h index e56d5752f..0803f66fd 100644 --- a/aegisub/reporter/platform_unix_bsd.h +++ b/aegisub/reporter/platform_unix_bsd.h @@ -34,7 +34,6 @@ public: virtual wxString CPUFeatures(); virtual wxString CPUFeatures2(); virtual wxString Memory(); - virtual wxString Video(); // Unix Specific virtual wxString UnixLibraries(); diff --git a/aegisub/reporter/platform_unix_linux.cpp b/aegisub/reporter/platform_unix_linux.cpp index 1877ef55b..7e0356f30 100644 --- a/aegisub/reporter/platform_unix_linux.cpp +++ b/aegisub/reporter/platform_unix_linux.cpp @@ -80,10 +80,6 @@ wxString PlatformUnixLinux::Memory() { return ""; }; -wxString PlatformUnixLinux::Video() { - return ""; -}; - wxString PlatformUnixLinux::UnixLibraries() { return ""; }; diff --git a/aegisub/reporter/platform_unix_linux.h b/aegisub/reporter/platform_unix_linux.h index e1350b63e..f0edca316 100644 --- a/aegisub/reporter/platform_unix_linux.h +++ b/aegisub/reporter/platform_unix_linux.h @@ -34,7 +34,6 @@ public: virtual wxString CPUFeatures(); virtual wxString CPUFeatures2(); virtual wxString Memory(); - virtual wxString Video(); // Unix Specific virtual wxString UnixLibraries(); diff --git a/aegisub/reporter/report.cpp b/aegisub/reporter/report.cpp index 21cbab6e9..1028d1b02 100644 --- a/aegisub/reporter/report.cpp +++ b/aegisub/reporter/report.cpp @@ -97,6 +97,9 @@ Report::XMLReport Report::ReportCreate() { Add(display, "colour", p->DisplayColour()); Add(display, "size", p->DisplaySize()); Add(display, "ppi", p->DisplayPPI()); + Add(doc.hardware, "videovendor", p->VideoVendor()); + Add(doc.hardware, "videorenderer", p->VideoRenderer()); + Add(doc.hardware, "videoversion", p->VideoVersion()); #ifdef __WINDOWS__ doc.windows = new wxXmlNode(wxXML_ELEMENT_NODE, "windows");