[RFC weston 02/12] Use wl_resource_get_user_data for weston_surface resources

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


Signed-off-by: Jason Ekstrand <jason at jlekstrand.net>
---
 src/compositor.c   | 28 ++++++++++++++++------------
 src/data-device.c  |  6 +++---
 src/input.c        |  2 +-
 src/shell.c        | 25 ++++++++++++++++---------
 src/tablet-shell.c | 10 +++++-----
 src/text-backend.c |  2 +-
 6 files changed, 42 insertions(+), 31 deletions(-)

diff --git a/src/compositor.c b/src/compositor.c
index 42011f5..14080a1 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -1408,7 +1408,7 @@ surface_attach(struct wl_client *client,
 	       struct wl_resource *resource,
 	       struct wl_resource *buffer_resource, int32_t sx, int32_t sy)
 {
-	struct weston_surface *surface = resource->data;
+	struct weston_surface *surface = wl_resource_get_user_data(resource);
 	struct wl_buffer *buffer = NULL;
 
 	if (buffer_resource)
@@ -1434,7 +1434,7 @@ surface_damage(struct wl_client *client,
 	       struct wl_resource *resource,
 	       int32_t x, int32_t y, int32_t width, int32_t height)
 {
-	struct weston_surface *surface = resource->data;
+	struct weston_surface *surface = wl_resource_get_user_data(resource);
 
 	pixman_region32_union_rect(&surface->pending.damage,
 				   &surface->pending.damage,
@@ -1455,7 +1455,7 @@ surface_frame(struct wl_client *client,
 	      struct wl_resource *resource, uint32_t callback)
 {
 	struct weston_frame_callback *cb;
-	struct weston_surface *surface = resource->data;
+	struct weston_surface *surface = wl_resource_get_user_data(resource);
 
 	cb = malloc(sizeof *cb);
 	if (cb == NULL) {
@@ -1478,7 +1478,7 @@ surface_set_opaque_region(struct wl_client *client,
 			  struct wl_resource *resource,
 			  struct wl_resource *region_resource)
 {
-	struct weston_surface *surface = resource->data;
+	struct weston_surface *surface = wl_resource_get_user_data(resource);
 	struct weston_region *region;
 
 	if (region_resource) {
@@ -1495,7 +1495,7 @@ surface_set_input_region(struct wl_client *client,
 			 struct wl_resource *resource,
 			 struct wl_resource *region_resource)
 {
-	struct weston_surface *surface = resource->data;
+	struct weston_surface *surface = wl_resource_get_user_data(resource);
 	struct weston_region *region;
 
 	if (region_resource) {
@@ -1605,7 +1605,7 @@ weston_subsurface_parent_commit(struct weston_subsurface *sub,
 static void
 surface_commit(struct wl_client *client, struct wl_resource *resource)
 {
-	struct weston_surface *surface = resource->data;
+	struct weston_surface *surface = wl_resource_get_user_data(resource);
 	struct weston_subsurface *sub = weston_surface_to_subsurface(surface);
 
 	if (sub) {
@@ -1625,7 +1625,7 @@ static void
 surface_set_buffer_transform(struct wl_client *client,
 			     struct wl_resource *resource, int transform)
 {
-	struct weston_surface *surface = resource->data;
+	struct weston_surface *surface = wl_resource_get_user_data(resource);
 
 	surface->pending.buffer_transform = transform;
 }
@@ -1635,7 +1635,7 @@ surface_set_buffer_scale(struct wl_client *client,
 			 struct wl_resource *resource,
 			 int32_t scale)
 {
-	struct weston_surface *surface = resource->data;
+	struct weston_surface *surface = wl_resource_get_user_data(resource);
 
 	surface->pending.buffer_scale = scale;
 }
@@ -2056,7 +2056,8 @@ subsurface_place_above(struct wl_client *client,
 		       struct wl_resource *sibling_resource)
 {
 	struct weston_subsurface *sub = resource->data;
-	struct weston_surface *surface = sibling_resource->data;
+	struct weston_surface *surface =
+		wl_resource_get_user_data(sibling_resource);
 	struct weston_subsurface *sibling;
 
 	if (!sub)
@@ -2077,7 +2078,8 @@ subsurface_place_below(struct wl_client *client,
 		       struct wl_resource *sibling_resource)
 {
 	struct weston_subsurface *sub = resource->data;
-	struct weston_surface *surface = sibling_resource->data;
+	struct weston_surface *surface =
+		wl_resource_get_user_data(sibling_resource);
 	struct weston_subsurface *sibling;
 
 	if (!sub)
@@ -2319,8 +2321,10 @@ subcompositor_get_subsurface(struct wl_client *client,
 			     struct wl_resource *surface_resource,
 			     struct wl_resource *parent_resource)
 {
-	struct weston_surface *surface = surface_resource->data;
-	struct weston_surface *parent = parent_resource->data;
+	struct weston_surface *surface =
+		wl_resource_get_user_data(surface_resource);
+	struct weston_surface *parent =
+		wl_resource_get_user_data(parent_resource);
 	struct weston_subsurface *sub;
 	static const char where[] = "get_subsurface: wl_subsurface@";
 
diff --git a/src/data-device.c b/src/data-device.c
index 06d24f1..1735620 100644
--- a/src/data-device.c
+++ b/src/data-device.c
@@ -372,13 +372,13 @@ data_device_start_drag(struct wl_client *client, struct wl_resource *resource,
 
 	if (seat->pointer->button_count == 0 ||
 	    seat->pointer->grab_serial != serial ||
-	    seat->pointer->focus != origin_resource->data)
+	    seat->pointer->focus != wl_resource_get_user_data(origin_resource))
 		return;
 
 	/* FIXME: Check that the data source type array isn't empty. */
 
 	if (icon_resource)
-		icon = icon_resource->data;
+		icon = wl_resource_get_user_data(icon_resource);
 	if (icon && icon->configure) {
 		wl_resource_post_error(icon_resource,
 				       WL_DISPLAY_ERROR_INVALID_OBJECT,
@@ -493,7 +493,7 @@ data_device_set_selection(struct wl_client *client,
 		return;
 
 	/* FIXME: Store serial and check against incoming serial here. */
-	weston_seat_set_selection(resource->data, source_resource->data,
+	weston_seat_set_selection(resource->data, wl_resource_get_user_data(source_resource),
 				  serial);
 }
 
diff --git a/src/input.c b/src/input.c
index 5463d78..9b6d475 100644
--- a/src/input.c
+++ b/src/input.c
@@ -1108,7 +1108,7 @@ pointer_set_cursor(struct wl_client *client, struct wl_resource *resource,
 	struct weston_surface *surface = NULL;
 
 	if (surface_resource)
-		surface = surface_resource->data;
+		surface = wl_resource_get_user_data(surface_resource);
 
 	if (pointer->focus == NULL)
 		return;
diff --git a/src/shell.c b/src/shell.c
index 57dbb0a..90a9659 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -984,7 +984,7 @@ workspace_manager_move_surface(struct wl_client *client,
 {
 	struct desktop_shell *shell = resource->data;
 	struct weston_surface *surface =
-		(struct weston_surface *) surface_resource;
+		wl_resource_get_user_data(surface_resource);
 	struct weston_surface *main_surface;
 
 	main_surface = weston_surface_get_main_surface(surface);
@@ -1661,7 +1661,8 @@ shell_surface_set_transient(struct wl_client *client,
 			    int x, int y, uint32_t flags)
 {
 	struct shell_surface *shsurf = resource->data;
-	struct weston_surface *parent = parent_resource->data;
+	struct weston_surface *parent =
+		wl_resource_get_user_data(parent_resource);
 
 	set_transient(shsurf, parent, x, y, flags);
 }
@@ -2290,7 +2291,8 @@ shell_get_shell_surface(struct wl_client *client,
 			uint32_t id,
 			struct wl_resource *surface_resource)
 {
-	struct weston_surface *surface = surface_resource->data;
+	struct weston_surface *surface =
+		wl_resource_get_user_data(surface_resource);
 	struct desktop_shell *shell = resource->data;
 	struct shell_surface *shsurf;
 
@@ -2417,7 +2419,8 @@ desktop_shell_set_background(struct wl_client *client,
 			     struct wl_resource *surface_resource)
 {
 	struct desktop_shell *shell = resource->data;
-	struct weston_surface *surface = surface_resource->data;
+	struct weston_surface *surface =
+		wl_resource_get_user_data(surface_resource);
 
 	if (surface->configure) {
 		wl_resource_post_error(surface_resource,
@@ -2450,7 +2453,8 @@ desktop_shell_set_panel(struct wl_client *client,
 			struct wl_resource *surface_resource)
 {
 	struct desktop_shell *shell = resource->data;
-	struct weston_surface *surface = surface_resource->data;
+	struct weston_surface *surface =
+		wl_resource_get_user_data(surface_resource);
 
 	if (surface->configure) {
 		wl_resource_post_error(surface_resource,
@@ -2504,7 +2508,8 @@ desktop_shell_set_lock_surface(struct wl_client *client,
 			       struct wl_resource *surface_resource)
 {
 	struct desktop_shell *shell = resource->data;
-	struct weston_surface *surface = surface_resource->data;
+	struct weston_surface *surface =
+		wl_resource_get_user_data(surface_resource);
 
 	shell->prepare_event_sent = false;
 
@@ -2568,7 +2573,7 @@ desktop_shell_set_grab_surface(struct wl_client *client,
 {
 	struct desktop_shell *shell = resource->data;
 
-	shell->grab_surface = surface_resource->data;
+	shell->grab_surface = wl_resource_get_user_data(surface_resource);
 }
 
 static void
@@ -3646,7 +3651,8 @@ screensaver_set_surface(struct wl_client *client,
 			struct wl_resource *output_resource)
 {
 	struct desktop_shell *shell = resource->data;
-	struct weston_surface *surface = surface_resource->data;
+	struct weston_surface *surface =
+		wl_resource_get_user_data(surface_resource);
 	struct weston_output *output = output_resource->data;
 
 	surface->configure = screensaver_configure;
@@ -3844,7 +3850,8 @@ input_panel_get_input_panel_surface(struct wl_client *client,
 				    uint32_t id,
 				    struct wl_resource *surface_resource)
 {
-	struct weston_surface *surface = surface_resource->data;
+	struct weston_surface *surface =
+		wl_resource_get_user_data(surface_resource);
 	struct desktop_shell *shell = resource->data;
 	struct input_panel_surface *ipsurf;
 
diff --git a/src/tablet-shell.c b/src/tablet-shell.c
index 3ef756c..c9f6699 100644
--- a/src/tablet-shell.c
+++ b/src/tablet-shell.c
@@ -180,7 +180,7 @@ tablet_shell_set_lockscreen(struct wl_client *client,
 			    struct wl_resource *surface_resource)
 {
 	struct tablet_shell *shell = resource->data;
-	struct weston_surface *es = surface_resource->data;
+	struct weston_surface *es = wl_resource_get_user_data(surface_resource);
 
 	weston_surface_set_position(es, 0, 0);
 	shell->lockscreen_surface = es;
@@ -207,7 +207,7 @@ tablet_shell_set_switcher(struct wl_client *client,
 			  struct wl_resource *surface_resource)
 {
 	struct tablet_shell *shell = resource->data;
-	struct weston_surface *es = surface_resource->data;
+	struct weston_surface *es = wl_resource_get_user_data(surface_resource);
 
 	/* FIXME: Switcher should be centered and the compositor
 	 * should do the tinting of the background.  With the cache
@@ -227,7 +227,7 @@ tablet_shell_set_homescreen(struct wl_client *client,
 {
 	struct tablet_shell *shell = resource->data;
 
-	shell->home_surface = surface_resource->data;
+	shell->home_surface = wl_resource_get_user_data(surface_resource);
 	shell->home_surface->configure = tablet_shell_surface_configure;
 
 	weston_surface_set_position(shell->home_surface, 0, 0);
@@ -280,7 +280,7 @@ tablet_shell_show_grid(struct wl_client *client,
 		       struct wl_resource *surface_resource)
 {
 	struct tablet_shell *shell = resource->data;
-	struct weston_surface *es = surface_resource->data;
+	struct weston_surface *es = wl_resource_get_user_data(surface_resource);
 
 	tablet_shell_switch_to(shell, es);
 }
@@ -291,7 +291,7 @@ tablet_shell_show_panels(struct wl_client *client,
 			 struct wl_resource *surface_resource)
 {
 	struct tablet_shell *shell = resource->data;
-	struct weston_surface *es = surface_resource->data;
+	struct weston_surface *es = wl_resource_get_user_data(surface_resource);
 
 	tablet_shell_switch_to(shell, es);
 }
diff --git a/src/text-backend.c b/src/text-backend.c
index f940bbf..27afdff 100644
--- a/src/text-backend.c
+++ b/src/text-backend.c
@@ -188,7 +188,7 @@ text_input_activate(struct wl_client *client,
 	wl_list_insert(&text_input->input_methods, &input_method->link);
 	input_method_init_seat(weston_seat);
 
-	text_input->surface = surface->data;
+	text_input->surface = wl_resource_get_user_data(surface);
 
 	input_method_context_create(text_input, input_method);
 
-- 
1.8.1.4



More information about the wayland-devel mailing list