From 60ebeb4608a871ba89ba081c1c6e7ebdd5efec9a Mon Sep 17 00:00:00 2001 From: Adam Jackson Date: Wed, 9 Sep 2020 14:00:35 -0400 Subject: [PATCH] glx: Implement GLX_EXT_swap_control for DRI2 and DRI3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a slight generalization of the existing SGI and MESA swap control extensions, and a prerequisite for GLX_EXT_swap_control_tear. Reviewed-by: Michel Dänzer Part-of: --- docs/relnotes/new_features.txt | 1 + src/glx/dri2_glx.c | 1 + src/glx/dri3_glx.c | 1 + src/glx/glx_pbuffer.c | 11 +++++++++++ src/glx/glxcmds.c | 31 +++++++++++++++++++++++++++++++ src/glx/glxextensions.c | 1 + src/glx/glxextensions.h | 1 + 7 files changed, 47 insertions(+) diff --git a/docs/relnotes/new_features.txt b/docs/relnotes/new_features.txt index 705d69cc9d3..01d1d5ffc5b 100644 --- a/docs/relnotes/new_features.txt +++ b/docs/relnotes/new_features.txt @@ -3,3 +3,4 @@ GL_NV_copy_depth_to_color for NIR GL_NV_half_float EGL_KHR_swap_buffers_with_damage on X11 (DRI3) VK_PRESENT_MODE_FIFO_RELAXED on X11 +GLX_EXT_swap_control for DRI2 and DRI3 diff --git a/src/glx/dri2_glx.c b/src/glx/dri2_glx.c index af50fbe9d9c..e281c8cb071 100644 --- a/src/glx/dri2_glx.c +++ b/src/glx/dri2_glx.c @@ -1109,6 +1109,7 @@ dri2BindExtensions(struct dri2_screen *psc, struct glx_display * priv, extensions = psc->core->getExtensions(psc->driScreen); + __glXEnableDirectExtension(&psc->base, "GLX_EXT_swap_control"); __glXEnableDirectExtension(&psc->base, "GLX_SGI_swap_control"); __glXEnableDirectExtension(&psc->base, "GLX_MESA_swap_control"); __glXEnableDirectExtension(&psc->base, "GLX_SGI_make_current_read"); diff --git a/src/glx/dri3_glx.c b/src/glx/dri3_glx.c index fc8e8157618..385791fcd6d 100644 --- a/src/glx/dri3_glx.c +++ b/src/glx/dri3_glx.c @@ -741,6 +741,7 @@ dri3_bind_extensions(struct dri3_screen *psc, struct glx_display * priv, extensions = psc->core->getExtensions(psc->driScreen); + __glXEnableDirectExtension(&psc->base, "GLX_EXT_swap_control"); __glXEnableDirectExtension(&psc->base, "GLX_SGI_swap_control"); __glXEnableDirectExtension(&psc->base, "GLX_MESA_swap_control"); __glXEnableDirectExtension(&psc->base, "GLX_SGI_make_current_read"); diff --git a/src/glx/glx_pbuffer.c b/src/glx/glx_pbuffer.c index b654168324c..ffc4f6c4648 100644 --- a/src/glx/glx_pbuffer.c +++ b/src/glx/glx_pbuffer.c @@ -35,6 +35,7 @@ #include #include #include +#include #include "glxextensions.h" #ifdef GLX_USE_APPLEGL @@ -343,6 +344,16 @@ __glXGetDrawableAttribute(Display * dpy, GLXDrawable drawable, return 0; } + + if (pdraw) { + if (attribute == GLX_SWAP_INTERVAL_EXT) { + *value = pdraw->psc->driScreen->getSwapInterval(pdraw); + return 0; + } else if (attribute == GLX_MAX_SWAP_INTERVAL_EXT) { + *value = INT_MAX; + return 0; + } + } #endif LockDisplay(dpy); diff --git a/src/glx/glxcmds.c b/src/glx/glxcmds.c index fb840eb6b7f..0a6324400c3 100644 --- a/src/glx/glxcmds.c +++ b/src/glx/glxcmds.c @@ -1845,6 +1845,34 @@ glXGetSwapIntervalMESA(void) } +/* +** GLX_EXT_swap_control +*/ +_X_HIDDEN void +glXSwapIntervalEXT(Display *dpy, GLXDrawable drawable, int interval) +{ +#ifdef GLX_DIRECT_RENDERING + __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable); + + /* + * Strictly, this should throw an error if drawable is not a Window or + * GLXWindow. We don't actually track that, so, oh well. + */ + if (!pdraw) { + __glXSendError(dpy, BadWindow, drawable, 0, True); + return; + } + + if (interval < 0) { + __glXSendError(dpy, BadValue, interval, 0, True); + return; + } + + pdraw->psc->driScreen->setSwapInterval(pdraw, interval); +#endif +} + + /* ** GLX_SGI_video_sync */ @@ -2530,6 +2558,9 @@ static const struct name_address_pair GLX_functions[] = { /*** GLX_EXT_texture_from_pixmap ***/ GLX_FUNCTION(glXBindTexImageEXT), GLX_FUNCTION(glXReleaseTexImageEXT), + + /*** GLX_EXT_swap_control ***/ + GLX_FUNCTION(glXSwapIntervalEXT), #endif #if defined(GLX_DIRECT_RENDERING) && defined(GLX_USE_DRM) diff --git a/src/glx/glxextensions.c b/src/glx/glxextensions.c index f6a7a31a219..1d65e680b81 100644 --- a/src/glx/glxextensions.c +++ b/src/glx/glxextensions.c @@ -147,6 +147,7 @@ static const struct extension_info known_glx_extensions[] = { { GLX(EXT_fbconfig_packed_float), VER(0,0), Y, Y, N, N }, { GLX(EXT_framebuffer_sRGB), VER(0,0), Y, Y, N, N }, { GLX(EXT_import_context), VER(0,0), Y, Y, N, N }, + { GLX(EXT_swap_control), VER(0,0), Y, N, N, Y }, { GLX(EXT_texture_from_pixmap), VER(0,0), Y, N, N, N }, { GLX(EXT_visual_info), VER(0,0), Y, Y, N, N }, { GLX(EXT_visual_rating), VER(0,0), Y, Y, N, N }, diff --git a/src/glx/glxextensions.h b/src/glx/glxextensions.h index bbdb00dd631..446079e2c5f 100644 --- a/src/glx/glxextensions.h +++ b/src/glx/glxextensions.h @@ -51,6 +51,7 @@ enum EXT_fbconfig_packed_float_bit, EXT_framebuffer_sRGB_bit, EXT_import_context_bit, + EXT_swap_control_bit, EXT_texture_from_pixmap_bit, EXT_visual_info_bit, EXT_visual_rating_bit,