[RFC weston 05/12] region: Change resource to a wl_resource pointer

Jason Ekstrand jason at jlekstrand.net
Fri Jun 14 08:07:56 PDT 2013


Signed-off-by: Jason Ekstrand <jason at jlekstrand.net>
---
 src/compositor.c | 23 ++++++++---------------
 src/compositor.h |  2 +-
 2 files changed, 9 insertions(+), 16 deletions(-)

diff --git a/src/compositor.c b/src/compositor.c
index 14080a1..2f178fd 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -1482,7 +1482,7 @@ surface_set_opaque_region(struct wl_client *client,
 	struct weston_region *region;
 
 	if (region_resource) {
-		region = region_resource->data;
+		region = wl_resource_get_user_data(region_resource);
 		pixman_region32_copy(&surface->pending.opaque,
 				     &region->region);
 	} else {
@@ -1499,7 +1499,7 @@ surface_set_input_region(struct wl_client *client,
 	struct weston_region *region;
 
 	if (region_resource) {
-		region = region_resource->data;
+		region = wl_resource_get_user_data(region_resource);
 		pixman_region32_copy(&surface->pending.input,
 				     &region->region);
 	} else {
@@ -1674,8 +1674,7 @@ compositor_create_surface(struct wl_client *client,
 static void
 destroy_region(struct wl_resource *resource)
 {
-	struct weston_region *region =
-		container_of(resource, struct weston_region, resource);
+	struct weston_region *region = wl_resource_get_user_data(resource);
 
 	pixman_region32_fini(&region->region);
 	free(region);
@@ -1691,7 +1690,7 @@ static void
 region_add(struct wl_client *client, struct wl_resource *resource,
 	   int32_t x, int32_t y, int32_t width, int32_t height)
 {
-	struct weston_region *region = resource->data;
+	struct weston_region *region = wl_resource_get_user_data(resource);
 
 	pixman_region32_union_rect(&region->region, &region->region,
 				   x, y, width, height);
@@ -1701,7 +1700,7 @@ static void
 region_subtract(struct wl_client *client, struct wl_resource *resource,
 		int32_t x, int32_t y, int32_t width, int32_t height)
 {
-	struct weston_region *region = resource->data;
+	struct weston_region *region = wl_resource_get_user_data(resource);
 	pixman_region32_t rect;
 
 	pixman_region32_init_rect(&rect, x, y, width, height);
@@ -1727,17 +1726,11 @@ compositor_create_region(struct wl_client *client,
 		return;
 	}
 
-	region->resource.destroy = destroy_region;
-
-	region->resource.object.id = id;
-	region->resource.object.interface = &wl_region_interface;
-	region->resource.object.implementation =
-		(void (**)(void)) &region_interface;
-	region->resource.data = region;
-
 	pixman_region32_init(&region->region);
 
-	wl_client_add_resource(client, &region->resource);
+	region->resource = wl_client_add_object(client, &wl_region_interface,
+						&region_interface, id, region);
+	wl_resource_set_destructor(region->resource, destroy_region);
 }
 
 static const struct wl_compositor_interface compositor_interface = {
diff --git a/src/compositor.h b/src/compositor.h
index 36875a6..8ca4672 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -567,7 +567,7 @@ struct weston_buffer_reference {
 };
 
 struct weston_region {
-	struct wl_resource resource;
+	struct wl_resource *resource;
 	pixman_region32_t region;
 };
 
-- 
1.8.1.4



More information about the wayland-devel mailing list