diff --git a/include/wlr/types/wlr_output_damage.h b/include/wlr/types/wlr_output_damage.h index 39d28263..e4b1f862 100644 --- a/include/wlr/types/wlr_output_damage.h +++ b/include/wlr/types/wlr_output_damage.h @@ -42,6 +42,8 @@ struct wlr_output_damage { pixman_region32_t previous[WLR_OUTPUT_DAMAGE_PREVIOUS_LEN]; size_t previous_idx; + enum wlr_output_state_buffer_type pending_buffer_type; + struct { struct wl_signal frame; struct wl_signal destroy; @@ -52,6 +54,7 @@ struct wlr_output_damage { struct wl_listener output_needs_frame; struct wl_listener output_damage; struct wl_listener output_frame; + struct wl_listener output_precommit; struct wl_listener output_commit; }; diff --git a/types/wlr_output_damage.c b/types/wlr_output_damage.c index 2bfc193e..76dac57f 100644 --- a/types/wlr_output_damage.c +++ b/types/wlr_output_damage.c @@ -44,6 +44,18 @@ static void output_handle_frame(struct wl_listener *listener, void *data) { wlr_signal_emit_safe(&output_damage->events.frame, output_damage); } +static void output_handle_precommit(struct wl_listener *listener, void *data) { + struct wlr_output_damage *output_damage = + wl_container_of(listener, output_damage, output_precommit); + struct wlr_output *output = output_damage->output; + + if (output->pending.committed & WLR_OUTPUT_STATE_BUFFER) { + // TODO: find a better way to access this info without a precommit + // handler + output_damage->pending_buffer_type = output->pending.buffer_type; + } +} + static void output_handle_commit(struct wl_listener *listener, void *data) { struct wlr_output_damage *output_damage = wl_container_of(listener, output_damage, output_commit); @@ -58,7 +70,7 @@ static void output_handle_commit(struct wl_listener *listener, void *data) { } pixman_region32_t *prev; - switch (output_damage->output->pending.buffer_type) { + switch (output_damage->pending_buffer_type) { case WLR_OUTPUT_STATE_BUFFER_RENDER: // render-buffers have been swapped, rotate the damage @@ -106,6 +118,8 @@ struct wlr_output_damage *wlr_output_damage_create(struct wlr_output *output) { output_damage->output_damage.notify = output_handle_damage; wl_signal_add(&output->events.frame, &output_damage->output_frame); output_damage->output_frame.notify = output_handle_frame; + wl_signal_add(&output->events.precommit, &output_damage->output_precommit); + output_damage->output_precommit.notify = output_handle_precommit; wl_signal_add(&output->events.commit, &output_damage->output_commit); output_damage->output_commit.notify = output_handle_commit; @@ -122,6 +136,7 @@ void wlr_output_damage_destroy(struct wlr_output_damage *output_damage) { wl_list_remove(&output_damage->output_needs_frame.link); wl_list_remove(&output_damage->output_damage.link); wl_list_remove(&output_damage->output_frame.link); + wl_list_remove(&output_damage->output_precommit.link); wl_list_remove(&output_damage->output_commit.link); pixman_region32_fini(&output_damage->current); for (size_t i = 0; i < WLR_OUTPUT_DAMAGE_PREVIOUS_LEN; ++i) {