Skip to content

Commit

Permalink
wayland: add wp-fractional-scale-v1 support
Browse files Browse the repository at this point in the history
This protocol is pretty important since it finally lets us solve the
longstanding issue of fractional scaling in wayland (no more mpv doing
rendering over the target resolution and then being scaled down). This
protocol also can completely replace the buffer_scale usage that we are
currently using for integer scaling so hopefully this can be removed
sometime in the future. Note that vo_dmabuf_wayland is omitted from the
fractional scale handling because we want the compositor to handle all
the scaling for that VO.

Fixes mpv-player#9443.
  • Loading branch information
Dudemanguy committed Jan 15, 2023
1 parent 6cdce9e commit 9f07371
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 60 deletions.
3 changes: 3 additions & 0 deletions DOCS/interface-changes.rst
Expand Up @@ -45,6 +45,9 @@ Interface changes
watch-later. It is still written by default but you may
need to explictly add `start` depending on how you have
`--watch-later-options` configured.
- add support for the fractional scale protocol in wayland
- in wayland, hidpi window scaling now scales the window by the compositor's
dpi scale factor by default (can be disabled with --no-hidpi-window-scale).
--- mpv 0.35.0 ---
- add the `--vo=gpu-next` video output driver, as well as the options
`--allow-delayed-peak-detect`, `--builtin-scalers`,
Expand Down
5 changes: 5 additions & 0 deletions generated/wayland/meson.build
Expand Up @@ -16,6 +16,11 @@ if features['wayland_protocols_1_27']
[wl_protocol_dir, 'staging/single-pixel-buffer/single-pixel-buffer-v1.xml']]
endif

features += {'wayland_protocols_1_31': wayland['deps'][2].version().version_compare('>=1.31')}
if features['wayland_protocols_1_31']
protocols += [[wl_protocol_dir, 'staging/fractional-scale/fractional-scale-v1.xml']]
endif

foreach p: protocols
xml = join_paths(p)
wl_protocols_source += custom_target(xml.underscorify() + '_c',
Expand Down
11 changes: 7 additions & 4 deletions video/out/opengl/context_wayland.c
Expand Up @@ -43,8 +43,8 @@ static void egl_create_window(struct ra_ctx *ctx)
struct vo_wayland_state *wl = ctx->vo->wl;

p->egl_window = wl_egl_window_create(wl->surface,
mp_rect_w(wl->geometry) * wl->scaling,
mp_rect_h(wl->geometry) * wl->scaling);
mp_rect_w(wl->geometry),
mp_rect_h(wl->geometry));

p->egl_surface = mpegl_create_window_surface(
p->egl_display, p->egl_config, p->egl_window);
Expand Down Expand Up @@ -75,15 +75,18 @@ static void resize(struct ra_ctx *ctx)
if (!p->egl_window)
egl_create_window(ctx);

const int32_t width = wl->scaling * mp_rect_w(wl->geometry);
const int32_t height = wl->scaling * mp_rect_h(wl->geometry);
const int32_t width = mp_rect_w(wl->geometry);
const int32_t height = mp_rect_h(wl->geometry);

vo_wayland_set_opaque_region(wl, ctx->opts.want_alpha);
if (p->egl_window)
wl_egl_window_resize(p->egl_window, width, height, 0, 0);

wl->vo->dwidth = width;
wl->vo->dheight = height;

if (wl->viewport)
vo_wayland_handle_fractional_scale(wl);
}

static bool wayland_egl_check_visible(struct ra_ctx *ctx)
Expand Down
7 changes: 2 additions & 5 deletions video/out/vo_dmabuf_wayland.c
@@ -1,6 +1,4 @@
/*
* Based on vo_gl.c by Reimar Doeffinger.
*
* This file is part of mpv.
*
* mpv is free software; you can redistribute it and/or
Expand Down Expand Up @@ -178,8 +176,8 @@ static void resize(struct vo *vo)
struct mp_rect dst;
struct mp_osd_res osd;
struct mp_vo_opts *vo_opts = wl->vo_opts;
const int width = wl->scaling * mp_rect_w(wl->geometry);
const int height = wl->scaling * mp_rect_h(wl->geometry);
const int width = mp_rect_w(wl->geometry);
const int height = mp_rect_h(wl->geometry);

vo_wayland_set_opaque_region(wl, 0);
vo->dwidth = width;
Expand Down Expand Up @@ -378,7 +376,6 @@ static int preinit(struct vo *vo)
goto err;
}


if (vo->wl->single_pixel_manager) {
#if HAVE_WAYLAND_PROTOCOLS_1_27
p->solid_buffer = wp_single_pixel_buffer_manager_v1_create_u32_rgba_buffer(
Expand Down
8 changes: 6 additions & 2 deletions video/out/vo_wlshm.c
Expand Up @@ -182,8 +182,8 @@ static int resize(struct vo *vo)
{
struct priv *p = vo->priv;
struct vo_wayland_state *wl = vo->wl;
const int32_t width = wl->scaling * mp_rect_w(wl->geometry);
const int32_t height = wl->scaling * mp_rect_h(wl->geometry);
const int32_t width = mp_rect_w(wl->geometry);
const int32_t height = mp_rect_h(wl->geometry);
struct buffer *buf;

vo_wayland_set_opaque_region(wl, 0);
Expand All @@ -204,6 +204,10 @@ static int resize(struct vo *vo)
p->free_buffers = buf->next;
talloc_free(buf);
}

if (wl->viewport)
vo_wayland_handle_fractional_scale(wl);

return mp_sws_reinit(p->sws);
}

Expand Down
8 changes: 6 additions & 2 deletions video/out/vulkan/context_wayland.c
Expand Up @@ -114,10 +114,14 @@ 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);
const int32_t width = mp_rect_w(wl->geometry);
const int32_t height = mp_rect_h(wl->geometry);

vo_wayland_set_opaque_region(wl, ctx->opts.want_alpha);

if (wl->viewport)
vo_wayland_handle_fractional_scale(wl);

return ra_vk_ctx_resize(ctx, width, height);
}

Expand Down

0 comments on commit 9f07371

Please sign in to comment.