[mutter] tests/kms: Add basic plane assignment update tests



commit 65073c145c7729307520447bdba33ee2e8395c8a
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Tue Jun 22 16:23:36 2021 +0200

    tests/kms: Add basic plane assignment update tests
    
    Test that adding a couple of plane assignments were correctly added to
    the update.
    
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2159>

 src/backends/native/meta-kms-mode.h |   2 +
 src/tests/meson.build               |   2 +
 src/tests/meta-kms-test-utils.c     | 105 ++++++++++++++++++++++
 src/tests/meta-kms-test-utils.h     |  38 ++++++++
 src/tests/native-kms-updates.c      | 175 +++++++++++++++++++++++++++++-------
 5 files changed, 290 insertions(+), 32 deletions(-)
---
diff --git a/src/backends/native/meta-kms-mode.h b/src/backends/native/meta-kms-mode.h
index a3499cd99c..d3a81aeafd 100644
--- a/src/backends/native/meta-kms-mode.h
+++ b/src/backends/native/meta-kms-mode.h
@@ -34,8 +34,10 @@ typedef enum _MetaKmsModeFlag
   META_KMS_MODE_FLAG_FALLBACK_PORTRAIT = 1 << 1,
 } MetaKmsModeFlag;
 
+META_EXPORT_TEST
 int meta_kms_mode_get_width (MetaKmsMode *mode);
 
+META_EXPORT_TEST
 int meta_kms_mode_get_height (MetaKmsMode *mode);
 
 const char * meta_kms_mode_get_name (MetaKmsMode *mode);
diff --git a/src/tests/meson.build b/src/tests/meson.build
index 5b3bf11084..c5cb3ed564 100644
--- a/src/tests/meson.build
+++ b/src/tests/meson.build
@@ -300,6 +300,8 @@ if have_native_tests
 
   native_kms_update_tests = executable('mutter-native-kms-update-tests',
     sources: [
+      'meta-kms-test-utils.c',
+      'meta-kms-test-utils.h',
       'native-kms-updates.c',
     ],
     include_directories: tests_includes,
diff --git a/src/tests/meta-kms-test-utils.c b/src/tests/meta-kms-test-utils.c
new file mode 100644
index 0000000000..671719f62a
--- /dev/null
+++ b/src/tests/meta-kms-test-utils.c
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2021 Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ */
+
+#include "config.h"
+
+#include "tests/meta-kms-test-utils.h"
+
+#include <drm_fourcc.h>
+
+#include "backends/native/meta-device-pool.h"
+#include "backends/native/meta-drm-buffer-dumb.h"
+#include "backends/native/meta-backend-native-private.h"
+#include "backends/native/meta-kms-connector.h"
+#include "backends/native/meta-kms-crtc.h"
+#include "backends/native/meta-kms-device.h"
+#include "backends/native/meta-kms.h"
+
+MetaKmsDevice *
+meta_get_test_kms_device (MetaContext *context)
+{
+  MetaBackend *backend = meta_context_get_backend (context);
+  MetaBackendNative *backend_native = META_BACKEND_NATIVE (backend);
+  MetaKms *kms = meta_backend_native_get_kms (backend_native);
+  GList *devices;
+
+  devices = meta_kms_get_devices (kms);
+  g_assert_cmpuint (g_list_length (devices), ==, 1);
+  return META_KMS_DEVICE (devices->data);
+}
+
+MetaKmsCrtc *
+meta_get_test_kms_crtc (MetaKmsDevice *device)
+{
+  GList *crtcs;
+
+  crtcs = meta_kms_device_get_crtcs (device);
+  g_assert_cmpuint (g_list_length (crtcs), ==, 1);
+
+  return META_KMS_CRTC (crtcs->data);
+}
+
+MetaKmsConnector *
+meta_get_test_kms_connector (MetaKmsDevice *device)
+{
+  GList *connectors;
+
+  connectors = meta_kms_device_get_connectors (device);
+  g_assert_cmpuint (g_list_length (connectors), ==, 1);
+
+  return META_KMS_CONNECTOR (connectors->data);
+}
+
+static MetaDeviceFile *
+open_device_file_for (MetaKmsDevice *device)
+{
+  MetaKms *kms = meta_kms_device_get_kms (device);
+  MetaBackend *backend = meta_kms_get_backend (kms);
+  MetaBackendNative *backend_native = META_BACKEND_NATIVE (backend);
+  MetaDevicePool *device_pool =
+    meta_backend_native_get_device_pool (backend_native);
+  const char *device_path;
+  MetaDeviceFile *device_file;
+
+  device_path = meta_kms_device_get_path (device);
+  device_file = meta_device_pool_open (device_pool, device_path,
+                                       META_DEVICE_FILE_FLAG_TAKE_CONTROL,
+                                       NULL);
+  g_assert_nonnull (device_file);
+  return device_file;
+}
+
+MetaDrmBuffer *
+meta_create_test_dumb_buffer (MetaKmsDevice *device,
+                              int            width,
+                              int            height)
+{
+  g_autoptr (MetaDeviceFile) device_file = NULL;
+  MetaDrmBufferDumb *dumb_buffer;
+
+  device_file = open_device_file_for (device);
+  dumb_buffer = meta_drm_buffer_dumb_new (device_file,
+                                          width, height,
+                                          DRM_FORMAT_XRGB8888,
+                                          NULL);
+  g_assert_nonnull (dumb_buffer);
+
+  return META_DRM_BUFFER (dumb_buffer);
+}
diff --git a/src/tests/meta-kms-test-utils.h b/src/tests/meta-kms-test-utils.h
new file mode 100644
index 0000000000..77b6ad8278
--- /dev/null
+++ b/src/tests/meta-kms-test-utils.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2021 Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ */
+
+#ifndef META_KMS_TEST_UTILS_H
+#define META_KMS_TEST_UTILS_H
+
+#include "backends/native/meta-drm-buffer.h"
+#include "backends/native/meta-kms-types.h"
+#include "meta/meta-context.h"
+
+MetaKmsDevice * meta_get_test_kms_device (MetaContext *context);
+
+MetaKmsCrtc * meta_get_test_kms_crtc (MetaKmsDevice *device);
+
+MetaKmsConnector * meta_get_test_kms_connector (MetaKmsDevice *device);
+
+MetaDrmBuffer * meta_create_test_dumb_buffer (MetaKmsDevice *device,
+                                              int            width,
+                                              int            height);
+
+#endif /* META_KMS_TEST_UTILS_H */
diff --git a/src/tests/native-kms-updates.c b/src/tests/native-kms-updates.c
index 86e99e2c9b..87e131d477 100644
--- a/src/tests/native-kms-updates.c
+++ b/src/tests/native-kms-updates.c
@@ -20,11 +20,6 @@
 
 #include "config.h"
 
-#include <gbm.h>
-
-#include "backends/native/meta-backend-native-private.h"
-#include "backends/native/meta-device-pool.h"
-#include "backends/native/meta-drm-buffer-dumb.h"
 #include "backends/native/meta-kms-connector.h"
 #include "backends/native/meta-kms-crtc.h"
 #include "backends/native/meta-kms-device.h"
@@ -32,34 +27,10 @@
 #include "backends/native/meta-kms-update-private.h"
 #include "backends/native/meta-kms.h"
 #include "meta-test/meta-context-test.h"
-#include "meta/meta-backend.h"
+#include "tests/meta-kms-test-utils.h"
 
 static MetaContext *test_context;
 
-static MetaKmsDevice *
-get_test_kms_device (void)
-{
-  MetaBackend *backend = meta_context_get_backend (test_context);
-  MetaBackendNative *backend_native = META_BACKEND_NATIVE (backend);
-  MetaKms *kms = meta_backend_native_get_kms (backend_native);
-  GList *devices;
-
-  devices = meta_kms_get_devices (kms);
-  g_assert_cmpuint (g_list_length (devices), ==, 1);
-  return META_KMS_DEVICE (devices->data);
-}
-
-static MetaKmsCrtc *
-get_test_crtc (MetaKmsDevice *device)
-{
-  GList *crtcs;
-
-  crtcs = meta_kms_device_get_crtcs (device);
-  g_assert_cmpuint (g_list_length (crtcs), ==, 1);
-
-  return META_KMS_CRTC (crtcs->data);
-}
-
 static void
 meta_test_kms_update_sanity (void)
 {
@@ -67,8 +38,8 @@ meta_test_kms_update_sanity (void)
   MetaKmsCrtc *crtc;
   MetaKmsUpdate *update;
 
-  device = get_test_kms_device ();
-  crtc = get_test_crtc (device);
+  device = meta_get_test_kms_device (test_context);
+  crtc = meta_get_test_kms_crtc (device);
 
   update = meta_kms_update_new (device);
   g_assert (meta_kms_update_get_device (update) == device);
@@ -83,6 +54,144 @@ 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)
+{
+  MetaKmsDevice *device;
+  MetaKmsUpdate *update;
+  MetaKmsCrtc *crtc;
+  MetaKmsConnector *connector;
+  MetaKmsPlane *primary_plane;
+  MetaKmsPlane *cursor_plane;
+  MetaKmsMode *mode;
+  int mode_width, mode_height;
+  g_autoptr (MetaDrmBuffer) primary_buffer = NULL;
+  g_autoptr (MetaDrmBuffer) cursor_buffer = NULL;
+  MetaKmsPlaneAssignment *primary_plane_assignment;
+  MetaKmsPlaneAssignment *cursor_plane_assignment;
+  GList *plane_assignments;
+
+  device = meta_get_test_kms_device (test_context);
+  update = meta_kms_update_new (device);
+  crtc = meta_get_test_kms_crtc (device);
+  connector = meta_get_test_kms_connector (device);
+
+  primary_plane = meta_kms_device_get_primary_plane_for (device, crtc);
+  g_assert_nonnull (primary_plane);
+
+  cursor_plane = meta_kms_device_get_cursor_plane_for (device, crtc);
+  g_assert_nonnull (cursor_plane);
+
+  mode = get_preferred_mode (connector);
+
+  mode_width = meta_kms_mode_get_width (mode);
+  mode_height = meta_kms_mode_get_height (mode);
+  primary_buffer = meta_create_test_dumb_buffer (device,
+                                                 mode_width, mode_height);
+
+  primary_plane_assignment =
+    meta_kms_update_assign_plane (update,
+                                  crtc,
+                                  primary_plane,
+                                  primary_buffer,
+                                  META_FIXED_16_RECTANGLE_INIT_INT (0, 0,
+                                                                    mode_width,
+                                                                    mode_height),
+                                  META_RECTANGLE_INIT (0, 0,
+                                                       mode_width, mode_height),
+                                  META_KMS_ASSIGN_PLANE_FLAG_NONE);
+  g_assert_nonnull (primary_plane_assignment);
+  g_assert_cmpint (primary_plane_assignment->src_rect.x, ==, 0);
+  g_assert_cmpint (primary_plane_assignment->src_rect.y, ==, 0);
+  g_assert_cmpint (primary_plane_assignment->src_rect.width,
+                   ==,
+                   meta_fixed_16_from_int (mode_width));
+  g_assert_cmpint (primary_plane_assignment->src_rect.height,
+                   ==,
+                   meta_fixed_16_from_int (mode_height));
+  g_assert_cmpint (primary_plane_assignment->dst_rect.x, ==, 0);
+  g_assert_cmpint (primary_plane_assignment->dst_rect.y, ==, 0);
+  g_assert_cmpint (primary_plane_assignment->dst_rect.width, ==, mode_width);
+  g_assert_cmpint (primary_plane_assignment->dst_rect.height, ==, mode_height);
+
+  cursor_buffer = meta_create_test_dumb_buffer (device, 64, 64);
+
+  cursor_plane_assignment =
+    meta_kms_update_assign_plane (update,
+                                  crtc,
+                                  cursor_plane,
+                                  cursor_buffer,
+                                  META_FIXED_16_RECTANGLE_INIT_INT (0, 0, 64, 64),
+                                  META_RECTANGLE_INIT (24, 48, 64, 64),
+                                  META_KMS_ASSIGN_PLANE_FLAG_NONE);
+  g_assert_nonnull (cursor_plane_assignment);
+  g_assert_cmpint (cursor_plane_assignment->src_rect.x, ==, 0);
+  g_assert_cmpint (cursor_plane_assignment->src_rect.y, ==, 0);
+  g_assert_cmpint (cursor_plane_assignment->src_rect.width,
+                   ==,
+                   meta_fixed_16_from_int (64));
+  g_assert_cmpint (cursor_plane_assignment->src_rect.height,
+                   ==,
+                   meta_fixed_16_from_int (64));
+  g_assert_cmpint (cursor_plane_assignment->dst_rect.x, ==, 24);
+  g_assert_cmpint (cursor_plane_assignment->dst_rect.y, ==, 48);
+  g_assert_cmpint (cursor_plane_assignment->dst_rect.width, ==, 64);
+  g_assert_cmpint (cursor_plane_assignment->dst_rect.height, ==, 64);
+
+  meta_kms_plane_assignment_set_cursor_hotspot (cursor_plane_assignment,
+                                                10, 11);
+
+  g_assert (meta_kms_update_get_primary_plane_assignment (update, crtc) ==
+            primary_plane_assignment);
+
+  g_assert (primary_plane_assignment->crtc == crtc);
+  g_assert (primary_plane_assignment->update == update);
+  g_assert (primary_plane_assignment->plane == primary_plane);
+  g_assert (primary_plane_assignment->buffer == primary_buffer);
+  g_assert_cmpuint (primary_plane_assignment->rotation, ==, 0);
+  g_assert_false (primary_plane_assignment->cursor_hotspot.is_valid);
+
+  g_assert (meta_kms_update_get_cursor_plane_assignment (update, crtc) ==
+            cursor_plane_assignment);
+
+  g_assert (cursor_plane_assignment->crtc == crtc);
+  g_assert (cursor_plane_assignment->update == update);
+  g_assert (cursor_plane_assignment->plane == cursor_plane);
+  g_assert (cursor_plane_assignment->buffer == cursor_buffer);
+  g_assert_cmpuint (cursor_plane_assignment->rotation, ==, 0);
+  g_assert_true (cursor_plane_assignment->cursor_hotspot.is_valid);
+  g_assert_cmpint (cursor_plane_assignment->cursor_hotspot.x, ==, 10);
+  g_assert_cmpint (cursor_plane_assignment->cursor_hotspot.y, ==, 11);
+
+  plane_assignments = meta_kms_update_get_plane_assignments (update);
+  g_assert_cmpuint (g_list_length (plane_assignments), ==, 2);
+
+  g_assert_nonnull (g_list_find (plane_assignments, primary_plane_assignment));
+  g_assert_nonnull (g_list_find (plane_assignments, cursor_plane_assignment));
+
+  meta_kms_update_free (update);
+}
+
 static void
 meta_test_kms_update_fixed16 (void)
 {
@@ -107,6 +216,8 @@ init_tests (void)
                    meta_test_kms_update_sanity);
   g_test_add_func ("/backends/native/kms/update/fixed16",
                    meta_test_kms_update_fixed16);
+  g_test_add_func ("/backends/native/kms/update/plane-assignments",
+                   meta_test_kms_update_plane_assignments);
 }
 
 int


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]