[PATCH weston v1] refactor configuration API of headless-backend

Benoit Gschwind gschwind at gnu-log.net
Sun Feb 28 13:08:07 UTC 2016


My apologies, I forget to add the new .h file

---
 Makefile.am               |  1 +
 src/compositor-headless.c | 42 +++++++-----------------------
 src/compositor-headless.h | 54 +++++++++++++++++++++++++++++++++++++++
 src/main.c                | 65 ++++++++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 128 insertions(+), 34 deletions(-)
 create mode 100644 src/compositor-headless.h

diff --git a/Makefile.am b/Makefile.am
index 505d40a..d63e9d0 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -72,6 +72,7 @@ weston_SOURCES =					\
 	src/log.c					\
 	src/compositor.c				\
 	src/compositor.h				\
+	src/compositor-headless.h				\
 	src/input.c					\
 	src/data-device.c				\
 	src/screenshooter.c				\
diff --git a/src/compositor-headless.c b/src/compositor-headless.c
index ba0d8d7..00a0f39 100644
--- a/src/compositor-headless.c
+++ b/src/compositor-headless.c
@@ -33,6 +33,7 @@
 
 #include "shared/helpers.h"
 #include "compositor.h"
+#include "compositor-headless.h"
 #include "pixman-renderer.h"
 #include "presentation_timing-server-protocol.h"
 
@@ -51,13 +52,6 @@ struct headless_output {
 	pixman_image_t *image;
 };
 
-struct headless_parameters {
-	int width;
-	int height;
-	int use_pixman;
-	uint32_t transform;
-};
-
 static void
 headless_output_start_repaint_loop(struct weston_output *output)
 {
@@ -120,7 +114,7 @@ headless_output_destroy(struct weston_output *output_base)
 
 static int
 headless_backend_create_output(struct headless_backend *b,
-			       struct headless_parameters *param)
+			       struct weston_headless_backend_config *param)
 {
 	struct weston_compositor *c = b->compositor;
 	struct headless_output *output;
@@ -217,7 +211,7 @@ headless_destroy(struct weston_compositor *ec)
 
 static struct headless_backend *
 headless_backend_create(struct weston_compositor *compositor,
-			struct headless_parameters *param,
+			struct weston_headless_backend_config *param,
 			const char *display_name)
 {
 	struct headless_backend *b;
@@ -258,34 +252,16 @@ err_free:
 }
 
 WL_EXPORT int
-backend_init(struct weston_compositor *compositor,
-	     int *argc, char *argv[],
-	     struct weston_config *config,
-	     struct weston_backend_config *config_base)
+headless_backend_init(struct weston_compositor *compositor,
+	     struct weston_headless_backend_config *config)
 {
-	int width = 1024, height = 640;
+	struct headless_backend * b = NULL;
 	char *display_name = NULL;
-	struct headless_parameters param = { 0, };
-	const char *transform = "normal";
-	struct headless_backend *b;
-
-	const struct weston_option headless_options[] = {
-		{ WESTON_OPTION_INTEGER, "width", 0, &width },
-		{ WESTON_OPTION_INTEGER, "height", 0, &height },
-		{ WESTON_OPTION_BOOLEAN, "use-pixman", 0, &param.use_pixman },
-		{ WESTON_OPTION_STRING, "transform", 0, &transform },
-	};
-
-	parse_options(headless_options,
-		      ARRAY_LENGTH(headless_options), argc, argv);
-
-	param.width = width;
-	param.height = height;
+	b = headless_backend_create(compositor, config, display_name);
 
-	if (weston_parse_transform(transform, &param.transform) < 0)
-		weston_log("Invalid transform \"%s\"\n", transform);
+	/* TODO: do better thing */
+	free(config);
 
-	b = headless_backend_create(compositor, &param, display_name);
 	if (b == NULL)
 		return -1;
 	return 0;
diff --git a/src/compositor-headless.h b/src/compositor-headless.h
new file mode 100644
index 0000000..76ee8a6
--- /dev/null
+++ b/src/compositor-headless.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright © 2016 Benoit Gschwind
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef SRC_COMPOSITOR_HEADLESS_H_
+#define SRC_COMPOSITOR_HEADLESS_H_
+
+#ifdef  __cplusplus
+extern "C" {
+#endif
+
+#include "compositor.h"
+
+struct weston_headless_backend_config {
+	int width;
+	int height;
+	int use_pixman;
+	uint32_t transform;
+};
+
+typedef int (*headless_backend_init_func)(
+		struct weston_compositor *c,
+	    struct weston_headless_backend_config *config);
+
+WL_EXPORT int
+headless_backend_init(struct weston_compositor *compositor,
+	     struct weston_headless_backend_config *config);
+
+#ifdef  __cplusplus
+}
+#endif
+
+#endif /* SRC_COMPOSITOR_HEADLESS_H_ */
diff --git a/src/main.c b/src/main.c
index 1850fa6..1fd8b76 100644
--- a/src/main.c
+++ b/src/main.c
@@ -42,6 +42,7 @@
 #endif
 
 #include "compositor.h"
+#include "compositor-headless.h"
 #include "../shared/os-compatibility.h"
 #include "../shared/helpers.h"
 #include "git-version.h"
@@ -653,12 +654,74 @@ load_backend_old(struct weston_compositor *compositor, const char *backend,
 	return backend_init(compositor, argc, argv, wc, NULL);
 }
 
+struct weston_headless_backend_config *
+weston_headless_backend_config_create() {
+	struct weston_headless_backend_config * ret =
+			(__typeof__(ret))zalloc(sizeof *ret);
+	return ret;
+}
+
+static int
+weston_headless_backend_load(
+		struct weston_compositor *compositor,
+		struct weston_wayland_backend_config *config) {
+
+	headless_backend_init_func backend_init;
+
+	backend_init = weston_load_module("headless-backend.so", "headless_backend_init");
+	if (!backend_init)
+		return -1;
+
+	return backend_init(compositor, config);
+}
+
+
+static int
+load_headless_backend(struct weston_compositor *c, char const * backend,
+		 int *argc, char **argv, struct weston_config *wc)
+{
+	int ret = 0;
+	int width = 1024, height = 640;
+	char *display_name = NULL;
+	struct weston_headless_backend_config * config = NULL;
+	const char *transform = "normal";
+	struct headless_backend *b;
+
+	config = weston_headless_backend_config_create();
+
+	const struct weston_option headless_options[] = {
+		{ WESTON_OPTION_INTEGER, "width", 0, &width },
+		{ WESTON_OPTION_INTEGER, "height", 0, &height },
+		{ WESTON_OPTION_BOOLEAN, "use-pixman", 0, &config->use_pixman },
+		{ WESTON_OPTION_STRING, "transform", 0, &transform },
+	};
+
+	parse_options(headless_options,
+		      ARRAY_LENGTH(headless_options), argc, argv);
+
+	config->width = width;
+	config->height = height;
+
+	if (weston_parse_transform(transform, &config->transform) < 0)
+		weston_log("Invalid transform \"%s\"\n", transform);
+
+	/* load the actual wayland backend and configure it */
+	if (weston_headless_backend_load(c, config) < 0) {
+		ret = -1;
+	}
+
+	return ret;
+
+}
+
 static int
 load_backend(struct weston_compositor *compositor, const char *backend,
 	     int *argc, char **argv, struct weston_config *config)
 {
+	if (strstr(backend, "headless-backend.so"))
+		return load_headless_backend(compositor, backend, argc, argv, config);
 #if 0
-	if (strstr(backend, "drm-backend.so"))
+	else if (strstr(backend, "drm-backend.so"))
 		return load_drm_backend(compositor, backend, argc, argv, config);
 	else if (strstr(backend, "wayland-backend.so"))
 		return load_wayland_backend(compositor, backend, argc, argv, config);
-- 
2.4.10



More information about the wayland-devel mailing list