[igt-dev] [PATCH i-g-t 05/16] lib/kms: Add igt_plane_has_rotation()

Ville Syrjala ville.syrjala at linux.intel.com
Fri Jul 16 14:44:31 UTC 2021


From: Ville Syrjälä <ville.syrjala at linux.intel.com>

Probe the supported rotations for each plane from the kernel
This should let us eliminate tons of hand rolled gen checks all over.

Signed-off-by: Ville Syrjälä <ville.syrjala at linux.intel.com>
---
 lib/igt_kms.c | 41 +++++++++++++++++++++++++++++++++++++++++
 lib/igt_kms.h | 16 ++++++++++++++++
 2 files changed, 57 insertions(+)

diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index c7c69b6ea0eb..944e3e411a0e 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -612,6 +612,41 @@ const char * const igt_connector_prop_names[IGT_NUM_CONNECTOR_PROPS] = {
 	[IGT_CONNECTOR_DITHERING_MODE] = "dithering mode",
 };
 
+const char * const igt_rotation_names[] = {
+	[0] = "rotate-0",
+	[1] = "rotate-90",
+	[2] = "rotate-180",
+	[3] = "rotate-270",
+	[4] = "reflect-x",
+	[5] = "reflect-y",
+};
+
+static unsigned int
+igt_plane_rotations(igt_display_t *display, igt_plane_t *plane,
+		    drmModePropertyPtr prop)
+{
+	unsigned int rotations = 0;
+
+	igt_assert_eq(prop->flags & DRM_MODE_PROP_LEGACY_TYPE,
+		      DRM_MODE_PROP_BITMASK);
+	igt_assert_eq(prop->count_values, prop->count_enums);
+
+	for (int i = 0; i < ARRAY_SIZE(igt_rotation_names); i++) {
+		for (int j = 0; j < prop->count_enums; j++) {
+			if (strcmp(igt_rotation_names[i], prop->enums[j].name))
+				continue;
+
+			/* various places assume the uabi uses specific bit values */
+			igt_assert_eq(prop->values[j], i);
+
+			rotations |= 1 << i;
+		}
+	}
+	igt_assert_neq(rotations, 0);
+
+	return rotations;
+}
+
 /*
  * Retrieve all the properies specified in props_name and store them into
  * plane->props.
@@ -640,9 +675,15 @@ igt_fill_plane_props(igt_display_t *display, igt_plane_t *plane,
 			break;
 		}
 
+		if (strcmp(prop->name, "rotation") == 0)
+			plane->rotations = igt_plane_rotations(display, plane, prop);
+
 		drmModeFreeProperty(prop);
 	}
 
+	if (!plane->rotations)
+		plane->rotations = IGT_ROTATION_0;
+
 	drmModeFreeObjectProperties(props);
 }
 
diff --git a/lib/igt_kms.h b/lib/igt_kms.h
index 45d21e42503e..64d12df4fd1b 100644
--- a/lib/igt_kms.h
+++ b/lib/igt_kms.h
@@ -358,6 +358,8 @@ typedef struct igt_plane {
 		uint64_t values[IGT_NUM_COLOR_RANGES];
 	} color_range;
 
+	igt_rotation_t rotations;
+
 	uint64_t changed;
 	uint32_t props[IGT_NUM_PLANE_PROPS];
 	uint64_t values[IGT_NUM_PLANE_PROPS];
@@ -491,6 +493,20 @@ void igt_fb_set_position(struct igt_fb *fb, igt_plane_t *plane,
 void igt_fb_set_size(struct igt_fb *fb, igt_plane_t *plane,
 	uint32_t w, uint32_t h);
 
+/**
+ * igt_plane_has_rotation:
+ * @plane: Plane pointer for which rotation is to be queried
+ * @rotation: Plane rotation value (0, 90, 180, 270)
+ *
+ * Check whether @plane potentially supports the given @rotation.
+ * Note that @rotation may still rejected later due to other
+ * constraints (eg. incompatible pixel format or modifier).
+ */
+static inline bool igt_plane_has_rotation(igt_plane_t *plane, igt_rotation_t rotation)
+{
+	return (plane->rotations & rotation) == rotation;
+}
+
 void igt_wait_for_vblank(int drm_fd, int crtc_offset);
 void igt_wait_for_vblank_count(int drm_fd, int crtc_offset, int count);
 
-- 
2.31.1



More information about the igt-dev mailing list