aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndri Yngvason <andri@yngvason.is>2020-06-02 21:49:44 +0000
committerSimon Ser <contact@emersion.fr>2020-06-08 20:49:41 +0200
commit11b598fe33a29f1f6c41faf6b1dfbdd94af6d19b (patch)
tree8d4726a743811ee595f6c419f36d6bc63d4ed0b9
parente77c046cf98f53a9307deeb8940d67938c078986 (diff)
render: egl: Add utility functions for saving/restoring context
-rw-r--r--include/wlr/render/egl.h19
-rw-r--r--render/egl.c12
2 files changed, 31 insertions, 0 deletions
diff --git a/include/wlr/render/egl.h b/include/wlr/render/egl.h
index 98435d91..d46d95af 100644
--- a/include/wlr/render/egl.h
+++ b/include/wlr/render/egl.h
@@ -30,6 +30,13 @@
#include <wlr/render/dmabuf.h>
#include <wlr/render/drm_format_set.h>
+struct wlr_egl_context {
+ EGLDisplay display;
+ EGLContext context;
+ EGLSurface draw_surface;
+ EGLSurface read_surface;
+};
+
struct wlr_egl {
EGLenum platform;
EGLDisplay display;
@@ -137,6 +144,18 @@ bool wlr_egl_unset_current(struct wlr_egl *egl);
bool wlr_egl_is_current(struct wlr_egl *egl);
+/**
+ * Save the current EGL context to the structure provided in the argument.
+ *
+ * This includes display, context, draw surface and read surface.
+ */
+void wlr_egl_save_context(struct wlr_egl_context *context);
+
+/**
+ * Restore EGL context that was previously saved using wlr_egl_save_current().
+ */
+bool wlr_egl_restore_context(struct wlr_egl_context *context);
+
bool wlr_egl_swap_buffers(struct wlr_egl *egl, EGLSurface surface,
pixman_region32_t *damage);
diff --git a/render/egl.c b/render/egl.c
index a2f7bd9a..6df5dac8 100644
--- a/render/egl.c
+++ b/render/egl.c
@@ -411,6 +411,18 @@ bool wlr_egl_is_current(struct wlr_egl *egl) {
return eglGetCurrentContext() == egl->context;
}
+void wlr_egl_save_context(struct wlr_egl_context *context) {
+ context->display = eglGetCurrentDisplay();
+ context->context = eglGetCurrentContext();
+ context->draw_surface = eglGetCurrentSurface(EGL_DRAW);
+ context->read_surface = eglGetCurrentSurface(EGL_READ);
+}
+
+bool wlr_egl_restore_context(struct wlr_egl_context *context) {
+ return eglMakeCurrent(context->display, context->draw_surface,
+ context->read_surface, context->context);
+}
+
bool wlr_egl_swap_buffers(struct wlr_egl *egl, EGLSurface surface,
pixman_region32_t *damage) {
// Never block when swapping buffers on Wayland