commit caa0f9f3689e3bd67410deef82eb0bb29e55bbf1
parent 961bdedaeaca25ccef8832e973a387ae9e425706
Author: Michael Forney <mforney@mforney.org>
Date: Fri, 21 Jun 2013 00:41:55 -0700
region: Use swc_region_new because regions are created dynamically
Diffstat:
3 files changed, 25 insertions(+), 31 deletions(-)
diff --git a/compositor.c b/compositor.c
@@ -259,15 +259,10 @@ static void create_region(struct wl_client * client,
{
struct swc_region * region;
- region = malloc(sizeof *region);
+ region = swc_region_new(client, id);
if (!region)
- {
wl_resource_post_no_memory(resource);
- return;
- }
-
- swc_region_initialize(region, client, id);
}
struct wl_compositor_interface compositor_implementation = {
diff --git a/region.c b/region.c
@@ -2,18 +2,7 @@
#include <stdlib.h>
-static void destroy_region_resource(struct wl_resource * resource)
-{
- struct swc_region * region;
-
- region = resource->data;
- swc_region_finish(region);
-
- free(region);
-}
-
-static void destroy(struct wl_client * client,
- struct wl_resource * resource)
+static void destroy(struct wl_client * client, struct wl_resource * resource)
{
wl_resource_destroy(resource);
}
@@ -43,20 +32,33 @@ static const struct wl_region_interface region_implementation = {
.subtract = &subtract
};
-bool swc_region_initialize(struct swc_region * region, struct wl_client * client,
- uint32_t id)
+static void region_destroy(struct wl_resource * resource)
{
- pixman_region32_init(®ion->region);
+ struct swc_region * region = wl_resource_get_user_data(resource);
- region->resource = wl_client_add_object(client, &wl_region_interface,
- ®ion_implementation, id, region);
- wl_resource_set_destructor(region->resource, &destroy_region_resource);
+ /* Finish the region. */
+ pixman_region32_fini(®ion->region);
- return true;
+ free(region);
}
-void swc_region_finish(struct swc_region * region)
+struct swc_region * swc_region_new(struct wl_client * client, uint32_t id)
{
- pixman_region32_fini(®ion->region);
+ struct swc_region * region;
+
+ region = malloc(sizeof *region);
+
+ if (!region)
+ return NULL;
+
+ /* Initialize the region. */
+ pixman_region32_init(®ion->region);
+
+ /* Add the region to the client. */
+ region->resource = wl_client_add_object(client, &wl_region_interface,
+ ®ion_implementation, id, region);
+ wl_resource_set_destructor(region->resource, ®ion_destroy);
+
+ return region;
}
diff --git a/region.h b/region.h
@@ -11,10 +11,7 @@ struct swc_region
pixman_region32_t region;
};
-bool swc_region_initialize(struct swc_region * region, struct wl_client * client,
- uint32_t id);
-
-void swc_region_finish(struct swc_region * region);
+struct swc_region * swc_region_new(struct wl_client * client, uint32_t id);
#endif