Skip to content

Commit

Permalink
wayland: add support for color-management and color-representation
Browse files Browse the repository at this point in the history
It's not official yet but both of these protocols are currently the
leading things in terms of color on wayland. Several compositors have
some preliminary support or are working on it. We currently vendor both
of these protocols since they are still a WIP but color management is
pretty important for mpv so it's worth trying to experiment a bit with
it. Both protocols are copy and pasted from an upstream fork*. The main
focus here is on setting colorspaces and hdr metadata, so the compositor
can be aware of what mpv is trying to render.

*: https://gitlab.freedesktop.org/swick/wayland-protocols/-/tree/color-xx/staging/color-management
*: https://gitlab.freedesktop.org/swick/wayland-protocols/-/tree/color-representation
  • Loading branch information
Dudemanguy committed Sep 30, 2024
1 parent c11239b commit d6ce8ce
Show file tree
Hide file tree
Showing 9 changed files with 2,241 additions and 2 deletions.
4 changes: 3 additions & 1 deletion video/out/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ protocols = [[wl_protocol_dir, 'stable/presentation-time/presentation-time.xml']
[wl_protocol_dir, 'unstable/xdg-decoration/xdg-decoration-unstable-v1.xml'],
[wl_protocol_dir, 'staging/content-type/content-type-v1.xml'],
[wl_protocol_dir, 'staging/single-pixel-buffer/single-pixel-buffer-v1.xml'],
[wl_protocol_dir, 'staging/fractional-scale/fractional-scale-v1.xml']]
[wl_protocol_dir, 'staging/fractional-scale/fractional-scale-v1.xml'],
['protocols', 'color-representation-v1.xml'],
['protocols', 'xx-color-management-v4.xml']]
wl_protocols_source = []
wl_protocols_headers = []

Expand Down
2 changes: 2 additions & 0 deletions video/out/opengl/context_wayland.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ static void wayland_egl_swap_buffers(struct ra_ctx *ctx)
struct priv *p = ctx->priv;
struct vo_wayland_state *wl = ctx->vo->wl;

vo_wayland_handle_color(wl);

eglSwapBuffers(p->egl_display, p->egl_surface);

if (!wl->opts->wl_disable_vsync)
Expand Down
395 changes: 395 additions & 0 deletions video/out/protocols/color-representation-v1.xml

Large diffs are not rendered by default.

1,453 changes: 1,453 additions & 0 deletions video/out/protocols/xx-color-management-v4.xml

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions video/out/vo_dmabuf_wayland.c
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@ static void draw_frame(struct vo *vo, struct vo_frame *frame)
buf = buffer_get(vo, frame);

if (buf && buf->frame) {
vo_wayland_handle_color(wl);
struct mp_image *image = buf->frame->current;
wl_surface_attach(wl->video_surface, buf->buffer, 0, 0);
wl_surface_damage_buffer(wl->video_surface, 0, 0, image->w,
Expand Down Expand Up @@ -671,6 +672,10 @@ static int reconfig(struct vo *vo, struct mp_image *img)
{
struct priv *p = vo->priv;

mp_mutex_lock(&vo->params_mutex);
vo->target_params = &img->params;
mp_mutex_unlock(&vo->params_mutex);

if (img->params.force_window) {
p->force_window = true;
goto done;
Expand Down
2 changes: 2 additions & 0 deletions video/out/vo_wlshm.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ static int resize(struct vo *vo)
vo->target_params = &p->sws->dst;
mp_mutex_unlock(&vo->params_mutex);

vo_wayland_handle_color(wl);

while (p->free_buffers) {
buf = p->free_buffers;
p->free_buffers = buf->next;
Expand Down
2 changes: 2 additions & 0 deletions video/out/vulkan/context_wayland.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ static void wayland_vk_swap_buffers(struct ra_ctx *ctx)
{
struct vo_wayland_state *wl = ctx->vo->wl;

vo_wayland_handle_color(wl);

if (!wl->opts->wl_disable_vsync)
vo_wayland_wait_frame(wl);

Expand Down
Loading

0 comments on commit d6ce8ce

Please sign in to comment.