From bf6d24540000339029a30715f1f72b5b95a45018 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 9 Feb 2018 22:54:14 +0100 Subject: Swap buffers with damage --- render/egl.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'render/egl.c') diff --git a/render/egl.c b/render/egl.c index 9ac0b307..328726ba 100644 --- a/render/egl.c +++ b/render/egl.c @@ -1,8 +1,8 @@ #include +#include #include #include #include -#include #include #include #include "glapi.h" @@ -143,6 +143,9 @@ bool wlr_egl_init(struct wlr_egl *egl, EGLenum platform, void *remote_display, egl->egl_exts.buffer_age = strstr(egl->egl_exts_str, "EGL_EXT_buffer_age") != NULL; + egl->egl_exts.swap_buffers_with_damage = + strstr(egl->egl_exts_str, "EGL_EXT_swap_buffers_with_damage") != NULL || + strstr(egl->egl_exts_str, "EGL_KHR_swap_buffers_with_damage") != NULL; return true; @@ -242,3 +245,37 @@ bool wlr_egl_make_current(struct wlr_egl *egl, EGLSurface surface, } return true; } + +bool wlr_egl_swap_buffers(struct wlr_egl *egl, EGLSurface surface, + pixman_region32_t *damage) { + EGLBoolean ret; + if (damage != NULL && egl->egl_exts.swap_buffers_with_damage) { + int nrects; + pixman_box32_t *rects = + pixman_region32_rectangles(damage, &nrects); + EGLint egl_damage[4 * nrects]; + for (int i = 0; i < nrects; ++i) { + egl_damage[4*i] = rects[i].x1; + egl_damage[4*i + 1] = rects[i].y1; + egl_damage[4*i + 2] = rects[i].x2 - rects[i].x1; + egl_damage[4*i + 3] = rects[i].y2 - rects[i].y1; + } + + assert(eglSwapBuffersWithDamageEXT || eglSwapBuffersWithDamageKHR); + if (eglSwapBuffersWithDamageEXT) { + ret = eglSwapBuffersWithDamageEXT(egl->display, surface, egl_damage, + nrects); + } else { + ret = eglSwapBuffersWithDamageKHR(egl->display, surface, egl_damage, + nrects); + } + } else { + ret = eglSwapBuffers(egl->display, surface); + } + + if (!ret) { + wlr_log(L_ERROR, "eglSwapBuffers failed: %s", egl_error()); + return false; + } + return true; +} -- cgit v1.2.3