[PATCH weston v6 07/12] headless: port the headless backend to the new init api
Giulio Camuffo
giuliocamuffo at gmail.com
Sun Apr 17 14:14:17 UTC 2016
Reviewed-by: Giulio Camuffo <giuliocamuffo at gmail.com>
2016-04-16 6:28 GMT+03:00 Bryce Harrington <bryce at osg.samsung.com>:
> From: Benoit Gschwind <gschwind at gnu-log.net>
>
> refactor configuration API of headless-backend
>
> Signed-off-by: Bryce Harrington <bryce at osg.samsung.com>
> Reviewed-by: Pekka Paalanen <pekka.paalanen at 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 at osg.samsung.com>
> ---
> Makefile.am | 3 ++
> src/compositor-headless.c | 74 +++++++++++++++++++++--------------------------
> src/compositor-headless.h | 53 +++++++++++++++++++++++++++++++++
> src/main.c | 45 ++++++++++++++++++++++++++--
> 4 files changed, 132 insertions(+), 43 deletions(-)
> create mode 100644 src/compositor-headless.h
>
> diff --git a/Makefile.am b/Makefile.am
> index dfa11ab..b33d289 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -73,6 +73,7 @@ weston_SOURCES = \
> src/compositor.c \
> src/compositor.h \
> src/compositor-drm.h \
> + src/compositor-headless.h \
> src/compositor-x11.h \
> src/input.c \
> src/data-device.c \
> @@ -211,6 +212,7 @@ westoninclude_HEADERS = \
> src/version.h \
> src/compositor.h \
> src/compositor-drm.h \
> + src/compositor-headless.h \
> src/compositor-x11.h \
> src/timeline-object.h \
> shared/matrix.h \
> @@ -359,6 +361,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 16b5c39..ed6c48c 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, ¶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;
> + 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, ¶m.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, ¶m, 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 0000000..79f39c8
> --- /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 26ae143..feb967d 100644
> --- a/src/main.c
> +++ b/src/main.c
> @@ -48,6 +48,7 @@
> #include "version.h"
>
> #include "compositor-drm.h"
> +#include "compositor-headless.h"
> #include "compositor-x11.h"
>
> static struct wl_list child_process_list;
> @@ -766,6 +767,46 @@ load_drm_backend(struct weston_compositor *c, 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;
> + int ret = 0;
> + const char *transform = "normal";
> +
> + config = zalloc(sizeof(struct weston_headless_backend_config));
> + if (config == NULL)
> + return -1;
> +
> + 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 */
> + if (load_backend_new(c, backend,
> + (struct weston_backend_config *)config) < 0) {
> + ret = -1;
> + free(config);
> + }
> +
> + return ret;
> +}
> +
> +static int
> weston_x11_backend_config_append_output_config(struct weston_x11_backend_config *config,
> struct weston_x11_backend_output_config *output_config) {
> struct weston_x11_backend_output_config *new_outputs;
> @@ -912,6 +953,8 @@ load_backend(struct weston_compositor *compositor, const char *backend,
> {
> if (strstr(backend, "drm-backend.so"))
> return load_drm_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, "x11-backend.so"))
> return load_x11_backend(compositor, backend, argc, argv, config);
> #if 0
> @@ -919,8 +962,6 @@ load_backend(struct weston_compositor *compositor, const char *backend,
> return load_wayland_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"))
> --
> 1.9.1
>
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/wayland-devel
More information about the wayland-devel
mailing list