Skip to content

Commit

Permalink
wayland: add support for xx-color-management-v4
Browse files Browse the repository at this point in the history
Although this protocol isn't official yet, several compositors are known
to support it to some extent and this lets users actually view HDR with
less hacks/workarounds. The actual protocol here is simply copy and
pasted from the upstream fork* where these are developed. There is also
icc profile support in the protocol, but this is omitted for now in
favor of setting colorspaces and signalling hdr metadata.

*: https://gitlab.freedesktop.org/swick/wayland-protocols/-/tree/color-xx/staging/color-management
  • Loading branch information
Dudemanguy committed Oct 11, 2024
1 parent 3b95c00 commit 274b6d8
Show file tree
Hide file tree
Showing 8 changed files with 1,771 additions and 3 deletions.
3 changes: 2 additions & 1 deletion video/out/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ protocols = [[wl_protocol_dir, 'stable/presentation-time/presentation-time.xml']
[wl_protocol_dir, 'unstable/linux-dmabuf/linux-dmabuf-unstable-v1.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/fractional-scale/fractional-scale-v1.xml'],
[wl_protocol_dir, 'staging/single-pixel-buffer/single-pixel-buffer-v1.xml'],
[wl_protocol_dir, 'staging/fractional-scale/fractional-scale-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
1,453 changes: 1,453 additions & 0 deletions video/out/protocols/xx-color-management-v4.xml

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions video/out/vo_dmabuf_wayland.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ struct priv {
bool destroy_buffers;
bool force_window;
enum hwdec_type hwdec_type;

struct mp_image_params target_params;
uint32_t drm_format;
uint64_t drm_modifier;
};
Expand Down Expand Up @@ -538,6 +540,12 @@ static void resize(struct vo *vo)
lround(vo->dheight / wl->scaling_factor));
wl_subsurface_set_position(wl->osd_subsurface, lround((0 - dst.x0) / wl->scaling_factor), lround((0 - dst.y0) / wl->scaling_factor));
set_viewport_source(vo, src);

mp_mutex_lock(&vo->params_mutex);
vo->target_params->w = mp_rect_w(dst);
vo->target_params->h = mp_rect_h(dst);
vo->target_params->rotate = (vo->params->rotate % 90) * 90;
mp_mutex_unlock(&vo->params_mutex);
}

static bool draw_osd(struct vo *vo, struct mp_image *cur, double pts)
Expand Down Expand Up @@ -612,6 +620,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 @@ -691,6 +700,17 @@ static int reconfig(struct vo *vo, struct mp_image *img)
if (!vo_wayland_reconfig(vo))
return VO_ERROR;

mp_mutex_lock(&vo->params_mutex);
p->target_params = img->params;
// Restore fallback layer parameters if available.
mp_image_params_restore_dovi_mapping(&p->target_params);
// Strip metadata that is not understood anyway.
struct pl_hdr_metadata *hdr = &p->target_params.color.hdr;
hdr->scene_max[0] = hdr->scene_max[1] = hdr->scene_max[2] = 0;
hdr->scene_avg = hdr->max_pq_y = hdr->avg_pq_y = 0;
vo->target_params = &p->target_params;
mp_mutex_unlock(&vo->params_mutex);

wl_surface_set_buffer_transform(vo->wl->video_surface, img->params.rotate / 90);

// Immediately destroy all buffers if params change.
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
7 changes: 7 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 Expand Up @@ -99,6 +101,11 @@ static bool wayland_vk_init(struct ra_ctx *ctx)
if (!ra_vk_ctx_init(ctx, vk, params, VK_PRESENT_MODE_MAILBOX_KHR))
goto error;

// Assume user is using vk_hdr_layer for color management.
const char *hdr_wsi = getenv("ENABLE_HDR_WSI");
if (hdr_wsi)
ctx->vo->wl->hdr_wsi = true;

ra_add_native_resource(ctx->ra, "wl", ctx->vo->wl->display);

return true;
Expand Down
Loading

0 comments on commit 274b6d8

Please sign in to comment.