[PATCH weston v2 02/17] don't use weston_config in the backends code

Giulio Camuffo giuliocamuffo at gmail.com
Thu Dec 4 13:01:08 PST 2014


This is to make them usable by future libweston users, since they will
not use weston_config.
weston_config is still used in the backends entry points, which will
later on live in their own files.
---
 src/compositor-drm.c     | 305 +++++++++++++++++++++++++----------------------
 src/compositor-fbdev.c   |  10 +-
 src/compositor-rdp.c     |   8 +-
 src/compositor-wayland.c |  32 ++---
 src/compositor-x11.c     | 117 +++++++++---------
 src/compositor.c         |   6 +-
 src/compositor.h         |   2 +-
 7 files changed, 244 insertions(+), 236 deletions(-)

diff --git a/src/compositor-drm.c b/src/compositor-drm.c
index ea25bd5..ebba242 100644
--- a/src/compositor-drm.c
+++ b/src/compositor-drm.c
@@ -78,6 +78,19 @@ enum output_config {
 	OUTPUT_CONFIG_MODELINE
 };
 
+struct drm_output_parameters {
+	uint32_t format;
+	char *seat;
+	int scale;
+	uint32_t transform;
+	struct {
+		enum output_config config;
+		int width;
+		int height;
+		drmModeModeInfo modeline;
+	} mode;
+};
+
 struct drm_backend {
 	struct weston_backend base;
 	struct weston_compositor *compositor;
@@ -123,6 +136,9 @@ struct drm_backend {
 
 	uint32_t cursor_width;
 	uint32_t cursor_height;
+
+	void (*get_output_parameters)(const char *name,
+				      struct drm_output_parameters *parameters);
 };
 
 struct drm_mode {
@@ -216,6 +232,9 @@ struct drm_parameters {
 	int tty;
 	int use_pixman;
 	const char *seat_id;
+	uint32_t format;
+	void (*get_output_parameters)(const char *name,
+				      struct drm_output_parameters *parameters);
 };
 
 static struct gl_renderer_interface *gl_renderer;
@@ -1820,51 +1839,6 @@ find_and_parse_output_edid(struct drm_backend *b,
 	drmModeFreePropertyBlob(edid_blob);
 }
 
-
-
-static int
-parse_modeline(const char *s, drmModeModeInfo *mode)
-{
-	char hsync[16];
-	char vsync[16];
-	float fclock;
-
-	mode->type = DRM_MODE_TYPE_USERDEF;
-	mode->hskew = 0;
-	mode->vscan = 0;
-	mode->vrefresh = 0;
-	mode->flags = 0;
-
-	if (sscanf(s, "%f %hd %hd %hd %hd %hd %hd %hd %hd %15s %15s",
-		   &fclock,
-		   &mode->hdisplay,
-		   &mode->hsync_start,
-		   &mode->hsync_end,
-		   &mode->htotal,
-		   &mode->vdisplay,
-		   &mode->vsync_start,
-		   &mode->vsync_end,
-		   &mode->vtotal, hsync, vsync) != 11)
-		return -1;
-
-	mode->clock = fclock * 1000;
-	if (strcmp(hsync, "+hsync") == 0)
-		mode->flags |= DRM_MODE_FLAG_PHSYNC;
-	else if (strcmp(hsync, "-hsync") == 0)
-		mode->flags |= DRM_MODE_FLAG_NHSYNC;
-	else
-		return -1;
-
-	if (strcmp(vsync, "+vsync") == 0)
-		mode->flags |= DRM_MODE_FLAG_PVSYNC;
-	else if (strcmp(vsync, "-vsync") == 0)
-		mode->flags |= DRM_MODE_FLAG_NVSYNC;
-	else
-		return -1;
-
-	return 0;
-}
-
 static void
 setup_output_seat_constraint(struct drm_backend *b,
 			     struct weston_output *output,
@@ -1885,35 +1859,6 @@ setup_output_seat_constraint(struct drm_backend *b,
 }
 
 static int
-get_gbm_format_from_section(struct weston_config_section *section,
-			    uint32_t default_value,
-			    uint32_t *format)
-{
-	char *s;
-	int ret = 0;
-
-	weston_config_section_get_string(section,
-					 "gbm-format", &s, NULL);
-
-	if (s == NULL)
-		*format = default_value;
-	else if (strcmp(s, "xrgb8888") == 0)
-		*format = GBM_FORMAT_XRGB8888;
-	else if (strcmp(s, "rgb565") == 0)
-		*format = GBM_FORMAT_RGB565;
-	else if (strcmp(s, "xrgb2101010") == 0)
-		*format = GBM_FORMAT_XRGB2101010;
-	else {
-		weston_log("fatal: unrecognized pixel format: %s\n", s);
-		ret = -1;
-	}
-
-	free(s);
-
-	return ret;
-}
-
-static int
 create_output_for_connector(struct drm_backend *b,
 			    drmModeRes *resources,
 			    drmModeConnector *connector,
@@ -1922,15 +1867,13 @@ create_output_for_connector(struct drm_backend *b,
 	struct drm_output *output;
 	struct drm_mode *drm_mode, *next, *preferred, *current, *configured, *best;
 	struct weston_mode *m;
-	struct weston_config_section *section;
 	drmModeEncoder *encoder;
-	drmModeModeInfo crtc_mode, modeline;
+	drmModeModeInfo crtc_mode;
 	drmModeCrtc *crtc;
-	int i, width, height, scale;
-	char name[32], *s;
+	int i;
+	char name[32];
 	const char *type_name;
-	enum output_config config;
-	uint32_t transform;
+	struct drm_output_parameters params = { 0 };
 
 	i = find_crtc_for_connector(b, resources, connector);
 	if (i < 0) {
@@ -1955,42 +1898,13 @@ create_output_for_connector(struct drm_backend *b,
 	snprintf(name, 32, "%s%d", type_name, connector->connector_type_id);
 	output->base.name = strdup(name);
 
-	section = weston_config_get_section(b->compositor->config, "output", "name",
-					    output->base.name);
-	weston_config_section_get_string(section, "mode", &s, "preferred");
-	if (strcmp(s, "off") == 0)
-		config = OUTPUT_CONFIG_OFF;
-	else if (strcmp(s, "preferred") == 0)
-		config = OUTPUT_CONFIG_PREFERRED;
-	else if (strcmp(s, "current") == 0)
-		config = OUTPUT_CONFIG_CURRENT;
-	else if (sscanf(s, "%dx%d", &width, &height) == 2)
-		config = OUTPUT_CONFIG_MODE;
-	else if (parse_modeline(s, &modeline) == 0)
-		config = OUTPUT_CONFIG_MODELINE;
-	else {
-		weston_log("Invalid mode \"%s\" for output %s\n",
-			   s, output->base.name);
-		config = OUTPUT_CONFIG_PREFERRED;
-	}
-	free(s);
+	params.format = b->format;
 
-	weston_config_section_get_int(section, "scale", &scale, 1);
-	weston_config_section_get_string(section, "transform", &s, "normal");
-	if (weston_parse_transform(s, &transform) < 0)
-		weston_log("Invalid transform \"%s\" for output %s\n",
-			   s, output->base.name);
-
-	free(s);
-
-	if (get_gbm_format_from_section(section,
-					b->format,
-					&output->format) == -1)
-		output->format = b->format;
+	b->get_output_parameters(output->base.name, &params);
+	output->format = params.format;
 
-	weston_config_section_get_string(section, "seat", &s, "");
-	setup_output_seat_constraint(b, &output->base, s);
-	free(s);
+	setup_output_seat_constraint(b, &output->base, params.seat);
+	free(params.seat);
 
 	output->crtc_id = resources->crtcs[i];
 	output->pipe = i;
@@ -2021,7 +1935,7 @@ create_output_for_connector(struct drm_backend *b,
 			goto err_free;
 	}
 
-	if (config == OUTPUT_CONFIG_OFF) {
+	if (params.mode.config == OUTPUT_CONFIG_OFF) {
 		weston_log("Disabling output %s\n", output->base.name);
 		drmModeSetCrtc(b->drm.fd, output->crtc_id,
 			       0, 0, 0, 0, 0, NULL);
@@ -2034,9 +1948,9 @@ create_output_for_connector(struct drm_backend *b,
 	best = NULL;
 
 	wl_list_for_each_reverse(drm_mode, &output->base.mode_list, base.link) {
-		if (config == OUTPUT_CONFIG_MODE &&
-		    width == drm_mode->base.width &&
-		    height == drm_mode->base.height)
+		if (params.mode.config == OUTPUT_CONFIG_MODE &&
+		    params.mode.width == drm_mode->base.width &&
+		    params.mode.height == drm_mode->base.height)
 			configured = drm_mode;
 		if (!memcmp(&crtc_mode, &drm_mode->mode_info, sizeof crtc_mode))
 			current = drm_mode;
@@ -2045,8 +1959,8 @@ create_output_for_connector(struct drm_backend *b,
 		best = drm_mode;
 	}
 
-	if (config == OUTPUT_CONFIG_MODELINE) {
-		configured = drm_output_add_mode(output, &modeline);
+	if (params.mode.config == OUTPUT_CONFIG_MODELINE) {
+		configured = drm_output_add_mode(output, &params.mode.modeline);
 		if (!configured)
 			goto err_free;
 	}
@@ -2057,7 +1971,7 @@ create_output_for_connector(struct drm_backend *b,
 			goto err_free;
 	}
 
-	if (config == OUTPUT_CONFIG_CURRENT)
+	if (params.mode.config == OUTPUT_CONFIG_CURRENT)
 		configured = current;
 
 	if (option_current_mode && current)
@@ -2080,7 +1994,7 @@ create_output_for_connector(struct drm_backend *b,
 
 	weston_output_init(&output->base, b->compositor, x, y,
 			   connector->mmWidth, connector->mmHeight,
-			   transform, scale);
+			   params.transform, params.scale);
 
 	if (b->use_pixman) {
 		if (drm_output_init_pixman(output, b) < 0) {
@@ -2740,12 +2654,9 @@ renderer_switch_binding(struct weston_seat *seat, uint32_t time, uint32_t key,
 
 static struct drm_backend *
 drm_backend_create(struct weston_compositor *compositor,
-		      struct drm_parameters *param,
-		      int *argc, char *argv[],
-		      struct weston_config *config)
+		      struct drm_parameters *param)
 {
 	struct drm_backend *b;
-	struct weston_config_section *section;
 	struct udev_device *drm_device;
 	struct wl_event_loop *loop;
 	const char *path;
@@ -2761,20 +2672,9 @@ drm_backend_create(struct weston_compositor *compositor,
 	 * functionality for now. */
 	b->sprites_are_broken = 1;
 	b->compositor = compositor;
-
-	section = weston_config_get_section(config, "core", NULL, NULL);
-	if (get_gbm_format_from_section(section,
-					GBM_FORMAT_XRGB8888,
-					&b->format) == -1)
-		goto err_base;
-
 	b->use_pixman = param->use_pixman;
-
-	if (weston_compositor_init(compositor, argc, argv,
-				   config) < 0) {
-		weston_log("%s failed\n", __func__);
-		goto err_base;
-	}
+	b->get_output_parameters = param->get_output_parameters;
+	b->format = param->format;
 
 	/* Check if we run drm-backend using weston-launch */
 	compositor->launcher = weston_launcher_connect(compositor, param->tty,
@@ -2906,17 +2806,131 @@ err_udev:
 	udev_unref(b->udev);
 err_compositor:
 	weston_compositor_shutdown(compositor);
-err_base:
+
 	free(b);
 	return NULL;
 }
 
+static int
+parse_modeline(const char *s, drmModeModeInfo *mode)
+{
+	char hsync[16];
+	char vsync[16];
+	float fclock;
+
+	mode->type = DRM_MODE_TYPE_USERDEF;
+	mode->hskew = 0;
+	mode->vscan = 0;
+	mode->vrefresh = 0;
+	mode->flags = 0;
+
+	if (sscanf(s, "%f %hd %hd %hd %hd %hd %hd %hd %hd %15s %15s",
+		   &fclock,
+		   &mode->hdisplay,
+		   &mode->hsync_start,
+		   &mode->hsync_end,
+		   &mode->htotal,
+		   &mode->vdisplay,
+		   &mode->vsync_start,
+		   &mode->vsync_end,
+		   &mode->vtotal, hsync, vsync) != 11)
+		return -1;
+
+	mode->clock = fclock * 1000;
+	if (strcmp(hsync, "+hsync") == 0)
+		mode->flags |= DRM_MODE_FLAG_PHSYNC;
+	else if (strcmp(hsync, "-hsync") == 0)
+		mode->flags |= DRM_MODE_FLAG_NHSYNC;
+	else
+		return -1;
+
+	if (strcmp(vsync, "+vsync") == 0)
+		mode->flags |= DRM_MODE_FLAG_PVSYNC;
+	else if (strcmp(vsync, "-vsync") == 0)
+		mode->flags |= DRM_MODE_FLAG_NVSYNC;
+	else
+		return -1;
+
+	return 0;
+}
+
+static int
+parse_gbm_format(const char *s, uint32_t default_value, uint32_t *format)
+{
+	int ret = 0;
+
+	if (s == NULL)
+		*format = default_value;
+	else if (strcmp(s, "xrgb8888") == 0)
+		*format = GBM_FORMAT_XRGB8888;
+	else if (strcmp(s, "rgb565") == 0)
+		*format = GBM_FORMAT_RGB565;
+	else if (strcmp(s, "xrgb2101010") == 0)
+		*format = GBM_FORMAT_XRGB2101010;
+	else {
+		weston_log("fatal: unrecognized pixel format: %s\n", s);
+		ret = -1;
+	}
+
+	return ret;
+}
+
+static struct weston_config *wconfig;
+
+static void
+output_parameters(const char *name, struct drm_output_parameters *params)
+{
+	struct weston_config_section *section;
+	char *s;
+	uint32_t transform;
+
+	section = weston_config_get_section(wconfig, "output", "name", name);
+	weston_config_section_get_string(section, "mode", &s, "preferred");
+	if (strcmp(s, "off") == 0)
+		params->mode.config = OUTPUT_CONFIG_OFF;
+	else if (strcmp(s, "preferred") == 0)
+		params->mode.config = OUTPUT_CONFIG_PREFERRED;
+	else if (strcmp(s, "current") == 0)
+		params->mode.config = OUTPUT_CONFIG_CURRENT;
+	else if (sscanf(s, "%dx%d", &params->mode.width,
+				    &params->mode.height) == 2)
+		params->mode.config = OUTPUT_CONFIG_MODE;
+	else if (parse_modeline(s, &params->mode.modeline) == 0)
+		params->mode.config = OUTPUT_CONFIG_MODELINE;
+	else {
+		weston_log("Invalid mode \"%s\" for output %s\n",
+			   s, name);
+		params->mode.config = OUTPUT_CONFIG_PREFERRED;
+	}
+	free(s);
+
+	weston_config_section_get_int(section, "scale", &params->scale, 1);
+	weston_config_section_get_string(section, "transform", &s, "normal");
+	if (weston_parse_transform(s, &transform) < 0)
+		weston_log("Invalid transform \"%s\" for output %s\n",
+			   s, name);
+	free(s);
+
+	weston_config_section_get_string(section,
+					 "gbm-format", &s, NULL);
+	parse_gbm_format(s, params->format, &params->format);
+
+	free(s);
+
+	weston_config_section_get_string(section, "seat", &params->seat, "");
+}
+
 WL_EXPORT int
 backend_init(struct weston_compositor *compositor, int *argc, char *argv[],
 	     struct weston_config *config)
 {
 	struct drm_backend *b;
 	struct drm_parameters param = { 0, };
+	struct weston_config_section *section;
+	char *s;
+	int ret;
+
+	wconfig = config;
 
 	const struct weston_option drm_options[] = {
 		{ WESTON_OPTION_INTEGER, "connector", 0, &param.connector },
@@ -2927,10 +2941,19 @@ backend_init(struct weston_compositor *compositor, int *argc, char *argv[],
 	};
 
 	param.seat_id = default_seat;
+	param.get_output_parameters = output_parameters;
 
 	parse_options(drm_options, ARRAY_LENGTH(drm_options), argc, argv);
 
-	b = drm_backend_create(compositor, &param, argc, argv, config);
+	section = weston_config_get_section(config, "core", NULL, NULL);
+	weston_config_section_get_string(section,
+					 "gbm-format", &s, NULL);
+	ret = parse_gbm_format(s, GBM_FORMAT_XRGB8888, &param.format);
+	free(s);
+	if (ret == -1)
+		return -1;
+
+	b = drm_backend_create(compositor, &param);
 	if (b == NULL)
 		return -1;
 	return 0;
diff --git a/src/compositor-fbdev.c b/src/compositor-fbdev.c
index fe5224d..b047d38 100644
--- a/src/compositor-fbdev.c
+++ b/src/compositor-fbdev.c
@@ -861,8 +861,7 @@ switch_vt_binding(struct weston_seat *seat, uint32_t time, uint32_t key, void *d
 }
 
 static struct fbdev_backend *
-fbdev_backend_create(struct weston_compositor *compositor, int *argc, char *argv[],
-                     struct weston_config *config,
+fbdev_backend_create(struct weston_compositor *compositor,
                      struct fbdev_parameters *param)
 {
 	struct fbdev_backend *backend;
@@ -876,10 +875,6 @@ fbdev_backend_create(struct weston_compositor *compositor, int *argc, char *argv
 		return NULL;
 
 	backend->compositor = compositor;
-	if (weston_compositor_init(compositor, argc, argv,
-	                           config) < 0)
-		goto out_free;
-
 	if (weston_compositor_set_presentation_clock_software(
 							compositor) < 0)
 		goto out_compositor;
@@ -952,7 +947,6 @@ out_udev:
 out_compositor:
 	weston_compositor_shutdown(compositor);
 
-out_free:
 	free(backend);
 
 	return NULL;
@@ -979,7 +973,7 @@ backend_init(struct weston_compositor *compositor, int *argc, char *argv[],
 
 	parse_options(fbdev_options, ARRAY_LENGTH(fbdev_options), argc, argv);
 
-	b = fbdev_backend_create(compositor, argc, argv, config, &param);
+	b = fbdev_backend_create(compositor, &param);
 	if (b == NULL)
 		return -1;
 	return 0;
diff --git a/src/compositor-rdp.c b/src/compositor-rdp.c
index 678c35e..191e0c3 100644
--- a/src/compositor-rdp.c
+++ b/src/compositor-rdp.c
@@ -1085,8 +1085,7 @@ rdp_incoming_peer(freerdp_listener *instance, freerdp_peer *client)
 
 static struct rdp_backend *
 rdp_backend_create(struct weston_compositor *compositor,
-		   struct rdp_backend_config *config,
-		   int *argc, char *argv[], struct weston_config *wconfig)
+		   struct rdp_backend_config *config)
 {
 	struct rdp_backend *b;
 	char *fd_str;
@@ -1097,9 +1096,6 @@ rdp_backend_create(struct weston_compositor *compositor,
 		return NULL;
 
 	b->compositor = compositor;
-	if (weston_compositor_init(compositor, argc, argv, wconfig) < 0)
-		goto err_free;
-
 	b->base.destroy = rdp_destroy;
 	b->base.restore = rdp_restore;
 	b->rdp_key = config->rdp_key ? strdup(config->rdp_key) : NULL;
@@ -1196,7 +1192,7 @@ backend_init(struct weston_compositor *compositor, int *argc, char *argv[],
 	};
 
 	parse_options(rdp_options, ARRAY_LENGTH(rdp_options), argc, argv);
-	b = rdp_backend_create(compositor, &config, argc, argv, wconfig);
+	b = rdp_backend_create(compositor, &config);
 	if (b == NULL)
 		return -1;
 	return 0;
diff --git a/src/compositor-wayland.c b/src/compositor-wayland.c
index 6265d9c..d8148a6 100644
--- a/src/compositor-wayland.c
+++ b/src/compositor-wayland.c
@@ -1864,25 +1864,16 @@ static const char *left_ptrs[] = {
 };
 
 static void
-create_cursor(struct wayland_backend *b, struct weston_config *config)
+create_cursor(struct wayland_backend *b, const char *theme, int size)
 {
-	struct weston_config_section *s;
-	int size;
-	char *theme = NULL;
 	unsigned int i;
 
-	s = weston_config_get_section(config, "shell", NULL, NULL);
-	weston_config_section_get_string(s, "cursor-theme", &theme, NULL);
-	weston_config_section_get_int(s, "cursor-size", &size, 32);
-
 	b->cursor_theme = wl_cursor_theme_load(theme, size, b->parent.shm);
 	if (!b->cursor_theme) {
 		fprintf(stderr, "could not load cursor theme\n");
 		return;
 	}
 
-	free(theme);
-
 	b->cursor = NULL;
 	for (i = 0; !b->cursor && i < ARRAY_LENGTH(left_ptrs); ++i)
 		b->cursor = wl_cursor_theme_get_cursor(b->cursor_theme,
@@ -1917,8 +1908,8 @@ fullscreen_binding(struct weston_seat *seat_base, uint32_t time, uint32_t key,
 
 static struct wayland_backend *
 wayland_backend_create(struct weston_compositor *compositor, int use_pixman,
-		       const char *display_name, int *argc, char *argv[],
-		       struct weston_config *config)
+		       const char *display_name,
+		       const char *cursor_theme, int cursor_size)
 {
 	struct wayland_backend *b;
 	struct wl_event_loop *loop;
@@ -1929,10 +1920,6 @@ wayland_backend_create(struct weston_compositor *compositor, int use_pixman,
 		return NULL;
 
 	b->compositor = compositor;
-	if (weston_compositor_init(compositor, argc, argv,
-				   config) < 0)
-		goto err_free;
-
 	if (weston_compositor_set_presentation_clock_software(compositor) < 0)
 		goto err_compositor;
 
@@ -1948,7 +1935,7 @@ wayland_backend_create(struct weston_compositor *compositor, int use_pixman,
 	wl_registry_add_listener(b->parent.registry, &registry_listener, b);
 	wl_display_roundtrip(b->parent.wl_display);
 
-	create_cursor(b, config);
+	create_cursor(b, cursor_theme, cursor_size);
 
 	b->use_pixman = use_pixman;
 
@@ -1998,7 +1985,7 @@ err_display:
 	wl_display_disconnect(b->parent.wl_display);
 err_compositor:
 	weston_compositor_shutdown(compositor);
-err_free:
+
 	free(b);
 	return NULL;
 }
@@ -2035,6 +2022,8 @@ backend_init(struct weston_compositor *compositor, int *argc, char *argv[],
 	int x, count, width, height, scale, use_pixman, fullscreen, sprawl;
 	const char *section_name, *display_name;
 	char *name;
+	int size;
+	char *theme = NULL;
 
 	const struct weston_option wayland_options[] = {
 		{ WESTON_OPTION_INTEGER, "width", 0, &width },
@@ -2058,8 +2047,13 @@ backend_init(struct weston_compositor *compositor, int *argc, char *argv[],
 	parse_options(wayland_options,
 		      ARRAY_LENGTH(wayland_options), argc, argv);
 
+	section = weston_config_get_section(config, "shell", NULL, NULL);
+	weston_config_section_get_string(section, "cursor-theme", &theme, NULL);
+	weston_config_section_get_int(section, "cursor-size", &size, 32);
+
 	b = wayland_backend_create(compositor, use_pixman, display_name,
-				   argc, argv, config);
+				   theme, size);
+	free(theme);
 	if (!b)
 		return -1;
 
diff --git a/src/compositor-x11.c b/src/compositor-x11.c
index 10c9543..9521e32 100644
--- a/src/compositor-x11.c
+++ b/src/compositor-x11.c
@@ -1449,19 +1449,10 @@ static struct x11_backend *
 x11_backend_create(struct weston_compositor *compositor,
 		   int fullscreen,
 		   int no_input,
-		   int use_pixman,
-		   int *argc, char *argv[],
-		   struct weston_config *config)
+		   int use_pixman)
 {
 	struct x11_backend *b;
-	struct x11_output *output;
-	struct weston_config_section *section;
 	xcb_screen_iterator_t s;
-	int i, x = 0, output_count = 0;
-	int width, height, scale, count;
-	const char *section_name;
-	char *name, *t, *mode;
-	uint32_t transform;
 
 	weston_log("initializing x11 backend\n");
 
@@ -1470,9 +1461,6 @@ x11_backend_create(struct weston_compositor *compositor,
 		return NULL;
 
 	b->compositor = compositor;
-	if (weston_compositor_init(compositor, argc, argv, config) < 0)
-		goto err_free;
-
 	if (weston_compositor_set_presentation_clock_software(compositor) < 0)
 		goto err_free;
 
@@ -1515,6 +1503,60 @@ x11_backend_create(struct weston_compositor *compositor,
 	if (x11_input_create(b, no_input) < 0)
 		goto err_renderer;
 
+	b->xcb_source =
+		wl_event_loop_add_fd(compositor->input_loop,
+				     xcb_get_file_descriptor(b->conn),
+				     WL_EVENT_READABLE,
+				     x11_backend_handle_event, b);
+	wl_event_source_check(b->xcb_source);
+
+	compositor->backend = &b->base;
+	return b;
+
+err_renderer:
+	compositor->renderer->destroy(compositor);
+err_xdisplay:
+	XCloseDisplay(b->dpy);
+err_free:
+	free(b);
+	return NULL;
+}
+
+WL_EXPORT int
+backend_init(struct weston_compositor *compositor, int *argc, char *argv[],
+	     struct weston_config *config)
+{
+	struct x11_backend *b;
+	int fullscreen = 0;
+	int no_input = 0;
+	int use_pixman = 0;
+	struct weston_config_section *section;
+	int width, height, scale, count;
+	const char *section_name;
+	int i, x = 0, output_count = 0;
+	char *name, *t, *mode;
+	uint32_t transform;
+	struct x11_output *output;
+
+	const struct weston_option x11_options[] = {
+		{ WESTON_OPTION_INTEGER, "width", 0, &option_width },
+		{ WESTON_OPTION_INTEGER, "height", 0, &option_height },
+		{ WESTON_OPTION_INTEGER, "scale", 0, &option_scale },
+		{ WESTON_OPTION_BOOLEAN, "fullscreen", 'f', &fullscreen },
+		{ WESTON_OPTION_INTEGER, "output-count", 0, &option_count },
+		{ WESTON_OPTION_BOOLEAN, "no-input", 0, &no_input },
+		{ WESTON_OPTION_BOOLEAN, "use-pixman", 0, &use_pixman },
+	};
+
+	parse_options(x11_options, ARRAY_LENGTH(x11_options), argc, argv);
+
+	b = x11_backend_create(compositor,
+			       fullscreen,
+			       no_input,
+			       use_pixman);
+	if (b == NULL)
+		return -1;
+
 	width = option_width ? option_width : 1024;
 	height = option_height ? option_height : 640;
 	scale = option_scale ? option_scale : 1;
@@ -1581,54 +1623,9 @@ x11_backend_create(struct weston_compositor *compositor,
 		x = pixman_region32_extents(&output->base.region)->x2;
 	}
 
-	b->xcb_source =
-		wl_event_loop_add_fd(compositor->input_loop,
-				     xcb_get_file_descriptor(b->conn),
-				     WL_EVENT_READABLE,
-				     x11_backend_handle_event, b);
-	wl_event_source_check(b->xcb_source);
-
-	compositor->backend = &b->base;
-	return b;
+	return 0;
 
 err_x11_input:
 	x11_input_destroy(b);
-err_renderer:
-	compositor->renderer->destroy(compositor);
-err_xdisplay:
-	XCloseDisplay(b->dpy);
-err_free:
-	free(b);
-	return NULL;
-}
-
-WL_EXPORT int
-backend_init(struct weston_compositor *compositor, int *argc, char *argv[],
-	     struct weston_config *config)
-{
-	struct x11_backend *b;
-	int fullscreen = 0;
-	int no_input = 0;
-	int use_pixman = 0;
-
-	const struct weston_option x11_options[] = {
-		{ WESTON_OPTION_INTEGER, "width", 0, &option_width },
-		{ WESTON_OPTION_INTEGER, "height", 0, &option_height },
-		{ WESTON_OPTION_INTEGER, "scale", 0, &option_scale },
-		{ WESTON_OPTION_BOOLEAN, "fullscreen", 'f', &fullscreen },
-		{ WESTON_OPTION_INTEGER, "output-count", 0, &option_count },
-		{ WESTON_OPTION_BOOLEAN, "no-input", 0, &no_input },
-		{ WESTON_OPTION_BOOLEAN, "use-pixman", 0, &use_pixman },
-	};
-
-	parse_options(x11_options, ARRAY_LENGTH(x11_options), argc, argv);
-
-	b = x11_backend_create(compositor,
-			       fullscreen,
-			       no_input,
-			       use_pixman,
-			       argc, argv, config);
-	if (b == NULL)
-		return -1;
-	return 0;
+	return -1;
 }
diff --git a/src/compositor.c b/src/compositor.c
index b5a3cb3..db07f70 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -4010,7 +4010,6 @@ weston_environment_get_fd(const char *env)
 
 WL_EXPORT int
 weston_compositor_init(struct weston_compositor *ec,
-		       int *argc, char *argv[],
 		       struct weston_config *config)
 {
 	struct wl_event_loop *loop;
@@ -4804,6 +4803,11 @@ int main(int argc, char *argv[])
 	}
 
 	ec->wl_display = display;
+	if (weston_compositor_init(ec, config) < 0) {
+		ret = EXIT_FAILURE;
+		goto out_signals;
+	}
+
 	if (backend_init(ec, &argc, argv, config) < 0) {
 		weston_log("fatal: failed to create compositor backend\n");
 		ret = EXIT_FAILURE;
diff --git a/src/compositor.h b/src/compositor.h
index bc10137..774605e 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -1258,7 +1258,7 @@ weston_compositor_get_time(void);
 
 int
 weston_compositor_init(struct weston_compositor *ec,
-		       int *argc, char *argv[], struct weston_config *config);
+		       struct weston_config *config);
 int
 weston_compositor_set_presentation_clock(struct weston_compositor *compositor,
 					 clockid_t clk_id);
-- 
2.1.3



More information about the wayland-devel mailing list