From d9e2c84c49aba48de48a70295c3fb1e0b9a2be97 Mon Sep 17 00:00:00 2001 From: yuiiio Date: Mon, 17 Nov 2025 17:58:06 +0900 Subject: [PATCH 1/3] cursor_move defer when enable ADAPTIVE_SYNC split out from https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/4340 Co-authored-by: Daniel Hill --- include/wlr/types/wlr_output.h | 4 ++++ types/output/cursor.c | 32 +++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index 3cf8778a5..8ad741a3d 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -51,6 +51,9 @@ struct wlr_output_cursor { uint64_t wait_point; struct wl_list link; + bool deferred; + double deferred_x, deferred_y; + struct { struct wl_listener renderer_destroy; } WLR_PRIVATE; @@ -459,6 +462,7 @@ bool wlr_output_cursor_set_buffer(struct wlr_output_cursor *cursor, struct wlr_buffer *buffer, int32_t hotspot_x, int32_t hotspot_y); bool wlr_output_cursor_move(struct wlr_output_cursor *cursor, double x, double y); +void wlr_output_cursor_move_all_deferred(struct wlr_output *output); void wlr_output_cursor_destroy(struct wlr_output_cursor *cursor); /** diff --git a/types/output/cursor.c b/types/output/cursor.c index a24f4abd1..290168557 100644 --- a/types/output/cursor.c +++ b/types/output/cursor.c @@ -440,8 +440,10 @@ bool output_cursor_set_texture(struct wlr_output_cursor *cursor, return true; } -bool wlr_output_cursor_move(struct wlr_output_cursor *cursor, +static bool output_cursor_move(struct wlr_output_cursor *cursor, double x, double y) { + cursor->deferred = false; + // Scale coordinates for the output x *= cursor->output->scale; y *= cursor->output->scale; @@ -472,6 +474,34 @@ bool wlr_output_cursor_move(struct wlr_output_cursor *cursor, return output_move_hardware_cursor(cursor->output, (int)x, (int)y); } +bool wlr_output_cursor_move(struct wlr_output_cursor *cursor, + double x, double y) { + // Scale coordinates for the output + x *= cursor->output->scale; + y *= cursor->output->scale; + + if (cursor->x == x && cursor->y == y) { + return true; + } + + if (cursor->output->adaptive_sync_status == WLR_OUTPUT_ADAPTIVE_SYNC_ENABLED) { + cursor->deferred_x = x; + cursor->deferred_y = y; + cursor->deferred = true; + return true; + } + + return output_cursor_move(cursor, x, y); +} + +void wlr_output_cursor_move_all_deferred(struct wlr_output *output) { + struct wlr_output_cursor *cursor; + wl_list_for_each(cursor, &output->cursors, link) { + if (cursor->deferred) + output_cursor_move(cursor, cursor->deferred_x, cursor->deferred_y); + } +} + struct wlr_output_cursor *wlr_output_cursor_create(struct wlr_output *output) { struct wlr_output_cursor *cursor = calloc(1, sizeof(*cursor)); if (cursor == NULL) { From 3a16ca8ace9171ecdc4f4fcfb47207f2a718ca09 Mon Sep 17 00:00:00 2001 From: yuiiio Date: Fri, 16 Aug 2024 16:20:53 +0900 Subject: [PATCH 2/3] move_all_deferred_cursor trigger in wlr_scene cursor move before scanout --- types/scene/wlr_scene.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/types/scene/wlr_scene.c b/types/scene/wlr_scene.c index 0c854c5b7..5e61d9de6 100644 --- a/types/scene/wlr_scene.c +++ b/types/scene/wlr_scene.c @@ -2319,6 +2319,10 @@ bool wlr_scene_output_build_state(struct wlr_scene_output *scene_output, wlr_output_state_set_damage(state, &scene_output->pending_commit_damage); + // before scanout early return, + // update cursor if deferred + wlr_output_cursor_move_all_deferred(output); + // We only want to try direct scanout if: // - There is only one entry in the render list // - There are no color transforms that need to be applied From fae4d6c935adf53c9786f0b1c55f42d7f977abd7 Mon Sep 17 00:00:00 2001 From: yuiiio Date: Mon, 17 Nov 2025 21:56:24 +0900 Subject: [PATCH 3/3] Ensure the maximum cursor latency(10Hz) --- include/wlr/types/wlr_output.h | 3 ++- types/output/cursor.c | 36 +++++++++++++++++++++++++++++----- types/scene/wlr_scene.c | 5 ++++- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index 8ad741a3d..7c4029058 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -51,6 +51,7 @@ struct wlr_output_cursor { uint64_t wait_point; struct wl_list link; + struct timespec last_presentation; bool deferred; double deferred_x, deferred_y; @@ -462,7 +463,7 @@ bool wlr_output_cursor_set_buffer(struct wlr_output_cursor *cursor, struct wlr_buffer *buffer, int32_t hotspot_x, int32_t hotspot_y); bool wlr_output_cursor_move(struct wlr_output_cursor *cursor, double x, double y); -void wlr_output_cursor_move_all_deferred(struct wlr_output *output); +void wlr_output_cursor_move_all_deferred(struct wlr_output *output, struct timespec *now); void wlr_output_cursor_destroy(struct wlr_output_cursor *cursor); /** diff --git a/types/output/cursor.c b/types/output/cursor.c index 290168557..72b8ecb6b 100644 --- a/types/output/cursor.c +++ b/types/output/cursor.c @@ -13,6 +13,7 @@ #include "render/color.h" #include "types/wlr_buffer.h" #include "types/wlr_output.h" +#include static bool output_set_hardware_cursor(struct wlr_output *output, struct wlr_buffer *buffer, int hotspot_x, int hotspot_y) { @@ -441,8 +442,9 @@ bool output_cursor_set_texture(struct wlr_output_cursor *cursor, } static bool output_cursor_move(struct wlr_output_cursor *cursor, - double x, double y) { + double x, double y, struct timespec *now) { cursor->deferred = false; + cursor->last_presentation = *now; // Scale coordinates for the output x *= cursor->output->scale; @@ -474,6 +476,22 @@ static bool output_cursor_move(struct wlr_output_cursor *cursor, return output_move_hardware_cursor(cursor->output, (int)x, (int)y); } + +static bool output_cursor_move_should_defer(struct wlr_output_cursor *cursor, + struct timespec *now) { + if (cursor->output->adaptive_sync_status != WLR_OUTPUT_ADAPTIVE_SYNC_ENABLED) + return false; + + struct timespec delta; + int32_t vrr_min = NSEC_PER_SEC / 10; // enforce 10fps minimum for now. + timespec_sub(&delta, now, &cursor->last_presentation); + if (delta.tv_sec || delta.tv_nsec >= vrr_min) + return false; + + return true; +} + + bool wlr_output_cursor_move(struct wlr_output_cursor *cursor, double x, double y) { // Scale coordinates for the output @@ -484,21 +502,29 @@ bool wlr_output_cursor_move(struct wlr_output_cursor *cursor, return true; } - if (cursor->output->adaptive_sync_status == WLR_OUTPUT_ADAPTIVE_SYNC_ENABLED) { + + struct timespec now; + clock_gettime(CLOCK_MONOTONIC, &now); + + if (output_cursor_move_should_defer(cursor, &now)) { cursor->deferred_x = x; cursor->deferred_y = y; cursor->deferred = true; return true; } - return output_cursor_move(cursor, x, y); + return output_cursor_move(cursor, x, y, &now); } -void wlr_output_cursor_move_all_deferred(struct wlr_output *output) { +void wlr_output_cursor_move_all_deferred(struct wlr_output *output, struct timespec *now) { struct wlr_output_cursor *cursor; wl_list_for_each(cursor, &output->cursors, link) { if (cursor->deferred) - output_cursor_move(cursor, cursor->deferred_x, cursor->deferred_y); + output_cursor_move(cursor, cursor->deferred_x, cursor->deferred_y, now); + else { + // Should be on wlr_output? + cursor->last_presentation = *now; + }; } } diff --git a/types/scene/wlr_scene.c b/types/scene/wlr_scene.c index 5e61d9de6..36e5d26ec 100644 --- a/types/scene/wlr_scene.c +++ b/types/scene/wlr_scene.c @@ -2321,7 +2321,10 @@ bool wlr_scene_output_build_state(struct wlr_scene_output *scene_output, // before scanout early return, // update cursor if deferred - wlr_output_cursor_move_all_deferred(output); + + struct timespec cursor_now; + clock_gettime(CLOCK_MONOTONIC, &cursor_now); + wlr_output_cursor_move_all_deferred(output, &cursor_now); // We only want to try direct scanout if: // - There is only one entry in the render list