render: egl: Add utility functions for saving/restoring context
This commit is contained in:
parent
e77c046cf9
commit
11b598fe33
|
@ -30,6 +30,13 @@
|
||||||
#include <wlr/render/dmabuf.h>
|
#include <wlr/render/dmabuf.h>
|
||||||
#include <wlr/render/drm_format_set.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 {
|
struct wlr_egl {
|
||||||
EGLenum platform;
|
EGLenum platform;
|
||||||
EGLDisplay display;
|
EGLDisplay display;
|
||||||
|
@ -137,6 +144,18 @@ bool wlr_egl_unset_current(struct wlr_egl *egl);
|
||||||
|
|
||||||
bool wlr_egl_is_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,
|
bool wlr_egl_swap_buffers(struct wlr_egl *egl, EGLSurface surface,
|
||||||
pixman_region32_t *damage);
|
pixman_region32_t *damage);
|
||||||
|
|
||||||
|
|
12
render/egl.c
12
render/egl.c
|
@ -411,6 +411,18 @@ bool wlr_egl_is_current(struct wlr_egl *egl) {
|
||||||
return eglGetCurrentContext() == egl->context;
|
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,
|
bool wlr_egl_swap_buffers(struct wlr_egl *egl, EGLSurface surface,
|
||||||
pixman_region32_t *damage) {
|
pixman_region32_t *damage) {
|
||||||
// Never block when swapping buffers on Wayland
|
// Never block when swapping buffers on Wayland
|
||||||
|
|
Loading…
Reference in New Issue