dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Zimmermann <tzimmermann@suse.de>
To: javierm@redhat.com, maarten.lankhorst@linux.intel.com,
	mripard@kernel.org, airlied@linux.ie, daniel@ffwll.ch
Cc: Thomas Zimmermann <tzimmermann@suse.de>, dri-devel@lists.freedesktop.org
Subject: [PATCH 1/4] drm/format-helper: Implement drm_fb_swab() with per-line helpers
Date: Wed, 27 Apr 2022 16:14:06 +0200	[thread overview]
Message-ID: <20220427141409.22842-2-tzimmermann@suse.de> (raw)
In-Reply-To: <20220427141409.22842-1-tzimmermann@suse.de>

Replace the inner loop of drm_fb_swab() with helper functions that
swap the bytes in each pixel. This will allow to share the outer
loop with other conversion helpers.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/gpu/drm/drm_format_helper.c | 60 +++++++++++++++++------------
 1 file changed, 35 insertions(+), 25 deletions(-)

diff --git a/drivers/gpu/drm/drm_format_helper.c b/drivers/gpu/drm/drm_format_helper.c
index 34b7ef443ad2..f70499344a04 100644
--- a/drivers/gpu/drm/drm_format_helper.c
+++ b/drivers/gpu/drm/drm_format_helper.c
@@ -100,6 +100,26 @@ void drm_fb_memcpy_toio(void __iomem *dst, unsigned int dst_pitch, const void *v
 }
 EXPORT_SYMBOL(drm_fb_memcpy_toio);
 
+static void drm_fb_swab16_line(void *dbuf, const void *sbuf, unsigned int pixels)
+{
+	u16 *dbuf16 = dbuf;
+	const u16 *sbuf16 = sbuf;
+	const u16 *send16 = sbuf16 + pixels;
+
+	while (sbuf16 < send16)
+		*dbuf16++ = swab16(*sbuf16++);
+}
+
+static void drm_fb_swab32_line(void *dbuf, const void *sbuf, unsigned int pixels)
+{
+	u32 *dbuf32 = dbuf;
+	const u32 *sbuf32 = sbuf;
+	const u32 *send32 = sbuf32 + pixels;
+
+	while (sbuf32 < send32)
+		*dbuf32++ = swab32(*sbuf32++);
+}
+
 /**
  * drm_fb_swab - Swap bytes into clip buffer
  * @dst: Destination buffer
@@ -120,12 +140,11 @@ void drm_fb_swab(void *dst, unsigned int dst_pitch, const void *src,
 		 bool cached)
 {
 	u8 cpp = fb->format->cpp[0];
-	size_t len = drm_rect_width(clip) * cpp;
-	const u16 *src16;
-	const u32 *src32;
-	u16 *dst16;
-	u32 *dst32;
-	unsigned int x, y;
+	unsigned long linepixels = drm_rect_width(clip);
+	size_t len = linepixels * cpp;
+	const void *sbuf;
+	void *dbuf;
+	unsigned int y;
 	void *buf = NULL;
 
 	if (WARN_ON_ONCE(cpp != 2 && cpp != 4))
@@ -133,31 +152,22 @@ void drm_fb_swab(void *dst, unsigned int dst_pitch, const void *src,
 
 	if (!dst_pitch)
 		dst_pitch = len;
+	src += clip_offset(clip, fb->pitches[0], cpp);
 
 	if (!cached)
 		buf = kmalloc(len, GFP_KERNEL);
 
-	src += clip_offset(clip, fb->pitches[0], cpp);
-
 	for (y = clip->y1; y < clip->y2; y++) {
-		if (buf) {
-			memcpy(buf, src, len);
-			src16 = buf;
-			src32 = buf;
-		} else {
-			src16 = src;
-			src32 = src;
-		}
-
-		dst16 = dst;
-		dst32 = dst;
+		if (buf)
+			sbuf = memcpy(buf, src, len);
+		else
+			sbuf = src;
+		dbuf = dst + clip->x1 * cpp;
 
-		for (x = clip->x1; x < clip->x2; x++) {
-			if (cpp == 4)
-				*dst32++ = swab32(*src32++);
-			else
-				*dst16++ = swab16(*src16++);
-		}
+		if (cpp == 4)
+			drm_fb_swab32_line(dbuf, sbuf, linepixels);
+		else
+			drm_fb_swab16_line(dbuf, sbuf, linepixels);
 
 		src += fb->pitches[0];
 		dst += dst_pitch;
-- 
2.36.0


  reply	other threads:[~2022-04-27 14:14 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-27 14:14 [PATCH 0/4] drm/format-helper: Share common code among conversion helpers Thomas Zimmermann
2022-04-27 14:14 ` Thomas Zimmermann [this message]
2022-05-03  7:48   ` [PATCH 1/4] drm/format-helper: Implement drm_fb_swab() with per-line helpers Javier Martinez Canillas
2022-05-03  8:02     ` Thomas Zimmermann
2022-04-27 14:14 ` [PATCH 2/4] drm/format-helper: Remove optional byte-swap from line convertion Thomas Zimmermann
2022-05-03  8:02   ` Javier Martinez Canillas
2022-04-27 14:14 ` [PATCH 3/4] drm/format-helper: Unify the parameters of all per-line conversion helpers Thomas Zimmermann
2022-05-03  8:06   ` Javier Martinez Canillas
2022-04-27 14:14 ` [PATCH 4/4] drm/format-helper: Share implementation among " Thomas Zimmermann
2022-05-03  8:12   ` Javier Martinez Canillas

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=20220427141409.22842-2-tzimmermann@suse.de \
    --to=tzimmermann@suse.de \
    --cc=airlied@linux.ie \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=javierm@redhat.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox