2 * Copyright © 2010-2011 Benjamin Franzke
3 * Copyright © 2012 Intel Corporation
5 * Permission to use, copy, modify, distribute, and sell this software and
6 * its documentation for any purpose is hereby granted without fee, provided
7 * that the above copyright notice appear in all copies and that both that
8 * copyright notice and this permission notice appear in supporting
9 * documentation, and that the name of the copyright holders not be used in
10 * advertising or publicity pertaining to distribution of the software
11 * without specific, written prior permission. The copyright holders make
12 * no representations about the suitability of this software for any
13 * purpose. It is provided "as is" without express or implied warranty.
15 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
16 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
18 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
19 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
20 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
30 #include "compositor.h"
32 struct headless_compositor {
33 struct weston_compositor base;
34 struct weston_seat fake_seat;
37 struct headless_output {
38 struct weston_output base;
39 struct weston_mode mode;
40 struct wl_event_source *finish_frame_timer;
45 headless_output_start_repaint_loop(struct weston_output *output)
50 gettimeofday(&tv, NULL);
51 msec = tv.tv_sec * 1000 + tv.tv_usec / 1000;
52 weston_output_finish_frame(output, msec);
56 finish_frame_handler(void *data)
58 headless_output_start_repaint_loop(data);
64 headless_output_repaint(struct weston_output *output_base,
65 pixman_region32_t *damage)
67 struct headless_output *output = (struct headless_output *) output_base;
68 struct weston_compositor *ec = output->base.compositor;
70 ec->renderer->repaint_output(&output->base, damage);
72 pixman_region32_subtract(&ec->primary_plane.damage,
73 &ec->primary_plane.damage, damage);
75 wl_event_source_timer_update(output->finish_frame_timer, 16);
81 headless_output_destroy(struct weston_output *output_base)
83 struct headless_output *output = (struct headless_output *) output_base;
85 wl_event_source_remove(output->finish_frame_timer);
92 headless_compositor_create_output(struct headless_compositor *c,
93 int width, int height)
95 struct headless_output *output;
96 struct wl_event_loop *loop;
98 output = zalloc(sizeof *output);
103 WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED;
104 output->mode.width = width;
105 output->mode.height = height;
106 output->mode.refresh = 60;
107 wl_list_init(&output->base.mode_list);
108 wl_list_insert(&output->base.mode_list, &output->mode.link);
110 output->base.current_mode = &output->mode;
111 weston_output_init(&output->base, &c->base, 0, 0, width, height,
112 WL_OUTPUT_TRANSFORM_NORMAL, 1);
114 output->base.make = "weston";
115 output->base.model = "headless";
117 loop = wl_display_get_event_loop(c->base.wl_display);
118 output->finish_frame_timer =
119 wl_event_loop_add_timer(loop, finish_frame_handler, output);
121 output->base.start_repaint_loop = headless_output_start_repaint_loop;
122 output->base.repaint = headless_output_repaint;
123 output->base.destroy = headless_output_destroy;
124 output->base.assign_planes = NULL;
125 output->base.set_backlight = NULL;
126 output->base.set_dpms = NULL;
127 output->base.switch_mode = NULL;
129 wl_list_insert(c->base.output_list.prev, &output->base.link);
135 headless_input_create(struct headless_compositor *c)
137 weston_seat_init(&c->fake_seat, &c->base, "default");
139 weston_seat_init_pointer(&c->fake_seat);
141 if (weston_seat_init_keyboard(&c->fake_seat, NULL) < 0)
148 headless_input_destroy(struct headless_compositor *c)
150 weston_seat_release(&c->fake_seat);
154 headless_restore(struct weston_compositor *ec)
159 headless_destroy(struct weston_compositor *ec)
161 struct headless_compositor *c = (struct headless_compositor *) ec;
163 headless_input_destroy(c);
164 weston_compositor_shutdown(ec);
169 static struct weston_compositor *
170 headless_compositor_create(struct wl_display *display,
171 int width, int height, const char *display_name,
172 int *argc, char *argv[],
173 struct weston_config *config)
175 struct headless_compositor *c;
177 c = zalloc(sizeof *c);
181 if (weston_compositor_init(&c->base, display, argc, argv, config) < 0)
184 if (headless_input_create(c) < 0)
187 c->base.destroy = headless_destroy;
188 c->base.restore = headless_restore;
190 if (headless_compositor_create_output(c, width, height) < 0)
193 if (noop_renderer_init(&c->base) < 0)
199 headless_input_destroy(c);
201 weston_compositor_shutdown(&c->base);
207 WL_EXPORT struct weston_compositor *
208 backend_init(struct wl_display *display, int *argc, char *argv[],
209 struct weston_config *config)
211 int width = 1024, height = 640;
212 char *display_name = NULL;
214 const struct weston_option headless_options[] = {
215 { WESTON_OPTION_INTEGER, "width", 0, &width },
216 { WESTON_OPTION_INTEGER, "height", 0, &height },
219 parse_options(headless_options,
220 ARRAY_LENGTH(headless_options), argc, argv);
222 return headless_compositor_create(display, width, height, display_name,