mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2024-11-22 07:02:28 +00: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
@ -105,10 +105,10 @@ bool wlr_egl_restore_context(struct wlr_egl_context *context);
|
|||||||
/**
|
/**
|
||||||
* Make the EGL context current.
|
* Make the EGL context current.
|
||||||
*
|
*
|
||||||
* Callers are expected to clear the current context when they are done by
|
* The old EGL context is saved. Callers are expected to clear the current
|
||||||
* calling wlr_egl_unset_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);
|
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);
|
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,
|
if (!eglMakeCurrent(egl->display, EGL_NO_SURFACE, EGL_NO_SURFACE,
|
||||||
egl->context)) {
|
egl->context)) {
|
||||||
wlr_log(WLR_ERROR, "eglMakeCurrent failed");
|
wlr_log(WLR_ERROR, "eglMakeCurrent failed");
|
||||||
|
@ -56,8 +56,7 @@ static void destroy_buffer(struct wlr_gles2_buffer *buffer) {
|
|||||||
wlr_addon_finish(&buffer->addon);
|
wlr_addon_finish(&buffer->addon);
|
||||||
|
|
||||||
struct wlr_egl_context prev_ctx;
|
struct wlr_egl_context prev_ctx;
|
||||||
wlr_egl_save_context(&prev_ctx);
|
wlr_egl_make_current(buffer->renderer->egl, &prev_ctx);
|
||||||
wlr_egl_make_current(buffer->renderer->egl);
|
|
||||||
|
|
||||||
push_gles2_debug(buffer->renderer);
|
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) {
|
static void gles2_destroy(struct wlr_renderer *wlr_renderer) {
|
||||||
struct wlr_gles2_renderer *renderer = gles2_get_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;
|
struct wlr_gles2_texture *tex, *tex_tmp;
|
||||||
wl_list_for_each_safe(tex, tex_tmp, &renderer->textures, link) {
|
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_gles2_renderer *renderer = gles2_get_renderer(wlr_renderer);
|
||||||
|
|
||||||
struct wlr_egl_context prev_ctx = {0};
|
struct wlr_egl_context prev_ctx = {0};
|
||||||
wlr_egl_save_context(&prev_ctx);
|
if (!wlr_egl_make_current(renderer->egl, &prev_ctx)) {
|
||||||
if (!wlr_egl_make_current(renderer->egl)) {
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -276,8 +274,7 @@ GLuint wlr_gles2_renderer_get_buffer_fbo(struct wlr_renderer *wlr_renderer,
|
|||||||
GLuint fbo = 0;
|
GLuint fbo = 0;
|
||||||
|
|
||||||
struct wlr_egl_context prev_ctx = {0};
|
struct wlr_egl_context prev_ctx = {0};
|
||||||
wlr_egl_save_context(&prev_ctx);
|
if (!wlr_egl_make_current(renderer->egl, &prev_ctx)) {
|
||||||
if (!wlr_egl_make_current(renderer->egl)) {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -305,8 +302,7 @@ static struct wlr_render_timer *gles2_render_timer_create(struct wlr_renderer *w
|
|||||||
timer->renderer = renderer;
|
timer->renderer = renderer;
|
||||||
|
|
||||||
struct wlr_egl_context prev_ctx;
|
struct wlr_egl_context prev_ctx;
|
||||||
wlr_egl_save_context(&prev_ctx);
|
wlr_egl_make_current(renderer->egl, &prev_ctx);
|
||||||
wlr_egl_make_current(renderer->egl);
|
|
||||||
renderer->procs.glGenQueriesEXT(1, &timer->id);
|
renderer->procs.glGenQueriesEXT(1, &timer->id);
|
||||||
wlr_egl_restore_context(&prev_ctx);
|
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_gles2_renderer *renderer = timer->renderer;
|
||||||
|
|
||||||
struct wlr_egl_context prev_ctx;
|
struct wlr_egl_context prev_ctx;
|
||||||
wlr_egl_save_context(&prev_ctx);
|
wlr_egl_make_current(renderer->egl, &prev_ctx);
|
||||||
wlr_egl_make_current(renderer->egl);
|
|
||||||
|
|
||||||
GLint64 disjoint;
|
GLint64 disjoint;
|
||||||
renderer->procs.glGetInteger64vEXT(GL_GPU_DISJOINT_EXT, &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_gles2_renderer *renderer = timer->renderer;
|
||||||
|
|
||||||
struct wlr_egl_context prev_ctx;
|
struct wlr_egl_context prev_ctx;
|
||||||
wlr_egl_save_context(&prev_ctx);
|
wlr_egl_make_current(renderer->egl, &prev_ctx);
|
||||||
wlr_egl_make_current(renderer->egl);
|
|
||||||
renderer->procs.glDeleteQueriesEXT(1, &timer->id);
|
renderer->procs.glDeleteQueriesEXT(1, &timer->id);
|
||||||
wlr_egl_restore_context(&prev_ctx);
|
wlr_egl_restore_context(&prev_ctx);
|
||||||
free(timer);
|
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) {
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,8 +68,7 @@ static bool gles2_texture_update_from_buffer(struct wlr_texture *wlr_texture,
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct wlr_egl_context prev_ctx;
|
struct wlr_egl_context prev_ctx;
|
||||||
wlr_egl_save_context(&prev_ctx);
|
wlr_egl_make_current(texture->renderer->egl, &prev_ctx);
|
||||||
wlr_egl_make_current(texture->renderer->egl);
|
|
||||||
|
|
||||||
push_gles2_debug(texture->renderer);
|
push_gles2_debug(texture->renderer);
|
||||||
|
|
||||||
@ -112,8 +111,7 @@ void gles2_texture_destroy(struct wlr_gles2_texture *texture) {
|
|||||||
wlr_buffer_unlock(texture->buffer->buffer);
|
wlr_buffer_unlock(texture->buffer->buffer);
|
||||||
} else {
|
} else {
|
||||||
struct wlr_egl_context prev_ctx;
|
struct wlr_egl_context prev_ctx;
|
||||||
wlr_egl_save_context(&prev_ctx);
|
wlr_egl_make_current(texture->renderer->egl, &prev_ctx);
|
||||||
wlr_egl_make_current(texture->renderer->egl);
|
|
||||||
|
|
||||||
push_gles2_debug(texture->renderer);
|
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);
|
push_gles2_debug(texture->renderer);
|
||||||
struct wlr_egl_context prev_ctx;
|
struct wlr_egl_context prev_ctx;
|
||||||
wlr_egl_save_context(&prev_ctx);
|
if (!wlr_egl_make_current(texture->renderer->egl, &prev_ctx)) {
|
||||||
|
|
||||||
if (!wlr_egl_make_current(texture->renderer->egl)) {
|
|
||||||
return false;
|
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);
|
struct wlr_gles2_texture *texture = gles2_get_texture(wlr_texture);
|
||||||
|
|
||||||
push_gles2_debug(texture->renderer);
|
push_gles2_debug(texture->renderer);
|
||||||
struct wlr_egl_context prev_ctx;
|
|
||||||
wlr_egl_save_context(&prev_ctx);
|
|
||||||
|
|
||||||
uint32_t fmt = DRM_FORMAT_INVALID;
|
uint32_t fmt = DRM_FORMAT_INVALID;
|
||||||
|
|
||||||
if (!wlr_egl_make_current(texture->renderer->egl)) {
|
struct wlr_egl_context prev_ctx;
|
||||||
goto out;
|
if (!wlr_egl_make_current(texture->renderer->egl, &prev_ctx)) {
|
||||||
|
return fmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!gles2_texture_bind(texture)) {
|
if (!gles2_texture_bind(texture)) {
|
||||||
@ -339,8 +334,7 @@ static struct wlr_texture *gles2_texture_from_pixels(
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct wlr_egl_context prev_ctx;
|
struct wlr_egl_context prev_ctx;
|
||||||
wlr_egl_save_context(&prev_ctx);
|
wlr_egl_make_current(renderer->egl, &prev_ctx);
|
||||||
wlr_egl_make_current(renderer->egl);
|
|
||||||
|
|
||||||
push_gles2_debug(renderer);
|
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);
|
texture->has_alpha = pixel_format_has_alpha(attribs->format);
|
||||||
|
|
||||||
struct wlr_egl_context prev_ctx;
|
struct wlr_egl_context prev_ctx;
|
||||||
wlr_egl_save_context(&prev_ctx);
|
wlr_egl_make_current(renderer->egl, &prev_ctx);
|
||||||
wlr_egl_make_current(renderer->egl);
|
|
||||||
push_gles2_debug(texture->renderer);
|
push_gles2_debug(texture->renderer);
|
||||||
|
|
||||||
bool invalid;
|
bool invalid;
|
||||||
|
Loading…
Reference in New Issue
Block a user