1
0
Fork 0

kms/connector: Add getter for preferred mode

This replaces a helper used in tests. The intention is to use it from
other tests, and seemed like a good fit to place it under the KMS
connector object itself.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2159>
This commit is contained in:
Jonas Ådahl 2021-06-24 15:30:25 +02:00 committed by Marge Bot
parent 6a9e2e9e2d
commit feadaacfdd
4 changed files with 26 additions and 22 deletions

View file

@ -123,6 +123,26 @@ meta_kms_connector_can_clone (MetaKmsConnector *connector,
return TRUE;
}
MetaKmsMode *
meta_kms_connector_get_preferred_mode (MetaKmsConnector *connector)
{
const MetaKmsConnectorState *state;
GList *l;
state = meta_kms_connector_get_current_state (connector);
for (l = state->modes; l; l = l->next)
{
MetaKmsMode *mode = l->data;
const drmModeModeInfo *drm_mode;
drm_mode = meta_kms_mode_get_drm_mode (mode);
if (drm_mode->type & DRM_MODE_TYPE_PREFERRED)
return mode;
}
return NULL;
}
const MetaKmsConnectorState *
meta_kms_connector_get_current_state (MetaKmsConnector *connector)
{

View file

@ -73,6 +73,9 @@ const char * meta_kms_connector_get_name (MetaKmsConnector *connector);
gboolean meta_kms_connector_can_clone (MetaKmsConnector *connector,
MetaKmsConnector *other_connector);
META_EXPORT_TEST
MetaKmsMode * meta_kms_connector_get_preferred_mode (MetaKmsConnector *connector);
META_EXPORT_TEST
const MetaKmsConnectorState * meta_kms_connector_get_current_state (MetaKmsConnector *connector);

View file

@ -58,6 +58,7 @@ meta_test_kms_device_sanity (void)
g_assert_cmpuint (g_list_length (connectors), ==, 1);
connector = META_KMS_CONNECTOR (connectors->data);
g_assert (meta_kms_connector_get_device (connector) == device);
g_assert_nonnull (meta_kms_connector_get_preferred_mode (connector));
crtcs = meta_kms_device_get_crtcs (device);
g_assert_cmpuint (g_list_length (crtcs), ==, 1);

View file

@ -54,26 +54,6 @@ meta_test_kms_update_sanity (void)
meta_kms_update_free (update);
}
static MetaKmsMode *
get_preferred_mode (MetaKmsConnector *connector)
{
const MetaKmsConnectorState *state;
GList *l;
state = meta_kms_connector_get_current_state (connector);
for (l = state->modes; l; l = l->next)
{
MetaKmsMode *mode = l->data;
const drmModeModeInfo *drm_mode;
drm_mode = meta_kms_mode_get_drm_mode (mode);
if (drm_mode->type & DRM_MODE_TYPE_PREFERRED)
return mode;
}
g_assert_not_reached ();
}
static void
meta_test_kms_update_plane_assignments (void)
{
@ -102,7 +82,7 @@ meta_test_kms_update_plane_assignments (void)
cursor_plane = meta_kms_device_get_cursor_plane_for (device, crtc);
g_assert_nonnull (cursor_plane);
mode = get_preferred_mode (connector);
mode = meta_kms_connector_get_preferred_mode (connector);
mode_width = meta_kms_mode_get_width (mode);
mode_height = meta_kms_mode_get_height (mode);
@ -220,7 +200,7 @@ meta_test_kms_update_mode_sets (void)
update = meta_kms_update_new (device);
crtc = meta_get_test_kms_crtc (device);
connector = meta_get_test_kms_connector (device);
mode = get_preferred_mode (connector);
mode = meta_kms_connector_get_preferred_mode (connector);
meta_kms_update_mode_set (update, crtc,
g_list_append (NULL, connector),