summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Gschwind <gschwind@gnu-log.net>2016-04-15 20:28:32 -0700
committerPekka Paalanen <pekka.paalanen@collabora.co.uk>2016-04-18 14:44:39 +0300
commit3c53094e2413050617dcae400d117449a800c50e (patch)
treee53141afcbe07c0222272c608acf40c7adcaf6c8
parent98ab08bef865e061faaf9adb65aa214292f6d69c (diff)
headless: port the headless backend to the new init api
refactor configuration API of headless-backend Signed-off-by: Bryce Harrington <bryce@osg.samsung.com> Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk> v6: - Define version number in the header - Don't use leading underscores in header guards - Add stub config_init_to_defaults() - Allocate config on stack - Drop unused display_name parameter - Add error message when config is invalid - Install compositor-headless.h and list it in headless-backend sources v5: - Update to current trunk - Fixed typo 'struct weston_wayland_backend_config' - Dropped unused variables - Dropped weston_headless_backend_config_create() in favor of directly zalloc'ing the object - Dropped weston_headless_backend_load() in favor of the more generalized load_backend_new(). - Dropped typedef from header - Restored use of 'backend_init' entry point - Backend_init() takes a base weston_backend_config object - Renamed 'param' to 'config' in a few places for consistency - Renamed 'headless_options' variable to 'options for consistency - Version the base struct - Free config on error - Don't free config during backend_init normal operations - Adjust header ordering - Make header guard naming consistent with other headers - Light reformatting for code style and consistency with other backend config patches Signed-off-by: Bryce Harrington <bryce@osg.samsung.com> Reviewed-by: Giulio Camuffo <giuliocamuffo@gmail.com> [Pekka: rebased to apply before drm and x11 backends] [Pekka: squashed in the headless part of "Enforce destruction of all backend config objects after initialization"] Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
-rw-r--r--Makefile.am3
-rw-r--r--src/compositor-headless.c74
-rw-r--r--src/compositor-headless.h53
-rw-r--r--src/main.c40
4 files changed, 126 insertions, 44 deletions
diff --git a/Makefile.am b/Makefile.am
index 9bed32c7..d3c3f71e 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 \
@@ -208,6 +209,7 @@ westonincludedir = $(includedir)/weston
westoninclude_HEADERS = \
src/version.h \
src/compositor.h \
+ src/compositor-headless.h \
src/timeline-object.h \
shared/matrix.h \
shared/config-parser.h \
@@ -353,6 +355,7 @@ headless_backend_la_LIBADD = $(COMPOSITOR_LIBS) libshared.la
headless_backend_la_CFLAGS = $(COMPOSITOR_CFLAGS) $(AM_CFLAGS)
headless_backend_la_SOURCES = \
src/compositor-headless.c \
+ src/compositor-headless.h \
shared/helpers.h
endif
diff --git a/src/compositor-headless.c b/src/compositor-headless.c
index 16b5c39d..ed6c48c4 100644
--- a/src/compositor-headless.c
+++ b/src/compositor-headless.c
@@ -31,33 +31,29 @@
#include <sys/time.h>
#include <stdbool.h>
-#include "shared/helpers.h"
#include "compositor.h"
+#include "compositor-headless.h"
+#include "shared/helpers.h"
#include "pixman-renderer.h"
#include "presentation-time-server-protocol.h"
struct headless_backend {
struct weston_backend base;
struct weston_compositor *compositor;
+
struct weston_seat fake_seat;
bool use_pixman;
};
struct headless_output {
struct weston_output base;
+
struct weston_mode mode;
struct wl_event_source *finish_frame_timer;
uint32_t *image_buf;
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 +116,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 *config)
{
struct weston_compositor *c = b->compositor;
struct headless_output *output;
@@ -132,15 +128,15 @@ headless_backend_create_output(struct headless_backend *b,
output->mode.flags =
WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED;
- output->mode.width = param->width;
- output->mode.height = param->height;
+ output->mode.width = config->width;
+ output->mode.height = config->height;
output->mode.refresh = 60000;
wl_list_init(&output->base.mode_list);
wl_list_insert(&output->base.mode_list, &output->mode.link);
output->base.current_mode = &output->mode;
- weston_output_init(&output->base, c, 0, 0, param->width,
- param->height, param->transform, 1);
+ weston_output_init(&output->base, c, 0, 0, config->width,
+ config->height, config->transform, 1);
output->base.make = "weston";
output->base.model = "headless";
@@ -158,15 +154,15 @@ headless_backend_create_output(struct headless_backend *b,
output->base.switch_mode = NULL;
if (b->use_pixman) {
- output->image_buf = malloc(param->width * param->height * 4);
+ output->image_buf = malloc(config->width * config->height * 4);
if (!output->image_buf)
return -1;
output->image = pixman_image_create_bits(PIXMAN_x8r8g8b8,
- param->width,
- param->height,
+ config->width,
+ config->height,
output->image_buf,
- param->width * 4);
+ config->width * 4);
if (pixman_renderer_output_create(&output->base) < 0)
return -1;
@@ -217,8 +213,7 @@ headless_destroy(struct weston_compositor *ec)
static struct headless_backend *
headless_backend_create(struct weston_compositor *compositor,
- struct headless_parameters *param,
- const char *display_name)
+ struct weston_headless_backend_config *config)
{
struct headless_backend *b;
@@ -236,11 +231,11 @@ headless_backend_create(struct weston_compositor *compositor,
b->base.destroy = headless_destroy;
b->base.restore = headless_restore;
- b->use_pixman = param->use_pixman;
+ b->use_pixman = config->use_pixman;
if (b->use_pixman) {
pixman_renderer_init(compositor);
}
- if (headless_backend_create_output(b, param) < 0)
+ if (headless_backend_create_output(b, config) < 0)
goto err_input;
if (!b->use_pixman && noop_renderer_init(compositor) < 0)
@@ -257,36 +252,33 @@ err_free:
return NULL;
}
+static void
+config_init_to_defaults(struct weston_headless_backend_config *config)
+{
+}
+
WL_EXPORT int
backend_init(struct weston_compositor *compositor,
int *argc, char *argv[],
- struct weston_config *config,
+ struct weston_config *wc,
struct weston_backend_config *config_base)
{
- int width = 1024, height = 640;
- char *display_name = NULL;
- struct headless_parameters param = { 0, };
- const char *transform = "normal";
struct headless_backend *b;
+ struct weston_headless_backend_config config = {{ 0, }};
- 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;
+ if (config_base == NULL ||
+ config_base->struct_version != WESTON_HEADLESS_BACKEND_CONFIG_VERSION ||
+ config_base->struct_size > sizeof(struct weston_headless_backend_config)) {
+ weston_log("headless backend config structure is invalid\n");
+ return -1;
+ }
- if (weston_parse_transform(transform, &param.transform) < 0)
- weston_log("Invalid transform \"%s\"\n", transform);
+ config_init_to_defaults(&config);
+ memcpy(&config, config_base, config_base->struct_size);
- b = headless_backend_create(compositor, &param, display_name);
+ b = headless_backend_create(compositor, &config);
if (b == NULL)
return -1;
+
return 0;
}
diff --git a/src/compositor-headless.h b/src/compositor-headless.h
new file mode 100644
index 00000000..79f39c89
--- /dev/null
+++ b/src/compositor-headless.h
@@ -0,0 +1,53 @@
+/*
+ * 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 WESTON_COMPOSITOR_HEADLESS_H
+#define WESTON_COMPOSITOR_HEADLESS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "compositor.h"
+
+#define WESTON_HEADLESS_BACKEND_CONFIG_VERSION 1
+
+struct weston_headless_backend_config {
+ struct weston_backend_config base;
+
+ int width;
+ int height;
+
+ /** Whether to use the pixman renderer instead of the OpenGL ES renderer. */
+ int use_pixman;
+
+ uint32_t transform;
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* WESTON_COMPOSITOR_HEADLESS_H */
diff --git a/src/main.c b/src/main.c
index 6a708e37..fc97dd80 100644
--- a/src/main.c
+++ b/src/main.c
@@ -47,6 +47,8 @@
#include "git-version.h"
#include "version.h"
+#include "compositor-headless.h"
+
static struct wl_list child_process_list;
static struct weston_compositor *segv_compositor;
@@ -684,11 +686,45 @@ load_backend_new(struct weston_compositor *compositor, const char *backend,
}
static int
+load_headless_backend(struct weston_compositor *c, char const * backend,
+ int *argc, char **argv, struct weston_config *wc)
+{
+ struct weston_headless_backend_config config = {{ 0, }};
+ int ret = 0;
+ const char *transform = "normal";
+
+ config.width = 1024;
+ config.height = 640;
+
+ const struct weston_option options[] = {
+ { WESTON_OPTION_INTEGER, "width", 0, &config.width },
+ { WESTON_OPTION_INTEGER, "height", 0, &config.height },
+ { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &config.use_pixman },
+ { WESTON_OPTION_STRING, "transform", 0, &transform },
+ };
+
+ parse_options(options, ARRAY_LENGTH(options), argc, argv);
+
+ if (weston_parse_transform(transform, &config.transform) < 0)
+ weston_log("Invalid transform \"%s\"\n", transform);
+
+ config.base.struct_version = WESTON_HEADLESS_BACKEND_CONFIG_VERSION;
+ config.base.struct_size = sizeof(struct weston_headless_backend_config);
+
+ /* load the actual wayland backend and configure it */
+ ret = load_backend_new(c, backend, &config.base);
+
+ 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);
@@ -696,8 +732,6 @@ load_backend(struct weston_compositor *compositor, const char *backend,
return load_x11_backend(compositor, backend, argc, argv, config);
else if (strstr(backend, "fbdev-backend.so"))
return load_fbdev_backend(compositor, backend, argc, argv, config);
- else if (strstr(backend, "headless-backend.so"))
- return load_headless_backend(compositor, backend, argc, argv, config);
else if (strstr(backend, "rpi-backend.so"))
return load_rpi_backend(compositor, backend, argc, argv, config);
else if (strstr(backend, "rdp-backend.so"))