mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2025-11-10 13:29:44 -05:00
render/egl: make wlr_egl_context public
This commit is contained in:
parent
3c26244340
commit
6eff6c365b
5 changed files with 36 additions and 34 deletions
|
|
@ -3,13 +3,6 @@
|
|||
|
||||
#include <wlr/render/egl.h>
|
||||
|
||||
struct wlr_egl_context {
|
||||
EGLDisplay display;
|
||||
EGLContext context;
|
||||
EGLSurface draw_surface;
|
||||
EGLSurface read_surface;
|
||||
};
|
||||
|
||||
/**
|
||||
* Initializes an EGL context for the given DRM FD.
|
||||
*
|
||||
|
|
@ -48,16 +41,4 @@ bool wlr_egl_destroy_image(struct wlr_egl *egl, EGLImageKHR image);
|
|||
|
||||
int wlr_egl_dup_drm_fd(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);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -29,6 +29,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 {
|
||||
EGLDisplay display;
|
||||
EGLContext context;
|
||||
|
|
@ -80,4 +87,16 @@ 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_context_save(struct wlr_egl_context *context);
|
||||
|
||||
/**
|
||||
* Restore EGL context that was previously saved using wlr_egl_context_save().
|
||||
*/
|
||||
bool wlr_egl_context_restore(struct wlr_egl_context *context);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -560,14 +560,16 @@ bool wlr_egl_is_current(struct wlr_egl *egl) {
|
|||
return eglGetCurrentContext() == egl->context;
|
||||
}
|
||||
|
||||
void wlr_egl_save_context(struct wlr_egl_context *context) {
|
||||
|
||||
void wlr_egl_context_save(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) {
|
||||
|
||||
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
|
||||
// handle EGL_NO_DISPLAY.
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ static void destroy_buffer(struct wlr_gles2_buffer *buffer) {
|
|||
wlr_addon_finish(&buffer->addon);
|
||||
|
||||
struct wlr_egl_context prev_ctx;
|
||||
wlr_egl_save_context(&prev_ctx);
|
||||
wlr_egl_context_save(&prev_ctx);
|
||||
wlr_egl_make_current(buffer->renderer->egl);
|
||||
|
||||
push_gles2_debug(buffer->renderer);
|
||||
|
|
@ -63,7 +63,7 @@ static void destroy_buffer(struct wlr_gles2_buffer *buffer) {
|
|||
|
||||
wlr_egl_destroy_image(buffer->renderer->egl, buffer->image);
|
||||
|
||||
wlr_egl_restore_context(&prev_ctx);
|
||||
wlr_egl_context_restore(&prev_ctx);
|
||||
|
||||
free(buffer);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ static bool gles2_texture_write_pixels(struct wlr_texture *wlr_texture,
|
|||
}
|
||||
|
||||
struct wlr_egl_context prev_ctx;
|
||||
wlr_egl_save_context(&prev_ctx);
|
||||
wlr_egl_context_save(&prev_ctx);
|
||||
wlr_egl_make_current(texture->renderer->egl);
|
||||
|
||||
push_gles2_debug(texture->renderer);
|
||||
|
|
@ -95,7 +95,7 @@ static bool gles2_texture_write_pixels(struct wlr_texture *wlr_texture,
|
|||
|
||||
pop_gles2_debug(texture->renderer);
|
||||
|
||||
wlr_egl_restore_context(&prev_ctx);
|
||||
wlr_egl_context_restore(&prev_ctx);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -110,7 +110,7 @@ static bool gles2_texture_invalidate(struct wlr_gles2_texture *texture) {
|
|||
}
|
||||
|
||||
struct wlr_egl_context prev_ctx;
|
||||
wlr_egl_save_context(&prev_ctx);
|
||||
wlr_egl_context_save(&prev_ctx);
|
||||
wlr_egl_make_current(texture->renderer->egl);
|
||||
|
||||
push_gles2_debug(texture->renderer);
|
||||
|
|
@ -122,7 +122,7 @@ static bool gles2_texture_invalidate(struct wlr_gles2_texture *texture) {
|
|||
|
||||
pop_gles2_debug(texture->renderer);
|
||||
|
||||
wlr_egl_restore_context(&prev_ctx);
|
||||
wlr_egl_context_restore(&prev_ctx);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -134,7 +134,7 @@ void gles2_texture_destroy(struct wlr_gles2_texture *texture) {
|
|||
}
|
||||
|
||||
struct wlr_egl_context prev_ctx;
|
||||
wlr_egl_save_context(&prev_ctx);
|
||||
wlr_egl_context_save(&prev_ctx);
|
||||
wlr_egl_make_current(texture->renderer->egl);
|
||||
|
||||
push_gles2_debug(texture->renderer);
|
||||
|
|
@ -144,7 +144,7 @@ void gles2_texture_destroy(struct wlr_gles2_texture *texture) {
|
|||
|
||||
pop_gles2_debug(texture->renderer);
|
||||
|
||||
wlr_egl_restore_context(&prev_ctx);
|
||||
wlr_egl_context_restore(&prev_ctx);
|
||||
|
||||
free(texture);
|
||||
}
|
||||
|
|
@ -211,7 +211,7 @@ static struct wlr_texture *gles2_texture_from_pixels(
|
|||
texture->drm_format = fmt->drm_format;
|
||||
|
||||
struct wlr_egl_context prev_ctx;
|
||||
wlr_egl_save_context(&prev_ctx);
|
||||
wlr_egl_context_save(&prev_ctx);
|
||||
wlr_egl_make_current(renderer->egl);
|
||||
|
||||
push_gles2_debug(renderer);
|
||||
|
|
@ -230,7 +230,7 @@ static struct wlr_texture *gles2_texture_from_pixels(
|
|||
|
||||
pop_gles2_debug(renderer);
|
||||
|
||||
wlr_egl_restore_context(&prev_ctx);
|
||||
wlr_egl_context_restore(&prev_ctx);
|
||||
|
||||
return &texture->wlr_texture;
|
||||
}
|
||||
|
|
@ -263,7 +263,7 @@ static struct wlr_texture *gles2_texture_from_dmabuf(
|
|||
}
|
||||
|
||||
struct wlr_egl_context prev_ctx;
|
||||
wlr_egl_save_context(&prev_ctx);
|
||||
wlr_egl_context_save(&prev_ctx);
|
||||
wlr_egl_make_current(renderer->egl);
|
||||
|
||||
bool external_only;
|
||||
|
|
@ -271,7 +271,7 @@ static struct wlr_texture *gles2_texture_from_dmabuf(
|
|||
wlr_egl_create_image_from_dmabuf(renderer->egl, attribs, &external_only);
|
||||
if (texture->image == EGL_NO_IMAGE_KHR) {
|
||||
wlr_log(WLR_ERROR, "Failed to create EGL image from DMA-BUF");
|
||||
wlr_egl_restore_context(&prev_ctx);
|
||||
wlr_egl_context_restore(&prev_ctx);
|
||||
wl_list_remove(&texture->link);
|
||||
free(texture);
|
||||
return NULL;
|
||||
|
|
@ -290,7 +290,7 @@ static struct wlr_texture *gles2_texture_from_dmabuf(
|
|||
|
||||
pop_gles2_debug(renderer);
|
||||
|
||||
wlr_egl_restore_context(&prev_ctx);
|
||||
wlr_egl_context_restore(&prev_ctx);
|
||||
|
||||
return &texture->wlr_texture;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue