From f864f9a14a7db7247cfec1e337abacbbcf1dc30f Mon Sep 17 00:00:00 2001 From: Dudemanguy Date: Sun, 15 Feb 2026 01:34:36 -0600 Subject: [PATCH] wayland: use set_color for vo_wayland_handle_color Move this out of swap_buffers. This makes it more consistent with what vo_dmabuf_wayland does. --- video/out/opengl/context_wayland.c | 8 +++- video/out/vo_dmabuf_wayland.c | 2 +- video/out/vo_gpu_next.c | 5 ++- video/out/vo_wlshm.c | 2 +- video/out/vulkan/context_wayland.c | 8 +++- video/out/wayland_common.c | 66 +++++++++++++++--------------- video/out/wayland_common.h | 4 +- 7 files changed, 54 insertions(+), 41 deletions(-) diff --git a/video/out/opengl/context_wayland.c b/video/out/opengl/context_wayland.c index 3200f9b10e..0849df68b8 100644 --- a/video/out/opengl/context_wayland.c +++ b/video/out/opengl/context_wayland.c @@ -62,13 +62,16 @@ static bool wayland_egl_check_visible(struct ra_ctx *ctx) return vo_wayland_check_visible(ctx->vo); } +static void wayland_egl_set_color(struct ra_ctx *ctx, struct mp_image_params *params) +{ + vo_wayland_handle_color(ctx->vo->wl, params); +} + 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_internal_vsync) @@ -108,6 +111,7 @@ static bool egl_create_context(struct ra_ctx *ctx) struct ra_ctx_params params = { .check_visible = wayland_egl_check_visible, + .set_color = wayland_egl_set_color, .swap_buffers = wayland_egl_swap_buffers, .get_vsync = wayland_egl_get_vsync, }; diff --git a/video/out/vo_dmabuf_wayland.c b/video/out/vo_dmabuf_wayland.c index a98fc488a8..b4fbcc2f39 100644 --- a/video/out/vo_dmabuf_wayland.c +++ b/video/out/vo_dmabuf_wayland.c @@ -636,7 +636,7 @@ static bool draw_frame(struct vo *vo, struct vo_frame *frame) vo_wait_on_vo(vo, !wl->image_description_processed); p->vo_is_waiting = !wl->image_description_processed; } - vo_wayland_handle_color(wl); + vo_wayland_handle_color(wl, &frame->current->params); 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, diff --git a/video/out/vo_gpu_next.c b/video/out/vo_gpu_next.c index f913615efd..999ff66daf 100644 --- a/video/out/vo_gpu_next.c +++ b/video/out/vo_gpu_next.c @@ -963,6 +963,9 @@ static void set_colorspace_hint(struct priv *p, struct pl_color_space *hint) if (sw->fns->set_color) { sw->fns->set_color(sw, ¶ms); + // Wayland on Vulkan requires this until we can do VK_COLOR_SPACE_PASS_THROUGH_EXT + if (strcmp(p->ra_ctx->fns->name, "waylandvk") == 0) + pl_swapchain_colorspace_hint(p->sw, hint); if (hint) *hint = params.color; } else { @@ -1280,7 +1283,7 @@ static bool draw_frame(struct vo *vo, struct vo_frame *frame) // Calculate target struct pl_frame target; pl_frame_from_swapchain(&target, &swframe); - if (target_hint && sw->fns->set_color) + if (target_hint && sw->fns->set_color && strcmp(p->ra_ctx->fns->name, "waylandvk") != 0) target.color = hint; bool strict_sw_params = target_hint && p->next_opts->target_hint_strict; apply_target_options(p, &target, hint.hdr.min_luma, strict_sw_params); diff --git a/video/out/vo_wlshm.c b/video/out/vo_wlshm.c index c4c74f7285..18c0b8a509 100644 --- a/video/out/vo_wlshm.c +++ b/video/out/vo_wlshm.c @@ -261,7 +261,7 @@ static bool draw_frame(struct vo *vo, struct vo_frame *frame) } } if (src) { - vo_wayland_handle_color(wl); + vo_wayland_handle_color(wl, &src->params); struct mp_image dst = buf->mpi; struct mp_rect src_rc; struct mp_rect dst_rc; diff --git a/video/out/vulkan/context_wayland.c b/video/out/vulkan/context_wayland.c index 1e957158e1..d6295a845b 100644 --- a/video/out/vulkan/context_wayland.c +++ b/video/out/vulkan/context_wayland.c @@ -41,6 +41,11 @@ static bool wayland_vk_check_visible(struct ra_ctx *ctx) return vo_wayland_check_visible(ctx->vo); } +static void wayland_vk_set_color(struct ra_ctx *ctx, struct mp_image_params *params) +{ + vo_wayland_handle_color(ctx->vo->wl, params); +} + static pl_color_space_t wayland_vk_preferred_csp(struct ra_ctx *ctx) { return vo_wayland_preferred_csp(ctx->vo); @@ -51,8 +56,6 @@ static void wayland_vk_swap_buffers(struct ra_ctx *ctx) struct vo_wayland_state *wl = ctx->vo->wl; struct priv *p = ctx->priv; - vo_wayland_handle_color(wl); - if ((!p->use_fifo && wl->opts->wl_internal_vsync == 1) || wl->opts->wl_internal_vsync == 2) vo_wayland_wait_frame(wl); @@ -98,6 +101,7 @@ static bool wayland_vk_init(struct ra_ctx *ctx) .color_depth = wayland_vk_color_depth, .check_visible = wayland_vk_check_visible, .preferred_csp = wayland_vk_preferred_csp, + .set_color = wayland_vk_set_color, .swap_buffers = wayland_vk_swap_buffers, .get_vsync = wayland_vk_get_vsync, }; diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c index 889cc12f60..7edff30a71 100644 --- a/video/out/wayland_common.c +++ b/video/out/wayland_common.c @@ -3486,36 +3486,36 @@ static void seat_create_text_input(struct vo_wayland_seat *seat) zwp_text_input_v3_add_listener(seat->text_input->text_input, &text_input_listener, seat); } -static void set_color_management(struct vo_wayland_state *wl) +static void set_color_management(struct vo_wayland_state *wl, struct pl_color_space *color) { #if HAVE_WAYLAND_PROTOCOLS_1_41 if (!wl->color_surface || !wl->supports_parametric) goto nosupport; - struct pl_color_space color = wl->target_params.color; - int primaries = wl->primaries_map[color.primaries]; - int transfer = wl->transfer_map[color.transfer]; + int primaries = wl->primaries_map[color->primaries]; + int transfer = wl->transfer_map[color->transfer]; if (!primaries) - MP_VERBOSE(wl, "Compositor does not support color primary: %s\n", m_opt_choice_str(pl_csp_prim_names, color.primaries)); + MP_VERBOSE(wl, "Compositor does not support color primary: %s\n", m_opt_choice_str(pl_csp_prim_names, color->primaries)); if (!transfer) - MP_VERBOSE(wl, "Compositor does not support transfer function: %s\n", m_opt_choice_str(pl_csp_trc_names, color.transfer)); + MP_VERBOSE(wl, "Compositor does not support transfer function: %s\n", m_opt_choice_str(pl_csp_trc_names, color->transfer)); if (!primaries || !transfer) { + // Set to srgb if the compositor doesn't support it. wp_color_management_surface_v1_unset_image_description(wl->color_surface); goto nosupport; } MP_VERBOSE(wl, "Generating image creator params:\n"); MP_VERBOSE(wl, "primaries: %s, transfer: %s\n", - m_opt_choice_str(pl_csp_prim_names, color.primaries), - m_opt_choice_str(pl_csp_trc_names, color.transfer)); + m_opt_choice_str(pl_csp_prim_names, color->primaries), + m_opt_choice_str(pl_csp_trc_names, color->transfer)); struct wp_image_description_creator_params_v1 *image_creator_params = wp_color_manager_v1_create_parametric_creator(wl->color_manager); wp_image_description_creator_params_v1_set_primaries_named(image_creator_params, primaries); wp_image_description_creator_params_v1_set_tf_named(image_creator_params, transfer); - struct pl_hdr_metadata hdr = wl->target_params.color.hdr; - bool is_hdr = pl_color_transfer_is_hdr(color.transfer); + struct pl_hdr_metadata hdr = color->hdr; + bool is_hdr = pl_color_transfer_is_hdr(color->transfer); bool use_metadata = hdr_metadata_valid(wl, &hdr); if (!use_metadata) MP_VERBOSE(wl, "supplied HDR metadata does not conform to the wayland color management protocol. It will not be used.\n"); @@ -3553,12 +3553,14 @@ static void set_color_management(struct vo_wayland_state *wl) return; nosupport: + *color = pl_color_space_srgb; + pl_color_space_infer(color); wl->image_description_processed = true; return; #endif } -static void set_color_representation(struct vo_wayland_state *wl) +static void set_color_representation(struct vo_wayland_state *wl, struct mp_image_params *params) { #if HAVE_WAYLAND_PROTOCOLS_1_44 if (!wl->color_representation_manager) @@ -3570,13 +3572,12 @@ static void set_color_representation(struct vo_wayland_state *wl) wl->color_representation_surface = wp_color_representation_manager_v1_get_surface(wl->color_representation_manager, wl->callback_surface); - struct pl_color_repr repr = wl->target_params.repr; - int alpha = wl->alpha_map[repr.alpha]; - int coefficients = wl->coefficients_map[repr.sys]; - int range = repr.levels == PL_COLOR_LEVELS_FULL ? wl->range_map[repr.sys] : - wl->range_map[repr.sys + PL_COLOR_SYSTEM_COUNT]; - int chroma_location = map_supported_chroma_location(wl->target_params.chroma_location); - enum mp_imgfmt imgfmt = wl->target_params.hw_subfmt ? wl->target_params.hw_subfmt : wl->target_params.imgfmt; + int alpha = wl->alpha_map[params->repr.alpha]; + int coefficients = wl->coefficients_map[params->repr.sys]; + int range = params->repr.levels == PL_COLOR_LEVELS_FULL ? wl->range_map[params->repr.sys] : + wl->range_map[params->repr.sys + PL_COLOR_SYSTEM_COUNT]; + int chroma_location = map_supported_chroma_location(params->chroma_location); + enum mp_imgfmt imgfmt = params->hw_subfmt ? params->hw_subfmt : params->imgfmt; bool is_420_subsampled = mp_imgfmt_is_420_subsampled(imgfmt); if ((coefficients && range) || alpha || (is_420_subsampled && chroma_location)) @@ -3584,18 +3585,18 @@ static void set_color_representation(struct vo_wayland_state *wl) if (coefficients && range) { MP_VERBOSE(wl, " Coefficients: %s, Range: %s\n", - m_opt_choice_str(pl_csp_names, repr.sys), - m_opt_choice_str(pl_csp_levels_names, repr.levels)); + m_opt_choice_str(pl_csp_names, params->repr.sys), + m_opt_choice_str(pl_csp_levels_names, params->repr.levels)); wp_color_representation_surface_v1_set_coefficients_and_range(wl->color_representation_surface, coefficients, range); } if (alpha) { - MP_VERBOSE(wl, " Alpha mode: %s\n", m_opt_choice_str(pl_alpha_names, repr.alpha)); + MP_VERBOSE(wl, " Alpha mode: %s\n", m_opt_choice_str(pl_alpha_names, params->repr.alpha)); wp_color_representation_surface_v1_set_alpha_mode(wl->color_representation_surface, alpha); } if (is_420_subsampled && chroma_location) { - MP_VERBOSE(wl, " Chroma location: %s\n", m_opt_choice_str(pl_chroma_names, wl->target_params.chroma_location)); + MP_VERBOSE(wl, " Chroma location: %s\n", m_opt_choice_str(pl_chroma_names, params->chroma_location)); wp_color_representation_surface_v1_set_chroma_location(wl->color_representation_surface, chroma_location); } #endif @@ -4202,18 +4203,19 @@ int vo_wayland_control(struct vo *vo, int *events, int request, void *arg) return VO_NOTIMPL; } -void vo_wayland_handle_color(struct vo_wayland_state *wl) +void vo_wayland_handle_color(struct vo_wayland_state *wl, struct mp_image_params *params) { - if (!wl->vo->target_params) + bool color_space_changed = !pl_color_space_equal(&wl->current_params.color, ¶ms->color); + bool color_repr_changed = !pl_color_repr_equal(&wl->current_params.repr, ¶ms->repr) || + wl->current_params.chroma_location != params->chroma_location; + + if (!color_space_changed && !color_repr_changed) return; - struct mp_image_params target_params = vo_get_target_params(wl->vo); - if (pl_color_space_equal(&target_params.color, &wl->target_params.color) && - pl_color_repr_equal(&target_params.repr, &wl->target_params.repr) && - target_params.chroma_location == wl->target_params.chroma_location) - return; - wl->target_params = target_params; - set_color_management(wl); - set_color_representation(wl); + if (color_space_changed) + set_color_management(wl, ¶ms->color); + if (color_repr_changed) + set_color_representation(wl, params); + wl->current_params = *params; } diff --git a/video/out/wayland_common.h b/video/out/wayland_common.h index 576e3c6b51..3ec0116fad 100644 --- a/video/out/wayland_common.h +++ b/video/out/wayland_common.h @@ -96,7 +96,7 @@ struct vo_wayland_state { struct wp_color_management_surface_v1 *color_surface; struct wp_color_management_surface_feedback_v1 *color_surface_feedback; struct wp_image_description_creator_icc_v1 *icc_creator; - struct mp_image_params target_params; + struct mp_image_params current_params; bool image_description_processed; bool supports_parametric; bool supports_display_primaries; @@ -204,7 +204,7 @@ bool vo_wayland_reconfig(struct vo *vo); int vo_wayland_allocate_memfd(struct vo *vo, size_t size); int vo_wayland_control(struct vo *vo, int *events, int request, void *arg); -void vo_wayland_handle_color(struct vo_wayland_state *wl); +void vo_wayland_handle_color(struct vo_wayland_state *wl, struct mp_image_params *params); void vo_wayland_handle_scale(struct vo_wayland_state *wl); void vo_wayland_set_opaque_region(struct vo_wayland_state *wl, bool alpha); void vo_wayland_sync_swap(struct vo_wayland_state *wl);