All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ville Syrjala <ville.syrjala@linux.intel.com>
To: igt-dev@lists.freedesktop.org
Subject: [igt-dev] [PATCH i-g-t 3/8] lib: Clean up format_desc
Date: Wed, 23 May 2018 21:31:05 +0300	[thread overview]
Message-ID: <20180523183110.1975-3-ville.syrjala@linux.intel.com> (raw)
In-Reply-To: <20180523183110.1975-1-ville.syrjala@linux.intel.com>

From: Ville Syrjälä <ville.syrjala@linux.intel.com>

Always populate the plane_bpp[] stuff, and use named initializers so
that we can actually see what's being set to what.

v2: Fix depth for xrgb8888

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 lib/igt_fb.c | 66 +++++++++++++++++++++++++++++++++---------------------------
 1 file changed, 36 insertions(+), 30 deletions(-)

diff --git a/lib/igt_fb.c b/lib/igt_fb.c
index c89f7850ed70..9edee74b57c3 100644
--- a/lib/igt_fb.c
+++ b/lib/igt_fb.c
@@ -57,26 +57,35 @@
  */
 
 /* drm fourcc/cairo format maps */
-#define DF(did, cid, ...)	\
-	{ DRM_FORMAT_##did, CAIRO_FORMAT_##cid, # did, __VA_ARGS__ }
 static struct format_desc_struct {
+	const char *name;
 	uint32_t drm_id;
 	cairo_format_t cairo_id;
-	const char *name;
-	int bpp;
 	int depth;
-	int planes;
+	int num_planes;
 	int plane_bpp[4];
 } format_desc[] = {
-	DF(RGB565,	RGB16_565,	16, 16),
-	//DF(RGB888,	INVALID,	24, 24),
-	DF(XRGB8888,	RGB24,		32, 24),
-	DF(XRGB2101010,	RGB30,		32, 30),
-	DF(ARGB8888,	ARGB32,		32, 32),
-	DF(NV12,	RGB24,		32, -1, 2, {8, 16}),
+	{ .name = "RGB565", .depth = 16, .drm_id = DRM_FORMAT_RGB565,
+	  .cairo_id = CAIRO_FORMAT_RGB16_565,
+	  .num_planes = 1, .plane_bpp = { 16, },
+	},
+	{ .name = "XRGB8888", .depth = 24, .drm_id = DRM_FORMAT_XRGB8888,
+	  .cairo_id = CAIRO_FORMAT_RGB24,
+	  .num_planes = 1, .plane_bpp = { 32, },
+	},
+	{ .name = "XRGB2101010", .depth = 30, .drm_id = DRM_FORMAT_XRGB2101010,
+	  .cairo_id = CAIRO_FORMAT_RGB30,
+	  .num_planes = 1, .plane_bpp = { 32, },
+	},
+	{ .name = "ARGB8888", .depth = 32, .drm_id = DRM_FORMAT_ARGB8888,
+	  .cairo_id = CAIRO_FORMAT_ARGB32,
+	  .num_planes = 1, .plane_bpp = { 32, },
+	},
+	{ .name = "NV12", .depth = -1, .drm_id = DRM_FORMAT_NV12,
+	  .cairo_id = CAIRO_FORMAT_RGB24,
+	  .num_planes = 2, .plane_bpp = { 8, 16, },
+	},
 };
-#undef DF
-
 #define for_each_format(f)	\
 	for (f = format_desc; f - format_desc < ARRAY_SIZE(format_desc); f++)
 
@@ -195,7 +204,7 @@ static void calc_fb_size_planar(int fd, int width, int height,
 
 	*size_ret = 0;
 
-	for (plane = 0; plane < format->planes; plane++) {
+	for (plane = 0; plane < format->num_planes; plane++) {
 		unsigned plane_stride;
 
 		igt_get_fb_tile_size(fd, tiling, format->plane_bpp[plane], &tile_width, &tile_height);
@@ -205,7 +214,7 @@ static void calc_fb_size_planar(int fd, int width, int height,
 			stride = plane_stride;
 	}
 
-	for (plane = 0; plane < format->planes; plane++) {
+	for (plane = 0; plane < format->num_planes; plane++) {
 		if (offsets)
 			offsets[plane] = *size_ret;
 
@@ -226,9 +235,9 @@ static void calc_fb_size_packed(int fd, int width, int height,
 				unsigned *size_ret, unsigned *stride_ret)
 {
 	unsigned int tile_width, tile_height, stride, size;
-	int byte_width = width * (format->bpp / 8);
+	int byte_width = width * (format->plane_bpp[0] / 8);
 
-	igt_get_fb_tile_size(fd, tiling, format->bpp, &tile_width, &tile_height);
+	igt_get_fb_tile_size(fd, tiling, format->plane_bpp[0], &tile_width, &tile_height);
 
 	if (tiling != LOCAL_DRM_FORMAT_MOD_NONE &&
 	    intel_gen(intel_get_drm_devid(fd)) <= 3) {
@@ -277,7 +286,7 @@ void igt_calc_fb_size(int fd, int width, int height, uint32_t drm_format, uint64
 	struct format_desc_struct *format = lookup_drm_format(drm_format);
 	igt_assert(format);
 
-	if (format->planes > 1)
+	if (format->num_planes > 1)
 		calc_fb_size_planar(fd, width, height, format, tiling, size_ret, stride_ret, NULL);
 	else
 		calc_fb_size_packed(fd, width, height, format, tiling, size_ret, stride_ret);
@@ -362,7 +371,7 @@ static int create_bo_for_fb(int fd, int width, int height,
 	if (tiling || size || stride || igt_format_is_yuv(format->drm_id)) {
 		unsigned calculated_size, calculated_stride;
 
-		if (format->planes > 1)
+		if (format->num_planes > 1)
 			calc_fb_size_planar(fd, width, height, format, tiling,
 					    &calculated_size, &calculated_stride, offsets);
 		else
@@ -425,8 +434,9 @@ static int create_bo_for_fb(int fd, int width, int height,
 		if (is_dumb)
 			*is_dumb = true;
 
-		return kmstest_dumb_create(fd, width, height, format->bpp, stride_ret,
-					   size_ret);
+		return kmstest_dumb_create(fd, width, height,
+					   format->plane_bpp[0],
+					   stride_ret, size_ret);
 	}
 }
 
@@ -828,7 +838,7 @@ igt_create_fb_with_bo_size(int fd, int width, int height,
 
 		handles[0] = fb->gem_handle;
 		pitches[0] = fb->stride;
-		for (i = 0; i < f->planes; i++) {
+		for (i = 0; i < f->num_planes; i++) {
 			handles[i] = fb->gem_handle;
 			pitches[i] = fb->stride;
 		}
@@ -844,13 +854,9 @@ igt_create_fb_with_bo_size(int fd, int width, int height,
 	fb->drm_format = format;
 	fb->fb_id = fb_id;
 	fb->fd = fd;
-	fb->num_planes = f->planes ?: 1;
-	fb->plane_bpp[0] = f->bpp;
-	fb->plane_height[0] = height;
-	fb->plane_width[0] = width;
+	fb->num_planes = f->num_planes;
 
-	/* if f->planes is set, then plane_bpp is valid too so use that. */
-	for (i = 0; i < f->planes; i++) {
+	for (i = 0; i < f->num_planes; i++) {
 		fb->plane_bpp[i] = f->plane_bpp[i];
 		fb->plane_height[i] = planar_height(f, height, i);
 		fb->plane_width[i] = planar_width(f, width, i);
@@ -1669,7 +1675,7 @@ uint32_t igt_bpp_depth_to_drm_format(int bpp, int depth)
 	struct format_desc_struct *f;
 
 	for_each_format(f)
-		if (f->bpp == bpp && f->depth == depth)
+		if (f->plane_bpp[0] == bpp && f->depth == depth)
 			return f->drm_id;
 
 
@@ -1692,7 +1698,7 @@ uint32_t igt_drm_format_to_bpp(uint32_t drm_format)
 	igt_assert_f(f, "can't find a bpp format for %08x (%s)\n",
 		     drm_format, igt_format_str(drm_format));
 
-	return f->bpp;
+	return f->plane_bpp[0];
 }
 
 /**
-- 
2.16.1

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

  parent reply	other threads:[~2018-05-23 18:31 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-23 18:31 [igt-dev] [PATCH i-g-t 1/8] lib: Clear packed YUV formats to black Ville Syrjala
2018-05-23 18:31 ` [igt-dev] [PATCH i-g-t 2/8] lib: Don't use dumb buffers for YCbCr Ville Syrjala
2018-06-05  9:51   ` Maarten Lankhorst
2018-05-23 18:31 ` Ville Syrjala [this message]
2018-05-23 18:31 ` [igt-dev] [PATCH i-g-t 4/8] lib: Use igt_matrix for ycbcr<->rgb conversion Ville Syrjala
2018-06-06 10:11   ` Maarten Lankhorst
2018-05-23 18:31 ` [igt-dev] [PATCH i-g-t 5/8] lib: Add support for rendering into packed YCbCr framebuffers Ville Syrjala
2018-05-23 18:31 ` [igt-dev] [PATCH i-g-t 6/8] lib/fb: Add color_encoding/color_range to igt_fb Ville Syrjala
2018-05-23 18:31 ` [igt-dev] [PATCH i-g-t 7/8] lib/kms: Respect fb color_encoding/color_range Ville Syrjala
2018-05-23 18:31 ` [igt-dev] [PATCH i-g-t 8/8] tests/kms_plane: crc check plane pixel formats Ville Syrjala
2018-05-24 10:48   ` [igt-dev] [PATCH i-g-t v2 " Ville Syrjala
2018-06-07 15:18     ` Maarten Lankhorst
2018-05-23 19:09 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [i-g-t,1/8] lib: Clear packed YUV formats to black Patchwork
2018-05-23 23:27 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork
2018-05-24 17:15 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [i-g-t,1/8] lib: Clear packed YUV formats to black (rev2) Patchwork
2018-05-24 23:05 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork
2018-06-05  9:42 ` [igt-dev] [PATCH i-g-t 1/8] lib: Clear packed YUV formats to black Maarten Lankhorst
2018-06-05 10:13   ` Ville Syrjälä
2018-06-05 10:33     ` Maarten Lankhorst

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=20180523183110.1975-3-ville.syrjala@linux.intel.com \
    --to=ville.syrjala@linux.intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    /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.