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 2/4] drm/format-helper: Remove optional byte-swap from line convertion
Date: Wed, 27 Apr 2022 16:14:07 +0200	[thread overview]
Message-ID: <20220427141409.22842-3-tzimmermann@suse.de> (raw)
In-Reply-To: <20220427141409.22842-1-tzimmermann@suse.de>

Implement per-pixel byte swapping in a separate conversion helper
for the single function that requires it. Select the correct helper
for each conversion.

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

diff --git a/drivers/gpu/drm/drm_format_helper.c b/drivers/gpu/drm/drm_format_helper.c
index f70499344a04..b7daa40fc856 100644
--- a/drivers/gpu/drm/drm_format_helper.c
+++ b/drivers/gpu/drm/drm_format_helper.c
@@ -229,8 +229,7 @@ void drm_fb_xrgb8888_to_rgb332(void *dst, unsigned int dst_pitch, const void *sr
 EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgb332);
 
 static void drm_fb_xrgb8888_to_rgb565_line(u16 *dbuf, const u32 *sbuf,
-					   unsigned int pixels,
-					   bool swab)
+					   unsigned int pixels)
 {
 	unsigned int x;
 	u16 val16;
@@ -239,10 +238,21 @@ static void drm_fb_xrgb8888_to_rgb565_line(u16 *dbuf, const u32 *sbuf,
 		val16 = ((sbuf[x] & 0x00F80000) >> 8) |
 			((sbuf[x] & 0x0000FC00) >> 5) |
 			((sbuf[x] & 0x000000F8) >> 3);
-		if (swab)
-			dbuf[x] = swab16(val16);
-		else
-			dbuf[x] = val16;
+		dbuf[x] = val16;
+	}
+}
+
+static void drm_fb_xrgb8888_to_rgb565_swab_line(u16 *dbuf, const u32 *sbuf,
+						unsigned int pixels)
+{
+	unsigned int x;
+	u16 val16;
+
+	for (x = 0; x < pixels; x++) {
+		val16 = ((sbuf[x] & 0x00F80000) >> 8) |
+			((sbuf[x] & 0x0000FC00) >> 5) |
+			((sbuf[x] & 0x000000F8) >> 3);
+		dbuf[x] = swab16(val16);
 	}
 }
 
@@ -282,7 +292,10 @@ void drm_fb_xrgb8888_to_rgb565(void *dst, unsigned int dst_pitch, const void *va
 	vaddr += clip_offset(clip, fb->pitches[0], sizeof(u32));
 	for (y = 0; y < lines; y++) {
 		memcpy(sbuf, vaddr, src_len);
-		drm_fb_xrgb8888_to_rgb565_line(dst, sbuf, linepixels, swab);
+		if (swab)
+			drm_fb_xrgb8888_to_rgb565_swab_line(dst, sbuf, linepixels);
+		else
+			drm_fb_xrgb8888_to_rgb565_line(dst, sbuf, linepixels);
 		vaddr += fb->pitches[0];
 		dst += dst_pitch;
 	}
@@ -321,7 +334,10 @@ void drm_fb_xrgb8888_to_rgb565_toio(void __iomem *dst, unsigned int dst_pitch,
 
 	vaddr += clip_offset(clip, fb->pitches[0], sizeof(u32));
 	for (y = 0; y < lines; y++) {
-		drm_fb_xrgb8888_to_rgb565_line(dbuf, vaddr, linepixels, swab);
+		if (swab)
+			drm_fb_xrgb8888_to_rgb565_swab_line(dbuf, vaddr, linepixels);
+		else
+			drm_fb_xrgb8888_to_rgb565_line(dbuf, vaddr, linepixels);
 		memcpy_toio(dst, dbuf, dst_len);
 		vaddr += fb->pitches[0];
 		dst += dst_pitch;
-- 
2.36.0


  parent 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 ` [PATCH 1/4] drm/format-helper: Implement drm_fb_swab() with per-line helpers Thomas Zimmermann
2022-05-03  7:48   ` Javier Martinez Canillas
2022-05-03  8:02     ` Thomas Zimmermann
2022-04-27 14:14 ` Thomas Zimmermann [this message]
2022-05-03  8:02   ` [PATCH 2/4] drm/format-helper: Remove optional byte-swap from line convertion 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-3-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