X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fcompositor.c;h=078157a06b69a9e4c26f0135e71e4deef7bfda5c;hb=HEAD;hp=c0a66c87c7f149b4799f4b558904b39db2dbe29f;hpb=07c332f0b8c32976dc3b0ad7f8433de7641e4778;p=src%2Fagl-compositor.git diff --git a/src/compositor.c b/src/compositor.c index c0a66c8..078157a 100644 --- a/src/compositor.c +++ b/src/compositor.c @@ -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 @@ -39,8 +39,8 @@ #include #include -#ifdef HAVE_BACKEND_HEADLESS -#include +#ifdef HAVE_BACKEND_RDP +#include #endif #ifdef HAVE_BACKEND_X11 #include @@ -54,12 +54,16 @@ #include "shared/os-compatibility.h" #include "shared/helpers.h" +#include "config.h" #include "agl-shell-server-protocol.h" #ifdef HAVE_REMOTING #include "remote.h" #endif +#define WINDOWED_DEFAULT_WIDTH 1024 +#define WINDOWED_DEFAULT_HEIGHT 768 + static int cached_tm_mday = -1; static struct weston_log_scope *log_scope; @@ -69,99 +73,102 @@ to_ivi_compositor(struct weston_compositor *ec) return weston_compositor_get_user_data(ec); } -static void -sigint_helper(int sig) +void +ivi_process_destroy(struct wet_process *process, int status, bool call_cleanup) { - raise(SIGUSR2); + wl_list_remove(&process->link); + if (call_cleanup && process->cleanup) + process->cleanup(process, status, process->cleanup_data); + free(process->path); + free(process); } -void -ivi_layout_save(struct ivi_compositor *ivi, struct ivi_output *output) +struct ivi_output_config * +ivi_init_parsed_options(struct weston_compositor *compositor) { - struct ivi_output *new_output; - ivi->need_ivi_output_relayout = true; + struct ivi_compositor *ivi = to_ivi_compositor(compositor); + struct ivi_output_config *config; - new_output = zalloc(sizeof(*new_output)); + config = zalloc(sizeof *config); + if (!config) + return NULL; - new_output->ivi = ivi; - new_output->background = output->background; + config->width = 0; + config->height = 0; + config->scale = 0; + config->transform = UINT32_MAX; - new_output->top = output->top; - new_output->bottom = output->bottom; - new_output->left = output->left; - new_output->right = output->right; + ivi->parsed_options = config; - 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); + return config; +} - new_output->area = output->area; - new_output->area_saved = output->area_saved; - new_output->area_activation = output->area_activation; +static void +screenshot_allow_all(struct wl_listener *l, struct weston_output_capture_attempt *att) +{ + att->authorized = true; +} - weston_log("saving output layout for output %s\n", new_output->name); - wl_list_insert(&ivi->saved_outputs, &new_output->link); +static void +sigint_helper(int sig) +{ + raise(SIGUSR2); } -void -ivi_layout_restore(struct ivi_compositor *ivi, struct ivi_output *n_output) +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) { - struct ivi_output *output = NULL; - struct ivi_output *iter_output; - - if (!ivi->need_ivi_output_relayout) - return; + size_t i; - 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; + 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 @@ -174,7 +181,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; } @@ -191,6 +199,9 @@ to_ivi_output(struct weston_output *o) struct ivi_output *output; listener = weston_output_get_destroy_listener(o, handle_output_destroy); + if (!listener) + return NULL; + output = wl_container_of(listener, output, output_destroy); return output; @@ -218,7 +229,8 @@ ivi_output_configure_app_id(struct ivi_output *ivi_output) static struct ivi_output * ivi_ensure_output(struct ivi_compositor *ivi, char *name, - struct weston_config_section *config) + struct weston_config_section *config, + struct weston_head *head) { struct ivi_output *output = NULL; wl_list_for_each(output, &ivi->outputs, link) { @@ -238,19 +250,45 @@ ivi_ensure_output(struct ivi_compositor *ivi, char *name, output->name = name; output->config = config; - output->output = weston_compositor_create_output(ivi->compositor, name); + output->output = + weston_compositor_create_output(ivi->compositor, head, head->name); if (!output->output) { free(output->name); free(output); return NULL; } + /* simple_output_configure might assume we have an ivi_output created + * by this point, which we do but we can only link it to a + * weston_output through the destroy listener, so install it earlier + * before actually running the callback handler */ output->output_destroy.notify = handle_output_destroy; weston_output_add_destroy_listener(output->output, &output->output_destroy); + if (ivi->simple_output_configure) { + int ret = ivi->simple_output_configure(output->output); + if (ret < 0) { + weston_log("Configuring output \"%s\" failed.\n", + weston_head_get_name(head)); + weston_output_destroy(output->output); + ivi->init_failed = true; + return NULL; + } + + if (weston_output_enable(output->output) < 0) { + weston_log("Enabling output \"%s\" failed.\n", + weston_head_get_name(head)); + weston_output_destroy(output->output); + ivi->init_failed = true; + return NULL; + } + } + + wl_list_insert(&ivi->outputs, &output->link); ivi_output_configure_app_id(output); + return output; } @@ -302,63 +340,14 @@ add_head_destroyed_listener(struct weston_head *head) } static int -drm_configure_output(struct ivi_output *output) -{ - struct ivi_compositor *ivi = output->ivi; - struct weston_config_section *section = output->config; - enum weston_drm_backend_output_mode mode = - WESTON_DRM_BACKEND_OUTPUT_PREFERRED; - char *modeline = NULL; - char *gbm_format = NULL; - char *seat = NULL; - - if (section) { - char *m; - weston_config_section_get_string(section, "mode", &m, "preferred"); - - /* This should have been handled earlier */ - assert(strcmp(m, "off") != 0); - - if (ivi->cmdline.use_current_mode || strcmp(m, "current") == 0) { - mode = WESTON_DRM_BACKEND_OUTPUT_CURRENT; - } else if (strcmp(m, "preferred") != 0) { - modeline = m; - m = NULL; - } - free(m); - - weston_config_section_get_string(section, "gbm-format", - &gbm_format, NULL); - - weston_config_section_get_string(section, "seat", &seat, ""); - } - - if (ivi->drm_api->set_mode(output->output, mode, modeline) < 0) { - weston_log("Cannot configure output using weston_drm_output_api.\n"); - free(modeline); - return -1; - } - free(modeline); - - ivi->drm_api->set_gbm_format(output->output, gbm_format); - free(gbm_format); - - ivi->drm_api->set_seat(output->output, seat); - free(seat); - - return 0; -} - -#define WINDOWED_DEFAULT_WIDTH 1024 -#define WINDOWED_DEFAULT_HEIGHT 768 - -static int -windowed_configure_output(struct ivi_output *output) +ivi_configure_windowed_output_from_config(struct ivi_output *output, + struct ivi_output_config *defaults) { struct ivi_compositor *ivi = output->ivi; struct weston_config_section *section = output->config; - int width = WINDOWED_DEFAULT_WIDTH; - int height = WINDOWED_DEFAULT_HEIGHT; + int width; + int height; + int scale; if (section) { char *mode; @@ -367,18 +356,26 @@ windowed_configure_output(struct ivi_output *output) if (!mode || sscanf(mode, "%dx%d", &width, &height) != 2) { weston_log("Invalid mode for output %s. Using defaults.\n", output->name); - width = WINDOWED_DEFAULT_WIDTH; - height = WINDOWED_DEFAULT_HEIGHT; + width = defaults->width; + height = defaults->height; } free(mode); + } else { + width = defaults->width; + height = defaults->height; } + scale = defaults->scale; + if (ivi->cmdline.width) width = ivi->cmdline.width; if (ivi->cmdline.height) height = ivi->cmdline.height; if (ivi->cmdline.scale) - weston_output_set_scale(output->output, ivi->cmdline.scale); + scale = ivi->cmdline.scale; + + weston_output_set_scale(output->output, scale); + weston_output_set_transform(output->output, defaults->transform); if (ivi->window_api->output_set_size(output->output, width, height) < 0) { weston_log("Cannot configure output '%s' using weston_windowed_output_api.\n", @@ -386,7 +383,9 @@ windowed_configure_output(struct ivi_output *output) return -1; } - weston_log("Configured windowed_output_api to %dx%d\n", width, height); + + weston_log("Configured windowed_output_api to %dx%d, scale %d\n", + width, height, scale); return 0; } @@ -433,19 +432,17 @@ parse_activation_area(const char *geometry, struct ivi_output *output) } static int -configure_output(struct ivi_output *output) +drm_configure_output(struct ivi_output *output) { struct ivi_compositor *ivi = output->ivi; struct weston_config_section *section = output->config; int32_t scale = 1; uint32_t transform = WL_OUTPUT_TRANSFORM_NORMAL; - - /* - * This can happen with the wayland backend with 'sprawl'. The config - * is hard-coded, so we don't need to do anything. - */ - if (!ivi->drm_api && !ivi->window_api) - return 0; + enum weston_drm_backend_output_mode mode = + WESTON_DRM_BACKEND_OUTPUT_PREFERRED; + char *modeline = NULL; + char *gbm_format = NULL; + char *seat = NULL; if (section) { char *t; @@ -465,10 +462,41 @@ configure_output(struct ivi_output *output) weston_output_set_scale(output->output, scale); weston_output_set_transform(output->output, transform); - if (ivi->drm_api) - return drm_configure_output(output); - else - return windowed_configure_output(output); + if (section) { + char *m; + weston_config_section_get_string(section, "mode", &m, "preferred"); + + /* This should have been handled earlier */ + assert(strcmp(m, "off") != 0); + + if (ivi->cmdline.use_current_mode || strcmp(m, "current") == 0) { + mode = WESTON_DRM_BACKEND_OUTPUT_CURRENT; + } else if (strcmp(m, "preferred") != 0) { + modeline = m; + m = NULL; + } + free(m); + + weston_config_section_get_string(section, "gbm-format", + &gbm_format, NULL); + + weston_config_section_get_string(section, "seat", &seat, ""); + } + + if (ivi->drm_api->set_mode(output->output, mode, modeline) < 0) { + weston_log("Cannot configure output using weston_drm_output_api.\n"); + free(modeline); + return -1; + } + free(modeline); + + ivi->drm_api->set_gbm_format(output->output, gbm_format); + free(gbm_format); + + ivi->drm_api->set_seat(output->output, seat); + free(seat); + + return 0; } /* @@ -483,7 +511,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], @@ -491,10 +519,42 @@ try_attach_heads(struct ivi_output *output) output->add[fail_len++] = tmp; } } - 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. @@ -506,6 +566,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; @@ -528,7 +590,7 @@ try_attach_enable_heads(struct ivi_output *output) fail_len = try_attach_heads(output); - if (configure_output(output) < 0) + if (drm_configure_output(output) < 0) return -1; fail_len = try_enable_output(output, fail_len); @@ -559,7 +621,7 @@ process_output(struct ivi_output *output) } static void -head_disable(struct ivi_compositor *ivi, struct weston_head *head) +drm_head_disable(struct ivi_compositor *ivi, struct weston_head *head) { struct weston_output *output; struct ivi_output *ivi_output; @@ -629,13 +691,14 @@ find_controlling_output_config(struct weston_config *config, } static void -head_prepare_enable(struct ivi_compositor *ivi, struct weston_head *head) +drm_head_prepare_enable(struct ivi_compositor *ivi, struct weston_head *head) { const char *name = weston_head_get_name(head); struct weston_config_section *section; struct ivi_output *output; char *output_name = NULL; + section = find_controlling_output_config(ivi->config, name); if (section) { char *mode; @@ -656,7 +719,7 @@ head_prepare_enable(struct ivi_compositor *ivi, struct weston_head *head) if (!output_name) return; - output = ivi_ensure_output(ivi, output_name, section); + output = ivi_ensure_output(ivi, output_name, section, head); if (!output) return; @@ -667,7 +730,7 @@ head_prepare_enable(struct ivi_compositor *ivi, struct weston_head *head) } static void -heads_changed(struct wl_listener *listener, void *arg) +drm_heads_changed(struct wl_listener *listener, void *arg) { struct weston_compositor *compositor = arg; struct weston_head *head = NULL; @@ -681,9 +744,9 @@ heads_changed(struct wl_listener *listener, void *arg) bool non_desktop = weston_head_is_non_desktop(head); if (connected && !enabled && !non_desktop) - head_prepare_enable(ivi, head); + drm_head_prepare_enable(ivi, head); else if (!connected && enabled) - head_disable(ivi, head); + drm_head_disable(ivi, head); else if (enabled && changed) weston_log("Detected a monitor change on head '%s', " "not bothering to do anything about it.\n", @@ -703,6 +766,90 @@ heads_changed(struct wl_listener *listener, void *arg) } } +static void +simple_head_enable(struct ivi_compositor *ivi, struct weston_head *head) +{ + struct ivi_output *output; + struct weston_config_section *section; + char *output_name = NULL; + const char *name = weston_head_get_name(head); + + section = find_controlling_output_config(ivi->config, name); + if (section) { + char *mode; + + weston_config_section_get_string(section, "mode", &mode, NULL); + if (mode && strcmp(mode, "off") == 0) { + free(mode); + return; + } + free(mode); + + weston_config_section_get_string(section, "name", + &output_name, NULL); + } else { + output_name = strdup(name); + } + + if (!output_name) + return; + + output = ivi_ensure_output(ivi, output_name, section, head); + if (!output) { + weston_log("Failed to create output %s\n", output_name); + return; + } + + add_head_destroyed_listener(head); +} + + +static void +simple_head_disable(struct weston_head *head) +{ + struct weston_output *output; + struct wl_listener *listener; + + listener = weston_head_get_destroy_listener(head, handle_head_destroy); + wl_list_empty(&listener->link); + + output = weston_head_get_output(head); + assert(output); + weston_output_destroy(output); +} + + +static void +simple_heads_changed(struct wl_listener *listener, void *arg) +{ + struct weston_compositor *compositor = arg; + struct ivi_compositor *ivi = to_ivi_compositor(compositor); + struct weston_head *head = NULL; + bool connected; + bool enabled; + bool changed; + bool non_desktop; + + while ((head = weston_compositor_iterate_heads(ivi->compositor, head))) { + connected = weston_head_is_connected(head); + enabled = weston_head_is_enabled(head); + changed = weston_head_is_device_changed(head); + non_desktop = weston_head_is_non_desktop(head); + + if (connected && !enabled && !non_desktop) { + simple_head_enable(ivi, head); + } else if (!connected && enabled) { + simple_head_disable(head); + } else if (enabled && changed) { + weston_log("Detected a monitor change on head '%s', " + "not bothering to do anything about it.\n", + weston_head_get_name(head)); + } + weston_head_reset_device_changed(head); + } +} + + #ifdef HAVE_REMOTING static int drm_backend_remoted_output_configure(struct weston_output *output, @@ -886,7 +1033,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; @@ -907,7 +1055,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 = { @@ -917,21 +1066,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); @@ -945,29 +1098,35 @@ 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 = drm_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)) { + weston_log("Failed to load DRM backend\n"); + 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; @@ -977,17 +1136,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; } @@ -1018,7 +1177,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; } @@ -1031,7 +1190,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; } @@ -1042,8 +1201,30 @@ windowed_create_outputs(struct ivi_compositor *ivi, int output_count, return 0; } + +static int +wayland_backend_output_configure(struct weston_output *output) +{ + struct ivi_output *ivi_output = to_ivi_output(output); + + struct ivi_output_config defaults = { + .width = WINDOWED_DEFAULT_WIDTH, + .height = WINDOWED_DEFAULT_HEIGHT, + .scale = 1, + .transform = WL_OUTPUT_TRANSFORM_NORMAL + }; + + if (!ivi_output) { + weston_log("Failed to configure and enable Wayland output. No ivi-output available!\n"); + return -1; + } + + return ivi_configure_windowed_output_from_config(to_ivi_output(output), &defaults); +} + 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 = { @@ -1054,14 +1235,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); @@ -1073,14 +1254,23 @@ 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->simple_output_configure = wayland_backend_output_configure; + ivi->heads_changed.notify = simple_heads_changed; + weston_compositor_add_heads_changed_listener(ivi->compositor, + &ivi->heads_changed); + + ivi->backend = weston_compositor_load_backend(ivi->compositor, + WESTON_BACKEND_WAYLAND, + &config.base); + if (!ivi->backend) { + weston_log("Failed to create Wayland backend!\n"); + } 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); @@ -1099,7 +1289,29 @@ 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[]) +x11_backend_output_configure(struct weston_output *output) +{ + struct ivi_output *ivi_output = to_ivi_output(output); + + struct ivi_output_config defaults = { + .width = WINDOWED_DEFAULT_WIDTH, + .height = WINDOWED_DEFAULT_HEIGHT, + .scale = 1, + .transform = WL_OUTPUT_TRANSFORM_NORMAL + }; + + if (!ivi_output) { + weston_log("Failed to configure and enable X11 output. No ivi-output available!\n"); + return -1; + } + + + return ivi_configure_windowed_output_from_config(ivi_output, &defaults); +} + +static int +load_x11_backend(struct ivi_compositor *ivi, int *argc, char *argv[], + enum weston_renderer_type renderer) { struct weston_x11_backend_config config = { .base = { @@ -1109,23 +1321,35 @@ 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); + ivi->simple_output_configure = x11_backend_output_configure; - if (ret < 0) - return ret; + ivi->heads_changed.notify = simple_heads_changed; + weston_compositor_add_heads_changed_listener(ivi->compositor, + &ivi->heads_changed); + + ivi->backend = weston_compositor_load_backend(ivi->compositor, + WESTON_BACKEND_X11, + &config.base); + if (!ivi->backend) { + weston_log("Failed to create X11 backend!\n"); + return -1; + } ivi->window_api = weston_windowed_output_get_api(ivi->compositor); if (!ivi->window_api) { @@ -1137,84 +1361,204 @@ 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[]) +load_x11_backend(struct ivi_compositor *ivi, int *argc, char **argv, + enum weston_renderer_type renderer) { return -1; } #endif -#ifdef HAVE_BACKEND_HEADLESS +#ifdef HAVE_BACKEND_RDP +static void +weston_rdp_backend_config_init(struct weston_rdp_backend_config *config) +{ + config->base.struct_version = WESTON_RDP_BACKEND_CONFIG_VERSION; + config->base.struct_size = sizeof(struct weston_rdp_backend_config); + + config->renderer = WESTON_RENDERER_AUTO; + config->bind_address = NULL; + config->port = 3389; + config->rdp_key = NULL; + config->server_cert = NULL; + config->server_key = NULL; + config->env_socket = 0; + config->external_listener_fd = -1; + config->no_clients_resize = 0; + config->force_no_compression = 0; + config->remotefx_codec = true; + config->refresh_rate = RDP_DEFAULT_FREQ; + +} + static int -load_headless_backend(struct ivi_compositor *ivi, int *argc, char **argv) +rdp_backend_output_configure(struct weston_output *output) { - struct weston_headless_backend_config config = {}; - int ret = 0; + struct ivi_compositor *ivi = to_ivi_compositor(output->compositor); + struct ivi_output_config *parsed_options = ivi->parsed_options; + const struct weston_rdp_output_api *api = + weston_rdp_output_get_api(output->compositor); + int width = 640; + int height = 480; + struct weston_config_section *section; + uint32_t transform = WL_OUTPUT_TRANSFORM_NORMAL; + char *transform_string; + struct weston_mode new_mode = {}; - bool use_pixman; - bool fullscreen; - bool use_gl; - int output_count; + assert(parsed_options); + + if (!api) { + weston_log("Cannot use weston_rdp_output_api.\n"); + return -1; + } - struct weston_compositor *c = ivi->compositor; + section = weston_config_get_section(ivi->config, "rdp", NULL, NULL); - const struct weston_option options[] = { - { WESTON_OPTION_BOOLEAN, "use-pixman", 0, &use_pixman }, - { WESTON_OPTION_BOOLEAN, "use-gl", 0, &use_gl }, - }; + if (parsed_options->width) + width = parsed_options->width; - windowed_parse_common_options(ivi, argc, argv, &use_pixman, - &fullscreen, &output_count); + if (parsed_options->height) + height = parsed_options->height; - parse_options(options, ARRAY_LENGTH(options), argc, argv); - config.use_pixman = use_pixman; - config.use_gl = use_gl; + weston_output_set_scale(output, 1); - config.base.struct_version = WESTON_HEADLESS_BACKEND_CONFIG_VERSION; - config.base.struct_size = sizeof(struct weston_headless_backend_config); + weston_config_section_get_int(section, "width", + &width, width); - /* load the actual headless-backend and configure it */ - ret = weston_compositor_load_backend(c, WESTON_BACKEND_HEADLESS, - &config.base); - if (ret < 0) - return ret; + weston_config_section_get_int(section, "height", + &height, height); - ivi->window_api = weston_windowed_output_get_api(c); - if (!ivi->window_api) { - weston_log("Cannot use weston_windowed_output_api.\n"); + if (parsed_options->transform) + transform = parsed_options->transform; + + weston_config_section_get_string(section, "transform", + &transform_string, "normal"); + + if (parse_transform(transform_string, &transform) < 0) { + weston_log("Invalid transform \"%s\" for output %s\n", + transform_string, output->name); return -1; } - if (ivi->window_api->create_head(c, "headless") < 0) { - weston_log("Cannot create headless back-end\n"); + + new_mode.width = width; + new_mode.height = height; + + weston_log("Setting modeline to %dx%d\n", width, height); + + api->output_set_mode(output, &new_mode); + weston_output_set_transform(output, transform); + + return 0; +} + +static int +load_rdp_backend(struct ivi_compositor *ivi, int *argc, char **argv, + enum weston_renderer_type renderer) +{ + struct weston_rdp_backend_config config = {}; + struct weston_config_section *section; + bool no_remotefx_codec = false; + + struct ivi_output_config *parsed_options = ivi_init_parsed_options(ivi->compositor); + if (!parsed_options) + return -1; + + weston_rdp_backend_config_init(&config); + + const struct weston_option rdp_options[] = { + { WESTON_OPTION_BOOLEAN, "env-socket", 0, &config.env_socket }, + { WESTON_OPTION_INTEGER, "external-listener-fd", 0, &config.external_listener_fd }, + { WESTON_OPTION_INTEGER, "width", 0, &parsed_options->width }, + { WESTON_OPTION_INTEGER, "height", 0, &parsed_options->height }, + { WESTON_OPTION_STRING, "address", 0, &config.bind_address }, + { WESTON_OPTION_INTEGER, "port", 0, &config.port }, + { WESTON_OPTION_BOOLEAN, "no-clients-resize", 0, &config.no_clients_resize }, + { WESTON_OPTION_STRING, "rdp4-key", 0, &config.rdp_key }, + { WESTON_OPTION_STRING, "rdp-tls-cert", 0, &config.server_cert }, + { WESTON_OPTION_STRING, "rdp-tls-key", 0, &config.server_key }, + { WESTON_OPTION_INTEGER, "scale", 0, &parsed_options->scale }, + { WESTON_OPTION_BOOLEAN, "force-no-compression", 0, &config.force_no_compression }, + { WESTON_OPTION_BOOLEAN, "no-remotefx-codec", 0, &no_remotefx_codec }, + }; + + config.remotefx_codec = !no_remotefx_codec; + config.renderer = renderer; + + section = weston_config_get_section(ivi->config, "rdp", NULL, NULL); + + weston_config_section_get_int(section, "refresh-rate", + &config.refresh_rate, RDP_DEFAULT_FREQ); + + weston_config_section_get_string(section, "tls-cert", + &config.server_cert, config.server_cert); + + weston_config_section_get_string(section, "tls-key", + &config.server_key, config.server_key); + + + parse_options(rdp_options, ARRAY_LENGTH(rdp_options), argc, argv); + weston_log("No clients resize: %d\n", config.no_clients_resize); + + ivi->simple_output_configure = rdp_backend_output_configure; + + ivi->heads_changed.notify = simple_heads_changed; + weston_compositor_add_heads_changed_listener(ivi->compositor, + &ivi->heads_changed); + + if (!weston_compositor_load_backend(ivi->compositor, + WESTON_BACKEND_RDP, &config.base)) { + weston_log("Failed to create RDP backend\n"); return -1; } + free(config.bind_address); + free(config.rdp_key); + free(config.server_cert); + free(config.server_key); + return 0; } #else static int -load_headless_backend(struct ivi_compositor *ivi, int *argc, char **argv) +load_rdp_backend(struct ivi_compositor *ivi, int *argc, char **argv, + enum weston_renderer_type renderer) { return -1; } #endif + static int -load_backend(struct ivi_compositor *ivi, const char *backend, - int *argc, char *argv[]) +load_backend(struct ivi_compositor *ivi, int *argc, char **argv, + const char *backend_name, const char *renderer_name) { - 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); + 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; } - weston_log("fatal: unknown backend '%s'.\n", backend); - 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, renderer); + 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()"); + } + + return 0; } static int @@ -1234,27 +1578,18 @@ load_modules(struct ivi_compositor *ivi, const char *modules, 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; - } - - if (strstr(buffer, "systemd-notify.so")) { + *xwayland = true; + } else if (strstr(buffer, "systemd-notify.so")) { weston_log("systemd-notify plug-in already loaded!\n"); - p = end; - while (*p == ',') - p++; - continue; - } + } else { + module_init = weston_load_module(buffer, "wet_module_init", WESTON_MODULEDIR); + if (!module_init) + return -1; - module_init = weston_load_module(buffer, "wet_module_init"); - if (!module_init) - return -1; + if (module_init(ivi->compositor, *argc, argv) < 0) + return -1; - if (module_init(ivi->compositor, *argc, argv) < 0) - return -1; + } p = end; while (*p == ',') @@ -1510,7 +1845,7 @@ log_timestamp(char *buf, size_t len) strftime(timestr, sizeof(timestr), "%H:%M:%S", brokendown_time); /* if datestr is empty it prints only timestr*/ - snprintf(buf, len, "%s[%s.%03li]", datestr, + snprintf(buf, len, "%s[%s.%03"PRIi64"]", datestr, timestr, (tv.tv_usec / 1000)); return buf; @@ -1619,6 +1954,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" @@ -1649,6 +1985,16 @@ copy_command_line(int argc, char * const argv[]) return str; } +#if !defined(BUILD_XWAYLAND) +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 NULL; +} +#endif + static void weston_log_setup_scopes(struct weston_log_context *log_ctx, struct weston_log_subscriber *subscriber, @@ -1677,7 +2023,6 @@ weston_log_subscribe_to_scopes(struct weston_log_context *log_ctx, weston_log_subscribe(log_ctx, logger, "log"); } - WL_EXPORT int wet_main(int argc, char *argv[], const struct weston_testsuite_data *test_data) { @@ -1705,8 +2050,11 @@ 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; + struct wet_process *process, *process_tmp; 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 }, @@ -1730,6 +2078,7 @@ int wet_main(int argc, char *argv[], const struct weston_testsuite_data *test_da wl_list_init(&ivi.remote_pending_apps); wl_list_init(&ivi.desktop_clients); wl_list_init(&ivi.child_process_list); + wl_list_init(&ivi.pending_apps); /* Prevent any clients we spawn getting our stdin */ os_fd_set_cloexec(STDIN_FILENO); @@ -1818,14 +2167,15 @@ 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; @@ -1840,18 +2190,29 @@ int wet_main(int argc, char *argv[], const struct weston_testsuite_data *test_da if (load_modules(&ivi, option_modules, &argc, argv, &xwayland) < 0) goto error_compositor; - if (ivi_policy_init(&ivi) < 0) - goto error_compositor; + if (!xwayland) { + weston_config_section_get_bool(section, "xwayland", &xwayland, + false); + } if (ivi_shell_init(&ivi) < 0) goto error_compositor; + if (xwayland) { + if (!wet_load_xwayland(ivi.compositor)) + goto error_compositor; + } + + if (ivi_policy_init(&ivi) < 0) + goto error_compositor; + + if (list_debug_scopes) { struct weston_log_scope *nscope = NULL; weston_log("Printing available debug scopes:\n"); - while ((nscope = weston_log_scopes_iterate(ivi.compositor, nscope))) { + while ((nscope = weston_log_scopes_iterate(log_ctx, nscope))) { weston_log("\tscope name: %s, desc: %s", weston_log_scope_get_name(nscope), weston_log_scope_get_description(nscope)); @@ -1864,8 +2225,6 @@ int wet_main(int argc, char *argv[], const struct weston_testsuite_data *test_da add_bindings(ivi.compositor); - weston_compositor_flush_heads_changed(ivi.compositor); - if (ivi.remoting_api) ivi_enable_remote_outputs(&ivi); @@ -1885,8 +2244,11 @@ int wet_main(int argc, char *argv[], const struct weston_testsuite_data *test_da ivi_launch_shell_client(&ivi, "shell-client-ext", &ivi.shell_client_ext.client); - if (debug) - ivi_screenshooter_create(&ivi); + if (debug) { + weston_compositor_add_screenshot_authority(ivi.compositor, + &ivi.screenshot_auth, + screenshot_allow_all); + } ivi_agl_systemd_notify(&ivi); wl_display_run(display); @@ -1911,6 +2273,9 @@ error_compositor: ivi_policy_destroy(ivi.policy); + wl_list_for_each_safe(process, process_tmp, &ivi.child_process_list, link) + ivi_process_destroy(process, 0, false); + error_signals: for (size_t i = 0; i < ARRAY_LENGTH(signals); ++i) if (signals[i])