[Mesa-dev] [PATCH 06/12] egl: add dri2_setup_swap_interval helper

Eric Engestrom eric.engestrom at imgtec.com
Fri Aug 4 10:11:57 UTC 2017


On Thursday, 2017-08-03 19:29:32 +0100, Emil Velikov wrote:
> From: Emil Velikov <emil.velikov at collabora.com>
> 
> 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 ;-)
> 
> Signed-off-by: Emil Velikov <emil.velikov at collabora.com>

I still haven't really looked into that extension system, I don't
understand it enough to review, so I'm skipping 1-3.

4-6, 9, 10 (with comments), 11 are
Reviewed-by: Eric Engestrom <eric.engestrom at imgtec.com>

> ---
> FWIW I choose to keep the local wrapper since I'm too lazy to copy the
> same comments multiple times. Can fold it if people prefer.

Nah, you'd have to duplicate `arbitrary_max_interval` too, which I find meh...

> ---
>  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     | 42 ++++-----------------------------
>  4 files changed, 48 insertions(+), 69 deletions(-)
> 
> diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
> index 733659d547f..936b7c5199e 100644
> --- a/src/egl/drivers/dri2/egl_dri2.c
> +++ b/src/egl/drivers/dri2/egl_dri2.c
> @@ -728,6 +728,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 1144ce988e1..21bbc1fd966 100644
> --- a/src/egl/drivers/dri2/egl_dri2.h
> +++ b/src/egl/drivers/dri2/egl_dri2.h
> @@ -366,6 +366,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 73966b7c504..38fdfe974fa 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
> @@ -1967,7 +1940,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 bec8a277958..111c478b9de 100644
> --- a/src/egl/drivers/dri2/platform_x11.c
> +++ b/src/egl/drivers/dri2/platform_x11.c
> @@ -1259,46 +1259,14 @@ 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;
>     int arbitrary_max_interval = 1000;
>  
> -   /* default behavior for no SwapBuffers support: no vblank syncing
> -    * either.
> -    */
> -   dri2_dpy->min_swap_interval = 0;
> -   dri2_dpy->max_swap_interval = 0;
> -
>     /* 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
> @@ -1340,7 +1308,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;
> @@ -1420,7 +1388,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.13.3
> 


More information about the mesa-dev mailing list