[PATCH weston] compositor: ref-count weston_surface instances

Giulio Camuffo giuliocamuffo at gmail.com
Tue Aug 13 14:10:14 PDT 2013


this allows a surface to live on after its resource has been
destroyed if the ref-count was increased by some code that needs
to use the surface after the end of its life, like a destroy
animation.
---
 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;
 
-- 
1.8.3.4



More information about the wayland-devel mailing list