From 3607e3567d44754e1c4dd795291e5c1463ac012d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20GOULPI=C3=89?= Date: Sun, 8 Feb 2026 16:40:46 +0100 Subject: [PATCH] pipewire: Add transparent background support for overlay composition MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch enables transparent background rendering in the PipeWire backend, allowing Weston compositor output to be used as a transparent overlay layer in external composition pipelines. Use case: In embedded systems (drones, medical devices, industrial HMI), it is common to overlay UI elements (telemetry, alerts, controls) on top of live video feeds. This patch enables any Wayland-native UI toolkit (Qt, GTK, LVGL) to render as a transparent OSD that can be composited with video streams using GStreamer or similar frameworks, while maintaining full GPU acceleration and zero-copy transfers via DMA-BUF. Implementation: - frontend/main.c: Force ARGB8888 pixel format when transparent-background option is enabled, ensuring alpha channel preservation - kiosk-shell: Parse alpha component from background-color and skip curtain creation when fully transparent (alpha=0) - backend-pipewire: Add DRM_FORMAT_ARGB8888 to SPA_VIDEO_FORMAT_BGRA mapping to properly expose alpha channel to PipeWire consumers Configuration example (weston.ini): [shell] background-color=0x00000000 [output] name=pipewire transparent-background=true Usage example: # Run UI application through Weston PipeWire backend weston --backend=pipewire --shell=kiosk-shell.so -- ui-osd-qt6 # Compose with video stream in GStreamer gst-launch-1.0 compositor name=comp ! videoconvert ! waylandsink \ v4l2src device=/dev/video0 ! comp.sink_0 \ pipewiresrc path=55 ! video/x-raw,format=BGRA ! comp.sink_1 Benefits: - Process isolation: UI crashes don't affect video pipeline - Toolkit flexibility: Use any Wayland-compatible UI framework - GPU acceleration: Full hardware compositing and encoding support - Zero-copy: DMA-BUF sharing throughout the pipeline - Routing flexibility: PipeWire allows dynamic stream routing The patch is minimal, backward-compatible (opt-in via configuration), and follows existing Weston patterns for output configuration. Tested on: Debian 13, Qt 6.8.2, GStreamer 1.28.0 Signed-off-by: Paul GOULPIÉ --- frontend/main.c | 8 ++++++++ kiosk-shell/kiosk-shell.c | 7 ++++++- libweston/backend-pipewire/pipewire.c | 2 ++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/frontend/main.c b/frontend/main.c index 43915f8af..3f48750ae 100644 --- a/frontend/main.c +++ b/frontend/main.c @@ -4402,6 +4402,7 @@ pipewire_backend_output_configure(struct weston_output *output) struct weston_config *wc = wet_get_config(output->compositor); struct weston_config_section *section; char *gbm_format = NULL; + bool transparent_background = false; int width; int height; int framerate = -1; @@ -4419,6 +4420,13 @@ pipewire_backend_output_configure(struct weston_output *output) parsed_options); weston_config_section_get_string(section, "gbm-format", &gbm_format, NULL); + weston_config_section_get_bool(section, "transparent-background", + &transparent_background, false); + + if (transparent_background) { + free(gbm_format); + gbm_format = strdup("argb8888"); + } wet_output_set_scale(output, section, 1, 0); weston_output_set_transform(output, WL_OUTPUT_TRANSFORM_NORMAL); diff --git a/kiosk-shell/kiosk-shell.c b/kiosk-shell/kiosk-shell.c index 58525874d..1a917f65d 100644 --- a/kiosk-shell/kiosk-shell.c +++ b/kiosk-shell/kiosk-shell.c @@ -704,7 +704,12 @@ kiosk_shell_output_recreate_background(struct kiosk_shell_output *shoutput) curtain_params.r = ((bg_color >> 16) & 0xff) / 255.0; curtain_params.g = ((bg_color >> 8) & 0xff) / 255.0; curtain_params.b = ((bg_color >> 0) & 0xff) / 255.0; - curtain_params.a = 1.0; + curtain_params.a = ((bg_color >> 24) & 0xff) / 255.0; + + if (curtain_params.a == 0.0) { + shoutput->curtain = NULL; + return; + } curtain_params.pos = output->pos; curtain_params.width = output->width; diff --git a/libweston/backend-pipewire/pipewire.c b/libweston/backend-pipewire/pipewire.c index 9921f958b..6c9f0d22a 100644 --- a/libweston/backend-pipewire/pipewire.c +++ b/libweston/backend-pipewire/pipewire.c @@ -200,6 +200,8 @@ spa_video_format_from_drm_fourcc(uint32_t fourcc) switch (fourcc) { case DRM_FORMAT_XRGB8888: return SPA_VIDEO_FORMAT_BGRx; + case DRM_FORMAT_ARGB8888: + return SPA_VIDEO_FORMAT_BGRA; case DRM_FORMAT_RGB565: return SPA_VIDEO_FORMAT_RGB16; default: