From 1721dad5ec0578e79114c80f59892ae987e4d70e Mon Sep 17 00:00:00 2001 From: Dor Askayo Date: Tue, 17 Mar 2020 20:57:41 +0200 Subject: [PATCH] monitor: Include the refresh rate mode in the mode spec Variable refresh rate modes are preferred over their fixed refresh rate counterparts. Part-of: --- src/backends/meta-monitor.c | 49 +++++++++++++++++++++++++++++++++---- src/backends/meta-monitor.h | 4 +++ 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/src/backends/meta-monitor.c b/src/backends/meta-monitor.c index 1cfed5d9c..6b275705b 100644 --- a/src/backends/meta-monitor.c +++ b/src/backends/meta-monitor.c @@ -622,16 +622,21 @@ generate_mode_id (MetaMonitorModeSpec *monitor_mode_spec) { gboolean is_interlaced; char rate_str[G_ASCII_DTOSTR_BUF_SIZE]; + gboolean is_vrr; is_interlaced = !!(monitor_mode_spec->flags & META_CRTC_MODE_FLAG_INTERLACE); g_ascii_formatd (rate_str, sizeof (rate_str), "%.3f", monitor_mode_spec->refresh_rate); - return g_strdup_printf ("%dx%d%s@%s", + is_vrr = monitor_mode_spec->refresh_rate_mode == + META_CRTC_REFRESH_RATE_MODE_VARIABLE; + + return g_strdup_printf ("%dx%d%s@%s%s", monitor_mode_spec->width, monitor_mode_spec->height, is_interlaced ? "i" : "", - rate_str); + rate_str, + is_vrr ? "+vrr" : ""); } static gboolean @@ -678,6 +683,7 @@ meta_monitor_create_spec (MetaMonitor *monitor, .width = width, .height = height, .refresh_rate = crtc_mode_info->refresh_rate, + .refresh_rate_mode = crtc_mode_info->refresh_rate_mode, .flags = crtc_mode_info->flags & HANDLED_CRTC_MODE_FLAGS }; } @@ -1141,6 +1147,9 @@ find_tiled_crtc_mode (MetaOutput *output, if (crtc_mode_info->refresh_rate != reference_crtc_mode_info->refresh_rate) continue; + if (crtc_mode_info->refresh_rate_mode != reference_crtc_mode_info->refresh_rate_mode) + continue; + if (crtc_mode_info->flags != reference_crtc_mode_info->flags) continue; @@ -1255,9 +1264,24 @@ generate_tiled_monitor_modes (MetaMonitorTiled *monitor_tiled) if (!monitor_priv->preferred_mode) { - if (!best_mode || - mode->spec.refresh_rate > best_mode->spec.refresh_rate) - best_mode = mode; + if (!best_mode) + { + best_mode = mode; + continue; + } + + if (mode->spec.refresh_rate > best_mode->spec.refresh_rate) + { + best_mode = mode; + continue; + } + + if (mode->spec.refresh_rate == best_mode->spec.refresh_rate && + mode->spec.refresh_rate_mode > best_mode->spec.refresh_rate_mode) + { + best_mode = mode; + continue; + } } } @@ -1443,6 +1467,13 @@ find_best_mode (MetaMonitor *monitor) best_mode = mode; continue; } + + if (mode->spec.refresh_rate == best_mode->spec.refresh_rate && + mode->spec.refresh_rate_mode > best_mode->spec.refresh_rate_mode) + { + best_mode = mode; + continue; + } } return best_mode; @@ -1711,6 +1742,8 @@ meta_monitor_mode_spec_equals (MetaMonitorModeSpec *monitor_mode_spec, monitor_mode_spec->height == other_monitor_mode_spec->height && ABS (monitor_mode_spec->refresh_rate - other_monitor_mode_spec->refresh_rate) < MAXIMUM_REFRESH_RATE_DIFF && + monitor_mode_spec->refresh_rate_mode == + other_monitor_mode_spec->refresh_rate_mode && monitor_mode_spec->flags == other_monitor_mode_spec->flags); } @@ -2119,6 +2152,12 @@ meta_monitor_mode_get_refresh_rate (MetaMonitorMode *monitor_mode) return monitor_mode->spec.refresh_rate; } +MetaCrtcRefreshRateMode +meta_monitor_mode_get_refresh_rate_mode (MetaMonitorMode *monitor_mode) +{ + return monitor_mode->spec.refresh_rate_mode; +} + MetaCrtcModeFlag meta_monitor_mode_get_flags (MetaMonitorMode *monitor_mode) { diff --git a/src/backends/meta-monitor.h b/src/backends/meta-monitor.h index 57275983a..f4acf268a 100644 --- a/src/backends/meta-monitor.h +++ b/src/backends/meta-monitor.h @@ -38,6 +38,7 @@ typedef struct _MetaMonitorModeSpec int width; int height; float refresh_rate; + MetaCrtcRefreshRateMode refresh_rate_mode; MetaCrtcModeFlag flags; } MetaMonitorModeSpec; @@ -252,6 +253,9 @@ void meta_monitor_mode_get_resolution (MetaMonitorMode *monitor_mode, META_EXPORT_TEST float meta_monitor_mode_get_refresh_rate (MetaMonitorMode *monitor_mode); +META_EXPORT_TEST +MetaCrtcRefreshRateMode meta_monitor_mode_get_refresh_rate_mode (MetaMonitorMode *monitor_mode); + META_EXPORT_TEST MetaCrtcModeFlag meta_monitor_mode_get_flags (MetaMonitorMode *monitor_mode);