From 13b85bdb65088d520d41727e48a71377b4b97213 Mon Sep 17 00:00:00 2001 From: Giulio Camuffo Date: Tue, 13 Aug 2013 23:10:14 +0200 Subject: [PATCH] compositor: ref-count weston_surface instances This allows a surface to live on after its resource has been destroyed. The ref-count can be increased in a resource destroy signal listener, to keep the surface around for a destroy animation, for example. --- src/compositor.c | 8 ++++++-- src/compositor.h | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/compositor.c b/src/compositor.c index 3213a7b..8da348a 100644 --- a/src/compositor.c +++ b/src/compositor.c @@ -287,6 +287,7 @@ weston_surface_create(struct weston_compositor *compositor) surface->compositor = compositor; surface->alpha = 1.0; + surface->ref_count = 1; if (compositor->renderer->create_surface(surface) < 0) { free(surface); @@ -1003,11 +1004,14 @@ struct weston_frame_callback { WL_EXPORT void weston_surface_destroy(struct weston_surface *surface) { - wl_signal_emit(&surface->destroy_signal, &surface->resource); - struct weston_compositor *compositor = surface->compositor; struct weston_frame_callback *cb, *next; + if (--surface->ref_count > 0) + return; + + wl_signal_emit(&surface->destroy_signal, &surface->resource); + assert(wl_list_empty(&surface->geometry.child_list)); assert(wl_list_empty(&surface->subsurface_list_pending)); assert(wl_list_empty(&surface->subsurface_list)); diff --git a/src/compositor.h b/src/compositor.h index 7600ce3..6db3c61 100644 --- a/src/compositor.h +++ b/src/compositor.h @@ -709,6 +709,7 @@ struct weston_surface { struct wl_list layer_link; float alpha; /* part of geometry, see below */ struct weston_plane *plane; + int32_t ref_count; void *renderer_state; -- 2.7.4