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"
61 #include "agl-shell-server-protocol.h"
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);
76 struct ivi_output_config *
77 ivi_init_parsed_options(struct weston_compositor *compositor)
79 struct ivi_compositor *ivi = to_ivi_compositor(compositor);
80 struct ivi_output_config *config;
82 config = zalloc(sizeof *config);
89 config->transform = UINT32_MAX;
91 ivi->parsed_options = config;
99 sigint_helper(int sig)
106 enum weston_renderer_type renderer;
107 } renderer_name_map[] = {
108 { "auto", WESTON_RENDERER_AUTO },
109 { "gl", WESTON_RENDERER_GL },
110 { "noop", WESTON_RENDERER_NOOP },
111 { "pixman", WESTON_RENDERER_PIXMAN },
117 enum weston_compositor_backend backend;
118 } backend_name_map[] = {
119 { "drm", "drm-backend.so", WESTON_BACKEND_DRM },
120 { "headless", "headless-backend.so", WESTON_BACKEND_HEADLESS },
121 { "pipewire", "pipewire-backend.so", WESTON_BACKEND_PIPEWIRE },
122 { "rdp", "rdp-backend.so", WESTON_BACKEND_RDP },
123 { "vnc", "vnc-backend.so", WESTON_BACKEND_VNC },
124 { "wayland", "wayland-backend.so", WESTON_BACKEND_WAYLAND },
125 { "x11", "x11-backend.so", WESTON_BACKEND_X11 },
129 get_backend_from_string(const char *name,
130 enum weston_compositor_backend *backend)
134 for (i = 0; i < ARRAY_LENGTH(backend_name_map); i++) {
135 if (strcmp(name, backend_name_map[i].short_name) == 0 ||
136 strcmp(name, backend_name_map[i].long_name) == 0) {
137 *backend = backend_name_map[i].backend;
147 get_renderer_from_string(const char *name, enum weston_renderer_type *renderer)
154 for (i = 0; i < ARRAY_LENGTH(renderer_name_map); i++) {
155 if (strcmp(name, renderer_name_map[i].name) == 0) {
156 *renderer = renderer_name_map[i].renderer;
166 ivi_layout_save(struct ivi_compositor *ivi, struct ivi_output *output)
168 struct ivi_output *new_output;
169 ivi->need_ivi_output_relayout = true;
171 new_output = zalloc(sizeof(*new_output));
173 new_output->ivi = ivi;
174 new_output->background = output->background;
176 new_output->top = output->top;
177 new_output->bottom = output->bottom;
178 new_output->left = output->left;
179 new_output->right = output->right;
181 new_output->active = output->active;
182 new_output->previous_active = output->previous_active;
183 new_output->name = strdup(output->name);
185 new_output->app_ids = strdup(output->app_ids);
187 new_output->area = output->area;
188 new_output->area_saved = output->area_saved;
189 new_output->area_activation = output->area_activation;
191 weston_log("saving output layout for output %s\n", new_output->name);
193 wl_list_insert(&ivi->saved_outputs, &new_output->link);
197 ivi_layout_restore(struct ivi_compositor *ivi, struct ivi_output *n_output)
199 struct ivi_output *output = NULL;
200 struct ivi_output *iter_output;
202 if (!ivi->need_ivi_output_relayout)
205 ivi->need_ivi_output_relayout = false;
207 wl_list_for_each(iter_output, &ivi->saved_outputs, link) {
208 if (strcmp(n_output->name, iter_output->name) == 0) {
209 output = iter_output;
217 weston_log("restoring output layout for output %s\n", output->name);
218 n_output->background = output->background;
220 n_output->top = output->top;
221 n_output->bottom = output->bottom;
222 n_output->left = output->left;
223 n_output->right = output->right;
225 n_output->active = output->active;
226 n_output->previous_active = output->previous_active;
228 n_output->app_ids = strdup(output->app_ids);
230 n_output->area = output->area;
231 n_output->area_saved = output->area_saved;
232 n_output->area_activation = output->area_activation;
234 free(output->app_ids);
236 wl_list_remove(&output->link);
241 ivi_layout_destroy_saved_outputs(struct ivi_compositor *ivi)
243 struct ivi_output *output, *output_next;
245 wl_list_for_each_safe(output, output_next, &ivi->saved_outputs, link) {
246 free(output->app_ids);
249 wl_list_remove(&output->link);
255 handle_output_destroy(struct wl_listener *listener, void *data)
257 struct ivi_output *output;
259 output = wl_container_of(listener, output, output_destroy);
260 assert(output->output == data);
262 if (output->fullscreen_view.fs &&
263 output->fullscreen_view.fs->view) {
264 weston_surface_unref(output->fullscreen_view.fs->view->surface);
265 weston_buffer_destroy_solid(output->fullscreen_view.buffer_ref);
266 output->fullscreen_view.fs->view = NULL;
269 ivi_layout_save(output->ivi, output);
271 output->output = NULL;
272 wl_list_remove(&output->output_destroy.link);
276 to_ivi_output(struct weston_output *o)
278 struct wl_listener *listener;
279 struct ivi_output *output;
281 listener = weston_output_get_destroy_listener(o, handle_output_destroy);
282 output = wl_container_of(listener, output, output_destroy);
288 ivi_output_configure_app_id(struct ivi_output *ivi_output)
290 if (ivi_output->config) {
291 if (ivi_output->app_ids != NULL)
294 weston_config_section_get_string(ivi_output->config,
296 &ivi_output->app_ids,
299 if (ivi_output->app_ids == NULL)
302 weston_log("Will place app_id %s on output %s\n",
303 ivi_output->app_ids, ivi_output->name);
307 static struct ivi_output *
308 ivi_ensure_output(struct ivi_compositor *ivi, char *name,
309 struct weston_config_section *config,
310 struct weston_head *head)
312 struct ivi_output *output = NULL;
313 wl_list_for_each(output, &ivi->outputs, link) {
314 if (strcmp(output->name, name) == 0) {
320 output = zalloc(sizeof *output);
328 output->config = config;
330 if (ivi->simple_output_configure) {
332 weston_compositor_create_output_with_head(ivi->compositor,
334 if (!output->output) {
340 int ret = ivi->simple_output_configure(output->output);
342 weston_log("Configuring output \"%s\" failed.\n",
343 weston_head_get_name(head));
344 weston_output_destroy(output->output);
345 ivi->init_failed = true;
349 if (weston_output_enable(output->output) < 0) {
350 weston_log("Enabling output \"%s\" failed.\n",
351 weston_head_get_name(head));
352 weston_output_destroy(output->output);
353 ivi->init_failed = true;
359 weston_compositor_create_output(ivi->compositor, name);
360 if (!output->output) {
367 output->output_destroy.notify = handle_output_destroy;
368 weston_output_add_destroy_listener(output->output,
369 &output->output_destroy);
371 wl_list_insert(&ivi->outputs, &output->link);
372 ivi_output_configure_app_id(output);
377 count_heads(struct weston_output *output)
379 struct weston_head *iter = NULL;
382 while ((iter = weston_output_iterate_heads(output, iter)))
389 handle_head_destroy(struct wl_listener *listener, void *data)
391 struct weston_head *head = data;
392 struct weston_output *output;
394 wl_list_remove(&listener->link);
397 output = weston_head_get_output(head);
399 /* On shutdown path, the output might be already gone. */
403 /* We're the last head */
404 if (count_heads(output) <= 1)
405 weston_output_destroy(output);
409 add_head_destroyed_listener(struct weston_head *head)
411 /* We already have a destroy listener */
412 if (weston_head_get_destroy_listener(head, handle_head_destroy))
415 struct wl_listener *listener = zalloc(sizeof *listener);
419 listener->notify = handle_head_destroy;
420 weston_head_add_destroy_listener(head, listener);
424 drm_configure_output(struct ivi_output *output)
426 struct ivi_compositor *ivi = output->ivi;
427 struct weston_config_section *section = output->config;
428 enum weston_drm_backend_output_mode mode =
429 WESTON_DRM_BACKEND_OUTPUT_PREFERRED;
430 char *modeline = NULL;
431 char *gbm_format = NULL;
436 weston_config_section_get_string(section, "mode", &m, "preferred");
438 /* This should have been handled earlier */
439 assert(strcmp(m, "off") != 0);
441 if (ivi->cmdline.use_current_mode || strcmp(m, "current") == 0) {
442 mode = WESTON_DRM_BACKEND_OUTPUT_CURRENT;
443 } else if (strcmp(m, "preferred") != 0) {
449 weston_config_section_get_string(section, "gbm-format",
452 weston_config_section_get_string(section, "seat", &seat, "");
455 if (ivi->drm_api->set_mode(output->output, mode, modeline) < 0) {
456 weston_log("Cannot configure output using weston_drm_output_api.\n");
462 ivi->drm_api->set_gbm_format(output->output, gbm_format);
465 ivi->drm_api->set_seat(output->output, seat);
471 #define WINDOWED_DEFAULT_WIDTH 1024
472 #define WINDOWED_DEFAULT_HEIGHT 768
475 windowed_configure_output(struct ivi_output *output)
477 struct ivi_compositor *ivi = output->ivi;
478 struct weston_config_section *section = output->config;
479 int width = WINDOWED_DEFAULT_WIDTH;
480 int height = WINDOWED_DEFAULT_HEIGHT;
485 weston_config_section_get_string(section, "mode", &mode, NULL);
486 if (!mode || sscanf(mode, "%dx%d", &width, &height) != 2) {
487 weston_log("Invalid mode for output %s. Using defaults.\n",
489 width = WINDOWED_DEFAULT_WIDTH;
490 height = WINDOWED_DEFAULT_HEIGHT;
495 if (ivi->cmdline.width)
496 width = ivi->cmdline.width;
497 if (ivi->cmdline.height)
498 height = ivi->cmdline.height;
499 if (ivi->cmdline.scale)
500 weston_output_set_scale(output->output, ivi->cmdline.scale);
502 if (ivi->window_api->output_set_size(output->output, width, height) < 0) {
503 weston_log("Cannot configure output '%s' using weston_windowed_output_api.\n",
508 weston_log("Configured windowed_output_api to %dx%d\n", width, height);
514 parse_transform(const char *transform, uint32_t *out)
516 static const struct { const char *name; uint32_t token; } transforms[] = {
517 { "normal", WL_OUTPUT_TRANSFORM_NORMAL },
518 { "rotate-90", WL_OUTPUT_TRANSFORM_90 },
519 { "rotate-180", WL_OUTPUT_TRANSFORM_180 },
520 { "rotate-270", WL_OUTPUT_TRANSFORM_270 },
521 { "flipped", WL_OUTPUT_TRANSFORM_FLIPPED },
522 { "flipped-rotate-90", WL_OUTPUT_TRANSFORM_FLIPPED_90 },
523 { "flipped-rotate-180", WL_OUTPUT_TRANSFORM_FLIPPED_180 },
524 { "flipped-rotate-270", WL_OUTPUT_TRANSFORM_FLIPPED_270 },
527 for (size_t i = 0; i < ARRAY_LENGTH(transforms); i++)
528 if (strcmp(transforms[i].name, transform) == 0) {
529 *out = transforms[i].token;
533 *out = WL_OUTPUT_TRANSFORM_NORMAL;
538 parse_activation_area(const char *geometry, struct ivi_output *output)
541 unsigned width, height, x, y;
543 n = sscanf(geometry, "%ux%u+%u,%u", &width, &height, &x, &y);
547 output->area_activation.width = width;
548 output->area_activation.height = height;
549 output->area_activation.x = x;
550 output->area_activation.y = y;
555 configure_output(struct ivi_output *output)
557 struct ivi_compositor *ivi = output->ivi;
558 struct weston_config_section *section = output->config;
560 uint32_t transform = WL_OUTPUT_TRANSFORM_NORMAL;
563 * This can happen with the wayland backend with 'sprawl'. The config
564 * is hard-coded, so we don't need to do anything.
566 if (!ivi->drm_api && !ivi->window_api)
572 weston_config_section_get_int(section, "scale", &scale, 1);
573 weston_config_section_get_string(section, "transform", &t, "normal");
574 if (parse_transform(t, &transform) < 0)
575 weston_log("Invalid transform \"%s\" for output %s\n",
577 weston_config_section_get_string(section, "activation-area", &t, "");
578 if (parse_activation_area(t, output) < 0)
579 weston_log("Invalid activation-area \"%s\" for output %s\n",
584 weston_output_set_scale(output->output, scale);
585 weston_output_set_transform(output->output, transform);
588 return drm_configure_output(output);
590 return windowed_configure_output(output);
594 * Reorgainizes the output's add array into two sections.
595 * add[0..ret-1] are the heads that failed to get attached.
596 * add[ret..add_len] are the heads that were successfully attached.
598 * The order between elements in each section is stable.
601 try_attach_heads(struct ivi_output *output)
605 for (size_t i = 1; i < output->add_len; i++) {
606 if (weston_output_attach_head(output->output, output->add[i]) < 0) {
607 struct weston_head *tmp = output->add[i];
608 memmove(&output->add[fail_len + 1], output->add[fail_len],
609 sizeof output->add[0] * (i - fail_len));
610 output->add[fail_len++] = tmp;
616 /* Place output exactly to the right of the most recently enabled output.
618 * Historically, we haven't given much thought to output placement,
619 * simply adding outputs in a horizontal line as they're enabled. This
620 * function simply sets an output's x coordinate to the right of the
621 * most recently enabled output, and its y to zero.
623 * If you're adding new calls to this function, you're also not giving
624 * much thought to output placement, so please consider carefully if
625 * it's really doing what you want.
627 * You especially don't want to use this for any code that won't
628 * immediately enable the passed output.
631 weston_output_lazy_align(struct weston_output *output)
633 struct weston_compositor *c;
634 struct weston_output *peer;
637 /* Put this output to the right of the most recently enabled output */
638 c = output->compositor;
639 if (!wl_list_empty(&c->output_list)) {
640 peer = container_of(c->output_list.prev,
641 struct weston_output, link);
642 next_x = peer->pos.c.x + peer->width;
644 output->pos.c.x = next_x;
650 * Like try_attach_heads, this reorganizes the output's add array into a failed
651 * and successful section.
652 * i is the number of heads that already failed the previous step.
655 try_enable_output(struct ivi_output *output, size_t i)
657 for (; i < output->add_len; ++i) {
658 struct weston_head *head;
660 weston_output_lazy_align(output->output);
662 if (weston_output_enable(output->output) == 0)
665 head = output->add[output->add_len - 1];
666 memmove(&output->add[i + 1], &output->add[i],
667 sizeof output->add[0] * (output->add_len - i));
668 output->add[i] = head;
670 weston_head_detach(head);
677 try_attach_enable_heads(struct ivi_output *output)
680 assert(!output->output->enabled);
682 fail_len = try_attach_heads(output);
684 if (configure_output(output) < 0)
687 fail_len = try_enable_output(output, fail_len);
689 /* All heads failed to be attached */
690 if (fail_len == output->add_len)
693 /* For each successful head attached */
694 for (size_t i = fail_len; i < output->add_len; ++i)
695 add_head_destroyed_listener(output->add[i]);
697 ivi_layout_restore(output->ivi, output);
699 output->add_len = fail_len;
704 process_output(struct ivi_output *output)
706 if (output->output->enabled) {
707 output->add_len = try_attach_heads(output);
708 return output->add_len == 0 ? 0 : -1;
711 return try_attach_enable_heads(output);
715 head_disable(struct ivi_compositor *ivi, struct weston_head *head)
717 struct weston_output *output;
718 struct ivi_output *ivi_output;
719 struct wl_listener *listener;
721 output = weston_head_get_output(head);
724 listener = weston_output_get_destroy_listener(output,
725 handle_output_destroy);
728 ivi_output = wl_container_of(listener, ivi_output, output_destroy);
729 assert(ivi_output->output == output);
731 weston_head_detach(head);
732 if (count_heads(ivi_output->output) == 0) {
733 if (ivi_output->output) {
734 /* ivi_output->output destruction may be deferred in
735 * some cases (see drm_output_destroy()), so we need to
736 * forcibly trigger the destruction callback now, or
737 * otherwise would later access data that we are about
740 struct weston_output *save = ivi_output->output;
742 handle_output_destroy(&ivi_output->output_destroy, save);
743 weston_output_destroy(save);
746 wl_list_remove(&ivi_output->link);
747 free(ivi_output->app_ids);
751 static struct weston_config_section *
752 find_controlling_output_config(struct weston_config *config,
755 struct weston_config_section *section;
759 same_as = strdup(name);
761 section = weston_config_get_section(config, "output",
763 if (!section && depth > 0)
764 weston_log("Configuration error: output section reffered"
765 "to by same-as=%s not found.\n", same_as);
772 weston_log("Configuration error: same-as nested too "
773 "deep for output '%s'.\n", name);
777 weston_config_section_get_string(section, "same-as",
785 head_prepare_enable(struct ivi_compositor *ivi, struct weston_head *head)
787 const char *name = weston_head_get_name(head);
788 struct weston_config_section *section;
789 struct ivi_output *output;
790 char *output_name = NULL;
793 section = find_controlling_output_config(ivi->config, name);
797 weston_config_section_get_string(section, "mode", &mode, NULL);
798 if (mode && strcmp(mode, "off") == 0) {
804 weston_config_section_get_string(section, "name",
807 output_name = strdup(name);
813 output = ivi_ensure_output(ivi, output_name, section, head);
817 if (output->add_len >= ARRAY_LENGTH(output->add))
820 output->add[output->add_len++] = head;
824 heads_changed(struct wl_listener *listener, void *arg)
826 struct weston_compositor *compositor = arg;
827 struct weston_head *head = NULL;
828 struct ivi_compositor *ivi = to_ivi_compositor(compositor);
829 struct ivi_output *output;
831 while ((head = weston_compositor_iterate_heads(ivi->compositor, head))) {
832 bool connected = weston_head_is_connected(head);
833 bool enabled = weston_head_is_enabled(head);
834 bool changed = weston_head_is_device_changed(head);
835 bool non_desktop = weston_head_is_non_desktop(head);
837 if (connected && !enabled && !non_desktop)
838 head_prepare_enable(ivi, head);
839 else if (!connected && enabled)
840 head_disable(ivi, head);
841 else if (enabled && changed)
842 weston_log("Detected a monitor change on head '%s', "
843 "not bothering to do anything about it.\n",
844 weston_head_get_name(head));
846 weston_head_reset_device_changed(head);
849 wl_list_for_each(output, &ivi->outputs, link) {
850 if (output->add_len == 0)
853 if (process_output(output) < 0) {
855 ivi->init_failed = true;
862 drm_backend_remoted_output_configure(struct weston_output *output,
863 struct weston_config_section *section,
865 const struct weston_remoting_api *api)
867 char *gbm_format = NULL;
870 char *pipeline = NULL;
873 uint32_t transform = WL_OUTPUT_TRANSFORM_NORMAL;
876 ret = api->set_mode(output, modeline);
878 weston_log("Cannot configure an output \"%s\" using "
879 "weston_remoting_api. Invalid mode\n",
884 weston_config_section_get_int(section, "scale", &scale, 1);
885 weston_output_set_scale(output, scale);
887 weston_config_section_get_string(section, "transform", &trans, "normal");
888 if (parse_transform(trans, &transform) < 0) {
889 weston_log("Invalid transform \"%s\" for output %s\n",
890 trans, output->name);
892 weston_output_set_transform(output, transform);
894 weston_config_section_get_string(section, "gbm-format",
896 api->set_gbm_format(output, gbm_format);
899 weston_config_section_get_string(section, "seat", &seat, "");
901 api->set_seat(output, seat);
904 weston_config_section_get_string(section, "gst-pipeline", &pipeline,
907 api->set_gst_pipeline(output, pipeline);
912 weston_config_section_get_string(section, "host", &host, NULL);
913 weston_config_section_get_int(section, "port", &port, 0);
914 if (!host || port <= 0 || 65533 < port) {
915 weston_log("Cannot configure an output \"%s\". "
916 "Need to specify gst-pipeline or "
917 "host and port (1-65533).\n", output->name);
919 api->set_host(output, host);
921 api->set_port(output, port);
928 remote_output_init(struct ivi_output *ivi_output,
929 struct weston_compositor *compositor,
930 struct weston_config_section *section,
931 const struct weston_remoting_api *api)
933 char *output_name, *modeline = NULL;
936 weston_config_section_get_string(section, "name", &output_name, NULL);
940 weston_config_section_get_string(section, "mode", &modeline, "off");
941 if (strcmp(modeline, "off") == 0)
944 ivi_output->output = api->create_output(compositor, output_name);
945 if (!ivi_output->output) {
946 weston_log("Cannot create remoted output \"%s\".\n",
951 ret = drm_backend_remoted_output_configure(ivi_output->output, section,
954 weston_log("Cannot configure remoted output \"%s\".\n",
959 if ((ret = weston_output_enable(ivi_output->output)) < 0) {
960 weston_log("Enabling remoted output \"%s\" failed.\n",
967 weston_log("remoted output '%s' enabled\n", ivi_output->output->name);
974 if (ivi_output->output)
975 weston_output_destroy(ivi_output->output);
981 ivi_enable_remote_outputs(struct ivi_compositor *ivi)
983 struct weston_config_section *remote_section = NULL;
984 const char *section_name;
985 struct weston_config *config = ivi->config;
987 while (weston_config_next_section(config, &remote_section, §ion_name)) {
988 if (strcmp(section_name, "remote-output"))
991 struct ivi_output *ivi_output = NULL;
992 bool output_found = false;
995 weston_config_section_get_string(remote_section,
996 "name", &_name, NULL);
997 wl_list_for_each(ivi_output, &ivi->outputs, link) {
998 if (!strcmp(ivi_output->name, _name)) {
1009 ivi_output = zalloc(sizeof(*ivi_output));
1015 ivi_output->ivi = ivi;
1016 ivi_output->name = _name;
1017 ivi_output->config = remote_section;
1018 ivi_output->type = OUTPUT_REMOTE;
1020 if (remote_output_init(ivi_output, ivi->compositor,
1021 remote_section, ivi->remoting_api)) {
1022 free(ivi_output->name);
1027 ivi_output->output_destroy.notify = handle_output_destroy;
1028 weston_output_add_destroy_listener(ivi_output->output,
1029 &ivi_output->output_destroy);
1031 wl_list_insert(&ivi->outputs, &ivi_output->link);
1032 ivi_output_configure_app_id(ivi_output);
1037 load_remoting_plugin(struct ivi_compositor *ivi, struct weston_config *config)
1039 struct weston_compositor *compositor = ivi->compositor;
1040 int (*module_init)(struct weston_compositor *wc);
1042 module_init = weston_load_module("remoting-plugin.so",
1043 "weston_module_init",
1044 LIBWESTON_MODULEDIR);
1048 if (module_init(compositor) < 0)
1051 ivi->remoting_api = weston_remoting_get_api(compositor);
1052 if (!ivi->remoting_api)
1058 load_remoting_plugin(struct weston_compositor *compositor, struct weston_config *config)
1065 load_drm_backend(struct ivi_compositor *ivi, int *argc, char *argv[],
1066 enum weston_renderer_type renderer)
1068 struct weston_drm_backend_config config = {
1070 .struct_version = WESTON_DRM_BACKEND_CONFIG_VERSION,
1071 .struct_size = sizeof config,
1074 struct weston_config_section *section;
1075 int use_current_mode = 0;
1076 bool force_pixman = false;
1078 bool without_input = false;
1080 const struct weston_option options[] = {
1081 { WESTON_OPTION_STRING, "seat", 0, &config.seat_id },
1082 { WESTON_OPTION_STRING, "drm-device", 0, &config.specific_device },
1083 { WESTON_OPTION_BOOLEAN, "current-mode", 0, &use_current_mode },
1084 { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &force_pixman },
1085 { WESTON_OPTION_BOOLEAN, "continue-without-input", false, &without_input }
1088 parse_options(options, ARRAY_LENGTH(options), argc, argv);
1091 config.renderer = WESTON_RENDERER_PIXMAN;
1093 config.renderer = WESTON_RENDERER_AUTO;
1095 ivi->cmdline.use_current_mode = use_current_mode;
1097 section = weston_config_get_section(ivi->config, "core", NULL, NULL);
1098 weston_config_section_get_string(section, "gbm-format",
1099 &config.gbm_format, NULL);
1100 weston_config_section_get_uint(section, "pageflip-timeout",
1101 &config.pageflip_timeout, 0);
1102 weston_config_section_get_bool(section, "pixman-shadow", &use_shadow, 1);
1103 config.use_pixman_shadow = use_shadow;
1106 ivi->compositor->require_input = !without_input;
1108 if (!weston_compositor_load_backend(ivi->compositor, WESTON_BACKEND_DRM,
1112 ivi->drm_api = weston_drm_output_get_api(ivi->compositor);
1113 if (!ivi->drm_api) {
1114 weston_log("Cannot use drm output api.\n");
1118 load_remoting_plugin(ivi, ivi->config);
1121 free(config.gbm_format);
1122 free(config.seat_id);
1127 windowed_parse_common_options(struct ivi_compositor *ivi, int *argc, char *argv[],
1128 bool *force_pixman, bool *fullscreen, int *output_count)
1130 struct weston_config_section *section;
1134 const struct weston_option options[] = {
1135 { WESTON_OPTION_INTEGER, "width", 0, &ivi->cmdline.width },
1136 { WESTON_OPTION_INTEGER, "height", 0, &ivi->cmdline.height },
1137 { WESTON_OPTION_INTEGER, "scale", 0, &ivi->cmdline.scale },
1138 { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &force_pixman },
1139 { WESTON_OPTION_BOOLEAN, "fullscreen", 0, &fs },
1140 { WESTON_OPTION_INTEGER, "output-count", 0, output_count },
1143 section = weston_config_get_section(ivi->config, "core", NULL, NULL);
1144 weston_config_section_get_bool(section, "use-pixman", &pixman, false);
1147 parse_options(options, ARRAY_LENGTH(options), argc, argv);
1148 *force_pixman = pixman;
1153 windowed_create_outputs(struct ivi_compositor *ivi, int output_count,
1154 const char *match_prefix, const char *name_prefix)
1156 struct weston_config_section *section = NULL;
1157 const char *section_name;
1158 char *default_output = NULL;
1160 size_t match_len = strlen(match_prefix);
1162 while (weston_config_next_section(ivi->config, §ion, §ion_name)) {
1165 if (i >= output_count)
1168 if (strcmp(section_name, "output") != 0)
1171 weston_config_section_get_string(section, "name", &output_name, NULL);
1172 if (output_name == NULL)
1174 if (strncmp(output_name, match_prefix, match_len) != 0) {
1179 if (ivi->window_api->create_head(ivi->backend, output_name) < 0) {
1188 for (; i < output_count; ++i) {
1189 if (asprintf(&default_output, "%s%d", name_prefix, i) < 0)
1192 if (ivi->window_api->create_head(ivi->backend, default_output) < 0) {
1193 free(default_output);
1197 free(default_output);
1204 load_wayland_backend(struct ivi_compositor *ivi, int *argc, char *argv[],
1205 enum weston_renderer_type renderer)
1207 struct weston_wayland_backend_config config = {
1209 .struct_version = WESTON_WAYLAND_BACKEND_CONFIG_VERSION,
1210 .struct_size = sizeof config,
1213 struct weston_config_section *section;
1216 bool force_pixman = false;
1218 const struct weston_option options[] = {
1219 { WESTON_OPTION_STRING, "display", 0, &config.display_name },
1220 { WESTON_OPTION_STRING, "sprawl", 0, &sprawl },
1223 windowed_parse_common_options(ivi, argc, argv, &force_pixman,
1224 &config.fullscreen, &output_count);
1226 parse_options(options, ARRAY_LENGTH(options), argc, argv);
1227 config.sprawl = sprawl;
1229 section = weston_config_get_section(ivi->config, "shell", NULL, NULL);
1230 weston_config_section_get_string(section, "cursor-theme",
1231 &config.cursor_theme, NULL);
1232 weston_config_section_get_int(section, "cursor-size",
1233 &config.cursor_size, 32);
1235 ivi->backend = weston_compositor_load_backend(ivi->compositor, WESTON_BACKEND_WAYLAND,
1238 free(config.cursor_theme);
1239 free(config.display_name);
1244 ivi->window_api = weston_windowed_output_get_api(ivi->compositor);
1247 * We will just assume if load_backend() finished cleanly and
1248 * windowed_output_api is not present that wayland backend is started
1249 * with --sprawl or runs on fullscreen-shell. In this case, all values
1250 * are hardcoded, so nothing can be configured; simply create and
1253 if (ivi->window_api == NULL)
1256 return windowed_create_outputs(ivi, output_count, "WL", "wayland");
1259 #ifdef HAVE_BACKEND_X11
1261 load_x11_backend(struct ivi_compositor *ivi, int *argc, char *argv[],
1262 enum weston_renderer_type renderer)
1264 struct weston_x11_backend_config config = {
1266 .struct_version = WESTON_X11_BACKEND_CONFIG_VERSION,
1267 .struct_size = sizeof config,
1273 bool force_pixman = false;
1275 const struct weston_option options[] = {
1276 { WESTON_OPTION_BOOLEAN, "no-input", 0, &no_input },
1279 windowed_parse_common_options(ivi, argc, argv, &force_pixman,
1280 &config.fullscreen, &output_count);
1282 parse_options(options, ARRAY_LENGTH(options), argc, argv);
1284 config.renderer = WESTON_RENDERER_PIXMAN;
1286 config.renderer = WESTON_RENDERER_AUTO;
1287 config.no_input = no_input;
1289 ret = weston_compositor_load_backend(ivi->compositor, WESTON_BACKEND_X11,
1295 ivi->window_api = weston_windowed_output_get_api(ivi->compositor);
1296 if (!ivi->window_api) {
1297 weston_log("Cannot use weston_windowed_output_api.\n");
1301 return windowed_create_outputs(ivi, output_count, "X", "screen");
1305 load_x11_backend(struct ivi_compositor *ivi, int *argc, char **argv,
1306 enum weston_renderer_type renderer)
1312 #ifdef HAVE_BACKEND_HEADLESS
1314 load_headless_backend(struct ivi_compositor *ivi, int *argc, char **argv,
1315 enum weston_renderer_type renderer)
1317 struct weston_headless_backend_config config = {};
1320 bool force_pixman = false;
1322 bool force_gl = false;
1325 struct weston_compositor *c = ivi->compositor;
1327 const struct weston_option options[] = {
1328 { WESTON_OPTION_BOOLEAN, "use-pixman", false, &force_pixman },
1329 { WESTON_OPTION_BOOLEAN, "use-gl", false, &force_gl },
1332 windowed_parse_common_options(ivi, argc, argv, &force_pixman,
1333 &fullscreen, &output_count);
1335 parse_options(options, ARRAY_LENGTH(options), argc, argv);
1337 if ((force_pixman && force_gl) ||
1338 (renderer != WESTON_RENDERER_AUTO && (force_pixman || force_gl))) {
1339 weston_log("Conflicting renderer specifications\n");
1341 } else if (force_pixman) {
1342 config.renderer = WESTON_RENDERER_PIXMAN;
1343 } else if (force_gl) {
1344 config.renderer = WESTON_RENDERER_GL;
1346 config.renderer = renderer;
1349 config.base.struct_version = WESTON_HEADLESS_BACKEND_CONFIG_VERSION;
1350 config.base.struct_size = sizeof(struct weston_headless_backend_config);
1352 /* load the actual headless-backend and configure it */
1353 ret = weston_compositor_load_backend(c, WESTON_BACKEND_HEADLESS,
1358 ivi->window_api = weston_windowed_output_get_api(c);
1359 if (!ivi->window_api) {
1360 weston_log("Cannot use weston_windowed_output_api.\n");
1364 if (ivi->window_api->create_head(c->backend, "headless") < 0) {
1365 weston_log("Cannot create headless back-end\n");
1373 load_headless_backend(struct ivi_compositor *ivi, int *argc, char **argv, enum weston_renderer_type renderer)
1379 #ifdef HAVE_BACKEND_RDP
1381 weston_rdp_backend_config_init(struct weston_rdp_backend_config *config)
1383 config->base.struct_version = WESTON_RDP_BACKEND_CONFIG_VERSION;
1384 config->base.struct_size = sizeof(struct weston_rdp_backend_config);
1386 config->bind_address = NULL;
1387 config->port = 3389;
1388 config->rdp_key = NULL;
1389 config->server_cert = NULL;
1390 config->server_key = NULL;
1391 config->env_socket = 0;
1392 config->no_clients_resize = 1;
1393 config->force_no_compression = 0;
1397 rdp_backend_output_configure(struct weston_output *output)
1399 struct ivi_compositor *ivi = to_ivi_compositor(output->compositor);
1400 struct ivi_output_config *parsed_options = ivi->parsed_options;
1401 const struct weston_rdp_output_api *api =
1402 weston_rdp_output_get_api(output->compositor);
1405 struct weston_config_section *section;
1406 uint32_t transform = WL_OUTPUT_TRANSFORM_NORMAL;
1407 char *transform_string;
1409 assert(parsed_options);
1412 weston_log("Cannot use weston_rdp_output_api.\n");
1416 section = weston_config_get_section(ivi->config, "rdp", NULL, NULL);
1418 if (parsed_options->width)
1419 width = parsed_options->width;
1421 if (parsed_options->height)
1422 height = parsed_options->height;
1424 weston_output_set_scale(output, 1);
1426 weston_config_section_get_int(section, "width",
1429 weston_config_section_get_int(section, "height",
1432 if (parsed_options->transform)
1433 transform = parsed_options->transform;
1435 weston_config_section_get_string(section, "transform",
1436 &transform_string, "normal");
1438 if (parse_transform(transform_string, &transform) < 0) {
1439 weston_log("Invalid transform \"%s\" for output %s\n",
1440 transform_string, output->name);
1444 weston_output_set_transform(output, transform);
1446 if (api->output_set_size(output, width, height) < 0) {
1447 weston_log("Cannot configure output \"%s\" using weston_rdp_output_api.\n",
1456 load_rdp_backend(struct ivi_compositor *ivi, int *argc, char **argv)
1458 struct weston_rdp_backend_config config = {};
1460 struct weston_config_section *section;
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, "width", 0, &parsed_options->width },
1471 { WESTON_OPTION_INTEGER, "height", 0, &parsed_options->height },
1472 { WESTON_OPTION_INTEGER, "transform", 0, &parsed_options->transform },
1473 { WESTON_OPTION_INTEGER, "scale", 0, &parsed_options->scale },
1474 { WESTON_OPTION_STRING, "address", 0, &config.bind_address },
1475 { WESTON_OPTION_INTEGER, "port", 0, &config.port },
1476 { WESTON_OPTION_BOOLEAN, "no-clients-resize", 0, &config.no_clients_resize },
1477 { WESTON_OPTION_STRING, "rdp4-key", 0, &config.rdp_key },
1478 { WESTON_OPTION_STRING, "rdp-tls-cert", 0, &config.server_cert },
1479 { WESTON_OPTION_STRING, "rdp-tls-key", 0, &config.server_key },
1480 { WESTON_OPTION_BOOLEAN, "force-no-compression", 0, &config.force_no_compression },
1483 section = weston_config_get_section(ivi->config, "rdp", NULL, NULL);
1485 weston_config_section_get_string(section, "tls-cert",
1486 &config.server_cert, config.server_cert);
1488 weston_config_section_get_string(section, "tls-key",
1489 &config.server_key, config.server_key);
1492 parse_options(rdp_options, ARRAY_LENGTH(rdp_options), argc, argv);
1494 ivi->simple_output_configure = rdp_backend_output_configure;
1495 ret = weston_compositor_load_backend(ivi->compositor, WESTON_BACKEND_RDP, &config.base);
1497 free(config.bind_address);
1498 free(config.rdp_key);
1499 free(config.server_cert);
1500 free(config.server_key);
1506 load_rdp_backend(struct ivi_compositor *ivi, int *argc, char **argv)
1514 load_backend(struct ivi_compositor *ivi, int *argc, char **argv,
1515 const char *backend_name, const char *renderer_name)
1517 enum weston_compositor_backend backend;
1518 enum weston_renderer_type renderer;
1520 if (!get_backend_from_string(backend_name, &backend)) {
1521 weston_log("Error: unknown backend \"%s\"\n", backend_name);
1525 if (!get_renderer_from_string(renderer_name, &renderer)) {
1526 weston_log("Error: unknown renderer \"%s\"\n", renderer_name);
1529 if (strcmp(backend, "drm-backend.so") == 0) {
1530 return load_drm_backend(ivi, argc, argv);
1531 } else if (strcmp(backend, "wayland-backend.so") == 0) {
1532 return load_wayland_backend(ivi, argc, argv);
1533 } else if (strcmp(backend, "x11-backend.so") == 0) {
1534 return load_x11_backend(ivi, argc, argv);
1535 } else if (strcmp(backend, "headless-backend.so") == 0) {
1536 return load_headless_backend(ivi, argc, argv);
1537 } else if (strcmp(backend, "rdp-backend.so") == 0) {
1538 return load_rdp_backend(ivi, argc, argv);
1540 weston_log("fatal: unknown backend '%s'.\n", backend_name);
1545 load_modules(struct ivi_compositor *ivi, const char *modules,
1546 int *argc, char *argv[], bool *xwayland)
1548 const char *p, *end;
1550 int (*module_init)(struct weston_compositor *wc, int argc, char *argv[]);
1552 if (modules == NULL)
1557 end = strchrnul(p, ',');
1558 snprintf(buffer, sizeof buffer, "%.*s", (int) (end - p), p);
1560 if (strstr(buffer, "xwayland.so")) {
1562 } else if (strstr(buffer, "systemd-notify.so")) {
1563 weston_log("systemd-notify plug-in already loaded!\n");
1565 module_init = weston_load_module(buffer, "wet_module_init", WESTON_MODULEDIR);
1569 if (module_init(ivi->compositor, *argc, argv) < 0)
1584 choose_default_backend(void)
1586 char *backend = NULL;
1588 if (getenv("WAYLAND_DISPLAY") || getenv("WAYLAND_SOCKET"))
1589 backend = strdup("wayland-backend.so");
1590 else if (getenv("DISPLAY"))
1591 backend = strdup("x11-backend.so");
1593 backend = strdup("drm-backend.so");
1599 compositor_init_config(struct ivi_compositor *ivi)
1601 struct xkb_rule_names xkb_names;
1602 struct weston_config_section *section;
1603 struct weston_compositor *compositor = ivi->compositor;
1604 struct weston_config *config = ivi->config;
1609 /* agl-compositor.ini [keyboard] */
1610 section = weston_config_get_section(config, "keyboard", NULL, NULL);
1611 weston_config_section_get_string(section, "keymap_rules",
1612 (char **) &xkb_names.rules, NULL);
1613 weston_config_section_get_string(section, "keymap_model",
1614 (char **) &xkb_names.model, NULL);
1615 weston_config_section_get_string(section, "keymap_layout",
1616 (char **) &xkb_names.layout, NULL);
1617 weston_config_section_get_string(section, "keymap_variant",
1618 (char **) &xkb_names.variant, NULL);
1619 weston_config_section_get_string(section, "keymap_options",
1620 (char **) &xkb_names.options, NULL);
1622 if (weston_compositor_set_xkb_rule_names(compositor, &xkb_names) < 0)
1625 weston_config_section_get_int(section, "repeat-rate",
1626 &compositor->kb_repeat_rate, 40);
1627 weston_config_section_get_int(section, "repeat-delay",
1628 &compositor->kb_repeat_delay, 400);
1630 weston_config_section_get_bool(section, "vt-switching",
1631 &vt_switching, false);
1632 compositor->vt_switching = vt_switching;
1634 /* agl-compositor.ini [core] */
1635 section = weston_config_get_section(config, "core", NULL, NULL);
1637 weston_config_section_get_bool(section, "disable-cursor",
1638 &ivi->disable_cursor, false);
1639 weston_config_section_get_bool(section, "activate-by-default",
1640 &ivi->activate_by_default, true);
1642 weston_config_section_get_bool(section, "require-input", &require_input, true);
1643 compositor->require_input = require_input;
1645 weston_config_section_get_int(section, "repaint-window", &repaint_msec,
1646 compositor->repaint_msec);
1647 if (repaint_msec < -10 || repaint_msec > 1000) {
1648 weston_log("Invalid repaint_window value in config: %d\n",
1651 compositor->repaint_msec = repaint_msec;
1653 weston_log("Output repaint window is %d ms maximum.\n",
1654 compositor->repaint_msec);
1659 struct ivi_surface *
1660 to_ivi_surface(struct weston_surface *surface)
1662 struct weston_desktop_surface *dsurface;
1664 dsurface = weston_surface_get_desktop_surface(surface);
1668 return weston_desktop_surface_get_user_data(dsurface);
1672 activate_binding(struct weston_seat *seat,
1673 struct weston_view *focus_view, uint32_t flags)
1675 struct weston_surface *focus_surface;
1676 struct weston_surface *main_surface;
1677 struct ivi_surface *ivi_surface;
1678 struct ivi_shell_seat *ivi_seat = get_ivi_shell_seat(seat);
1683 focus_surface = focus_view->surface;
1684 main_surface = weston_surface_get_main_surface(focus_surface);
1686 ivi_surface = to_ivi_surface(main_surface);
1691 ivi_shell_activate_surface(ivi_surface, ivi_seat, flags);
1695 click_to_activate_binding(struct weston_pointer *pointer,
1696 const struct timespec *time,
1697 uint32_t button, void *data)
1699 if (pointer->grab != &pointer->default_grab)
1701 if (pointer->focus == NULL)
1704 activate_binding(pointer->seat, pointer->focus,
1705 WESTON_ACTIVATE_FLAG_CLICKED);
1709 touch_to_activate_binding(struct weston_touch *touch,
1710 const struct timespec *time,
1713 if (touch->grab != &touch->default_grab)
1715 if (touch->focus == NULL)
1718 activate_binding(touch->seat, touch->focus,
1719 WESTON_ACTIVATE_FLAG_NONE);
1723 add_bindings(struct weston_compositor *compositor)
1725 weston_compositor_add_button_binding(compositor, BTN_LEFT, 0,
1726 click_to_activate_binding,
1728 weston_compositor_add_button_binding(compositor, BTN_RIGHT, 0,
1729 click_to_activate_binding,
1731 weston_compositor_add_touch_binding(compositor, 0,
1732 touch_to_activate_binding,
1737 create_listening_socket(struct wl_display *display, const char *socket_name)
1740 if (wl_display_add_socket(display, socket_name)) {
1741 weston_log("fatal: failed to add socket: %s\n",
1746 socket_name = wl_display_add_socket_auto(display);
1748 weston_log("fatal: failed to add socket: %s\n",
1754 setenv("WAYLAND_DISPLAY", socket_name, 1);
1760 global_filter(const struct wl_client *client, const struct wl_global *global,
1767 load_config(struct weston_config **config, bool no_config,
1768 const char *config_file)
1770 const char *file = "agl-compositor.ini";
1771 const char *full_path;
1777 *config = weston_config_parse(file);
1780 full_path = weston_config_get_full_path(*config);
1782 weston_log("Using config file '%s'.\n", full_path);
1783 setenv(WESTON_CONFIG_FILE_ENV_VAR, full_path, 1);
1788 if (config_file && !no_config) {
1789 weston_log("fatal: error opening or reading config file '%s'.\n",
1795 weston_log("Starting with no config file.\n");
1796 setenv(WESTON_CONFIG_FILE_ENV_VAR, "", 1);
1801 static FILE *logfile;
1804 log_timestamp(char *buf, size_t len)
1807 struct tm *brokendown_time;
1811 gettimeofday(&tv, NULL);
1813 brokendown_time = localtime(&tv.tv_sec);
1814 if (brokendown_time == NULL) {
1815 snprintf(buf, len, "%s", "[(NULL)localtime] ");
1819 memset(datestr, 0, sizeof(datestr));
1820 if (brokendown_time->tm_mday != cached_tm_mday) {
1821 strftime(datestr, sizeof(datestr), "Date: %Y-%m-%d %Z\n",
1823 cached_tm_mday = brokendown_time->tm_mday;
1826 strftime(timestr, sizeof(timestr), "%H:%M:%S", brokendown_time);
1827 /* if datestr is empty it prints only timestr*/
1828 snprintf(buf, len, "%s[%s.%03li]", datestr,
1829 timestr, (tv.tv_usec / 1000));
1835 custom_handler(const char *fmt, va_list arg)
1839 weston_log_scope_printf(log_scope, "%s libwayland: ",
1840 log_timestamp(timestr, sizeof(timestr)));
1841 weston_log_scope_vprintf(log_scope, fmt, arg);
1845 log_file_open(const char *filename)
1847 wl_log_set_handler_server(custom_handler);
1850 logfile = fopen(filename, "a");
1855 os_fd_set_cloexec(fileno(logfile));
1856 setvbuf(logfile, NULL, _IOLBF, 256);
1861 log_file_close(void)
1863 if (logfile && logfile != stderr)
1869 vlog(const char *fmt, va_list ap)
1871 const char *oom = "Out of memory";
1876 if (weston_log_scope_is_enabled(log_scope)) {
1878 char *xlog_timestamp = log_timestamp(timestr, sizeof(timestr));
1879 len_va = vasprintf(&str, fmt, ap);
1881 len = weston_log_scope_printf(log_scope, "%s %s",
1882 xlog_timestamp, str);
1885 len = weston_log_scope_printf(log_scope, "%s %s",
1886 xlog_timestamp, oom);
1895 vlog_continue(const char *fmt, va_list ap)
1897 return weston_log_scope_vprintf(log_scope, fmt, ap);
1901 on_term_signal(int signo, void *data)
1903 struct wl_display *display = data;
1905 weston_log("caught signal %d\n", signo);
1906 wl_display_terminate(display);
1912 handle_exit(struct weston_compositor *compositor)
1914 wl_display_terminate(compositor->wl_display);
1918 usage(int error_code)
1920 FILE *out = error_code == EXIT_SUCCESS ? stdout : stderr;
1922 "Usage: agl-compositor [OPTIONS]\n"
1924 "This is " PACKAGE_STRING ", the reference compositor for\n"
1925 "Automotive Grade Linux. " PACKAGE_STRING " supports multiple "
1926 "backends,\nand depending on which backend is in use different "
1927 "options will be accepted.\n"
1931 " --version\t\tPrint agl-compositor version\n"
1932 " -B, --backend=MODULE\tBackend module, one of\n"
1933 "\t\t\t\tdrm-backend.so\n"
1934 "\t\t\t\twayland-backend.so\n"
1935 "\t\t\t\tx11-backend.so\n"
1936 "\t\t\t\theadless-backend.so\n"
1937 " -r, --renderer=NAME\tName of renderer to use: auto, gl, noop, pixman\n"
1938 " -S, --socket=NAME\tName of socket to listen on\n"
1939 " --log=FILE\t\tLog to the given file\n"
1940 " -c, --config=FILE\tConfig file to load, defaults to agl-compositor.ini\n"
1941 " --no-config\t\tDo not read agl-compositor.ini\n"
1942 " --debug\t\tEnable debug extension(s)\n"
1943 " -h, --help\t\tThis help message\n"
1949 copy_command_line(int argc, char * const argv[])
1956 fp = open_memstream(&str, &size);
1960 fprintf(fp, "%s", argv[0]);
1961 for (i = 1; i < argc; i++)
1962 fprintf(fp, " %s", argv[i]);
1968 #if !defined(BUILD_XWAYLAND)
1970 wet_load_xwayland(struct weston_compositor *comp)
1972 weston_log("Attempted to load xwayland library but compositor "
1973 "was *not* built with xwayland support!\n");
1979 weston_log_setup_scopes(struct weston_log_context *log_ctx,
1980 struct weston_log_subscriber *subscriber,
1986 char *tokenize = strdup(names);
1987 char *token = strtok(tokenize, ",");
1989 weston_log_subscribe(log_ctx, subscriber, token);
1990 token = strtok(NULL, ",");
1996 weston_log_subscribe_to_scopes(struct weston_log_context *log_ctx,
1997 struct weston_log_subscriber *logger,
1998 const char *debug_scopes)
2000 if (logger && debug_scopes)
2001 weston_log_setup_scopes(log_ctx, logger, debug_scopes);
2003 weston_log_subscribe(log_ctx, logger, "log");
2007 int wet_main(int argc, char *argv[], const struct weston_testsuite_data *test_data)
2009 struct ivi_compositor ivi = { 0 };
2011 struct wl_display *display = NULL;
2012 struct wl_event_loop *loop;
2013 struct wl_event_source *signals[3] = { 0 };
2014 struct weston_config_section *section;
2015 /* Command line options */
2016 char *backend = NULL;
2017 char *socket_name = NULL;
2019 char *modules = NULL;
2020 char *option_modules = NULL;
2021 char *debug_scopes = NULL;
2026 bool list_debug_scopes = false;
2027 char *config_file = NULL;
2028 struct weston_log_context *log_ctx = NULL;
2029 struct weston_log_subscriber *logger;
2030 int ret = EXIT_FAILURE;
2031 bool xwayland = false;
2032 struct sigaction action;
2033 char *renderer = NULL;
2035 const struct weston_option core_options[] = {
2036 { WESTON_OPTION_STRING, "renderer", 'r', &renderer },
2037 { WESTON_OPTION_STRING, "backend", 'B', &backend },
2038 { WESTON_OPTION_STRING, "socket", 'S', &socket_name },
2039 { WESTON_OPTION_STRING, "log", 0, &log },
2040 { WESTON_OPTION_BOOLEAN, "help", 'h', &help },
2041 { WESTON_OPTION_BOOLEAN, "version", 0, &version },
2042 { WESTON_OPTION_BOOLEAN, "no-config", 0, &no_config },
2043 { WESTON_OPTION_BOOLEAN, "debug", 0, &debug },
2044 { WESTON_OPTION_STRING, "config", 'c', &config_file },
2045 { WESTON_OPTION_STRING, "modules", 0, &option_modules },
2046 { WESTON_OPTION_STRING, "debug-scopes", 'l', &debug_scopes },
2047 { WESTON_OPTION_STRING, "list-debug-scopes", 'L', &list_debug_scopes },
2050 wl_list_init(&ivi.outputs);
2051 wl_list_init(&ivi.saved_outputs);
2052 wl_list_init(&ivi.surfaces);
2053 wl_list_init(&ivi.pending_surfaces);
2054 wl_list_init(&ivi.popup_pending_apps);
2055 wl_list_init(&ivi.fullscreen_pending_apps);
2056 wl_list_init(&ivi.split_pending_apps);
2057 wl_list_init(&ivi.remote_pending_apps);
2058 wl_list_init(&ivi.desktop_clients);
2059 wl_list_init(&ivi.child_process_list);
2060 wl_list_init(&ivi.pending_apps);
2062 /* Prevent any clients we spawn getting our stdin */
2063 os_fd_set_cloexec(STDIN_FILENO);
2065 cmdline = copy_command_line(argc, argv);
2066 parse_options(core_options, ARRAY_LENGTH(core_options), &argc, argv);
2069 usage(EXIT_SUCCESS);
2072 printf(PACKAGE_STRING "\n");
2077 log_ctx = weston_log_ctx_create();
2079 fprintf(stderr, "Failed to initialize weston debug framework.\n");
2083 log_scope = weston_log_ctx_add_log_scope(log_ctx, "log",
2084 "agl-compositor log\n",
2088 weston_log_set_handler(vlog, vlog_continue);
2090 logger = weston_log_subscriber_create_log(logfile);
2091 weston_log_subscribe_to_scopes(log_ctx, logger, debug_scopes);
2093 weston_log("Command line: %s\n", cmdline);
2096 if (load_config(&ivi.config, no_config, config_file) < 0)
2098 section = weston_config_get_section(ivi.config, "core", NULL, NULL);
2100 weston_config_section_get_string(section, "backend", &backend,
2103 backend = choose_default_backend();
2106 display = wl_display_create();
2107 loop = wl_display_get_event_loop(display);
2109 wl_display_set_global_filter(display,
2110 global_filter, &ivi);
2112 /* Register signal handlers so we shut down cleanly */
2114 signals[0] = wl_event_loop_add_signal(loop, SIGTERM, on_term_signal,
2116 signals[1] = wl_event_loop_add_signal(loop, SIGUSR2, on_term_signal,
2118 signals[2] = wl_event_loop_add_signal(loop, SIGCHLD, sigchld_handler,
2121 /* When debugging the compositor, if use wl_event_loop_add_signal() to
2122 * catch SIGINT, the debugger can't catch it, and attempting to stop
2123 * the compositor from within the debugger results in weston exiting
2126 * Instead, use the sigaction() function, which sets up the signal in a
2127 * way that gdb can successfully catch, but have the handler for SIGINT
2128 * send SIGUSR2 (xwayland uses SIGUSR1), which we catch via
2129 * wl_event_loop_add_signal().
2131 action.sa_handler = sigint_helper;
2132 sigemptyset(&action.sa_mask);
2133 action.sa_flags = 0;
2134 sigaction(SIGINT, &action, NULL);
2136 for (size_t i = 0; i < ARRAY_LENGTH(signals); ++i)
2140 ivi.compositor = weston_compositor_create(display, log_ctx, &ivi, test_data);
2141 if (!ivi.compositor) {
2142 weston_log("fatal: failed to create compositor.\n");
2146 if (compositor_init_config(&ivi) < 0)
2147 goto error_compositor;
2149 if (load_backend(&ivi, &argc, argv, backend, renderer) < 0) {
2150 weston_log("fatal: failed to create compositor backend.\n");
2151 goto error_compositor;
2154 ivi.heads_changed.notify = heads_changed;
2155 weston_compositor_add_heads_changed_listener(ivi.compositor,
2156 &ivi.heads_changed);
2158 weston_compositor_flush_heads_changed(ivi.compositor);
2159 if (ivi_desktop_init(&ivi) < 0)
2160 goto error_compositor;
2162 ivi_seat_init(&ivi);
2164 /* load additional modules */
2165 weston_config_section_get_string(section, "modules", &modules, "");
2166 if (load_modules(&ivi, modules, &argc, argv, &xwayland) < 0)
2167 goto error_compositor;
2169 if (load_modules(&ivi, option_modules, &argc, argv, &xwayland) < 0)
2170 goto error_compositor;
2173 weston_config_section_get_bool(section, "xwayland", &xwayland,
2177 if (ivi_shell_init(&ivi) < 0)
2178 goto error_compositor;
2181 if (!wet_load_xwayland(ivi.compositor))
2182 goto error_compositor;
2185 if (ivi_policy_init(&ivi) < 0)
2186 goto error_compositor;
2189 if (list_debug_scopes) {
2190 struct weston_log_scope *nscope = NULL;
2192 weston_log("Printing available debug scopes:\n");
2194 while ((nscope = weston_log_scopes_iterate(log_ctx, nscope))) {
2195 weston_log("\tscope name: %s, desc: %s",
2196 weston_log_scope_get_name(nscope),
2197 weston_log_scope_get_description(nscope));
2202 goto error_compositor;
2205 add_bindings(ivi.compositor);
2207 if (ivi.remoting_api)
2208 ivi_enable_remote_outputs(&ivi);
2210 if (create_listening_socket(display, socket_name) < 0)
2211 goto error_compositor;
2213 ivi_shell_init_black_fs(&ivi);
2215 ivi.compositor->exit = handle_exit;
2217 weston_compositor_wake(ivi.compositor);
2219 ivi_shell_create_global(&ivi);
2221 ivi_launch_shell_client(&ivi, "shell-client",
2222 &ivi.shell_client.client);
2223 ivi_launch_shell_client(&ivi, "shell-client-ext",
2224 &ivi.shell_client_ext.client);
2227 ivi_screenshooter_create(&ivi);
2228 ivi_agl_systemd_notify(&ivi);
2230 wl_display_run(display);
2232 ret = ivi.compositor->exit_code;
2234 wl_display_destroy_clients(display);
2242 weston_compositor_destroy(ivi.compositor);
2244 weston_log_scope_destroy(log_scope);
2247 weston_log_subscriber_destroy(logger);
2248 weston_log_ctx_destroy(log_ctx);
2250 ivi_policy_destroy(ivi.policy);
2253 for (size_t i = 0; i < ARRAY_LENGTH(signals); ++i)
2255 wl_event_source_remove(signals[i]);
2257 wl_display_destroy(display);
2261 weston_config_destroy(ivi.config);
2267 free(option_modules);