From feadaacfdd02fa1d3bedfb64b94c719d86c01f6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Thu, 24 Jun 2021 15:30:25 +0200 Subject: [PATCH] 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: --- src/backends/native/meta-kms-connector.c | 20 ++++++++++++++++++++ src/backends/native/meta-kms-connector.h | 3 +++ src/tests/native-kms-device.c | 1 + src/tests/native-kms-updates.c | 24 ++---------------------- 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/backends/native/meta-kms-connector.c b/src/backends/native/meta-kms-connector.c index b317cf935..ca0710f21 100644 --- a/src/backends/native/meta-kms-connector.c +++ b/src/backends/native/meta-kms-connector.c @@ -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) { diff --git a/src/backends/native/meta-kms-connector.h b/src/backends/native/meta-kms-connector.h index 02f74d9f6..c2b763548 100644 --- a/src/backends/native/meta-kms-connector.h +++ b/src/backends/native/meta-kms-connector.h @@ -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); diff --git a/src/tests/native-kms-device.c b/src/tests/native-kms-device.c index c14579ff8..55649ed6d 100644 --- a/src/tests/native-kms-device.c +++ b/src/tests/native-kms-device.c @@ -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); diff --git a/src/tests/native-kms-updates.c b/src/tests/native-kms-updates.c index ff983f004..7aa77ce02 100644 --- a/src/tests/native-kms-updates.c +++ b/src/tests/native-kms-updates.c @@ -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),