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. As an aside, this makes the viewport protocol
required for simplicity (but everyone supports that anyway).

Fixes mpv-player#9443.
  • Loading branch information
Dudemanguy committed Nov 29, 2022
1 parent e97e0e4 commit c1bccd7
Show file tree
Hide file tree
Showing 10 changed files with 168 additions and 61 deletions.
3 changes: 3 additions & 0 deletions DOCS/interface-changes.rst
Expand Up @@ -30,6 +30,9 @@ Interface changes
- add `--force-render`
- add `--wayland-content-type`
- deprecate `--drm-atomic`
- 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
7 changes: 5 additions & 2 deletions video/out/opengl/context_wayland.c
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->fractional_viewport)
vo_wayland_handle_fractional_scale(wl);
}

static bool wayland_egl_check_visible(struct ra_ctx *ctx)
Expand Down
11 changes: 2 additions & 9 deletions video/out/vo_dmabuf_wayland.c
Expand Up @@ -156,8 +156,8 @@ static void resize(struct vo *vo)
struct mp_rect src;
struct mp_rect dst;
struct mp_osd_res osd;
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 @@ -336,13 +336,6 @@ static int preinit(struct vo *vo)
return VO_ERROR;
}

if (!vo->wl->viewport) {
MP_FATAL(vo->wl, "Compositor doesn't support the %s protocol!\n",
wp_viewporter_interface.name);
return VO_ERROR;
}


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 @@ -166,8 +166,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 @@ -188,6 +188,10 @@ static int resize(struct vo *vo)
p->free_buffers = buf->next;
talloc_free(buf);
}

if (wl->fractional_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->fractional_viewport)
vo_wayland_handle_fractional_scale(wl);

return ra_vk_ctx_resize(ctx, width, height);
}

Expand Down

0 comments on commit c1bccd7

Please sign in to comment.