[PATCH weston 15/15] libweston: introduce weston_output_from_resource()

Pekka Paalanen ppaalanen at gmail.com
Tue Apr 4 10:58:18 UTC 2017


From: Pekka Paalanen <pekka.paalanen at collabora.co.uk>

This is a simple wrapper for casting the user data of a wl_resource into
a struct weston_output pointer. Using the wrapper clearly marks all the
places where a wl_output protocol object is used.

Replace ALL wl_output related calls to wl_resource_get_user_data() with
a call to weston_output_from_resource().

This patch does not add any type checks or asserts to ensure the user
data actually is a weston_output. That is left for another patch, as
well as introducing similar wrappers for other casts.

Signed-off-by: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
---
 compositor/weston-screenshooter.c   |  2 +-
 desktop-shell/input-panel.c         |  2 +-
 desktop-shell/shell.c               |  4 ++--
 fullscreen-shell/fullscreen-shell.c |  4 ++--
 ivi-shell/input-panel-ivi.c         |  2 +-
 libweston-desktop/wl-shell.c        |  2 +-
 libweston-desktop/xdg-shell-v5.c    |  2 +-
 libweston-desktop/xdg-shell-v6.c    |  2 +-
 libweston/compositor.c              | 13 +++++++++++++
 libweston/compositor.h              |  3 +++
 tests/weston-test.c                 |  2 +-
 11 files changed, 27 insertions(+), 11 deletions(-)

diff --git a/compositor/weston-screenshooter.c b/compositor/weston-screenshooter.c
index 9999909..f874c3e 100644
--- a/compositor/weston-screenshooter.c
+++ b/compositor/weston-screenshooter.c
@@ -66,7 +66,7 @@ screenshooter_shoot(struct wl_client *client,
 		    struct wl_resource *buffer_resource)
 {
 	struct weston_output *output =
-		wl_resource_get_user_data(output_resource);
+		weston_output_from_resource(output_resource);
 	struct weston_buffer *buffer =
 		weston_buffer_from_resource(buffer_resource);
 
diff --git a/desktop-shell/input-panel.c b/desktop-shell/input-panel.c
index 40a4092..e6b1541 100644
--- a/desktop-shell/input-panel.c
+++ b/desktop-shell/input-panel.c
@@ -274,7 +274,7 @@ input_panel_surface_set_toplevel(struct wl_client *client,
 	wl_list_insert(&shell->input_panel.surfaces,
 		       &input_panel_surface->link);
 
-	input_panel_surface->output = wl_resource_get_user_data(output_resource);
+	input_panel_surface->output = weston_output_from_resource(output_resource);
 	input_panel_surface->panel = 0;
 }
 
diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c
index c905879..8a4f2e1 100644
--- a/desktop-shell/shell.c
+++ b/desktop-shell/shell.c
@@ -2941,7 +2941,7 @@ desktop_shell_set_background(struct wl_client *client,
 	surface->committed = background_committed;
 	surface->committed_private = shell;
 	weston_surface_set_label_func(surface, background_get_label);
-	surface->output = wl_resource_get_user_data(output_resource);
+	surface->output = weston_output_from_resource(output_resource);
 	view->output = surface->output;
 	weston_desktop_shell_send_configure(resource, 0,
 					    surface_resource,
@@ -3026,7 +3026,7 @@ desktop_shell_set_panel(struct wl_client *client,
 	surface->committed = panel_committed;
 	surface->committed_private = shell;
 	weston_surface_set_label_func(surface, panel_get_label);
-	surface->output = wl_resource_get_user_data(output_resource);
+	surface->output = weston_output_from_resource(output_resource);
 	view->output = surface->output;
 	weston_desktop_shell_send_configure(resource, 0,
 					    surface_resource,
diff --git a/fullscreen-shell/fullscreen-shell.c b/fullscreen-shell/fullscreen-shell.c
index 7368cb4..6f4565a 100644
--- a/fullscreen-shell/fullscreen-shell.c
+++ b/fullscreen-shell/fullscreen-shell.c
@@ -769,7 +769,7 @@ fullscreen_shell_present_surface(struct wl_client *client,
 	}
 
 	if (output_res) {
-		output = wl_resource_get_user_data(output_res);
+		output = weston_output_from_resource(output_res);
 		fsout = fs_output_for_output(output);
 		fs_output_set_surface(fsout, surface, method, 0, 0);
 	} else {
@@ -813,7 +813,7 @@ fullscreen_shell_present_surface_for_mode(struct wl_client *client,
 	struct weston_seat *seat;
 	struct fs_output *fsout;
 
-	output = wl_resource_get_user_data(output_res);
+	output = weston_output_from_resource(output_res);
 	fsout = fs_output_for_output(output);
 
 	if (surface_res == NULL) {
diff --git a/ivi-shell/input-panel-ivi.c b/ivi-shell/input-panel-ivi.c
index 57d1cb2..0008a52 100644
--- a/ivi-shell/input-panel-ivi.c
+++ b/ivi-shell/input-panel-ivi.c
@@ -275,7 +275,7 @@ input_panel_surface_set_toplevel(struct wl_client *client,
 	wl_list_insert(&shell->input_panel.surfaces,
 		       &input_panel_surface->link);
 
-	input_panel_surface->output = wl_resource_get_user_data(output_resource);
+	input_panel_surface->output = weston_output_from_resource(output_resource);
 	input_panel_surface->panel = 0;
 }
 
diff --git a/libweston-desktop/wl-shell.c b/libweston-desktop/wl-shell.c
index 399139c..66553f4 100644
--- a/libweston-desktop/wl-shell.c
+++ b/libweston-desktop/wl-shell.c
@@ -302,7 +302,7 @@ weston_desktop_wl_shell_surface_protocol_set_fullscreen(struct wl_client *wl_cli
 	struct weston_output *output = NULL;
 
 	if (output_resource != NULL)
-		output = wl_resource_get_user_data(output_resource);
+		output = weston_output_from_resource(output_resource);
 
 	weston_desktop_wl_shell_change_state(surface, FULLSCREEN, NULL, 0, 0);
 	weston_desktop_api_fullscreen_requested(surface->desktop, dsurface,
diff --git a/libweston-desktop/xdg-shell-v5.c b/libweston-desktop/xdg-shell-v5.c
index 08cf71e..6c9292d 100644
--- a/libweston-desktop/xdg-shell-v5.c
+++ b/libweston-desktop/xdg-shell-v5.c
@@ -474,7 +474,7 @@ weston_desktop_xdg_surface_protocol_set_fullscreen(struct wl_client *wl_client,
 	struct weston_output *output = NULL;
 
 	if (output_resource != NULL)
-		output = wl_resource_get_user_data(output_resource);
+		output = weston_output_from_resource(output_resource);
 
 	weston_desktop_xdg_surface_ensure_added(surface);
 	weston_desktop_api_fullscreen_requested(surface->desktop, dsurface,
diff --git a/libweston-desktop/xdg-shell-v6.c b/libweston-desktop/xdg-shell-v6.c
index 7d0bd8e..c2225d2 100644
--- a/libweston-desktop/xdg-shell-v6.c
+++ b/libweston-desktop/xdg-shell-v6.c
@@ -482,7 +482,7 @@ weston_desktop_xdg_toplevel_protocol_set_fullscreen(struct wl_client *wl_client,
 	struct weston_output *output = NULL;
 
 	if (output_resource != NULL)
-		output = wl_resource_get_user_data(output_resource);
+		output = weston_output_from_resource(output_resource);
 
 	weston_desktop_xdg_toplevel_ensure_added(toplevel);
 	weston_desktop_api_fullscreen_requested(toplevel->base.desktop, dsurface,
diff --git a/libweston/compositor.c b/libweston/compositor.c
index cd5b6ec..8f53b65 100644
--- a/libweston/compositor.c
+++ b/libweston/compositor.c
@@ -4318,6 +4318,19 @@ bind_output(struct wl_client *client,
 		wl_output_send_done(resource);
 }
 
+/** Get the backing object of wl_output
+ *
+ * \param resource A wl_output protocol object.
+ * \return The backing object (user data) of a wl_resource representing a
+ * wl_output protocol object.
+ */
+WL_EXPORT struct weston_output *
+weston_output_from_resource(struct wl_resource *resource)
+{
+	return wl_resource_get_user_data(resource);
+}
+
+
 /* Move other outputs when one is resized so the space remains contiguous. */
 static void
 weston_compositor_reflow_outputs(struct weston_compositor *compositor,
diff --git a/libweston/compositor.h b/libweston/compositor.h
index c375f48..e5f111c 100644
--- a/libweston/compositor.h
+++ b/libweston/compositor.h
@@ -1937,6 +1937,9 @@ weston_output_disable(struct weston_output *output);
 void
 weston_pending_output_coldplug(struct weston_compositor *compositor);
 
+struct weston_output *
+weston_output_from_resource(struct wl_resource *resource);
+
 #ifdef  __cplusplus
 }
 #endif
diff --git a/tests/weston-test.c b/tests/weston-test.c
index 0123e99..189fcc1 100644
--- a/tests/weston-test.c
+++ b/tests/weston-test.c
@@ -473,7 +473,7 @@ capture_screenshot(struct wl_client *client,
 		   struct wl_resource *buffer_resource)
 {
 	struct weston_output *output =
-		wl_resource_get_user_data(output_resource);
+		weston_output_from_resource(output_resource);
 	struct weston_buffer *buffer =
 		weston_buffer_from_resource(buffer_resource);
 
-- 
2.10.2



More information about the wayland-devel mailing list