[igt-dev] [PATCH i-g-t 1/2] lib/igt_fb: Add cairo conversion to igt_fb_convert_with_stride.

Maarten Lankhorst maarten.lankhorst at linux.intel.com
Tue Apr 2 19:12:46 UTC 2019


fb_convert() cannot convert to the HDR formats, so we need a fallback.
When cairo is available on source and target format, create a surface
for source and target. This way we can convert framebuffers directly
when no direct conversion using fb_convert() is available.

This is required to make the kms_chamelium.*-cmp-planes-random tests
pass.

Signed-off-by: Maarten Lankhorst <maarten.lankhorst at linux.intel.com>
---
 lib/igt_fb.c | 87 ++++++++++++++++++++++++++++++++--------------------
 1 file changed, 53 insertions(+), 34 deletions(-)

diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index 6adf422228e8..8319c4d5b227 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -2976,53 +2976,72 @@ unsigned int igt_fb_convert_with_stride(struct igt_fb *dst, struct igt_fb *src,
 	void *dst_ptr, *src_ptr;
 	uint64_t base_modifier;
 	int fb_id;
+	const struct format_desc_struct *src_format = lookup_drm_format(src->drm_format);
+	const struct format_desc_struct *dst_format = lookup_drm_format(dst_fourcc);
 
 	if (is_vc4_device(src->fd))
 		base_modifier = fourcc_mod_broadcom_mod(dst_modifier);
 	else
 		base_modifier = dst_modifier;
 
-	fb_id = igt_create_fb_with_bo_size(src->fd, src->width, src->height,
-					   dst_fourcc,
-					   LOCAL_DRM_FORMAT_MOD_NONE, &linear,
-					   0, dst_stride);
-	igt_assert(fb_id > 0);
+	if (src_format->cairo_id == CAIRO_FORMAT_INVALID ||
+	    dst_format->cairo_id == CAIRO_FORMAT_INVALID) {
+		fb_id = igt_create_fb_with_bo_size(src->fd, src->width, src->height,
+						dst_fourcc,
+						LOCAL_DRM_FORMAT_MOD_NONE, &linear,
+						0, dst_stride);
+		igt_assert(fb_id > 0);
 
-	src_ptr = igt_fb_map_buffer(src->fd, src);
-	igt_assert(src_ptr);
+		src_ptr = igt_fb_map_buffer(src->fd, src);
+		igt_assert(src_ptr);
 
-	dst_ptr = igt_fb_map_buffer(linear.fd, &linear);
-	igt_assert(dst_ptr);
+		dst_ptr = igt_fb_map_buffer(linear.fd, &linear);
+		igt_assert(dst_ptr);
 
-	cvt.dst.ptr = dst_ptr;
-	cvt.dst.fb = &linear;
-	cvt.src.ptr = src_ptr;
-	cvt.src.fb = src;
-	fb_convert(&cvt);
+		cvt.dst.ptr = dst_ptr;
+		cvt.dst.fb = &linear;
+		cvt.src.ptr = src_ptr;
+		cvt.src.fb = src;
+		fb_convert(&cvt);
 
-	igt_fb_unmap_buffer(dst, dst_ptr);
-	igt_fb_unmap_buffer(src, src_ptr);
+		igt_fb_unmap_buffer(dst, dst_ptr);
+		igt_fb_unmap_buffer(src, src_ptr);
 
-	switch (base_modifier) {
-	case DRM_FORMAT_MOD_BROADCOM_VC4_T_TILED:
-		fb_id = igt_vc4_fb_t_tiled_convert(dst, &linear);
-		break;
-	case DRM_FORMAT_MOD_BROADCOM_SAND32:
-	case DRM_FORMAT_MOD_BROADCOM_SAND64:
-	case DRM_FORMAT_MOD_BROADCOM_SAND128:
-	case DRM_FORMAT_MOD_BROADCOM_SAND256:
-		fb_id = vc4_fb_sand_tiled_convert(dst, &linear, dst_modifier);
-		break;
-	default:
-		igt_assert(dst_modifier == LOCAL_DRM_FORMAT_MOD_NONE);
-	}
+		switch (base_modifier) {
+		case DRM_FORMAT_MOD_BROADCOM_VC4_T_TILED:
+			fb_id = igt_vc4_fb_t_tiled_convert(dst, &linear);
+			break;
+		case DRM_FORMAT_MOD_BROADCOM_SAND32:
+		case DRM_FORMAT_MOD_BROADCOM_SAND64:
+		case DRM_FORMAT_MOD_BROADCOM_SAND128:
+		case DRM_FORMAT_MOD_BROADCOM_SAND256:
+			fb_id = vc4_fb_sand_tiled_convert(dst, &linear, dst_modifier);
+			break;
+		default:
+			igt_assert(dst_modifier == LOCAL_DRM_FORMAT_MOD_NONE);
+		}
 
-	igt_assert(fb_id > 0);
+		igt_assert(fb_id > 0);
 
-	if (dst_modifier == LOCAL_DRM_FORMAT_MOD_NONE)
-		*dst = linear;
-	else
-		igt_remove_fb(linear.fd, &linear);
+		if (dst_modifier == LOCAL_DRM_FORMAT_MOD_NONE)
+			*dst = linear;
+		else
+			igt_remove_fb(linear.fd, &linear);
+	} else {
+		/* Use the cairo api to convert */
+		cairo_surface_t *surf = igt_get_cairo_surface(src->fd, src);
+		cairo_t *cr;
+
+		igt_create_fb_with_bo_size(src->fd, src->width, src->height, dst_fourcc,
+					   dst_modifier, dst, 0, dst_stride);
+
+		cr = igt_get_cairo_ctx(dst->fd, dst);
+		cairo_set_source_surface(cr, surf, 0, 0);
+		cairo_paint(cr);
+		igt_put_cairo_ctx(dst->fd, dst, cr);
+
+		cairo_surface_destroy(surf);
+	}
 
 	return fb_id;
 }
-- 
2.20.1



More information about the igt-dev mailing list