egl: add dri2_setup_swap_interval helper
authorEmil Velikov <emil.velikov@collabora.com>
Fri, 4 Aug 2017 23:25:46 +0000 (00:25 +0100)
committerEmil Velikov <emil.l.velikov@gmail.com>
Thu, 10 Aug 2017 18:23:31 +0000 (19:23 +0100)
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 <emil.velikov@collabora.com>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com> (v1)
src/egl/drivers/dri2/egl_dri2.c
src/egl/drivers/dri2/egl_dri2.h
src/egl/drivers/dri2/platform_wayland.c
src/egl/drivers/dri2/platform_x11.c

index f0d1ded40834b122416da907bc6fb413d07716e0..f584740751a48322a3cf718489a3b7522fe3ab3e 100644 (file)
@@ -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.
  */
index ccfefef61fc2d4022d14076de38b092f0f79be76..751e7a4e2f3928d8fb4ab725462c33f6bfabdb65 100644 (file)
@@ -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);
 
index a11eaedefd4ee200af446cf2f6932f9051ebf90a..e0febf8c4cb9e54cea0ebf25010568369fecdaf6 100644 (file)
@@ -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");
index 4610ec579f52336ca1d915184aa61b585bdda76b..f9aaf47e7d1821f62133e590ab05a74263e0683b 100644 (file)
@@ -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;