aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2022-05-27 11:35:33 +0200
committerSimon Ser <contact@emersion.fr>2022-05-30 11:40:34 +0200
commit501ac5398d6f9a85dfdeeb9bf60a342bcff35adc (patch)
tree76ce02ac07cf349d47632e468277b478a04c477b
parentb21c26a1c9b5f035eb69ede201980c82c256dabc (diff)
output: add output_state_{init,finish}
-rw-r--r--types/output/output.c19
1 files 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);