mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2026-04-14 08:22:25 -04:00
Merge branch 'deferred-cursor' into 'master'
Draft: cursor_move defer when enable ADAPTIVE_SYNC See merge request wlroots/wlroots!5193
This commit is contained in:
commit
b3197d487d
3 changed files with 70 additions and 2 deletions
|
|
@ -51,6 +51,10 @@ struct wlr_output_cursor {
|
||||||
uint64_t wait_point;
|
uint64_t wait_point;
|
||||||
struct wl_list link;
|
struct wl_list link;
|
||||||
|
|
||||||
|
struct timespec last_presentation;
|
||||||
|
bool deferred;
|
||||||
|
double deferred_x, deferred_y;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
struct wl_listener renderer_destroy;
|
struct wl_listener renderer_destroy;
|
||||||
struct wlr_color_transform *color_transform;
|
struct wlr_color_transform *color_transform;
|
||||||
|
|
@ -467,6 +471,7 @@ bool wlr_output_cursor_set_buffer(struct wlr_output_cursor *cursor,
|
||||||
struct wlr_buffer *buffer, int32_t hotspot_x, int32_t hotspot_y);
|
struct wlr_buffer *buffer, int32_t hotspot_x, int32_t hotspot_y);
|
||||||
bool wlr_output_cursor_move(struct wlr_output_cursor *cursor,
|
bool wlr_output_cursor_move(struct wlr_output_cursor *cursor,
|
||||||
double x, double y);
|
double x, double y);
|
||||||
|
void wlr_output_cursor_move_all_deferred(struct wlr_output *output, struct timespec *now);
|
||||||
void wlr_output_cursor_destroy(struct wlr_output_cursor *cursor);
|
void wlr_output_cursor_destroy(struct wlr_output_cursor *cursor);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
#include "render/color.h"
|
#include "render/color.h"
|
||||||
#include "types/wlr_buffer.h"
|
#include "types/wlr_buffer.h"
|
||||||
#include "types/wlr_output.h"
|
#include "types/wlr_output.h"
|
||||||
|
#include <util/time.h>
|
||||||
|
|
||||||
static bool output_set_hardware_cursor(struct wlr_output *output,
|
static bool output_set_hardware_cursor(struct wlr_output *output,
|
||||||
struct wlr_buffer *buffer, int hotspot_x, int hotspot_y) {
|
struct wlr_buffer *buffer, int hotspot_x, int hotspot_y) {
|
||||||
|
|
@ -432,8 +433,11 @@ bool output_cursor_set_texture(struct wlr_output_cursor *cursor,
|
||||||
return true;
|
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) {
|
double x, double y, struct timespec *now) {
|
||||||
|
cursor->deferred = false;
|
||||||
|
cursor->last_presentation = *now;
|
||||||
|
|
||||||
// Scale coordinates for the output
|
// Scale coordinates for the output
|
||||||
x *= cursor->output->scale;
|
x *= cursor->output->scale;
|
||||||
y *= cursor->output->scale;
|
y *= cursor->output->scale;
|
||||||
|
|
@ -464,6 +468,58 @@ bool wlr_output_cursor_move(struct wlr_output_cursor *cursor,
|
||||||
return output_move_hardware_cursor(cursor->output, (int)x, (int)y);
|
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
|
||||||
|
x *= cursor->output->scale;
|
||||||
|
y *= cursor->output->scale;
|
||||||
|
|
||||||
|
if (cursor->x == x && cursor->y == y) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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, &now);
|
||||||
|
}
|
||||||
|
|
||||||
|
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, now);
|
||||||
|
else {
|
||||||
|
// Should be on wlr_output?
|
||||||
|
cursor->last_presentation = *now;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct wlr_output_cursor *wlr_output_cursor_create(struct wlr_output *output) {
|
struct wlr_output_cursor *wlr_output_cursor_create(struct wlr_output *output) {
|
||||||
struct wlr_output_cursor *cursor = calloc(1, sizeof(*cursor));
|
struct wlr_output_cursor *cursor = calloc(1, sizeof(*cursor));
|
||||||
if (cursor == NULL) {
|
if (cursor == NULL) {
|
||||||
|
|
|
||||||
|
|
@ -2403,6 +2403,13 @@ bool wlr_scene_output_build_state(struct wlr_scene_output *scene_output,
|
||||||
|
|
||||||
wlr_output_state_set_damage(state, &scene_output->pending_commit_damage);
|
wlr_output_state_set_damage(state, &scene_output->pending_commit_damage);
|
||||||
|
|
||||||
|
// before scanout early return,
|
||||||
|
// update cursor if deferred
|
||||||
|
|
||||||
|
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:
|
// We only want to try direct scanout if:
|
||||||
// - There is only one entry in the render list
|
// - There is only one entry in the render list
|
||||||
// - There are no color transforms that need to be applied
|
// - There are no color transforms that need to be applied
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue