From 655f2c1d6593064b83f64a527798f48cd300fa16 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fredrik=20H=C3=B6glund?= Date: Tue, 20 Dec 2011 17:17:02 +0100 Subject: [PATCH] egl_dri2/x11: Add support for eglSwapInterval --- src/egl/drivers/dri2/egl_dri2.c | 8 +++++++- src/egl/drivers/dri2/egl_dri2.h | 1 + src/egl/drivers/dri2/platform_x11.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c index 4c9ece351af..47de978404d 100644 --- a/src/egl/drivers/dri2/egl_dri2.c +++ b/src/egl/drivers/dri2/egl_dri2.c @@ -259,9 +259,15 @@ dri2_add_config(_EGLDisplay *disp, const __DRIconfig *dri_config, int id, return NULL; } - if (double_buffer) + if (double_buffer) { surface_type &= ~EGL_PIXMAP_BIT; + if (dri2_dpy->swap_available) { + conf->base.MinSwapInterval = 0; + conf->base.MaxSwapInterval = 1000; /* XXX arbitrary value */ + } + } + conf->base.SurfaceType |= surface_type; return conf; diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h index 193a866324f..bead446dad6 100644 --- a/src/egl/drivers/dri2/egl_dri2.h +++ b/src/egl/drivers/dri2/egl_dri2.h @@ -102,6 +102,7 @@ struct dri2_egl_display int fd; int own_device; + int swap_available; #ifdef HAVE_DRM_PLATFORM struct gbm_dri_device *gbm_dri; #endif diff --git a/src/egl/drivers/dri2/platform_x11.c b/src/egl/drivers/dri2/platform_x11.c index d789ec6793a..d761fe053d6 100644 --- a/src/egl/drivers/dri2/platform_x11.c +++ b/src/egl/drivers/dri2/platform_x11.c @@ -763,6 +763,31 @@ dri2_post_sub_buffer(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *draw, return dri2_swap_buffers_region(drv, disp, draw, 1, rect); } +static EGLBoolean +dri2_swap_interval(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf, EGLint interval) +{ +#if XCB_DRI2_MINOR_VERSION >= 3 + struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp); + struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf); + + /* XXX Check vblank_mode here? */ + + if (interval > surf->Config->MaxSwapInterval) + interval = surf->Config->MaxSwapInterval; + else if (interval < surf->Config->MinSwapInterval) + interval = surf->Config->MinSwapInterval; + + if (interval != surf->SwapInterval && dri2_dpy->swap_available) + xcb_dri2_swap_interval(dri2_dpy->conn, dri2_surf->drawable, interval); + + surf->SwapInterval = interval; + + return EGL_TRUE; +#else + return EGL_FALSE; +#endif +} + static EGLBoolean dri2_copy_buffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf, EGLNativePixmapType target) @@ -987,6 +1012,7 @@ dri2_initialize_x11_dri2(_EGLDriver *drv, _EGLDisplay *disp) drv->API.CreateImageKHR = dri2_x11_create_image_khr; drv->API.SwapBuffersRegionNOK = dri2_swap_buffers_region; drv->API.PostSubBufferNV = dri2_post_sub_buffer; + drv->API.SwapInterval = dri2_swap_interval; dri2_dpy = malloc(sizeof *dri2_dpy); if (!dri2_dpy) @@ -1046,6 +1072,8 @@ dri2_initialize_x11_dri2(_EGLDriver *drv, _EGLDisplay *disp) dri2_dpy->extensions[1] = &image_lookup_extension.base; dri2_dpy->extensions[2] = NULL; + dri2_dpy->swap_available = (dri2_dpy->dri2_minor >= 2); + if (!dri2_create_screen(disp)) goto cleanup_fd; -- 2.30.2