commit caa0f9f
Michael Forney
·
2013-06-21 07:41:55 +0000 UTC
parent 961bded
region: Use swc_region_new because regions are created dynamically
3 files changed,
+25,
-31
+1,
-6
1@@ -259,15 +259,10 @@ static void create_region(struct wl_client * client,
2 {
3 struct swc_region * region;
4
5- region = malloc(sizeof *region);
6+ region = swc_region_new(client, id);
7
8 if (!region)
9- {
10 wl_resource_post_no_memory(resource);
11- return;
12- }
13-
14- swc_region_initialize(region, client, id);
15 }
16
17 struct wl_compositor_interface compositor_implementation = {
M
region.c
+23,
-21
1@@ -2,18 +2,7 @@
2
3 #include <stdlib.h>
4
5-static void destroy_region_resource(struct wl_resource * resource)
6-{
7- struct swc_region * region;
8-
9- region = resource->data;
10- swc_region_finish(region);
11-
12- free(region);
13-}
14-
15-static void destroy(struct wl_client * client,
16- struct wl_resource * resource)
17+static void destroy(struct wl_client * client, struct wl_resource * resource)
18 {
19 wl_resource_destroy(resource);
20 }
21@@ -43,20 +32,33 @@ static const struct wl_region_interface region_implementation = {
22 .subtract = &subtract
23 };
24
25-bool swc_region_initialize(struct swc_region * region, struct wl_client * client,
26- uint32_t id)
27+static void region_destroy(struct wl_resource * resource)
28 {
29- pixman_region32_init(®ion->region);
30+ struct swc_region * region = wl_resource_get_user_data(resource);
31
32- region->resource = wl_client_add_object(client, &wl_region_interface,
33- ®ion_implementation, id, region);
34- wl_resource_set_destructor(region->resource, &destroy_region_resource);
35+ /* Finish the region. */
36+ pixman_region32_fini(®ion->region);
37
38- return true;
39+ free(region);
40 }
41
42-void swc_region_finish(struct swc_region * region)
43+struct swc_region * swc_region_new(struct wl_client * client, uint32_t id)
44 {
45- pixman_region32_fini(®ion->region);
46+ struct swc_region * region;
47+
48+ region = malloc(sizeof *region);
49+
50+ if (!region)
51+ return NULL;
52+
53+ /* Initialize the region. */
54+ pixman_region32_init(®ion->region);
55+
56+ /* Add the region to the client. */
57+ region->resource = wl_client_add_object(client, &wl_region_interface,
58+ ®ion_implementation, id, region);
59+ wl_resource_set_destructor(region->resource, ®ion_destroy);
60+
61+ return region;
62 }
63
M
region.h
+1,
-4
1@@ -11,10 +11,7 @@ struct swc_region
2 pixman_region32_t region;
3 };
4
5-bool swc_region_initialize(struct swc_region * region, struct wl_client * client,
6- uint32_t id);
7-
8-void swc_region_finish(struct swc_region * region);
9+struct swc_region * swc_region_new(struct wl_client * client, uint32_t id);
10
11 #endif
12