mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-25 14:15:58 +01:00
render/egl: add save_context parameter to wlr_egl_make_current()
Saving the old context and immediately making our own context current is a common pattern. Let's make it easier to do. No functional change, just refactoring.
This commit is contained in:
parent
2521fba37c
commit
d5556ec78f
4 changed files with 24 additions and 33 deletions
|
@ -105,10 +105,10 @@ bool wlr_egl_restore_context(struct wlr_egl_context *context);
|
|||
/**
|
||||
* Make the EGL context current.
|
||||
*
|
||||
* Callers are expected to clear the current context when they are done by
|
||||
* calling wlr_egl_unset_current().
|
||||
* The old EGL context is saved. Callers are expected to clear the current
|
||||
* context when they are done by calling wlr_egl_restore_context().
|
||||
*/
|
||||
bool wlr_egl_make_current(struct wlr_egl *egl);
|
||||
bool wlr_egl_make_current(struct wlr_egl *egl, struct wlr_egl_context *save_context);
|
||||
|
||||
bool wlr_egl_unset_current(struct wlr_egl *egl);
|
||||
|
||||
|
|
|
@ -649,7 +649,11 @@ bool wlr_egl_destroy_image(struct wlr_egl *egl, EGLImage image) {
|
|||
return egl->procs.eglDestroyImageKHR(egl->display, image);
|
||||
}
|
||||
|
||||
bool wlr_egl_make_current(struct wlr_egl *egl) {
|
||||
bool wlr_egl_make_current(struct wlr_egl *egl,
|
||||
struct wlr_egl_context *save_context) {
|
||||
if (save_context != NULL) {
|
||||
wlr_egl_save_context(save_context);
|
||||
}
|
||||
if (!eglMakeCurrent(egl->display, EGL_NO_SURFACE, EGL_NO_SURFACE,
|
||||
egl->context)) {
|
||||
wlr_log(WLR_ERROR, "eglMakeCurrent failed");
|
||||
|
|
|
@ -56,8 +56,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_make_current(buffer->renderer->egl);
|
||||
wlr_egl_make_current(buffer->renderer->egl, &prev_ctx);
|
||||
|
||||
push_gles2_debug(buffer->renderer);
|
||||
|
||||
|
@ -208,7 +207,7 @@ struct wlr_egl *wlr_gles2_renderer_get_egl(struct wlr_renderer *wlr_renderer) {
|
|||
static void gles2_destroy(struct wlr_renderer *wlr_renderer) {
|
||||
struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer);
|
||||
|
||||
wlr_egl_make_current(renderer->egl);
|
||||
wlr_egl_make_current(renderer->egl, NULL);
|
||||
|
||||
struct wlr_gles2_texture *tex, *tex_tmp;
|
||||
wl_list_for_each_safe(tex, tex_tmp, &renderer->textures, link) {
|
||||
|
@ -247,8 +246,7 @@ static struct wlr_render_pass *gles2_begin_buffer_pass(struct wlr_renderer *wlr_
|
|||
struct wlr_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer);
|
||||
|
||||
struct wlr_egl_context prev_ctx = {0};
|
||||
wlr_egl_save_context(&prev_ctx);
|
||||
if (!wlr_egl_make_current(renderer->egl)) {
|
||||
if (!wlr_egl_make_current(renderer->egl, &prev_ctx)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -276,8 +274,7 @@ GLuint wlr_gles2_renderer_get_buffer_fbo(struct wlr_renderer *wlr_renderer,
|
|||
GLuint fbo = 0;
|
||||
|
||||
struct wlr_egl_context prev_ctx = {0};
|
||||
wlr_egl_save_context(&prev_ctx);
|
||||
if (!wlr_egl_make_current(renderer->egl)) {
|
||||
if (!wlr_egl_make_current(renderer->egl, &prev_ctx)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -305,8 +302,7 @@ static struct wlr_render_timer *gles2_render_timer_create(struct wlr_renderer *w
|
|||
timer->renderer = renderer;
|
||||
|
||||
struct wlr_egl_context prev_ctx;
|
||||
wlr_egl_save_context(&prev_ctx);
|
||||
wlr_egl_make_current(renderer->egl);
|
||||
wlr_egl_make_current(renderer->egl, &prev_ctx);
|
||||
renderer->procs.glGenQueriesEXT(1, &timer->id);
|
||||
wlr_egl_restore_context(&prev_ctx);
|
||||
|
||||
|
@ -318,8 +314,7 @@ static int gles2_get_render_time(struct wlr_render_timer *wlr_timer) {
|
|||
struct wlr_gles2_renderer *renderer = timer->renderer;
|
||||
|
||||
struct wlr_egl_context prev_ctx;
|
||||
wlr_egl_save_context(&prev_ctx);
|
||||
wlr_egl_make_current(renderer->egl);
|
||||
wlr_egl_make_current(renderer->egl, &prev_ctx);
|
||||
|
||||
GLint64 disjoint;
|
||||
renderer->procs.glGetInteger64vEXT(GL_GPU_DISJOINT_EXT, &disjoint);
|
||||
|
@ -353,8 +348,7 @@ static void gles2_render_timer_destroy(struct wlr_render_timer *wlr_timer) {
|
|||
struct wlr_gles2_renderer *renderer = timer->renderer;
|
||||
|
||||
struct wlr_egl_context prev_ctx;
|
||||
wlr_egl_save_context(&prev_ctx);
|
||||
wlr_egl_make_current(renderer->egl);
|
||||
wlr_egl_make_current(renderer->egl, &prev_ctx);
|
||||
renderer->procs.glDeleteQueriesEXT(1, &timer->id);
|
||||
wlr_egl_restore_context(&prev_ctx);
|
||||
free(timer);
|
||||
|
@ -521,7 +515,7 @@ struct wlr_renderer *wlr_gles2_renderer_create_with_drm_fd(int drm_fd) {
|
|||
}
|
||||
|
||||
struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_egl *egl) {
|
||||
if (!wlr_egl_make_current(egl)) {
|
||||
if (!wlr_egl_make_current(egl, NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -68,8 +68,7 @@ static bool gles2_texture_update_from_buffer(struct wlr_texture *wlr_texture,
|
|||
}
|
||||
|
||||
struct wlr_egl_context prev_ctx;
|
||||
wlr_egl_save_context(&prev_ctx);
|
||||
wlr_egl_make_current(texture->renderer->egl);
|
||||
wlr_egl_make_current(texture->renderer->egl, &prev_ctx);
|
||||
|
||||
push_gles2_debug(texture->renderer);
|
||||
|
||||
|
@ -112,8 +111,7 @@ void gles2_texture_destroy(struct wlr_gles2_texture *texture) {
|
|||
wlr_buffer_unlock(texture->buffer->buffer);
|
||||
} else {
|
||||
struct wlr_egl_context prev_ctx;
|
||||
wlr_egl_save_context(&prev_ctx);
|
||||
wlr_egl_make_current(texture->renderer->egl);
|
||||
wlr_egl_make_current(texture->renderer->egl, &prev_ctx);
|
||||
|
||||
push_gles2_debug(texture->renderer);
|
||||
|
||||
|
@ -196,9 +194,7 @@ static bool gles2_texture_read_pixels(struct wlr_texture *wlr_texture,
|
|||
|
||||
push_gles2_debug(texture->renderer);
|
||||
struct wlr_egl_context prev_ctx;
|
||||
wlr_egl_save_context(&prev_ctx);
|
||||
|
||||
if (!wlr_egl_make_current(texture->renderer->egl)) {
|
||||
if (!wlr_egl_make_current(texture->renderer->egl, &prev_ctx)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -240,13 +236,12 @@ static uint32_t gles2_texture_preferred_read_format(struct wlr_texture *wlr_text
|
|||
struct wlr_gles2_texture *texture = gles2_get_texture(wlr_texture);
|
||||
|
||||
push_gles2_debug(texture->renderer);
|
||||
struct wlr_egl_context prev_ctx;
|
||||
wlr_egl_save_context(&prev_ctx);
|
||||
|
||||
uint32_t fmt = DRM_FORMAT_INVALID;
|
||||
|
||||
if (!wlr_egl_make_current(texture->renderer->egl)) {
|
||||
goto out;
|
||||
struct wlr_egl_context prev_ctx;
|
||||
if (!wlr_egl_make_current(texture->renderer->egl, &prev_ctx)) {
|
||||
return fmt;
|
||||
}
|
||||
|
||||
if (!gles2_texture_bind(texture)) {
|
||||
|
@ -339,8 +334,7 @@ static struct wlr_texture *gles2_texture_from_pixels(
|
|||
}
|
||||
|
||||
struct wlr_egl_context prev_ctx;
|
||||
wlr_egl_save_context(&prev_ctx);
|
||||
wlr_egl_make_current(renderer->egl);
|
||||
wlr_egl_make_current(renderer->egl, &prev_ctx);
|
||||
|
||||
push_gles2_debug(renderer);
|
||||
|
||||
|
@ -387,8 +381,7 @@ static struct wlr_texture *gles2_texture_from_dmabuf(
|
|||
texture->has_alpha = pixel_format_has_alpha(attribs->format);
|
||||
|
||||
struct wlr_egl_context prev_ctx;
|
||||
wlr_egl_save_context(&prev_ctx);
|
||||
wlr_egl_make_current(renderer->egl);
|
||||
wlr_egl_make_current(renderer->egl, &prev_ctx);
|
||||
push_gles2_debug(texture->renderer);
|
||||
|
||||
bool invalid;
|
||||
|
|
Loading…
Reference in a new issue