2 * Copyright © 2012-2024 Collabora, Ltd.
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 #include "ivi-compositor.h"
38 #include <linux/input.h>
40 #include <libweston/backend-drm.h>
41 #include <libweston/backend-wayland.h>
42 #ifdef HAVE_BACKEND_RDP
43 #include <libweston/backend-rdp.h>
45 #ifdef HAVE_BACKEND_X11
46 #include <libweston/backend-x11.h>
48 #include <libweston/libweston.h>
49 #include <libweston/windowed-output-api.h>
50 #include <libweston/config-parser.h>
51 #include <libweston/weston-log.h>
54 #include "shared/os-compatibility.h"
55 #include "shared/helpers.h"
58 #include "agl-shell-server-protocol.h"
64 #define WINDOWED_DEFAULT_WIDTH 1024
65 #define WINDOWED_DEFAULT_HEIGHT 768
67 static int cached_tm_mday = -1;
68 static struct weston_log_scope *log_scope;
70 struct ivi_compositor *
71 to_ivi_compositor(struct weston_compositor *ec)
73 return weston_compositor_get_user_data(ec);
77 ivi_process_destroy(struct wet_process *process, int status, bool call_cleanup)
79 wl_list_remove(&process->link);
80 if (call_cleanup && process->cleanup)
81 process->cleanup(process, status, process->cleanup_data);
86 struct ivi_output_config *
87 ivi_init_parsed_options(struct weston_compositor *compositor)
89 struct ivi_compositor *ivi = to_ivi_compositor(compositor);
90 struct ivi_output_config *config;
92 config = zalloc(sizeof *config);
99 config->transform = UINT32_MAX;
101 ivi->parsed_options = config;
107 sigint_helper(int sig)
114 enum weston_renderer_type renderer;
115 } renderer_name_map[] = {
116 { "auto", WESTON_RENDERER_AUTO },
117 { "gl", WESTON_RENDERER_GL },
118 { "noop", WESTON_RENDERER_NOOP },
119 { "pixman", WESTON_RENDERER_PIXMAN },
125 enum weston_compositor_backend backend;
126 } backend_name_map[] = {
127 { "drm", "drm-backend.so", WESTON_BACKEND_DRM },
128 { "rdp", "rdp-backend.so", WESTON_BACKEND_RDP },
129 { "wayland", "wayland-backend.so", WESTON_BACKEND_WAYLAND },
130 { "x11", "x11-backend.so", WESTON_BACKEND_X11 },
134 get_backend_from_string(const char *name, enum weston_compositor_backend *backend)
138 for (i = 0; i < ARRAY_LENGTH(backend_name_map); i++) {
139 if (strcmp(name, backend_name_map[i].short_name) == 0 ||
140 strcmp(name, backend_name_map[i].long_name) == 0) {
141 *backend = backend_name_map[i].backend;
150 get_renderer_from_string(const char *name, enum weston_renderer_type *renderer)
157 for (i = 0; i < ARRAY_LENGTH(renderer_name_map); i++) {
158 if (strcmp(name, renderer_name_map[i].name) == 0) {
159 *renderer = renderer_name_map[i].renderer;
168 handle_output_destroy(struct wl_listener *listener, void *data)
170 struct ivi_output *output;
172 output = wl_container_of(listener, output, output_destroy);
173 assert(output->output == data);
175 if (output->fullscreen_view.fs &&
176 output->fullscreen_view.fs->view) {
177 weston_surface_unref(output->fullscreen_view.fs->view->surface);
178 weston_buffer_destroy_solid(output->fullscreen_view.buffer_ref);
179 output->fullscreen_view.fs->view = NULL;
182 ivi_layout_save(output->ivi, output);
184 output->output = NULL;
185 wl_list_remove(&output->output_destroy.link);
189 to_ivi_output(struct weston_output *o)
191 struct wl_listener *listener;
192 struct ivi_output *output;
194 listener = weston_output_get_destroy_listener(o, handle_output_destroy);
198 output = wl_container_of(listener, output, output_destroy);
204 ivi_output_configure_app_id(struct ivi_output *ivi_output)
206 if (ivi_output->config) {
207 if (ivi_output->app_ids != NULL)
210 weston_config_section_get_string(ivi_output->config,
212 &ivi_output->app_ids,
215 if (ivi_output->app_ids == NULL)
218 weston_log("Will place app_id %s on output %s\n",
219 ivi_output->app_ids, ivi_output->name);
223 static struct ivi_output *
224 ivi_ensure_output(struct ivi_compositor *ivi, char *name,
225 struct weston_config_section *config,
226 struct weston_head *head)
228 struct ivi_output *output = NULL;
229 wl_list_for_each(output, &ivi->outputs, link) {
230 if (strcmp(output->name, name) == 0) {
236 output = zalloc(sizeof *output);
244 output->config = config;
247 weston_compositor_create_output(ivi->compositor, head, head->name);
248 if (!output->output) {
254 /* simple_output_configure might assume we have an ivi_output created
255 * by this point, which we do but we can only link it to a
256 * weston_output through the destroy listener, so install it earlier
257 * before actually running the callback handler */
258 output->output_destroy.notify = handle_output_destroy;
259 weston_output_add_destroy_listener(output->output,
260 &output->output_destroy);
262 if (ivi->simple_output_configure) {
263 int ret = ivi->simple_output_configure(output->output);
265 weston_log("Configuring output \"%s\" failed.\n",
266 weston_head_get_name(head));
267 weston_output_destroy(output->output);
268 ivi->init_failed = true;
272 if (weston_output_enable(output->output) < 0) {
273 weston_log("Enabling output \"%s\" failed.\n",
274 weston_head_get_name(head));
275 weston_output_destroy(output->output);
276 ivi->init_failed = true;
282 wl_list_insert(&ivi->outputs, &output->link);
283 ivi_output_configure_app_id(output);
289 count_heads(struct weston_output *output)
291 struct weston_head *iter = NULL;
294 while ((iter = weston_output_iterate_heads(output, iter)))
301 handle_head_destroy(struct wl_listener *listener, void *data)
303 struct weston_head *head = data;
304 struct weston_output *output;
306 wl_list_remove(&listener->link);
309 output = weston_head_get_output(head);
311 /* On shutdown path, the output might be already gone. */
315 /* We're the last head */
316 if (count_heads(output) <= 1)
317 weston_output_destroy(output);
321 add_head_destroyed_listener(struct weston_head *head)
323 /* We already have a destroy listener */
324 if (weston_head_get_destroy_listener(head, handle_head_destroy))
327 struct wl_listener *listener = zalloc(sizeof *listener);
331 listener->notify = handle_head_destroy;
332 weston_head_add_destroy_listener(head, listener);
336 ivi_configure_windowed_output_from_config(struct ivi_output *output,
337 struct ivi_output_config *defaults)
339 struct ivi_compositor *ivi = output->ivi;
340 struct weston_config_section *section = output->config;
348 weston_config_section_get_string(section, "mode", &mode, NULL);
349 if (!mode || sscanf(mode, "%dx%d", &width, &height) != 2) {
350 weston_log("Invalid mode for output %s. Using defaults.\n",
352 width = defaults->width;
353 height = defaults->height;
357 width = defaults->width;
358 height = defaults->height;
361 scale = defaults->scale;
363 if (ivi->cmdline.width)
364 width = ivi->cmdline.width;
365 if (ivi->cmdline.height)
366 height = ivi->cmdline.height;
367 if (ivi->cmdline.scale)
368 scale = ivi->cmdline.scale;
370 weston_output_set_scale(output->output, scale);
371 weston_output_set_transform(output->output, defaults->transform);
373 if (ivi->window_api->output_set_size(output->output, width, height) < 0) {
374 weston_log("Cannot configure output '%s' using weston_windowed_output_api.\n",
380 weston_log("Configured windowed_output_api to %dx%d, scale %d\n",
381 width, height, scale);
387 parse_transform(const char *transform, uint32_t *out)
389 static const struct { const char *name; uint32_t token; } transforms[] = {
390 { "normal", WL_OUTPUT_TRANSFORM_NORMAL },
391 { "rotate-90", WL_OUTPUT_TRANSFORM_90 },
392 { "rotate-180", WL_OUTPUT_TRANSFORM_180 },
393 { "rotate-270", WL_OUTPUT_TRANSFORM_270 },
394 { "flipped", WL_OUTPUT_TRANSFORM_FLIPPED },
395 { "flipped-rotate-90", WL_OUTPUT_TRANSFORM_FLIPPED_90 },
396 { "flipped-rotate-180", WL_OUTPUT_TRANSFORM_FLIPPED_180 },
397 { "flipped-rotate-270", WL_OUTPUT_TRANSFORM_FLIPPED_270 },
400 for (size_t i = 0; i < ARRAY_LENGTH(transforms); i++)
401 if (strcmp(transforms[i].name, transform) == 0) {
402 *out = transforms[i].token;
406 *out = WL_OUTPUT_TRANSFORM_NORMAL;
411 parse_activation_area(const char *geometry, struct ivi_output *output)
414 unsigned width, height, x, y;
416 n = sscanf(geometry, "%ux%u+%u,%u", &width, &height, &x, &y);
420 output->area_activation.width = width;
421 output->area_activation.height = height;
422 output->area_activation.x = x;
423 output->area_activation.y = y;
428 drm_configure_output(struct ivi_output *output)
430 struct ivi_compositor *ivi = output->ivi;
431 struct weston_config_section *section = output->config;
433 uint32_t transform = WL_OUTPUT_TRANSFORM_NORMAL;
434 enum weston_drm_backend_output_mode mode =
435 WESTON_DRM_BACKEND_OUTPUT_PREFERRED;
436 char *modeline = NULL;
437 char *gbm_format = NULL;
443 weston_config_section_get_int(section, "scale", &scale, 1);
444 weston_config_section_get_string(section, "transform", &t, "normal");
445 if (parse_transform(t, &transform) < 0)
446 weston_log("Invalid transform \"%s\" for output %s\n",
448 weston_config_section_get_string(section, "activation-area", &t, "");
449 if (parse_activation_area(t, output) < 0)
450 weston_log("Invalid activation-area \"%s\" for output %s\n",
455 weston_output_set_scale(output->output, scale);
456 weston_output_set_transform(output->output, transform);
460 weston_config_section_get_string(section, "mode", &m, "preferred");
462 /* This should have been handled earlier */
463 assert(strcmp(m, "off") != 0);
465 if (ivi->cmdline.use_current_mode || strcmp(m, "current") == 0) {
466 mode = WESTON_DRM_BACKEND_OUTPUT_CURRENT;
467 } else if (strcmp(m, "preferred") != 0) {
473 weston_config_section_get_string(section, "gbm-format",
476 weston_config_section_get_string(section, "seat", &seat, "");
479 if (ivi->drm_api->set_mode(output->output, mode, modeline) < 0) {
480 weston_log("Cannot configure output using weston_drm_output_api.\n");
486 ivi->drm_api->set_gbm_format(output->output, gbm_format);
489 ivi->drm_api->set_seat(output->output, seat);
496 * Reorgainizes the output's add array into two sections.
497 * add[0..ret-1] are the heads that failed to get attached.
498 * add[ret..add_len] are the heads that were successfully attached.
500 * The order between elements in each section is stable.
503 try_attach_heads(struct ivi_output *output)
507 for (size_t i = 1; i < output->add_len; i++) {
508 if (weston_output_attach_head(output->output, output->add[i]) < 0) {
509 struct weston_head *tmp = output->add[i];
510 memmove(&output->add[fail_len + 1], output->add[fail_len],
511 sizeof output->add[0] * (i - fail_len));
512 output->add[fail_len++] = tmp;
518 /* Place output exactly to the right of the most recently enabled output.
520 * Historically, we haven't given much thought to output placement,
521 * simply adding outputs in a horizontal line as they're enabled. This
522 * function simply sets an output's x coordinate to the right of the
523 * most recently enabled output, and its y to zero.
525 * If you're adding new calls to this function, you're also not giving
526 * much thought to output placement, so please consider carefully if
527 * it's really doing what you want.
529 * You especially don't want to use this for any code that won't
530 * immediately enable the passed output.
533 weston_output_lazy_align(struct weston_output *output)
535 struct weston_compositor *c;
536 struct weston_output *peer;
539 /* Put this output to the right of the most recently enabled output */
540 c = output->compositor;
541 if (!wl_list_empty(&c->output_list)) {
542 peer = container_of(c->output_list.prev,
543 struct weston_output, link);
544 next_x = peer->pos.c.x + peer->width;
546 output->pos.c.x = next_x;
552 * Like try_attach_heads, this reorganizes the output's add array into a failed
553 * and successful section.
554 * i is the number of heads that already failed the previous step.
557 try_enable_output(struct ivi_output *output, size_t i)
559 for (; i < output->add_len; ++i) {
560 struct weston_head *head;
562 weston_output_lazy_align(output->output);
564 if (weston_output_enable(output->output) == 0)
567 head = output->add[output->add_len - 1];
568 memmove(&output->add[i + 1], &output->add[i],
569 sizeof output->add[0] * (output->add_len - i));
570 output->add[i] = head;
572 weston_head_detach(head);
579 try_attach_enable_heads(struct ivi_output *output)
582 assert(!output->output->enabled);
584 fail_len = try_attach_heads(output);
586 if (drm_configure_output(output) < 0)
589 fail_len = try_enable_output(output, fail_len);
591 /* All heads failed to be attached */
592 if (fail_len == output->add_len)
595 /* For each successful head attached */
596 for (size_t i = fail_len; i < output->add_len; ++i)
597 add_head_destroyed_listener(output->add[i]);
599 ivi_layout_restore(output->ivi, output);
601 output->add_len = fail_len;
606 process_output(struct ivi_output *output)
608 if (output->output->enabled) {
609 output->add_len = try_attach_heads(output);
610 return output->add_len == 0 ? 0 : -1;
613 return try_attach_enable_heads(output);
617 drm_head_disable(struct ivi_compositor *ivi, struct weston_head *head)
619 struct weston_output *output;
620 struct ivi_output *ivi_output;
621 struct wl_listener *listener;
623 output = weston_head_get_output(head);
626 listener = weston_output_get_destroy_listener(output,
627 handle_output_destroy);
630 ivi_output = wl_container_of(listener, ivi_output, output_destroy);
631 assert(ivi_output->output == output);
633 weston_head_detach(head);
634 if (count_heads(ivi_output->output) == 0) {
635 if (ivi_output->output) {
636 /* ivi_output->output destruction may be deferred in
637 * some cases (see drm_output_destroy()), so we need to
638 * forcibly trigger the destruction callback now, or
639 * otherwise would later access data that we are about
642 struct weston_output *save = ivi_output->output;
644 handle_output_destroy(&ivi_output->output_destroy, save);
645 weston_output_destroy(save);
648 wl_list_remove(&ivi_output->link);
649 free(ivi_output->app_ids);
653 static struct weston_config_section *
654 find_controlling_output_config(struct weston_config *config,
657 struct weston_config_section *section;
661 same_as = strdup(name);
663 section = weston_config_get_section(config, "output",
665 if (!section && depth > 0)
666 weston_log("Configuration error: output section reffered"
667 "to by same-as=%s not found.\n", same_as);
674 weston_log("Configuration error: same-as nested too "
675 "deep for output '%s'.\n", name);
679 weston_config_section_get_string(section, "same-as",
687 drm_head_prepare_enable(struct ivi_compositor *ivi, struct weston_head *head)
689 const char *name = weston_head_get_name(head);
690 struct weston_config_section *section;
691 struct ivi_output *output;
692 char *output_name = NULL;
695 section = find_controlling_output_config(ivi->config, name);
699 weston_config_section_get_string(section, "mode", &mode, NULL);
700 if (mode && strcmp(mode, "off") == 0) {
706 weston_config_section_get_string(section, "name",
709 output_name = strdup(name);
715 output = ivi_ensure_output(ivi, output_name, section, head);
719 if (output->add_len >= ARRAY_LENGTH(output->add))
722 output->add[output->add_len++] = head;
726 drm_heads_changed(struct wl_listener *listener, void *arg)
728 struct weston_compositor *compositor = arg;
729 struct weston_head *head = NULL;
730 struct ivi_compositor *ivi = to_ivi_compositor(compositor);
731 struct ivi_output *output;
733 while ((head = weston_compositor_iterate_heads(ivi->compositor, head))) {
734 bool connected = weston_head_is_connected(head);
735 bool enabled = weston_head_is_enabled(head);
736 bool changed = weston_head_is_device_changed(head);
737 bool non_desktop = weston_head_is_non_desktop(head);
739 if (connected && !enabled && !non_desktop)
740 drm_head_prepare_enable(ivi, head);
741 else if (!connected && enabled)
742 drm_head_disable(ivi, head);
743 else if (enabled && changed)
744 weston_log("Detected a monitor change on head '%s', "
745 "not bothering to do anything about it.\n",
746 weston_head_get_name(head));
748 weston_head_reset_device_changed(head);
751 wl_list_for_each(output, &ivi->outputs, link) {
752 if (output->add_len == 0)
755 if (process_output(output) < 0) {
757 ivi->init_failed = true;
763 simple_head_enable(struct ivi_compositor *ivi, struct weston_head *head)
765 struct ivi_output *output;
766 struct weston_config_section *section;
767 char *output_name = NULL;
768 const char *name = weston_head_get_name(head);
770 section = find_controlling_output_config(ivi->config, name);
774 weston_config_section_get_string(section, "mode", &mode, NULL);
775 if (mode && strcmp(mode, "off") == 0) {
781 weston_config_section_get_string(section, "name",
784 output_name = strdup(name);
790 output = ivi_ensure_output(ivi, output_name, section, head);
792 weston_log("Failed to create output %s\n", output_name);
796 add_head_destroyed_listener(head);
801 simple_head_disable(struct weston_head *head)
803 struct weston_output *output;
804 struct wl_listener *listener;
806 listener = weston_head_get_destroy_listener(head, handle_head_destroy);
807 wl_list_empty(&listener->link);
809 output = weston_head_get_output(head);
811 weston_output_destroy(output);
816 simple_heads_changed(struct wl_listener *listener, void *arg)
818 struct weston_compositor *compositor = arg;
819 struct ivi_compositor *ivi = to_ivi_compositor(compositor);
820 struct weston_head *head = NULL;
826 while ((head = weston_compositor_iterate_heads(ivi->compositor, head))) {
827 connected = weston_head_is_connected(head);
828 enabled = weston_head_is_enabled(head);
829 changed = weston_head_is_device_changed(head);
830 non_desktop = weston_head_is_non_desktop(head);
832 if (connected && !enabled && !non_desktop) {
833 simple_head_enable(ivi, head);
834 } else if (!connected && enabled) {
835 simple_head_disable(head);
836 } else if (enabled && changed) {
837 weston_log("Detected a monitor change on head '%s', "
838 "not bothering to do anything about it.\n",
839 weston_head_get_name(head));
841 weston_head_reset_device_changed(head);
848 drm_backend_remoted_output_configure(struct weston_output *output,
849 struct weston_config_section *section,
851 const struct weston_remoting_api *api)
853 char *gbm_format = NULL;
856 char *pipeline = NULL;
859 uint32_t transform = WL_OUTPUT_TRANSFORM_NORMAL;
862 ret = api->set_mode(output, modeline);
864 weston_log("Cannot configure an output \"%s\" using "
865 "weston_remoting_api. Invalid mode\n",
870 weston_config_section_get_int(section, "scale", &scale, 1);
871 weston_output_set_scale(output, scale);
873 weston_config_section_get_string(section, "transform", &trans, "normal");
874 if (parse_transform(trans, &transform) < 0) {
875 weston_log("Invalid transform \"%s\" for output %s\n",
876 trans, output->name);
878 weston_output_set_transform(output, transform);
880 weston_config_section_get_string(section, "gbm-format",
882 api->set_gbm_format(output, gbm_format);
885 weston_config_section_get_string(section, "seat", &seat, "");
887 api->set_seat(output, seat);
890 weston_config_section_get_string(section, "gst-pipeline", &pipeline,
893 api->set_gst_pipeline(output, pipeline);
898 weston_config_section_get_string(section, "host", &host, NULL);
899 weston_config_section_get_int(section, "port", &port, 0);
900 if (!host || port <= 0 || 65533 < port) {
901 weston_log("Cannot configure an output \"%s\". "
902 "Need to specify gst-pipeline or "
903 "host and port (1-65533).\n", output->name);
905 api->set_host(output, host);
907 api->set_port(output, port);
914 remote_output_init(struct ivi_output *ivi_output,
915 struct weston_compositor *compositor,
916 struct weston_config_section *section,
917 const struct weston_remoting_api *api)
919 char *output_name, *modeline = NULL;
922 weston_config_section_get_string(section, "name", &output_name, NULL);
926 weston_config_section_get_string(section, "mode", &modeline, "off");
927 if (strcmp(modeline, "off") == 0)
930 ivi_output->output = api->create_output(compositor, output_name);
931 if (!ivi_output->output) {
932 weston_log("Cannot create remoted output \"%s\".\n",
937 ret = drm_backend_remoted_output_configure(ivi_output->output, section,
940 weston_log("Cannot configure remoted output \"%s\".\n",
945 if ((ret = weston_output_enable(ivi_output->output)) < 0) {
946 weston_log("Enabling remoted output \"%s\" failed.\n",
953 weston_log("remoted output '%s' enabled\n", ivi_output->output->name);
960 if (ivi_output->output)
961 weston_output_destroy(ivi_output->output);
967 ivi_enable_remote_outputs(struct ivi_compositor *ivi)
969 struct weston_config_section *remote_section = NULL;
970 const char *section_name;
971 struct weston_config *config = ivi->config;
973 while (weston_config_next_section(config, &remote_section, §ion_name)) {
974 if (strcmp(section_name, "remote-output"))
977 struct ivi_output *ivi_output = NULL;
978 bool output_found = false;
981 weston_config_section_get_string(remote_section,
982 "name", &_name, NULL);
983 wl_list_for_each(ivi_output, &ivi->outputs, link) {
984 if (!strcmp(ivi_output->name, _name)) {
995 ivi_output = zalloc(sizeof(*ivi_output));
1001 ivi_output->ivi = ivi;
1002 ivi_output->name = _name;
1003 ivi_output->config = remote_section;
1004 ivi_output->type = OUTPUT_REMOTE;
1006 if (remote_output_init(ivi_output, ivi->compositor,
1007 remote_section, ivi->remoting_api)) {
1008 free(ivi_output->name);
1013 ivi_output->output_destroy.notify = handle_output_destroy;
1014 weston_output_add_destroy_listener(ivi_output->output,
1015 &ivi_output->output_destroy);
1017 wl_list_insert(&ivi->outputs, &ivi_output->link);
1018 ivi_output_configure_app_id(ivi_output);
1023 load_remoting_plugin(struct ivi_compositor *ivi, struct weston_config *config)
1025 struct weston_compositor *compositor = ivi->compositor;
1026 int (*module_init)(struct weston_compositor *wc);
1028 module_init = weston_load_module("remoting-plugin.so",
1029 "weston_module_init",
1030 LIBWESTON_MODULEDIR);
1034 if (module_init(compositor) < 0)
1037 ivi->remoting_api = weston_remoting_get_api(compositor);
1038 if (!ivi->remoting_api)
1044 load_remoting_plugin(struct weston_compositor *compositor, struct weston_config *config)
1051 load_drm_backend(struct ivi_compositor *ivi, int *argc, char *argv[],
1052 enum weston_renderer_type renderer)
1054 struct weston_drm_backend_config config = {
1056 .struct_version = WESTON_DRM_BACKEND_CONFIG_VERSION,
1057 .struct_size = sizeof config,
1060 struct weston_config_section *section;
1061 int use_current_mode = 0;
1062 bool force_pixman = false;
1064 bool without_input = false;
1066 const struct weston_option options[] = {
1067 { WESTON_OPTION_STRING, "seat", 0, &config.seat_id },
1068 { WESTON_OPTION_STRING, "drm-device", 0, &config.specific_device },
1069 { WESTON_OPTION_BOOLEAN, "current-mode", 0, &use_current_mode },
1070 { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &force_pixman },
1071 { WESTON_OPTION_BOOLEAN, "continue-without-input", false, &without_input }
1074 parse_options(options, ARRAY_LENGTH(options), argc, argv);
1077 config.renderer = WESTON_RENDERER_PIXMAN;
1079 config.renderer = WESTON_RENDERER_AUTO;
1081 ivi->cmdline.use_current_mode = use_current_mode;
1083 section = weston_config_get_section(ivi->config, "core", NULL, NULL);
1084 weston_config_section_get_string(section, "gbm-format",
1085 &config.gbm_format, NULL);
1086 weston_config_section_get_uint(section, "pageflip-timeout",
1087 &config.pageflip_timeout, 0);
1088 weston_config_section_get_bool(section, "pixman-shadow", &use_shadow, 1);
1089 config.use_pixman_shadow = use_shadow;
1092 ivi->compositor->require_input = !without_input;
1094 ivi->heads_changed.notify = drm_heads_changed;
1095 weston_compositor_add_heads_changed_listener(ivi->compositor,
1096 &ivi->heads_changed);
1098 if (!weston_compositor_load_backend(ivi->compositor, WESTON_BACKEND_DRM,
1100 weston_log("Failed to load DRM backend\n");
1104 ivi->drm_api = weston_drm_output_get_api(ivi->compositor);
1105 if (!ivi->drm_api) {
1106 weston_log("Cannot use drm output api.\n");
1110 load_remoting_plugin(ivi, ivi->config);
1115 free(config.gbm_format);
1116 free(config.seat_id);
1121 windowed_parse_common_options(struct ivi_compositor *ivi, int *argc, char *argv[],
1122 bool *force_pixman, bool *fullscreen, int *output_count)
1124 struct weston_config_section *section;
1128 const struct weston_option options[] = {
1129 { WESTON_OPTION_INTEGER, "width", 0, &ivi->cmdline.width },
1130 { WESTON_OPTION_INTEGER, "height", 0, &ivi->cmdline.height },
1131 { WESTON_OPTION_INTEGER, "scale", 0, &ivi->cmdline.scale },
1132 { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &force_pixman },
1133 { WESTON_OPTION_BOOLEAN, "fullscreen", 0, &fs },
1134 { WESTON_OPTION_INTEGER, "output-count", 0, output_count },
1137 section = weston_config_get_section(ivi->config, "core", NULL, NULL);
1138 weston_config_section_get_bool(section, "use-pixman", &pixman, false);
1141 parse_options(options, ARRAY_LENGTH(options), argc, argv);
1142 *force_pixman = pixman;
1147 windowed_create_outputs(struct ivi_compositor *ivi, int output_count,
1148 const char *match_prefix, const char *name_prefix)
1150 struct weston_config_section *section = NULL;
1151 const char *section_name;
1152 char *default_output = NULL;
1154 size_t match_len = strlen(match_prefix);
1156 while (weston_config_next_section(ivi->config, §ion, §ion_name)) {
1159 if (i >= output_count)
1162 if (strcmp(section_name, "output") != 0)
1165 weston_config_section_get_string(section, "name", &output_name, NULL);
1166 if (output_name == NULL)
1168 if (strncmp(output_name, match_prefix, match_len) != 0) {
1173 if (ivi->window_api->create_head(ivi->backend, output_name) < 0) {
1182 for (; i < output_count; ++i) {
1183 if (asprintf(&default_output, "%s%d", name_prefix, i) < 0)
1186 if (ivi->window_api->create_head(ivi->backend, default_output) < 0) {
1187 free(default_output);
1191 free(default_output);
1199 wayland_backend_output_configure(struct weston_output *output)
1201 struct ivi_output *ivi_output = to_ivi_output(output);
1203 struct ivi_output_config defaults = {
1204 .width = WINDOWED_DEFAULT_WIDTH,
1205 .height = WINDOWED_DEFAULT_HEIGHT,
1207 .transform = WL_OUTPUT_TRANSFORM_NORMAL
1211 weston_log("Failed to configure and enable Wayland output. No ivi-output available!\n");
1215 return ivi_configure_windowed_output_from_config(to_ivi_output(output), &defaults);
1219 load_wayland_backend(struct ivi_compositor *ivi, int *argc, char *argv[],
1220 enum weston_renderer_type renderer)
1222 struct weston_wayland_backend_config config = {
1224 .struct_version = WESTON_WAYLAND_BACKEND_CONFIG_VERSION,
1225 .struct_size = sizeof config,
1228 struct weston_config_section *section;
1231 bool force_pixman = false;
1233 const struct weston_option options[] = {
1234 { WESTON_OPTION_STRING, "display", 0, &config.display_name },
1235 { WESTON_OPTION_STRING, "sprawl", 0, &sprawl },
1238 windowed_parse_common_options(ivi, argc, argv, &force_pixman,
1239 &config.fullscreen, &output_count);
1241 parse_options(options, ARRAY_LENGTH(options), argc, argv);
1242 config.sprawl = sprawl;
1244 section = weston_config_get_section(ivi->config, "shell", NULL, NULL);
1245 weston_config_section_get_string(section, "cursor-theme",
1246 &config.cursor_theme, NULL);
1247 weston_config_section_get_int(section, "cursor-size",
1248 &config.cursor_size, 32);
1250 ivi->simple_output_configure = wayland_backend_output_configure;
1251 ivi->heads_changed.notify = simple_heads_changed;
1252 weston_compositor_add_heads_changed_listener(ivi->compositor,
1253 &ivi->heads_changed);
1255 ivi->backend = weston_compositor_load_backend(ivi->compositor,
1256 WESTON_BACKEND_WAYLAND,
1258 if (!ivi->backend) {
1259 weston_log("Failed to create Wayland backend!\n");
1262 free(config.cursor_theme);
1263 free(config.display_name);
1268 ivi->window_api = weston_windowed_output_get_api(ivi->compositor);
1271 * We will just assume if load_backend() finished cleanly and
1272 * windowed_output_api is not present that wayland backend is started
1273 * with --sprawl or runs on fullscreen-shell. In this case, all values
1274 * are hardcoded, so nothing can be configured; simply create and
1277 if (ivi->window_api == NULL)
1280 return windowed_create_outputs(ivi, output_count, "WL", "wayland");
1283 #ifdef HAVE_BACKEND_X11
1285 x11_backend_output_configure(struct weston_output *output)
1287 struct ivi_output *ivi_output = to_ivi_output(output);
1289 struct ivi_output_config defaults = {
1290 .width = WINDOWED_DEFAULT_WIDTH,
1291 .height = WINDOWED_DEFAULT_HEIGHT,
1293 .transform = WL_OUTPUT_TRANSFORM_NORMAL
1297 weston_log("Failed to configure and enable X11 output. No ivi-output available!\n");
1302 return ivi_configure_windowed_output_from_config(ivi_output, &defaults);
1306 load_x11_backend(struct ivi_compositor *ivi, int *argc, char *argv[],
1307 enum weston_renderer_type renderer)
1309 struct weston_x11_backend_config config = {
1311 .struct_version = WESTON_X11_BACKEND_CONFIG_VERSION,
1312 .struct_size = sizeof config,
1317 bool force_pixman = false;
1319 const struct weston_option options[] = {
1320 { WESTON_OPTION_BOOLEAN, "no-input", 0, &no_input },
1323 windowed_parse_common_options(ivi, argc, argv, &force_pixman,
1324 &config.fullscreen, &output_count);
1326 parse_options(options, ARRAY_LENGTH(options), argc, argv);
1328 config.renderer = WESTON_RENDERER_PIXMAN;
1330 config.renderer = WESTON_RENDERER_AUTO;
1331 config.no_input = no_input;
1333 ivi->simple_output_configure = x11_backend_output_configure;
1335 ivi->heads_changed.notify = simple_heads_changed;
1336 weston_compositor_add_heads_changed_listener(ivi->compositor,
1337 &ivi->heads_changed);
1339 ivi->backend = weston_compositor_load_backend(ivi->compositor,
1342 if (!ivi->backend) {
1343 weston_log("Failed to create X11 backend!\n");
1347 ivi->window_api = weston_windowed_output_get_api(ivi->compositor);
1348 if (!ivi->window_api) {
1349 weston_log("Cannot use weston_windowed_output_api.\n");
1353 return windowed_create_outputs(ivi, output_count, "X", "screen");
1357 load_x11_backend(struct ivi_compositor *ivi, int *argc, char **argv,
1358 enum weston_renderer_type renderer)
1364 #ifdef HAVE_BACKEND_RDP
1366 weston_rdp_backend_config_init(struct weston_rdp_backend_config *config)
1368 config->base.struct_version = WESTON_RDP_BACKEND_CONFIG_VERSION;
1369 config->base.struct_size = sizeof(struct weston_rdp_backend_config);
1371 config->renderer = WESTON_RENDERER_AUTO;
1372 config->bind_address = NULL;
1373 config->port = 3389;
1374 config->rdp_key = NULL;
1375 config->server_cert = NULL;
1376 config->server_key = NULL;
1377 config->env_socket = 0;
1378 config->external_listener_fd = -1;
1379 config->no_clients_resize = 0;
1380 config->force_no_compression = 0;
1381 config->remotefx_codec = true;
1382 config->refresh_rate = RDP_DEFAULT_FREQ;
1387 rdp_backend_output_configure(struct weston_output *output)
1389 struct ivi_compositor *ivi = to_ivi_compositor(output->compositor);
1390 struct ivi_output_config *parsed_options = ivi->parsed_options;
1391 const struct weston_rdp_output_api *api =
1392 weston_rdp_output_get_api(output->compositor);
1395 struct weston_config_section *section;
1396 uint32_t transform = WL_OUTPUT_TRANSFORM_NORMAL;
1397 char *transform_string;
1398 struct weston_mode new_mode = {};
1400 assert(parsed_options);
1403 weston_log("Cannot use weston_rdp_output_api.\n");
1407 section = weston_config_get_section(ivi->config, "rdp", NULL, NULL);
1409 if (parsed_options->width)
1410 width = parsed_options->width;
1412 if (parsed_options->height)
1413 height = parsed_options->height;
1415 weston_output_set_scale(output, 1);
1417 weston_config_section_get_int(section, "width",
1420 weston_config_section_get_int(section, "height",
1423 if (parsed_options->transform)
1424 transform = parsed_options->transform;
1426 weston_config_section_get_string(section, "transform",
1427 &transform_string, "normal");
1429 if (parse_transform(transform_string, &transform) < 0) {
1430 weston_log("Invalid transform \"%s\" for output %s\n",
1431 transform_string, output->name);
1436 new_mode.width = width;
1437 new_mode.height = height;
1439 weston_log("Setting modeline to %dx%d\n", width, height);
1441 api->output_set_mode(output, &new_mode);
1442 weston_output_set_transform(output, transform);
1448 load_rdp_backend(struct ivi_compositor *ivi, int *argc, char **argv,
1449 enum weston_renderer_type renderer)
1451 struct weston_rdp_backend_config config = {};
1452 struct weston_config_section *section;
1453 bool no_remotefx_codec = false;
1455 struct ivi_output_config *parsed_options = ivi_init_parsed_options(ivi->compositor);
1456 if (!parsed_options)
1459 weston_rdp_backend_config_init(&config);
1461 const struct weston_option rdp_options[] = {
1462 { WESTON_OPTION_BOOLEAN, "env-socket", 0, &config.env_socket },
1463 { WESTON_OPTION_INTEGER, "external-listener-fd", 0, &config.external_listener_fd },
1464 { WESTON_OPTION_INTEGER, "width", 0, &parsed_options->width },
1465 { WESTON_OPTION_INTEGER, "height", 0, &parsed_options->height },
1466 { WESTON_OPTION_STRING, "address", 0, &config.bind_address },
1467 { WESTON_OPTION_INTEGER, "port", 0, &config.port },
1468 { WESTON_OPTION_BOOLEAN, "no-clients-resize", 0, &config.no_clients_resize },
1469 { WESTON_OPTION_STRING, "rdp4-key", 0, &config.rdp_key },
1470 { WESTON_OPTION_STRING, "rdp-tls-cert", 0, &config.server_cert },
1471 { WESTON_OPTION_STRING, "rdp-tls-key", 0, &config.server_key },
1472 { WESTON_OPTION_INTEGER, "scale", 0, &parsed_options->scale },
1473 { WESTON_OPTION_BOOLEAN, "force-no-compression", 0, &config.force_no_compression },
1474 { WESTON_OPTION_BOOLEAN, "no-remotefx-codec", 0, &no_remotefx_codec },
1477 config.remotefx_codec = !no_remotefx_codec;
1478 config.renderer = renderer;
1480 section = weston_config_get_section(ivi->config, "rdp", NULL, NULL);
1482 weston_config_section_get_int(section, "refresh-rate",
1483 &config.refresh_rate, RDP_DEFAULT_FREQ);
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);
1493 weston_log("No clients resize: %d\n", config.no_clients_resize);
1495 ivi->simple_output_configure = rdp_backend_output_configure;
1497 ivi->heads_changed.notify = simple_heads_changed;
1498 weston_compositor_add_heads_changed_listener(ivi->compositor,
1499 &ivi->heads_changed);
1501 if (!weston_compositor_load_backend(ivi->compositor,
1502 WESTON_BACKEND_RDP, &config.base)) {
1503 weston_log("Failed to create RDP backend\n");
1507 free(config.bind_address);
1508 free(config.rdp_key);
1509 free(config.server_cert);
1510 free(config.server_key);
1516 load_rdp_backend(struct ivi_compositor *ivi, int *argc, char **argv,
1517 enum weston_renderer_type renderer)
1525 load_backend(struct ivi_compositor *ivi, int *argc, char **argv,
1526 const char *backend_name, const char *renderer_name)
1528 enum weston_compositor_backend backend;
1529 enum weston_renderer_type renderer;
1531 if (!get_backend_from_string(backend_name, &backend)) {
1532 weston_log("Error: unknown backend \"%s\"\n", backend_name);
1536 if (!get_renderer_from_string(renderer_name, &renderer)) {
1537 weston_log("Error: unknown renderer \"%s\"\n", renderer_name);
1542 case WESTON_BACKEND_DRM:
1543 return load_drm_backend(ivi, argc, argv, renderer);
1544 case WESTON_BACKEND_RDP:
1545 return load_rdp_backend(ivi, argc, argv, renderer);
1546 case WESTON_BACKEND_WAYLAND:
1547 return load_wayland_backend(ivi, argc, argv, renderer);
1548 case WESTON_BACKEND_X11:
1549 return load_x11_backend(ivi, argc, argv, renderer);
1551 assert(!"unknown backend type in load_backend()");
1558 load_modules(struct ivi_compositor *ivi, const char *modules,
1559 int *argc, char *argv[], bool *xwayland)
1561 const char *p, *end;
1563 int (*module_init)(struct weston_compositor *wc, int argc, char *argv[]);
1565 if (modules == NULL)
1570 end = strchrnul(p, ',');
1571 snprintf(buffer, sizeof buffer, "%.*s", (int) (end - p), p);
1573 if (strstr(buffer, "xwayland.so")) {
1575 } else if (strstr(buffer, "systemd-notify.so")) {
1576 weston_log("systemd-notify plug-in already loaded!\n");
1578 module_init = weston_load_module(buffer, "wet_module_init", WESTON_MODULEDIR);
1582 if (module_init(ivi->compositor, *argc, argv) < 0)
1597 choose_default_backend(void)
1599 char *backend = NULL;
1601 if (getenv("WAYLAND_DISPLAY") || getenv("WAYLAND_SOCKET"))
1602 backend = strdup("wayland-backend.so");
1603 else if (getenv("DISPLAY"))
1604 backend = strdup("x11-backend.so");
1606 backend = strdup("drm-backend.so");
1612 compositor_init_config(struct ivi_compositor *ivi)
1614 struct xkb_rule_names xkb_names;
1615 struct weston_config_section *section;
1616 struct weston_compositor *compositor = ivi->compositor;
1617 struct weston_config *config = ivi->config;
1622 /* agl-compositor.ini [keyboard] */
1623 section = weston_config_get_section(config, "keyboard", NULL, NULL);
1624 weston_config_section_get_string(section, "keymap_rules",
1625 (char **) &xkb_names.rules, NULL);
1626 weston_config_section_get_string(section, "keymap_model",
1627 (char **) &xkb_names.model, NULL);
1628 weston_config_section_get_string(section, "keymap_layout",
1629 (char **) &xkb_names.layout, NULL);
1630 weston_config_section_get_string(section, "keymap_variant",
1631 (char **) &xkb_names.variant, NULL);
1632 weston_config_section_get_string(section, "keymap_options",
1633 (char **) &xkb_names.options, NULL);
1635 if (weston_compositor_set_xkb_rule_names(compositor, &xkb_names) < 0)
1638 weston_config_section_get_int(section, "repeat-rate",
1639 &compositor->kb_repeat_rate, 40);
1640 weston_config_section_get_int(section, "repeat-delay",
1641 &compositor->kb_repeat_delay, 400);
1643 weston_config_section_get_bool(section, "vt-switching",
1644 &vt_switching, false);
1645 compositor->vt_switching = vt_switching;
1647 /* agl-compositor.ini [core] */
1648 section = weston_config_get_section(config, "core", NULL, NULL);
1650 weston_config_section_get_bool(section, "disable-cursor",
1651 &ivi->disable_cursor, false);
1652 weston_config_section_get_bool(section, "activate-by-default",
1653 &ivi->activate_by_default, true);
1655 weston_config_section_get_bool(section, "require-input", &require_input, true);
1656 compositor->require_input = require_input;
1658 weston_config_section_get_int(section, "repaint-window", &repaint_msec,
1659 compositor->repaint_msec);
1660 if (repaint_msec < -10 || repaint_msec > 1000) {
1661 weston_log("Invalid repaint_window value in config: %d\n",
1664 compositor->repaint_msec = repaint_msec;
1666 weston_log("Output repaint window is %d ms maximum.\n",
1667 compositor->repaint_msec);
1672 struct ivi_surface *
1673 to_ivi_surface(struct weston_surface *surface)
1675 struct weston_desktop_surface *dsurface;
1677 dsurface = weston_surface_get_desktop_surface(surface);
1681 return weston_desktop_surface_get_user_data(dsurface);
1685 activate_binding(struct weston_seat *seat,
1686 struct weston_view *focus_view, uint32_t flags)
1688 struct weston_surface *focus_surface;
1689 struct weston_surface *main_surface;
1690 struct ivi_surface *ivi_surface;
1691 struct ivi_shell_seat *ivi_seat = get_ivi_shell_seat(seat);
1696 focus_surface = focus_view->surface;
1697 main_surface = weston_surface_get_main_surface(focus_surface);
1699 ivi_surface = to_ivi_surface(main_surface);
1704 ivi_shell_activate_surface(ivi_surface, ivi_seat, flags);
1708 click_to_activate_binding(struct weston_pointer *pointer,
1709 const struct timespec *time,
1710 uint32_t button, void *data)
1712 if (pointer->grab != &pointer->default_grab)
1714 if (pointer->focus == NULL)
1717 activate_binding(pointer->seat, pointer->focus,
1718 WESTON_ACTIVATE_FLAG_CLICKED);
1722 touch_to_activate_binding(struct weston_touch *touch,
1723 const struct timespec *time,
1726 if (touch->grab != &touch->default_grab)
1728 if (touch->focus == NULL)
1731 activate_binding(touch->seat, touch->focus,
1732 WESTON_ACTIVATE_FLAG_NONE);
1736 add_bindings(struct weston_compositor *compositor)
1738 weston_compositor_add_button_binding(compositor, BTN_LEFT, 0,
1739 click_to_activate_binding,
1741 weston_compositor_add_button_binding(compositor, BTN_RIGHT, 0,
1742 click_to_activate_binding,
1744 weston_compositor_add_touch_binding(compositor, 0,
1745 touch_to_activate_binding,
1750 create_listening_socket(struct wl_display *display, const char *socket_name)
1753 if (wl_display_add_socket(display, socket_name)) {
1754 weston_log("fatal: failed to add socket: %s\n",
1759 socket_name = wl_display_add_socket_auto(display);
1761 weston_log("fatal: failed to add socket: %s\n",
1767 setenv("WAYLAND_DISPLAY", socket_name, 1);
1773 global_filter(const struct wl_client *client, const struct wl_global *global,
1780 load_config(struct weston_config **config, bool no_config,
1781 const char *config_file)
1783 const char *file = "agl-compositor.ini";
1784 const char *full_path;
1790 *config = weston_config_parse(file);
1793 full_path = weston_config_get_full_path(*config);
1795 weston_log("Using config file '%s'.\n", full_path);
1796 setenv(WESTON_CONFIG_FILE_ENV_VAR, full_path, 1);
1801 if (config_file && !no_config) {
1802 weston_log("fatal: error opening or reading config file '%s'.\n",
1808 weston_log("Starting with no config file.\n");
1809 setenv(WESTON_CONFIG_FILE_ENV_VAR, "", 1);
1814 static FILE *logfile;
1817 log_timestamp(char *buf, size_t len)
1820 struct tm *brokendown_time;
1824 gettimeofday(&tv, NULL);
1826 brokendown_time = localtime(&tv.tv_sec);
1827 if (brokendown_time == NULL) {
1828 snprintf(buf, len, "%s", "[(NULL)localtime] ");
1832 memset(datestr, 0, sizeof(datestr));
1833 if (brokendown_time->tm_mday != cached_tm_mday) {
1834 strftime(datestr, sizeof(datestr), "Date: %Y-%m-%d %Z\n",
1836 cached_tm_mday = brokendown_time->tm_mday;
1839 strftime(timestr, sizeof(timestr), "%H:%M:%S", brokendown_time);
1840 /* if datestr is empty it prints only timestr*/
1841 snprintf(buf, len, "%s[%s.%03li]", datestr,
1842 timestr, (tv.tv_usec / 1000));
1848 custom_handler(const char *fmt, va_list arg)
1852 weston_log_scope_printf(log_scope, "%s libwayland: ",
1853 log_timestamp(timestr, sizeof(timestr)));
1854 weston_log_scope_vprintf(log_scope, fmt, arg);
1858 log_file_open(const char *filename)
1860 wl_log_set_handler_server(custom_handler);
1863 logfile = fopen(filename, "a");
1868 os_fd_set_cloexec(fileno(logfile));
1869 setvbuf(logfile, NULL, _IOLBF, 256);
1874 log_file_close(void)
1876 if (logfile && logfile != stderr)
1882 vlog(const char *fmt, va_list ap)
1884 const char *oom = "Out of memory";
1889 if (weston_log_scope_is_enabled(log_scope)) {
1891 char *xlog_timestamp = log_timestamp(timestr, sizeof(timestr));
1892 len_va = vasprintf(&str, fmt, ap);
1894 len = weston_log_scope_printf(log_scope, "%s %s",
1895 xlog_timestamp, str);
1898 len = weston_log_scope_printf(log_scope, "%s %s",
1899 xlog_timestamp, oom);
1908 vlog_continue(const char *fmt, va_list ap)
1910 return weston_log_scope_vprintf(log_scope, fmt, ap);
1914 on_term_signal(int signo, void *data)
1916 struct wl_display *display = data;
1918 weston_log("caught signal %d\n", signo);
1919 wl_display_terminate(display);
1925 handle_exit(struct weston_compositor *compositor)
1927 wl_display_terminate(compositor->wl_display);
1931 usage(int error_code)
1933 FILE *out = error_code == EXIT_SUCCESS ? stdout : stderr;
1935 "Usage: agl-compositor [OPTIONS]\n"
1937 "This is " PACKAGE_STRING ", the reference compositor for\n"
1938 "Automotive Grade Linux. " PACKAGE_STRING " supports multiple "
1939 "backends,\nand depending on which backend is in use different "
1940 "options will be accepted.\n"
1944 " --version\t\tPrint agl-compositor version\n"
1945 " -B, --backend=MODULE\tBackend module, one of\n"
1946 "\t\t\t\tdrm-backend.so\n"
1947 "\t\t\t\twayland-backend.so\n"
1948 "\t\t\t\tx11-backend.so\n"
1949 "\t\t\t\theadless-backend.so\n"
1950 " -r, --renderer=NAME\tName of renderer to use: auto, gl, noop, pixman\n"
1951 " -S, --socket=NAME\tName of socket to listen on\n"
1952 " --log=FILE\t\tLog to the given file\n"
1953 " -c, --config=FILE\tConfig file to load, defaults to agl-compositor.ini\n"
1954 " --no-config\t\tDo not read agl-compositor.ini\n"
1955 " --debug\t\tEnable debug extension(s)\n"
1956 " -h, --help\t\tThis help message\n"
1962 copy_command_line(int argc, char * const argv[])
1969 fp = open_memstream(&str, &size);
1973 fprintf(fp, "%s", argv[0]);
1974 for (i = 1; i < argc; i++)
1975 fprintf(fp, " %s", argv[i]);
1981 #if !defined(BUILD_XWAYLAND)
1983 wet_load_xwayland(struct weston_compositor *comp)
1985 weston_log("Attempted to load xwayland library but compositor "
1986 "was *not* built with xwayland support!\n");
1992 weston_log_setup_scopes(struct weston_log_context *log_ctx,
1993 struct weston_log_subscriber *subscriber,
1999 char *tokenize = strdup(names);
2000 char *token = strtok(tokenize, ",");
2002 weston_log_subscribe(log_ctx, subscriber, token);
2003 token = strtok(NULL, ",");
2009 weston_log_subscribe_to_scopes(struct weston_log_context *log_ctx,
2010 struct weston_log_subscriber *logger,
2011 const char *debug_scopes)
2013 if (logger && debug_scopes)
2014 weston_log_setup_scopes(log_ctx, logger, debug_scopes);
2016 weston_log_subscribe(log_ctx, logger, "log");
2020 int wet_main(int argc, char *argv[], const struct weston_testsuite_data *test_data)
2022 struct ivi_compositor ivi = { 0 };
2024 struct wl_display *display = NULL;
2025 struct wl_event_loop *loop;
2026 struct wl_event_source *signals[3] = { 0 };
2027 struct weston_config_section *section;
2028 /* Command line options */
2029 char *backend = NULL;
2030 char *socket_name = NULL;
2032 char *modules = NULL;
2033 char *option_modules = NULL;
2034 char *debug_scopes = NULL;
2039 bool list_debug_scopes = false;
2040 char *config_file = NULL;
2041 struct weston_log_context *log_ctx = NULL;
2042 struct weston_log_subscriber *logger;
2043 int ret = EXIT_FAILURE;
2044 bool xwayland = false;
2045 struct sigaction action;
2046 char *renderer = NULL;
2047 struct wet_process *process, *process_tmp;
2049 const struct weston_option core_options[] = {
2050 { WESTON_OPTION_STRING, "renderer", 'r', &renderer },
2051 { WESTON_OPTION_STRING, "backend", 'B', &backend },
2052 { WESTON_OPTION_STRING, "socket", 'S', &socket_name },
2053 { WESTON_OPTION_STRING, "log", 0, &log },
2054 { WESTON_OPTION_BOOLEAN, "help", 'h', &help },
2055 { WESTON_OPTION_BOOLEAN, "version", 0, &version },
2056 { WESTON_OPTION_BOOLEAN, "no-config", 0, &no_config },
2057 { WESTON_OPTION_BOOLEAN, "debug", 0, &debug },
2058 { WESTON_OPTION_STRING, "config", 'c', &config_file },
2059 { WESTON_OPTION_STRING, "modules", 0, &option_modules },
2060 { WESTON_OPTION_STRING, "debug-scopes", 'l', &debug_scopes },
2061 { WESTON_OPTION_STRING, "list-debug-scopes", 'L', &list_debug_scopes },
2064 wl_list_init(&ivi.outputs);
2065 wl_list_init(&ivi.saved_outputs);
2066 wl_list_init(&ivi.surfaces);
2067 wl_list_init(&ivi.pending_surfaces);
2068 wl_list_init(&ivi.popup_pending_apps);
2069 wl_list_init(&ivi.fullscreen_pending_apps);
2070 wl_list_init(&ivi.split_pending_apps);
2071 wl_list_init(&ivi.remote_pending_apps);
2072 wl_list_init(&ivi.desktop_clients);
2073 wl_list_init(&ivi.child_process_list);
2074 wl_list_init(&ivi.pending_apps);
2076 /* Prevent any clients we spawn getting our stdin */
2077 os_fd_set_cloexec(STDIN_FILENO);
2079 cmdline = copy_command_line(argc, argv);
2080 parse_options(core_options, ARRAY_LENGTH(core_options), &argc, argv);
2083 usage(EXIT_SUCCESS);
2086 printf(PACKAGE_STRING "\n");
2091 log_ctx = weston_log_ctx_create();
2093 fprintf(stderr, "Failed to initialize weston debug framework.\n");
2097 log_scope = weston_log_ctx_add_log_scope(log_ctx, "log",
2098 "agl-compositor log\n",
2102 weston_log_set_handler(vlog, vlog_continue);
2104 logger = weston_log_subscriber_create_log(logfile);
2105 weston_log_subscribe_to_scopes(log_ctx, logger, debug_scopes);
2107 weston_log("Command line: %s\n", cmdline);
2110 if (load_config(&ivi.config, no_config, config_file) < 0)
2112 section = weston_config_get_section(ivi.config, "core", NULL, NULL);
2114 weston_config_section_get_string(section, "backend", &backend,
2117 backend = choose_default_backend();
2120 display = wl_display_create();
2121 loop = wl_display_get_event_loop(display);
2123 wl_display_set_global_filter(display,
2124 global_filter, &ivi);
2126 /* Register signal handlers so we shut down cleanly */
2128 signals[0] = wl_event_loop_add_signal(loop, SIGTERM, on_term_signal,
2130 signals[1] = wl_event_loop_add_signal(loop, SIGUSR2, on_term_signal,
2132 signals[2] = wl_event_loop_add_signal(loop, SIGCHLD, sigchld_handler,
2135 /* When debugging the compositor, if use wl_event_loop_add_signal() to
2136 * catch SIGINT, the debugger can't catch it, and attempting to stop
2137 * the compositor from within the debugger results in weston exiting
2140 * Instead, use the sigaction() function, which sets up the signal in a
2141 * way that gdb can successfully catch, but have the handler for SIGINT
2142 * send SIGUSR2 (xwayland uses SIGUSR1), which we catch via
2143 * wl_event_loop_add_signal().
2145 action.sa_handler = sigint_helper;
2146 sigemptyset(&action.sa_mask);
2147 action.sa_flags = 0;
2148 sigaction(SIGINT, &action, NULL);
2150 for (size_t i = 0; i < ARRAY_LENGTH(signals); ++i)
2154 ivi.compositor = weston_compositor_create(display, log_ctx, &ivi, test_data);
2155 if (!ivi.compositor) {
2156 weston_log("fatal: failed to create compositor.\n");
2160 if (compositor_init_config(&ivi) < 0)
2161 goto error_compositor;
2163 if (load_backend(&ivi, &argc, argv, backend, renderer) < 0) {
2164 weston_log("fatal: failed to create compositor backend.\n");
2165 goto error_compositor;
2168 if (weston_compositor_backends_loaded(ivi.compositor) < 0)
2169 goto error_compositor;
2171 weston_compositor_flush_heads_changed(ivi.compositor);
2173 if (ivi_desktop_init(&ivi) < 0)
2174 goto error_compositor;
2176 ivi_seat_init(&ivi);
2178 /* load additional modules */
2179 weston_config_section_get_string(section, "modules", &modules, "");
2180 if (load_modules(&ivi, modules, &argc, argv, &xwayland) < 0)
2181 goto error_compositor;
2183 if (load_modules(&ivi, option_modules, &argc, argv, &xwayland) < 0)
2184 goto error_compositor;
2187 weston_config_section_get_bool(section, "xwayland", &xwayland,
2191 if (ivi_shell_init(&ivi) < 0)
2192 goto error_compositor;
2195 if (!wet_load_xwayland(ivi.compositor))
2196 goto error_compositor;
2199 if (ivi_policy_init(&ivi) < 0)
2200 goto error_compositor;
2203 if (list_debug_scopes) {
2204 struct weston_log_scope *nscope = NULL;
2206 weston_log("Printing available debug scopes:\n");
2208 while ((nscope = weston_log_scopes_iterate(log_ctx, nscope))) {
2209 weston_log("\tscope name: %s, desc: %s",
2210 weston_log_scope_get_name(nscope),
2211 weston_log_scope_get_description(nscope));
2216 goto error_compositor;
2219 add_bindings(ivi.compositor);
2221 if (ivi.remoting_api)
2222 ivi_enable_remote_outputs(&ivi);
2224 if (create_listening_socket(display, socket_name) < 0)
2225 goto error_compositor;
2227 ivi_shell_init_black_fs(&ivi);
2229 ivi.compositor->exit = handle_exit;
2231 weston_compositor_wake(ivi.compositor);
2233 ivi_shell_create_global(&ivi);
2235 ivi_launch_shell_client(&ivi, "shell-client",
2236 &ivi.shell_client.client);
2237 ivi_launch_shell_client(&ivi, "shell-client-ext",
2238 &ivi.shell_client_ext.client);
2241 ivi_screenshooter_create(&ivi);
2242 ivi_agl_systemd_notify(&ivi);
2244 wl_display_run(display);
2246 ret = ivi.compositor->exit_code;
2248 wl_display_destroy_clients(display);
2256 weston_compositor_destroy(ivi.compositor);
2258 weston_log_scope_destroy(log_scope);
2261 weston_log_subscriber_destroy(logger);
2262 weston_log_ctx_destroy(log_ctx);
2264 ivi_policy_destroy(ivi.policy);
2266 wl_list_for_each_safe(process, process_tmp, &ivi.child_process_list, link)
2267 ivi_process_destroy(process, 0, false);
2270 for (size_t i = 0; i < ARRAY_LENGTH(signals); ++i)
2272 wl_event_source_remove(signals[i]);
2274 wl_display_destroy(display);
2278 weston_config_destroy(ivi.config);
2284 free(option_modules);