aboutsummaryrefslogtreecommitdiff
path: root/render
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2021-01-09 12:00:31 +0100
committerSimon Ser <contact@emersion.fr>2021-01-12 11:31:04 +0100
commit1d461687d24856a15fd8c37f744f40730888c9b0 (patch)
tree7d4a3856171310b71b0edb42e0b3b82204952f52 /render
parent50b120927ddcf26c83b219ebe9351b143efebfad (diff)
render/egl: replace init/finish with create/destroy
This ensures wlr_gles2_renderer can properly take ownership of the wlr_egl. Closes: https://github.com/swaywm/wlroots/issues/2612
Diffstat (limited to 'render')
-rw-r--r--render/egl.c21
-rw-r--r--render/gles2/renderer.c4
-rw-r--r--render/wlr_renderer.c15
3 files changed, 18 insertions, 22 deletions
diff --git a/render/egl.c b/render/egl.c
index 57146a06..8cf20ece 100644
--- a/render/egl.c
+++ b/render/egl.c
@@ -149,8 +149,14 @@ out:
free(formats);
}
-bool wlr_egl_init(struct wlr_egl *egl, EGLenum platform, void *remote_display,
+struct wlr_egl *wlr_egl_create(EGLenum platform, void *remote_display,
const EGLint *config_attribs) {
+ struct wlr_egl *egl = calloc(1, sizeof(struct wlr_egl));
+ if (egl == NULL) {
+ wlr_log_errno(WLR_ERROR, "Allocation failed");
+ return NULL;
+ }
+
const char *client_exts_str = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
if (client_exts_str == NULL) {
if (eglGetError() == EGL_BAD_DISPLAY) {
@@ -158,12 +164,12 @@ bool wlr_egl_init(struct wlr_egl *egl, EGLenum platform, void *remote_display,
} else {
wlr_log(WLR_ERROR, "Failed to query EGL client extensions");
}
- return false;
+ return NULL;
}
if (!check_egl_ext(client_exts_str, "EGL_EXT_platform_base")) {
wlr_log(WLR_ERROR, "EGL_EXT_platform_base not supported");
- return false;
+ return NULL;
}
load_egl_proc(&egl->procs.eglGetPlatformDisplayEXT,
"eglGetPlatformDisplayEXT");
@@ -205,7 +211,7 @@ bool wlr_egl_init(struct wlr_egl *egl, EGLenum platform, void *remote_display,
const char *display_exts_str = eglQueryString(egl->display, EGL_EXTENSIONS);
if (display_exts_str == NULL) {
wlr_log(WLR_ERROR, "Failed to query EGL display extensions");
- return false;
+ return NULL;
}
if (check_egl_ext(display_exts_str, "EGL_KHR_image_base")) {
@@ -343,7 +349,7 @@ bool wlr_egl_init(struct wlr_egl *egl, EGLenum platform, void *remote_display,
}
}
- return true;
+ return egl;
error:
eglMakeCurrent(EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
@@ -351,10 +357,10 @@ error:
eglTerminate(egl->display);
}
eglReleaseThread();
- return false;
+ return NULL;
}
-void wlr_egl_finish(struct wlr_egl *egl) {
+void wlr_egl_destroy(struct wlr_egl *egl) {
if (egl == NULL) {
return;
}
@@ -371,6 +377,7 @@ void wlr_egl_finish(struct wlr_egl *egl) {
eglDestroyContext(egl->display, egl->context);
eglTerminate(egl->display);
eglReleaseThread();
+ free(egl);
}
bool wlr_egl_bind_display(struct wlr_egl *egl, struct wl_display *local_display) {
diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c
index 2a78eb3e..5474e1b6 100644
--- a/render/gles2/renderer.c
+++ b/render/gles2/renderer.c
@@ -694,9 +694,7 @@ static void gles2_destroy(struct wlr_renderer *wlr_renderer) {
}
wlr_egl_unset_current(renderer->egl);
-
- wlr_egl_finish(renderer->egl);
- free(renderer->egl);
+ wlr_egl_destroy(renderer->egl);
if (renderer->drm_fd >= 0) {
close(renderer->drm_fd);
diff --git a/render/wlr_renderer.c b/render/wlr_renderer.c
index b721036f..377b795e 100644
--- a/render/wlr_renderer.c
+++ b/render/wlr_renderer.c
@@ -249,25 +249,16 @@ bool wlr_renderer_init_wl_display(struct wlr_renderer *r,
struct wlr_renderer *wlr_renderer_autocreate(EGLenum platform,
void *remote_display) {
- struct wlr_egl *egl = calloc(1, sizeof(*egl));
+ struct wlr_egl *egl = wlr_egl_create(platform, remote_display, NULL);
if (egl == NULL) {
- wlr_log_errno(WLR_ERROR, "Allocation failed");
- return NULL;
- }
-
- if (!wlr_egl_init(egl, platform, remote_display, NULL)) {
wlr_log(WLR_ERROR, "Could not initialize EGL");
return NULL;
}
- /*
- * wlr_renderer becomes the owner of the previously wlr_egl, and will
- * take care of freeing the allocated memory
- * TODO: move the wlr_egl logic to wlr_gles2_renderer
- */
struct wlr_renderer *renderer = wlr_gles2_renderer_create(egl);
if (!renderer) {
- wlr_egl_finish(egl);
+ wlr_log(WLR_ERROR, "Failed to create GLES2 renderer");
+ wlr_egl_destroy(egl);
}
return renderer;