main: Copy cmd line args and print them
[src/agl-compositor.git] / src / main.c
index 2cefcd6..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);
 }
@@ -280,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;
 }
 
@@ -558,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,
@@ -712,6 +756,7 @@ ivi_enable_remote_outputs(struct ivi_compositor *ivi)
                ivi_output->ivi = ivi;
                ivi_output->name = _name;
                ivi_output->config = remote_section;
+               ivi_output->type = OUTPUT_REMOTE;
 
                if (remote_output_init(ivi_output, ivi->compositor,
                                       remote_section, ivi->remoting_api)) {
@@ -729,6 +774,58 @@ ivi_enable_remote_outputs(struct ivi_compositor *ivi)
        }
 }
 
+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)
 {
@@ -804,6 +901,7 @@ load_drm_backend(struct ivi_compositor *ivi, int *argc, char *argv[])
        }
 
        load_remoting_plugin(ivi, ivi->config);
+       load_waltham_plugin(ivi, ivi->config);
 
 error:
        free(config.gbm_format);
@@ -989,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[])
@@ -999,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)
 {
@@ -1332,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"
@@ -1342,6 +1531,7 @@ 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"
@@ -1352,9 +1542,30 @@ usage(int error_code)
        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 };
@@ -1363,6 +1574,8 @@ 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;
@@ -1371,6 +1584,7 @@ int main(int argc, char *argv[])
        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 },
@@ -1381,6 +1595,7 @@ int main(int argc, char *argv[])
                { 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);
@@ -1392,10 +1607,10 @@ int main(int argc, char *argv[])
        wl_list_init(&ivi.remote_pending_apps);
        wl_list_init(&ivi.desktop_clients);
 
-
        /* 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)
@@ -1422,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);
@@ -1433,6 +1651,7 @@ int main(int argc, char *argv[])
        }
        /* 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);
@@ -1476,6 +1695,14 @@ int main(int argc, char *argv[])
 
        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;
 
@@ -1489,6 +1716,9 @@ int main(int argc, char *argv[])
        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;