From 47b06f5821551375e98699ca8ea41d06dc4ba0e9 Mon Sep 17 00:00:00 2001 From: Emil Velikov Date: Sat, 5 Aug 2017 00:25:46 +0100 Subject: [PATCH] egl: add dri2_setup_swap_interval helper The current two implementations - X11 and Wayland were identical, barrind the upper limit. Instead of having same code twice - introduce a helper and pass the limit as an argument. Thus as Android/DRM/others get support - they only need to call the function ;-) v2: Rebase on top of keeping ::swap_available Signed-off-by: Emil Velikov Reviewed-by: Eric Engestrom (v1) --- src/egl/drivers/dri2/egl_dri2.c | 35 +++++++++++++++++++++++ src/egl/drivers/dri2/egl_dri2.h | 3 ++ src/egl/drivers/dri2/platform_wayland.c | 37 ++++--------------------- src/egl/drivers/dri2/platform_x11.c | 37 ++++--------------------- 4 files changed, 49 insertions(+), 63 deletions(-) diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c index f0d1ded4083..f584740751a 100644 --- a/src/egl/drivers/dri2/egl_dri2.c +++ b/src/egl/drivers/dri2/egl_dri2.c @@ -729,6 +729,41 @@ dri2_setup_screen(_EGLDisplay *disp) } } +void +dri2_setup_swap_interval(_EGLDisplay *disp, int max_swap_interval) +{ + struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); + GLint vblank_mode = DRI_CONF_VBLANK_DEF_INTERVAL_1; + + /* Allow driconf to override applications.*/ + if (dri2_dpy->config) + dri2_dpy->config->configQueryi(dri2_dpy->dri_screen, + "vblank_mode", &vblank_mode); + switch (vblank_mode) { + case DRI_CONF_VBLANK_NEVER: + dri2_dpy->min_swap_interval = 0; + dri2_dpy->max_swap_interval = 0; + dri2_dpy->default_swap_interval = 0; + break; + case DRI_CONF_VBLANK_ALWAYS_SYNC: + dri2_dpy->min_swap_interval = 1; + dri2_dpy->max_swap_interval = max_swap_interval; + dri2_dpy->default_swap_interval = 1; + break; + case DRI_CONF_VBLANK_DEF_INTERVAL_0: + dri2_dpy->min_swap_interval = 0; + dri2_dpy->max_swap_interval = max_swap_interval; + dri2_dpy->default_swap_interval = 0; + break; + default: + case DRI_CONF_VBLANK_DEF_INTERVAL_1: + dri2_dpy->min_swap_interval = 0; + dri2_dpy->max_swap_interval = max_swap_interval; + dri2_dpy->default_swap_interval = 1; + break; + } +} + /* All platforms but DRM call this function to create the screen and populate * the driver_configs. DRM inherits that information from its display - GBM. */ diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h index ccfefef61fc..751e7a4e2f3 100644 --- a/src/egl/drivers/dri2/egl_dri2.h +++ b/src/egl/drivers/dri2/egl_dri2.h @@ -370,6 +370,9 @@ dri2_load_driver(_EGLDisplay *disp); void dri2_setup_screen(_EGLDisplay *disp); +void +dri2_setup_swap_interval(_EGLDisplay *disp, int max_swap_interval); + EGLBoolean dri2_load_driver_swrast(_EGLDisplay *disp); diff --git a/src/egl/drivers/dri2/platform_wayland.c b/src/egl/drivers/dri2/platform_wayland.c index a11eaedefd4..e0febf8c4cb 100644 --- a/src/egl/drivers/dri2/platform_wayland.c +++ b/src/egl/drivers/dri2/platform_wayland.c @@ -925,7 +925,7 @@ dri2_wl_query_buffer_age(_EGLDriver *drv, static EGLBoolean dri2_wl_swap_buffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *draw) { - return dri2_wl_swap_buffers_with_damage (drv, disp, draw, NULL, 0); + return dri2_wl_swap_buffers_with_damage(drv, disp, draw, NULL, 0); } static struct wl_buffer * @@ -1140,41 +1140,14 @@ static const struct wl_registry_listener registry_listener_drm = { }; static void -dri2_wl_setup_swap_interval(struct dri2_egl_display *dri2_dpy) +dri2_wl_setup_swap_interval(_EGLDisplay *disp) { - GLint vblank_mode = DRI_CONF_VBLANK_DEF_INTERVAL_1; - /* We can't use values greater than 1 on Wayland because we are using the * frame callback to synchronise the frame and the only way we be sure to * get a frame callback is to attach a new buffer. Therefore we can't just * sit drawing nothing to wait until the next ‘n’ frame callbacks */ - if (dri2_dpy->config) - dri2_dpy->config->configQueryi(dri2_dpy->dri_screen, - "vblank_mode", &vblank_mode); - switch (vblank_mode) { - case DRI_CONF_VBLANK_NEVER: - dri2_dpy->min_swap_interval = 0; - dri2_dpy->max_swap_interval = 0; - dri2_dpy->default_swap_interval = 0; - break; - case DRI_CONF_VBLANK_ALWAYS_SYNC: - dri2_dpy->min_swap_interval = 1; - dri2_dpy->max_swap_interval = 1; - dri2_dpy->default_swap_interval = 1; - break; - case DRI_CONF_VBLANK_DEF_INTERVAL_0: - dri2_dpy->min_swap_interval = 0; - dri2_dpy->max_swap_interval = 1; - dri2_dpy->default_swap_interval = 0; - break; - default: - case DRI_CONF_VBLANK_DEF_INTERVAL_1: - dri2_dpy->min_swap_interval = 0; - dri2_dpy->max_swap_interval = 1; - dri2_dpy->default_swap_interval = 1; - break; - } + dri2_setup_swap_interval(disp, 1); } static const struct dri2_egl_display_vtbl dri2_wl_display_vtbl = { @@ -1354,7 +1327,7 @@ dri2_initialize_wayland_drm(_EGLDriver *drv, _EGLDisplay *disp) dri2_setup_screen(disp); - dri2_wl_setup_swap_interval(dri2_dpy); + dri2_wl_setup_swap_interval(disp); /* To use Prime, we must have _DRI_IMAGE v7 at least. * createImageFromFds support indicates that Prime export/import @@ -1968,7 +1941,7 @@ dri2_initialize_wayland_swrast(_EGLDriver *drv, _EGLDisplay *disp) dri2_setup_screen(disp); - dri2_wl_setup_swap_interval(dri2_dpy); + dri2_wl_setup_swap_interval(disp); if (!dri2_wl_add_configs_for_visuals(drv, disp)) { _eglError(EGL_NOT_INITIALIZED, "DRI2: failed to add configs"); diff --git a/src/egl/drivers/dri2/platform_x11.c b/src/egl/drivers/dri2/platform_x11.c index 4610ec579f5..f9aaf47e7d1 100644 --- a/src/egl/drivers/dri2/platform_x11.c +++ b/src/egl/drivers/dri2/platform_x11.c @@ -1273,9 +1273,9 @@ dri2_initialize_x11_swrast(_EGLDriver *drv, _EGLDisplay *disp) } static void -dri2_x11_setup_swap_interval(struct dri2_egl_display *dri2_dpy) +dri2_x11_setup_swap_interval(_EGLDisplay *disp) { - GLint vblank_mode = DRI_CONF_VBLANK_DEF_INTERVAL_1; + struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); int arbitrary_max_interval = 1000; /* default behavior for no SwapBuffers support: no vblank syncing @@ -1288,34 +1288,9 @@ dri2_x11_setup_swap_interval(struct dri2_egl_display *dri2_dpy) return; /* If we do have swapbuffers, then we can support pretty much any swap - * interval, but we allow driconf to override applications. + * interval. */ - if (dri2_dpy->config) - dri2_dpy->config->configQueryi(dri2_dpy->dri_screen, - "vblank_mode", &vblank_mode); - switch (vblank_mode) { - case DRI_CONF_VBLANK_NEVER: - dri2_dpy->min_swap_interval = 0; - dri2_dpy->max_swap_interval = 0; - dri2_dpy->default_swap_interval = 0; - break; - case DRI_CONF_VBLANK_ALWAYS_SYNC: - dri2_dpy->min_swap_interval = 1; - dri2_dpy->max_swap_interval = arbitrary_max_interval; - dri2_dpy->default_swap_interval = 1; - break; - case DRI_CONF_VBLANK_DEF_INTERVAL_0: - dri2_dpy->min_swap_interval = 0; - dri2_dpy->max_swap_interval = arbitrary_max_interval; - dri2_dpy->default_swap_interval = 0; - break; - default: - case DRI_CONF_VBLANK_DEF_INTERVAL_1: - dri2_dpy->min_swap_interval = 0; - dri2_dpy->max_swap_interval = arbitrary_max_interval; - dri2_dpy->default_swap_interval = 1; - break; - } + dri2_setup_swap_interval(disp, arbitrary_max_interval); } #ifdef HAVE_DRI3 @@ -1359,7 +1334,7 @@ dri2_initialize_x11_dri3(_EGLDriver *drv, _EGLDisplay *disp) dri2_setup_screen(disp); - dri2_x11_setup_swap_interval(dri2_dpy); + dri2_x11_setup_swap_interval(disp); if (!dri2_dpy->is_different_gpu) disp->Extensions.KHR_image_pixmap = EGL_TRUE; @@ -1459,7 +1434,7 @@ dri2_initialize_x11_dri2(_EGLDriver *drv, _EGLDisplay *disp) dri2_setup_screen(disp); - dri2_x11_setup_swap_interval(dri2_dpy); + dri2_x11_setup_swap_interval(disp); disp->Extensions.KHR_image_pixmap = EGL_TRUE; disp->Extensions.NOK_swap_region = EGL_TRUE; -- 2.30.2