From e51ce333bc3c087cb333e9581e61bf80353291e9 Mon Sep 17 00:00:00 2001 From: David Turner Date: Thu, 24 Oct 2024 11:09:57 +0100 Subject: [PATCH] scene: Apply output offset for direct scanout When setting the primary buffer location for direct scanout, subtract the offset of that output to put the buffer location in output-relative coordinates. Fixes #3910 --- include/wlr/types/wlr_output.h | 6 ++++-- types/scene/wlr_scene.c | 9 +++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index e14034389..1cc7baecd 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -96,11 +96,13 @@ struct wlr_output_state { struct wlr_buffer *buffer; // Source crop for the buffer. If all zeros then no crop is applied. + // As usual with source crop, this is in buffer coordinates. // Double-buffered by WLR_OUTPUT_STATE_BUFFER along with `buffer`. struct wlr_fbox buffer_src_box; // Destination rect to scale the buffer to (after source crop). If width - // and height are zero then the buffer is displayed at native size. - // Double-buffered by WLR_OUTPUT_STATE_BUFFER along with `buffer`. + // and height are zero then the buffer is displayed at native size. The + // offset is relative to the origin of this output. Double-buffered by + // WLR_OUTPUT_STATE_BUFFER along with `buffer`. struct wlr_box buffer_dst_box; /* Request a tearing page-flip. When enabled, this may cause the output to diff --git a/types/scene/wlr_scene.c b/types/scene/wlr_scene.c index 86547c732..e4d68654a 100644 --- a/types/scene/wlr_scene.c +++ b/types/scene/wlr_scene.c @@ -1844,9 +1844,6 @@ static bool scene_entry_try_direct_scanout(struct render_list_entry *entry, return false; } - struct wlr_box node_box = { .x = entry->x, .y = entry->y }; - scene_node_get_size(node, &node_box.width, &node_box.height); - if (buffer->primary_output == scene_output) { struct wlr_linux_dmabuf_feedback_v1_init_options options = { .main_renderer = scene_output->output->renderer, @@ -1867,7 +1864,11 @@ static bool scene_entry_try_direct_scanout(struct render_list_entry *entry, !wlr_fbox_equal(&buffer->src_box, &default_box)) { pending.buffer_src_box = buffer->src_box; } - pending.buffer_dst_box = node_box; + + // Translate the location from scene coordinates to output coordinates + pending.buffer_dst_box.x = entry->x - scene_output->x; + pending.buffer_dst_box.y = entry->y - scene_output->y; + scene_node_get_size(node, &pending.buffer_dst_box.width, &pending.buffer_dst_box.height); wlr_output_state_set_buffer(&pending, buffer->buffer); if (buffer->wait_timeline != NULL) {