Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions video/out/wayland_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -2129,6 +2129,7 @@ static void image_description_failed(void *data, struct wp_image_description_v1
uint32_t cause, const char *msg)
{
struct vo_wayland_state *wl = data;
wl->image_desc_done = true;
MP_VERBOSE(wl, "Image description failed: %d, %s\n", cause, msg);
wp_color_management_surface_v1_unset_image_description(wl->color_surface);
wp_image_description_v1_destroy(image_description);
Expand All @@ -2138,6 +2139,7 @@ static void image_description_ready(void *data, struct wp_image_description_v1 *
uint32_t identity)
{
struct vo_wayland_state *wl = data;
wl->image_desc_done = true;
wp_color_management_surface_v1_set_image_description(wl->color_surface, image_description, 0);
MP_TRACE(wl, "Image description set on color surface.\n");
wp_image_description_v1_destroy(image_description);
Expand Down Expand Up @@ -3540,8 +3542,20 @@ static void set_color_management(struct vo_wayland_state *wl)
wp_image_description_creator_params_v1_set_max_cll(image_creator_params, lrintf(hdr.max_cll));
wp_image_description_creator_params_v1_set_max_fall(image_creator_params, lrintf(hdr.max_fall));
}

struct wp_image_description_v1 *image_description = wp_image_description_creator_params_v1_create(image_creator_params);
struct wl_event_queue *cm_queue = wl_display_create_queue(wl->display);
wl_proxy_set_queue((struct wl_proxy *)image_description, cm_queue);
wl->image_desc_done = false;
wp_image_description_v1_add_listener(image_description, &image_description_listener, wl);

/* Block here to ensure the compositor is ready to receive the
Copy link
Member

@kasper93 kasper93 Sep 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we instead of blocking thread, react in the callback and do rest of the work when compositor is ready for it? Blocking and callbacks generally doesn't go together.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's exactly what happens before this MR. If we don't block here then we need some other syncing primitive in vo.c's render_frame to wait after draw_frame before calling flip_page.

As I've already said before, this only happens on the very first frame mpv displays for each file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm too be honest, I don't really like this hard block here. A roundtrip is fine but since evidentially that is not sufficient, putting this while loop here doesn't feel very good. e.g. what if the compositor never gives us this event. Sure it would be bad behavior but that means we would spin here forever.

Don't have any concrete suggestions at this time though. Maybe something like how we wait for frame callback needs to be done here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if the compositor never gives us this event

It is guaranteed that the compositor will give us this event eventually by the protocol. Any compositor where this takes long enough for it to get noticeable for the end user is severely buggy and not our responsibility.

Of course compositor can be buggy and violate the protocol and actually never give us this event, then there will be no mpv window when opening a video with dmabuf-wayland and it will be very obvious what the cause is from WAYLAND_DEBUG logs.

Keep in mind that if the compositor never gives us this event on master, what will happen is that dmabuf-wayland will continue to display video but never set any metadata for it and the user would have no clue why.

I'm personally fine with a hard block here, since it only happens at the start of playback one time. But we can return to the roundtrip version if you prefer since in practice most compositors won't wait more than a roundtrip, I verified that a roundtrip will be sufficient for Kwin/wlroots compositors.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you do a roundtrip and the event has not yet arrived, the process will be aborted when the event arrives after you've destroyed the queue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could keep the queue around then

* image_description before we do anything else. */
while (wl->image_desc_done == false)
if (wl_display_dispatch_queue(wl->display, cm_queue) < 0)
break;

wl_event_queue_destroy(cm_queue);
#endif
}

Expand Down
1 change: 1 addition & 0 deletions video/out/wayland_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ struct vo_wayland_state {
void *icc_file;
uint32_t icc_size;
struct pl_color_space preferred_csp;
bool image_desc_done;

/* color-representation */
struct wp_color_representation_manager_v1 *color_representation_manager;
Expand Down
Loading