Commit 41fd6f0a authored by Thomas Zimmermann's avatar Thomas Zimmermann

drm/format-helper: Implement drm_fb_swab() with per-line helpers

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: default avatarThomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: default avatarJavier Martinez Canillas <javierm@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20220427141409.22842-2-tzimmermann@suse.de
parent 1bb533b6
...@@ -100,6 +100,26 @@ void drm_fb_memcpy_toio(void __iomem *dst, unsigned int dst_pitch, const void *v ...@@ -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); 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 * drm_fb_swab - Swap bytes into clip buffer
* @dst: Destination buffer * @dst: Destination buffer
...@@ -120,12 +140,11 @@ void drm_fb_swab(void *dst, unsigned int dst_pitch, const void *src, ...@@ -120,12 +140,11 @@ void drm_fb_swab(void *dst, unsigned int dst_pitch, const void *src,
bool cached) bool cached)
{ {
u8 cpp = fb->format->cpp[0]; u8 cpp = fb->format->cpp[0];
size_t len = drm_rect_width(clip) * cpp; unsigned long linepixels = drm_rect_width(clip);
const u16 *src16; size_t len = linepixels * cpp;
const u32 *src32; const void *sbuf;
u16 *dst16; void *dbuf;
u32 *dst32; unsigned int y;
unsigned int x, y;
void *buf = NULL; void *buf = NULL;
if (WARN_ON_ONCE(cpp != 2 && cpp != 4)) 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, ...@@ -133,31 +152,22 @@ void drm_fb_swab(void *dst, unsigned int dst_pitch, const void *src,
if (!dst_pitch) if (!dst_pitch)
dst_pitch = len; dst_pitch = len;
src += clip_offset(clip, fb->pitches[0], cpp);
if (!cached) if (!cached)
buf = kmalloc(len, GFP_KERNEL); buf = kmalloc(len, GFP_KERNEL);
src += clip_offset(clip, fb->pitches[0], cpp);
for (y = clip->y1; y < clip->y2; y++) { for (y = clip->y1; y < clip->y2; y++) {
if (buf) { if (buf)
memcpy(buf, src, len); sbuf = memcpy(buf, src, len);
src16 = buf; else
src32 = buf; sbuf = src;
} else { dbuf = dst + clip->x1 * cpp;
src16 = src;
src32 = src;
}
dst16 = dst;
dst32 = dst;
for (x = clip->x1; x < clip->x2; x++) { if (cpp == 4)
if (cpp == 4) drm_fb_swab32_line(dbuf, sbuf, linepixels);
*dst32++ = swab32(*src32++); else
else drm_fb_swab16_line(dbuf, sbuf, linepixels);
*dst16++ = swab16(*src16++);
}
src += fb->pitches[0]; src += fb->pitches[0];
dst += dst_pitch; dst += dst_pitch;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment