commit d9e6442

Michael Forney  ·  2013-06-21 07:30:48 +0000 UTC
parent b5c8fd0
surface: Add destructor
1 files changed,  +25, -0
+25, -0
 1@@ -21,6 +21,18 @@ static void state_initialize(struct swc_surface_state * state)
 2     wl_list_init(&state->frame_callbacks);
 3 }
 4 
 5+static void state_finish(struct swc_surface_state * state)
 6+{
 7+    struct wl_resource * resource, * tmp;
 8+
 9+    pixman_region32_fini(&state->damage);
10+    pixman_region32_fini(&state->opaque);
11+    pixman_region32_fini(&state->input);
12+
13+    /* Remove all leftover callbacks. */
14+    wl_list_for_each_safe(resource, tmp, &state->frame_callbacks, link)
15+        wl_resource_destroy(resource);
16+}
17 
18 static void destroy(struct wl_client * client, struct wl_resource * resource)
19 {
20@@ -168,6 +180,18 @@ struct wl_surface_interface surface_implementation = {
21     .commit = &commit,
22 };
23 
24+static void surface_destroy(struct wl_resource * resource)
25+{
26+    struct swc_surface * surface = wl_resource_get_user_data(resource);
27+
28+    /* Finish the surface. */
29+    state_finish(&surface->state);
30+    state_finish(&surface->pending.state);
31+
32+    printf("freeing surface %p\n", surface);
33+    free(surface);
34+}
35+
36 /**
37  * Construct a new surface, adding it to the given client as id.
38  *
39@@ -206,6 +230,7 @@ struct swc_surface * swc_surface_new(struct wl_client * client, uint32_t id)
40     surface->resource
41         = wl_client_add_object(client, &wl_surface_interface,
42                                &surface_implementation, id, surface);
43+    wl_resource_set_destructor(surface->resource, &surface_destroy);
44 
45     return surface;
46 }