2 * Copyright © 2012-2021 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_HEADLESS
46 #include <libweston/backend-headless.h>
48 #ifdef HAVE_BACKEND_X11
49 #include <libweston/backend-x11.h>
51 #include <libweston/libweston.h>
52 #include <libweston/windowed-output-api.h>
53 #include <libweston/config-parser.h>
54 #include <libweston/weston-log.h>
57 #include "shared/os-compatibility.h"
58 #include "shared/helpers.h"
60 #include "agl-shell-server-protocol.h"
66 static int cached_tm_mday = -1;
67 static struct weston_log_scope *log_scope;
69 struct ivi_compositor *
70 to_ivi_compositor(struct weston_compositor *ec)
72 return weston_compositor_get_user_data(ec);
75 struct ivi_output_config *
76 ivi_init_parsed_options(struct weston_compositor *compositor)
78 struct ivi_compositor *ivi = to_ivi_compositor(compositor);
79 struct ivi_output_config *config;
81 config = zalloc(sizeof *config);
88 config->transform = UINT32_MAX;
90 ivi->parsed_options = config;
98 sigint_helper(int sig)
104 ivi_layout_save(struct ivi_compositor *ivi, struct ivi_output *output)
106 struct ivi_output *new_output;
107 ivi->need_ivi_output_relayout = true;
109 new_output = zalloc(sizeof(*new_output));
111 new_output->ivi = ivi;
112 new_output->background = output->background;
114 new_output->top = output->top;
115 new_output->bottom = output->bottom;
116 new_output->left = output->left;
117 new_output->right = output->right;
119 new_output->active = output->active;
120 new_output->previous_active = output->previous_active;
121 new_output->name = strdup(output->name);
123 new_output->app_ids = strdup(output->app_ids);
125 new_output->area = output->area;
126 new_output->area_saved = output->area_saved;
127 new_output->area_activation = output->area_activation;
129 weston_log("saving output layout for output %s\n", new_output->name);
131 wl_list_insert(&ivi->saved_outputs, &new_output->link);
135 ivi_layout_restore(struct ivi_compositor *ivi, struct ivi_output *n_output)
137 struct ivi_output *output = NULL;
138 struct ivi_output *iter_output;
140 if (!ivi->need_ivi_output_relayout)
143 ivi->need_ivi_output_relayout = false;
145 wl_list_for_each(iter_output, &ivi->saved_outputs, link) {
146 if (strcmp(n_output->name, iter_output->name) == 0) {
147 output = iter_output;
155 weston_log("restoring output layout for output %s\n", output->name);
156 n_output->background = output->background;
158 n_output->top = output->top;
159 n_output->bottom = output->bottom;
160 n_output->left = output->left;
161 n_output->right = output->right;
163 n_output->active = output->active;
164 n_output->previous_active = output->previous_active;
166 n_output->app_ids = strdup(output->app_ids);
168 n_output->area = output->area;
169 n_output->area_saved = output->area_saved;
170 n_output->area_activation = output->area_activation;
172 free(output->app_ids);
174 wl_list_remove(&output->link);
179 ivi_layout_destroy_saved_outputs(struct ivi_compositor *ivi)
181 struct ivi_output *output, *output_next;
183 wl_list_for_each_safe(output, output_next, &ivi->saved_outputs, link) {
184 free(output->app_ids);
187 wl_list_remove(&output->link);
193 handle_output_destroy(struct wl_listener *listener, void *data)
195 struct ivi_output *output;
197 output = wl_container_of(listener, output, output_destroy);
198 assert(output->output == data);
200 if (output->fullscreen_view.fs &&
201 output->fullscreen_view.fs->view) {
202 weston_surface_unref(output->fullscreen_view.fs->view->surface);
203 weston_buffer_destroy_solid(output->fullscreen_view.buffer_ref);
204 output->fullscreen_view.fs->view = NULL;
207 ivi_layout_save(output->ivi, output);
209 output->output = NULL;
210 wl_list_remove(&output->output_destroy.link);
214 to_ivi_output(struct weston_output *o)
216 struct wl_listener *listener;
217 struct ivi_output *output;
219 listener = weston_output_get_destroy_listener(o, handle_output_destroy);
220 output = wl_container_of(listener, output, output_destroy);
226 ivi_output_configure_app_id(struct ivi_output *ivi_output)
228 if (ivi_output->config) {
229 if (ivi_output->app_ids != NULL)
232 weston_config_section_get_string(ivi_output->config,
234 &ivi_output->app_ids,
237 if (ivi_output->app_ids == NULL)
240 weston_log("Will place app_id %s on output %s\n",
241 ivi_output->app_ids, ivi_output->name);
245 static struct ivi_output *
246 ivi_ensure_output(struct ivi_compositor *ivi, char *name,
247 struct weston_config_section *config,
248 struct weston_head *head)
250 struct ivi_output *output = NULL;
251 wl_list_for_each(output, &ivi->outputs, link) {
252 if (strcmp(output->name, name) == 0) {
258 output = zalloc(sizeof *output);
266 output->config = config;
268 if (ivi->simple_output_configure) {
270 weston_compositor_create_output_with_head(ivi->compositor,
272 if (!output->output) {
278 int ret = ivi->simple_output_configure(output->output);
280 weston_log("Configuring output \"%s\" failed.\n",
281 weston_head_get_name(head));
282 weston_output_destroy(output->output);
283 ivi->init_failed = true;
287 if (weston_output_enable(output->output) < 0) {
288 weston_log("Enabling output \"%s\" failed.\n",
289 weston_head_get_name(head));
290 weston_output_destroy(output->output);
291 ivi->init_failed = true;
297 weston_compositor_create_output(ivi->compositor, name);
298 if (!output->output) {
305 output->output_destroy.notify = handle_output_destroy;
306 weston_output_add_destroy_listener(output->output,
307 &output->output_destroy);
309 wl_list_insert(&ivi->outputs, &output->link);
310 ivi_output_configure_app_id(output);
315 count_heads(struct weston_output *output)
317 struct weston_head *iter = NULL;
320 while ((iter = weston_output_iterate_heads(output, iter)))
327 handle_head_destroy(struct wl_listener *listener, void *data)
329 struct weston_head *head = data;
330 struct weston_output *output;
332 wl_list_remove(&listener->link);
335 output = weston_head_get_output(head);
337 /* On shutdown path, the output might be already gone. */
341 /* We're the last head */
342 if (count_heads(output) <= 1)
343 weston_output_destroy(output);
347 add_head_destroyed_listener(struct weston_head *head)
349 /* We already have a destroy listener */
350 if (weston_head_get_destroy_listener(head, handle_head_destroy))
353 struct wl_listener *listener = zalloc(sizeof *listener);
357 listener->notify = handle_head_destroy;
358 weston_head_add_destroy_listener(head, listener);
362 drm_configure_output(struct ivi_output *output)
364 struct ivi_compositor *ivi = output->ivi;
365 struct weston_config_section *section = output->config;
366 enum weston_drm_backend_output_mode mode =
367 WESTON_DRM_BACKEND_OUTPUT_PREFERRED;
368 char *modeline = NULL;
369 char *gbm_format = NULL;
374 weston_config_section_get_string(section, "mode", &m, "preferred");
376 /* This should have been handled earlier */
377 assert(strcmp(m, "off") != 0);
379 if (ivi->cmdline.use_current_mode || strcmp(m, "current") == 0) {
380 mode = WESTON_DRM_BACKEND_OUTPUT_CURRENT;
381 } else if (strcmp(m, "preferred") != 0) {
387 weston_config_section_get_string(section, "gbm-format",
390 weston_config_section_get_string(section, "seat", &seat, "");
393 if (ivi->drm_api->set_mode(output->output, mode, modeline) < 0) {
394 weston_log("Cannot configure output using weston_drm_output_api.\n");
400 ivi->drm_api->set_gbm_format(output->output, gbm_format);
403 ivi->drm_api->set_seat(output->output, seat);
409 #define WINDOWED_DEFAULT_WIDTH 1024
410 #define WINDOWED_DEFAULT_HEIGHT 768
413 windowed_configure_output(struct ivi_output *output)
415 struct ivi_compositor *ivi = output->ivi;
416 struct weston_config_section *section = output->config;
417 int width = WINDOWED_DEFAULT_WIDTH;
418 int height = WINDOWED_DEFAULT_HEIGHT;
423 weston_config_section_get_string(section, "mode", &mode, NULL);
424 if (!mode || sscanf(mode, "%dx%d", &width, &height) != 2) {
425 weston_log("Invalid mode for output %s. Using defaults.\n",
427 width = WINDOWED_DEFAULT_WIDTH;
428 height = WINDOWED_DEFAULT_HEIGHT;
433 if (ivi->cmdline.width)
434 width = ivi->cmdline.width;
435 if (ivi->cmdline.height)
436 height = ivi->cmdline.height;
437 if (ivi->cmdline.scale)
438 weston_output_set_scale(output->output, ivi->cmdline.scale);
440 if (ivi->window_api->output_set_size(output->output, width, height) < 0) {
441 weston_log("Cannot configure output '%s' using weston_windowed_output_api.\n",
446 weston_log("Configured windowed_output_api to %dx%d\n", width, height);
452 parse_transform(const char *transform, uint32_t *out)
454 static const struct { const char *name; uint32_t token; } transforms[] = {
455 { "normal", WL_OUTPUT_TRANSFORM_NORMAL },
456 { "rotate-90", WL_OUTPUT_TRANSFORM_90 },
457 { "rotate-180", WL_OUTPUT_TRANSFORM_180 },
458 { "rotate-270", WL_OUTPUT_TRANSFORM_270 },
459 { "flipped", WL_OUTPUT_TRANSFORM_FLIPPED },
460 { "flipped-rotate-90", WL_OUTPUT_TRANSFORM_FLIPPED_90 },
461 { "flipped-rotate-180", WL_OUTPUT_TRANSFORM_FLIPPED_180 },
462 { "flipped-rotate-270", WL_OUTPUT_TRANSFORM_FLIPPED_270 },
465 for (size_t i = 0; i < ARRAY_LENGTH(transforms); i++)
466 if (strcmp(transforms[i].name, transform) == 0) {
467 *out = transforms[i].token;
471 *out = WL_OUTPUT_TRANSFORM_NORMAL;
476 parse_activation_area(const char *geometry, struct ivi_output *output)
479 unsigned width, height, x, y;
481 n = sscanf(geometry, "%ux%u+%u,%u", &width, &height, &x, &y);
485 output->area_activation.width = width;
486 output->area_activation.height = height;
487 output->area_activation.x = x;
488 output->area_activation.y = y;
493 configure_output(struct ivi_output *output)
495 struct ivi_compositor *ivi = output->ivi;
496 struct weston_config_section *section = output->config;
498 uint32_t transform = WL_OUTPUT_TRANSFORM_NORMAL;
501 * This can happen with the wayland backend with 'sprawl'. The config
502 * is hard-coded, so we don't need to do anything.
504 if (!ivi->drm_api && !ivi->window_api)
510 weston_config_section_get_int(section, "scale", &scale, 1);
511 weston_config_section_get_string(section, "transform", &t, "normal");
512 if (parse_transform(t, &transform) < 0)
513 weston_log("Invalid transform \"%s\" for output %s\n",
515 weston_config_section_get_string(section, "activation-area", &t, "");
516 if (parse_activation_area(t, output) < 0)
517 weston_log("Invalid activation-area \"%s\" for output %s\n",
522 weston_output_set_scale(output->output, scale);
523 weston_output_set_transform(output->output, transform);
526 return drm_configure_output(output);
528 return windowed_configure_output(output);
532 * Reorgainizes the output's add array into two sections.
533 * add[0..ret-1] are the heads that failed to get attached.
534 * add[ret..add_len] are the heads that were successfully attached.
536 * The order between elements in each section is stable.
539 try_attach_heads(struct ivi_output *output)
543 for (size_t i = 1; i < output->add_len; i++) {
544 if (weston_output_attach_head(output->output, output->add[i]) < 0) {
545 struct weston_head *tmp = output->add[i];
546 memmove(&output->add[fail_len + 1], output->add[fail_len],
547 sizeof output->add[0] * (i - fail_len));
548 output->add[fail_len++] = tmp;
554 /* Place output exactly to the right of the most recently enabled output.
556 * Historically, we haven't given much thought to output placement,
557 * simply adding outputs in a horizontal line as they're enabled. This
558 * function simply sets an output's x coordinate to the right of the
559 * most recently enabled output, and its y to zero.
561 * If you're adding new calls to this function, you're also not giving
562 * much thought to output placement, so please consider carefully if
563 * it's really doing what you want.
565 * You especially don't want to use this for any code that won't
566 * immediately enable the passed output.
569 weston_output_lazy_align(struct weston_output *output)
571 struct weston_compositor *c;
572 struct weston_output *peer;
575 /* Put this output to the right of the most recently enabled output */
576 c = output->compositor;
577 if (!wl_list_empty(&c->output_list)) {
578 peer = container_of(c->output_list.prev,
579 struct weston_output, link);
580 next_x = peer->x + peer->width;
588 * Like try_attach_heads, this reorganizes the output's add array into a failed
589 * and successful section.
590 * i is the number of heads that already failed the previous step.
593 try_enable_output(struct ivi_output *output, size_t i)
595 for (; i < output->add_len; ++i) {
596 struct weston_head *head;
598 weston_output_lazy_align(output->output);
600 if (weston_output_enable(output->output) == 0)
603 head = output->add[output->add_len - 1];
604 memmove(&output->add[i + 1], &output->add[i],
605 sizeof output->add[0] * (output->add_len - i));
606 output->add[i] = head;
608 weston_head_detach(head);
615 try_attach_enable_heads(struct ivi_output *output)
618 assert(!output->output->enabled);
620 fail_len = try_attach_heads(output);
622 if (configure_output(output) < 0)
625 fail_len = try_enable_output(output, fail_len);
627 /* All heads failed to be attached */
628 if (fail_len == output->add_len)
631 /* For each successful head attached */
632 for (size_t i = fail_len; i < output->add_len; ++i)
633 add_head_destroyed_listener(output->add[i]);
635 ivi_layout_restore(output->ivi, output);
637 output->add_len = fail_len;
642 process_output(struct ivi_output *output)
644 if (output->output->enabled) {
645 output->add_len = try_attach_heads(output);
646 return output->add_len == 0 ? 0 : -1;
649 return try_attach_enable_heads(output);
653 head_disable(struct ivi_compositor *ivi, struct weston_head *head)
655 struct weston_output *output;
656 struct ivi_output *ivi_output;
657 struct wl_listener *listener;
659 output = weston_head_get_output(head);
662 listener = weston_output_get_destroy_listener(output,
663 handle_output_destroy);
666 ivi_output = wl_container_of(listener, ivi_output, output_destroy);
667 assert(ivi_output->output == output);
669 weston_head_detach(head);
670 if (count_heads(ivi_output->output) == 0) {
671 if (ivi_output->output) {
672 /* ivi_output->output destruction may be deferred in
673 * some cases (see drm_output_destroy()), so we need to
674 * forcibly trigger the destruction callback now, or
675 * otherwise would later access data that we are about
678 struct weston_output *save = ivi_output->output;
680 handle_output_destroy(&ivi_output->output_destroy, save);
681 weston_output_destroy(save);
684 wl_list_remove(&ivi_output->link);
685 free(ivi_output->app_ids);
689 static struct weston_config_section *
690 find_controlling_output_config(struct weston_config *config,
693 struct weston_config_section *section;
697 same_as = strdup(name);
699 section = weston_config_get_section(config, "output",
701 if (!section && depth > 0)
702 weston_log("Configuration error: output section reffered"
703 "to by same-as=%s not found.\n", same_as);
710 weston_log("Configuration error: same-as nested too "
711 "deep for output '%s'.\n", name);
715 weston_config_section_get_string(section, "same-as",
723 head_prepare_enable(struct ivi_compositor *ivi, struct weston_head *head)
725 const char *name = weston_head_get_name(head);
726 struct weston_config_section *section;
727 struct ivi_output *output;
728 char *output_name = NULL;
731 section = find_controlling_output_config(ivi->config, name);
735 weston_config_section_get_string(section, "mode", &mode, NULL);
736 if (mode && strcmp(mode, "off") == 0) {
742 weston_config_section_get_string(section, "name",
745 output_name = strdup(name);
751 output = ivi_ensure_output(ivi, output_name, section, head);
755 if (output->add_len >= ARRAY_LENGTH(output->add))
758 output->add[output->add_len++] = head;
762 heads_changed(struct wl_listener *listener, void *arg)
764 struct weston_compositor *compositor = arg;
765 struct weston_head *head = NULL;
766 struct ivi_compositor *ivi = to_ivi_compositor(compositor);
767 struct ivi_output *output;
769 while ((head = weston_compositor_iterate_heads(ivi->compositor, head))) {
770 bool connected = weston_head_is_connected(head);
771 bool enabled = weston_head_is_enabled(head);
772 bool changed = weston_head_is_device_changed(head);
773 bool non_desktop = weston_head_is_non_desktop(head);
775 if (connected && !enabled && !non_desktop)
776 head_prepare_enable(ivi, head);
777 else if (!connected && enabled)
778 head_disable(ivi, head);
779 else if (enabled && changed)
780 weston_log("Detected a monitor change on head '%s', "
781 "not bothering to do anything about it.\n",
782 weston_head_get_name(head));
784 weston_head_reset_device_changed(head);
787 wl_list_for_each(output, &ivi->outputs, link) {
788 if (output->add_len == 0)
791 if (process_output(output) < 0) {
793 ivi->init_failed = true;
800 drm_backend_remoted_output_configure(struct weston_output *output,
801 struct weston_config_section *section,
803 const struct weston_remoting_api *api)
805 char *gbm_format = NULL;
808 char *pipeline = NULL;
811 uint32_t transform = WL_OUTPUT_TRANSFORM_NORMAL;
814 ret = api->set_mode(output, modeline);
816 weston_log("Cannot configure an output \"%s\" using "
817 "weston_remoting_api. Invalid mode\n",
822 weston_config_section_get_int(section, "scale", &scale, 1);
823 weston_output_set_scale(output, scale);
825 weston_config_section_get_string(section, "transform", &trans, "normal");
826 if (parse_transform(trans, &transform) < 0) {
827 weston_log("Invalid transform \"%s\" for output %s\n",
828 trans, output->name);
830 weston_output_set_transform(output, transform);
832 weston_config_section_get_string(section, "gbm-format",
834 api->set_gbm_format(output, gbm_format);
837 weston_config_section_get_string(section, "seat", &seat, "");
839 api->set_seat(output, seat);
842 weston_config_section_get_string(section, "gst-pipeline", &pipeline,
845 api->set_gst_pipeline(output, pipeline);
850 weston_config_section_get_string(section, "host", &host, NULL);
851 weston_config_section_get_int(section, "port", &port, 0);
852 if (!host || port <= 0 || 65533 < port) {
853 weston_log("Cannot configure an output \"%s\". "
854 "Need to specify gst-pipeline or "
855 "host and port (1-65533).\n", output->name);
857 api->set_host(output, host);
859 api->set_port(output, port);
866 remote_output_init(struct ivi_output *ivi_output,
867 struct weston_compositor *compositor,
868 struct weston_config_section *section,
869 const struct weston_remoting_api *api)
871 char *output_name, *modeline = NULL;
874 weston_config_section_get_string(section, "name", &output_name, NULL);
878 weston_config_section_get_string(section, "mode", &modeline, "off");
879 if (strcmp(modeline, "off") == 0)
882 ivi_output->output = api->create_output(compositor, output_name);
883 if (!ivi_output->output) {
884 weston_log("Cannot create remoted output \"%s\".\n",
889 ret = drm_backend_remoted_output_configure(ivi_output->output, section,
892 weston_log("Cannot configure remoted output \"%s\".\n",
897 if ((ret = weston_output_enable(ivi_output->output)) < 0) {
898 weston_log("Enabling remoted output \"%s\" failed.\n",
905 weston_log("remoted output '%s' enabled\n", ivi_output->output->name);
912 if (ivi_output->output)
913 weston_output_destroy(ivi_output->output);
919 ivi_enable_remote_outputs(struct ivi_compositor *ivi)
921 struct weston_config_section *remote_section = NULL;
922 const char *section_name;
923 struct weston_config *config = ivi->config;
925 while (weston_config_next_section(config, &remote_section, §ion_name)) {
926 if (strcmp(section_name, "remote-output"))
929 struct ivi_output *ivi_output = NULL;
930 bool output_found = false;
933 weston_config_section_get_string(remote_section,
934 "name", &_name, NULL);
935 wl_list_for_each(ivi_output, &ivi->outputs, link) {
936 if (!strcmp(ivi_output->name, _name)) {
947 ivi_output = zalloc(sizeof(*ivi_output));
953 ivi_output->ivi = ivi;
954 ivi_output->name = _name;
955 ivi_output->config = remote_section;
956 ivi_output->type = OUTPUT_REMOTE;
958 if (remote_output_init(ivi_output, ivi->compositor,
959 remote_section, ivi->remoting_api)) {
960 free(ivi_output->name);
965 ivi_output->output_destroy.notify = handle_output_destroy;
966 weston_output_add_destroy_listener(ivi_output->output,
967 &ivi_output->output_destroy);
969 wl_list_insert(&ivi->outputs, &ivi_output->link);
970 ivi_output_configure_app_id(ivi_output);
975 load_remoting_plugin(struct ivi_compositor *ivi, struct weston_config *config)
977 struct weston_compositor *compositor = ivi->compositor;
978 int (*module_init)(struct weston_compositor *wc);
980 module_init = weston_load_module("remoting-plugin.so",
981 "weston_module_init");
985 if (module_init(compositor) < 0)
988 ivi->remoting_api = weston_remoting_get_api(compositor);
989 if (!ivi->remoting_api)
995 load_remoting_plugin(struct weston_compositor *compositor, struct weston_config *config)
1002 load_drm_backend(struct ivi_compositor *ivi, int *argc, char *argv[])
1004 struct weston_drm_backend_config config = {
1006 .struct_version = WESTON_DRM_BACKEND_CONFIG_VERSION,
1007 .struct_size = sizeof config,
1010 struct weston_config_section *section;
1011 int use_current_mode = 0;
1014 bool without_input = false;
1017 const struct weston_option options[] = {
1018 { WESTON_OPTION_STRING, "seat", 0, &config.seat_id },
1019 { WESTON_OPTION_STRING, "drm-device", 0, &config.specific_device },
1020 { WESTON_OPTION_BOOLEAN, "current-mode", 0, &use_current_mode },
1021 { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &use_pixman },
1022 { WESTON_OPTION_BOOLEAN, "continue-without-input", false, &without_input }
1025 parse_options(options, ARRAY_LENGTH(options), argc, argv);
1026 config.use_pixman = use_pixman;
1027 ivi->cmdline.use_current_mode = use_current_mode;
1029 section = weston_config_get_section(ivi->config, "core", NULL, NULL);
1030 weston_config_section_get_string(section, "gbm-format",
1031 &config.gbm_format, NULL);
1032 weston_config_section_get_uint(section, "pageflip-timeout",
1033 &config.pageflip_timeout, 0);
1034 weston_config_section_get_bool(section, "pixman-shadow", &use_shadow, 1);
1035 config.use_pixman_shadow = use_shadow;
1038 ivi->compositor->require_input = !without_input;
1040 ret = weston_compositor_load_backend(ivi->compositor, WESTON_BACKEND_DRM,
1045 ivi->drm_api = weston_drm_output_get_api(ivi->compositor);
1046 if (!ivi->drm_api) {
1047 weston_log("Cannot use drm output api.\n");
1052 load_remoting_plugin(ivi, ivi->config);
1055 free(config.gbm_format);
1056 free(config.seat_id);
1061 windowed_parse_common_options(struct ivi_compositor *ivi, int *argc, char *argv[],
1062 bool *use_pixman, bool *fullscreen, int *output_count)
1064 struct weston_config_section *section;
1068 const struct weston_option options[] = {
1069 { WESTON_OPTION_INTEGER, "width", 0, &ivi->cmdline.width },
1070 { WESTON_OPTION_INTEGER, "height", 0, &ivi->cmdline.height },
1071 { WESTON_OPTION_INTEGER, "scale", 0, &ivi->cmdline.scale },
1072 { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &pixman },
1073 { WESTON_OPTION_BOOLEAN, "fullscreen", 0, &fs },
1074 { WESTON_OPTION_INTEGER, "output-count", 0, output_count },
1077 section = weston_config_get_section(ivi->config, "core", NULL, NULL);
1078 weston_config_section_get_bool(section, "use-pixman", &pixman, 0);
1081 parse_options(options, ARRAY_LENGTH(options), argc, argv);
1082 *use_pixman = pixman;
1087 windowed_create_outputs(struct ivi_compositor *ivi, int output_count,
1088 const char *match_prefix, const char *name_prefix)
1090 struct weston_config_section *section = NULL;
1091 const char *section_name;
1092 char *default_output = NULL;
1094 size_t match_len = strlen(match_prefix);
1096 while (weston_config_next_section(ivi->config, §ion, §ion_name)) {
1099 if (i >= output_count)
1102 if (strcmp(section_name, "output") != 0)
1105 weston_config_section_get_string(section, "name", &output_name, NULL);
1106 if (output_name == NULL)
1108 if (strncmp(output_name, match_prefix, match_len) != 0) {
1113 if (ivi->window_api->create_head(ivi->compositor, output_name) < 0) {
1122 for (; i < output_count; ++i) {
1123 if (asprintf(&default_output, "%s%d", name_prefix, i) < 0)
1126 if (ivi->window_api->create_head(ivi->compositor, default_output) < 0) {
1127 free(default_output);
1131 free(default_output);
1138 load_wayland_backend(struct ivi_compositor *ivi, int *argc, char *argv[])
1140 struct weston_wayland_backend_config config = {
1142 .struct_version = WESTON_WAYLAND_BACKEND_CONFIG_VERSION,
1143 .struct_size = sizeof config,
1146 struct weston_config_section *section;
1151 const struct weston_option options[] = {
1152 { WESTON_OPTION_STRING, "display", 0, &config.display_name },
1153 { WESTON_OPTION_STRING, "sprawl", 0, &sprawl },
1156 windowed_parse_common_options(ivi, argc, argv, &config.use_pixman,
1157 &config.fullscreen, &output_count);
1159 parse_options(options, ARRAY_LENGTH(options), argc, argv);
1160 config.sprawl = sprawl;
1162 section = weston_config_get_section(ivi->config, "shell", NULL, NULL);
1163 weston_config_section_get_string(section, "cursor-theme",
1164 &config.cursor_theme, NULL);
1165 weston_config_section_get_int(section, "cursor-size",
1166 &config.cursor_size, 32);
1168 ret = weston_compositor_load_backend(ivi->compositor, WESTON_BACKEND_WAYLAND,
1171 free(config.cursor_theme);
1172 free(config.display_name);
1177 ivi->window_api = weston_windowed_output_get_api(ivi->compositor);
1180 * We will just assume if load_backend() finished cleanly and
1181 * windowed_output_api is not present that wayland backend is started
1182 * with --sprawl or runs on fullscreen-shell. In this case, all values
1183 * are hardcoded, so nothing can be configured; simply create and
1186 if (ivi->window_api == NULL)
1189 return windowed_create_outputs(ivi, output_count, "WL", "wayland");
1192 #ifdef HAVE_BACKEND_X11
1194 load_x11_backend(struct ivi_compositor *ivi, int *argc, char *argv[])
1196 struct weston_x11_backend_config config = {
1198 .struct_version = WESTON_X11_BACKEND_CONFIG_VERSION,
1199 .struct_size = sizeof config,
1206 const struct weston_option options[] = {
1207 { WESTON_OPTION_BOOLEAN, "no-input", 0, &no_input },
1210 windowed_parse_common_options(ivi, argc, argv, &config.use_pixman,
1211 &config.fullscreen, &output_count);
1213 parse_options(options, ARRAY_LENGTH(options), argc, argv);
1214 config.no_input = no_input;
1216 ret = weston_compositor_load_backend(ivi->compositor, WESTON_BACKEND_X11,
1222 ivi->window_api = weston_windowed_output_get_api(ivi->compositor);
1223 if (!ivi->window_api) {
1224 weston_log("Cannot use weston_windowed_output_api.\n");
1228 return windowed_create_outputs(ivi, output_count, "X", "screen");
1232 load_x11_backend(struct ivi_compositor *ivi, int *argc, char *argv[])
1238 #ifdef HAVE_BACKEND_HEADLESS
1240 load_headless_backend(struct ivi_compositor *ivi, int *argc, char **argv)
1242 struct weston_headless_backend_config config = {};
1250 struct weston_compositor *c = ivi->compositor;
1252 const struct weston_option options[] = {
1253 { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &use_pixman },
1254 { WESTON_OPTION_BOOLEAN, "use-gl", 0, &use_gl },
1257 windowed_parse_common_options(ivi, argc, argv, &use_pixman,
1258 &fullscreen, &output_count);
1260 parse_options(options, ARRAY_LENGTH(options), argc, argv);
1261 config.use_pixman = use_pixman;
1262 config.use_gl = use_gl;
1264 config.base.struct_version = WESTON_HEADLESS_BACKEND_CONFIG_VERSION;
1265 config.base.struct_size = sizeof(struct weston_headless_backend_config);
1267 /* load the actual headless-backend and configure it */
1268 ret = weston_compositor_load_backend(c, WESTON_BACKEND_HEADLESS,
1273 ivi->window_api = weston_windowed_output_get_api(c);
1274 if (!ivi->window_api) {
1275 weston_log("Cannot use weston_windowed_output_api.\n");
1279 if (ivi->window_api->create_head(c, "headless") < 0) {
1280 weston_log("Cannot create headless back-end\n");
1288 load_headless_backend(struct ivi_compositor *ivi, int *argc, char **argv)
1294 #ifdef HAVE_BACKEND_RDP
1296 weston_rdp_backend_config_init(struct weston_rdp_backend_config *config)
1298 config->base.struct_version = WESTON_RDP_BACKEND_CONFIG_VERSION;
1299 config->base.struct_size = sizeof(struct weston_rdp_backend_config);
1301 config->bind_address = NULL;
1302 config->port = 3389;
1303 config->rdp_key = NULL;
1304 config->server_cert = NULL;
1305 config->server_key = NULL;
1306 config->env_socket = 0;
1307 config->no_clients_resize = 1;
1308 config->force_no_compression = 0;
1312 rdp_backend_output_configure(struct weston_output *output)
1314 struct ivi_compositor *ivi = to_ivi_compositor(output->compositor);
1315 struct ivi_output_config *parsed_options = ivi->parsed_options;
1316 const struct weston_rdp_output_api *api =
1317 weston_rdp_output_get_api(output->compositor);
1320 struct weston_config_section *section;
1321 uint32_t transform = WL_OUTPUT_TRANSFORM_NORMAL;
1322 char *transform_string;
1324 assert(parsed_options);
1327 weston_log("Cannot use weston_rdp_output_api.\n");
1331 section = weston_config_get_section(ivi->config, "rdp", NULL, NULL);
1333 if (parsed_options->width)
1334 width = parsed_options->width;
1336 if (parsed_options->height)
1337 height = parsed_options->height;
1339 weston_output_set_scale(output, 1);
1341 weston_config_section_get_int(section, "width",
1344 weston_config_section_get_int(section, "height",
1347 if (parsed_options->transform)
1348 transform = parsed_options->transform;
1350 weston_config_section_get_string(section, "transform",
1351 &transform_string, "normal");
1353 if (parse_transform(transform_string, &transform) < 0) {
1354 weston_log("Invalid transform \"%s\" for output %s\n",
1355 transform_string, output->name);
1359 weston_output_set_transform(output, transform);
1361 if (api->output_set_size(output, width, height) < 0) {
1362 weston_log("Cannot configure output \"%s\" using weston_rdp_output_api.\n",
1371 load_rdp_backend(struct ivi_compositor *ivi, int *argc, char **argv)
1373 struct weston_rdp_backend_config config = {};
1375 struct weston_config_section *section;
1377 struct ivi_output_config *parsed_options = ivi_init_parsed_options(ivi->compositor);
1378 if (!parsed_options)
1381 weston_rdp_backend_config_init(&config);
1383 const struct weston_option rdp_options[] = {
1384 { WESTON_OPTION_BOOLEAN, "env-socket", 0, &config.env_socket },
1385 { WESTON_OPTION_INTEGER, "width", 0, &parsed_options->width },
1386 { WESTON_OPTION_INTEGER, "height", 0, &parsed_options->height },
1387 { WESTON_OPTION_INTEGER, "transform", 0, &parsed_options->transform },
1388 { WESTON_OPTION_INTEGER, "scale", 0, &parsed_options->scale },
1389 { WESTON_OPTION_STRING, "address", 0, &config.bind_address },
1390 { WESTON_OPTION_INTEGER, "port", 0, &config.port },
1391 { WESTON_OPTION_BOOLEAN, "no-clients-resize", 0, &config.no_clients_resize },
1392 { WESTON_OPTION_STRING, "rdp4-key", 0, &config.rdp_key },
1393 { WESTON_OPTION_STRING, "rdp-tls-cert", 0, &config.server_cert },
1394 { WESTON_OPTION_STRING, "rdp-tls-key", 0, &config.server_key },
1395 { WESTON_OPTION_BOOLEAN, "force-no-compression", 0, &config.force_no_compression },
1398 section = weston_config_get_section(ivi->config, "rdp", NULL, NULL);
1400 weston_config_section_get_string(section, "tls-cert",
1401 &config.server_cert, config.server_cert);
1403 weston_config_section_get_string(section, "tls-key",
1404 &config.server_key, config.server_key);
1407 parse_options(rdp_options, ARRAY_LENGTH(rdp_options), argc, argv);
1409 ivi->simple_output_configure = rdp_backend_output_configure;
1410 ret = weston_compositor_load_backend(ivi->compositor, WESTON_BACKEND_RDP, &config.base);
1412 free(config.bind_address);
1413 free(config.rdp_key);
1414 free(config.server_cert);
1415 free(config.server_key);
1421 load_rdp_backend(struct ivi_compositor *ivi, int *argc, char **argv)
1429 load_backend(struct ivi_compositor *ivi, const char *backend,
1430 int *argc, char *argv[])
1432 if (strcmp(backend, "drm-backend.so") == 0) {
1433 return load_drm_backend(ivi, argc, argv);
1434 } else if (strcmp(backend, "wayland-backend.so") == 0) {
1435 return load_wayland_backend(ivi, argc, argv);
1436 } else if (strcmp(backend, "x11-backend.so") == 0) {
1437 return load_x11_backend(ivi, argc, argv);
1438 } else if (strcmp(backend, "headless-backend.so") == 0) {
1439 return load_headless_backend(ivi, argc, argv);
1440 } else if (strcmp(backend, "rdp-backend.so") == 0) {
1441 return load_rdp_backend(ivi, argc, argv);
1444 weston_log("fatal: unknown backend '%s'.\n", backend);
1449 load_modules(struct ivi_compositor *ivi, const char *modules,
1450 int *argc, char *argv[], bool *xwayland)
1452 const char *p, *end;
1454 int (*module_init)(struct weston_compositor *wc, int argc, char *argv[]);
1456 if (modules == NULL)
1461 end = strchrnul(p, ',');
1462 snprintf(buffer, sizeof buffer, "%.*s", (int) (end - p), p);
1464 if (strstr(buffer, "xwayland.so")) {
1466 } else if (strstr(buffer, "systemd-notify.so")) {
1467 weston_log("systemd-notify plug-in already loaded!\n");
1469 module_init = weston_load_module(buffer, "wet_module_init");
1473 if (module_init(ivi->compositor, *argc, argv) < 0)
1488 choose_default_backend(void)
1490 char *backend = NULL;
1492 if (getenv("WAYLAND_DISPLAY") || getenv("WAYLAND_SOCKET"))
1493 backend = strdup("wayland-backend.so");
1494 else if (getenv("DISPLAY"))
1495 backend = strdup("x11-backend.so");
1497 backend = strdup("drm-backend.so");
1503 compositor_init_config(struct ivi_compositor *ivi)
1505 struct xkb_rule_names xkb_names;
1506 struct weston_config_section *section;
1507 struct weston_compositor *compositor = ivi->compositor;
1508 struct weston_config *config = ivi->config;
1513 /* agl-compositor.ini [keyboard] */
1514 section = weston_config_get_section(config, "keyboard", NULL, NULL);
1515 weston_config_section_get_string(section, "keymap_rules",
1516 (char **) &xkb_names.rules, NULL);
1517 weston_config_section_get_string(section, "keymap_model",
1518 (char **) &xkb_names.model, NULL);
1519 weston_config_section_get_string(section, "keymap_layout",
1520 (char **) &xkb_names.layout, NULL);
1521 weston_config_section_get_string(section, "keymap_variant",
1522 (char **) &xkb_names.variant, NULL);
1523 weston_config_section_get_string(section, "keymap_options",
1524 (char **) &xkb_names.options, NULL);
1526 if (weston_compositor_set_xkb_rule_names(compositor, &xkb_names) < 0)
1529 weston_config_section_get_int(section, "repeat-rate",
1530 &compositor->kb_repeat_rate, 40);
1531 weston_config_section_get_int(section, "repeat-delay",
1532 &compositor->kb_repeat_delay, 400);
1534 weston_config_section_get_bool(section, "vt-switching",
1535 &vt_switching, false);
1536 compositor->vt_switching = vt_switching;
1538 /* agl-compositor.ini [core] */
1539 section = weston_config_get_section(config, "core", NULL, NULL);
1541 weston_config_section_get_bool(section, "disable-cursor",
1542 &ivi->disable_cursor, false);
1543 weston_config_section_get_bool(section, "activate-by-default",
1544 &ivi->activate_by_default, true);
1546 weston_config_section_get_bool(section, "require-input", &require_input, true);
1547 compositor->require_input = require_input;
1549 weston_config_section_get_int(section, "repaint-window", &repaint_msec,
1550 compositor->repaint_msec);
1551 if (repaint_msec < -10 || repaint_msec > 1000) {
1552 weston_log("Invalid repaint_window value in config: %d\n",
1555 compositor->repaint_msec = repaint_msec;
1557 weston_log("Output repaint window is %d ms maximum.\n",
1558 compositor->repaint_msec);
1563 struct ivi_surface *
1564 to_ivi_surface(struct weston_surface *surface)
1566 struct weston_desktop_surface *dsurface;
1568 dsurface = weston_surface_get_desktop_surface(surface);
1572 return weston_desktop_surface_get_user_data(dsurface);
1576 activate_binding(struct weston_seat *seat,
1577 struct weston_view *focus_view, uint32_t flags)
1579 struct weston_surface *focus_surface;
1580 struct weston_surface *main_surface;
1581 struct ivi_surface *ivi_surface;
1582 struct ivi_shell_seat *ivi_seat = get_ivi_shell_seat(seat);
1587 focus_surface = focus_view->surface;
1588 main_surface = weston_surface_get_main_surface(focus_surface);
1590 ivi_surface = to_ivi_surface(main_surface);
1595 ivi_shell_activate_surface(ivi_surface, ivi_seat, flags);
1599 click_to_activate_binding(struct weston_pointer *pointer,
1600 const struct timespec *time,
1601 uint32_t button, void *data)
1603 if (pointer->grab != &pointer->default_grab)
1605 if (pointer->focus == NULL)
1608 activate_binding(pointer->seat, pointer->focus,
1609 WESTON_ACTIVATE_FLAG_CLICKED);
1613 touch_to_activate_binding(struct weston_touch *touch,
1614 const struct timespec *time,
1617 if (touch->grab != &touch->default_grab)
1619 if (touch->focus == NULL)
1622 activate_binding(touch->seat, touch->focus,
1623 WESTON_ACTIVATE_FLAG_NONE);
1627 add_bindings(struct weston_compositor *compositor)
1629 weston_compositor_add_button_binding(compositor, BTN_LEFT, 0,
1630 click_to_activate_binding,
1632 weston_compositor_add_button_binding(compositor, BTN_RIGHT, 0,
1633 click_to_activate_binding,
1635 weston_compositor_add_touch_binding(compositor, 0,
1636 touch_to_activate_binding,
1641 create_listening_socket(struct wl_display *display, const char *socket_name)
1644 if (wl_display_add_socket(display, socket_name)) {
1645 weston_log("fatal: failed to add socket: %s\n",
1650 socket_name = wl_display_add_socket_auto(display);
1652 weston_log("fatal: failed to add socket: %s\n",
1658 setenv("WAYLAND_DISPLAY", socket_name, 1);
1664 global_filter(const struct wl_client *client, const struct wl_global *global,
1671 load_config(struct weston_config **config, bool no_config,
1672 const char *config_file)
1674 const char *file = "agl-compositor.ini";
1675 const char *full_path;
1681 *config = weston_config_parse(file);
1684 full_path = weston_config_get_full_path(*config);
1686 weston_log("Using config file '%s'.\n", full_path);
1687 setenv(WESTON_CONFIG_FILE_ENV_VAR, full_path, 1);
1692 if (config_file && !no_config) {
1693 weston_log("fatal: error opening or reading config file '%s'.\n",
1699 weston_log("Starting with no config file.\n");
1700 setenv(WESTON_CONFIG_FILE_ENV_VAR, "", 1);
1705 static FILE *logfile;
1708 log_timestamp(char *buf, size_t len)
1711 struct tm *brokendown_time;
1715 gettimeofday(&tv, NULL);
1717 brokendown_time = localtime(&tv.tv_sec);
1718 if (brokendown_time == NULL) {
1719 snprintf(buf, len, "%s", "[(NULL)localtime] ");
1723 memset(datestr, 0, sizeof(datestr));
1724 if (brokendown_time->tm_mday != cached_tm_mday) {
1725 strftime(datestr, sizeof(datestr), "Date: %Y-%m-%d %Z\n",
1727 cached_tm_mday = brokendown_time->tm_mday;
1730 strftime(timestr, sizeof(timestr), "%H:%M:%S", brokendown_time);
1731 /* if datestr is empty it prints only timestr*/
1732 snprintf(buf, len, "%s[%s.%03li]", datestr,
1733 timestr, (tv.tv_usec / 1000));
1739 custom_handler(const char *fmt, va_list arg)
1743 weston_log_scope_printf(log_scope, "%s libwayland: ",
1744 log_timestamp(timestr, sizeof(timestr)));
1745 weston_log_scope_vprintf(log_scope, fmt, arg);
1749 log_file_open(const char *filename)
1751 wl_log_set_handler_server(custom_handler);
1754 logfile = fopen(filename, "a");
1759 os_fd_set_cloexec(fileno(logfile));
1760 setvbuf(logfile, NULL, _IOLBF, 256);
1765 log_file_close(void)
1767 if (logfile && logfile != stderr)
1773 vlog(const char *fmt, va_list ap)
1775 const char *oom = "Out of memory";
1780 if (weston_log_scope_is_enabled(log_scope)) {
1782 char *xlog_timestamp = log_timestamp(timestr, sizeof(timestr));
1783 len_va = vasprintf(&str, fmt, ap);
1785 len = weston_log_scope_printf(log_scope, "%s %s",
1786 xlog_timestamp, str);
1789 len = weston_log_scope_printf(log_scope, "%s %s",
1790 xlog_timestamp, oom);
1799 vlog_continue(const char *fmt, va_list ap)
1801 return weston_log_scope_vprintf(log_scope, fmt, ap);
1805 on_term_signal(int signo, void *data)
1807 struct wl_display *display = data;
1809 weston_log("caught signal %d\n", signo);
1810 wl_display_terminate(display);
1816 handle_exit(struct weston_compositor *compositor)
1818 wl_display_terminate(compositor->wl_display);
1822 usage(int error_code)
1824 FILE *out = error_code == EXIT_SUCCESS ? stdout : stderr;
1826 "Usage: agl-compositor [OPTIONS]\n"
1828 "This is " PACKAGE_STRING ", the reference compositor for\n"
1829 "Automotive Grade Linux. " PACKAGE_STRING " supports multiple "
1830 "backends,\nand depending on which backend is in use different "
1831 "options will be accepted.\n"
1835 " --version\t\tPrint agl-compositor version\n"
1836 " -B, --backend=MODULE\tBackend module, one of\n"
1837 "\t\t\t\tdrm-backend.so\n"
1838 "\t\t\t\twayland-backend.so\n"
1839 "\t\t\t\tx11-backend.so\n"
1840 "\t\t\t\theadless-backend.so\n"
1841 " -S, --socket=NAME\tName of socket to listen on\n"
1842 " --log=FILE\t\tLog to the given file\n"
1843 " -c, --config=FILE\tConfig file to load, defaults to agl-compositor.ini\n"
1844 " --no-config\t\tDo not read agl-compositor.ini\n"
1845 " --debug\t\tEnable debug extension(s)\n"
1846 " -h, --help\t\tThis help message\n"
1852 copy_command_line(int argc, char * const argv[])
1859 fp = open_memstream(&str, &size);
1863 fprintf(fp, "%s", argv[0]);
1864 for (i = 1; i < argc; i++)
1865 fprintf(fp, " %s", argv[i]);
1871 #if !defined(BUILD_XWAYLAND)
1873 wet_load_xwayland(struct weston_compositor *comp)
1875 weston_log("Attempted to load xwayland library but compositor "
1876 "was *not* built with xwayland support!\n");
1882 weston_log_setup_scopes(struct weston_log_context *log_ctx,
1883 struct weston_log_subscriber *subscriber,
1889 char *tokenize = strdup(names);
1890 char *token = strtok(tokenize, ",");
1892 weston_log_subscribe(log_ctx, subscriber, token);
1893 token = strtok(NULL, ",");
1899 weston_log_subscribe_to_scopes(struct weston_log_context *log_ctx,
1900 struct weston_log_subscriber *logger,
1901 const char *debug_scopes)
1903 if (logger && debug_scopes)
1904 weston_log_setup_scopes(log_ctx, logger, debug_scopes);
1906 weston_log_subscribe(log_ctx, logger, "log");
1910 int wet_main(int argc, char *argv[], const struct weston_testsuite_data *test_data)
1912 struct ivi_compositor ivi = { 0 };
1914 struct wl_display *display = NULL;
1915 struct wl_event_loop *loop;
1916 struct wl_event_source *signals[3] = { 0 };
1917 struct weston_config_section *section;
1918 /* Command line options */
1919 char *backend = NULL;
1920 char *socket_name = NULL;
1922 char *modules = NULL;
1923 char *option_modules = NULL;
1924 char *debug_scopes = NULL;
1929 bool list_debug_scopes = false;
1930 char *config_file = NULL;
1931 struct weston_log_context *log_ctx = NULL;
1932 struct weston_log_subscriber *logger;
1933 int ret = EXIT_FAILURE;
1934 bool xwayland = false;
1935 struct sigaction action;
1937 const struct weston_option core_options[] = {
1938 { WESTON_OPTION_STRING, "backend", 'B', &backend },
1939 { WESTON_OPTION_STRING, "socket", 'S', &socket_name },
1940 { WESTON_OPTION_STRING, "log", 0, &log },
1941 { WESTON_OPTION_BOOLEAN, "help", 'h', &help },
1942 { WESTON_OPTION_BOOLEAN, "version", 0, &version },
1943 { WESTON_OPTION_BOOLEAN, "no-config", 0, &no_config },
1944 { WESTON_OPTION_BOOLEAN, "debug", 0, &debug },
1945 { WESTON_OPTION_STRING, "config", 'c', &config_file },
1946 { WESTON_OPTION_STRING, "modules", 0, &option_modules },
1947 { WESTON_OPTION_STRING, "debug-scopes", 'l', &debug_scopes },
1948 { WESTON_OPTION_STRING, "list-debug-scopes", 'L', &list_debug_scopes },
1951 wl_list_init(&ivi.outputs);
1952 wl_list_init(&ivi.saved_outputs);
1953 wl_list_init(&ivi.surfaces);
1954 wl_list_init(&ivi.pending_surfaces);
1955 wl_list_init(&ivi.popup_pending_apps);
1956 wl_list_init(&ivi.fullscreen_pending_apps);
1957 wl_list_init(&ivi.split_pending_apps);
1958 wl_list_init(&ivi.remote_pending_apps);
1959 wl_list_init(&ivi.desktop_clients);
1960 wl_list_init(&ivi.child_process_list);
1961 wl_list_init(&ivi.pending_apps);
1963 /* Prevent any clients we spawn getting our stdin */
1964 os_fd_set_cloexec(STDIN_FILENO);
1966 cmdline = copy_command_line(argc, argv);
1967 parse_options(core_options, ARRAY_LENGTH(core_options), &argc, argv);
1970 usage(EXIT_SUCCESS);
1973 printf(PACKAGE_STRING "\n");
1978 log_ctx = weston_log_ctx_create();
1980 fprintf(stderr, "Failed to initialize weston debug framework.\n");
1984 log_scope = weston_log_ctx_add_log_scope(log_ctx, "log",
1985 "agl-compositor log\n",
1989 weston_log_set_handler(vlog, vlog_continue);
1991 logger = weston_log_subscriber_create_log(logfile);
1992 weston_log_subscribe_to_scopes(log_ctx, logger, debug_scopes);
1994 weston_log("Command line: %s\n", cmdline);
1997 if (load_config(&ivi.config, no_config, config_file) < 0)
1999 section = weston_config_get_section(ivi.config, "core", NULL, NULL);
2001 weston_config_section_get_string(section, "backend", &backend,
2004 backend = choose_default_backend();
2007 display = wl_display_create();
2008 loop = wl_display_get_event_loop(display);
2010 wl_display_set_global_filter(display,
2011 global_filter, &ivi);
2013 /* Register signal handlers so we shut down cleanly */
2015 signals[0] = wl_event_loop_add_signal(loop, SIGTERM, on_term_signal,
2017 signals[1] = wl_event_loop_add_signal(loop, SIGUSR2, on_term_signal,
2019 signals[2] = wl_event_loop_add_signal(loop, SIGCHLD, sigchld_handler,
2022 /* When debugging the compositor, if use wl_event_loop_add_signal() to
2023 * catch SIGINT, the debugger can't catch it, and attempting to stop
2024 * the compositor from within the debugger results in weston exiting
2027 * Instead, use the sigaction() function, which sets up the signal in a
2028 * way that gdb can successfully catch, but have the handler for SIGINT
2029 * send SIGUSR2 (xwayland uses SIGUSR1), which we catch via
2030 * wl_event_loop_add_signal().
2032 action.sa_handler = sigint_helper;
2033 sigemptyset(&action.sa_mask);
2034 action.sa_flags = 0;
2035 sigaction(SIGINT, &action, NULL);
2037 for (size_t i = 0; i < ARRAY_LENGTH(signals); ++i)
2041 ivi.compositor = weston_compositor_create(display, log_ctx, &ivi, test_data);
2042 if (!ivi.compositor) {
2043 weston_log("fatal: failed to create compositor.\n");
2047 if (compositor_init_config(&ivi) < 0)
2048 goto error_compositor;
2050 if (load_backend(&ivi, backend, &argc, argv) < 0) {
2051 weston_log("fatal: failed to create compositor backend.\n");
2052 goto error_compositor;
2055 ivi.heads_changed.notify = heads_changed;
2056 weston_compositor_add_heads_changed_listener(ivi.compositor,
2057 &ivi.heads_changed);
2059 weston_compositor_flush_heads_changed(ivi.compositor);
2060 if (ivi_desktop_init(&ivi) < 0)
2061 goto error_compositor;
2063 ivi_seat_init(&ivi);
2065 /* load additional modules */
2066 weston_config_section_get_string(section, "modules", &modules, "");
2067 if (load_modules(&ivi, modules, &argc, argv, &xwayland) < 0)
2068 goto error_compositor;
2070 if (load_modules(&ivi, option_modules, &argc, argv, &xwayland) < 0)
2071 goto error_compositor;
2074 weston_config_section_get_bool(section, "xwayland", &xwayland,
2078 if (ivi_shell_init(&ivi) < 0)
2079 goto error_compositor;
2082 if (wet_load_xwayland(ivi.compositor) < 0)
2083 goto error_compositor;
2086 if (ivi_policy_init(&ivi) < 0)
2087 goto error_compositor;
2090 if (list_debug_scopes) {
2091 struct weston_log_scope *nscope = NULL;
2093 weston_log("Printing available debug scopes:\n");
2095 while ((nscope = weston_log_scopes_iterate(log_ctx, nscope))) {
2096 weston_log("\tscope name: %s, desc: %s",
2097 weston_log_scope_get_name(nscope),
2098 weston_log_scope_get_description(nscope));
2103 goto error_compositor;
2106 add_bindings(ivi.compositor);
2108 if (ivi.remoting_api)
2109 ivi_enable_remote_outputs(&ivi);
2111 if (create_listening_socket(display, socket_name) < 0)
2112 goto error_compositor;
2114 ivi_shell_init_black_fs(&ivi);
2116 ivi.compositor->exit = handle_exit;
2118 weston_compositor_wake(ivi.compositor);
2120 ivi_shell_create_global(&ivi);
2122 ivi_launch_shell_client(&ivi, "shell-client",
2123 &ivi.shell_client.client);
2124 ivi_launch_shell_client(&ivi, "shell-client-ext",
2125 &ivi.shell_client_ext.client);
2128 ivi_screenshooter_create(&ivi);
2129 ivi_agl_systemd_notify(&ivi);
2131 wl_display_run(display);
2133 ret = ivi.compositor->exit_code;
2135 wl_display_destroy_clients(display);
2143 weston_compositor_destroy(ivi.compositor);
2145 weston_log_scope_destroy(log_scope);
2148 weston_log_subscriber_destroy(logger);
2149 weston_log_ctx_destroy(log_ctx);
2151 ivi_policy_destroy(ivi.policy);
2154 for (size_t i = 0; i < ARRAY_LENGTH(signals); ++i)
2156 wl_event_source_remove(signals[i]);
2158 wl_display_destroy(display);
2162 weston_config_destroy(ivi.config);
2168 free(option_modules);