2 * Copyright © 2012-2024 Collabora, Ltd.
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 #include "ivi-compositor.h"
38 #include <linux/input.h>
40 #include <libweston/backend-drm.h>
41 #include <libweston/backend-wayland.h>
42 #ifdef HAVE_BACKEND_RDP
43 #include <libweston/backend-rdp.h>
45 #ifdef HAVE_BACKEND_X11
46 #include <libweston/backend-x11.h>
48 #include <libweston/libweston.h>
49 #include <libweston/windowed-output-api.h>
50 #include <libweston/config-parser.h>
51 #include <libweston/weston-log.h>
54 #include "shared/os-compatibility.h"
55 #include "shared/helpers.h"
58 #include "agl-shell-server-protocol.h"
64 #define WINDOWED_DEFAULT_WIDTH 1024
65 #define WINDOWED_DEFAULT_HEIGHT 768
67 static int cached_tm_mday = -1;
68 static struct weston_log_scope *log_scope;
70 struct ivi_compositor *
71 to_ivi_compositor(struct weston_compositor *ec)
73 return weston_compositor_get_user_data(ec);
77 ivi_process_destroy(struct wet_process *process, int status, bool call_cleanup)
79 wl_list_remove(&process->link);
80 if (call_cleanup && process->cleanup)
81 process->cleanup(process, status, process->cleanup_data);
86 struct ivi_output_config *
87 ivi_init_parsed_options(struct weston_compositor *compositor)
89 struct ivi_compositor *ivi = to_ivi_compositor(compositor);
90 struct ivi_output_config *config;
92 config = zalloc(sizeof *config);
99 config->transform = UINT32_MAX;
101 ivi->parsed_options = config;
107 screenshot_allow_all(struct wl_listener *l, struct weston_output_capture_attempt *att)
109 att->authorized = true;
114 sigint_helper(int sig)
121 enum weston_renderer_type renderer;
122 } renderer_name_map[] = {
123 { "auto", WESTON_RENDERER_AUTO },
124 { "gl", WESTON_RENDERER_GL },
125 { "noop", WESTON_RENDERER_NOOP },
126 { "pixman", WESTON_RENDERER_PIXMAN },
132 enum weston_compositor_backend backend;
133 } backend_name_map[] = {
134 { "drm", "drm-backend.so", WESTON_BACKEND_DRM },
135 { "rdp", "rdp-backend.so", WESTON_BACKEND_RDP },
136 { "wayland", "wayland-backend.so", WESTON_BACKEND_WAYLAND },
137 { "x11", "x11-backend.so", WESTON_BACKEND_X11 },
141 get_backend_from_string(const char *name, enum weston_compositor_backend *backend)
145 for (i = 0; i < ARRAY_LENGTH(backend_name_map); i++) {
146 if (strcmp(name, backend_name_map[i].short_name) == 0 ||
147 strcmp(name, backend_name_map[i].long_name) == 0) {
148 *backend = backend_name_map[i].backend;
157 get_renderer_from_string(const char *name, enum weston_renderer_type *renderer)
164 for (i = 0; i < ARRAY_LENGTH(renderer_name_map); i++) {
165 if (strcmp(name, renderer_name_map[i].name) == 0) {
166 *renderer = renderer_name_map[i].renderer;
175 handle_output_destroy(struct wl_listener *listener, void *data)
177 struct ivi_output *output;
179 output = wl_container_of(listener, output, output_destroy);
180 assert(output->output == data);
182 if (output->fullscreen_view.fs &&
183 output->fullscreen_view.fs->view) {
184 weston_surface_unref(output->fullscreen_view.fs->view->surface);
185 weston_buffer_destroy_solid(output->fullscreen_view.buffer_ref);
186 output->fullscreen_view.fs->view = NULL;
189 ivi_layout_save(output->ivi, output);
191 output->output = NULL;
192 wl_list_remove(&output->output_destroy.link);
196 to_ivi_output(struct weston_output *o)
198 struct wl_listener *listener;
199 struct ivi_output *output;
201 listener = weston_output_get_destroy_listener(o, handle_output_destroy);
205 output = wl_container_of(listener, output, output_destroy);
211 ivi_output_configure_app_id(struct ivi_output *ivi_output)
213 if (ivi_output->config) {
214 if (ivi_output->app_ids != NULL)
217 weston_config_section_get_string(ivi_output->config,
219 &ivi_output->app_ids,
222 if (ivi_output->app_ids == NULL)
225 weston_log("Will place app_id %s on output %s\n",
226 ivi_output->app_ids, ivi_output->name);
230 static struct ivi_output *
231 ivi_ensure_output(struct ivi_compositor *ivi, char *name,
232 struct weston_config_section *config,
233 struct weston_head *head)
235 struct ivi_output *output = NULL;
236 wl_list_for_each(output, &ivi->outputs, link) {
237 if (strcmp(output->name, name) == 0) {
243 output = zalloc(sizeof *output);
251 output->config = config;
254 weston_compositor_create_output(ivi->compositor, head, head->name);
255 if (!output->output) {
261 /* simple_output_configure might assume we have an ivi_output created
262 * by this point, which we do but we can only link it to a
263 * weston_output through the destroy listener, so install it earlier
264 * before actually running the callback handler */
265 output->output_destroy.notify = handle_output_destroy;
266 weston_output_add_destroy_listener(output->output,
267 &output->output_destroy);
269 if (ivi->simple_output_configure) {
270 int ret = ivi->simple_output_configure(output->output);
272 weston_log("Configuring output \"%s\" failed.\n",
273 weston_head_get_name(head));
274 weston_output_destroy(output->output);
275 ivi->init_failed = true;
279 if (weston_output_enable(output->output) < 0) {
280 weston_log("Enabling output \"%s\" failed.\n",
281 weston_head_get_name(head));
282 weston_output_destroy(output->output);
283 ivi->init_failed = true;
289 wl_list_insert(&ivi->outputs, &output->link);
290 ivi_output_configure_app_id(output);
296 count_heads(struct weston_output *output)
298 struct weston_head *iter = NULL;
301 while ((iter = weston_output_iterate_heads(output, iter)))
308 handle_head_destroy(struct wl_listener *listener, void *data)
310 struct weston_head *head = data;
311 struct weston_output *output;
313 wl_list_remove(&listener->link);
316 output = weston_head_get_output(head);
318 /* On shutdown path, the output might be already gone. */
322 /* We're the last head */
323 if (count_heads(output) <= 1)
324 weston_output_destroy(output);
328 add_head_destroyed_listener(struct weston_head *head)
330 /* We already have a destroy listener */
331 if (weston_head_get_destroy_listener(head, handle_head_destroy))
334 struct wl_listener *listener = zalloc(sizeof *listener);
338 listener->notify = handle_head_destroy;
339 weston_head_add_destroy_listener(head, listener);
343 ivi_configure_windowed_output_from_config(struct ivi_output *output,
344 struct ivi_output_config *defaults)
346 struct ivi_compositor *ivi = output->ivi;
347 struct weston_config_section *section = output->config;
355 weston_config_section_get_string(section, "mode", &mode, NULL);
356 if (!mode || sscanf(mode, "%dx%d", &width, &height) != 2) {
357 weston_log("Invalid mode for output %s. Using defaults.\n",
359 width = defaults->width;
360 height = defaults->height;
364 width = defaults->width;
365 height = defaults->height;
368 scale = defaults->scale;
370 if (ivi->cmdline.width)
371 width = ivi->cmdline.width;
372 if (ivi->cmdline.height)
373 height = ivi->cmdline.height;
374 if (ivi->cmdline.scale)
375 scale = ivi->cmdline.scale;
377 weston_output_set_scale(output->output, scale);
378 weston_output_set_transform(output->output, defaults->transform);
380 if (ivi->window_api->output_set_size(output->output, width, height) < 0) {
381 weston_log("Cannot configure output '%s' using weston_windowed_output_api.\n",
387 weston_log("Configured windowed_output_api to %dx%d, scale %d\n",
388 width, height, scale);
394 parse_transform(const char *transform, uint32_t *out)
396 static const struct { const char *name; uint32_t token; } transforms[] = {
397 { "normal", WL_OUTPUT_TRANSFORM_NORMAL },
398 { "rotate-90", WL_OUTPUT_TRANSFORM_90 },
399 { "rotate-180", WL_OUTPUT_TRANSFORM_180 },
400 { "rotate-270", WL_OUTPUT_TRANSFORM_270 },
401 { "flipped", WL_OUTPUT_TRANSFORM_FLIPPED },
402 { "flipped-rotate-90", WL_OUTPUT_TRANSFORM_FLIPPED_90 },
403 { "flipped-rotate-180", WL_OUTPUT_TRANSFORM_FLIPPED_180 },
404 { "flipped-rotate-270", WL_OUTPUT_TRANSFORM_FLIPPED_270 },
407 for (size_t i = 0; i < ARRAY_LENGTH(transforms); i++)
408 if (strcmp(transforms[i].name, transform) == 0) {
409 *out = transforms[i].token;
413 *out = WL_OUTPUT_TRANSFORM_NORMAL;
418 parse_activation_area(const char *geometry, struct ivi_output *output)
421 unsigned width, height, x, y;
423 n = sscanf(geometry, "%ux%u+%u,%u", &width, &height, &x, &y);
427 output->area_activation.width = width;
428 output->area_activation.height = height;
429 output->area_activation.x = x;
430 output->area_activation.y = y;
435 drm_configure_output(struct ivi_output *output)
437 struct ivi_compositor *ivi = output->ivi;
438 struct weston_config_section *section = output->config;
440 uint32_t transform = WL_OUTPUT_TRANSFORM_NORMAL;
441 enum weston_drm_backend_output_mode mode =
442 WESTON_DRM_BACKEND_OUTPUT_PREFERRED;
443 char *modeline = NULL;
444 char *gbm_format = NULL;
450 weston_config_section_get_int(section, "scale", &scale, 1);
451 weston_config_section_get_string(section, "transform", &t, "normal");
452 if (parse_transform(t, &transform) < 0)
453 weston_log("Invalid transform \"%s\" for output %s\n",
455 weston_config_section_get_string(section, "activation-area", &t, "");
456 if (parse_activation_area(t, output) < 0)
457 weston_log("Invalid activation-area \"%s\" for output %s\n",
462 weston_output_set_scale(output->output, scale);
463 weston_output_set_transform(output->output, transform);
467 weston_config_section_get_string(section, "mode", &m, "preferred");
469 /* This should have been handled earlier */
470 assert(strcmp(m, "off") != 0);
472 if (ivi->cmdline.use_current_mode || strcmp(m, "current") == 0) {
473 mode = WESTON_DRM_BACKEND_OUTPUT_CURRENT;
474 } else if (strcmp(m, "preferred") != 0) {
480 weston_config_section_get_string(section, "gbm-format",
483 weston_config_section_get_string(section, "seat", &seat, "");
486 if (ivi->drm_api->set_mode(output->output, mode, modeline) < 0) {
487 weston_log("Cannot configure output using weston_drm_output_api.\n");
493 ivi->drm_api->set_gbm_format(output->output, gbm_format);
496 ivi->drm_api->set_seat(output->output, seat);
503 * Reorgainizes the output's add array into two sections.
504 * add[0..ret-1] are the heads that failed to get attached.
505 * add[ret..add_len] are the heads that were successfully attached.
507 * The order between elements in each section is stable.
510 try_attach_heads(struct ivi_output *output)
514 for (size_t i = 1; i < output->add_len; i++) {
515 if (weston_output_attach_head(output->output, output->add[i]) < 0) {
516 struct weston_head *tmp = output->add[i];
517 memmove(&output->add[fail_len + 1], output->add[fail_len],
518 sizeof output->add[0] * (i - fail_len));
519 output->add[fail_len++] = tmp;
525 /* Place output exactly to the right of the most recently enabled output.
527 * Historically, we haven't given much thought to output placement,
528 * simply adding outputs in a horizontal line as they're enabled. This
529 * function simply sets an output's x coordinate to the right of the
530 * most recently enabled output, and its y to zero.
532 * If you're adding new calls to this function, you're also not giving
533 * much thought to output placement, so please consider carefully if
534 * it's really doing what you want.
536 * You especially don't want to use this for any code that won't
537 * immediately enable the passed output.
540 weston_output_lazy_align(struct weston_output *output)
542 struct weston_compositor *c;
543 struct weston_output *peer;
546 /* Put this output to the right of the most recently enabled output */
547 c = output->compositor;
548 if (!wl_list_empty(&c->output_list)) {
549 peer = container_of(c->output_list.prev,
550 struct weston_output, link);
551 next_x = peer->pos.c.x + peer->width;
553 output->pos.c.x = next_x;
559 * Like try_attach_heads, this reorganizes the output's add array into a failed
560 * and successful section.
561 * i is the number of heads that already failed the previous step.
564 try_enable_output(struct ivi_output *output, size_t i)
566 for (; i < output->add_len; ++i) {
567 struct weston_head *head;
569 weston_output_lazy_align(output->output);
571 if (weston_output_enable(output->output) == 0)
574 head = output->add[output->add_len - 1];
575 memmove(&output->add[i + 1], &output->add[i],
576 sizeof output->add[0] * (output->add_len - i));
577 output->add[i] = head;
579 weston_head_detach(head);
586 try_attach_enable_heads(struct ivi_output *output)
589 assert(!output->output->enabled);
591 fail_len = try_attach_heads(output);
593 if (drm_configure_output(output) < 0)
596 fail_len = try_enable_output(output, fail_len);
598 /* All heads failed to be attached */
599 if (fail_len == output->add_len)
602 /* For each successful head attached */
603 for (size_t i = fail_len; i < output->add_len; ++i)
604 add_head_destroyed_listener(output->add[i]);
606 ivi_layout_restore(output->ivi, output);
608 output->add_len = fail_len;
613 process_output(struct ivi_output *output)
615 if (output->output->enabled) {
616 output->add_len = try_attach_heads(output);
617 return output->add_len == 0 ? 0 : -1;
620 return try_attach_enable_heads(output);
624 drm_head_disable(struct ivi_compositor *ivi, struct weston_head *head)
626 struct weston_output *output;
627 struct ivi_output *ivi_output;
628 struct wl_listener *listener;
630 output = weston_head_get_output(head);
633 listener = weston_output_get_destroy_listener(output,
634 handle_output_destroy);
637 ivi_output = wl_container_of(listener, ivi_output, output_destroy);
638 assert(ivi_output->output == output);
640 weston_head_detach(head);
641 if (count_heads(ivi_output->output) == 0) {
642 if (ivi_output->output) {
643 /* ivi_output->output destruction may be deferred in
644 * some cases (see drm_output_destroy()), so we need to
645 * forcibly trigger the destruction callback now, or
646 * otherwise would later access data that we are about
649 struct weston_output *save = ivi_output->output;
651 handle_output_destroy(&ivi_output->output_destroy, save);
652 weston_output_destroy(save);
655 wl_list_remove(&ivi_output->link);
656 free(ivi_output->app_ids);
660 static struct weston_config_section *
661 find_controlling_output_config(struct weston_config *config,
664 struct weston_config_section *section;
668 same_as = strdup(name);
670 section = weston_config_get_section(config, "output",
672 if (!section && depth > 0)
673 weston_log("Configuration error: output section reffered"
674 "to by same-as=%s not found.\n", same_as);
681 weston_log("Configuration error: same-as nested too "
682 "deep for output '%s'.\n", name);
686 weston_config_section_get_string(section, "same-as",
694 drm_head_prepare_enable(struct ivi_compositor *ivi, struct weston_head *head)
696 const char *name = weston_head_get_name(head);
697 struct weston_config_section *section;
698 struct ivi_output *output;
699 char *output_name = NULL;
702 section = find_controlling_output_config(ivi->config, name);
706 weston_config_section_get_string(section, "mode", &mode, NULL);
707 if (mode && strcmp(mode, "off") == 0) {
713 weston_config_section_get_string(section, "name",
716 output_name = strdup(name);
722 output = ivi_ensure_output(ivi, output_name, section, head);
726 if (output->add_len >= ARRAY_LENGTH(output->add))
729 output->add[output->add_len++] = head;
733 drm_heads_changed(struct wl_listener *listener, void *arg)
735 struct weston_compositor *compositor = arg;
736 struct weston_head *head = NULL;
737 struct ivi_compositor *ivi = to_ivi_compositor(compositor);
738 struct ivi_output *output;
740 while ((head = weston_compositor_iterate_heads(ivi->compositor, head))) {
741 bool connected = weston_head_is_connected(head);
742 bool enabled = weston_head_is_enabled(head);
743 bool changed = weston_head_is_device_changed(head);
744 bool non_desktop = weston_head_is_non_desktop(head);
746 if (connected && !enabled && !non_desktop)
747 drm_head_prepare_enable(ivi, head);
748 else if (!connected && enabled)
749 drm_head_disable(ivi, head);
750 else if (enabled && changed)
751 weston_log("Detected a monitor change on head '%s', "
752 "not bothering to do anything about it.\n",
753 weston_head_get_name(head));
755 weston_head_reset_device_changed(head);
758 wl_list_for_each(output, &ivi->outputs, link) {
759 if (output->add_len == 0)
762 if (process_output(output) < 0) {
764 ivi->init_failed = true;
770 simple_head_enable(struct ivi_compositor *ivi, struct weston_head *head)
772 struct ivi_output *output;
773 struct weston_config_section *section;
774 char *output_name = NULL;
775 const char *name = weston_head_get_name(head);
777 section = find_controlling_output_config(ivi->config, name);
781 weston_config_section_get_string(section, "mode", &mode, NULL);
782 if (mode && strcmp(mode, "off") == 0) {
788 weston_config_section_get_string(section, "name",
791 output_name = strdup(name);
797 output = ivi_ensure_output(ivi, output_name, section, head);
799 weston_log("Failed to create output %s\n", output_name);
803 add_head_destroyed_listener(head);
808 simple_head_disable(struct weston_head *head)
810 struct weston_output *output;
811 struct wl_listener *listener;
813 listener = weston_head_get_destroy_listener(head, handle_head_destroy);
814 wl_list_empty(&listener->link);
816 output = weston_head_get_output(head);
818 weston_output_destroy(output);
823 simple_heads_changed(struct wl_listener *listener, void *arg)
825 struct weston_compositor *compositor = arg;
826 struct ivi_compositor *ivi = to_ivi_compositor(compositor);
827 struct weston_head *head = NULL;
833 while ((head = weston_compositor_iterate_heads(ivi->compositor, head))) {
834 connected = weston_head_is_connected(head);
835 enabled = weston_head_is_enabled(head);
836 changed = weston_head_is_device_changed(head);
837 non_desktop = weston_head_is_non_desktop(head);
839 if (connected && !enabled && !non_desktop) {
840 simple_head_enable(ivi, head);
841 } else if (!connected && enabled) {
842 simple_head_disable(head);
843 } else if (enabled && changed) {
844 weston_log("Detected a monitor change on head '%s', "
845 "not bothering to do anything about it.\n",
846 weston_head_get_name(head));
848 weston_head_reset_device_changed(head);
855 drm_backend_remoted_output_configure(struct weston_output *output,
856 struct weston_config_section *section,
858 const struct weston_remoting_api *api)
860 char *gbm_format = NULL;
863 char *pipeline = NULL;
866 uint32_t transform = WL_OUTPUT_TRANSFORM_NORMAL;
869 ret = api->set_mode(output, modeline);
871 weston_log("Cannot configure an output \"%s\" using "
872 "weston_remoting_api. Invalid mode\n",
877 weston_config_section_get_int(section, "scale", &scale, 1);
878 weston_output_set_scale(output, scale);
880 weston_config_section_get_string(section, "transform", &trans, "normal");
881 if (parse_transform(trans, &transform) < 0) {
882 weston_log("Invalid transform \"%s\" for output %s\n",
883 trans, output->name);
885 weston_output_set_transform(output, transform);
887 weston_config_section_get_string(section, "gbm-format",
889 api->set_gbm_format(output, gbm_format);
892 weston_config_section_get_string(section, "seat", &seat, "");
894 api->set_seat(output, seat);
897 weston_config_section_get_string(section, "gst-pipeline", &pipeline,
900 api->set_gst_pipeline(output, pipeline);
905 weston_config_section_get_string(section, "host", &host, NULL);
906 weston_config_section_get_int(section, "port", &port, 0);
907 if (!host || port <= 0 || 65533 < port) {
908 weston_log("Cannot configure an output \"%s\". "
909 "Need to specify gst-pipeline or "
910 "host and port (1-65533).\n", output->name);
912 api->set_host(output, host);
914 api->set_port(output, port);
921 remote_output_init(struct ivi_output *ivi_output,
922 struct weston_compositor *compositor,
923 struct weston_config_section *section,
924 const struct weston_remoting_api *api)
926 char *output_name, *modeline = NULL;
929 weston_config_section_get_string(section, "name", &output_name, NULL);
933 weston_config_section_get_string(section, "mode", &modeline, "off");
934 if (strcmp(modeline, "off") == 0)
937 ivi_output->output = api->create_output(compositor, output_name);
938 if (!ivi_output->output) {
939 weston_log("Cannot create remoted output \"%s\".\n",
944 ret = drm_backend_remoted_output_configure(ivi_output->output, section,
947 weston_log("Cannot configure remoted output \"%s\".\n",
952 if ((ret = weston_output_enable(ivi_output->output)) < 0) {
953 weston_log("Enabling remoted output \"%s\" failed.\n",
960 weston_log("remoted output '%s' enabled\n", ivi_output->output->name);
967 if (ivi_output->output)
968 weston_output_destroy(ivi_output->output);
974 ivi_enable_remote_outputs(struct ivi_compositor *ivi)
976 struct weston_config_section *remote_section = NULL;
977 const char *section_name;
978 struct weston_config *config = ivi->config;
980 while (weston_config_next_section(config, &remote_section, §ion_name)) {
981 if (strcmp(section_name, "remote-output"))
984 struct ivi_output *ivi_output = NULL;
985 bool output_found = false;
988 weston_config_section_get_string(remote_section,
989 "name", &_name, NULL);
990 wl_list_for_each(ivi_output, &ivi->outputs, link) {
991 if (!strcmp(ivi_output->name, _name)) {
1002 ivi_output = zalloc(sizeof(*ivi_output));
1008 ivi_output->ivi = ivi;
1009 ivi_output->name = _name;
1010 ivi_output->config = remote_section;
1011 ivi_output->type = OUTPUT_REMOTE;
1013 if (remote_output_init(ivi_output, ivi->compositor,
1014 remote_section, ivi->remoting_api)) {
1015 free(ivi_output->name);
1020 ivi_output->output_destroy.notify = handle_output_destroy;
1021 weston_output_add_destroy_listener(ivi_output->output,
1022 &ivi_output->output_destroy);
1024 wl_list_insert(&ivi->outputs, &ivi_output->link);
1025 ivi_output_configure_app_id(ivi_output);
1030 load_remoting_plugin(struct ivi_compositor *ivi, struct weston_config *config)
1032 struct weston_compositor *compositor = ivi->compositor;
1033 int (*module_init)(struct weston_compositor *wc);
1035 module_init = weston_load_module("remoting-plugin.so",
1036 "weston_module_init",
1037 LIBWESTON_MODULEDIR);
1041 if (module_init(compositor) < 0)
1044 ivi->remoting_api = weston_remoting_get_api(compositor);
1045 if (!ivi->remoting_api)
1051 load_remoting_plugin(struct weston_compositor *compositor, struct weston_config *config)
1058 load_drm_backend(struct ivi_compositor *ivi, int *argc, char *argv[],
1059 enum weston_renderer_type renderer)
1061 struct weston_drm_backend_config config = {
1063 .struct_version = WESTON_DRM_BACKEND_CONFIG_VERSION,
1064 .struct_size = sizeof config,
1067 struct weston_config_section *section;
1068 int use_current_mode = 0;
1069 bool force_pixman = false;
1071 bool without_input = false;
1073 const struct weston_option options[] = {
1074 { WESTON_OPTION_STRING, "seat", 0, &config.seat_id },
1075 { WESTON_OPTION_STRING, "drm-device", 0, &config.specific_device },
1076 { WESTON_OPTION_BOOLEAN, "current-mode", 0, &use_current_mode },
1077 { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &force_pixman },
1078 { WESTON_OPTION_BOOLEAN, "continue-without-input", false, &without_input }
1081 parse_options(options, ARRAY_LENGTH(options), argc, argv);
1084 config.renderer = WESTON_RENDERER_PIXMAN;
1086 config.renderer = WESTON_RENDERER_AUTO;
1088 ivi->cmdline.use_current_mode = use_current_mode;
1090 section = weston_config_get_section(ivi->config, "core", NULL, NULL);
1091 weston_config_section_get_string(section, "gbm-format",
1092 &config.gbm_format, NULL);
1093 weston_config_section_get_uint(section, "pageflip-timeout",
1094 &config.pageflip_timeout, 0);
1095 weston_config_section_get_bool(section, "pixman-shadow", &use_shadow, 1);
1096 config.use_pixman_shadow = use_shadow;
1099 ivi->compositor->require_input = !without_input;
1101 ivi->heads_changed.notify = drm_heads_changed;
1102 weston_compositor_add_heads_changed_listener(ivi->compositor,
1103 &ivi->heads_changed);
1105 if (!weston_compositor_load_backend(ivi->compositor, WESTON_BACKEND_DRM,
1107 weston_log("Failed to load DRM backend\n");
1111 ivi->drm_api = weston_drm_output_get_api(ivi->compositor);
1112 if (!ivi->drm_api) {
1113 weston_log("Cannot use drm output api.\n");
1117 load_remoting_plugin(ivi, ivi->config);
1122 free(config.gbm_format);
1123 free(config.seat_id);
1128 windowed_parse_common_options(struct ivi_compositor *ivi, int *argc, char *argv[],
1129 bool *force_pixman, bool *fullscreen, int *output_count)
1131 struct weston_config_section *section;
1135 const struct weston_option options[] = {
1136 { WESTON_OPTION_INTEGER, "width", 0, &ivi->cmdline.width },
1137 { WESTON_OPTION_INTEGER, "height", 0, &ivi->cmdline.height },
1138 { WESTON_OPTION_INTEGER, "scale", 0, &ivi->cmdline.scale },
1139 { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &force_pixman },
1140 { WESTON_OPTION_BOOLEAN, "fullscreen", 0, &fs },
1141 { WESTON_OPTION_INTEGER, "output-count", 0, output_count },
1144 section = weston_config_get_section(ivi->config, "core", NULL, NULL);
1145 weston_config_section_get_bool(section, "use-pixman", &pixman, false);
1148 parse_options(options, ARRAY_LENGTH(options), argc, argv);
1149 *force_pixman = pixman;
1154 windowed_create_outputs(struct ivi_compositor *ivi, int output_count,
1155 const char *match_prefix, const char *name_prefix)
1157 struct weston_config_section *section = NULL;
1158 const char *section_name;
1159 char *default_output = NULL;
1161 size_t match_len = strlen(match_prefix);
1163 while (weston_config_next_section(ivi->config, §ion, §ion_name)) {
1166 if (i >= output_count)
1169 if (strcmp(section_name, "output") != 0)
1172 weston_config_section_get_string(section, "name", &output_name, NULL);
1173 if (output_name == NULL)
1175 if (strncmp(output_name, match_prefix, match_len) != 0) {
1180 if (ivi->window_api->create_head(ivi->backend, output_name) < 0) {
1189 for (; i < output_count; ++i) {
1190 if (asprintf(&default_output, "%s%d", name_prefix, i) < 0)
1193 if (ivi->window_api->create_head(ivi->backend, default_output) < 0) {
1194 free(default_output);
1198 free(default_output);
1206 wayland_backend_output_configure(struct weston_output *output)
1208 struct ivi_output *ivi_output = to_ivi_output(output);
1210 struct ivi_output_config defaults = {
1211 .width = WINDOWED_DEFAULT_WIDTH,
1212 .height = WINDOWED_DEFAULT_HEIGHT,
1214 .transform = WL_OUTPUT_TRANSFORM_NORMAL
1218 weston_log("Failed to configure and enable Wayland output. No ivi-output available!\n");
1222 return ivi_configure_windowed_output_from_config(to_ivi_output(output), &defaults);
1226 load_wayland_backend(struct ivi_compositor *ivi, int *argc, char *argv[],
1227 enum weston_renderer_type renderer)
1229 struct weston_wayland_backend_config config = {
1231 .struct_version = WESTON_WAYLAND_BACKEND_CONFIG_VERSION,
1232 .struct_size = sizeof config,
1235 struct weston_config_section *section;
1238 bool force_pixman = false;
1240 const struct weston_option options[] = {
1241 { WESTON_OPTION_STRING, "display", 0, &config.display_name },
1242 { WESTON_OPTION_STRING, "sprawl", 0, &sprawl },
1245 windowed_parse_common_options(ivi, argc, argv, &force_pixman,
1246 &config.fullscreen, &output_count);
1248 parse_options(options, ARRAY_LENGTH(options), argc, argv);
1249 config.sprawl = sprawl;
1251 section = weston_config_get_section(ivi->config, "shell", NULL, NULL);
1252 weston_config_section_get_string(section, "cursor-theme",
1253 &config.cursor_theme, NULL);
1254 weston_config_section_get_int(section, "cursor-size",
1255 &config.cursor_size, 32);
1257 ivi->simple_output_configure = wayland_backend_output_configure;
1258 ivi->heads_changed.notify = simple_heads_changed;
1259 weston_compositor_add_heads_changed_listener(ivi->compositor,
1260 &ivi->heads_changed);
1262 ivi->backend = weston_compositor_load_backend(ivi->compositor,
1263 WESTON_BACKEND_WAYLAND,
1265 if (!ivi->backend) {
1266 weston_log("Failed to create Wayland backend!\n");
1269 free(config.cursor_theme);
1270 free(config.display_name);
1275 ivi->window_api = weston_windowed_output_get_api(ivi->compositor);
1278 * We will just assume if load_backend() finished cleanly and
1279 * windowed_output_api is not present that wayland backend is started
1280 * with --sprawl or runs on fullscreen-shell. In this case, all values
1281 * are hardcoded, so nothing can be configured; simply create and
1284 if (ivi->window_api == NULL)
1287 return windowed_create_outputs(ivi, output_count, "WL", "wayland");
1290 #ifdef HAVE_BACKEND_X11
1292 x11_backend_output_configure(struct weston_output *output)
1294 struct ivi_output *ivi_output = to_ivi_output(output);
1296 struct ivi_output_config defaults = {
1297 .width = WINDOWED_DEFAULT_WIDTH,
1298 .height = WINDOWED_DEFAULT_HEIGHT,
1300 .transform = WL_OUTPUT_TRANSFORM_NORMAL
1304 weston_log("Failed to configure and enable X11 output. No ivi-output available!\n");
1309 return ivi_configure_windowed_output_from_config(ivi_output, &defaults);
1313 load_x11_backend(struct ivi_compositor *ivi, int *argc, char *argv[],
1314 enum weston_renderer_type renderer)
1316 struct weston_x11_backend_config config = {
1318 .struct_version = WESTON_X11_BACKEND_CONFIG_VERSION,
1319 .struct_size = sizeof config,
1324 bool force_pixman = false;
1326 const struct weston_option options[] = {
1327 { WESTON_OPTION_BOOLEAN, "no-input", 0, &no_input },
1330 windowed_parse_common_options(ivi, argc, argv, &force_pixman,
1331 &config.fullscreen, &output_count);
1333 parse_options(options, ARRAY_LENGTH(options), argc, argv);
1335 config.renderer = WESTON_RENDERER_PIXMAN;
1337 config.renderer = WESTON_RENDERER_AUTO;
1338 config.no_input = no_input;
1340 ivi->simple_output_configure = x11_backend_output_configure;
1342 ivi->heads_changed.notify = simple_heads_changed;
1343 weston_compositor_add_heads_changed_listener(ivi->compositor,
1344 &ivi->heads_changed);
1346 ivi->backend = weston_compositor_load_backend(ivi->compositor,
1349 if (!ivi->backend) {
1350 weston_log("Failed to create X11 backend!\n");
1354 ivi->window_api = weston_windowed_output_get_api(ivi->compositor);
1355 if (!ivi->window_api) {
1356 weston_log("Cannot use weston_windowed_output_api.\n");
1360 return windowed_create_outputs(ivi, output_count, "X", "screen");
1364 load_x11_backend(struct ivi_compositor *ivi, int *argc, char **argv,
1365 enum weston_renderer_type renderer)
1371 #ifdef HAVE_BACKEND_RDP
1373 weston_rdp_backend_config_init(struct weston_rdp_backend_config *config)
1375 config->base.struct_version = WESTON_RDP_BACKEND_CONFIG_VERSION;
1376 config->base.struct_size = sizeof(struct weston_rdp_backend_config);
1378 config->renderer = WESTON_RENDERER_AUTO;
1379 config->bind_address = NULL;
1380 config->port = 3389;
1381 config->rdp_key = NULL;
1382 config->server_cert = NULL;
1383 config->server_key = NULL;
1384 config->env_socket = 0;
1385 config->external_listener_fd = -1;
1386 config->no_clients_resize = 0;
1387 config->force_no_compression = 0;
1388 config->remotefx_codec = true;
1389 config->refresh_rate = RDP_DEFAULT_FREQ;
1394 rdp_backend_output_configure(struct weston_output *output)
1396 struct ivi_compositor *ivi = to_ivi_compositor(output->compositor);
1397 struct ivi_output_config *parsed_options = ivi->parsed_options;
1398 const struct weston_rdp_output_api *api =
1399 weston_rdp_output_get_api(output->compositor);
1402 struct weston_config_section *section;
1403 uint32_t transform = WL_OUTPUT_TRANSFORM_NORMAL;
1404 char *transform_string;
1405 struct weston_mode new_mode = {};
1407 assert(parsed_options);
1410 weston_log("Cannot use weston_rdp_output_api.\n");
1414 section = weston_config_get_section(ivi->config, "rdp", NULL, NULL);
1416 if (parsed_options->width)
1417 width = parsed_options->width;
1419 if (parsed_options->height)
1420 height = parsed_options->height;
1422 weston_output_set_scale(output, 1);
1424 weston_config_section_get_int(section, "width",
1427 weston_config_section_get_int(section, "height",
1430 if (parsed_options->transform)
1431 transform = parsed_options->transform;
1433 weston_config_section_get_string(section, "transform",
1434 &transform_string, "normal");
1436 if (parse_transform(transform_string, &transform) < 0) {
1437 weston_log("Invalid transform \"%s\" for output %s\n",
1438 transform_string, output->name);
1443 new_mode.width = width;
1444 new_mode.height = height;
1446 weston_log("Setting modeline to %dx%d\n", width, height);
1448 api->output_set_mode(output, &new_mode);
1449 weston_output_set_transform(output, transform);
1455 load_rdp_backend(struct ivi_compositor *ivi, int *argc, char **argv,
1456 enum weston_renderer_type renderer)
1458 struct weston_rdp_backend_config config = {};
1459 struct weston_config_section *section;
1460 bool no_remotefx_codec = false;
1462 struct ivi_output_config *parsed_options = ivi_init_parsed_options(ivi->compositor);
1463 if (!parsed_options)
1466 weston_rdp_backend_config_init(&config);
1468 const struct weston_option rdp_options[] = {
1469 { WESTON_OPTION_BOOLEAN, "env-socket", 0, &config.env_socket },
1470 { WESTON_OPTION_INTEGER, "external-listener-fd", 0, &config.external_listener_fd },
1471 { WESTON_OPTION_INTEGER, "width", 0, &parsed_options->width },
1472 { WESTON_OPTION_INTEGER, "height", 0, &parsed_options->height },
1473 { WESTON_OPTION_STRING, "address", 0, &config.bind_address },
1474 { WESTON_OPTION_INTEGER, "port", 0, &config.port },
1475 { WESTON_OPTION_BOOLEAN, "no-clients-resize", 0, &config.no_clients_resize },
1476 { WESTON_OPTION_STRING, "rdp4-key", 0, &config.rdp_key },
1477 { WESTON_OPTION_STRING, "rdp-tls-cert", 0, &config.server_cert },
1478 { WESTON_OPTION_STRING, "rdp-tls-key", 0, &config.server_key },
1479 { WESTON_OPTION_INTEGER, "scale", 0, &parsed_options->scale },
1480 { WESTON_OPTION_BOOLEAN, "force-no-compression", 0, &config.force_no_compression },
1481 { WESTON_OPTION_BOOLEAN, "no-remotefx-codec", 0, &no_remotefx_codec },
1484 config.remotefx_codec = !no_remotefx_codec;
1485 config.renderer = renderer;
1487 section = weston_config_get_section(ivi->config, "rdp", NULL, NULL);
1489 weston_config_section_get_int(section, "refresh-rate",
1490 &config.refresh_rate, RDP_DEFAULT_FREQ);
1492 weston_config_section_get_string(section, "tls-cert",
1493 &config.server_cert, config.server_cert);
1495 weston_config_section_get_string(section, "tls-key",
1496 &config.server_key, config.server_key);
1499 parse_options(rdp_options, ARRAY_LENGTH(rdp_options), argc, argv);
1500 weston_log("No clients resize: %d\n", config.no_clients_resize);
1502 ivi->simple_output_configure = rdp_backend_output_configure;
1504 ivi->heads_changed.notify = simple_heads_changed;
1505 weston_compositor_add_heads_changed_listener(ivi->compositor,
1506 &ivi->heads_changed);
1508 if (!weston_compositor_load_backend(ivi->compositor,
1509 WESTON_BACKEND_RDP, &config.base)) {
1510 weston_log("Failed to create RDP backend\n");
1514 free(config.bind_address);
1515 free(config.rdp_key);
1516 free(config.server_cert);
1517 free(config.server_key);
1523 load_rdp_backend(struct ivi_compositor *ivi, int *argc, char **argv,
1524 enum weston_renderer_type renderer)
1532 load_backend(struct ivi_compositor *ivi, int *argc, char **argv,
1533 const char *backend_name, const char *renderer_name)
1535 enum weston_compositor_backend backend;
1536 enum weston_renderer_type renderer;
1538 if (!get_backend_from_string(backend_name, &backend)) {
1539 weston_log("Error: unknown backend \"%s\"\n", backend_name);
1543 if (!get_renderer_from_string(renderer_name, &renderer)) {
1544 weston_log("Error: unknown renderer \"%s\"\n", renderer_name);
1549 case WESTON_BACKEND_DRM:
1550 return load_drm_backend(ivi, argc, argv, renderer);
1551 case WESTON_BACKEND_RDP:
1552 return load_rdp_backend(ivi, argc, argv, renderer);
1553 case WESTON_BACKEND_WAYLAND:
1554 return load_wayland_backend(ivi, argc, argv, renderer);
1555 case WESTON_BACKEND_X11:
1556 return load_x11_backend(ivi, argc, argv, renderer);
1558 assert(!"unknown backend type in load_backend()");
1565 load_modules(struct ivi_compositor *ivi, const char *modules,
1566 int *argc, char *argv[], bool *xwayland)
1568 const char *p, *end;
1570 int (*module_init)(struct weston_compositor *wc, int argc, char *argv[]);
1572 if (modules == NULL)
1577 end = strchrnul(p, ',');
1578 snprintf(buffer, sizeof buffer, "%.*s", (int) (end - p), p);
1580 if (strstr(buffer, "xwayland.so")) {
1582 } else if (strstr(buffer, "systemd-notify.so")) {
1583 weston_log("systemd-notify plug-in already loaded!\n");
1585 module_init = weston_load_module(buffer, "wet_module_init", WESTON_MODULEDIR);
1589 if (module_init(ivi->compositor, *argc, argv) < 0)
1604 choose_default_backend(void)
1606 char *backend = NULL;
1608 if (getenv("WAYLAND_DISPLAY") || getenv("WAYLAND_SOCKET"))
1609 backend = strdup("wayland-backend.so");
1610 else if (getenv("DISPLAY"))
1611 backend = strdup("x11-backend.so");
1613 backend = strdup("drm-backend.so");
1619 compositor_init_config(struct ivi_compositor *ivi)
1621 struct xkb_rule_names xkb_names;
1622 struct weston_config_section *section;
1623 struct weston_compositor *compositor = ivi->compositor;
1624 struct weston_config *config = ivi->config;
1629 /* agl-compositor.ini [keyboard] */
1630 section = weston_config_get_section(config, "keyboard", NULL, NULL);
1631 weston_config_section_get_string(section, "keymap_rules",
1632 (char **) &xkb_names.rules, NULL);
1633 weston_config_section_get_string(section, "keymap_model",
1634 (char **) &xkb_names.model, NULL);
1635 weston_config_section_get_string(section, "keymap_layout",
1636 (char **) &xkb_names.layout, NULL);
1637 weston_config_section_get_string(section, "keymap_variant",
1638 (char **) &xkb_names.variant, NULL);
1639 weston_config_section_get_string(section, "keymap_options",
1640 (char **) &xkb_names.options, NULL);
1642 if (weston_compositor_set_xkb_rule_names(compositor, &xkb_names) < 0)
1645 weston_config_section_get_int(section, "repeat-rate",
1646 &compositor->kb_repeat_rate, 40);
1647 weston_config_section_get_int(section, "repeat-delay",
1648 &compositor->kb_repeat_delay, 400);
1650 weston_config_section_get_bool(section, "vt-switching",
1651 &vt_switching, false);
1652 compositor->vt_switching = vt_switching;
1654 /* agl-compositor.ini [core] */
1655 section = weston_config_get_section(config, "core", NULL, NULL);
1657 weston_config_section_get_bool(section, "disable-cursor",
1658 &ivi->disable_cursor, false);
1659 weston_config_section_get_bool(section, "activate-by-default",
1660 &ivi->activate_by_default, true);
1662 weston_config_section_get_bool(section, "require-input", &require_input, true);
1663 compositor->require_input = require_input;
1665 weston_config_section_get_int(section, "repaint-window", &repaint_msec,
1666 compositor->repaint_msec);
1667 if (repaint_msec < -10 || repaint_msec > 1000) {
1668 weston_log("Invalid repaint_window value in config: %d\n",
1671 compositor->repaint_msec = repaint_msec;
1673 weston_log("Output repaint window is %d ms maximum.\n",
1674 compositor->repaint_msec);
1679 struct ivi_surface *
1680 to_ivi_surface(struct weston_surface *surface)
1682 struct weston_desktop_surface *dsurface;
1684 dsurface = weston_surface_get_desktop_surface(surface);
1688 return weston_desktop_surface_get_user_data(dsurface);
1692 activate_binding(struct weston_seat *seat,
1693 struct weston_view *focus_view, uint32_t flags)
1695 struct weston_surface *focus_surface;
1696 struct weston_surface *main_surface;
1697 struct ivi_surface *ivi_surface;
1698 struct ivi_shell_seat *ivi_seat = get_ivi_shell_seat(seat);
1703 focus_surface = focus_view->surface;
1704 main_surface = weston_surface_get_main_surface(focus_surface);
1706 ivi_surface = to_ivi_surface(main_surface);
1711 ivi_shell_activate_surface(ivi_surface, ivi_seat, flags);
1715 click_to_activate_binding(struct weston_pointer *pointer,
1716 const struct timespec *time,
1717 uint32_t button, void *data)
1719 if (pointer->grab != &pointer->default_grab)
1721 if (pointer->focus == NULL)
1724 activate_binding(pointer->seat, pointer->focus,
1725 WESTON_ACTIVATE_FLAG_CLICKED);
1729 touch_to_activate_binding(struct weston_touch *touch,
1730 const struct timespec *time,
1733 if (touch->grab != &touch->default_grab)
1735 if (touch->focus == NULL)
1738 activate_binding(touch->seat, touch->focus,
1739 WESTON_ACTIVATE_FLAG_NONE);
1743 add_bindings(struct weston_compositor *compositor)
1745 weston_compositor_add_button_binding(compositor, BTN_LEFT, 0,
1746 click_to_activate_binding,
1748 weston_compositor_add_button_binding(compositor, BTN_RIGHT, 0,
1749 click_to_activate_binding,
1751 weston_compositor_add_touch_binding(compositor, 0,
1752 touch_to_activate_binding,
1757 create_listening_socket(struct wl_display *display, const char *socket_name)
1760 if (wl_display_add_socket(display, socket_name)) {
1761 weston_log("fatal: failed to add socket: %s\n",
1766 socket_name = wl_display_add_socket_auto(display);
1768 weston_log("fatal: failed to add socket: %s\n",
1774 setenv("WAYLAND_DISPLAY", socket_name, 1);
1780 global_filter(const struct wl_client *client, const struct wl_global *global,
1787 load_config(struct weston_config **config, bool no_config,
1788 const char *config_file)
1790 const char *file = "agl-compositor.ini";
1791 const char *full_path;
1797 *config = weston_config_parse(file);
1800 full_path = weston_config_get_full_path(*config);
1802 weston_log("Using config file '%s'.\n", full_path);
1803 setenv(WESTON_CONFIG_FILE_ENV_VAR, full_path, 1);
1808 if (config_file && !no_config) {
1809 weston_log("fatal: error opening or reading config file '%s'.\n",
1815 weston_log("Starting with no config file.\n");
1816 setenv(WESTON_CONFIG_FILE_ENV_VAR, "", 1);
1821 static FILE *logfile;
1824 log_timestamp(char *buf, size_t len)
1827 struct tm *brokendown_time;
1831 gettimeofday(&tv, NULL);
1833 brokendown_time = localtime(&tv.tv_sec);
1834 if (brokendown_time == NULL) {
1835 snprintf(buf, len, "%s", "[(NULL)localtime] ");
1839 memset(datestr, 0, sizeof(datestr));
1840 if (brokendown_time->tm_mday != cached_tm_mday) {
1841 strftime(datestr, sizeof(datestr), "Date: %Y-%m-%d %Z\n",
1843 cached_tm_mday = brokendown_time->tm_mday;
1846 strftime(timestr, sizeof(timestr), "%H:%M:%S", brokendown_time);
1847 /* if datestr is empty it prints only timestr*/
1848 snprintf(buf, len, "%s[%s.%03"PRIi64"]", datestr,
1849 timestr, (tv.tv_usec / 1000));
1855 custom_handler(const char *fmt, va_list arg)
1859 weston_log_scope_printf(log_scope, "%s libwayland: ",
1860 log_timestamp(timestr, sizeof(timestr)));
1861 weston_log_scope_vprintf(log_scope, fmt, arg);
1865 log_file_open(const char *filename)
1867 wl_log_set_handler_server(custom_handler);
1870 logfile = fopen(filename, "a");
1875 os_fd_set_cloexec(fileno(logfile));
1876 setvbuf(logfile, NULL, _IOLBF, 256);
1881 log_file_close(void)
1883 if (logfile && logfile != stderr)
1889 vlog(const char *fmt, va_list ap)
1891 const char *oom = "Out of memory";
1896 if (weston_log_scope_is_enabled(log_scope)) {
1898 char *xlog_timestamp = log_timestamp(timestr, sizeof(timestr));
1899 len_va = vasprintf(&str, fmt, ap);
1901 len = weston_log_scope_printf(log_scope, "%s %s",
1902 xlog_timestamp, str);
1905 len = weston_log_scope_printf(log_scope, "%s %s",
1906 xlog_timestamp, oom);
1915 vlog_continue(const char *fmt, va_list ap)
1917 return weston_log_scope_vprintf(log_scope, fmt, ap);
1921 on_term_signal(int signo, void *data)
1923 struct wl_display *display = data;
1925 weston_log("caught signal %d\n", signo);
1926 wl_display_terminate(display);
1932 handle_exit(struct weston_compositor *compositor)
1934 wl_display_terminate(compositor->wl_display);
1938 usage(int error_code)
1940 FILE *out = error_code == EXIT_SUCCESS ? stdout : stderr;
1942 "Usage: agl-compositor [OPTIONS]\n"
1944 "This is " PACKAGE_STRING ", the reference compositor for\n"
1945 "Automotive Grade Linux. " PACKAGE_STRING " supports multiple "
1946 "backends,\nand depending on which backend is in use different "
1947 "options will be accepted.\n"
1951 " --version\t\tPrint agl-compositor version\n"
1952 " -B, --backend=MODULE\tBackend module, one of\n"
1953 "\t\t\t\tdrm-backend.so\n"
1954 "\t\t\t\twayland-backend.so\n"
1955 "\t\t\t\tx11-backend.so\n"
1956 "\t\t\t\theadless-backend.so\n"
1957 " -r, --renderer=NAME\tName of renderer to use: auto, gl, noop, pixman\n"
1958 " -S, --socket=NAME\tName of socket to listen on\n"
1959 " --log=FILE\t\tLog to the given file\n"
1960 " -c, --config=FILE\tConfig file to load, defaults to agl-compositor.ini\n"
1961 " --no-config\t\tDo not read agl-compositor.ini\n"
1962 " --debug\t\tEnable debug extension(s)\n"
1963 " -h, --help\t\tThis help message\n"
1969 copy_command_line(int argc, char * const argv[])
1976 fp = open_memstream(&str, &size);
1980 fprintf(fp, "%s", argv[0]);
1981 for (i = 1; i < argc; i++)
1982 fprintf(fp, " %s", argv[i]);
1988 #if !defined(BUILD_XWAYLAND)
1990 wet_load_xwayland(struct weston_compositor *comp)
1992 weston_log("Attempted to load xwayland library but compositor "
1993 "was *not* built with xwayland support!\n");
1999 weston_log_setup_scopes(struct weston_log_context *log_ctx,
2000 struct weston_log_subscriber *subscriber,
2006 char *tokenize = strdup(names);
2007 char *token = strtok(tokenize, ",");
2009 weston_log_subscribe(log_ctx, subscriber, token);
2010 token = strtok(NULL, ",");
2016 weston_log_subscribe_to_scopes(struct weston_log_context *log_ctx,
2017 struct weston_log_subscriber *logger,
2018 const char *debug_scopes)
2020 if (logger && debug_scopes)
2021 weston_log_setup_scopes(log_ctx, logger, debug_scopes);
2023 weston_log_subscribe(log_ctx, logger, "log");
2027 int wet_main(int argc, char *argv[], const struct weston_testsuite_data *test_data)
2029 struct ivi_compositor ivi = { 0 };
2031 struct wl_display *display = NULL;
2032 struct wl_event_loop *loop;
2033 struct wl_event_source *signals[3] = { 0 };
2034 struct weston_config_section *section;
2035 /* Command line options */
2036 char *backend = NULL;
2037 char *socket_name = NULL;
2039 char *modules = NULL;
2040 char *option_modules = NULL;
2041 char *debug_scopes = NULL;
2046 bool list_debug_scopes = false;
2047 char *config_file = NULL;
2048 struct weston_log_context *log_ctx = NULL;
2049 struct weston_log_subscriber *logger;
2050 int ret = EXIT_FAILURE;
2051 bool xwayland = false;
2052 struct sigaction action;
2053 char *renderer = NULL;
2054 struct wet_process *process, *process_tmp;
2056 const struct weston_option core_options[] = {
2057 { WESTON_OPTION_STRING, "renderer", 'r', &renderer },
2058 { WESTON_OPTION_STRING, "backend", 'B', &backend },
2059 { WESTON_OPTION_STRING, "socket", 'S', &socket_name },
2060 { WESTON_OPTION_STRING, "log", 0, &log },
2061 { WESTON_OPTION_BOOLEAN, "help", 'h', &help },
2062 { WESTON_OPTION_BOOLEAN, "version", 0, &version },
2063 { WESTON_OPTION_BOOLEAN, "no-config", 0, &no_config },
2064 { WESTON_OPTION_BOOLEAN, "debug", 0, &debug },
2065 { WESTON_OPTION_STRING, "config", 'c', &config_file },
2066 { WESTON_OPTION_STRING, "modules", 0, &option_modules },
2067 { WESTON_OPTION_STRING, "debug-scopes", 'l', &debug_scopes },
2068 { WESTON_OPTION_STRING, "list-debug-scopes", 'L', &list_debug_scopes },
2071 wl_list_init(&ivi.outputs);
2072 wl_list_init(&ivi.saved_outputs);
2073 wl_list_init(&ivi.surfaces);
2074 wl_list_init(&ivi.pending_surfaces);
2075 wl_list_init(&ivi.popup_pending_apps);
2076 wl_list_init(&ivi.fullscreen_pending_apps);
2077 wl_list_init(&ivi.split_pending_apps);
2078 wl_list_init(&ivi.remote_pending_apps);
2079 wl_list_init(&ivi.desktop_clients);
2080 wl_list_init(&ivi.child_process_list);
2081 wl_list_init(&ivi.pending_apps);
2083 /* Prevent any clients we spawn getting our stdin */
2084 os_fd_set_cloexec(STDIN_FILENO);
2086 cmdline = copy_command_line(argc, argv);
2087 parse_options(core_options, ARRAY_LENGTH(core_options), &argc, argv);
2090 usage(EXIT_SUCCESS);
2093 printf(PACKAGE_STRING "\n");
2098 log_ctx = weston_log_ctx_create();
2100 fprintf(stderr, "Failed to initialize weston debug framework.\n");
2104 log_scope = weston_log_ctx_add_log_scope(log_ctx, "log",
2105 "agl-compositor log\n",
2109 weston_log_set_handler(vlog, vlog_continue);
2111 logger = weston_log_subscriber_create_log(logfile);
2112 weston_log_subscribe_to_scopes(log_ctx, logger, debug_scopes);
2114 weston_log("Command line: %s\n", cmdline);
2117 if (load_config(&ivi.config, no_config, config_file) < 0)
2119 section = weston_config_get_section(ivi.config, "core", NULL, NULL);
2121 weston_config_section_get_string(section, "backend", &backend,
2124 backend = choose_default_backend();
2127 display = wl_display_create();
2128 loop = wl_display_get_event_loop(display);
2130 wl_display_set_global_filter(display,
2131 global_filter, &ivi);
2133 /* Register signal handlers so we shut down cleanly */
2135 signals[0] = wl_event_loop_add_signal(loop, SIGTERM, on_term_signal,
2137 signals[1] = wl_event_loop_add_signal(loop, SIGUSR2, on_term_signal,
2139 signals[2] = wl_event_loop_add_signal(loop, SIGCHLD, sigchld_handler,
2142 /* When debugging the compositor, if use wl_event_loop_add_signal() to
2143 * catch SIGINT, the debugger can't catch it, and attempting to stop
2144 * the compositor from within the debugger results in weston exiting
2147 * Instead, use the sigaction() function, which sets up the signal in a
2148 * way that gdb can successfully catch, but have the handler for SIGINT
2149 * send SIGUSR2 (xwayland uses SIGUSR1), which we catch via
2150 * wl_event_loop_add_signal().
2152 action.sa_handler = sigint_helper;
2153 sigemptyset(&action.sa_mask);
2154 action.sa_flags = 0;
2155 sigaction(SIGINT, &action, NULL);
2157 for (size_t i = 0; i < ARRAY_LENGTH(signals); ++i)
2161 ivi.compositor = weston_compositor_create(display, log_ctx, &ivi, test_data);
2162 if (!ivi.compositor) {
2163 weston_log("fatal: failed to create compositor.\n");
2167 if (compositor_init_config(&ivi) < 0)
2168 goto error_compositor;
2170 if (load_backend(&ivi, &argc, argv, backend, renderer) < 0) {
2171 weston_log("fatal: failed to create compositor backend.\n");
2172 goto error_compositor;
2175 if (weston_compositor_backends_loaded(ivi.compositor) < 0)
2176 goto error_compositor;
2178 weston_compositor_flush_heads_changed(ivi.compositor);
2180 if (ivi_desktop_init(&ivi) < 0)
2181 goto error_compositor;
2183 ivi_seat_init(&ivi);
2185 /* load additional modules */
2186 weston_config_section_get_string(section, "modules", &modules, "");
2187 if (load_modules(&ivi, modules, &argc, argv, &xwayland) < 0)
2188 goto error_compositor;
2190 if (load_modules(&ivi, option_modules, &argc, argv, &xwayland) < 0)
2191 goto error_compositor;
2194 weston_config_section_get_bool(section, "xwayland", &xwayland,
2198 if (ivi_shell_init(&ivi) < 0)
2199 goto error_compositor;
2202 if (!wet_load_xwayland(ivi.compositor))
2203 goto error_compositor;
2206 if (ivi_policy_init(&ivi) < 0)
2207 goto error_compositor;
2210 if (list_debug_scopes) {
2211 struct weston_log_scope *nscope = NULL;
2213 weston_log("Printing available debug scopes:\n");
2215 while ((nscope = weston_log_scopes_iterate(log_ctx, nscope))) {
2216 weston_log("\tscope name: %s, desc: %s",
2217 weston_log_scope_get_name(nscope),
2218 weston_log_scope_get_description(nscope));
2223 goto error_compositor;
2226 add_bindings(ivi.compositor);
2228 if (ivi.remoting_api)
2229 ivi_enable_remote_outputs(&ivi);
2231 if (create_listening_socket(display, socket_name) < 0)
2232 goto error_compositor;
2234 ivi_shell_init_black_fs(&ivi);
2236 ivi.compositor->exit = handle_exit;
2238 weston_compositor_wake(ivi.compositor);
2240 ivi_shell_create_global(&ivi);
2242 ivi_launch_shell_client(&ivi, "shell-client",
2243 &ivi.shell_client.client);
2244 ivi_launch_shell_client(&ivi, "shell-client-ext",
2245 &ivi.shell_client_ext.client);
2248 weston_compositor_add_screenshot_authority(ivi.compositor,
2249 &ivi.screenshot_auth,
2250 screenshot_allow_all);
2252 ivi_agl_systemd_notify(&ivi);
2254 wl_display_run(display);
2256 ret = ivi.compositor->exit_code;
2258 wl_display_destroy_clients(display);
2266 weston_compositor_destroy(ivi.compositor);
2268 weston_log_scope_destroy(log_scope);
2271 weston_log_subscriber_destroy(logger);
2272 weston_log_ctx_destroy(log_ctx);
2274 ivi_policy_destroy(ivi.policy);
2276 wl_list_for_each_safe(process, process_tmp, &ivi.child_process_list, link)
2277 ivi_process_destroy(process, 0, false);
2280 for (size_t i = 0; i < ARRAY_LENGTH(signals); ++i)
2282 wl_event_source_remove(signals[i]);
2284 wl_display_destroy(display);
2288 weston_config_destroy(ivi.config);
2294 free(option_modules);