fix: don't mess with output timings when tearing is enabled

This commit is contained in:
Ricardo Steijn 2024-08-04 19:16:26 +02:00
parent c810995119
commit 77b965dc33
2 changed files with 21 additions and 23 deletions

View file

@ -73,7 +73,7 @@ struct sway_output {
int max_render_time; // In milliseconds int max_render_time; // In milliseconds
struct wl_event_source *repaint_timer; struct wl_event_source *repaint_timer;
bool gamma_lut_changed; bool gamma_lut_changed;
bool allow_tearing, enable_tearing; bool allow_tearing;
}; };
struct sway_output_non_desktop { struct sway_output_non_desktop {

View file

@ -232,6 +232,23 @@ static void output_configure_scene(struct sway_output *output,
} }
} }
static bool output_can_tear(struct sway_output *output) {
struct sway_workspace *workspace = output->current.active_workspace;
if (!workspace) {
return false;
}
struct sway_container *fullscreen_con = root->fullscreen_global;
if (!fullscreen_con) {
fullscreen_con = workspace->current.fullscreen;
}
if (fullscreen_con && fullscreen_con->view) {
return (output->allow_tearing && view_can_tear(fullscreen_con->view));
}
return false;
}
static int output_repaint_timer_handler(void *data) { static int output_repaint_timer_handler(void *data) {
struct sway_output *output = data; struct sway_output *output = data;
@ -276,7 +293,7 @@ static int output_repaint_timer_handler(void *data) {
} }
} }
if (output->enable_tearing) { if (output_can_tear(output)) {
pending.tearing_page_flip = true; pending.tearing_page_flip = true;
if (!wlr_output_test_state(output->wlr_output, &pending)) { if (!wlr_output_test_state(output->wlr_output, &pending)) {
@ -294,23 +311,6 @@ static int output_repaint_timer_handler(void *data) {
return 0; return 0;
} }
static bool output_can_tear(struct sway_output *output) {
struct sway_workspace *workspace = output->current.active_workspace;
if (!workspace) {
return false;
}
struct sway_container *fullscreen_con = root->fullscreen_global;
if (!fullscreen_con) {
fullscreen_con = workspace->current.fullscreen;
}
if (fullscreen_con && fullscreen_con->view) {
return (output->allow_tearing && view_can_tear(fullscreen_con->view));
}
return false;
}
static void handle_frame(struct wl_listener *listener, void *user_data) { static void handle_frame(struct wl_listener *listener, void *user_data) {
struct sway_output *output = struct sway_output *output =
wl_container_of(listener, output, frame); wl_container_of(listener, output, frame);
@ -358,11 +358,9 @@ static void handle_frame(struct wl_listener *listener, void *user_data) {
int delay = msec_until_refresh - output->max_render_time; int delay = msec_until_refresh - output->max_render_time;
output->enable_tearing = output_can_tear(output);
// If the delay is less than 1 millisecond (which is the least we can wait) // If the delay is less than 1 millisecond (which is the least we can wait)
// or if the output is allowed to tear, then just render right away. // then just render right away.
if (delay < 1 || output->enable_tearing) { if (delay < 1) {
output_repaint_timer_handler(output); output_repaint_timer_handler(output);
} else { } else {
output->wlr_output->frame_pending = true; output->wlr_output->frame_pending = true;