[PATCH weston v0] refactor configuration API of headless-backend
Benoit Gschwind
gschwind at gnu-log.net
Sun Feb 28 12:51:10 UTC 2016
Here is my proposal for headless backend.
Best regards
---
Makefile.am | 1 +
src/compositor-headless.c | 42 +++++++-----------------------
src/main.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 74 insertions(+), 34 deletions(-)
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, ¶m.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, ¶m.transform) < 0)
- weston_log("Invalid transform \"%s\"\n", transform);
+ /* TODO: do better thing */
+ free(config);
- b = headless_backend_create(compositor, ¶m, display_name);
if (b == NULL)
return -1;
return 0;
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