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(ivi->compositor, head, head->name);
333 if (!output->output) {
339 int ret = ivi->simple_output_configure(output->output);
341 weston_log("Configuring output \"%s\" failed.\n",
342 weston_head_get_name(head));
343 weston_output_destroy(output->output);
344 ivi->init_failed = true;
348 if (weston_output_enable(output->output) < 0) {
349 weston_log("Enabling output \"%s\" failed.\n",
350 weston_head_get_name(head));
351 weston_output_destroy(output->output);
352 ivi->init_failed = true;
358 weston_compositor_create_output(ivi->compositor, head, name);
359 if (!output->output) {
366 output->output_destroy.notify = handle_output_destroy;
367 weston_output_add_destroy_listener(output->output,
368 &output->output_destroy);
370 wl_list_insert(&ivi->outputs, &output->link);
371 ivi_output_configure_app_id(output);
376 count_heads(struct weston_output *output)
378 struct weston_head *iter = NULL;
381 while ((iter = weston_output_iterate_heads(output, iter)))
388 handle_head_destroy(struct wl_listener *listener, void *data)
390 struct weston_head *head = data;
391 struct weston_output *output;
393 wl_list_remove(&listener->link);
396 output = weston_head_get_output(head);
398 /* On shutdown path, the output might be already gone. */
402 /* We're the last head */
403 if (count_heads(output) <= 1)
404 weston_output_destroy(output);
408 add_head_destroyed_listener(struct weston_head *head)
410 /* We already have a destroy listener */
411 if (weston_head_get_destroy_listener(head, handle_head_destroy))
414 struct wl_listener *listener = zalloc(sizeof *listener);
418 listener->notify = handle_head_destroy;
419 weston_head_add_destroy_listener(head, listener);
423 drm_configure_output(struct ivi_output *output)
425 struct ivi_compositor *ivi = output->ivi;
426 struct weston_config_section *section = output->config;
427 enum weston_drm_backend_output_mode mode =
428 WESTON_DRM_BACKEND_OUTPUT_PREFERRED;
429 char *modeline = NULL;
430 char *gbm_format = NULL;
435 weston_config_section_get_string(section, "mode", &m, "preferred");
437 /* This should have been handled earlier */
438 assert(strcmp(m, "off") != 0);
440 if (ivi->cmdline.use_current_mode || strcmp(m, "current") == 0) {
441 mode = WESTON_DRM_BACKEND_OUTPUT_CURRENT;
442 } else if (strcmp(m, "preferred") != 0) {
448 weston_config_section_get_string(section, "gbm-format",
451 weston_config_section_get_string(section, "seat", &seat, "");
454 if (ivi->drm_api->set_mode(output->output, mode, modeline) < 0) {
455 weston_log("Cannot configure output using weston_drm_output_api.\n");
461 ivi->drm_api->set_gbm_format(output->output, gbm_format);
464 ivi->drm_api->set_seat(output->output, seat);
470 #define WINDOWED_DEFAULT_WIDTH 1024
471 #define WINDOWED_DEFAULT_HEIGHT 768
474 windowed_configure_output(struct ivi_output *output)
476 struct ivi_compositor *ivi = output->ivi;
477 struct weston_config_section *section = output->config;
478 int width = WINDOWED_DEFAULT_WIDTH;
479 int height = WINDOWED_DEFAULT_HEIGHT;
484 weston_config_section_get_string(section, "mode", &mode, NULL);
485 if (!mode || sscanf(mode, "%dx%d", &width, &height) != 2) {
486 weston_log("Invalid mode for output %s. Using defaults.\n",
488 width = WINDOWED_DEFAULT_WIDTH;
489 height = WINDOWED_DEFAULT_HEIGHT;
494 if (ivi->cmdline.width)
495 width = ivi->cmdline.width;
496 if (ivi->cmdline.height)
497 height = ivi->cmdline.height;
498 if (ivi->cmdline.scale)
499 weston_output_set_scale(output->output, ivi->cmdline.scale);
501 if (ivi->window_api->output_set_size(output->output, width, height) < 0) {
502 weston_log("Cannot configure output '%s' using weston_windowed_output_api.\n",
507 weston_log("Configured windowed_output_api to %dx%d\n", width, height);
513 parse_transform(const char *transform, uint32_t *out)
515 static const struct { const char *name; uint32_t token; } transforms[] = {
516 { "normal", WL_OUTPUT_TRANSFORM_NORMAL },
517 { "rotate-90", WL_OUTPUT_TRANSFORM_90 },
518 { "rotate-180", WL_OUTPUT_TRANSFORM_180 },
519 { "rotate-270", WL_OUTPUT_TRANSFORM_270 },
520 { "flipped", WL_OUTPUT_TRANSFORM_FLIPPED },
521 { "flipped-rotate-90", WL_OUTPUT_TRANSFORM_FLIPPED_90 },
522 { "flipped-rotate-180", WL_OUTPUT_TRANSFORM_FLIPPED_180 },
523 { "flipped-rotate-270", WL_OUTPUT_TRANSFORM_FLIPPED_270 },
526 for (size_t i = 0; i < ARRAY_LENGTH(transforms); i++)
527 if (strcmp(transforms[i].name, transform) == 0) {
528 *out = transforms[i].token;
532 *out = WL_OUTPUT_TRANSFORM_NORMAL;
537 parse_activation_area(const char *geometry, struct ivi_output *output)
540 unsigned width, height, x, y;
542 n = sscanf(geometry, "%ux%u+%u,%u", &width, &height, &x, &y);
546 output->area_activation.width = width;
547 output->area_activation.height = height;
548 output->area_activation.x = x;
549 output->area_activation.y = y;
554 configure_output(struct ivi_output *output)
556 struct ivi_compositor *ivi = output->ivi;
557 struct weston_config_section *section = output->config;
559 uint32_t transform = WL_OUTPUT_TRANSFORM_NORMAL;
562 * This can happen with the wayland backend with 'sprawl'. The config
563 * is hard-coded, so we don't need to do anything.
565 if (!ivi->drm_api && !ivi->window_api)
571 weston_config_section_get_int(section, "scale", &scale, 1);
572 weston_config_section_get_string(section, "transform", &t, "normal");
573 if (parse_transform(t, &transform) < 0)
574 weston_log("Invalid transform \"%s\" for output %s\n",
576 weston_config_section_get_string(section, "activation-area", &t, "");
577 if (parse_activation_area(t, output) < 0)
578 weston_log("Invalid activation-area \"%s\" for output %s\n",
583 weston_output_set_scale(output->output, scale);
584 weston_output_set_transform(output->output, transform);
587 return drm_configure_output(output);
589 return windowed_configure_output(output);
593 * Reorgainizes the output's add array into two sections.
594 * add[0..ret-1] are the heads that failed to get attached.
595 * add[ret..add_len] are the heads that were successfully attached.
597 * The order between elements in each section is stable.
600 try_attach_heads(struct ivi_output *output)
604 for (size_t i = 1; i < output->add_len; i++) {
605 if (weston_output_attach_head(output->output, output->add[i]) < 0) {
606 struct weston_head *tmp = output->add[i];
607 memmove(&output->add[fail_len + 1], output->add[fail_len],
608 sizeof output->add[0] * (i - fail_len));
609 output->add[fail_len++] = tmp;
615 /* Place output exactly to the right of the most recently enabled output.
617 * Historically, we haven't given much thought to output placement,
618 * simply adding outputs in a horizontal line as they're enabled. This
619 * function simply sets an output's x coordinate to the right of the
620 * most recently enabled output, and its y to zero.
622 * If you're adding new calls to this function, you're also not giving
623 * much thought to output placement, so please consider carefully if
624 * it's really doing what you want.
626 * You especially don't want to use this for any code that won't
627 * immediately enable the passed output.
630 weston_output_lazy_align(struct weston_output *output)
632 struct weston_compositor *c;
633 struct weston_output *peer;
636 /* Put this output to the right of the most recently enabled output */
637 c = output->compositor;
638 if (!wl_list_empty(&c->output_list)) {
639 peer = container_of(c->output_list.prev,
640 struct weston_output, link);
641 next_x = peer->pos.c.x + peer->width;
643 output->pos.c.x = next_x;
649 * Like try_attach_heads, this reorganizes the output's add array into a failed
650 * and successful section.
651 * i is the number of heads that already failed the previous step.
654 try_enable_output(struct ivi_output *output, size_t i)
656 for (; i < output->add_len; ++i) {
657 struct weston_head *head;
659 weston_output_lazy_align(output->output);
661 if (weston_output_enable(output->output) == 0)
664 head = output->add[output->add_len - 1];
665 memmove(&output->add[i + 1], &output->add[i],
666 sizeof output->add[0] * (output->add_len - i));
667 output->add[i] = head;
669 weston_head_detach(head);
676 try_attach_enable_heads(struct ivi_output *output)
679 assert(!output->output->enabled);
681 fail_len = try_attach_heads(output);
683 if (configure_output(output) < 0)
686 fail_len = try_enable_output(output, fail_len);
688 /* All heads failed to be attached */
689 if (fail_len == output->add_len)
692 /* For each successful head attached */
693 for (size_t i = fail_len; i < output->add_len; ++i)
694 add_head_destroyed_listener(output->add[i]);
696 ivi_layout_restore(output->ivi, output);
698 output->add_len = fail_len;
703 process_output(struct ivi_output *output)
705 if (output->output->enabled) {
706 output->add_len = try_attach_heads(output);
707 return output->add_len == 0 ? 0 : -1;
710 return try_attach_enable_heads(output);
714 head_disable(struct ivi_compositor *ivi, struct weston_head *head)
716 struct weston_output *output;
717 struct ivi_output *ivi_output;
718 struct wl_listener *listener;
720 output = weston_head_get_output(head);
723 listener = weston_output_get_destroy_listener(output,
724 handle_output_destroy);
727 ivi_output = wl_container_of(listener, ivi_output, output_destroy);
728 assert(ivi_output->output == output);
730 weston_head_detach(head);
731 if (count_heads(ivi_output->output) == 0) {
732 if (ivi_output->output) {
733 /* ivi_output->output destruction may be deferred in
734 * some cases (see drm_output_destroy()), so we need to
735 * forcibly trigger the destruction callback now, or
736 * otherwise would later access data that we are about
739 struct weston_output *save = ivi_output->output;
741 handle_output_destroy(&ivi_output->output_destroy, save);
742 weston_output_destroy(save);
745 wl_list_remove(&ivi_output->link);
746 free(ivi_output->app_ids);
750 static struct weston_config_section *
751 find_controlling_output_config(struct weston_config *config,
754 struct weston_config_section *section;
758 same_as = strdup(name);
760 section = weston_config_get_section(config, "output",
762 if (!section && depth > 0)
763 weston_log("Configuration error: output section reffered"
764 "to by same-as=%s not found.\n", same_as);
771 weston_log("Configuration error: same-as nested too "
772 "deep for output '%s'.\n", name);
776 weston_config_section_get_string(section, "same-as",
784 head_prepare_enable(struct ivi_compositor *ivi, struct weston_head *head)
786 const char *name = weston_head_get_name(head);
787 struct weston_config_section *section;
788 struct ivi_output *output;
789 char *output_name = NULL;
792 section = find_controlling_output_config(ivi->config, name);
796 weston_config_section_get_string(section, "mode", &mode, NULL);
797 if (mode && strcmp(mode, "off") == 0) {
803 weston_config_section_get_string(section, "name",
806 output_name = strdup(name);
812 output = ivi_ensure_output(ivi, output_name, section, head);
816 if (output->add_len >= ARRAY_LENGTH(output->add))
819 output->add[output->add_len++] = head;
823 heads_changed(struct wl_listener *listener, void *arg)
825 struct weston_compositor *compositor = arg;
826 struct weston_head *head = NULL;
827 struct ivi_compositor *ivi = to_ivi_compositor(compositor);
828 struct ivi_output *output;
830 while ((head = weston_compositor_iterate_heads(ivi->compositor, head))) {
831 bool connected = weston_head_is_connected(head);
832 bool enabled = weston_head_is_enabled(head);
833 bool changed = weston_head_is_device_changed(head);
834 bool non_desktop = weston_head_is_non_desktop(head);
836 if (connected && !enabled && !non_desktop)
837 head_prepare_enable(ivi, head);
838 else if (!connected && enabled)
839 head_disable(ivi, head);
840 else if (enabled && changed)
841 weston_log("Detected a monitor change on head '%s', "
842 "not bothering to do anything about it.\n",
843 weston_head_get_name(head));
845 weston_head_reset_device_changed(head);
848 wl_list_for_each(output, &ivi->outputs, link) {
849 if (output->add_len == 0)
852 if (process_output(output) < 0) {
854 ivi->init_failed = true;
861 drm_backend_remoted_output_configure(struct weston_output *output,
862 struct weston_config_section *section,
864 const struct weston_remoting_api *api)
866 char *gbm_format = NULL;
869 char *pipeline = NULL;
872 uint32_t transform = WL_OUTPUT_TRANSFORM_NORMAL;
875 ret = api->set_mode(output, modeline);
877 weston_log("Cannot configure an output \"%s\" using "
878 "weston_remoting_api. Invalid mode\n",
883 weston_config_section_get_int(section, "scale", &scale, 1);
884 weston_output_set_scale(output, scale);
886 weston_config_section_get_string(section, "transform", &trans, "normal");
887 if (parse_transform(trans, &transform) < 0) {
888 weston_log("Invalid transform \"%s\" for output %s\n",
889 trans, output->name);
891 weston_output_set_transform(output, transform);
893 weston_config_section_get_string(section, "gbm-format",
895 api->set_gbm_format(output, gbm_format);
898 weston_config_section_get_string(section, "seat", &seat, "");
900 api->set_seat(output, seat);
903 weston_config_section_get_string(section, "gst-pipeline", &pipeline,
906 api->set_gst_pipeline(output, pipeline);
911 weston_config_section_get_string(section, "host", &host, NULL);
912 weston_config_section_get_int(section, "port", &port, 0);
913 if (!host || port <= 0 || 65533 < port) {
914 weston_log("Cannot configure an output \"%s\". "
915 "Need to specify gst-pipeline or "
916 "host and port (1-65533).\n", output->name);
918 api->set_host(output, host);
920 api->set_port(output, port);
927 remote_output_init(struct ivi_output *ivi_output,
928 struct weston_compositor *compositor,
929 struct weston_config_section *section,
930 const struct weston_remoting_api *api)
932 char *output_name, *modeline = NULL;
935 weston_config_section_get_string(section, "name", &output_name, NULL);
939 weston_config_section_get_string(section, "mode", &modeline, "off");
940 if (strcmp(modeline, "off") == 0)
943 ivi_output->output = api->create_output(compositor, output_name);
944 if (!ivi_output->output) {
945 weston_log("Cannot create remoted output \"%s\".\n",
950 ret = drm_backend_remoted_output_configure(ivi_output->output, section,
953 weston_log("Cannot configure remoted output \"%s\".\n",
958 if ((ret = weston_output_enable(ivi_output->output)) < 0) {
959 weston_log("Enabling remoted output \"%s\" failed.\n",
966 weston_log("remoted output '%s' enabled\n", ivi_output->output->name);
973 if (ivi_output->output)
974 weston_output_destroy(ivi_output->output);
980 ivi_enable_remote_outputs(struct ivi_compositor *ivi)
982 struct weston_config_section *remote_section = NULL;
983 const char *section_name;
984 struct weston_config *config = ivi->config;
986 while (weston_config_next_section(config, &remote_section, §ion_name)) {
987 if (strcmp(section_name, "remote-output"))
990 struct ivi_output *ivi_output = NULL;
991 bool output_found = false;
994 weston_config_section_get_string(remote_section,
995 "name", &_name, NULL);
996 wl_list_for_each(ivi_output, &ivi->outputs, link) {
997 if (!strcmp(ivi_output->name, _name)) {
1008 ivi_output = zalloc(sizeof(*ivi_output));
1014 ivi_output->ivi = ivi;
1015 ivi_output->name = _name;
1016 ivi_output->config = remote_section;
1017 ivi_output->type = OUTPUT_REMOTE;
1019 if (remote_output_init(ivi_output, ivi->compositor,
1020 remote_section, ivi->remoting_api)) {
1021 free(ivi_output->name);
1026 ivi_output->output_destroy.notify = handle_output_destroy;
1027 weston_output_add_destroy_listener(ivi_output->output,
1028 &ivi_output->output_destroy);
1030 wl_list_insert(&ivi->outputs, &ivi_output->link);
1031 ivi_output_configure_app_id(ivi_output);
1036 load_remoting_plugin(struct ivi_compositor *ivi, struct weston_config *config)
1038 struct weston_compositor *compositor = ivi->compositor;
1039 int (*module_init)(struct weston_compositor *wc);
1041 module_init = weston_load_module("remoting-plugin.so",
1042 "weston_module_init",
1043 LIBWESTON_MODULEDIR);
1047 if (module_init(compositor) < 0)
1050 ivi->remoting_api = weston_remoting_get_api(compositor);
1051 if (!ivi->remoting_api)
1057 load_remoting_plugin(struct weston_compositor *compositor, struct weston_config *config)
1064 load_drm_backend(struct ivi_compositor *ivi, int *argc, char *argv[],
1065 enum weston_renderer_type renderer)
1067 struct weston_drm_backend_config config = {
1069 .struct_version = WESTON_DRM_BACKEND_CONFIG_VERSION,
1070 .struct_size = sizeof config,
1073 struct weston_config_section *section;
1074 int use_current_mode = 0;
1075 bool force_pixman = false;
1077 bool without_input = false;
1079 const struct weston_option options[] = {
1080 { WESTON_OPTION_STRING, "seat", 0, &config.seat_id },
1081 { WESTON_OPTION_STRING, "drm-device", 0, &config.specific_device },
1082 { WESTON_OPTION_BOOLEAN, "current-mode", 0, &use_current_mode },
1083 { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &force_pixman },
1084 { WESTON_OPTION_BOOLEAN, "continue-without-input", false, &without_input }
1087 parse_options(options, ARRAY_LENGTH(options), argc, argv);
1090 config.renderer = WESTON_RENDERER_PIXMAN;
1092 config.renderer = WESTON_RENDERER_AUTO;
1094 ivi->cmdline.use_current_mode = use_current_mode;
1096 section = weston_config_get_section(ivi->config, "core", NULL, NULL);
1097 weston_config_section_get_string(section, "gbm-format",
1098 &config.gbm_format, NULL);
1099 weston_config_section_get_uint(section, "pageflip-timeout",
1100 &config.pageflip_timeout, 0);
1101 weston_config_section_get_bool(section, "pixman-shadow", &use_shadow, 1);
1102 config.use_pixman_shadow = use_shadow;
1105 ivi->compositor->require_input = !without_input;
1107 ivi->heads_changed.notify = heads_changed;
1108 weston_compositor_add_heads_changed_listener(ivi->compositor,
1109 &ivi->heads_changed);
1111 if (!weston_compositor_load_backend(ivi->compositor, WESTON_BACKEND_DRM,
1115 ivi->drm_api = weston_drm_output_get_api(ivi->compositor);
1116 if (!ivi->drm_api) {
1117 weston_log("Cannot use drm output api.\n");
1121 load_remoting_plugin(ivi, ivi->config);
1126 free(config.gbm_format);
1127 free(config.seat_id);
1132 windowed_parse_common_options(struct ivi_compositor *ivi, int *argc, char *argv[],
1133 bool *force_pixman, bool *fullscreen, int *output_count)
1135 struct weston_config_section *section;
1139 const struct weston_option options[] = {
1140 { WESTON_OPTION_INTEGER, "width", 0, &ivi->cmdline.width },
1141 { WESTON_OPTION_INTEGER, "height", 0, &ivi->cmdline.height },
1142 { WESTON_OPTION_INTEGER, "scale", 0, &ivi->cmdline.scale },
1143 { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &force_pixman },
1144 { WESTON_OPTION_BOOLEAN, "fullscreen", 0, &fs },
1145 { WESTON_OPTION_INTEGER, "output-count", 0, output_count },
1148 section = weston_config_get_section(ivi->config, "core", NULL, NULL);
1149 weston_config_section_get_bool(section, "use-pixman", &pixman, false);
1152 parse_options(options, ARRAY_LENGTH(options), argc, argv);
1153 *force_pixman = pixman;
1158 windowed_create_outputs(struct ivi_compositor *ivi, int output_count,
1159 const char *match_prefix, const char *name_prefix)
1161 struct weston_config_section *section = NULL;
1162 const char *section_name;
1163 char *default_output = NULL;
1165 size_t match_len = strlen(match_prefix);
1167 while (weston_config_next_section(ivi->config, §ion, §ion_name)) {
1170 if (i >= output_count)
1173 if (strcmp(section_name, "output") != 0)
1176 weston_config_section_get_string(section, "name", &output_name, NULL);
1177 if (output_name == NULL)
1179 if (strncmp(output_name, match_prefix, match_len) != 0) {
1184 if (ivi->window_api->create_head(ivi->backend, output_name) < 0) {
1193 for (; i < output_count; ++i) {
1194 if (asprintf(&default_output, "%s%d", name_prefix, i) < 0)
1197 if (ivi->window_api->create_head(ivi->backend, default_output) < 0) {
1198 free(default_output);
1202 free(default_output);
1209 load_wayland_backend(struct ivi_compositor *ivi, int *argc, char *argv[],
1210 enum weston_renderer_type renderer)
1212 struct weston_wayland_backend_config config = {
1214 .struct_version = WESTON_WAYLAND_BACKEND_CONFIG_VERSION,
1215 .struct_size = sizeof config,
1218 struct weston_config_section *section;
1221 bool force_pixman = false;
1223 const struct weston_option options[] = {
1224 { WESTON_OPTION_STRING, "display", 0, &config.display_name },
1225 { WESTON_OPTION_STRING, "sprawl", 0, &sprawl },
1228 windowed_parse_common_options(ivi, argc, argv, &force_pixman,
1229 &config.fullscreen, &output_count);
1231 parse_options(options, ARRAY_LENGTH(options), argc, argv);
1232 config.sprawl = sprawl;
1234 section = weston_config_get_section(ivi->config, "shell", NULL, NULL);
1235 weston_config_section_get_string(section, "cursor-theme",
1236 &config.cursor_theme, NULL);
1237 weston_config_section_get_int(section, "cursor-size",
1238 &config.cursor_size, 32);
1240 ivi->backend = weston_compositor_load_backend(ivi->compositor, WESTON_BACKEND_WAYLAND,
1243 free(config.cursor_theme);
1244 free(config.display_name);
1249 ivi->window_api = weston_windowed_output_get_api(ivi->compositor);
1252 * We will just assume if load_backend() finished cleanly and
1253 * windowed_output_api is not present that wayland backend is started
1254 * with --sprawl or runs on fullscreen-shell. In this case, all values
1255 * are hardcoded, so nothing can be configured; simply create and
1258 if (ivi->window_api == NULL)
1261 return windowed_create_outputs(ivi, output_count, "WL", "wayland");
1264 #ifdef HAVE_BACKEND_X11
1266 load_x11_backend(struct ivi_compositor *ivi, int *argc, char *argv[],
1267 enum weston_renderer_type renderer)
1269 struct weston_x11_backend_config config = {
1271 .struct_version = WESTON_X11_BACKEND_CONFIG_VERSION,
1272 .struct_size = sizeof config,
1278 bool force_pixman = false;
1280 const struct weston_option options[] = {
1281 { WESTON_OPTION_BOOLEAN, "no-input", 0, &no_input },
1284 windowed_parse_common_options(ivi, argc, argv, &force_pixman,
1285 &config.fullscreen, &output_count);
1287 parse_options(options, ARRAY_LENGTH(options), argc, argv);
1289 config.renderer = WESTON_RENDERER_PIXMAN;
1291 config.renderer = WESTON_RENDERER_AUTO;
1292 config.no_input = no_input;
1294 if (!weston_compositor_load_backend(ivi->compositor, WESTON_BACKEND_X11, &config.base))
1297 ivi->window_api = weston_windowed_output_get_api(ivi->compositor);
1298 if (!ivi->window_api) {
1299 weston_log("Cannot use weston_windowed_output_api.\n");
1303 return windowed_create_outputs(ivi, output_count, "X", "screen");
1307 load_x11_backend(struct ivi_compositor *ivi, int *argc, char **argv,
1308 enum weston_renderer_type renderer)
1314 #ifdef HAVE_BACKEND_HEADLESS
1316 load_headless_backend(struct ivi_compositor *ivi, int *argc, char **argv,
1317 enum weston_renderer_type renderer)
1319 struct weston_headless_backend_config config = {};
1321 bool force_pixman = false;
1323 bool force_gl = false;
1326 struct weston_compositor *c = ivi->compositor;
1327 struct weston_backend *wb = NULL;
1329 const struct weston_option options[] = {
1330 { WESTON_OPTION_BOOLEAN, "use-pixman", false, &force_pixman },
1331 { WESTON_OPTION_BOOLEAN, "use-gl", false, &force_gl },
1334 windowed_parse_common_options(ivi, argc, argv, &force_pixman,
1335 &fullscreen, &output_count);
1337 parse_options(options, ARRAY_LENGTH(options), argc, argv);
1339 if ((force_pixman && force_gl) ||
1340 (renderer != WESTON_RENDERER_AUTO && (force_pixman || force_gl))) {
1341 weston_log("Conflicting renderer specifications\n");
1343 } else if (force_pixman) {
1344 config.renderer = WESTON_RENDERER_PIXMAN;
1345 } else if (force_gl) {
1346 config.renderer = WESTON_RENDERER_GL;
1348 config.renderer = renderer;
1351 config.base.struct_version = WESTON_HEADLESS_BACKEND_CONFIG_VERSION;
1352 config.base.struct_size = sizeof(struct weston_headless_backend_config);
1354 /* load the actual headless-backend and configure it */
1355 if (!weston_compositor_load_backend(c, WESTON_BACKEND_HEADLESS, &config.base))
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 wb = weston_compositor_load_backend(ivi->compositor, WESTON_BACKEND_HEADLESS, &config.base);
1368 if (ivi->window_api->create_head(wb, "headless") < 0) {
1369 weston_log("Cannot create headless back-end\n");
1377 load_headless_backend(struct ivi_compositor *ivi, int *argc, char **argv, enum weston_renderer_type renderer)
1383 #ifdef HAVE_BACKEND_RDP
1385 weston_rdp_backend_config_init(struct weston_rdp_backend_config *config)
1387 config->base.struct_version = WESTON_RDP_BACKEND_CONFIG_VERSION;
1388 config->base.struct_size = sizeof(struct weston_rdp_backend_config);
1390 config->bind_address = NULL;
1391 config->port = 3389;
1392 config->rdp_key = NULL;
1393 config->server_cert = NULL;
1394 config->server_key = NULL;
1395 config->env_socket = 0;
1396 config->no_clients_resize = 1;
1397 config->force_no_compression = 0;
1401 rdp_backend_output_configure(struct weston_output *output)
1403 struct ivi_compositor *ivi = to_ivi_compositor(output->compositor);
1404 struct ivi_output_config *parsed_options = ivi->parsed_options;
1405 const struct weston_rdp_output_api *api =
1406 weston_rdp_output_get_api(output->compositor);
1409 struct weston_config_section *section;
1410 uint32_t transform = WL_OUTPUT_TRANSFORM_NORMAL;
1411 char *transform_string;
1412 struct weston_mode new_mode = {};
1414 assert(parsed_options);
1417 weston_log("Cannot use weston_rdp_output_api.\n");
1421 section = weston_config_get_section(ivi->config, "rdp", NULL, NULL);
1423 if (parsed_options->width)
1424 width = parsed_options->width;
1426 if (parsed_options->height)
1427 height = parsed_options->height;
1429 weston_output_set_scale(output, 1);
1431 weston_config_section_get_int(section, "width",
1434 weston_config_section_get_int(section, "height",
1437 if (parsed_options->transform)
1438 transform = parsed_options->transform;
1440 weston_config_section_get_string(section, "transform",
1441 &transform_string, "normal");
1443 if (parse_transform(transform_string, &transform) < 0) {
1444 weston_log("Invalid transform \"%s\" for output %s\n",
1445 transform_string, output->name);
1450 new_mode.width = width;
1451 new_mode.height = height;
1453 api->output_set_mode(output, &new_mode);
1454 weston_output_set_transform(output, transform);
1460 load_rdp_backend(struct ivi_compositor *ivi, int *argc, char **argv)
1462 struct weston_rdp_backend_config config = {};
1463 struct weston_config_section *section;
1465 struct ivi_output_config *parsed_options = ivi_init_parsed_options(ivi->compositor);
1466 if (!parsed_options)
1469 weston_rdp_backend_config_init(&config);
1471 const struct weston_option rdp_options[] = {
1472 { WESTON_OPTION_BOOLEAN, "env-socket", 0, &config.env_socket },
1473 { WESTON_OPTION_INTEGER, "width", 0, &parsed_options->width },
1474 { WESTON_OPTION_INTEGER, "height", 0, &parsed_options->height },
1475 { WESTON_OPTION_INTEGER, "transform", 0, &parsed_options->transform },
1476 { WESTON_OPTION_INTEGER, "scale", 0, &parsed_options->scale },
1477 { WESTON_OPTION_STRING, "address", 0, &config.bind_address },
1478 { WESTON_OPTION_INTEGER, "port", 0, &config.port },
1479 { WESTON_OPTION_BOOLEAN, "no-clients-resize", 0, &config.no_clients_resize },
1480 { WESTON_OPTION_STRING, "rdp4-key", 0, &config.rdp_key },
1481 { WESTON_OPTION_STRING, "rdp-tls-cert", 0, &config.server_cert },
1482 { WESTON_OPTION_STRING, "rdp-tls-key", 0, &config.server_key },
1483 { WESTON_OPTION_BOOLEAN, "force-no-compression", 0, &config.force_no_compression },
1486 section = weston_config_get_section(ivi->config, "rdp", NULL, NULL);
1488 weston_config_section_get_string(section, "tls-cert",
1489 &config.server_cert, config.server_cert);
1491 weston_config_section_get_string(section, "tls-key",
1492 &config.server_key, config.server_key);
1495 parse_options(rdp_options, ARRAY_LENGTH(rdp_options), argc, argv);
1497 ivi->simple_output_configure = rdp_backend_output_configure;
1498 if (!weston_compositor_load_backend(ivi->compositor, WESTON_BACKEND_RDP, &config.base))
1501 free(config.bind_address);
1502 free(config.rdp_key);
1503 free(config.server_cert);
1504 free(config.server_key);
1510 load_rdp_backend(struct ivi_compositor *ivi, int *argc, char **argv)
1518 load_backend(struct ivi_compositor *ivi, int *argc, char **argv,
1519 const char *backend_name, const char *renderer_name)
1521 enum weston_compositor_backend backend;
1522 enum weston_renderer_type renderer;
1524 if (!get_backend_from_string(backend_name, &backend)) {
1525 weston_log("Error: unknown backend \"%s\"\n", backend_name);
1529 if (!get_renderer_from_string(renderer_name, &renderer)) {
1530 weston_log("Error: unknown renderer \"%s\"\n", renderer_name);
1535 case WESTON_BACKEND_DRM:
1536 return load_drm_backend(ivi, argc, argv, renderer);
1537 case WESTON_BACKEND_HEADLESS:
1538 return load_headless_backend(ivi, argc, argv, renderer);
1539 case WESTON_BACKEND_RDP:
1540 return load_rdp_backend(ivi, argc, argv);
1541 case WESTON_BACKEND_WAYLAND:
1542 return load_wayland_backend(ivi, argc, argv, renderer);
1543 case WESTON_BACKEND_X11:
1544 return load_x11_backend(ivi, argc, argv, renderer);
1546 assert(!"unknown backend type in load_backend()");
1553 load_modules(struct ivi_compositor *ivi, const char *modules,
1554 int *argc, char *argv[], bool *xwayland)
1556 const char *p, *end;
1558 int (*module_init)(struct weston_compositor *wc, int argc, char *argv[]);
1560 if (modules == NULL)
1565 end = strchrnul(p, ',');
1566 snprintf(buffer, sizeof buffer, "%.*s", (int) (end - p), p);
1568 if (strstr(buffer, "xwayland.so")) {
1570 } else if (strstr(buffer, "systemd-notify.so")) {
1571 weston_log("systemd-notify plug-in already loaded!\n");
1573 module_init = weston_load_module(buffer, "wet_module_init", WESTON_MODULEDIR);
1577 if (module_init(ivi->compositor, *argc, argv) < 0)
1592 choose_default_backend(void)
1594 char *backend = NULL;
1596 if (getenv("WAYLAND_DISPLAY") || getenv("WAYLAND_SOCKET"))
1597 backend = strdup("wayland-backend.so");
1598 else if (getenv("DISPLAY"))
1599 backend = strdup("x11-backend.so");
1601 backend = strdup("drm-backend.so");
1607 compositor_init_config(struct ivi_compositor *ivi)
1609 struct xkb_rule_names xkb_names;
1610 struct weston_config_section *section;
1611 struct weston_compositor *compositor = ivi->compositor;
1612 struct weston_config *config = ivi->config;
1617 /* agl-compositor.ini [keyboard] */
1618 section = weston_config_get_section(config, "keyboard", NULL, NULL);
1619 weston_config_section_get_string(section, "keymap_rules",
1620 (char **) &xkb_names.rules, NULL);
1621 weston_config_section_get_string(section, "keymap_model",
1622 (char **) &xkb_names.model, NULL);
1623 weston_config_section_get_string(section, "keymap_layout",
1624 (char **) &xkb_names.layout, NULL);
1625 weston_config_section_get_string(section, "keymap_variant",
1626 (char **) &xkb_names.variant, NULL);
1627 weston_config_section_get_string(section, "keymap_options",
1628 (char **) &xkb_names.options, NULL);
1630 if (weston_compositor_set_xkb_rule_names(compositor, &xkb_names) < 0)
1633 weston_config_section_get_int(section, "repeat-rate",
1634 &compositor->kb_repeat_rate, 40);
1635 weston_config_section_get_int(section, "repeat-delay",
1636 &compositor->kb_repeat_delay, 400);
1638 weston_config_section_get_bool(section, "vt-switching",
1639 &vt_switching, false);
1640 compositor->vt_switching = vt_switching;
1642 /* agl-compositor.ini [core] */
1643 section = weston_config_get_section(config, "core", NULL, NULL);
1645 weston_config_section_get_bool(section, "disable-cursor",
1646 &ivi->disable_cursor, false);
1647 weston_config_section_get_bool(section, "activate-by-default",
1648 &ivi->activate_by_default, true);
1650 weston_config_section_get_bool(section, "require-input", &require_input, true);
1651 compositor->require_input = require_input;
1653 weston_config_section_get_int(section, "repaint-window", &repaint_msec,
1654 compositor->repaint_msec);
1655 if (repaint_msec < -10 || repaint_msec > 1000) {
1656 weston_log("Invalid repaint_window value in config: %d\n",
1659 compositor->repaint_msec = repaint_msec;
1661 weston_log("Output repaint window is %d ms maximum.\n",
1662 compositor->repaint_msec);
1667 struct ivi_surface *
1668 to_ivi_surface(struct weston_surface *surface)
1670 struct weston_desktop_surface *dsurface;
1672 dsurface = weston_surface_get_desktop_surface(surface);
1676 return weston_desktop_surface_get_user_data(dsurface);
1680 activate_binding(struct weston_seat *seat,
1681 struct weston_view *focus_view, uint32_t flags)
1683 struct weston_surface *focus_surface;
1684 struct weston_surface *main_surface;
1685 struct ivi_surface *ivi_surface;
1686 struct ivi_shell_seat *ivi_seat = get_ivi_shell_seat(seat);
1691 focus_surface = focus_view->surface;
1692 main_surface = weston_surface_get_main_surface(focus_surface);
1694 ivi_surface = to_ivi_surface(main_surface);
1699 ivi_shell_activate_surface(ivi_surface, ivi_seat, flags);
1703 click_to_activate_binding(struct weston_pointer *pointer,
1704 const struct timespec *time,
1705 uint32_t button, void *data)
1707 if (pointer->grab != &pointer->default_grab)
1709 if (pointer->focus == NULL)
1712 activate_binding(pointer->seat, pointer->focus,
1713 WESTON_ACTIVATE_FLAG_CLICKED);
1717 touch_to_activate_binding(struct weston_touch *touch,
1718 const struct timespec *time,
1721 if (touch->grab != &touch->default_grab)
1723 if (touch->focus == NULL)
1726 activate_binding(touch->seat, touch->focus,
1727 WESTON_ACTIVATE_FLAG_NONE);
1731 add_bindings(struct weston_compositor *compositor)
1733 weston_compositor_add_button_binding(compositor, BTN_LEFT, 0,
1734 click_to_activate_binding,
1736 weston_compositor_add_button_binding(compositor, BTN_RIGHT, 0,
1737 click_to_activate_binding,
1739 weston_compositor_add_touch_binding(compositor, 0,
1740 touch_to_activate_binding,
1745 create_listening_socket(struct wl_display *display, const char *socket_name)
1748 if (wl_display_add_socket(display, socket_name)) {
1749 weston_log("fatal: failed to add socket: %s\n",
1754 socket_name = wl_display_add_socket_auto(display);
1756 weston_log("fatal: failed to add socket: %s\n",
1762 setenv("WAYLAND_DISPLAY", socket_name, 1);
1768 global_filter(const struct wl_client *client, const struct wl_global *global,
1775 load_config(struct weston_config **config, bool no_config,
1776 const char *config_file)
1778 const char *file = "agl-compositor.ini";
1779 const char *full_path;
1785 *config = weston_config_parse(file);
1788 full_path = weston_config_get_full_path(*config);
1790 weston_log("Using config file '%s'.\n", full_path);
1791 setenv(WESTON_CONFIG_FILE_ENV_VAR, full_path, 1);
1796 if (config_file && !no_config) {
1797 weston_log("fatal: error opening or reading config file '%s'.\n",
1803 weston_log("Starting with no config file.\n");
1804 setenv(WESTON_CONFIG_FILE_ENV_VAR, "", 1);
1809 static FILE *logfile;
1812 log_timestamp(char *buf, size_t len)
1815 struct tm *brokendown_time;
1819 gettimeofday(&tv, NULL);
1821 brokendown_time = localtime(&tv.tv_sec);
1822 if (brokendown_time == NULL) {
1823 snprintf(buf, len, "%s", "[(NULL)localtime] ");
1827 memset(datestr, 0, sizeof(datestr));
1828 if (brokendown_time->tm_mday != cached_tm_mday) {
1829 strftime(datestr, sizeof(datestr), "Date: %Y-%m-%d %Z\n",
1831 cached_tm_mday = brokendown_time->tm_mday;
1834 strftime(timestr, sizeof(timestr), "%H:%M:%S", brokendown_time);
1835 /* if datestr is empty it prints only timestr*/
1836 snprintf(buf, len, "%s[%s.%03li]", datestr,
1837 timestr, (tv.tv_usec / 1000));
1843 custom_handler(const char *fmt, va_list arg)
1847 weston_log_scope_printf(log_scope, "%s libwayland: ",
1848 log_timestamp(timestr, sizeof(timestr)));
1849 weston_log_scope_vprintf(log_scope, fmt, arg);
1853 log_file_open(const char *filename)
1855 wl_log_set_handler_server(custom_handler);
1858 logfile = fopen(filename, "a");
1863 os_fd_set_cloexec(fileno(logfile));
1864 setvbuf(logfile, NULL, _IOLBF, 256);
1869 log_file_close(void)
1871 if (logfile && logfile != stderr)
1877 vlog(const char *fmt, va_list ap)
1879 const char *oom = "Out of memory";
1884 if (weston_log_scope_is_enabled(log_scope)) {
1886 char *xlog_timestamp = log_timestamp(timestr, sizeof(timestr));
1887 len_va = vasprintf(&str, fmt, ap);
1889 len = weston_log_scope_printf(log_scope, "%s %s",
1890 xlog_timestamp, str);
1893 len = weston_log_scope_printf(log_scope, "%s %s",
1894 xlog_timestamp, oom);
1903 vlog_continue(const char *fmt, va_list ap)
1905 return weston_log_scope_vprintf(log_scope, fmt, ap);
1909 on_term_signal(int signo, void *data)
1911 struct wl_display *display = data;
1913 weston_log("caught signal %d\n", signo);
1914 wl_display_terminate(display);
1920 handle_exit(struct weston_compositor *compositor)
1922 wl_display_terminate(compositor->wl_display);
1926 usage(int error_code)
1928 FILE *out = error_code == EXIT_SUCCESS ? stdout : stderr;
1930 "Usage: agl-compositor [OPTIONS]\n"
1932 "This is " PACKAGE_STRING ", the reference compositor for\n"
1933 "Automotive Grade Linux. " PACKAGE_STRING " supports multiple "
1934 "backends,\nand depending on which backend is in use different "
1935 "options will be accepted.\n"
1939 " --version\t\tPrint agl-compositor version\n"
1940 " -B, --backend=MODULE\tBackend module, one of\n"
1941 "\t\t\t\tdrm-backend.so\n"
1942 "\t\t\t\twayland-backend.so\n"
1943 "\t\t\t\tx11-backend.so\n"
1944 "\t\t\t\theadless-backend.so\n"
1945 " -r, --renderer=NAME\tName of renderer to use: auto, gl, noop, pixman\n"
1946 " -S, --socket=NAME\tName of socket to listen on\n"
1947 " --log=FILE\t\tLog to the given file\n"
1948 " -c, --config=FILE\tConfig file to load, defaults to agl-compositor.ini\n"
1949 " --no-config\t\tDo not read agl-compositor.ini\n"
1950 " --debug\t\tEnable debug extension(s)\n"
1951 " -h, --help\t\tThis help message\n"
1957 copy_command_line(int argc, char * const argv[])
1964 fp = open_memstream(&str, &size);
1968 fprintf(fp, "%s", argv[0]);
1969 for (i = 1; i < argc; i++)
1970 fprintf(fp, " %s", argv[i]);
1976 #if !defined(BUILD_XWAYLAND)
1978 wet_load_xwayland(struct weston_compositor *comp)
1980 weston_log("Attempted to load xwayland library but compositor "
1981 "was *not* built with xwayland support!\n");
1987 weston_log_setup_scopes(struct weston_log_context *log_ctx,
1988 struct weston_log_subscriber *subscriber,
1994 char *tokenize = strdup(names);
1995 char *token = strtok(tokenize, ",");
1997 weston_log_subscribe(log_ctx, subscriber, token);
1998 token = strtok(NULL, ",");
2004 weston_log_subscribe_to_scopes(struct weston_log_context *log_ctx,
2005 struct weston_log_subscriber *logger,
2006 const char *debug_scopes)
2008 if (logger && debug_scopes)
2009 weston_log_setup_scopes(log_ctx, logger, debug_scopes);
2011 weston_log_subscribe(log_ctx, logger, "log");
2015 int wet_main(int argc, char *argv[], const struct weston_testsuite_data *test_data)
2017 struct ivi_compositor ivi = { 0 };
2019 struct wl_display *display = NULL;
2020 struct wl_event_loop *loop;
2021 struct wl_event_source *signals[3] = { 0 };
2022 struct weston_config_section *section;
2023 /* Command line options */
2024 char *backend = NULL;
2025 char *socket_name = NULL;
2027 char *modules = NULL;
2028 char *option_modules = NULL;
2029 char *debug_scopes = NULL;
2034 bool list_debug_scopes = false;
2035 char *config_file = NULL;
2036 struct weston_log_context *log_ctx = NULL;
2037 struct weston_log_subscriber *logger;
2038 int ret = EXIT_FAILURE;
2039 bool xwayland = false;
2040 struct sigaction action;
2041 char *renderer = NULL;
2043 const struct weston_option core_options[] = {
2044 { WESTON_OPTION_STRING, "renderer", 'r', &renderer },
2045 { WESTON_OPTION_STRING, "backend", 'B', &backend },
2046 { WESTON_OPTION_STRING, "socket", 'S', &socket_name },
2047 { WESTON_OPTION_STRING, "log", 0, &log },
2048 { WESTON_OPTION_BOOLEAN, "help", 'h', &help },
2049 { WESTON_OPTION_BOOLEAN, "version", 0, &version },
2050 { WESTON_OPTION_BOOLEAN, "no-config", 0, &no_config },
2051 { WESTON_OPTION_BOOLEAN, "debug", 0, &debug },
2052 { WESTON_OPTION_STRING, "config", 'c', &config_file },
2053 { WESTON_OPTION_STRING, "modules", 0, &option_modules },
2054 { WESTON_OPTION_STRING, "debug-scopes", 'l', &debug_scopes },
2055 { WESTON_OPTION_STRING, "list-debug-scopes", 'L', &list_debug_scopes },
2058 wl_list_init(&ivi.outputs);
2059 wl_list_init(&ivi.saved_outputs);
2060 wl_list_init(&ivi.surfaces);
2061 wl_list_init(&ivi.pending_surfaces);
2062 wl_list_init(&ivi.popup_pending_apps);
2063 wl_list_init(&ivi.fullscreen_pending_apps);
2064 wl_list_init(&ivi.split_pending_apps);
2065 wl_list_init(&ivi.remote_pending_apps);
2066 wl_list_init(&ivi.desktop_clients);
2067 wl_list_init(&ivi.child_process_list);
2068 wl_list_init(&ivi.pending_apps);
2070 /* Prevent any clients we spawn getting our stdin */
2071 os_fd_set_cloexec(STDIN_FILENO);
2073 cmdline = copy_command_line(argc, argv);
2074 parse_options(core_options, ARRAY_LENGTH(core_options), &argc, argv);
2077 usage(EXIT_SUCCESS);
2080 printf(PACKAGE_STRING "\n");
2085 log_ctx = weston_log_ctx_create();
2087 fprintf(stderr, "Failed to initialize weston debug framework.\n");
2091 log_scope = weston_log_ctx_add_log_scope(log_ctx, "log",
2092 "agl-compositor log\n",
2096 weston_log_set_handler(vlog, vlog_continue);
2098 logger = weston_log_subscriber_create_log(logfile);
2099 weston_log_subscribe_to_scopes(log_ctx, logger, debug_scopes);
2101 weston_log("Command line: %s\n", cmdline);
2104 if (load_config(&ivi.config, no_config, config_file) < 0)
2106 section = weston_config_get_section(ivi.config, "core", NULL, NULL);
2108 weston_config_section_get_string(section, "backend", &backend,
2111 backend = choose_default_backend();
2114 display = wl_display_create();
2115 loop = wl_display_get_event_loop(display);
2117 wl_display_set_global_filter(display,
2118 global_filter, &ivi);
2120 /* Register signal handlers so we shut down cleanly */
2122 signals[0] = wl_event_loop_add_signal(loop, SIGTERM, on_term_signal,
2124 signals[1] = wl_event_loop_add_signal(loop, SIGUSR2, on_term_signal,
2126 signals[2] = wl_event_loop_add_signal(loop, SIGCHLD, sigchld_handler,
2129 /* When debugging the compositor, if use wl_event_loop_add_signal() to
2130 * catch SIGINT, the debugger can't catch it, and attempting to stop
2131 * the compositor from within the debugger results in weston exiting
2134 * Instead, use the sigaction() function, which sets up the signal in a
2135 * way that gdb can successfully catch, but have the handler for SIGINT
2136 * send SIGUSR2 (xwayland uses SIGUSR1), which we catch via
2137 * wl_event_loop_add_signal().
2139 action.sa_handler = sigint_helper;
2140 sigemptyset(&action.sa_mask);
2141 action.sa_flags = 0;
2142 sigaction(SIGINT, &action, NULL);
2144 for (size_t i = 0; i < ARRAY_LENGTH(signals); ++i)
2148 ivi.compositor = weston_compositor_create(display, log_ctx, &ivi, test_data);
2149 if (!ivi.compositor) {
2150 weston_log("fatal: failed to create compositor.\n");
2154 if (compositor_init_config(&ivi) < 0)
2155 goto error_compositor;
2157 if (load_backend(&ivi, &argc, argv, backend, renderer) < 0) {
2158 weston_log("fatal: failed to create compositor backend.\n");
2159 goto error_compositor;
2162 if (weston_compositor_backends_loaded(ivi.compositor) < 0)
2163 goto error_compositor;
2165 weston_compositor_flush_heads_changed(ivi.compositor);
2167 if (ivi_desktop_init(&ivi) < 0)
2168 goto error_compositor;
2170 ivi_seat_init(&ivi);
2172 /* load additional modules */
2173 weston_config_section_get_string(section, "modules", &modules, "");
2174 if (load_modules(&ivi, modules, &argc, argv, &xwayland) < 0)
2175 goto error_compositor;
2177 if (load_modules(&ivi, option_modules, &argc, argv, &xwayland) < 0)
2178 goto error_compositor;
2181 weston_config_section_get_bool(section, "xwayland", &xwayland,
2185 if (ivi_shell_init(&ivi) < 0)
2186 goto error_compositor;
2189 if (!wet_load_xwayland(ivi.compositor))
2190 goto error_compositor;
2193 if (ivi_policy_init(&ivi) < 0)
2194 goto error_compositor;
2197 if (list_debug_scopes) {
2198 struct weston_log_scope *nscope = NULL;
2200 weston_log("Printing available debug scopes:\n");
2202 while ((nscope = weston_log_scopes_iterate(log_ctx, nscope))) {
2203 weston_log("\tscope name: %s, desc: %s",
2204 weston_log_scope_get_name(nscope),
2205 weston_log_scope_get_description(nscope));
2210 goto error_compositor;
2213 add_bindings(ivi.compositor);
2215 if (ivi.remoting_api)
2216 ivi_enable_remote_outputs(&ivi);
2218 if (create_listening_socket(display, socket_name) < 0)
2219 goto error_compositor;
2221 ivi_shell_init_black_fs(&ivi);
2223 ivi.compositor->exit = handle_exit;
2225 weston_compositor_wake(ivi.compositor);
2227 ivi_shell_create_global(&ivi);
2229 ivi_launch_shell_client(&ivi, "shell-client",
2230 &ivi.shell_client.client);
2231 ivi_launch_shell_client(&ivi, "shell-client-ext",
2232 &ivi.shell_client_ext.client);
2235 ivi_screenshooter_create(&ivi);
2236 ivi_agl_systemd_notify(&ivi);
2238 wl_display_run(display);
2240 ret = ivi.compositor->exit_code;
2242 wl_display_destroy_clients(display);
2250 weston_compositor_destroy(ivi.compositor);
2252 weston_log_scope_destroy(log_scope);
2255 weston_log_subscriber_destroy(logger);
2256 weston_log_ctx_destroy(log_ctx);
2258 ivi_policy_destroy(ivi.policy);
2261 for (size_t i = 0; i < ARRAY_LENGTH(signals); ++i)
2263 wl_event_source_remove(signals[i]);
2265 wl_display_destroy(display);
2269 weston_config_destroy(ivi.config);
2275 free(option_modules);