[igt-dev] [PATCH v5 04/13] fb: Add format conversion routine

Maxime Ripard maxime.ripard at bootlin.com
Fri Aug 24 08:04:10 UTC 2018


The chamelium format subtests will need to convert the reference pattern to
the format to be tested on the DRM device.

However, Cairo is very limited when it comes to format, and while pixman
has much more support for formats, it's still falling short compared to
what DRM exposes, especially on the YUV side. Plus, since we want to run
CRC checks on the frame, we can't afford having conversions back and forth
between RGB24, as the current API is doing.

In order to abstract this away, let's create a function that will convert a
igt_fb structure to another DRM format and return the converted igt_fb.

For now, we will use only cairo to do the conversion, but we will use other
libraries or roll our own routines to convert to more exotic formats and
abstract it away from the users.

Reviewed-by: Eric Anholt <eric at anholt.net>
Signed-off-by: Maxime Ripard <maxime.ripard at bootlin.com>
---
 lib/igt_fb.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 lib/igt_fb.h |  2 ++-
 2 files changed, 61 insertions(+)

diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index 1914233786a5..9aee02c35c16 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -2029,6 +2029,65 @@ void igt_remove_fb(int fd, struct igt_fb *fb)
 }
 
 /**
+ * igt_fb_convert:
+ * @dst: pointer to the #igt_fb structure that will store the conversion result
+ * @src: pointer to the #igt_fb structure that stores the frame we convert
+ * @dst_fourcc: DRM format specifier to convert to
+ *
+ * This will convert a given @src content to the @dst_fourcc format,
+ * storing the result in the @dst fb, allocating the @dst fb
+ * underlying buffer.
+ *
+ * Once done with @dst, the caller will have to call igt_remove_fb()
+ * on it to free the associated resources.
+ *
+ * Returns:
+ * The kms id of the created framebuffer.
+ */
+unsigned int igt_fb_convert(struct igt_fb *dst, struct igt_fb *src,
+			    uint32_t dst_fourcc)
+{
+	struct fb_convert cvt = { 0 };
+	void *dst_ptr, *src_ptr;
+	int fb_id;
+
+	fb_id = igt_create_fb(src->fd, src->width, src->height,
+			      dst_fourcc, LOCAL_DRM_FORMAT_MOD_NONE, dst);
+	igt_assert(fb_id > 0);
+
+	src_ptr = igt_fb_map_buffer(src->fd, src);
+	igt_assert(src_ptr);
+
+	dst_ptr = igt_fb_map_buffer(dst->fd, dst);
+	igt_assert(dst_ptr);
+
+	cvt.width = src->width;
+	cvt.height = src->height;
+
+	cvt.dst.ptr = dst_ptr;
+	cvt.dst.fmt = dst_fourcc;
+	cvt.dst.stride = dst->stride;
+	cvt.dst.size = dst->size;
+	cvt.dst.color_encoding = dst->color_encoding;
+	cvt.dst.color_range = dst->color_range;
+	memcpy(&cvt.dst.offsets, dst->offsets, sizeof(dst->offsets));
+
+	cvt.src.ptr = src_ptr;
+	cvt.src.fmt = src->drm_format;
+	cvt.src.stride = src->stride;
+	cvt.src.size = src->size;
+	cvt.src.color_encoding = src->color_encoding;
+	cvt.src.color_range = src->color_range;
+	memcpy(&cvt.src.offsets, src->offsets, sizeof(src->offsets));
+	fb_convert(&cvt);
+
+	igt_fb_unmap_buffer(dst, dst_ptr);
+	igt_fb_unmap_buffer(src, src_ptr);
+
+	return fb_id;
+}
+
+/**
  * igt_bpp_depth_to_drm_format:
  * @bpp: desired bits per pixel
  * @depth: desired depth
diff --git a/lib/igt_fb.h b/lib/igt_fb.h
index ca028f550ab8..eb68b236530e 100644
--- a/lib/igt_fb.h
+++ b/lib/igt_fb.h
@@ -130,6 +130,8 @@ unsigned int igt_create_image_fb(int drm_fd,  int width, int height,
 				 struct igt_fb *fb /* out */);
 unsigned int igt_create_stereo_fb(int drm_fd, drmModeModeInfo *mode,
 				  uint32_t format, uint64_t tiling);
+unsigned int igt_fb_convert(struct igt_fb *dst, struct igt_fb *src,
+			    uint32_t dst_fourcc);
 void igt_remove_fb(int fd, struct igt_fb *fb);
 int igt_dirty_fb(int fd, struct igt_fb *fb);
 void *igt_fb_map_buffer(int fd, struct igt_fb *fb);
-- 
git-series 0.9.1


More information about the igt-dev mailing list