From 78a6af8dae87c2de48e6c432825cc9a3a26ba55a Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Thu, 23 May 2019 16:54:50 +1000 Subject: [PATCH] [common] added new sysinfo unit and multisample query support Based on @rLink234's work in 4ac781b4516678b6c59d9ecf4a61df64a01ec8c1 --- VERSION | 2 +- common/CMakeLists.txt | 18 ++++++++-- common/include/common/sysinfo.h | 21 +++++++++++ common/src/sysinfo.linux.c | 64 +++++++++++++++++++++++++++++++++ common/src/sysinfo.windows.c | 24 +++++++++++++ 5 files changed, 125 insertions(+), 4 deletions(-) create mode 100644 common/include/common/sysinfo.h create mode 100644 common/src/sysinfo.linux.c create mode 100644 common/src/sysinfo.windows.c diff --git a/VERSION b/VERSION index 9ff5545d..6c2ffb53 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -a12-217-gf946117dac+1 \ No newline at end of file +a12-219-g3585e02993+1 \ No newline at end of file diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 93f3d235..63647fe2 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -5,16 +5,28 @@ include_directories( ${PROJECT_SOURCE_DIR}/include ) -set(SOURCES +set(COMMON_SOURCES src/stringutils.c src/stringlist.c src/option.c ) +set(LINUX_SOURCES + src/crash.linux.c + src/sysinfo.linux.c +) + +set(WINOWS_SOURCES + src/crash.windows.c + src/sysinfo.windows.c +) + if(WIN32) - add_library(lg_common STATIC src/crash.windows.c ${SOURCES}) + set(SOURCES ${COMMON_SOURCES} ${WINDOWS_SOURCES}) + add_library(lg_common STATIC ${SOURCES}) else() - add_library(lg_common STATIC src/crash.linux.c ${SOURCES}) + set(SOURCES ${COMMON_SOURCES} ${LINUX_SOURCES}) + add_library(lg_common STATIC ${SOURCES}) target_link_libraries(lg_common bfd) endif() diff --git a/common/include/common/sysinfo.h b/common/include/common/sysinfo.h new file mode 100644 index 00000000..dd7121a0 --- /dev/null +++ b/common/include/common/sysinfo.h @@ -0,0 +1,21 @@ +/* +KVMGFX Client - A KVM Client for VGA Passthrough +Copyright (C) 2017-2019 Geoffrey McRae +https://looking-glass.hostfission.com + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 59 Temple +Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +// returns the maximum number of multisamples supported by the system +int sysinfo_gfx_max_multisample(); \ No newline at end of file diff --git a/common/src/sysinfo.linux.c b/common/src/sysinfo.linux.c new file mode 100644 index 00000000..7411b226 --- /dev/null +++ b/common/src/sysinfo.linux.c @@ -0,0 +1,64 @@ +/* +KVMGFX Client - A KVM Client for VGA Passthrough +Copyright (C) 2017-2019 Geoffrey McRae +https://looking-glass.hostfission.com + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 59 Temple +Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include + +int sysinfo_gfx_max_multisample() +{ + Display * dpy = XOpenDisplay(NULL); + if (!dpy) + return -1; + + XVisualInfo queryTemplate; + queryTemplate.screen = 0; + + int visualCount; + int maxSamples = -1; + XVisualInfo * visuals = XGetVisualInfo(dpy, VisualScreenMask, &queryTemplate, &visualCount); + + for (int i = 0; i < visualCount; i++) + { + XVisualInfo * visual = &visuals[i]; + + int res, supportsGL; + // Some GLX visuals do not use GL, and these must be ignored in our search. + if ((res = glXGetConfig(dpy, visual, GLX_USE_GL, &supportsGL)) != 0 || !supportsGL) + continue; + + int sampleBuffers, samples; + if ((res = glXGetConfig(dpy, visual, GLX_SAMPLE_BUFFERS, &sampleBuffers)) != 0) + continue; + + // Will be 1 if this visual supports multisampling + if (sampleBuffers != 1) + continue; + + if ((res = glXGetConfig(dpy, visual, GLX_SAMPLES, &samples)) != 0) + continue; + + // Track the largest number of samples supported + if (samples > maxSamples) + maxSamples = samples; + + } + + XCloseDisplay(dpy); + + return maxSamples; +} \ No newline at end of file diff --git a/common/src/sysinfo.windows.c b/common/src/sysinfo.windows.c new file mode 100644 index 00000000..6ccd671a --- /dev/null +++ b/common/src/sysinfo.windows.c @@ -0,0 +1,24 @@ +/* +KVMGFX Client - A KVM Client for VGA Passthrough +Copyright (C) 2017-2019 Geoffrey McRae +https://looking-glass.hostfission.com + +This program is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation; either version 2 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., 59 Temple +Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +int sysinfo_gfx_max_multisample() +{ + //FIXME: Implement this + return 4; +} \ No newline at end of file