layout: Migrate the layout save/restore to a more useful place
[src/agl-compositor.git] / src / compositor.c
index 6447662..61dbec6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2012-2021 Collabora, Ltd.
+ * Copyright © 2012-2024 Collabora, Ltd.
  *
  * Permission is hereby granted, free of charge, to any person obtaining
  * a copy of this software and associated documentation files (the
@@ -42,9 +42,6 @@
 #ifdef HAVE_BACKEND_RDP
 #include <libweston/backend-rdp.h>
 #endif
-#ifdef HAVE_BACKEND_HEADLESS
-#include <libweston/backend-headless.h>
-#endif
 #ifdef HAVE_BACKEND_X11
 #include <libweston/backend-x11.h>
 #endif
@@ -57,6 +54,7 @@
 #include "shared/os-compatibility.h"
 #include "shared/helpers.h"
 
+#include "config.h"
 #include "agl-shell-server-protocol.h"
 
 #ifdef HAVE_REMOTING
@@ -72,7 +70,7 @@ to_ivi_compositor(struct weston_compositor *ec)
        return weston_compositor_get_user_data(ec);
 }
 
-static struct ivi_output_config *
+struct ivi_output_config *
 ivi_init_parsed_options(struct weston_compositor *compositor)
 {
        struct ivi_compositor *ivi = to_ivi_compositor(compositor);
@@ -92,101 +90,66 @@ ivi_init_parsed_options(struct weston_compositor *compositor)
        return config;
 }
 
-
-
 static void
 sigint_helper(int sig)
 {
        raise(SIGUSR2);
 }
 
-void
-ivi_layout_save(struct ivi_compositor *ivi, struct ivi_output *output)
-{
-       struct ivi_output *new_output;
-       ivi->need_ivi_output_relayout = true;
-
-       new_output = zalloc(sizeof(*new_output));
-
-       new_output->ivi = ivi;
-       new_output->background = output->background;
-
-       new_output->top = output->top;
-       new_output->bottom = output->bottom;
-       new_output->left = output->left;
-       new_output->right = output->right;
-
-       new_output->active = output->active;
-       new_output->previous_active = output->previous_active;
-       new_output->name = strdup(output->name);
-       if (output->app_ids)
-               new_output->app_ids = strdup(output->app_ids);
-
-       new_output->area = output->area;
-       new_output->area_saved = output->area_saved;
-       new_output->area_activation = output->area_activation;
-
-       weston_log("saving output layout for output %s\n", new_output->name);
-
-       wl_list_insert(&ivi->saved_outputs, &new_output->link);
-}
-
-void
-ivi_layout_restore(struct ivi_compositor *ivi, struct ivi_output *n_output)
-{
-       struct ivi_output *output = NULL;
-       struct ivi_output *iter_output;
-
-       if (!ivi->need_ivi_output_relayout)
-               return;
-
-       ivi->need_ivi_output_relayout = false;
-
-       wl_list_for_each(iter_output, &ivi->saved_outputs, link) {
-               if (strcmp(n_output->name, iter_output->name) == 0) {
-                       output = iter_output;
-                       break;
+struct {
+        char *name;
+        enum weston_renderer_type renderer;
+} renderer_name_map[] = {
+        { "auto", WESTON_RENDERER_AUTO },
+        { "gl", WESTON_RENDERER_GL },
+        { "noop", WESTON_RENDERER_NOOP },
+        { "pixman", WESTON_RENDERER_PIXMAN },
+};
+
+struct {
+       char *short_name;
+       char *long_name;
+       enum weston_compositor_backend backend;
+} backend_name_map[] = {
+       { "drm", "drm-backend.so", WESTON_BACKEND_DRM },
+       { "rdp", "rdp-backend.so", WESTON_BACKEND_RDP },
+       { "wayland", "wayland-backend.so", WESTON_BACKEND_WAYLAND },
+       { "x11", "x11-backend.so", WESTON_BACKEND_X11 },
+};
+
+bool
+get_backend_from_string(const char *name,
+               enum weston_compositor_backend *backend)
+{
+       size_t i;
+
+       for (i = 0; i < ARRAY_LENGTH(backend_name_map); i++) {
+               if (strcmp(name, backend_name_map[i].short_name) == 0 ||
+                               strcmp(name, backend_name_map[i].long_name) == 0) {
+                       *backend = backend_name_map[i].backend;
+                       return true;
                }
        }
 
-       if (!output)
-               return;
-
-       weston_log("restoring output layout for output %s\n", output->name);
-       n_output->background = output->background;
-
-       n_output->top = output->top;
-       n_output->bottom = output->bottom;
-       n_output->left = output->left;
-       n_output->right = output->right;
-
-       n_output->active = output->active;
-       n_output->previous_active = output->previous_active;
-       if (output->app_ids)
-               n_output->app_ids = strdup(output->app_ids);
-
-       n_output->area = output->area;
-       n_output->area_saved = output->area_saved;
-       n_output->area_activation = output->area_activation;
-
-       free(output->app_ids);
-       free(output->name);
-       wl_list_remove(&output->link);
-       free(output);
+       return false;
 }
 
-void
-ivi_layout_destroy_saved_outputs(struct ivi_compositor *ivi)
+bool
+get_renderer_from_string(const char *name, enum weston_renderer_type *renderer)
 {
-       struct ivi_output *output, *output_next;
+       size_t i;
 
-       wl_list_for_each_safe(output, output_next, &ivi->saved_outputs, link) {
-               free(output->app_ids);
-               free(output->name);
+       if (!name)
+               name = "auto";
 
-               wl_list_remove(&output->link);
-               free(output);
+       for (i = 0; i < ARRAY_LENGTH(renderer_name_map); i++) {
+               if (strcmp(name, renderer_name_map[i].name) == 0) {
+                       *renderer = renderer_name_map[i].renderer;
+                       return true;
+               }
        }
+
+       return false;
 }
 
 static void
@@ -199,7 +162,8 @@ handle_output_destroy(struct wl_listener *listener, void *data)
 
        if (output->fullscreen_view.fs &&
            output->fullscreen_view.fs->view) {
-               weston_surface_destroy(output->fullscreen_view.fs->view->surface);
+               weston_surface_unref(output->fullscreen_view.fs->view->surface);
+               weston_buffer_destroy_solid(output->fullscreen_view.buffer_ref);
                output->fullscreen_view.fs->view = NULL;
        }
 
@@ -264,16 +228,15 @@ ivi_ensure_output(struct ivi_compositor *ivi, char *name,
        output->name = name;
        output->config = config;
 
-       if (ivi->simple_output_configure) {
-               output->output =
-                       weston_compositor_create_output_with_head(ivi->compositor,
-                                                                 head);
-               if (!output->output) {
-                       free(output->name);
-                       free(output);
-                       return NULL;
-               }
+       output->output =
+               weston_compositor_create_output(ivi->compositor, head, head->name);
+       if (!output->output) {
+               free(output->name);
+               free(output);
+               return NULL;
+       }
 
+       if (ivi->simple_output_configure) {
                int ret = ivi->simple_output_configure(output->output);
                if (ret < 0) {
                        weston_log("Configuring output \"%s\" failed.\n",
@@ -290,15 +253,6 @@ ivi_ensure_output(struct ivi_compositor *ivi, char *name,
                        ivi->init_failed = true;
                        return NULL;
                }
-
-       } else {
-               output->output =
-                       weston_compositor_create_output(ivi->compositor, name);
-               if (!output->output) {
-                       free(output->name);
-                       free(output);
-                       return NULL;
-               }
        }
 
        output->output_destroy.notify = handle_output_destroy;
@@ -539,7 +493,7 @@ try_attach_heads(struct ivi_output *output)
 {
        size_t fail_len = 0;
 
-       for (size_t i = 0; i < output->add_len; ++i) {
+       for (size_t i = 1; i < output->add_len; i++) {
                if (weston_output_attach_head(output->output, output->add[i]) < 0) {
                        struct weston_head *tmp = output->add[i];
                        memmove(&output->add[fail_len + 1], output->add[fail_len],
@@ -550,6 +504,39 @@ try_attach_heads(struct ivi_output *output)
        return fail_len;
 }
 
+/* Place output exactly to the right of the most recently enabled output.
+ *
+ * Historically, we haven't given much thought to output placement,
+ * simply adding outputs in a horizontal line as they're enabled. This
+ * function simply sets an output's x coordinate to the right of the
+ * most recently enabled output, and its y to zero.
+ *
+ * If you're adding new calls to this function, you're also not giving
+ * much thought to output placement, so please consider carefully if
+ * it's really doing what you want.
+ *
+ * You especially don't want to use this for any code that won't
+ * immediately enable the passed output.
+ */
+static void
+weston_output_lazy_align(struct weston_output *output)
+{
+       struct weston_compositor *c;
+       struct weston_output *peer;
+       int next_x = 0;
+
+       /* Put this output to the right of the most recently enabled output */
+       c = output->compositor;
+       if (!wl_list_empty(&c->output_list)) {
+               peer = container_of(c->output_list.prev,
+                               struct weston_output, link);
+               next_x = peer->pos.c.x + peer->width;
+       }
+       output->pos.c.x = next_x;
+       output->pos.c.y = 0;
+}
+
+
 /*
  * Like try_attach_heads, this reorganizes the output's add array into a failed
  * and successful section.
@@ -561,6 +548,8 @@ try_enable_output(struct ivi_output *output, size_t i)
        for (; i < output->add_len; ++i) {
                struct weston_head *head;
 
+               weston_output_lazy_align(output->output);
+
                if (weston_output_enable(output->output) == 0)
                        break;
 
@@ -942,7 +931,8 @@ load_remoting_plugin(struct ivi_compositor *ivi, struct weston_config *config)
        int (*module_init)(struct weston_compositor *wc);
 
        module_init = weston_load_module("remoting-plugin.so",
-                                        "weston_module_init");
+                                        "weston_module_init",
+                                        LIBWESTON_MODULEDIR);
        if (!module_init)
                return -1;
 
@@ -963,7 +953,8 @@ load_remoting_plugin(struct weston_compositor *compositor, struct weston_config
 #endif
 
 static int
-load_drm_backend(struct ivi_compositor *ivi, int *argc, char *argv[])
+load_drm_backend(struct ivi_compositor *ivi, int *argc, char *argv[],
+                enum weston_renderer_type renderer)
 {
        struct weston_drm_backend_config config = {
                .base = {
@@ -973,21 +964,25 @@ load_drm_backend(struct ivi_compositor *ivi, int *argc, char *argv[])
        };
        struct weston_config_section *section;
        int use_current_mode = 0;
-       int use_pixman = 0;
+       bool force_pixman = false;
        bool use_shadow;
        bool without_input = false;
-       int ret;
 
        const struct weston_option options[] = {
                { WESTON_OPTION_STRING, "seat", 0, &config.seat_id },
                { WESTON_OPTION_STRING, "drm-device", 0, &config.specific_device },
                { WESTON_OPTION_BOOLEAN, "current-mode", 0, &use_current_mode },
-               { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &use_pixman },
+               { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &force_pixman },
                { WESTON_OPTION_BOOLEAN, "continue-without-input", false, &without_input }
        };
 
        parse_options(options, ARRAY_LENGTH(options), argc, argv);
-       config.use_pixman = use_pixman;
+
+       if (force_pixman)
+               config.renderer = WESTON_RENDERER_PIXMAN;
+       else
+               config.renderer = WESTON_RENDERER_AUTO;
+
        ivi->cmdline.use_current_mode = use_current_mode;
 
        section = weston_config_get_section(ivi->config, "core", NULL, NULL);
@@ -1001,29 +996,33 @@ load_drm_backend(struct ivi_compositor *ivi, int *argc, char *argv[])
        if (without_input)
                ivi->compositor->require_input = !without_input;
 
-       ret = weston_compositor_load_backend(ivi->compositor, WESTON_BACKEND_DRM,
-                                            &config.base);
-       if (ret < 0)
-               return ret;
+       ivi->heads_changed.notify = heads_changed;
+       weston_compositor_add_heads_changed_listener(ivi->compositor,
+                                                    &ivi->heads_changed);
+
+       if (!weston_compositor_load_backend(ivi->compositor, WESTON_BACKEND_DRM,
+                                           &config.base))
+               return -1;
 
        ivi->drm_api = weston_drm_output_get_api(ivi->compositor);
        if (!ivi->drm_api) {
                weston_log("Cannot use drm output api.\n");
-               ret = -1;
                goto error;
        }
 
        load_remoting_plugin(ivi, ivi->config);
 
+       return 0;
+
 error:
        free(config.gbm_format);
        free(config.seat_id);
-       return ret;
+       return -1;
 }
 
 static void
 windowed_parse_common_options(struct ivi_compositor *ivi, int *argc, char *argv[],
-                             bool *use_pixman, bool *fullscreen, int *output_count)
+                             bool *force_pixman, bool *fullscreen, int *output_count)
 {
        struct weston_config_section *section;
        bool pixman;
@@ -1033,17 +1032,17 @@ windowed_parse_common_options(struct ivi_compositor *ivi, int *argc, char *argv[
                { WESTON_OPTION_INTEGER, "width", 0, &ivi->cmdline.width },
                { WESTON_OPTION_INTEGER, "height", 0, &ivi->cmdline.height },
                { WESTON_OPTION_INTEGER, "scale", 0, &ivi->cmdline.scale },
-               { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &pixman },
+               { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &force_pixman },
                { WESTON_OPTION_BOOLEAN, "fullscreen", 0, &fs },
                { WESTON_OPTION_INTEGER, "output-count", 0, output_count },
        };
 
        section = weston_config_get_section(ivi->config, "core", NULL, NULL);
-       weston_config_section_get_bool(section, "use-pixman", &pixman, 0);
+       weston_config_section_get_bool(section, "use-pixman", &pixman, false);
 
        *output_count = 1;
        parse_options(options, ARRAY_LENGTH(options), argc, argv);
-       *use_pixman = pixman;
+       *force_pixman = pixman;
        *fullscreen = fs;
 }
 
@@ -1074,7 +1073,7 @@ windowed_create_outputs(struct ivi_compositor *ivi, int output_count,
                        continue;
                }
 
-               if (ivi->window_api->create_head(ivi->compositor, output_name) < 0) {
+               if (ivi->window_api->create_head(ivi->backend, output_name) < 0) {
                        free(output_name);
                        return -1;
                }
@@ -1087,7 +1086,7 @@ windowed_create_outputs(struct ivi_compositor *ivi, int output_count,
                if (asprintf(&default_output, "%s%d", name_prefix, i) < 0)
                        return -1;
 
-               if (ivi->window_api->create_head(ivi->compositor, default_output) < 0) {
+               if (ivi->window_api->create_head(ivi->backend, default_output) < 0) {
                        free(default_output);
                        return -1;
                }
@@ -1099,7 +1098,8 @@ windowed_create_outputs(struct ivi_compositor *ivi, int output_count,
 }
 
 static int
-load_wayland_backend(struct ivi_compositor *ivi, int *argc, char *argv[])
+load_wayland_backend(struct ivi_compositor *ivi, int *argc, char *argv[],
+                    enum weston_renderer_type renderer)
 {
        struct weston_wayland_backend_config config = {
                .base = {
@@ -1110,14 +1110,14 @@ load_wayland_backend(struct ivi_compositor *ivi, int *argc, char *argv[])
        struct weston_config_section *section;
        int sprawl = 0;
        int output_count;
-       int ret;
+       bool force_pixman = false;
 
        const struct weston_option options[] = {
                { WESTON_OPTION_STRING, "display", 0, &config.display_name },
                { WESTON_OPTION_STRING, "sprawl", 0, &sprawl },
        };
 
-       windowed_parse_common_options(ivi, argc, argv, &config.use_pixman,
+       windowed_parse_common_options(ivi, argc, argv, &force_pixman,
                                      &config.fullscreen, &output_count);
 
        parse_options(options, ARRAY_LENGTH(options), argc, argv);
@@ -1129,14 +1129,14 @@ load_wayland_backend(struct ivi_compositor *ivi, int *argc, char *argv[])
        weston_config_section_get_int(section, "cursor-size",
                                      &config.cursor_size, 32);
 
-       ret = weston_compositor_load_backend(ivi->compositor, WESTON_BACKEND_WAYLAND,
-                                            &config.base);
+       ivi->backend = weston_compositor_load_backend(ivi->compositor, WESTON_BACKEND_WAYLAND,
+                                                     &config.base);
 
        free(config.cursor_theme);
        free(config.display_name);
 
-       if (ret < 0)
-               return ret;
+       if (!ivi->backend)
+               return -1;
 
        ivi->window_api = weston_windowed_output_get_api(ivi->compositor);
 
@@ -1155,7 +1155,8 @@ load_wayland_backend(struct ivi_compositor *ivi, int *argc, char *argv[])
 
 #ifdef HAVE_BACKEND_X11
 static int
-load_x11_backend(struct ivi_compositor *ivi, int *argc, char *argv[])
+load_x11_backend(struct ivi_compositor *ivi, int *argc, char *argv[],
+                enum weston_renderer_type renderer)
 {
        struct weston_x11_backend_config config = {
                .base = {
@@ -1166,22 +1167,24 @@ load_x11_backend(struct ivi_compositor *ivi, int *argc, char *argv[])
        int no_input = 0;
        int output_count;
        int ret;
+       bool force_pixman = false;
 
        const struct weston_option options[] = {
               { WESTON_OPTION_BOOLEAN, "no-input", 0, &no_input },
        };
 
-       windowed_parse_common_options(ivi, argc, argv, &config.use_pixman,
+       windowed_parse_common_options(ivi, argc, argv, &force_pixman,
                                      &config.fullscreen, &output_count);
 
        parse_options(options, ARRAY_LENGTH(options), argc, argv);
+       if (force_pixman)
+               config.renderer = WESTON_RENDERER_PIXMAN;
+       else
+               config.renderer = WESTON_RENDERER_AUTO;
        config.no_input = no_input;
 
-       ret = weston_compositor_load_backend(ivi->compositor, WESTON_BACKEND_X11,
-                                            &config.base);
-
-       if (ret < 0)
-               return ret;
+       if (!weston_compositor_load_backend(ivi->compositor, WESTON_BACKEND_X11, &config.base))
+               return -1;
 
        ivi->window_api = weston_windowed_output_get_api(ivi->compositor);
        if (!ivi->window_api) {
@@ -1193,63 +1196,8 @@ load_x11_backend(struct ivi_compositor *ivi, int *argc, char *argv[])
 }
 #else
 static int
-load_x11_backend(struct ivi_compositor *ivi, int *argc, char *argv[])
-{
-       return -1;
-}
-#endif
-
-#ifdef HAVE_BACKEND_HEADLESS
-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;
-}
-#else
-static int
-load_headless_backend(struct ivi_compositor *ivi, int *argc, char **argv)
+load_x11_backend(struct ivi_compositor *ivi, int *argc, char **argv,
+                enum weston_renderer_type renderer)
 {
        return -1;
 }
@@ -1284,6 +1232,7 @@ rdp_backend_output_configure(struct weston_output *output)
        struct weston_config_section *section;
        uint32_t transform = WL_OUTPUT_TRANSFORM_NORMAL;
        char *transform_string;
+       struct weston_mode new_mode = {};
 
        assert(parsed_options);
 
@@ -1320,13 +1269,12 @@ rdp_backend_output_configure(struct weston_output *output)
                return -1;
        }
 
-       weston_output_set_transform(output, transform);
 
-       if (api->output_set_size(output, width, height) < 0) {
-               weston_log("Cannot configure output \"%s\" using weston_rdp_output_api.\n",
-                               output->name);
-               return -1;
-       }
+       new_mode.width = width;
+       new_mode.height = height;
+
+       api->output_set_mode(output, &new_mode);
+       weston_output_set_transform(output, transform);
 
        return 0;
 }
@@ -1335,7 +1283,6 @@ static int
 load_rdp_backend(struct ivi_compositor *ivi, int *argc, char **argv)
 {
        struct weston_rdp_backend_config config = {};
-       int ret = 0;
        struct weston_config_section *section;
 
        struct ivi_output_config *parsed_options = ivi_init_parsed_options(ivi->compositor);
@@ -1371,14 +1318,15 @@ load_rdp_backend(struct ivi_compositor *ivi, int *argc, char **argv)
        parse_options(rdp_options, ARRAY_LENGTH(rdp_options), argc, argv);
 
        ivi->simple_output_configure = rdp_backend_output_configure;
-       ret = weston_compositor_load_backend(ivi->compositor, WESTON_BACKEND_RDP, &config.base);
+       if (!weston_compositor_load_backend(ivi->compositor, WESTON_BACKEND_RDP, &config.base))
+               return -1;
 
        free(config.bind_address);
        free(config.rdp_key);
        free(config.server_cert);
        free(config.server_key);
 
-       return ret;
+       return 0;
 }
 #else
 static int
@@ -1390,23 +1338,36 @@ load_rdp_backend(struct ivi_compositor *ivi, int *argc, char **argv)
 
 
 static int
-load_backend(struct ivi_compositor *ivi, const char *backend,
-            int *argc, char *argv[])
-{
-       if (strcmp(backend, "drm-backend.so") == 0) {
-               return load_drm_backend(ivi, argc, argv);
-       } else if (strcmp(backend, "wayland-backend.so") == 0) {
-               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);
-       } else if (strcmp(backend, "rdp-backend.so") == 0) {
+load_backend(struct ivi_compositor *ivi, int *argc, char **argv,
+            const char *backend_name, const char *renderer_name)
+{
+       enum weston_compositor_backend backend;
+       enum weston_renderer_type renderer;
+
+       if (!get_backend_from_string(backend_name, &backend)) {
+               weston_log("Error: unknown backend \"%s\"\n", backend_name);
+               return -1;
+       }
+
+       if (!get_renderer_from_string(renderer_name, &renderer)) {
+               weston_log("Error: unknown renderer \"%s\"\n", renderer_name);
+               return -1;
+       }
+
+       switch (backend) {
+       case WESTON_BACKEND_DRM:
+               return load_drm_backend(ivi, argc, argv, renderer);
+       case WESTON_BACKEND_RDP:
                return load_rdp_backend(ivi, argc, argv);
+       case WESTON_BACKEND_WAYLAND:
+               return load_wayland_backend(ivi, argc, argv, renderer);
+       case WESTON_BACKEND_X11:
+               return load_x11_backend(ivi, argc, argv, renderer);
+       default:
+               assert(!"unknown backend type in load_backend()");
        }
 
-       weston_log("fatal: unknown backend '%s'.\n", backend);
-       return -1;
+       return 0;
 }
 
 static int
@@ -1430,7 +1391,7 @@ load_modules(struct ivi_compositor *ivi, const char *modules,
                } else if (strstr(buffer, "systemd-notify.so")) {
                        weston_log("systemd-notify plug-in already loaded!\n");
                } else {
-                       module_init = weston_load_module(buffer, "wet_module_init");
+                       module_init = weston_load_module(buffer, "wet_module_init", WESTON_MODULEDIR);
                        if (!module_init)
                                return -1;
 
@@ -1802,6 +1763,7 @@ usage(int error_code)
                        "\t\t\t\twayland-backend.so\n"
                        "\t\t\t\tx11-backend.so\n"
                        "\t\t\t\theadless-backend.so\n"
+               "  -r, --renderer=NAME\tName of renderer to use: auto, gl, noop, pixman\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"
@@ -1833,12 +1795,12 @@ copy_command_line(int argc, char * const argv[])
 }
 
 #if !defined(BUILD_XWAYLAND)
-int
+void *
 wet_load_xwayland(struct weston_compositor *comp)
 {
        weston_log("Attempted to load xwayland library but compositor "
                   "was *not* built with xwayland support!\n");
-       return -1;
+       return NULL;
 }
 #endif
 
@@ -1897,8 +1859,10 @@ int wet_main(int argc, char *argv[], const struct weston_testsuite_data *test_da
        int ret = EXIT_FAILURE;
        bool xwayland = false;
        struct sigaction action;
+       char *renderer = NULL;
 
        const struct weston_option core_options[] = {
+               { WESTON_OPTION_STRING, "renderer", 'r', &renderer },
                { WESTON_OPTION_STRING, "backend", 'B', &backend },
                { WESTON_OPTION_STRING, "socket", 'S', &socket_name },
                { WESTON_OPTION_STRING, "log", 0, &log },
@@ -2011,16 +1975,16 @@ int wet_main(int argc, char *argv[], const struct weston_testsuite_data *test_da
        if (compositor_init_config(&ivi) < 0)
                goto error_compositor;
 
-       if (load_backend(&ivi, backend, &argc, argv) < 0) {
+       if (load_backend(&ivi, &argc, argv, backend, renderer) < 0) {
                weston_log("fatal: failed to create compositor backend.\n");
                goto error_compositor;
        }
 
-       ivi.heads_changed.notify = heads_changed;
-       weston_compositor_add_heads_changed_listener(ivi.compositor,
-                                                    &ivi.heads_changed);
+       if (weston_compositor_backends_loaded(ivi.compositor) < 0)
+                goto error_compositor;
 
        weston_compositor_flush_heads_changed(ivi.compositor);
+
        if (ivi_desktop_init(&ivi) < 0)
                goto error_compositor;
 
@@ -2043,7 +2007,7 @@ int wet_main(int argc, char *argv[], const struct weston_testsuite_data *test_da
                goto error_compositor;
 
        if (xwayland) {
-               if (wet_load_xwayland(ivi.compositor) < 0)
+               if (!wet_load_xwayland(ivi.compositor))
                        goto error_compositor;
        }