[igt-dev] [PATCH v4 05/13] fb: Add support for conversions through pixman
Maxime Ripard
maxime.ripard at bootlin.com
Thu Jul 26 10:42:04 UTC 2018
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.
Signed-off-by: Maxime Ripard <maxime.ripard at 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 9aee02c35c16..9defbd8b044c 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 = 32, .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,
@@ -1175,6 +1184,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;
@@ -1772,9 +1793,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.fmt);
+ pixman_format_code_t dst_pixman = drm_format_to_pixman(cvt->dst.fmt);
+ 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.stride);
+ igt_assert(src_image);
+
+ dst_image = pixman_image_create_bits(dst_pixman,
+ cvt->width, cvt->height,
+ cvt->dst.ptr, cvt->dst.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.fmt == DRM_FORMAT_RGB888) {
+ if ((drm_format_to_pixman(cvt->src.fmt) != PIXMAN_invalid) &&
+ (drm_format_to_pixman(cvt->dst.fmt) != PIXMAN_invalid)) {
+ convert_pixman(cvt);
+ return;
+ } else if (cvt->dst.fmt == DRM_FORMAT_RGB888) {
switch (cvt->src.fmt) {
case DRM_FORMAT_NV12:
convert_nv12_to_rgb24(cvt);
@@ -2155,7 +2205,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
More information about the igt-dev
mailing list