backend-headless: Use renderer enum type for config selection

When we're selecting our renderer, use the enum rather than two
mutually-exclusive booleans to not use the no-op renderer.

Signed-off-by: Daniel Stone <daniels@collabora.com>
This commit is contained in:
Daniel Stone 2022-12-29 18:20:26 +00:00 committed by Marius Vlad
parent c683ebdea3
commit b846c26d97
3 changed files with 40 additions and 22 deletions

View file

@ -2981,6 +2981,8 @@ load_headless_backend(struct weston_compositor *c,
const struct weston_windowed_output_api *api;
struct weston_headless_backend_config config = {{ 0, }};
struct weston_config_section *section;
bool force_pixman;
bool force_gl;
bool no_outputs = false;
int ret = 0;
char *transform = NULL;
@ -2990,9 +2992,9 @@ load_headless_backend(struct weston_compositor *c,
return -1;
section = weston_config_get_section(wc, "core", NULL, NULL);
weston_config_section_get_bool(section, "use-pixman", &config.use_pixman,
weston_config_section_get_bool(section, "use-pixman", &force_pixman,
false);
weston_config_section_get_bool(section, "use-gl", &config.use_gl,
weston_config_section_get_bool(section, "use-gl", &force_gl,
false);
weston_config_section_get_bool(section, "output-decorations", &config.decorate,
false);
@ -3001,14 +3003,25 @@ load_headless_backend(struct weston_compositor *c,
{ WESTON_OPTION_INTEGER, "width", 0, &parsed_options->width },
{ WESTON_OPTION_INTEGER, "height", 0, &parsed_options->height },
{ WESTON_OPTION_INTEGER, "scale", 0, &parsed_options->scale },
{ WESTON_OPTION_BOOLEAN, "use-pixman", 0, &config.use_pixman },
{ WESTON_OPTION_BOOLEAN, "use-gl", 0, &config.use_gl },
{ WESTON_OPTION_BOOLEAN, "use-pixman", 0, &force_pixman },
{ WESTON_OPTION_BOOLEAN, "use-gl", 0, &force_gl },
{ WESTON_OPTION_STRING, "transform", 0, &transform },
{ WESTON_OPTION_BOOLEAN, "no-outputs", 0, &no_outputs },
};
parse_options(options, ARRAY_LENGTH(options), argc, argv);
if (force_pixman && force_gl) {
weston_log("Conflicting renderer specifications\n");
return -1;
} else if (force_pixman) {
config.renderer = WESTON_RENDERER_PIXMAN;
} else if (force_gl) {
config.renderer = WESTON_RENDERER_GL;
} else {
config.renderer = WESTON_RENDERER_AUTO;
}
if (transform) {
if (weston_parse_transform(transform, &parsed_options->transform) < 0) {
weston_log("Invalid transform \"%s\"\n", transform);

View file

@ -34,16 +34,13 @@ extern "C" {
#include <libweston/libweston.h>
#define WESTON_HEADLESS_BACKEND_CONFIG_VERSION 2
#define WESTON_HEADLESS_BACKEND_CONFIG_VERSION 3
struct weston_headless_backend_config {
struct weston_backend_config base;
/** Whether to use the pixman renderer, default is no-op */
bool use_pixman;
/** Whether to use the GL renderer, conflicts with use_pixman */
bool use_gl;
/** Select the renderer to use */
enum weston_renderer_type renderer;
/** Use output decorations, requires use_gl = true */
bool decorate;

View file

@ -543,15 +543,6 @@ headless_backend_create(struct weston_compositor *compositor,
b->base.destroy = headless_destroy;
b->base.create_output = headless_output_create;
if (config->use_pixman && config->use_gl) {
weston_log("Error: cannot use both Pixman *and* GL renderers.\n");
goto err_free;
}
if (config->decorate && !config->use_gl) {
weston_log("Error: headless-backend decorations require GL renderer.\n");
goto err_free;
}
b->decorate = config->decorate;
if (b->decorate) {
b->theme = theme_create();
@ -561,12 +552,29 @@ headless_backend_create(struct weston_compositor *compositor,
}
}
if (config->use_gl)
switch (config->renderer) {
case WESTON_RENDERER_GL:
ret = headless_gl_renderer_init(b);
else if (config->use_pixman)
break;
case WESTON_RENDERER_PIXMAN:
if (config->decorate) {
weston_log("Error: Pixman renderer does not support decorations.\n");
goto err_input;
}
ret = pixman_renderer_init(compositor);
else
break;
case WESTON_RENDERER_AUTO:
case WESTON_RENDERER_NOOP:
if (config->decorate) {
weston_log("Error: no-op renderer does not support decorations.\n");
goto err_input;
}
ret = noop_renderer_init(compositor);
break;
default:
weston_log("Error: unsupported renderer\n");
break;
}
if (ret < 0)
goto err_input;