1
0
mirror of https://github.com/mpv-player/mpv synced 2025-01-29 03:02:53 +00:00

wayland: update opaque region on runtime

Made possible with 00b9c81. 34b8adc let the wayland surface set an
opaque region depending on if alpha was set by the user or not. However,
there was no attempted detection for runtime changes and it is possible
(at least in wayland vulkan) to toggle the alpha on and off. So this
meant, we could be incorrectly signalling an opaque region if the user
happened to change the alpha. Additionally, add a helper function for
this and use it everywhere we want to set the opaque region.
This commit is contained in:
Dudemanguy 2020-10-05 10:28:37 -05:00
parent aacefa4ae5
commit b60545bdc6
5 changed files with 54 additions and 39 deletions

View File

@ -119,16 +119,10 @@ static void resize(struct ra_ctx *ctx)
MP_VERBOSE(wl, "Handling resize on the egl side\n");
const int32_t width = wl->scaling*mp_rect_w(wl->geometry);
const int32_t height = wl->scaling*mp_rect_h(wl->geometry);
if (!ctx->opts.want_alpha) {
struct wl_region *region = wl_compositor_create_region(wl->compositor);
wl_region_add(region, 0, 0, width, height);
wl_surface_set_opaque_region(wl->surface, region);
wl_region_destroy(region);
}
const int32_t width = wl->scaling * mp_rect_w(wl->geometry);
const int32_t height = wl->scaling * mp_rect_h(wl->geometry);
vo_wayland_set_opaque_region(wl, ctx->opts.want_alpha);
wl_surface_set_buffer_scale(wl->surface, wl->scaling);
if (p->egl_window)
@ -296,6 +290,13 @@ static void wayland_egl_wait_events(struct ra_ctx *ctx, int64_t until_time_us)
vo_wayland_wait_events(ctx->vo, until_time_us);
}
static void wayland_egl_update_render_opts(struct ra_ctx *ctx)
{
struct vo_wayland_state *wl = ctx->vo->wl;
vo_wayland_set_opaque_region(wl, ctx->opts.want_alpha);
wl_surface_commit(wl->surface);
}
static bool wayland_egl_init(struct ra_ctx *ctx)
{
if (!vo_wayland_init(ctx->vo)) {
@ -307,12 +308,13 @@ static bool wayland_egl_init(struct ra_ctx *ctx)
}
const struct ra_ctx_fns ra_ctx_wayland_egl = {
.type = "opengl",
.name = "wayland",
.reconfig = wayland_egl_reconfig,
.control = wayland_egl_control,
.wakeup = wayland_egl_wakeup,
.wait_events = wayland_egl_wait_events,
.init = wayland_egl_init,
.uninit = wayland_egl_uninit,
.type = "opengl",
.name = "wayland",
.reconfig = wayland_egl_reconfig,
.control = wayland_egl_control,
.wakeup = wayland_egl_wakeup,
.wait_events = wayland_egl_wait_events,
.update_render_opts = wayland_egl_update_render_opts,
.init = wayland_egl_init,
.uninit = wayland_egl_uninit,
};

View File

@ -201,11 +201,7 @@ static int resize(struct vo *vo)
const int32_t height = wl->scaling * mp_rect_h(wl->geometry);
struct buffer *buf;
struct wl_region *region = wl_compositor_create_region(wl->compositor);
wl_region_add(region, 0, 0, width, height);
wl_surface_set_opaque_region(wl->surface, region);
wl_region_destroy(region);
vo_wayland_set_opaque_region(wl, 0);
vo->want_redraw = true;
vo->dwidth = width;
vo->dheight = height;

View File

@ -205,16 +205,10 @@ static bool resize(struct ra_ctx *ctx)
MP_VERBOSE(wl, "Handling resize on the vk side\n");
const int32_t width = wl->scaling*mp_rect_w(wl->geometry);
const int32_t height = wl->scaling*mp_rect_h(wl->geometry);
if (!ctx->opts.want_alpha) {
struct wl_region *region = wl_compositor_create_region(wl->compositor);
wl_region_add(region, 0, 0, width, height);
wl_surface_set_opaque_region(wl->surface, region);
wl_region_destroy(region);
}
const int32_t width = wl->scaling * mp_rect_w(wl->geometry);
const int32_t height = wl->scaling * mp_rect_h(wl->geometry);
vo_wayland_set_opaque_region(wl, ctx->opts.want_alpha);
wl_surface_set_buffer_scale(wl->surface, wl->scaling);
bool ok = ra_vk_ctx_resize(ctx, width, height);
if (!wl->vo_opts->fullscreen && !wl->vo_opts->window_maximized)
@ -250,13 +244,21 @@ static void wayland_vk_wait_events(struct ra_ctx *ctx, int64_t until_time_us)
vo_wayland_wait_events(ctx->vo, until_time_us);
}
static void wayland_vk_update_render_opts(struct ra_ctx *ctx)
{
struct vo_wayland_state *wl = ctx->vo->wl;
vo_wayland_set_opaque_region(wl, ctx->opts.want_alpha);
wl_surface_commit(wl->surface);
}
const struct ra_ctx_fns ra_ctx_vulkan_wayland = {
.type = "vulkan",
.name = "waylandvk",
.reconfig = wayland_vk_reconfig,
.control = wayland_vk_control,
.wakeup = wayland_vk_wakeup,
.wait_events = wayland_vk_wait_events,
.init = wayland_vk_init,
.uninit = wayland_vk_uninit,
.type = "vulkan",
.name = "waylandvk",
.reconfig = wayland_vk_reconfig,
.control = wayland_vk_control,
.wakeup = wayland_vk_wakeup,
.wait_events = wayland_vk_wait_events,
.update_render_opts = wayland_vk_update_render_opts,
.init = wayland_vk_init,
.uninit = wayland_vk_uninit,
};

View File

@ -1612,6 +1612,20 @@ int vo_wayland_control(struct vo *vo, int *events, int request, void *arg)
return VO_NOTIMPL;
}
void vo_wayland_set_opaque_region(struct vo_wayland_state *wl, int alpha)
{
const int32_t width = wl->scaling * mp_rect_w(wl->geometry);
const int32_t height = wl->scaling * mp_rect_h(wl->geometry);
if (!alpha) {
struct wl_region *region = wl_compositor_create_region(wl->compositor);
wl_region_add(region, 0, 0, width, height);
wl_surface_set_opaque_region(wl->surface, region);
wl_region_destroy(region);
} else {
wl_surface_set_opaque_region(wl->surface, NULL);
}
}
void vo_wayland_sync_clear(struct vo_wayland_state *wl)
{
struct vo_wayland_sync sync = {0, 0, 0, 0};

View File

@ -153,6 +153,7 @@ void vo_wayland_uninit(struct vo *vo);
void vo_wayland_wakeup(struct vo *vo);
void vo_wayland_wait_events(struct vo *vo, int64_t until_time_us);
void vo_wayland_wait_frame(struct vo_wayland_state *wl);
void vo_wayland_set_opaque_region(struct vo_wayland_state *wl, int alpha);
void vo_wayland_sync_clear(struct vo_wayland_state *wl);
void wayland_sync_swap(struct vo_wayland_state *wl);
void vo_wayland_sync_shift(struct vo_wayland_state *wl);