[igt-dev] [PATCH i-g-t v2 2/3] lib/igt_kms: Add igt_reduce_format()

Ville Syrjala ville.syrjala at linux.intel.com
Mon Feb 3 16:35:07 UTC 2020


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

Add a helper to reduce a pixel format to a "base" format.
Ie. group all formats to some idea of classes based on the
bits per pixel + component sizes etc. ignoring any component ordering.
Let's us skip potentially redundant tests when all we might care
about is testing each format "class" the once.

v2: Add some docs (Chris)

Cc: From: Chris Wilson <chris at chris-wilson.co.uk>
Signed-off-by: Ville Syrjälä <ville.syrjala at linux.intel.com>
---
 lib/igt_kms.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/igt_kms.h |  1 +
 2 files changed, 96 insertions(+)

diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index d20daaad7764..f66da635c66e 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -4474,3 +4474,98 @@ void igt_parse_connector_tile_blob(drmModePropertyBlobPtr blob,
 	tile->tile_h_size = atoi(strtok(NULL, ":"));
 	tile->tile_v_size = atoi(strtok(NULL, ":"));
 }
+
+/**
+ * igt_reduce_format:
+ * @format: drm fourcc
+ *
+ * Reduce @format to a base format. The aim is to allow grouping
+ * sufficiently similar formats into classes. Formats with identical
+ * component sizes, overall pixel size, chroma subsamling, etc. are
+ * considered part of the same class, no matter in which order the
+ * components appear. We arbitrarily choose one of the formats in
+ * the class as the base format. Note that the base format itself
+ * may not be supported by whatever device is being tested even if
+ * some of the other formats in the class are supported.
+ *
+ * Returns:
+ * The base format for @format
+ */
+uint32_t igt_reduce_format(uint32_t format)
+{
+	switch (format) {
+	case DRM_FORMAT_RGB332:
+	case DRM_FORMAT_BGR233:
+		return DRM_FORMAT_RGB332;
+	case DRM_FORMAT_XRGB1555:
+	case DRM_FORMAT_XBGR1555:
+	case DRM_FORMAT_ARGB1555:
+	case DRM_FORMAT_ABGR1555:
+	case DRM_FORMAT_RGBX5551:
+	case DRM_FORMAT_BGRX5551:
+	case DRM_FORMAT_RGBA5551:
+	case DRM_FORMAT_BGRA5551:
+		return DRM_FORMAT_XRGB1555;
+	case DRM_FORMAT_RGB565:
+	case DRM_FORMAT_BGR565:
+		return DRM_FORMAT_RGB565;
+	case DRM_FORMAT_XRGB8888:
+	case DRM_FORMAT_XBGR8888:
+	case DRM_FORMAT_ARGB8888:
+	case DRM_FORMAT_ABGR8888:
+	case DRM_FORMAT_RGBX8888:
+	case DRM_FORMAT_BGRX8888:
+	case DRM_FORMAT_RGBA8888:
+	case DRM_FORMAT_BGRA8888:
+		return DRM_FORMAT_XRGB8888;
+	case DRM_FORMAT_XRGB2101010:
+	case DRM_FORMAT_XBGR2101010:
+	case DRM_FORMAT_ARGB2101010:
+	case DRM_FORMAT_ABGR2101010:
+	case DRM_FORMAT_RGBX1010102:
+	case DRM_FORMAT_BGRX1010102:
+	case DRM_FORMAT_RGBA1010102:
+	case DRM_FORMAT_BGRA1010102:
+		return DRM_FORMAT_XRGB2101010;
+	case DRM_FORMAT_XRGB16161616F:
+	case DRM_FORMAT_XBGR16161616F:
+	case DRM_FORMAT_ARGB16161616F:
+	case DRM_FORMAT_ABGR16161616F:
+		return DRM_FORMAT_XRGB16161616F;
+	case DRM_FORMAT_YUYV:
+	case DRM_FORMAT_UYVY:
+	case DRM_FORMAT_YVYU:
+	case DRM_FORMAT_VYUY:
+		return DRM_FORMAT_YUYV;
+	case DRM_FORMAT_NV12:
+	case DRM_FORMAT_NV21:
+		return DRM_FORMAT_NV12;
+	case DRM_FORMAT_NV16:
+	case DRM_FORMAT_NV61:
+		return DRM_FORMAT_NV16;
+	case DRM_FORMAT_NV24:
+	case DRM_FORMAT_NV42:
+		return DRM_FORMAT_NV24;
+	case DRM_FORMAT_P010:
+	case DRM_FORMAT_P012:
+	case DRM_FORMAT_P016:
+		return DRM_FORMAT_P010;
+	case DRM_FORMAT_Y210:
+	case DRM_FORMAT_Y212:
+	case DRM_FORMAT_Y216:
+		return DRM_FORMAT_Y210;
+	case DRM_FORMAT_XYUV8888:
+	case DRM_FORMAT_AYUV:
+		return DRM_FORMAT_XYUV8888;
+	case DRM_FORMAT_XVYU2101010:
+	case DRM_FORMAT_Y410:
+		return DRM_FORMAT_XVYU2101010;
+	case DRM_FORMAT_XVYU12_16161616:
+	case DRM_FORMAT_XVYU16161616:
+	case DRM_FORMAT_Y412:
+	case DRM_FORMAT_Y416:
+		return DRM_FORMAT_XVYU12_16161616;
+	default:
+		return format;
+	}
+}
diff --git a/lib/igt_kms.h b/lib/igt_kms.h
index 6c919e92f488..66b0de516e3c 100644
--- a/lib/igt_kms.h
+++ b/lib/igt_kms.h
@@ -846,5 +846,6 @@ void igt_parse_connector_tile_blob(drmModePropertyBlobPtr blob,
 
 int igt_connector_sysfs_open(int drm_fd,
 			     drmModeConnector *connector);
+uint32_t igt_reduce_format(uint32_t format);
 
 #endif /* __IGT_KMS_H__ */
-- 
2.24.1



More information about the igt-dev mailing list