main: Copy cmd line args and print them
[src/agl-compositor.git] / src / main.c
index 2571d17..126b938 100644 (file)
@@ -39,6 +39,7 @@
 
 #include <libweston/backend-drm.h>
 #include <libweston/backend-wayland.h>
+#include <libweston/backend-headless.h>
 #ifdef HAVE_BACKEND_X11
 #include <libweston/backend-x11.h>
 #endif
 #include "remote.h"
 #endif
 
+#ifdef HAVE_WALTHAM
+#include <waltham-transmitter/transmitter_api.h>
+#endif
+
 static int cached_tm_mday = -1;
 static struct weston_log_scope *log_scope;
 
@@ -74,6 +79,11 @@ handle_output_destroy(struct wl_listener *listener, void *data)
        output = wl_container_of(listener, output, output_destroy);
        assert(output->output == data);
 
+       if (output->fullscreen_view.fs->view) {
+               weston_surface_destroy(output->fullscreen_view.fs->view->surface);
+               output->fullscreen_view.fs->view = NULL;
+       }
+
        output->output = NULL;
        wl_list_remove(&output->output_destroy.link);
 }
@@ -101,6 +111,12 @@ ivi_output_configure_app_id(struct ivi_output *ivi_output)
                                                 "agl-shell-app-id",
                                                 &ivi_output->app_id,
                                                 NULL);
+
+               if (ivi_output->app_id == NULL)
+                       return;
+
+               weston_log("Will place app_id %s on output %s\n",
+                               ivi_output->app_id, ivi_output->name);
        }
 }
 
@@ -274,6 +290,8 @@ windowed_configure_output(struct ivi_output *output)
                return -1;
        }
 
+       weston_log("Configured windowed_output_api to %dx%d\n", width, height);
+
        return 0;
 }
 
@@ -552,6 +570,38 @@ heads_changed(struct wl_listener *listener, void *arg)
        }
 }
 
+#ifdef HAVE_WALTHAM
+static int
+load_waltham_plugin(struct ivi_compositor *ivi, struct weston_config *config)
+{
+       struct weston_compositor *compositor = ivi->compositor;
+       int (*module_init)(struct weston_compositor *wc);
+
+       module_init = weston_load_module("waltham-transmitter.so",
+                                        "wet_module_init");
+       if (!module_init)
+               return -1;
+
+       if (module_init(compositor) < 0)
+               return -1;
+
+       ivi->waltham_transmitter_api = weston_get_transmitter_api(compositor);
+       if (!ivi->waltham_transmitter_api) {
+               weston_log("Failed to load waltham-transmitter plugin.\n");
+               return -1;
+       }
+
+       weston_log("waltham-transmitter plug-in loaded\n");
+       return 0;
+}
+#else
+static int
+load_waltham_plugin(struct ivi_compositor *ivi, struct weston_config *config)
+{
+       return -1;
+}
+#endif
+
 #ifdef HAVE_REMOTING
 static int
 drm_backend_remoted_output_configure(struct weston_output *output,
@@ -672,25 +722,12 @@ err:
        return ret;
 }
 
-static int
-load_remoting(struct ivi_compositor *ivi, struct weston_config *config)
+static void
+ivi_enable_remote_outputs(struct ivi_compositor *ivi)
 {
-       struct weston_compositor *compositor = ivi->compositor;
-       int (*module_init)(struct weston_compositor *wc);
        struct weston_config_section *remote_section = NULL;
        const char *section_name;
-
-       module_init = weston_load_module("remoting-plugin.so",
-                                        "weston_module_init");
-       if (!module_init)
-               return -1;
-
-       if (module_init(compositor) < 0)
-               return -1;
-
-       ivi->remoting_api = weston_remoting_get_api(compositor);
-       if (!ivi->remoting_api)
-               return -1;
+       struct weston_config *config = ivi->config;
 
        while (weston_config_next_section(config, &remote_section, &section_name)) {
                if (strcmp(section_name, "remote-output"))
@@ -700,7 +737,8 @@ load_remoting(struct ivi_compositor *ivi, struct weston_config *config)
                bool output_found = false;
                char *_name = NULL;
 
-               weston_config_section_get_string(remote_section, "name", &_name, NULL);
+               weston_config_section_get_string(remote_section,
+                                                "name", &_name, NULL);
                wl_list_for_each(ivi_output, &ivi->outputs, link) {
                        if (!strcmp(ivi_output->name, _name)) {
                                output_found = true;
@@ -718,8 +756,9 @@ load_remoting(struct ivi_compositor *ivi, struct weston_config *config)
                ivi_output->ivi = ivi;
                ivi_output->name = _name;
                ivi_output->config = remote_section;
+               ivi_output->type = OUTPUT_REMOTE;
 
-               if (remote_output_init(ivi_output, compositor,
+               if (remote_output_init(ivi_output, ivi->compositor,
                                       remote_section, ivi->remoting_api)) {
                        free(ivi_output->name);
                        free(ivi_output);
@@ -733,12 +772,82 @@ load_remoting(struct ivi_compositor *ivi, struct weston_config *config)
                wl_list_insert(&ivi->outputs, &ivi_output->link);
                ivi_output_configure_app_id(ivi_output);
        }
+}
+
+static void
+ivi_enable_waltham_outputs(struct ivi_compositor *ivi)
+{
+       struct weston_config_section *transmitter_section = NULL;
+       const char *sect_name;
+       struct weston_config *config = ivi->config;
+
+       while (weston_config_next_section(config, &transmitter_section, &sect_name)) {
+               if (strcmp(sect_name, "transmitter-output"))
+                       continue;
+
+               struct ivi_output *ivi_output = NULL;
+               bool output_found = false;
+               char *_name = NULL;
+
+               weston_config_section_get_string(transmitter_section,
+                               "name", &_name, NULL);
+               wl_list_for_each(ivi_output, &ivi->outputs, link) {
+                       if (!strcmp(ivi_output->name, _name)) {
+                               output_found = true;
+                               break;
+                       }
+               }
+
+               if (output_found) {
+                       free(_name);
+                       continue;
+               }
+
+               ivi_output = zalloc(sizeof(*ivi_output));
+
+               ivi_output->ivi = ivi;
+               ivi_output->name = _name;
+               ivi_output->config = transmitter_section;
+
+               if (remote_output_init(ivi_output, ivi->compositor,
+                                       transmitter_section, ivi->remoting_api)) {
+                       free(ivi_output->name);
+                       free(ivi_output);
+                       continue;
+               }
+
+               ivi_output->type = OUTPUT_WALTHAM;
+               ivi_output->output_destroy.notify = handle_output_destroy;
+               weston_output_add_destroy_listener(ivi_output->output,
+                               &ivi_output->output_destroy);
+
+               wl_list_insert(&ivi->outputs, &ivi_output->link);
+               ivi_output_configure_app_id(ivi_output);
+       }
+}
+
+static int
+load_remoting_plugin(struct ivi_compositor *ivi, struct weston_config *config)
+{
+       struct weston_compositor *compositor = ivi->compositor;
+       int (*module_init)(struct weston_compositor *wc);
+
+       module_init = weston_load_module("remoting-plugin.so",
+                                        "weston_module_init");
+       if (!module_init)
+               return -1;
+
+       if (module_init(compositor) < 0)
+               return -1;
 
+       ivi->remoting_api = weston_remoting_get_api(compositor);
+       if (!ivi->remoting_api)
+               return -1;
        return 0;
 }
 #else
 static int
-load_remoting(struct weston_compositor *compositor, struct weston_config *config)
+load_remoting_plugin(struct weston_compositor *compositor, struct weston_config *config)
 {
        return -1;
 }
@@ -791,7 +900,8 @@ load_drm_backend(struct ivi_compositor *ivi, int *argc, char *argv[])
                goto error;
        }
 
-       load_remoting(ivi, ivi->config);
+       load_remoting_plugin(ivi, ivi->config);
+       load_waltham_plugin(ivi, ivi->config);
 
 error:
        free(config.gbm_format);
@@ -977,6 +1087,54 @@ load_x11_backend(struct ivi_compositor *ivi, int *argc, char *argv[])
 }
 #endif
 
+static int
+load_headless_backend(struct ivi_compositor *ivi, int *argc, char **argv)
+{
+       struct weston_headless_backend_config config = {};
+       int ret = 0;
+
+       bool use_pixman;
+       bool fullscreen;
+       bool use_gl;
+       int output_count;
+
+       struct weston_compositor *c = ivi->compositor;
+
+       const struct weston_option options[] = {
+               { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &use_pixman },
+               { WESTON_OPTION_BOOLEAN, "use-gl", 0, &use_gl },
+       };
+
+       windowed_parse_common_options(ivi, argc, argv, &use_pixman,
+                       &fullscreen, &output_count);
+
+       parse_options(options, ARRAY_LENGTH(options), argc, argv);
+       config.use_pixman = use_pixman;
+       config.use_gl = use_gl;
+
+       config.base.struct_version = WESTON_HEADLESS_BACKEND_CONFIG_VERSION;
+       config.base.struct_size = sizeof(struct weston_headless_backend_config);
+
+       /* load the actual headless-backend and configure it */
+       ret = weston_compositor_load_backend(c, WESTON_BACKEND_HEADLESS,
+                                            &config.base);
+       if (ret < 0)
+               return ret;
+
+       ivi->window_api = weston_windowed_output_get_api(c);
+       if (!ivi->window_api) {
+               weston_log("Cannot use weston_windowed_output_api.\n");
+               return -1;
+       }
+
+       if (ivi->window_api->create_head(c, "headless") < 0) {
+               weston_log("Cannot create headless back-end\n");
+               return -1;
+       }
+
+       return 0;
+}
+
 static int
 load_backend(struct ivi_compositor *ivi, const char *backend,
             int *argc, char *argv[])
@@ -987,12 +1145,54 @@ load_backend(struct ivi_compositor *ivi, const char *backend,
                return load_wayland_backend(ivi, argc, argv);
        } else if (strcmp(backend, "x11-backend.so") == 0) {
                return load_x11_backend(ivi, argc, argv);
+       } else if (strcmp(backend, "headless-backend.so") == 0) {
+               return load_headless_backend(ivi, argc, argv);
        }
 
        weston_log("fatal: unknown backend '%s'.\n", backend);
        return -1;
 }
 
+static int
+load_modules(struct ivi_compositor *ivi, const char *modules,
+            int *argc, char *argv[], bool *xwayland)
+{
+       const char *p, *end;
+       char buffer[256];
+       int (*module_init)(struct weston_compositor *wc, int argc, char *argv[]);
+
+       if (modules == NULL)
+               return 0;
+
+       p = modules;
+       while (*p) {
+               end = strchrnul(p, ',');
+               snprintf(buffer, sizeof buffer, "%.*s", (int) (end - p), p);
+
+               if (strstr(buffer, "xwayland.so")) {
+                       weston_log("Xwayland plug-in not supported!\n");
+                       p = end;
+                       while (*p == ',')
+                               p++;
+                       continue;
+               }
+
+               module_init = weston_load_module(buffer, "wet_module_init");
+               if (!module_init)
+                       return -1;
+
+               if (module_init(ivi->compositor, *argc, argv) < 0)
+                       return -1;
+
+               p = end;
+               while (*p == ',')
+                       p++;
+       }
+
+       return 0;
+}
+
+
 static char *
 choose_default_backend(void)
 {
@@ -1320,8 +1520,9 @@ usage(int error_code)
                "Usage: agl-compositor [OPTIONS]\n"
                "\n"
                "This is " PACKAGE_STRING ", the reference compositor for\n"
-               "Automotive Grade Linux. Weston-ivi supports multiple backends, and depending\n"
-               "on which backend is in use different options will be accepted.\n"
+               "Automotive Grade Linux. " PACKAGE_STRING " supports multiple "
+               "backends,\nand depending on which backend is in use different "
+               "options will be accepted.\n"
                "\n"
                "Core options:\n"
                "\n"
@@ -1330,19 +1531,41 @@ usage(int error_code)
                        "\t\t\t\tdrm-backend.so\n"
                        "\t\t\t\twayland-backend.so\n"
                        "\t\t\t\tx11-backend.so\n"
+                       "\t\t\t\theadless-backend.so\n"
                "  -S, --socket=NAME\tName of socket to listen on\n"
                "  --log=FILE\t\tLog to the given file\n"
                "  -c, --config=FILE\tConfig file to load, defaults to agl-compositor.ini\n"
                "  --no-config\t\tDo not read agl-compositor.ini\n"
-               "  --debug\t\tEnable debug extension\n"
+               "  --debug\t\tEnable debug extension(s)\n"
                "  -h, --help\t\tThis help message\n"
                "\n");
        exit(error_code);
 }
 
+static char *
+copy_command_line(int argc, char * const argv[])
+{
+       FILE *fp;
+       char *str = NULL;
+       size_t size = 0;
+       int i;
+
+       fp = open_memstream(&str, &size);
+       if (!fp)
+               return NULL;
+
+       fprintf(fp, "%s", argv[0]);
+       for (i = 1; i < argc; i++)
+               fprintf(fp, " %s", argv[i]);
+       fclose(fp);
+
+       return str;
+}
+
 int main(int argc, char *argv[])
 {
        struct ivi_compositor ivi = { 0 };
+       char *cmdline;
        struct wl_display *display = NULL;
        struct wl_event_loop *loop;
        struct wl_event_source *signals[3] = { 0 };
@@ -1351,13 +1574,17 @@ int main(int argc, char *argv[])
        char *backend = NULL;
        char *socket_name = NULL;
        char *log = NULL;
+       char *modules = NULL;
+       char *option_modules = NULL;
        int help = 0;
        int version = 0;
        int no_config = 0;
+       int debug = 0;
        char *config_file = NULL;
        struct weston_log_context *log_ctx = NULL;
        struct weston_log_subscriber *logger;
        int ret = EXIT_FAILURE;
+       bool xwayland = false;
 
        const struct weston_option core_options[] = {
                { WESTON_OPTION_STRING, "backend", 'B', &backend },
@@ -1366,7 +1593,9 @@ int main(int argc, char *argv[])
                { WESTON_OPTION_BOOLEAN, "help", 'h', &help },
                { WESTON_OPTION_BOOLEAN, "version", 0, &version },
                { WESTON_OPTION_BOOLEAN, "no-config", 0, &no_config },
+               { WESTON_OPTION_BOOLEAN, "debug", 0, &debug },
                { WESTON_OPTION_STRING, "config", 'c', &config_file },
+               { WESTON_OPTION_STRING, "modules", 0, &option_modules },
        };
 
        wl_list_init(&ivi.outputs);
@@ -1381,6 +1610,7 @@ int main(int argc, char *argv[])
        /* Prevent any clients we spawn getting our stdin */
        os_fd_set_cloexec(STDIN_FILENO);
 
+       cmdline = copy_command_line(argc, argv);
        parse_options(core_options, ARRAY_LENGTH(core_options), &argc, argv);
 
        if (help)
@@ -1407,6 +1637,9 @@ int main(int argc, char *argv[])
        logger = weston_log_subscriber_create_log(logfile);
        weston_log_subscribe(log_ctx, logger, "log");
 
+       weston_log("Command line: %s\n", cmdline);
+       free(cmdline);
+
        if (load_config(&ivi.config, no_config, config_file) < 0)
                goto error_signals;
        section = weston_config_get_section(ivi.config, "core", NULL, NULL);
@@ -1416,6 +1649,9 @@ int main(int argc, char *argv[])
                if (!backend)
                        backend = choose_default_backend();
        }
+       /* from [core] */
+       weston_config_section_get_bool(section, "hide-cursor", &ivi.hide_cursor, false);
+       weston_config_section_get_bool(section, "activate-by-default", &ivi.activate_by_default, true);
 
        display = wl_display_create();
        loop = wl_display_get_event_loop(display);
@@ -1457,6 +1693,16 @@ int main(int argc, char *argv[])
        if (ivi_desktop_init(&ivi) < 0)
                goto error_compositor;
 
+       ivi_seat_init(&ivi);
+
+       /* load additional modules */
+       weston_config_section_get_string(section, "modules", &modules, "");
+       if (load_modules(&ivi, modules, &argc, argv, &xwayland) < 0)
+               goto error_compositor;
+
+       if (load_modules(&ivi, option_modules, &argc, argv, &xwayland) < 0)
+               goto error_compositor;
+
        if (ivi_policy_init(&ivi) < 0)
                goto error_compositor;
 
@@ -1467,17 +1713,25 @@ int main(int argc, char *argv[])
 
        weston_compositor_flush_heads_changed(ivi.compositor);
 
-       ivi_shell_init_black_fs(&ivi);
+       if (ivi.remoting_api)
+               ivi_enable_remote_outputs(&ivi);
+
+       if (ivi.waltham_transmitter_api)
+               ivi_enable_waltham_outputs(&ivi);
 
        if (create_listening_socket(display, socket_name) < 0)
                goto error_compositor;
 
+       ivi_shell_init_black_fs(&ivi);
+
        ivi.compositor->exit = handle_exit;
 
        weston_compositor_wake(ivi.compositor);
 
        ivi_shell_create_global(&ivi);
        ivi_launch_shell_client(&ivi);
+       if (debug)
+               ivi_screenshooter_create(&ivi);
        ivi_agl_systemd_notify(&ivi);
 
        wl_display_run(display);