[PATCH weston] Add a headless backend
Ander Conselvan de Oliveira
ander.conselvan.de.oliveira at intel.com
Mon Oct 29 09:19:24 PDT 2012
Add a headless backend and a noop renderer, mainly for testing
purposes. Although no rendering is performed with this backend,
this allow some of the code paths inside Weston and shm clients
to be tested without any windowing system or any need for drm
access.
---
configure.ac | 6 ++
src/Makefile.am | 15 +++-
src/compositor-headless.c | 203 +++++++++++++++++++++++++++++++++++++++++++++
src/compositor.h | 5 ++
src/noop-renderer.c | 74 +++++++++++++++++
5 files changed, 302 insertions(+), 1 deletion(-)
create mode 100644 src/compositor-headless.c
create mode 100644 src/noop-renderer.c
diff --git a/configure.ac b/configure.ac
index 0f34a7e..f6cc44a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -109,6 +109,12 @@ if test x$enable_wayland_compositor = xyes; then
fi
+AC_ARG_ENABLE(headless-compositor, [ --enable-headless-compositor],,
+ enable_headless_compositor=yes)
+AM_CONDITIONAL(ENABLE_HEADLESS_COMPOSITOR,
+ test x$enable_headless_compositor = xyes)
+
+
AC_ARG_ENABLE(android-compositor,
AS_HELP_STRING([--disable-android-compositor],
[do not build-test the Android 4.0 backend]),,
diff --git a/src/Makefile.am b/src/Makefile.am
index acc2415..b2c404e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -35,6 +35,7 @@ weston_SOURCES = \
matrix.c \
matrix.h \
gles2-renderer.c \
+ null-renderer.c \
weston-launch.h \
weston-egl-ext.h
@@ -74,7 +75,8 @@ module_LTLIBRARIES = \
$(tablet_shell) \
$(x11_backend) \
$(drm_backend) \
- $(wayland_backend)
+ $(wayland_backend) \
+ $(headless_backend)
# Do not install, since the binary produced via autotools is unusable.
# The real backend is built by the Android build system.
@@ -143,6 +145,17 @@ android_backend_la_SOURCES = \
android-framebuffer.h
endif
+if ENABLE_HEADLESS_COMPOSITOR
+headless_backend = headless-backend.la
+headless_backend_la_LDFLAGS = -module -avoid-version
+headless_backend_la_LIBADD = $(COMPOSITOR_LIBS) \
+ ../shared/libshared.la
+headless_backend_la_CFLAGS = \
+ $(COMPOSITOR_CFLAGS) \
+ $(GCC_CFLAGS)
+headless_backend_la_SOURCES = compositor-headless.c
+endif
+
if ENABLE_DESKTOP_SHELL
desktop_shell = desktop-shell.la
desktop_shell_la_LDFLAGS = -module -avoid-version
diff --git a/src/compositor-headless.c b/src/compositor-headless.c
new file mode 100644
index 0000000..55206b3
--- /dev/null
+++ b/src/compositor-headless.c
@@ -0,0 +1,203 @@
+/*
+ * Copyright © 2010-2011 Benjamin Franzke
+ * Copyright © 2012 Intel Corporation
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of the copyright holders not be used in
+ * advertising or publicity pertaining to distribution of the software
+ * without specific, written prior permission. The copyright holders make
+ * no representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include <sys/time.h>
+
+#include "compositor.h"
+
+struct headless_compositor {
+ struct weston_compositor base;
+ struct weston_seat fake_seat;
+};
+
+struct headless_output {
+ struct weston_output base;
+ struct weston_mode mode;
+ struct wl_event_source *finish_frame_timer;
+};
+
+
+static int
+finish_frame_handler(void *data)
+{
+ struct weston_output *output = data;
+ uint32_t msec;
+ struct timeval tv;
+
+ gettimeofday(&tv, NULL);
+ msec = tv.tv_sec * 1000 + tv.tv_usec / 1000;
+ weston_output_finish_frame(output, msec);
+
+ return 1;
+}
+
+static void
+headless_output_repaint(struct weston_output *output_base,
+ pixman_region32_t *damage)
+{
+ struct headless_output *output = (struct headless_output *) output_base;
+ struct weston_compositor *ec = output->base.compositor;
+
+ ec->renderer->repaint_output(&output->base, damage);
+
+ wl_event_source_timer_update(output->finish_frame_timer, 16);
+
+ return;
+}
+
+static void
+headless_output_destroy(struct weston_output *output_base)
+{
+ struct headless_output *output = (struct headless_output *) output_base;
+
+ wl_event_source_remove(output->finish_frame_timer);
+ free(output);
+
+ return;
+}
+
+static int
+headless_compositor_create_output(struct headless_compositor *c,
+ int width, int height)
+{
+ struct headless_output *output;
+ struct wl_event_loop *loop;
+
+ output = malloc(sizeof *output);
+ if (output == NULL)
+ return -1;
+ memset(output, 0, sizeof *output);
+
+ output->mode.flags =
+ WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED;
+ output->mode.width = width;
+ output->mode.height = height;
+ output->mode.refresh = 60;
+ wl_list_init(&output->base.mode_list);
+ wl_list_insert(&output->base.mode_list, &output->mode.link);
+
+ output->base.current = &output->mode;
+ weston_output_init(&output->base, &c->base, 0, 0, width, height,
+ WL_OUTPUT_TRANSFORM_NORMAL);
+
+ output->base.make = "weston";
+ output->base.model = "headless";
+
+ weston_output_move(&output->base, 0, 0);
+
+ loop = wl_display_get_event_loop(c->base.wl_display);
+ output->finish_frame_timer =
+ wl_event_loop_add_timer(loop, finish_frame_handler, output);
+
+ output->base.origin = output->base.current;
+ output->base.repaint = headless_output_repaint;
+ output->base.destroy = headless_output_destroy;
+ output->base.assign_planes = NULL;
+ output->base.set_backlight = NULL;
+ output->base.set_dpms = NULL;
+ output->base.switch_mode = NULL;
+
+ wl_list_insert(c->base.output_list.prev, &output->base.link);
+
+ return 0;
+}
+
+static void
+headless_restore(struct weston_compositor *ec)
+{
+}
+
+static void
+headless_destroy(struct weston_compositor *ec)
+{
+ struct headless_compositor *c = (struct headless_compositor *) ec;
+
+ noop_renderer_destroy(ec);
+
+ weston_seat_release(&c->fake_seat);
+ weston_compositor_shutdown(ec);
+
+ free(ec);
+}
+
+static struct weston_compositor *
+headless_compositor_create(struct wl_display *display,
+ int width, int height, const char *display_name,
+ int argc, char *argv[], const char *config_file)
+{
+ struct headless_compositor *c;
+
+ c = calloc(1, sizeof *c);
+ if (c == NULL)
+ return NULL;
+
+ memset(c, 0, sizeof *c);
+
+ if (weston_compositor_init(&c->base, display, argc, argv,
+ config_file) < 0)
+ goto err_free;
+
+ weston_seat_init(&c->fake_seat, &c->base);
+
+ c->base.destroy = headless_destroy;
+ c->base.restore = headless_restore;
+
+ if (headless_compositor_create_output(c, width, height) < 0)
+ goto err_compositor;
+
+ if (noop_renderer_init(&c->base) < 0)
+ goto err_compositor;
+
+ return &c->base;
+
+err_compositor:
+ weston_compositor_shutdown(&c->base);
+err_free:
+ free(c);
+ return NULL;
+}
+
+WL_EXPORT struct weston_compositor *
+backend_init(struct wl_display *display, int argc, char *argv[],
+ const char *config_file)
+{
+ int width = 1024, height = 640;
+ char *display_name = NULL;
+
+ const struct weston_option headless_options[] = {
+ { WESTON_OPTION_INTEGER, "width", 0, &width },
+ { WESTON_OPTION_INTEGER, "height", 0, &height },
+ };
+
+ parse_options(headless_options,
+ ARRAY_LENGTH(headless_options), argc, argv);
+
+ return headless_compositor_create(display, width, height, display_name,
+ argc, argv, config_file);
+}
diff --git a/src/compositor.h b/src/compositor.h
index 3176bfd..3369e56 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -827,6 +827,11 @@ gles2_renderer_init(struct weston_compositor *ec);
void
gles2_renderer_destroy(struct weston_compositor *ec);
+int
+noop_renderer_init(struct weston_compositor *ec);
+void
+noop_renderer_destroy(struct weston_compositor *ec);
+
struct weston_compositor *
backend_init(struct wl_display *display, int argc, char *argv[],
const char *config_file);
diff --git a/src/noop-renderer.c b/src/noop-renderer.c
new file mode 100644
index 0000000..116fc00
--- /dev/null
+++ b/src/noop-renderer.c
@@ -0,0 +1,74 @@
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of the copyright holders not be used in
+ * advertising or publicity pertaining to distribution of the software
+ * without specific, written prior permission. The copyright holders make
+ * no representations about the suitability of this software for any
+ * purpose. It is provided "as is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#define _GNU_SOURCE
+
+#include <stdlib.h>
+
+#include "compositor.h"
+
+static void
+noop_renderer_repaint_output(struct weston_output *output,
+ pixman_region32_t *output_damage)
+{
+}
+
+static void
+noop_renderer_flush_damage(struct weston_surface *surface)
+{
+}
+
+static void
+noop_renderer_attach(struct weston_surface *es, struct wl_buffer *buffer)
+{
+}
+
+static void
+noop_renderer_destroy_surface(struct weston_surface *surface)
+{
+}
+
+WL_EXPORT void
+noop_renderer_destroy(struct weston_compositor *ec)
+{
+ free(ec->renderer);
+ ec->renderer = NULL;
+}
+
+WL_EXPORT int
+noop_renderer_init(struct weston_compositor *ec)
+{
+ struct weston_renderer *renderer;
+ struct weston_output *output;
+
+ renderer = malloc(sizeof *renderer);
+ if (renderer == NULL)
+ return -1;
+
+ renderer->repaint_output = noop_renderer_repaint_output;
+ renderer->flush_damage = noop_renderer_flush_damage;
+ renderer->attach = noop_renderer_attach;
+ renderer->destroy_surface = noop_renderer_destroy_surface;
+ ec->renderer = renderer;
+
+ return 0;
+}
--
1.7.10.4
More information about the wayland-devel
mailing list