[PATCH 03/12] compositor: Move output positining logic out of the backends

Xiong Zhang xiong.y.zhang at intel.com
Fri Mar 7 00:27:21 PST 2014


From: Ander Conselvan de Oliveira <ander.conselvan.de.oliveira at intel.com>

Move the code for choosing the x and y of an output out of the backend
into weston_output_init(). All the backends implement the same simple
behavior, so this lets that code be in just one place.

Signed-off-by: Ander Conselvan de Oliveira <ander.conselvan.de.oliveira at intel.com>
---
 src/compositor-drm.c      | 24 ++++--------------------
 src/compositor-fbdev.c    |  2 +-
 src/compositor-headless.c |  2 +-
 src/compositor-rpi.c      |  2 +-
 src/compositor-wayland.c  | 22 +++++++++-------------
 src/compositor-x11.c      | 14 +++++---------
 src/compositor.c          | 20 ++++++++++++++++----
 src/compositor.h          |  2 +-
 8 files changed, 38 insertions(+), 50 deletions(-)

diff --git a/src/compositor-drm.c b/src/compositor-drm.c
index a1f653c..57064ec 100644
--- a/src/compositor-drm.c
+++ b/src/compositor-drm.c
@@ -1871,7 +1871,7 @@ static int
 create_output_for_connector(struct drm_compositor *ec,
 			    drmModeRes *resources,
 			    drmModeConnector *connector,
-			    int x, int y, struct udev_device *drm_device)
+			    struct udev_device *drm_device)
 {
 	struct drm_output *output;
 	struct drm_mode *drm_mode, *next, *preferred, *current, *configured, *best;
@@ -2024,7 +2024,7 @@ create_output_for_connector(struct drm_compositor *ec,
 
 	output->base.current_mode->flags |= WL_OUTPUT_MODE_CURRENT;
 
-	weston_output_init(&output->base, &ec->base, x, y,
+	weston_output_init(&output->base, &ec->base,
 			   connector->mmWidth, connector->mmHeight,
 			   transform, scale);
 
@@ -2179,7 +2179,6 @@ create_outputs(struct drm_compositor *ec, uint32_t option_connector,
 	drmModeConnector *connector;
 	drmModeRes *resources;
 	int i;
-	int x = 0, y = 0;
 
 	resources = drmModeGetResources(ec->drm.fd);
 	if (!resources) {
@@ -2211,15 +2210,11 @@ create_outputs(struct drm_compositor *ec, uint32_t option_connector,
 		    (option_connector == 0 ||
 		     connector->connector_id == option_connector)) {
 			if (create_output_for_connector(ec, resources,
-							connector, x, y,
+							connector,
 							drm_device) < 0) {
 				drmModeFreeConnector(connector);
 				continue;
 			}
-
-			x += container_of(ec->base.output_list.prev,
-					  struct weston_output,
-					  link)->width;
 		}
 
 		drmModeFreeConnector(connector);
@@ -2242,7 +2237,6 @@ update_outputs(struct drm_compositor *ec, struct udev_device *drm_device)
 	drmModeConnector *connector;
 	drmModeRes *resources;
 	struct drm_output *output, *next;
-	int x = 0, y = 0;
 	uint32_t connected = 0, disconnects = 0;
 	int i;
 
@@ -2268,18 +2262,8 @@ update_outputs(struct drm_compositor *ec, struct udev_device *drm_device)
 		connected |= (1 << connector_id);
 
 		if (!(ec->connector_allocator & (1 << connector_id))) {
-			struct weston_output *last =
-				container_of(ec->base.output_list.prev,
-					     struct weston_output, link);
-
-			/* XXX: not yet needed, we die with 0 outputs */
-			if (!wl_list_empty(&ec->base.output_list))
-				x = last->x + last->width;
-			else
-				x = 0;
-			y = 0;
 			create_output_for_connector(ec, resources,
-						    connector, x, y,
+						    connector,
 						    drm_device);
 			weston_log("connector %d connected\n", connector_id);
 
diff --git a/src/compositor-fbdev.c b/src/compositor-fbdev.c
index 0d96269..076a9a8 100644
--- a/src/compositor-fbdev.c
+++ b/src/compositor-fbdev.c
@@ -555,7 +555,7 @@ fbdev_output_create(struct fbdev_compositor *compositor,
 	output->base.model = output->fb_info.id;
 
 	weston_output_init(&output->base, &compositor->base,
-	                   0, 0, output->fb_info.width_mm,
+			   output->fb_info.width_mm,
 	                   output->fb_info.height_mm,
 	                   WL_OUTPUT_TRANSFORM_NORMAL,
 			   1);
diff --git a/src/compositor-headless.c b/src/compositor-headless.c
index 4ecb8d4..326c11b 100644
--- a/src/compositor-headless.c
+++ b/src/compositor-headless.c
@@ -108,7 +108,7 @@ headless_compositor_create_output(struct headless_compositor *c,
 	wl_list_insert(&output->base.mode_list, &output->mode.link);
 
 	output->base.current_mode = &output->mode;
-	weston_output_init(&output->base, &c->base, 0, 0, width, height,
+	weston_output_init(&output->base, &c->base, width, height,
 			   WL_OUTPUT_TRANSFORM_NORMAL, 1);
 
 	output->base.make = "weston";
diff --git a/src/compositor-rpi.c b/src/compositor-rpi.c
index e7c0e0d..7312822 100644
--- a/src/compositor-rpi.c
+++ b/src/compositor-rpi.c
@@ -381,7 +381,7 @@ rpi_output_create(struct rpi_compositor *compositor, uint32_t transform)
 	mm_height = modeinfo.height * (25.4f / 96.0f);
 
 	weston_output_init(&output->base, &compositor->base,
-			   0, 0, round(mm_width), round(mm_height),
+			   round(mm_width), round(mm_height),
 			   transform, 1);
 
 	if (rpi_renderer_output_create(&output->base, output->display) < 0)
diff --git a/src/compositor-wayland.c b/src/compositor-wayland.c
index 899c329..9e94a7b 100644
--- a/src/compositor-wayland.c
+++ b/src/compositor-wayland.c
@@ -748,15 +748,14 @@ wayland_output_set_fullscreen(struct wayland_output *output,
 }
 
 static struct wayland_output *
-wayland_output_create(struct wayland_compositor *c, int x, int y,
+wayland_output_create(struct wayland_compositor *c,
 		      int width, int height, const char *name, int fullscreen,
 		      uint32_t transform, int32_t scale)
 {
 	struct wayland_output *output;
 	int output_width, output_height;
 
-	weston_log("Creating %dx%d wayland output at (%d, %d)\n",
-		   width, height, x, y);
+	weston_log("Creating %dx%d wayland output\n", width, height);
 
 	output = zalloc(sizeof *output);
 	if (output == NULL)
@@ -807,7 +806,7 @@ wayland_output_create(struct wayland_compositor *c, int x, int y,
 	wl_list_init(&output->shm.buffers);
 	wl_list_init(&output->shm.free_buffers);
 
-	weston_output_init(&output->base, &c->base, x, y, width, height,
+	weston_output_init(&output->base, &c->base, width, height,
 			   transform, scale);
 
 	if (c->use_pixman) {
@@ -849,7 +848,7 @@ static struct wayland_output *
 wayland_output_create_for_config(struct wayland_compositor *c,
 				 struct weston_config_section *config_section,
 				 int option_width, int option_height,
-				 int option_scale, int32_t x, int32_t y)
+				 int option_scale)
 {
 	struct wayland_output *output;
 	char *mode, *t, *name, *str;
@@ -914,7 +913,7 @@ wayland_output_create_for_config(struct wayland_compositor *c,
 		weston_log("Invalid transform \"%s\" for output %s\n", t, name);
 	free(t);
 
-	output = wayland_output_create(c, x, y, width, height, name, 0,
+	output = wayland_output_create(c, width, height, name, 0,
 				       transform, scale);
 	free(name);
 
@@ -1578,7 +1577,7 @@ backend_init(struct wl_display *display, int *argc, char *argv[],
 	struct wayland_compositor *c;
 	struct wayland_output *output;
 	struct weston_config_section *section;
-	int x, count, width, height, scale, use_pixman, fullscreen;
+	int count, width, height, scale, use_pixman, fullscreen;
 	const char *section_name, *display_name;
 	char *name;
 
@@ -1608,7 +1607,7 @@ backend_init(struct wl_display *display, int *argc, char *argv[],
 		return NULL;
 
 	if (fullscreen) {
-		output = wayland_output_create(c, 0, 0, width, height,
+		output = wayland_output_create(c, width, height,
 					       NULL, 1, 0, 1);
 		if (!output)
 			goto err_outputs;
@@ -1618,7 +1617,6 @@ backend_init(struct wl_display *display, int *argc, char *argv[],
 	}
 
 	section = NULL;
-	x = 0;
 	while (weston_config_next_section(config, &section, &section_name)) {
 		if (!section_name || strcmp(section_name, "output") != 0)
 			continue;
@@ -1633,13 +1631,12 @@ backend_init(struct wl_display *display, int *argc, char *argv[],
 		free(name);
 
 		output = wayland_output_create_for_config(c, section, width,
-							  height, scale, x, 0);
+							  height, scale);
 		if (!output)
 			goto err_outputs;
 		if (wayland_output_set_windowed(output))
 			goto err_outputs;
 
-		x += output->base.width;
 		--count;
 	}
 
@@ -1650,14 +1647,13 @@ backend_init(struct wl_display *display, int *argc, char *argv[],
 	if (!scale)
 		scale = 1;
 	while (count > 0) {
-		output = wayland_output_create(c, x, 0, width, height,
+		output = wayland_output_create(c, width, height,
 					       NULL, 0, 0, scale);
 		if (!output)
 			goto err_outputs;
 		if (wayland_output_set_windowed(output))
 			goto err_outputs;
 
-		x += width;
 		--count;
 	}
 
diff --git a/src/compositor-x11.c b/src/compositor-x11.c
index 6b5eb64..01af835 100644
--- a/src/compositor-x11.c
+++ b/src/compositor-x11.c
@@ -748,7 +748,7 @@ x11_output_init_shm(struct x11_compositor *c, struct x11_output *output,
 }
 
 static struct x11_output *
-x11_compositor_create_output(struct x11_compositor *c, int x, int y,
+x11_compositor_create_output(struct x11_compositor *c,
 			     int width, int height, int fullscreen,
 			     int no_input, char *configured_name,
 			     uint32_t transform, int32_t scale)
@@ -876,7 +876,7 @@ x11_compositor_create_output(struct x11_compositor *c, int x, int y,
 		output->base.name = strdup(configured_name);
 
 	weston_output_init(&output->base, &c->base,
-			   x, y, width, height, transform, scale);
+			   width, height, transform, scale);
 
 	if (c->use_pixman) {
 		if (x11_output_init_shm(c, output,
@@ -1477,7 +1477,7 @@ x11_compositor_create(struct wl_display *display,
 	struct x11_output *output;
 	struct weston_config_section *section;
 	xcb_screen_iterator_t s;
-	int i, x = 0, output_count = 0;
+	int i, output_count = 0;
 	int width, height, count, scale;
 	const char *section_name;
 	char *name, *t, *mode;
@@ -1568,28 +1568,24 @@ x11_compositor_create(struct wl_display *display,
 		transform = parse_transform(t, name);
 		free(t);
 
-		output = x11_compositor_create_output(c, x, 0,
-						      width, height,
+		output = x11_compositor_create_output(c, width, height,
 						      fullscreen, no_input,
 						      name, transform, scale);
 		free(name);
 		if (output == NULL)
 			goto err_x11_input;
 
-		x = pixman_region32_extents(&output->base.region)->x2;
-
 		output_count++;
 		if (option_count && output_count >= option_count)
 			break;
 	}
 
 	for (i = output_count; i < count; i++) {
-		output = x11_compositor_create_output(c, x, 0, width, height,
+		output = x11_compositor_create_output(c, width, height,
 						      fullscreen, no_input, NULL,
 						      WL_OUTPUT_TRANSFORM_NORMAL, 1);
 		if (output == NULL)
 			goto err_x11_input;
-		x = pixman_region32_extents(&output->base.region)->x2;
 	}
 
 	c->xcb_source =
diff --git a/src/compositor.c b/src/compositor.c
index 7c29d51..51f2fae 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -3259,12 +3259,24 @@ weston_output_move(struct weston_output *output, int x, int y)
 
 WL_EXPORT void
 weston_output_init(struct weston_output *output, struct weston_compositor *c,
-		   int x, int y, int mm_width, int mm_height, uint32_t transform,
+		   int mm_width, int mm_height, uint32_t transform,
 		   int32_t scale)
 {
+	struct weston_output *last;
+
+	/* Find the position for this output */
+	if (!wl_list_empty(&c->output_list)) {
+		last = container_of(c->output_list.prev,
+				    struct weston_output, link);
+
+		output->x = last->x + last->width;
+		output->y = 0;
+	} else {
+		output->x = 0;
+		output->y = 0;
+	}
+
 	output->compositor = c;
-	output->x = x;
-	output->y = y;
 	output->mm_width = mm_width;
 	output->mm_height = mm_height;
 	output->dirty = 1;
@@ -3273,7 +3285,7 @@ weston_output_init(struct weston_output *output, struct weston_compositor *c,
 	weston_output_transform_scale_init(output, transform, scale);
 	weston_output_init_zoom(output);
 
-	weston_output_init_geometry(output, x, y);
+	weston_output_init_geometry(output, output->x, output->y);
 	weston_output_damage(output);
 
 	wl_signal_init(&output->frame_signal);
diff --git a/src/compositor.h b/src/compositor.h
index 8fb8afb..e3412a1 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -1210,7 +1210,7 @@ void
 weston_output_move(struct weston_output *output, int x, int y);
 void
 weston_output_init(struct weston_output *output, struct weston_compositor *c,
-		   int x, int y, int width, int height, uint32_t transform, int32_t scale);
+		   int width, int height, uint32_t transform, int32_t scale);
 void
 weston_output_destroy(struct weston_output *output);
 void
-- 
1.8.3.2



More information about the wayland-devel mailing list