wayland: cleanup on vo_wayland_init error

Instead of just returning true/false, it's better to have this function
cleanup itself. We can eliminate some redundant uninit calls elsewhere
in the code as well.
This commit is contained in:
Dudemanguy 2023-01-08 13:31:03 -06:00
parent e4e0e7dfcf
commit d73fc7912a
3 changed files with 12 additions and 13 deletions

View File

@ -208,11 +208,8 @@ static void wayland_egl_update_render_opts(struct ra_ctx *ctx)
static bool wayland_egl_init(struct ra_ctx *ctx)
{
if (!vo_wayland_init(ctx->vo)) {
vo_wayland_uninit(ctx->vo);
if (!vo_wayland_init(ctx->vo))
return false;
}
return egl_create_context(ctx);
}

View File

@ -1953,10 +1953,10 @@ bool vo_wayland_init(struct vo *vo)
wl_list_init(&wl->output_list);
if (!wl->display)
return false;
goto err;
if (create_input(wl))
return false;
goto err;
wl->registry = wl_display_get_registry(wl->display);
wl_registry_add_listener(wl->registry, &registry_listener, wl);
@ -1967,24 +1967,24 @@ bool vo_wayland_init(struct vo *vo)
if (!wl->surface) {
MP_FATAL(wl, "Compositor doesn't support %s (ver. 4)\n",
wl_compositor_interface.name);
return false;
goto err;
}
if (!wl->wm_base) {
MP_FATAL(wl, "Compositor doesn't support the required %s protocol!\n",
xdg_wm_base_interface.name);
return false;
goto err;
}
if (!wl_list_length(&wl->output_list)) {
MP_FATAL(wl, "No outputs found or compositor doesn't support %s (ver. 2)\n",
wl_output_interface.name);
return false;
goto err;
}
/* Can't be initialized during registry due to multi-protocol dependence */
if (create_xdg_surface(wl))
return false;
goto err;
if (wl->subcompositor) {
wl->video_subsurface = wl_subcompositor_get_subsurface(wl->subcompositor, wl->video_surface, wl->surface);
@ -2063,6 +2063,10 @@ bool vo_wayland_init(struct vo *vo)
wl_display_roundtrip(wl->display);
return true;
err:
vo_wayland_uninit(vo);
return false;
}
int vo_wayland_reconfig(struct vo *vo)

View File

@ -27,10 +27,8 @@ static void uninit(struct ra_ctx *ctx)
static bool init(struct ra_ctx *ctx)
{
if (!vo_wayland_init(ctx->vo)) {
vo_wayland_uninit(ctx->vo);
if (!vo_wayland_init(ctx->vo))
return false;
}
ctx->ra = ra_create_wayland(ctx->log, ctx->vo->wl->display);
return true;