All of lore.kernel.org
 help / color / mirror / Atom feed
From: Maxime Ripard <maxime.ripard@bootlin.com>
To: igt-dev@lists.freedesktop.org
Cc: eben@raspberrypi.org,
	Paul Kocialkowski <paul.kocialkowski@bootlin.com>,
	Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Subject: [igt-dev] [PATCH v7 07/14] fb: Add support for conversions through pixman
Date: Tue, 11 Sep 2018 10:47:34 +0200	[thread overview]
Message-ID: <2a7b88e3a05afa4b8c8661a59a87e9d668cf5a07.1536655647.git-series.maxime.ripard@bootlin.com> (raw)
In-Reply-To: <cover.cafc7aee9c887562e8432741cd1f0543ff92121a.1536655647.git-series.maxime.ripard@bootlin.com>
In-Reply-To: <cover.cafc7aee9c887562e8432741cd1f0543ff92121a.1536655647.git-series.maxime.ripard@bootlin.com>

Pixman allows for much more conversions than cairo, and we don't want to
open code conversions routine for the common formats.

Let's plug pixman in our conversion function so that we can benefit from it
when possible.

Reviewed-by: Eric Anholt <eric@anholt.net>
Signed-off-by: Maxime Ripard <maxime.ripard@bootlin.com>
---
 lib/igt_fb.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 53 insertions(+), 2 deletions(-)

diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index 624fddbd465b..64370e01c1d6 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -29,6 +29,7 @@
 #include <math.h>
 #include <wchar.h>
 #include <inttypes.h>
+#include <pixman.h>
 
 #include "drmtest.h"
 #include "igt_aux.h"
@@ -59,29 +60,36 @@
  * functions to work with these pixel format codes.
  */
 
+#define PIXMAN_invalid	0
+
 /* drm fourcc/cairo format maps */
 static struct format_desc_struct {
 	const char *name;
 	uint32_t drm_id;
 	cairo_format_t cairo_id;
+	pixman_format_code_t pixman_id;
 	int depth;
 	int num_planes;
 	int plane_bpp[4];
 } format_desc[] = {
 	{ .name = "RGB565", .depth = 16, .drm_id = DRM_FORMAT_RGB565,
 	  .cairo_id = CAIRO_FORMAT_RGB16_565,
+	  .pixman_id = PIXMAN_r5g6b5,
 	  .num_planes = 1, .plane_bpp = { 16, },
 	},
 	{ .name = "XRGB8888", .depth = 24, .drm_id = DRM_FORMAT_XRGB8888,
 	  .cairo_id = CAIRO_FORMAT_RGB24,
+	  .pixman_id = PIXMAN_x8r8g8b8,
 	  .num_planes = 1, .plane_bpp = { 32, },
 	},
 	{ .name = "XRGB2101010", .depth = 30, .drm_id = DRM_FORMAT_XRGB2101010,
 	  .cairo_id = CAIRO_FORMAT_RGB30,
+	  .pixman_id = PIXMAN_x2r10g10b10,
 	  .num_planes = 1, .plane_bpp = { 32, },
 	},
 	{ .name = "ARGB8888", .depth = 24, .drm_id = DRM_FORMAT_ARGB8888,
 	  .cairo_id = CAIRO_FORMAT_ARGB32,
+	  .pixman_id = PIXMAN_a8r8g8b8,
 	  .num_planes = 1, .plane_bpp = { 32, },
 	},
 	{ .name = "NV12", .depth = -1, .drm_id = DRM_FORMAT_NV12,
@@ -90,6 +98,7 @@ static struct format_desc_struct {
 	},
 	{ .name = "YUYV", .depth = -1, .drm_id = DRM_FORMAT_YUYV,
 	  .cairo_id = CAIRO_FORMAT_RGB24,
+	  .pixman_id = PIXMAN_yuy2,
 	  .num_planes = 1, .plane_bpp = { 16, },
 	},
 	{ .name = "YVYU", .depth = -1, .drm_id = DRM_FORMAT_YVYU,
@@ -1178,6 +1187,18 @@ unsigned int igt_create_stereo_fb(int drm_fd, drmModeModeInfo *mode,
 	return fb_id;
 }
 
+static pixman_format_code_t drm_format_to_pixman(uint32_t drm_format)
+{
+	struct format_desc_struct *f;
+
+	for_each_format(f)
+		if (f->drm_id == drm_format)
+			return f->pixman_id;
+
+	igt_assert_f(0, "can't find a pixman format for %08x (%s)\n",
+		     drm_format, igt_format_str(drm_format));
+}
+
 static cairo_format_t drm_format_to_cairo(uint32_t drm_format)
 {
 	struct format_desc_struct *f;
@@ -1774,9 +1795,38 @@ static void convert_rgb24_to_yuyv(struct fb_convert *cvt)
 	}
 }
 
+static void convert_pixman(struct fb_convert *cvt)
+{
+	pixman_format_code_t src_pixman = drm_format_to_pixman(cvt->src.fb->drm_format);
+	pixman_format_code_t dst_pixman = drm_format_to_pixman(cvt->dst.fb->drm_format);
+	pixman_image_t *dst_image, *src_image;
+
+	igt_assert((src_pixman != PIXMAN_invalid) &&
+		   (dst_pixman != PIXMAN_invalid));
+
+	src_image = pixman_image_create_bits(src_pixman,
+					     cvt->width, cvt->height,
+					     cvt->src.ptr, cvt->src.fb->stride);
+	igt_assert(src_image);
+
+	dst_image = pixman_image_create_bits(dst_pixman,
+					     cvt->width, cvt->height,
+					     cvt->dst.ptr, cvt->dst.fb->stride);
+	igt_assert(dst_image);
+
+	pixman_image_composite(PIXMAN_OP_SRC, src_image, NULL, dst_image,
+			       0, 0, 0, 0, 0, 0, cvt->width, cvt->height);
+	pixman_image_unref(dst_image);
+	pixman_image_unref(src_image);
+}
+
 static void fb_convert(struct fb_convert *cvt)
 {
-	if (cvt->dst.fb->drm_format == DRM_FORMAT_RGB888) {
+	if ((drm_format_to_pixman(cvt->src.fb->drm_format) != PIXMAN_invalid) &&
+	    (drm_format_to_pixman(cvt->dst.fb->drm_format) != PIXMAN_invalid)) {
+		convert_pixman(cvt);
+		return;
+	} else if (cvt->dst.fb->drm_format == DRM_FORMAT_RGB888) {
 		switch (cvt->src.fb->drm_format) {
 		case DRM_FORMAT_NV12:
 			convert_nv12_to_rgb24(cvt);
@@ -2130,7 +2180,8 @@ bool igt_fb_supported_format(uint32_t drm_format)
 
 	for_each_format(f)
 		if (f->drm_id == drm_format)
-			return f->cairo_id != CAIRO_FORMAT_INVALID;
+			return (f->cairo_id != CAIRO_FORMAT_INVALID) ||
+				(f->pixman_id != PIXMAN_invalid);
 
 	return false;
 }
-- 
git-series 0.9.1
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

  parent reply	other threads:[~2018-09-11  8:47 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-11  8:47 [igt-dev] [PATCH v7 00/14] chamelium: Test the plane formats Maxime Ripard
2018-09-11  8:47 ` [igt-dev] [PATCH v7 01/14] fb: Add buffer map/unmap functions Maxime Ripard
2018-09-11  8:47 ` [igt-dev] [PATCH v7 02/14] fb: Use an igt_fb for the cairo shadow buffer Maxime Ripard
2018-09-19 13:21   ` Ville Syrjälä
2018-09-25  8:51     ` Maxime Ripard
2018-10-01 10:47       ` Arkadiusz Hiler
2018-10-01 13:55         ` Ville Syrjälä
2018-10-01 14:10           ` Arkadiusz Hiler
2018-10-02 14:56             ` Maxime Ripard
2018-09-11  8:47 ` [igt-dev] [PATCH v7 03/14] fb: convert: Remove swizzle from the arguments Maxime Ripard
2018-09-11  8:47 ` [igt-dev] [PATCH v7 04/14] fb: Create common function to convert frame formats Maxime Ripard
2018-09-19 13:03   ` Ville Syrjälä
2018-09-25  7:51     ` Maxime Ripard
2018-09-25 12:20       ` Ville Syrjälä
2018-09-11  8:47 ` [igt-dev] [PATCH v7 05/14] fb: Add format conversion routine Maxime Ripard
2018-09-11  8:47 ` [igt-dev] [PATCH v7 06/14] fb: Fix ARGB8888 color depth Maxime Ripard
2018-09-11  8:47 ` Maxime Ripard [this message]
2018-10-01  9:26   ` [igt-dev] [PATCH v7 07/14] fb: Add support for conversions through pixman Petri Latvala
2018-10-02 14:57     ` Maxime Ripard
2018-09-11  8:47 ` [igt-dev] [PATCH v7 08/14] fb: Add depth lookup function Maxime Ripard
2018-09-11  8:47 ` [igt-dev] [PATCH v7 09/14] fb: Add more formats Maxime Ripard
2018-09-19 13:14   ` Ville Syrjälä
2018-09-25  7:49     ` Maxime Ripard
2018-09-25 12:18       ` Ville Syrjälä
2018-09-11  8:47 ` [igt-dev] [PATCH v7 10/14] chamelium: Split CRC test function in two Maxime Ripard
2018-09-11  8:47 ` [igt-dev] [PATCH v7 11/14] chamelium: Change our pattern for a custom one if needed Maxime Ripard
2018-09-11  8:47 ` [igt-dev] [PATCH v7 12/14] chamelium: Add format support Maxime Ripard
2018-09-11  8:47 ` [igt-dev] [PATCH v7 13/14] chamelium: Add format subtests Maxime Ripard
2018-09-11  8:47 ` [igt-dev] [PATCH v7 14/14] tests: Add chamelium formats subtests to vc4 test lists Maxime Ripard
2018-09-12  8:12 ` [igt-dev] ✗ Fi.CI.BAT: failure for chamelium: Test the plane formats (rev6) Patchwork
2018-09-19 12:45 ` [igt-dev] [PATCH v7 00/14] chamelium: Test the plane formats Maxime Ripard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2a7b88e3a05afa4b8c8661a59a87e9d668cf5a07.1536655647.git-series.maxime.ripard@bootlin.com \
    --to=maxime.ripard@bootlin.com \
    --cc=eben@raspberrypi.org \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=paul.kocialkowski@bootlin.com \
    --cc=thomas.petazzoni@bootlin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.