[igt-dev] [PATCH i-g-t 03/12] lib/igt_fb: Add igt_fb_supported_format()

Maarten Lankhorst maarten.lankhorst at linux.intel.com
Tue Feb 6 10:14:08 UTC 2018


This makes it possible to iterate whether a format is supported or not,
without each driver having to open code it.

Signed-off-by: Maarten Lankhorst <maarten.lankhorst at linux.intel.com>
---
 lib/igt_fb.c              | 18 ++++++++++++++++++
 lib/igt_fb.h              |  1 +
 tests/kms_atomic.c        | 13 +++----------
 tests/kms_plane.c         | 16 +---------------
 tests/kms_plane_scaling.c | 22 ++++------------------
 5 files changed, 27 insertions(+), 43 deletions(-)

diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index 35a928b9281d..0389b1c1b159 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -1719,3 +1719,21 @@ void igt_get_all_cairo_formats(const uint32_t **formats, int *format_count)
 	*formats = drm_formats;
 	*format_count = n_formats;
 }
+
+/**
+ * igt_fb_supported_format:
+ * @drm_format: drm fourcc to test.
+ *
+ * This functions returns whether @drm_format can be succesfully created by
+ * igt_create_fb() and drawn to by igt_get_cairo_ctx().
+ */
+bool igt_fb_supported_format(uint32_t drm_format)
+{
+	struct format_desc_struct *f;
+
+	for_each_format(f)
+		if (f->drm_id == drm_format)
+			return f->cairo_id != CAIRO_FORMAT_INVALID;
+
+	return false;
+}
diff --git a/lib/igt_fb.h b/lib/igt_fb.h
index 77fd88bb7aca..a6ce07898784 100644
--- a/lib/igt_fb.h
+++ b/lib/igt_fb.h
@@ -163,6 +163,7 @@ uint32_t igt_bpp_depth_to_drm_format(int bpp, int depth);
 uint32_t igt_drm_format_to_bpp(uint32_t drm_format);
 const char *igt_format_str(uint32_t drm_format);
 void igt_get_all_cairo_formats(const uint32_t **formats, int *format_count);
+bool igt_fb_supported_format(uint32_t drm_format);
 
 #endif /* __IGT_FB_H__ */
 
diff --git a/tests/kms_atomic.c b/tests/kms_atomic.c
index 2e21b53b8c87..ac02baf0170b 100644
--- a/tests/kms_atomic.c
+++ b/tests/kms_atomic.c
@@ -264,20 +264,13 @@ static void crtc_commit_atomic_flags_err(igt_pipe_t *pipe, igt_plane_t *plane,
 static uint32_t plane_get_igt_format(igt_plane_t *plane)
 {
 	drmModePlanePtr plane_kms;
-	const uint32_t *igt_formats;
-	int num_igt_formats;
 	int i;
 
 	plane_kms = plane->drm_plane;
 
-	igt_get_all_cairo_formats(&igt_formats, &num_igt_formats);
-	for (i = 0; i < num_igt_formats; i++) {
-		int j;
-
-		for (j = 0; j < plane_kms->count_formats; j++) {
-			if (plane_kms->formats[j] == igt_formats[i])
-				return plane_kms->formats[j];
-		}
+	for (i = 0; i < plane_kms->count_formats; i++) {
+		if (igt_fb_supported_format(plane_kms->formats[i]))
+			return plane_kms->formats[i];
 	}
 
 	return 0;
diff --git a/tests/kms_plane.c b/tests/kms_plane.c
index 54bcffc16f4f..23173b966eab 100644
--- a/tests/kms_plane.c
+++ b/tests/kms_plane.c
@@ -366,20 +366,6 @@ test_plane_panning(data_t *data, enum pipe pipe, unsigned int flags)
 	igt_skip_on(connected_outs == 0);
 }
 
-static bool can_draw(uint32_t drm_format)
-{
-	const uint32_t *drm_formats;
-	int format_count, i;
-
-	igt_get_all_cairo_formats(&drm_formats, &format_count);
-
-	for (i = 0; i < format_count; i++)
-		if (drm_formats[i] == drm_format)
-			return true;
-
-	return false;
-}
-
 static void test_format_plane(data_t *data, enum pipe pipe,
 			      igt_output_t *output, igt_plane_t *plane)
 {
@@ -420,7 +406,7 @@ static void test_format_plane(data_t *data, enum pipe pipe,
 	for (i = 0; i < plane->drm_plane->count_formats; i++) {
 		format = plane->drm_plane->formats[i];
 
-		if (!can_draw(format))
+		if (!igt_fb_supported_format(format))
 			continue;
 
 		igt_debug("Testing format 0x%x on %s.%u\n",
diff --git a/tests/kms_plane_scaling.c b/tests/kms_plane_scaling.c
index 3171331c96b8..7a5470106cd5 100644
--- a/tests/kms_plane_scaling.c
+++ b/tests/kms_plane_scaling.c
@@ -173,20 +173,6 @@ static bool can_rotate(unsigned format)
 	return true;
 }
 
-static bool can_draw(uint32_t drm_format)
-{
-	const uint32_t *drm_formats;
-	int format_count, i;
-
-	igt_get_all_cairo_formats(&drm_formats, &format_count);
-
-	for (i = 0; i < format_count; i++)
-		if (drm_formats[i] == drm_format)
-			return true;
-
-	return false;
-}
-
 static void test_scaler_with_rotation_pipe(data_t *d, enum pipe pipe,
 					   igt_output_t *output)
 {
@@ -202,7 +188,7 @@ static void test_scaler_with_rotation_pipe(data_t *d, enum pipe pipe,
 			igt_rotation_t rot = rotations[i];
 			for (int j = 0; j < plane->drm_plane->count_formats; j++) {
 				unsigned format = plane->drm_plane->formats[j];
-				if (can_draw(format) && can_rotate(format))
+				if (igt_fb_supported_format(format) && can_rotate(format))
 					check_scaling_pipe_plane_rot(d, plane, format,
 								     LOCAL_I915_FORMAT_MOD_Y_TILED,
 								     pipe, output, rot);
@@ -235,7 +221,7 @@ static void test_scaler_with_pixel_format_pipe(data_t *d, enum pipe pipe, igt_ou
 			for (int j = 0; j < plane->drm_plane->count_formats; j++) {
 				uint32_t format = plane->drm_plane->formats[j];
 
-				if (can_draw(format))
+				if (igt_fb_supported_format(format))
 					check_scaling_pipe_plane_rot(d, plane,
 								     format, tiling,
 								     pipe, output, IGT_ROTATION_0);
@@ -446,13 +432,13 @@ test_scaler_with_clipping_clamping_scenario(data_t *d, enum pipe pipe, igt_outpu
 
 	for (int i = 0; i < d->plane1->drm_plane->count_formats; i++) {
 		unsigned f1 = d->plane1->drm_plane->formats[i];
-		if (!can_draw(f1))
+		if (!igt_fb_supported_format(f1))
 			continue;
 
 		for (int j = 0; j < d->plane2->drm_plane->count_formats; j++) {
 			unsigned f2 = d->plane2->drm_plane->formats[j];
 
-			if (!can_draw(f2))
+			if (!igt_fb_supported_format(f2))
 				continue;
 
 			__test_scaler_with_clipping_clamping_scenario(d, mode, f1, f2);
-- 
2.16.1



More information about the igt-dev mailing list