From 1c3c24825f3114a7950a3574a96589bad59122ee Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 6 Dec 2023 16:50:52 +0100 Subject: presentation-time: use wlr_surface_synced --- types/wlr_presentation_time.c | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/types/wlr_presentation_time.c b/types/wlr_presentation_time.c index fcfa0f74..e3b10139 100644 --- a/types/wlr_presentation_time.c +++ b/types/wlr_presentation_time.c @@ -18,8 +18,7 @@ struct wlr_presentation_surface { struct wlr_presentation_surface_state current, pending; struct wlr_addon addon; // wlr_surface.addons - - struct wl_listener surface_commit; + struct wlr_surface_synced synced; }; static void feedback_handle_resource_destroy(struct wl_resource *resource) { @@ -62,11 +61,8 @@ static void presentation_surface_addon_destroy(struct wlr_addon *addon) { wl_container_of(addon, p_surface, addon); wlr_addon_finish(addon); + wlr_surface_synced_finish(&p_surface->synced); - wlr_presentation_feedback_destroy(p_surface->current.feedback); - wlr_presentation_feedback_destroy(p_surface->pending.feedback); - - wl_list_remove(&p_surface->surface_commit.link); free(p_surface); } @@ -75,16 +71,24 @@ static const struct wlr_addon_interface presentation_surface_addon_impl = { .destroy = presentation_surface_addon_destroy, }; -static void presentation_surface_handle_surface_commit( - struct wl_listener *listener, void *data) { - struct wlr_presentation_surface *p_surface = - wl_container_of(listener, p_surface, surface_commit); +static void surface_synced_finish_state(void *_state) { + struct wlr_presentation_surface_state *state = _state; + wlr_presentation_feedback_destroy(state->feedback); +} - wlr_presentation_feedback_destroy(p_surface->current.feedback); - p_surface->current.feedback = p_surface->pending.feedback; - p_surface->pending.feedback = NULL; +static void surface_synced_move_state(void *_dst, void *_src) { + struct wlr_presentation_surface_state *dst = _dst, *src = _src; + surface_synced_finish_state(dst); + dst->feedback = src->feedback; + src->feedback = NULL; } +static const struct wlr_surface_synced_impl surface_synced_impl = { + .state_size = sizeof(struct wlr_presentation_surface_state), + .finish_state = surface_synced_finish_state, + .move_state = surface_synced_move_state, +}; + static const struct wp_presentation_interface presentation_impl; static struct wlr_presentation *presentation_from_resource( @@ -114,10 +118,12 @@ static void presentation_handle_feedback(struct wl_client *client, } wlr_addon_init(&p_surface->addon, &surface->addons, presentation, &presentation_surface_addon_impl); - p_surface->surface_commit.notify = - presentation_surface_handle_surface_commit; - wl_signal_add(&surface->events.commit, - &p_surface->surface_commit); + if (!wlr_surface_synced_init(&p_surface->synced, surface, + &surface_synced_impl, &p_surface->pending, &p_surface->current)) { + free(p_surface); + wl_client_post_no_memory(client); + return; + } } struct wlr_presentation_feedback *feedback = p_surface->pending.feedback; -- cgit v1.2.3