Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2010-2011 Benjamin Franzke |
| 3 | * Copyright © 2012 Intel Corporation |
| 4 | * |
Bryce Harrington | a0bbfea | 2015-06-11 15:35:43 -0700 | [diff] [blame] | 5 | * Permission is hereby granted, free of charge, to any person obtaining |
| 6 | * a copy of this software and associated documentation files (the |
| 7 | * "Software"), to deal in the Software without restriction, including |
| 8 | * without limitation the rights to use, copy, modify, merge, publish, |
| 9 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 10 | * permit persons to whom the Software is furnished to do so, subject to |
| 11 | * the following conditions: |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 12 | * |
Bryce Harrington | a0bbfea | 2015-06-11 15:35:43 -0700 | [diff] [blame] | 13 | * The above copyright notice and this permission notice (including the |
| 14 | * next paragraph) shall be included in all copies or substantial |
| 15 | * portions of the Software. |
| 16 | * |
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 21 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 22 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 24 | * SOFTWARE. |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 25 | */ |
| 26 | |
Daniel Stone | c228e23 | 2013-05-22 18:03:19 +0300 | [diff] [blame] | 27 | #include "config.h" |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 28 | |
Armin Krezović | 7fb1775 | 2016-09-30 14:11:07 +0200 | [diff] [blame] | 29 | #include <assert.h> |
Jussi Kukkonen | 649bbce | 2016-07-19 14:16:27 +0300 | [diff] [blame] | 30 | #include <stdint.h> |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 31 | #include <stdlib.h> |
| 32 | #include <string.h> |
| 33 | #include <sys/time.h> |
Derek Foreman | a04e913 | 2014-11-19 15:06:17 -0800 | [diff] [blame] | 34 | #include <stdbool.h> |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 35 | |
| 36 | #include "compositor.h" |
Benoit Gschwind | 3c53094 | 2016-04-15 20:28:32 -0700 | [diff] [blame] | 37 | #include "compositor-headless.h" |
| 38 | #include "shared/helpers.h" |
Derek Foreman | a04e913 | 2014-11-19 15:06:17 -0800 | [diff] [blame] | 39 | #include "pixman-renderer.h" |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 40 | #include "presentation-time-server-protocol.h" |
Armin Krezović | 7fb1775 | 2016-09-30 14:11:07 +0200 | [diff] [blame] | 41 | #include "windowed-output-api.h" |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 42 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 43 | struct headless_backend { |
| 44 | struct weston_backend base; |
| 45 | struct weston_compositor *compositor; |
Benoit Gschwind | 3c53094 | 2016-04-15 20:28:32 -0700 | [diff] [blame] | 46 | |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 47 | struct weston_seat fake_seat; |
Derek Foreman | a04e913 | 2014-11-19 15:06:17 -0800 | [diff] [blame] | 48 | bool use_pixman; |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | struct headless_output { |
| 52 | struct weston_output base; |
Benoit Gschwind | 3c53094 | 2016-04-15 20:28:32 -0700 | [diff] [blame] | 53 | |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 54 | struct weston_mode mode; |
| 55 | struct wl_event_source *finish_frame_timer; |
Derek Foreman | a04e913 | 2014-11-19 15:06:17 -0800 | [diff] [blame] | 56 | uint32_t *image_buf; |
| 57 | pixman_image_t *image; |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 58 | }; |
| 59 | |
Armin Krezović | a8fb5ea | 2016-08-01 19:17:55 +0200 | [diff] [blame] | 60 | static inline struct headless_output * |
| 61 | to_headless_output(struct weston_output *base) |
| 62 | { |
| 63 | return container_of(base, struct headless_output, base); |
| 64 | } |
| 65 | |
| 66 | static inline struct headless_backend * |
| 67 | to_headless_backend(struct weston_compositor *base) |
| 68 | { |
| 69 | return container_of(base->backend, struct headless_backend, base); |
| 70 | } |
| 71 | |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 72 | static void |
| 73 | headless_output_start_repaint_loop(struct weston_output *output) |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 74 | { |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 75 | struct timespec ts; |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 76 | |
Pekka Paalanen | 662f384 | 2015-03-18 12:17:26 +0200 | [diff] [blame] | 77 | weston_compositor_read_presentation_clock(output->compositor, &ts); |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 78 | weston_output_finish_frame(output, &ts, WP_PRESENTATION_FEEDBACK_INVALID); |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | static int |
| 82 | finish_frame_handler(void *data) |
| 83 | { |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 84 | struct headless_output *output = data; |
| 85 | struct timespec ts; |
| 86 | |
Pekka Paalanen | 662f384 | 2015-03-18 12:17:26 +0200 | [diff] [blame] | 87 | weston_compositor_read_presentation_clock(output->base.compositor, &ts); |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 88 | weston_output_finish_frame(&output->base, &ts, 0); |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 89 | |
| 90 | return 1; |
| 91 | } |
| 92 | |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 93 | static int |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 94 | headless_output_repaint(struct weston_output *output_base, |
| 95 | pixman_region32_t *damage) |
| 96 | { |
Armin Krezović | a8fb5ea | 2016-08-01 19:17:55 +0200 | [diff] [blame] | 97 | struct headless_output *output = to_headless_output(output_base); |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 98 | struct weston_compositor *ec = output->base.compositor; |
| 99 | |
| 100 | ec->renderer->repaint_output(&output->base, damage); |
| 101 | |
Ander Conselvan de Oliveira | 0a88772 | 2012-11-22 15:57:00 +0200 | [diff] [blame] | 102 | pixman_region32_subtract(&ec->primary_plane.damage, |
| 103 | &ec->primary_plane.damage, damage); |
| 104 | |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 105 | wl_event_source_timer_update(output->finish_frame_timer, 16); |
| 106 | |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 107 | return 0; |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 108 | } |
| 109 | |
Armin Krezović | 7fb1775 | 2016-09-30 14:11:07 +0200 | [diff] [blame] | 110 | static int |
| 111 | headless_output_disable(struct weston_output *base) |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 112 | { |
Armin Krezović | 7fb1775 | 2016-09-30 14:11:07 +0200 | [diff] [blame] | 113 | struct headless_output *output = to_headless_output(base); |
| 114 | struct headless_backend *b = to_headless_backend(base->compositor); |
| 115 | |
| 116 | if (!output->base.enabled) |
| 117 | return 0; |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 118 | |
| 119 | wl_event_source_remove(output->finish_frame_timer); |
Derek Foreman | a04e913 | 2014-11-19 15:06:17 -0800 | [diff] [blame] | 120 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 121 | if (b->use_pixman) { |
Derek Foreman | a04e913 | 2014-11-19 15:06:17 -0800 | [diff] [blame] | 122 | pixman_renderer_output_destroy(&output->base); |
| 123 | pixman_image_unref(output->image); |
| 124 | free(output->image_buf); |
| 125 | } |
| 126 | |
Armin Krezović | 7fb1775 | 2016-09-30 14:11:07 +0200 | [diff] [blame] | 127 | return 0; |
| 128 | } |
| 129 | |
| 130 | static void |
| 131 | headless_output_destroy(struct weston_output *base) |
| 132 | { |
| 133 | struct headless_output *output = to_headless_output(base); |
| 134 | |
| 135 | headless_output_disable(&output->base); |
Derek Foreman | a04e913 | 2014-11-19 15:06:17 -0800 | [diff] [blame] | 136 | weston_output_destroy(&output->base); |
| 137 | |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 138 | free(output); |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | static int |
Armin Krezović | 7fb1775 | 2016-09-30 14:11:07 +0200 | [diff] [blame] | 142 | headless_output_enable(struct weston_output *base) |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 143 | { |
Armin Krezović | 7fb1775 | 2016-09-30 14:11:07 +0200 | [diff] [blame] | 144 | struct headless_output *output = to_headless_output(base); |
| 145 | struct headless_backend *b = to_headless_backend(base->compositor); |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 146 | struct wl_event_loop *loop; |
| 147 | |
Armin Krezović | 7fb1775 | 2016-09-30 14:11:07 +0200 | [diff] [blame] | 148 | loop = wl_display_get_event_loop(b->compositor->wl_display); |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 149 | output->finish_frame_timer = |
| 150 | wl_event_loop_add_timer(loop, finish_frame_handler, output); |
| 151 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 152 | if (b->use_pixman) { |
Armin Krezović | 7fb1775 | 2016-09-30 14:11:07 +0200 | [diff] [blame] | 153 | output->image_buf = malloc(output->base.current_mode->width * |
| 154 | output->base.current_mode->height * 4); |
Derek Foreman | a04e913 | 2014-11-19 15:06:17 -0800 | [diff] [blame] | 155 | if (!output->image_buf) |
Armin Krezović | 7fb1775 | 2016-09-30 14:11:07 +0200 | [diff] [blame] | 156 | goto err_malloc; |
Derek Foreman | a04e913 | 2014-11-19 15:06:17 -0800 | [diff] [blame] | 157 | |
| 158 | output->image = pixman_image_create_bits(PIXMAN_x8r8g8b8, |
Armin Krezović | 7fb1775 | 2016-09-30 14:11:07 +0200 | [diff] [blame] | 159 | output->base.current_mode->width, |
| 160 | output->base.current_mode->height, |
Derek Foreman | a04e913 | 2014-11-19 15:06:17 -0800 | [diff] [blame] | 161 | output->image_buf, |
Armin Krezović | 7fb1775 | 2016-09-30 14:11:07 +0200 | [diff] [blame] | 162 | output->base.current_mode->width * 4); |
Derek Foreman | a04e913 | 2014-11-19 15:06:17 -0800 | [diff] [blame] | 163 | |
| 164 | if (pixman_renderer_output_create(&output->base) < 0) |
Armin Krezović | 7fb1775 | 2016-09-30 14:11:07 +0200 | [diff] [blame] | 165 | goto err_renderer; |
Derek Foreman | a04e913 | 2014-11-19 15:06:17 -0800 | [diff] [blame] | 166 | |
| 167 | pixman_renderer_output_set_buffer(&output->base, |
| 168 | output->image); |
| 169 | } |
| 170 | |
Armin Krezović | 7fb1775 | 2016-09-30 14:11:07 +0200 | [diff] [blame] | 171 | return 0; |
| 172 | |
| 173 | err_renderer: |
| 174 | pixman_image_unref(output->image); |
| 175 | free(output->image_buf); |
| 176 | err_malloc: |
| 177 | wl_event_source_remove(output->finish_frame_timer); |
| 178 | |
| 179 | return -1; |
| 180 | } |
| 181 | |
| 182 | static int |
| 183 | headless_output_set_size(struct weston_output *base, |
| 184 | int width, int height) |
| 185 | { |
| 186 | struct headless_output *output = to_headless_output(base); |
| 187 | int output_width, output_height; |
| 188 | |
| 189 | /* We can only be called once. */ |
| 190 | assert(!output->base.current_mode); |
| 191 | |
| 192 | /* Make sure we have scale set. */ |
| 193 | assert(output->base.scale); |
| 194 | |
| 195 | output_width = width * output->base.scale; |
| 196 | output_height = height * output->base.scale; |
| 197 | |
| 198 | output->mode.flags = |
| 199 | WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED; |
| 200 | output->mode.width = output_width; |
| 201 | output->mode.height = output_height; |
| 202 | output->mode.refresh = 60000; |
| 203 | wl_list_init(&output->base.mode_list); |
| 204 | wl_list_insert(&output->base.mode_list, &output->mode.link); |
| 205 | |
| 206 | output->base.current_mode = &output->mode; |
| 207 | output->base.make = "weston"; |
| 208 | output->base.model = "headless"; |
| 209 | |
| 210 | /* XXX: Calculate proper size. */ |
| 211 | output->base.mm_width = width; |
| 212 | output->base.mm_height = height; |
| 213 | |
| 214 | output->base.start_repaint_loop = headless_output_start_repaint_loop; |
| 215 | output->base.repaint = headless_output_repaint; |
| 216 | output->base.assign_planes = NULL; |
| 217 | output->base.set_backlight = NULL; |
| 218 | output->base.set_dpms = NULL; |
| 219 | output->base.switch_mode = NULL; |
| 220 | |
| 221 | return 0; |
| 222 | } |
| 223 | |
| 224 | static int |
| 225 | headless_output_create(struct weston_compositor *compositor, |
| 226 | const char *name) |
| 227 | { |
| 228 | struct headless_output *output; |
| 229 | |
| 230 | /* name can't be NULL. */ |
| 231 | assert(name); |
| 232 | |
| 233 | output = zalloc(sizeof *output); |
| 234 | if (output == NULL) |
| 235 | return -1; |
| 236 | |
| 237 | output->base.name = strdup(name); |
| 238 | output->base.destroy = headless_output_destroy; |
| 239 | output->base.disable = headless_output_disable; |
| 240 | output->base.enable = headless_output_enable; |
| 241 | |
Armin Krezović | 4008740 | 2016-09-30 14:11:12 +0200 | [diff] [blame] | 242 | weston_output_init(&output->base, compositor); |
Armin Krezović | 7fb1775 | 2016-09-30 14:11:07 +0200 | [diff] [blame] | 243 | weston_compositor_add_pending_output(&output->base, compositor); |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 244 | |
| 245 | return 0; |
| 246 | } |
| 247 | |
| 248 | static void |
| 249 | headless_restore(struct weston_compositor *ec) |
| 250 | { |
| 251 | } |
| 252 | |
| 253 | static void |
| 254 | headless_destroy(struct weston_compositor *ec) |
| 255 | { |
Armin Krezović | a8fb5ea | 2016-08-01 19:17:55 +0200 | [diff] [blame] | 256 | struct headless_backend *b = to_headless_backend(ec); |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 257 | |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 258 | weston_compositor_shutdown(ec); |
| 259 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 260 | free(b); |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 261 | } |
| 262 | |
Armin Krezović | 7fb1775 | 2016-09-30 14:11:07 +0200 | [diff] [blame] | 263 | static const struct weston_windowed_output_api api = { |
| 264 | headless_output_set_size, |
| 265 | headless_output_create, |
| 266 | }; |
| 267 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 268 | static struct headless_backend * |
| 269 | headless_backend_create(struct weston_compositor *compositor, |
Benoit Gschwind | 3c53094 | 2016-04-15 20:28:32 -0700 | [diff] [blame] | 270 | struct weston_headless_backend_config *config) |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 271 | { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 272 | struct headless_backend *b; |
Armin Krezović | 7fb1775 | 2016-09-30 14:11:07 +0200 | [diff] [blame] | 273 | int ret; |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 274 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 275 | b = zalloc(sizeof *b); |
| 276 | if (b == NULL) |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 277 | return NULL; |
| 278 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 279 | b->compositor = compositor; |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 280 | if (weston_compositor_set_presentation_clock_software(compositor) < 0) |
| 281 | goto err_free; |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 282 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 283 | b->base.destroy = headless_destroy; |
| 284 | b->base.restore = headless_restore; |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 285 | |
Benoit Gschwind | 3c53094 | 2016-04-15 20:28:32 -0700 | [diff] [blame] | 286 | b->use_pixman = config->use_pixman; |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 287 | if (b->use_pixman) { |
| 288 | pixman_renderer_init(compositor); |
Derek Foreman | a04e913 | 2014-11-19 15:06:17 -0800 | [diff] [blame] | 289 | } |
Armin Krezović | d84deeb | 2016-06-23 11:59:29 +0200 | [diff] [blame] | 290 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 291 | if (!b->use_pixman && noop_renderer_init(compositor) < 0) |
Emilio Pozuelo Monfort | dd9f6bc | 2014-02-07 09:34:43 +0100 | [diff] [blame] | 292 | goto err_input; |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 293 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 294 | compositor->backend = &b->base; |
Armin Krezović | 7fb1775 | 2016-09-30 14:11:07 +0200 | [diff] [blame] | 295 | |
| 296 | ret = weston_plugin_api_register(compositor, WESTON_WINDOWED_OUTPUT_API_NAME, |
| 297 | &api, sizeof(api)); |
| 298 | |
| 299 | if (ret < 0) { |
| 300 | weston_log("Failed to register output API.\n"); |
| 301 | goto err_input; |
| 302 | } |
| 303 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 304 | return b; |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 305 | |
Emilio Pozuelo Monfort | dd9f6bc | 2014-02-07 09:34:43 +0100 | [diff] [blame] | 306 | err_input: |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 307 | weston_compositor_shutdown(compositor); |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 308 | err_free: |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 309 | free(b); |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 310 | return NULL; |
| 311 | } |
| 312 | |
Benoit Gschwind | 3c53094 | 2016-04-15 20:28:32 -0700 | [diff] [blame] | 313 | static void |
| 314 | config_init_to_defaults(struct weston_headless_backend_config *config) |
| 315 | { |
| 316 | } |
| 317 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 318 | WL_EXPORT int |
Quentin Glidic | 23e1d6f | 2016-12-02 14:08:44 +0100 | [diff] [blame^] | 319 | weston_backend_init(struct weston_compositor *compositor, |
| 320 | struct weston_backend_config *config_base) |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 321 | { |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 322 | struct headless_backend *b; |
Benoit Gschwind | 3c53094 | 2016-04-15 20:28:32 -0700 | [diff] [blame] | 323 | struct weston_headless_backend_config config = {{ 0, }}; |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 324 | |
Benoit Gschwind | 3c53094 | 2016-04-15 20:28:32 -0700 | [diff] [blame] | 325 | if (config_base == NULL || |
| 326 | config_base->struct_version != WESTON_HEADLESS_BACKEND_CONFIG_VERSION || |
| 327 | config_base->struct_size > sizeof(struct weston_headless_backend_config)) { |
| 328 | weston_log("headless backend config structure is invalid\n"); |
| 329 | return -1; |
| 330 | } |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 331 | |
Benoit Gschwind | 3c53094 | 2016-04-15 20:28:32 -0700 | [diff] [blame] | 332 | config_init_to_defaults(&config); |
| 333 | memcpy(&config, config_base, config_base->struct_size); |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 334 | |
Benoit Gschwind | 3c53094 | 2016-04-15 20:28:32 -0700 | [diff] [blame] | 335 | b = headless_backend_create(compositor, &config); |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 336 | if (b == NULL) |
| 337 | return -1; |
Benoit Gschwind | 3c53094 | 2016-04-15 20:28:32 -0700 | [diff] [blame] | 338 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 339 | return 0; |
Ander Conselvan de Oliveira | 11f8d40 | 2012-10-29 18:19:24 +0200 | [diff] [blame] | 340 | } |