From 0c7a19fda67c05ad09cf4930b0615938a780f1da Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Wed, 25 Sep 2019 23:15:17 +0100 Subject: [PATCH] backend: glx: add support for setting vsync Signed-off-by: Yuxuan Shui --- src/backend/gl/glx.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/backend/gl/glx.c b/src/backend/gl/glx.c index 18b1d07..d02d4a5 100644 --- a/src/backend/gl/glx.c +++ b/src/backend/gl/glx.c @@ -213,6 +213,22 @@ static void *glx_decouple_user_data(backend_t *base attr_unused, void *ud attr_u return ret; } +static bool glx_set_swap_interval(int interval, Display *dpy, GLXDrawable drawable) { + bool vsync_enabled = false; + if (glxext.has_GLX_MESA_swap_control) { + vsync_enabled = (glXSwapIntervalMESA((uint)interval) == 0); + } + if (!vsync_enabled && glxext.has_GLX_SGI_swap_control) { + vsync_enabled = (glXSwapIntervalSGI(interval) == 0); + } + if (!vsync_enabled && glxext.has_GLX_EXT_swap_control) { + // glXSwapIntervalEXT doesn't return if it's successful + glXSwapIntervalEXT(dpy, drawable, interval); + vsync_enabled = true; + } + return vsync_enabled; +} + /** * Initialize OpenGL. */ @@ -327,6 +343,14 @@ static backend_t *glx_init(session_t *ps) { gd->gl.decouple_texture_user_data = glx_decouple_user_data; gd->gl.release_user_data = glx_release_image; + if (ps->o.vsync) { + if (!glx_set_swap_interval(1, ps->dpy, tgt)) { + log_error("Failed to enable vsync."); + } + } else { + glx_set_swap_interval(0, ps->dpy, tgt); + } + success = true; end: