compositor: Don't reuse weston_compositor_create_output
[src/agl-compositor.git] / src / compositor.c
index 6097da0..59c3d9f 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
@@ -327,16 +327,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",
@@ -353,15 +352,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;
@@ -1076,7 +1066,6 @@ load_drm_backend(struct ivi_compositor *ivi, int *argc, char *argv[],
        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 },
@@ -1106,24 +1095,28 @@ 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
@@ -1179,7 +1172,7 @@ windowed_create_outputs(struct ivi_compositor *ivi, int output_count,
                        continue;
                }
 
-               if (ivi->window_api->create_head(ivi->compositor->backend, output_name) < 0) {
+               if (ivi->window_api->create_head(ivi->backend, output_name) < 0) {
                        free(output_name);
                        return -1;
                }
@@ -1192,7 +1185,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->backend, default_output) < 0) {
+               if (ivi->window_api->create_head(ivi->backend, default_output) < 0) {
                        free(default_output);
                        return -1;
                }
@@ -1217,7 +1210,6 @@ load_wayland_backend(struct ivi_compositor *ivi, int *argc, char *argv[],
        int sprawl = 0;
        int output_count;
        bool force_pixman = false;
-       int ret;
 
        const struct weston_option options[] = {
                { WESTON_OPTION_STRING, "display", 0, &config.display_name },
@@ -1236,14 +1228,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);
 
@@ -1290,11 +1282,8 @@ load_x11_backend(struct ivi_compositor *ivi, int *argc, char *argv[],
                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) {
@@ -1319,7 +1308,6 @@ load_headless_backend(struct ivi_compositor *ivi, int *argc, char **argv,
                      enum weston_renderer_type renderer)
 {
        struct weston_headless_backend_config config = {};
-       int ret = 0;
 
        bool force_pixman = false;
        bool fullscreen;
@@ -1327,6 +1315,7 @@ load_headless_backend(struct ivi_compositor *ivi, int *argc, char **argv,
        int output_count;
 
        struct weston_compositor *c = ivi->compositor;
+       struct weston_backend *wb = NULL;
 
        const struct weston_option options[] = {
                { WESTON_OPTION_BOOLEAN, "use-pixman", false, &force_pixman },
@@ -1354,10 +1343,8 @@ load_headless_backend(struct ivi_compositor *ivi, int *argc, char **argv,
        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;
+       if (!weston_compositor_load_backend(c, WESTON_BACKEND_HEADLESS, &config.base))
+               return -1;
 
        ivi->window_api = weston_windowed_output_get_api(c);
        if (!ivi->window_api) {
@@ -1365,7 +1352,11 @@ load_headless_backend(struct ivi_compositor *ivi, int *argc, char **argv,
                return -1;
        }
 
-       if (ivi->window_api->create_head(c->backend, "headless") < 0) {
+       wb = weston_compositor_load_backend(ivi->compositor, WESTON_BACKEND_HEADLESS, &config.base);
+       if (!wb)
+               return -1;
+
+       if (ivi->window_api->create_head(wb, "headless") < 0) {
                weston_log("Cannot create headless back-end\n");
                return -1;
        }
@@ -1409,6 +1400,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);
 
@@ -1445,13 +1437,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;
 }
@@ -1460,7 +1451,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);
@@ -1496,14 +1486,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
@@ -1530,19 +1521,23 @@ load_backend(struct ivi_compositor *ivi, int *argc, char **argv,
                weston_log("Error: unknown renderer \"%s\"\n", renderer_name);
                return -1;
        }
-       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) {
+
+       switch (backend) {
+       case WESTON_BACKEND_DRM:
+               return load_drm_backend(ivi, argc, argv, renderer);
+       case WESTON_BACKEND_HEADLESS:
+               return load_headless_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_name);
-       return -1;
+       return 0;
 }
 
 static int
@@ -1970,12 +1965,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
 
@@ -2155,11 +2150,11 @@ int wet_main(int argc, char *argv[], const struct weston_testsuite_data *test_da
                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;
 
@@ -2182,7 +2177,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;
        }