From 501ac5398d6f9a85dfdeeb9bf60a342bcff35adc Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Fri, 27 May 2022 11:35:33 +0200 Subject: [PATCH] output: add output_state_{init,finish} --- types/output/output.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/types/output/output.c b/types/output/output.c index a587edc1..cdfb48ff 100644 --- a/types/output/output.c +++ b/types/output/output.c @@ -382,6 +382,21 @@ static void handle_display_destroy(struct wl_listener *listener, void *data) { wlr_output_destroy_global(output); } +static void output_state_init(struct wlr_output_state *state) { + memset(state, 0, sizeof(*state)); + pixman_region32_init(&state->damage); +} + +static void output_state_finish(struct wlr_output_state *state) { + wlr_buffer_unlock(state->buffer); + // struct wlr_buffer is ref'counted, so the pointer may remain valid after + // wlr_buffer_unlock(). Reset the field to NULL to ensure nobody mistakenly + // reads it after output_state_finish(). + state->buffer = NULL; + pixman_region32_fini(&state->damage); + free(state->gamma_lut); +} + void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend, const struct wlr_output_impl *impl, struct wl_display *display) { assert(impl->commit); @@ -411,7 +426,7 @@ void wlr_output_init(struct wlr_output *output, struct wlr_backend *backend, wl_signal_init(&output->events.mode); wl_signal_init(&output->events.description); wl_signal_init(&output->events.destroy); - pixman_region32_init(&output->pending.damage); + output_state_init(&output->pending); const char *no_hardware_cursors = getenv("WLR_NO_HARDWARE_CURSORS"); if (no_hardware_cursors != NULL && strcmp(no_hardware_cursors, "1") == 0) { @@ -461,7 +476,7 @@ void wlr_output_destroy(struct wlr_output *output) { free(output->name); free(output->description); - pixman_region32_fini(&output->pending.damage); + output_state_finish(&output->pending); if (output->impl && output->impl->destroy) { output->impl->destroy(output);