From bf00fef07dbbc3577fe85add2a104a2f997a35db Mon Sep 17 00:00:00 2001 From: Leandro Ribeiro Date: Wed, 20 May 2026 14:40:27 -0300 Subject: [PATCH] frontend: add output-straight-alpha config option This introduces a new .ini config option: output-straight-alpha. It's currently only supported by the headless backend, and it forces renderers to produce straight alpha framebuffers for headless backend outputs. For now, only the GL renderer supports creating straight alpha framebuffers (the support was introduced in "backend-drm: add support for KMS devices with only coverage blend mode"). This is useful mostly for testing, and the main motivation to add such support in our DRM-backend and GL-renderer was to be able to support KMS devices that only supports straight alpha framebuffers. Signed-off-by: Leandro Ribeiro --- frontend/main.c | 6 ++++++ include/libweston/backend-headless.h | 5 +++++ libweston/backend-headless/headless.c | 4 ++++ man/weston.ini.man | 5 +++++ 4 files changed, 20 insertions(+) diff --git a/frontend/main.c b/frontend/main.c index 32f44e1ab..b1fdc4daa 100644 --- a/frontend/main.c +++ b/frontend/main.c @@ -4217,6 +4217,7 @@ load_headless_backend(struct weston_compositor *c, bool force_gl; bool force_vulkan; bool no_outputs = false; + bool output_straight_alpha; char *transform = NULL; struct wet_output_config *parsed_options = wet_init_parsed_options(c); @@ -4232,6 +4233,8 @@ load_headless_backend(struct weston_compositor *c, false); weston_config_section_get_bool(section, "output-decorations", &config.decorate, false); + weston_config_section_get_bool(section, "output-straight-alpha", &output_straight_alpha, + false); const struct weston_option options[] = { { WESTON_OPTION_INTEGER, "width", 0, &parsed_options->width }, @@ -4265,6 +4268,9 @@ load_headless_backend(struct weston_compositor *c, config.renderer = renderer; } + config.output_fb_alpha_encoding = output_straight_alpha ? + WESTON_OUTPUT_FB_ALPHA_STRAIGHT : WESTON_OUTPUT_FB_ALPHA_PREMULT; + if (transform) { if (weston_parse_transform(transform, &parsed_options->transform) < 0) { weston_log("Invalid transform \"%s\"\n", transform); diff --git a/include/libweston/backend-headless.h b/include/libweston/backend-headless.h index ce5ec9f3f..648d9001e 100644 --- a/include/libweston/backend-headless.h +++ b/include/libweston/backend-headless.h @@ -54,6 +54,11 @@ struct weston_headless_backend_config { * The default is not to create a wl_seat. */ bool fake_seat; + + /** Defines if renderers must produce straight or premultiplied alpha + * framebuffers for headless-backend outputs. + */ + enum weston_output_fb_alpha_encoding output_fb_alpha_encoding; }; #ifdef __cplusplus diff --git a/libweston/backend-headless/headless.c b/libweston/backend-headless/headless.c index d454381ae..a666fb920 100644 --- a/libweston/backend-headless/headless.c +++ b/libweston/backend-headless/headless.c @@ -70,6 +70,7 @@ struct headless_backend { int refresh; bool repaint_only_on_capture; + enum weston_output_fb_alpha_encoding output_fb_alpha_encoding; bool use_fake_seat; }; @@ -547,6 +548,7 @@ headless_output_create(struct weston_backend *backend, const char *name) output->base.enable = headless_output_enable; output->base.attach_head = NULL; output->base.repaint_only_on_capture = b->repaint_only_on_capture; + output->base.fb_alpha_encoding = b->output_fb_alpha_encoding; output->backend = b; @@ -680,6 +682,7 @@ headless_backend_create(struct weston_compositor *compositor, b->base.create_output = headless_output_create; b->decorate = config->decorate; + b->output_fb_alpha_encoding = config->output_fb_alpha_encoding; if (b->decorate) { b->theme = theme_create(); if (!b->theme) { @@ -786,6 +789,7 @@ config_init_to_defaults(struct weston_headless_backend_config *config) { config->refresh = DEFAULT_OUTPUT_REPAINT_REFRESH; config->fake_seat = false; + config->output_fb_alpha_encoding = WESTON_OUTPUT_FB_ALPHA_PREMULT; } WL_EXPORT int diff --git a/man/weston.ini.man b/man/weston.ini.man index 43b2657c2..f3b2bec39 100644 --- a/man/weston.ini.man +++ b/man/weston.ini.man @@ -237,6 +237,11 @@ Boolean, defaults to These decorations cannot normally be screenshot. This option is useful for the Weston test suite only. .TP 7 +.BI "output-straight-alpha=" true +Require straight alpha framebuffers from renderers for outputs. Only supported +by the headless backend. Boolean, defaults to +.BR false . +.TP 7 .BI "placeholder-color=" 0xRRGGBB sets the color of the placeholder (unsigned integer). The hexadecimal digit pairs are in order red, green, and blue. This placeholder is used for