aboutsummaryrefslogtreecommitdiff
path: root/render/egl.c
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2018-02-10 09:45:18 -0500
committerGitHub <noreply@github.com>2018-02-10 09:45:18 -0500
commit07856580c446607fa55888db8ae75491e0447c20 (patch)
treefe1ab648a792adfd9d66f3975ff093f2ed5a4844 /render/egl.c
parent039f112c31eea17e45c121db9b470fa36bbf9af9 (diff)
parentbf6d24540000339029a30715f1f72b5b95a45018 (diff)
Merge pull request #619 from emersion/swap-with-damage
Swap buffers with damage
Diffstat (limited to 'render/egl.c')
-rw-r--r--render/egl.c39
1 files changed, 38 insertions, 1 deletions
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 <assert.h>
+#include <stdlib.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <GLES2/gl2.h>
-#include <stdlib.h>
#include <wlr/util/log.h>
#include <wlr/render/egl.h>
#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;
+}