From 7b2eddf022e42dd15b6b07a805657ee0c8d26648 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Molinari?= Date: Tue, 20 Feb 2024 16:47:54 +0100 Subject: [PATCH] backend-headless: Add support to repaint only on captures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Damages and captures both trigger repaints of outputs. Some configurations don't care about damages and use headless only for captures. This commit adds a new feature to libweston that lets outputs repaint only on captures, not on damages. The headless backend enables that new feature when given a special refresh rate of 0 mHz. Signed-off-by: Loïc Molinari --- include/libweston/backend-headless.h | 4 +++- include/libweston/libweston.h | 3 +++ libweston/backend-headless/headless.c | 13 ++++++++++--- libweston/compositor.c | 5 +++++ 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/include/libweston/backend-headless.h b/include/libweston/backend-headless.h index 5d4f03eb..ed26d88a 100644 --- a/include/libweston/backend-headless.h +++ b/include/libweston/backend-headless.h @@ -45,7 +45,9 @@ struct weston_headless_backend_config { /** Use output decorations, requires use_gl = true */ bool decorate; - /** Output repaint refresh rate (in mHz). */ + /** Output repaint refresh rate (in mHz). Supported values range from 0 + * mHz to 1,000,000 mHz. 0 is a special value that triggers repaints + * only on capture requests, not on damages. */ int refresh; }; diff --git a/include/libweston/libweston.h b/include/libweston/libweston.h index 667b79ea..423d8a65 100644 --- a/include/libweston/libweston.h +++ b/include/libweston/libweston.h @@ -507,6 +507,9 @@ struct weston_output { /** Used only between repaint_begin and repaint_cancel. */ bool repainted; + /** Repaints are triggered only on capture requests, not on damages. */ + bool repaint_only_on_capture; + /** State of the repaint loop */ enum { REPAINT_NOT_SCHEDULED = 0, /**< idle; no repaint will occur */ diff --git a/libweston/backend-headless/headless.c b/libweston/backend-headless/headless.c index 2d74eea0..107ef3f5 100644 --- a/libweston/backend-headless/headless.c +++ b/libweston/backend-headless/headless.c @@ -68,6 +68,7 @@ struct headless_backend { unsigned int formats_count; int refresh; + bool repaint_only_on_capture; }; struct headless_head { @@ -458,6 +459,7 @@ headless_output_create(struct weston_backend *backend, const char *name) output->base.disable = headless_output_disable; output->base.enable = headless_output_enable; output->base.attach_head = NULL; + output->base.repaint_only_on_capture = b->repaint_only_on_capture; output->backend = b; @@ -573,11 +575,16 @@ headless_backend_create(struct weston_compositor *compositor, b->formats = pixel_format_get_array(headless_formats, b->formats_count); /* Wayland event source's timeout has a granularity of the order of - * milliseconds so the highest supported rate is 1 kHz. */ - if (config->refresh > 0) + * milliseconds so the highest supported rate is 1 kHz. 0 is a special + * value that enables repaints only on capture. */ + if (config->refresh > 0) { b->refresh = MIN(config->refresh, 1000000); - else + } else if (config->refresh == 0) { + b->refresh = 1000000; + b->repaint_only_on_capture = true; + } else { b->refresh = DEFAULT_OUTPUT_REPAINT_REFRESH; + } if (!compositor->renderer) { switch (config->renderer) { diff --git a/libweston/compositor.c b/libweston/compositor.c index 8d8aa778..af3c79cb 100644 --- a/libweston/compositor.c +++ b/libweston/compositor.c @@ -3673,6 +3673,10 @@ weston_output_maybe_repaint(struct weston_output *output, struct timespec *now) if (output->power_state == WESTON_OUTPUT_POWER_FORCED_OFF) goto err; + if (output->repaint_only_on_capture && + !weston_output_has_renderer_capture_tasks(output)) + goto err; + /* If repaint fails, we aren't going to get weston_output_finish_frame * to trigger a new repaint, so drop it from repaint and hope * something schedules a successful repaint later. As repainting may @@ -7799,6 +7803,7 @@ weston_output_init(struct weston_output *output, output->desired_protection = WESTON_HDCP_DISABLE; output->allow_protection = true; output->power_state = WESTON_OUTPUT_POWER_NORMAL; + output->repaint_only_on_capture = false; wl_list_init(&output->head_list);