output/kms: Filter out duplicate fallback modes

Right now we often add a duplicate fallback mode that's almost
identical to the native mode. This adds unnecessary clutter to
UIs, thus filter out such modes.

In order to keep the code small, use `MetaCrtcModeInfo` directly
instead of recalculating the values. And to keep consistency, do
the same in the loop above.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2189>
This commit is contained in:
Robert Mader 2021-12-30 07:18:40 +01:00 committed by Marge Bot
parent 60d7cd82ba
commit fb9564b87b

View File

@ -132,7 +132,6 @@ add_common_modes (MetaOutputInfo *output_info,
{ {
MetaCrtcMode *crtc_mode; MetaCrtcMode *crtc_mode;
GPtrArray *array; GPtrArray *array;
float refresh_rate;
unsigned i; unsigned i;
unsigned max_hdisplay = 0; unsigned max_hdisplay = 0;
unsigned max_vdisplay = 0; unsigned max_vdisplay = 0;
@ -144,17 +143,15 @@ add_common_modes (MetaOutputInfo *output_info,
for (i = 0; i < output_info->n_modes; i++) for (i = 0; i < output_info->n_modes; i++)
{ {
MetaCrtcMode *crtc_mode = output_info->modes[i]; const MetaCrtcModeInfo *crtc_mode_info =
MetaCrtcModeKms *crtc_mode_kms = META_CRTC_MODE_KMS (crtc_mode); meta_crtc_mode_get_info (output_info->modes[i]);
MetaKmsMode *kms_mode = meta_crtc_mode_kms_get_kms_mode (crtc_mode_kms);
const drmModeModeInfo *drm_mode = meta_kms_mode_get_drm_mode (kms_mode);
float bandwidth; float bandwidth;
refresh_rate = meta_calculate_drm_mode_refresh_rate (drm_mode); bandwidth = crtc_mode_info->refresh_rate * crtc_mode_info->width *
bandwidth = refresh_rate * drm_mode->hdisplay * drm_mode->vdisplay; crtc_mode_info->height;
max_hdisplay = MAX (max_hdisplay, drm_mode->hdisplay); max_hdisplay = MAX (max_hdisplay, crtc_mode_info->width);
max_vdisplay = MAX (max_vdisplay, drm_mode->vdisplay); max_vdisplay = MAX (max_vdisplay, crtc_mode_info->height);
max_refresh_rate = MAX (max_refresh_rate, refresh_rate); max_refresh_rate = MAX (max_refresh_rate, crtc_mode_info->refresh_rate);
max_bandwidth = MAX (max_bandwidth, bandwidth); max_bandwidth = MAX (max_bandwidth, bandwidth);
} }
@ -175,6 +172,8 @@ add_common_modes (MetaOutputInfo *output_info,
MetaKmsMode *fallback_mode = l->data; MetaKmsMode *fallback_mode = l->data;
const drmModeModeInfo *drm_mode; const drmModeModeInfo *drm_mode;
float bandwidth; float bandwidth;
float refresh_rate;
gboolean is_duplicate = FALSE;
if (!(meta_kms_mode_get_flags (fallback_mode) & flag_filter)) if (!(meta_kms_mode_get_flags (fallback_mode) & flag_filter))
continue; continue;
@ -188,6 +187,23 @@ add_common_modes (MetaOutputInfo *output_info,
bandwidth > max_bandwidth) bandwidth > max_bandwidth)
continue; continue;
for (i = 0; i < output_info->n_modes; i++)
{
const MetaCrtcModeInfo *crtc_mode_info =
meta_crtc_mode_get_info (output_info->modes[i]);
if (drm_mode->hdisplay == crtc_mode_info->width &&
drm_mode->vdisplay == crtc_mode_info->height &&
fabs (1 - (refresh_rate / crtc_mode_info->refresh_rate)) <
SYNC_TOLERANCE)
{
is_duplicate = TRUE;
break;
}
}
if (is_duplicate)
continue;
crtc_mode = meta_gpu_kms_get_mode_from_kms_mode (gpu_kms, fallback_mode); crtc_mode = meta_gpu_kms_get_mode_from_kms_mode (gpu_kms, fallback_mode);
g_ptr_array_add (array, crtc_mode); g_ptr_array_add (array, crtc_mode);
} }