From 6eae8f22dc9e37bbd1d99c7147612691efd2ce9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Sat, 10 Dec 2016 23:41:19 +0100 Subject: [PATCH] X11: Load Xxf86vm at run-time --- .github/CONTRIBUTING.md | 2 +- CMakeLists.txt | 15 --------------- README.md | 1 + docs/compile.dox | 6 ------ docs/internal.dox | 2 +- src/glfw_config.h.in | 3 --- src/x11_init.c | 27 +++++++++++++++++---------- src/x11_monitor.c | 4 ---- src/x11_platform.h | 21 ++++++++++++++------- 9 files changed, 34 insertions(+), 47 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 672264dc..9ef48784 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -140,7 +140,7 @@ include the __GLFW release version__ (e.g. `3.1.2`), otherwise include the __GLFW commit ID__ (e.g. `3795d78b14ef06008889cc422a1fb8d642597751`) from Git. Please also include the __GLFW version string__ (`3.2.0 X11 EGL clock_gettime -/dev/js XI Xf86vm`), as described +/dev/js`), as described [here](http://www.glfw.org/docs/latest/intro.html#intro_version_string), the __GPU model and driver version__ (e.g. `GeForce GTX660 with 352.79`), and the __output of `glfwinfo`__ (with switches matching any hints you set in your diff --git a/CMakeLists.txt b/CMakeLists.txt index 3bebc599..448c7f79 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -262,21 +262,6 @@ if (_GLFW_X11) list(APPEND glfw_LIBRARIES "${X11_Xinerama_LIB}") list(APPEND glfw_PKG_DEPS "xinerama") - # Check for Xf86VidMode (fallback gamma control) - if (X11_xf86vmode_FOUND) - list(APPEND glfw_INCLUDE_DIRS "${X11_xf86vmode_INCLUDE_PATH}") - list(APPEND glfw_PKG_DEPS "xxf86vm") - - if (X11_Xxf86vm_LIB) - list(APPEND glfw_LIBRARIES "${X11_Xxf86vm_LIB}") - else() - # Backwards compatibility (see CMake bug 0006976) - list(APPEND glfw_LIBRARIES Xxf86vm) - endif() - - set(_GLFW_HAS_XF86VM TRUE) - endif() - # Check for Xkb (X keyboard extension) if (NOT X11_Xkb_FOUND) message(FATAL_ERROR "The X keyboard extension headers were not found") diff --git a/README.md b/README.md index 40c8b803..eb09c967 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,7 @@ information on what to include when reporting a bug. - Bugfix: `glfwGetInstanceProcAddress` returned `NULL` for `vkGetInstanceProcAddr` when `_GLFW_VULKAN_STATIC` was enabled - [Win32] Bugfix: Undecorated windows could not be iconified by the user (#861) +- [X11] Replaced `_GLFW_HAS_XF86VM` compile-time option with dynamic loading - [Cocoa] Added support for Vulkan window surface creation via MoltenVK (#870) - [Cocoa] Bugfix: Disabling window aspect ratio would assert (#852) - [Cocoa] Bugfix: Window creation failed to set first responder (#876,#883) diff --git a/docs/compile.dox b/docs/compile.dox index 23d46882..6ac2432d 100644 --- a/docs/compile.dox +++ b/docs/compile.dox @@ -281,12 +281,6 @@ For the EGL context creation API, the following options are available: - @b _GLFW_USE_EGLPLATFORM_H to use `EGL/eglplatform.h` for native handle definitions (fallback) -If you are using the X11 window creation API, support for the following X11 -extensions can be enabled: - - - @b _GLFW_HAS_XF86VM to use Xxf86vm as a fallback when RandR gamma is broken - (recommended) - If you are using the Cocoa window creation API, the following options are available: diff --git a/docs/internal.dox b/docs/internal.dox index 3eb0aee5..72a09540 100644 --- a/docs/internal.dox +++ b/docs/internal.dox @@ -111,6 +111,6 @@ which is generated from the `glfw_config.h.in` file by CMake. Configuration macros the same style as tokens in the public interface, except with a leading underscore. -Examples: `_GLFW_HAS_XF86VM` +Examples: `_GLFW_USE_HYBRID_HPG` */ diff --git a/src/glfw_config.h.in b/src/glfw_config.h.in index 30638247..822814e4 100644 --- a/src/glfw_config.h.in +++ b/src/glfw_config.h.in @@ -55,9 +55,6 @@ // Define this to 1 to force use of high-performance GPU on hybrid systems #cmakedefine _GLFW_USE_HYBRID_HPG -// Define this to 1 if the Xxf86vm X11 extension is available -#cmakedefine _GLFW_HAS_XF86VM - // Define this to 1 if glfwInit should change the current directory #cmakedefine _GLFW_USE_CHDIR // Define this to 1 if glfwCreateWindow should populate the menu bar diff --git a/src/x11_init.c b/src/x11_init.c index 5c2b72b6..ca1bdf4b 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -462,13 +462,23 @@ static void detectEWMH(void) // static GLFWbool initExtensions(void) { -#if defined(_GLFW_HAS_XF86VM) - // Check for XF86VidMode extension - _glfw.x11.vidmode.available = - XF86VidModeQueryExtension(_glfw.x11.display, - &_glfw.x11.vidmode.eventBase, - &_glfw.x11.vidmode.errorBase); -#endif /*_GLFW_HAS_XF86VM*/ + _glfw.x11.vidmode.handle = dlopen("libXxf86vm.so", RTLD_LAZY | RTLD_GLOBAL); + if (_glfw.x11.vidmode.handle) + { + _glfw.x11.vidmode.QueryExtension = (PFN_XF86VidModeQueryExtension) + dlsym(_glfw.x11.vidmode.handle, "XF86VidModeQueryExtension"); + _glfw.x11.vidmode.GetGammaRamp = (PFN_XF86VidModeGetGammaRamp) + dlsym(_glfw.x11.vidmode.handle, "XF86VidModeGetGammaRamp"); + _glfw.x11.vidmode.SetGammaRamp = (PFN_XF86VidModeSetGammaRamp) + dlsym(_glfw.x11.vidmode.handle, "XF86VidModeSetGammaRamp"); + _glfw.x11.vidmode.GetGammaRampSize = (PFN_XF86VidModeGetGammaRampSize) + dlsym(_glfw.x11.vidmode.handle, "XF86VidModeGetGammaRampSize"); + + _glfw.x11.vidmode.available = + XF86VidModeQueryExtension(_glfw.x11.display, + &_glfw.x11.vidmode.eventBase, + &_glfw.x11.vidmode.errorBase); + } // Check for RandR extension if (XRRQueryExtension(_glfw.x11.display, @@ -848,9 +858,6 @@ const char* _glfwPlatformGetVersionString(void) #if defined(__linux__) " /dev/js" #endif -#if defined(_GLFW_HAS_XF86VM) - " Xf86vm" -#endif #if defined(_GLFW_BUILD_DLL) " shared" #endif diff --git a/src/x11_monitor.c b/src/x11_monitor.c index c0aebdaf..4806f0f8 100644 --- a/src/x11_monitor.c +++ b/src/x11_monitor.c @@ -429,7 +429,6 @@ void _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp) XRRFreeGamma(gamma); } -#if defined(_GLFW_HAS_XF86VM) else if (_glfw.x11.vidmode.available) { int size; @@ -441,7 +440,6 @@ void _glfwPlatformGetGammaRamp(_GLFWmonitor* monitor, GLFWgammaramp* ramp) _glfw.x11.screen, ramp->size, ramp->red, ramp->green, ramp->blue); } -#endif /*_GLFW_HAS_XF86VM*/ } void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp) @@ -457,7 +455,6 @@ void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp) XRRSetCrtcGamma(_glfw.x11.display, monitor->x11.crtc, gamma); XRRFreeGamma(gamma); } -#if defined(_GLFW_HAS_XF86VM) else if (_glfw.x11.vidmode.available) { XF86VidModeSetGammaRamp(_glfw.x11.display, @@ -467,7 +464,6 @@ void _glfwPlatformSetGammaRamp(_GLFWmonitor* monitor, const GLFWgammaramp* ramp) (unsigned short*) ramp->green, (unsigned short*) ramp->blue); } -#endif /*_GLFW_HAS_XF86VM*/ } diff --git a/src/x11_platform.h b/src/x11_platform.h index 33f15d34..b6035bbe 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -47,16 +47,20 @@ // The Xinerama extension provides legacy monitor indices #include -#if defined(_GLFW_HAS_XF86VM) - // The Xf86VidMode extension provides fallback gamma control - #include -#endif - typedef XID xcb_window_t; typedef XID xcb_visualid_t; typedef struct xcb_connection_t xcb_connection_t; typedef xcb_connection_t* (* PFN_XGetXCBConnection)(Display*); +typedef Bool (* PFN_XF86VidModeQueryExtension)(Display*,int*,int*); +typedef Bool (* PFN_XF86VidModeGetGammaRamp)(Display*,int,int,unsigned short*,unsigned short*,unsigned short*); +typedef Bool (* PFN_XF86VidModeSetGammaRamp)(Display*,int,int,unsigned short*,unsigned short*,unsigned short*); +typedef Bool (* PFN_XF86VidModeGetGammaRampSize)(Display*,int,int*); +#define XF86VidModeQueryExtension _glfw.x11.vidmode.QueryExtension +#define XF86VidModeGetGammaRamp _glfw.x11.vidmode.GetGammaRamp +#define XF86VidModeSetGammaRamp _glfw.x11.vidmode.SetGammaRamp +#define XF86VidModeGetGammaRampSize _glfw.x11.vidmode.GetGammaRampSize + typedef VkFlags VkXlibSurfaceCreateFlagsKHR; typedef VkFlags VkXcbSurfaceCreateFlagsKHR; @@ -250,13 +254,16 @@ typedef struct _GLFWlibraryX11 PFN_XGetXCBConnection XGetXCBConnection; } x11xcb; -#if defined(_GLFW_HAS_XF86VM) struct { GLFWbool available; + void* handle; int eventBase; int errorBase; + PFN_XF86VidModeQueryExtension QueryExtension; + PFN_XF86VidModeGetGammaRamp GetGammaRamp; + PFN_XF86VidModeSetGammaRamp SetGammaRamp; + PFN_XF86VidModeGetGammaRampSize GetGammaRampSize; } vidmode; -#endif /*_GLFW_HAS_XF86VM*/ } _GLFWlibraryX11;