diff --git a/include/render/egl.h b/include/render/egl.h index af38af7e1..20ebc09e4 100644 --- a/include/render/egl.h +++ b/include/render/egl.h @@ -41,4 +41,19 @@ bool wlr_egl_destroy_image(struct wlr_egl *egl, EGLImageKHR image); int wlr_egl_dup_drm_fd(struct wlr_egl *egl); +/** + * Makes the provided EGL context current + * + * Callers are expected to clear the current context when they are done by + * calling wlr_egl_unset_current. + */ +bool wlr_egl_make_current(struct wlr_egl *egl); + +/** + * Clears the current EGLContext + */ +bool wlr_egl_unset_current(struct wlr_egl *egl); + +bool wlr_egl_is_current(struct wlr_egl *egl); + #endif diff --git a/include/wlr/render/egl.h b/include/wlr/render/egl.h index 88db130f7..297f49f3b 100644 --- a/include/wlr/render/egl.h +++ b/include/wlr/render/egl.h @@ -81,11 +81,14 @@ struct wlr_egl { * Callers are expected to clear the current context when they are done by * calling wlr_egl_unset_current. */ -bool wlr_egl_make_current(struct wlr_egl *egl); +bool wlr_egl_context_set_current(struct wlr_egl_context *ctx); -bool wlr_egl_unset_current(struct wlr_egl *egl); +/** + * Clear the EGL context + */ +bool wlr_egl_context_unset_current(struct wlr_egl_context *ctx); -bool wlr_egl_is_current(struct wlr_egl *egl); +bool wlr_egl_context_is_current(struct wlr_egl_context *ctx); /** * Save the current EGL context to the structure provided in the argument. diff --git a/render/egl.c b/render/egl.c index e7734f86c..892a0cafc 100644 --- a/render/egl.c +++ b/render/egl.c @@ -560,6 +560,27 @@ bool wlr_egl_is_current(struct wlr_egl *egl) { return eglGetCurrentContext() == egl->context; } +bool wlr_egl_context_set_current(struct wlr_egl_context *ctx) { + if (!eglMakeCurrent(ctx->display, EGL_NO_SURFACE, EGL_NO_SURFACE, + ctx->context)) { + wlr_log(WLR_ERROR, "eglMakeCurrent failed"); + return false; + } + return true; +} + +bool wlr_egl_context_unset_current(struct wlr_egl_context *ctx) { + if (!eglMakeCurrent(ctx->display, EGL_NO_SURFACE, EGL_NO_SURFACE, + EGL_NO_CONTEXT)) { + wlr_log(WLR_ERROR, "eglMakeCurrent failed"); + return false; + } + return true; +} + +bool wlr_egl_context_is_current(struct wlr_egl_context *ctx) { + return eglGetCurrentContext() == ctx->context; +} void wlr_egl_context_save(struct wlr_egl_context *context) { context->display = eglGetCurrentDisplay(); @@ -568,7 +589,6 @@ void wlr_egl_context_save(struct wlr_egl_context *context) { context->read_surface = eglGetCurrentSurface(EGL_READ); } - bool wlr_egl_context_restore(struct wlr_egl_context *context) { // If the saved context is a null-context, we must use the current // display instead of the saved display because eglMakeCurrent() can't