From c7cf87fe85c386488c12150ab6c817b7ff6f7e3c Mon Sep 17 00:00:00 2001 From: Derek Foreman Date: Mon, 3 Feb 2025 12:29:01 -0600 Subject: [PATCH] frontend: Enable VRR from the config file Allow weston.ini to enable game VRR. Signed-off-by: Derek Foreman --- frontend/main.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++ man/weston.ini.man | 13 ++++++++++++ 2 files changed, 66 insertions(+) diff --git a/frontend/main.c b/frontend/main.c index c27c011d9..c35a16077 100644 --- a/frontend/main.c +++ b/frontend/main.c @@ -1361,6 +1361,56 @@ wet_output_set_transform(struct weston_output *output, return 0; } +static int +wet_output_set_vrr_mode(struct weston_output *output, + struct weston_config_section *section) +{ + static const struct { + const char *name; + enum weston_vrr_mode vrr_mode; + } vrr_modes[] = { + { "none", WESTON_VRR_MODE_NONE }, + { "game", WESTON_VRR_MODE_GAME }, + }; + enum weston_vrr_mode vrr_mode = WESTON_VRR_MODE_NONE; + char *vrr_str = NULL; + unsigned int i; + + weston_config_section_get_string(section, "vrr-mode", &vrr_str, NULL); + if (!vrr_str) + return vrr_mode; + + for (i = 0; i < ARRAY_LENGTH(vrr_modes); i++) + if (strcmp(vrr_str, vrr_modes[i].name) == 0) + break; + + if (i == ARRAY_LENGTH(vrr_modes)) { + weston_log("Error in config for output '%s': '%s' is not a valid vrr mode. Try one of:", + output->name, vrr_str); + for (i = 0; i < ARRAY_LENGTH(vrr_modes); i++) + weston_log_continue(" %s", vrr_modes[i].name); + weston_log_continue("\n"); + free(vrr_str); + return -1; + } + + vrr_mode = vrr_modes[i].vrr_mode; + + if (vrr_mode && (weston_output_get_supported_vrr_modes(output) & vrr_mode) == 0) { + weston_log("Error: output '%s' does not support output format %s.\n", + output->name, vrr_str); + free(vrr_str); + return -1; + } + + free(vrr_str); + + if (weston_output_set_vrr_mode(output, vrr_mode) < 0) + return -1; + + return 0; +} + static int wet_output_set_color_profile(struct weston_output *output, struct weston_config_section *section, @@ -2423,6 +2473,9 @@ drm_backend_output_configure(struct weston_output *output, wet->config, section) < 0) return -1; + if (wet_output_set_vrr_mode(output, section) < 0) + return -1; + return 0; } diff --git a/man/weston.ini.man b/man/weston.ini.man index a8b501ec3..f079a9a14 100644 --- a/man/weston.ini.man +++ b/man/weston.ini.man @@ -669,6 +669,19 @@ only for remote outputs. NOTE: The native outputs created by the DRM backend using the 'clone-of' are for cloning the outputs, and not sharing or mirroring. See also .BR weston-drm(7). +.TP 7 +.BI "vrr-mode=" mode +Sets the variable refresh rate mode of the display. +The mode can be one of the following strings: +.PP +.RS 10 +.nf +.BR "none " "variable refresh rate is disabled" +.BR "game " "game variable refresh rate" +.fi +.RE +.IP +Defaults to "none". .\"--------------------------------------------------------------------- .SH "INPUT-METHOD SECTION" .TP 7