aboutsummaryrefslogtreecommitdiff
path: root/render
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2020-05-19 11:54:59 +0200
committerDrew DeVault <sir@cmpwn.com>2020-05-19 14:56:20 +0200
commit1edc42157bbb01b25ec27750f883fd84ee5908d6 (patch)
tree068205ea52bf4c76a86e96f19862f794852937d0 /render
parent781ed1ff02e38dffdfebca0fa80baa1791849c3b (diff)
render/egl: introduce wlr_egl_unset_current
This function can be called after wlr_egl_make_current to cleanup the EGL context. This avoids having lingering EGL contexts that make things work by chance. Closes: https://github.com/swaywm/wlroots/issues/2197
Diffstat (limited to 'render')
-rw-r--r--render/egl.c11
-rw-r--r--render/gles2/renderer.c6
-rw-r--r--render/gles2/texture.c34
3 files changed, 33 insertions, 18 deletions
diff --git a/render/egl.c b/render/egl.c
index b96a90f1..ec00a12f 100644
--- a/render/egl.c
+++ b/render/egl.c
@@ -387,6 +387,15 @@ bool wlr_egl_make_current(struct wlr_egl *egl, EGLSurface surface,
return true;
}
+bool wlr_egl_unset_current(struct wlr_egl *egl) {
+ if (!eglMakeCurrent(egl->display, EGL_NO_SURFACE, EGL_NO_SURFACE,
+ EGL_NO_CONTEXT)) {
+ wlr_log(WLR_ERROR, "eglMakeCurrent failed");
+ return false;
+ }
+ return true;
+}
+
bool wlr_egl_is_current(struct wlr_egl *egl) {
return eglGetCurrentContext() == egl->context;
}
@@ -690,7 +699,7 @@ bool wlr_egl_destroy_surface(struct wlr_egl *egl, EGLSurface surface) {
// Reset the current EGL surface in case it's the one we're destroying,
// otherwise the next wlr_egl_make_current call will result in a
// use-after-free.
- wlr_egl_make_current(egl, NULL, NULL);
+ wlr_egl_make_current(egl, EGL_NO_SURFACE, NULL);
}
return eglDestroySurface(egl->display, surface);
}
diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c
index 8d197f42..e6ec881a 100644
--- a/render/gles2/renderer.c
+++ b/render/gles2/renderer.c
@@ -401,6 +401,8 @@ static void gles2_destroy(struct wlr_renderer *wlr_renderer) {
gles2_procs.glDebugMessageCallbackKHR(NULL, NULL);
}
+ wlr_egl_unset_current(renderer->egl);
+
free(renderer);
}
@@ -670,6 +672,8 @@ struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_egl *egl) {
POP_GLES2_DEBUG;
+ wlr_egl_unset_current(renderer->egl);
+
return &renderer->wlr_renderer;
error:
@@ -686,6 +690,8 @@ error:
gles2_procs.glDebugMessageCallbackKHR(NULL, NULL);
}
+ wlr_egl_unset_current(renderer->egl);
+
free(renderer);
return NULL;
}
diff --git a/render/gles2/texture.c b/render/gles2/texture.c
index 32efb03f..64a0d9f1 100644
--- a/render/gles2/texture.c
+++ b/render/gles2/texture.c
@@ -29,9 +29,7 @@ struct wlr_gles2_texture *gles2_get_texture(
static struct wlr_gles2_texture *get_gles2_texture_in_context(
struct wlr_texture *wlr_texture) {
struct wlr_gles2_texture *texture = gles2_get_texture(wlr_texture);
- if (!wlr_egl_is_current(texture->egl)) {
- wlr_egl_make_current(texture->egl, EGL_NO_SURFACE, NULL);
- }
+ wlr_egl_make_current(texture->egl, EGL_NO_SURFACE, NULL);
return texture;
}
@@ -49,6 +47,7 @@ static bool gles2_texture_write_pixels(struct wlr_texture *wlr_texture,
if (texture->target != GL_TEXTURE_2D) {
wlr_log(WLR_ERROR, "Cannot write pixels to immutable texture");
+ wlr_egl_unset_current(texture->egl);
return false;
}
@@ -75,6 +74,8 @@ static bool gles2_texture_write_pixels(struct wlr_texture *wlr_texture,
glBindTexture(GL_TEXTURE_2D, 0);
POP_GLES2_DEBUG;
+
+ wlr_egl_unset_current(texture->egl);
return true;
}
@@ -111,11 +112,8 @@ static void gles2_texture_destroy(struct wlr_texture *wlr_texture) {
return;
}
- struct wlr_gles2_texture *texture = gles2_get_texture(wlr_texture);
-
- if (!wlr_egl_is_current(texture->egl)) {
- wlr_egl_make_current(texture->egl, EGL_NO_SURFACE, NULL);
- }
+ struct wlr_gles2_texture *texture =
+ get_gles2_texture_in_context(wlr_texture);
PUSH_GLES2_DEBUG;
@@ -124,6 +122,8 @@ static void gles2_texture_destroy(struct wlr_texture *wlr_texture) {
POP_GLES2_DEBUG;
+ wlr_egl_unset_current(texture->egl);
+
free(texture);
}
@@ -137,9 +137,7 @@ static const struct wlr_texture_impl texture_impl = {
struct wlr_texture *wlr_gles2_texture_from_pixels(struct wlr_egl *egl,
enum wl_shm_format wl_fmt, uint32_t stride, uint32_t width,
uint32_t height, const void *data) {
- if (!wlr_egl_is_current(egl)) {
- wlr_egl_make_current(egl, EGL_NO_SURFACE, NULL);
- }
+ wlr_egl_make_current(egl, EGL_NO_SURFACE, NULL);
const struct wlr_gles2_pixel_format *fmt = get_gles2_format_from_wl(wl_fmt);
if (fmt == NULL) {
@@ -172,14 +170,14 @@ struct wlr_texture *wlr_gles2_texture_from_pixels(struct wlr_egl *egl,
glBindTexture(GL_TEXTURE_2D, 0);
POP_GLES2_DEBUG;
+
+ wlr_egl_unset_current(egl);
return &texture->wlr_texture;
}
struct wlr_texture *wlr_gles2_texture_from_wl_drm(struct wlr_egl *egl,
struct wl_resource *resource) {
- if (!wlr_egl_is_current(egl)) {
- wlr_egl_make_current(egl, EGL_NO_SURFACE, NULL);
- }
+ wlr_egl_make_current(egl, EGL_NO_SURFACE, NULL);
if (!gles2_procs.glEGLImageTargetTexture2DOES) {
return NULL;
@@ -235,14 +233,14 @@ struct wlr_texture *wlr_gles2_texture_from_wl_drm(struct wlr_egl *egl,
glBindTexture(GL_TEXTURE_EXTERNAL_OES, 0);
POP_GLES2_DEBUG;
+
+ wlr_egl_unset_current(egl);
return &texture->wlr_texture;
}
struct wlr_texture *wlr_gles2_texture_from_dmabuf(struct wlr_egl *egl,
struct wlr_dmabuf_attributes *attribs) {
- if (!wlr_egl_is_current(egl)) {
- wlr_egl_make_current(egl, EGL_NO_SURFACE, NULL);
- }
+ wlr_egl_make_current(egl, EGL_NO_SURFACE, NULL);
if (!gles2_procs.glEGLImageTargetTexture2DOES) {
return NULL;
@@ -297,6 +295,8 @@ struct wlr_texture *wlr_gles2_texture_from_dmabuf(struct wlr_egl *egl,
glBindTexture(GL_TEXTURE_EXTERNAL_OES, 0);
POP_GLES2_DEBUG;
+
+ wlr_egl_unset_current(egl);
return &texture->wlr_texture;
}