2020-02-16 02:09:11 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0 or MIT
|
2019-04-05 17:52:15 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2016 Noralf Trønnes
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/slab.h>
|
2019-04-10 14:38:13 +08:00
|
|
|
#include <linux/io.h>
|
2019-04-05 17:52:15 +08:00
|
|
|
|
2022-02-14 21:37:06 +08:00
|
|
|
#include <drm/drm_device.h>
|
2019-04-05 17:52:15 +08:00
|
|
|
#include <drm/drm_format_helper.h>
|
|
|
|
#include <drm/drm_framebuffer.h>
|
|
|
|
#include <drm/drm_fourcc.h>
|
2022-02-14 21:37:06 +08:00
|
|
|
#include <drm/drm_print.h>
|
2019-04-05 17:52:15 +08:00
|
|
|
#include <drm/drm_rect.h>
|
|
|
|
|
2021-11-10 18:36:54 +08:00
|
|
|
static unsigned int clip_offset(const struct drm_rect *clip, unsigned int pitch, unsigned int cpp)
|
2019-04-05 17:52:16 +08:00
|
|
|
{
|
2019-04-10 14:38:13 +08:00
|
|
|
return clip->y1 * pitch + clip->x1 * cpp;
|
2019-04-05 17:52:16 +08:00
|
|
|
}
|
|
|
|
|
2021-11-10 18:36:54 +08:00
|
|
|
/**
|
|
|
|
* drm_fb_clip_offset - Returns the clipping rectangles byte-offset in a framebuffer
|
|
|
|
* @pitch: Framebuffer line pitch in byte
|
|
|
|
* @format: Framebuffer format
|
|
|
|
* @clip: Clip rectangle
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* The byte offset of the clip rectangle's top-left corner within the framebuffer.
|
|
|
|
*/
|
|
|
|
unsigned int drm_fb_clip_offset(unsigned int pitch, const struct drm_format_info *format,
|
|
|
|
const struct drm_rect *clip)
|
|
|
|
{
|
|
|
|
return clip_offset(clip, pitch, format->cpp[0]);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_fb_clip_offset);
|
|
|
|
|
2019-04-05 17:52:15 +08:00
|
|
|
/**
|
|
|
|
* drm_fb_memcpy - Copy clip buffer
|
|
|
|
* @dst: Destination buffer
|
2021-11-10 18:36:55 +08:00
|
|
|
* @dst_pitch: Number of bytes between two consecutive scanlines within dst
|
2019-04-05 17:52:15 +08:00
|
|
|
* @vaddr: Source buffer
|
|
|
|
* @fb: DRM framebuffer
|
|
|
|
* @clip: Clip rectangle area to copy
|
2019-04-05 17:52:16 +08:00
|
|
|
*
|
|
|
|
* This function does not apply clipping on dst, i.e. the destination
|
2021-11-10 18:36:55 +08:00
|
|
|
* is at the top-left corner.
|
2019-04-05 17:52:15 +08:00
|
|
|
*/
|
2021-11-10 18:36:55 +08:00
|
|
|
void drm_fb_memcpy(void *dst, unsigned int dst_pitch, const void *vaddr,
|
|
|
|
const struct drm_framebuffer *fb, const struct drm_rect *clip)
|
2019-04-05 17:52:15 +08:00
|
|
|
{
|
2019-05-16 18:31:52 +08:00
|
|
|
unsigned int cpp = fb->format->cpp[0];
|
2019-04-05 17:52:15 +08:00
|
|
|
size_t len = (clip->x2 - clip->x1) * cpp;
|
2019-04-10 14:38:13 +08:00
|
|
|
unsigned int y, lines = clip->y2 - clip->y1;
|
2019-04-05 17:52:15 +08:00
|
|
|
|
2021-11-10 18:36:55 +08:00
|
|
|
if (!dst_pitch)
|
|
|
|
dst_pitch = len;
|
|
|
|
|
2019-04-10 14:38:13 +08:00
|
|
|
vaddr += clip_offset(clip, fb->pitches[0], cpp);
|
|
|
|
for (y = 0; y < lines; y++) {
|
|
|
|
memcpy(dst, vaddr, len);
|
|
|
|
vaddr += fb->pitches[0];
|
2021-11-10 18:36:55 +08:00
|
|
|
dst += dst_pitch;
|
2019-04-10 14:38:13 +08:00
|
|
|
}
|
2019-04-05 17:52:15 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_fb_memcpy);
|
|
|
|
|
2019-04-05 17:52:16 +08:00
|
|
|
/**
|
2021-11-10 18:36:55 +08:00
|
|
|
* drm_fb_memcpy_toio - Copy clip buffer
|
2019-04-10 14:38:13 +08:00
|
|
|
* @dst: Destination buffer (iomem)
|
2021-04-30 18:58:32 +08:00
|
|
|
* @dst_pitch: Number of bytes between two consecutive scanlines within dst
|
2019-04-05 17:52:16 +08:00
|
|
|
* @vaddr: Source buffer
|
|
|
|
* @fb: DRM framebuffer
|
|
|
|
* @clip: Clip rectangle area to copy
|
|
|
|
*
|
2021-11-10 18:36:55 +08:00
|
|
|
* This function does not apply clipping on dst, i.e. the destination
|
|
|
|
* is at the top-left corner.
|
2019-04-05 17:52:16 +08:00
|
|
|
*/
|
2021-11-10 18:36:55 +08:00
|
|
|
void drm_fb_memcpy_toio(void __iomem *dst, unsigned int dst_pitch, const void *vaddr,
|
|
|
|
const struct drm_framebuffer *fb, const struct drm_rect *clip)
|
2019-04-05 17:52:16 +08:00
|
|
|
{
|
2019-05-16 18:31:52 +08:00
|
|
|
unsigned int cpp = fb->format->cpp[0];
|
2019-04-05 17:52:16 +08:00
|
|
|
size_t len = (clip->x2 - clip->x1) * cpp;
|
2019-04-10 14:38:13 +08:00
|
|
|
unsigned int y, lines = clip->y2 - clip->y1;
|
2019-04-05 17:52:16 +08:00
|
|
|
|
2021-11-10 18:36:55 +08:00
|
|
|
if (!dst_pitch)
|
|
|
|
dst_pitch = len;
|
|
|
|
|
|
|
|
vaddr += clip_offset(clip, fb->pitches[0], cpp);
|
2019-04-10 14:38:13 +08:00
|
|
|
for (y = 0; y < lines; y++) {
|
|
|
|
memcpy_toio(dst, vaddr, len);
|
|
|
|
vaddr += fb->pitches[0];
|
2021-04-30 18:58:32 +08:00
|
|
|
dst += dst_pitch;
|
2019-04-10 14:38:13 +08:00
|
|
|
}
|
2019-04-05 17:52:16 +08:00
|
|
|
}
|
2021-11-10 18:36:55 +08:00
|
|
|
EXPORT_SYMBOL(drm_fb_memcpy_toio);
|
2019-04-05 17:52:16 +08:00
|
|
|
|
2022-04-27 22:14:06 +08:00
|
|
|
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++);
|
|
|
|
}
|
|
|
|
|
2019-04-05 17:52:15 +08:00
|
|
|
/**
|
2020-05-09 22:16:16 +08:00
|
|
|
* drm_fb_swab - Swap bytes into clip buffer
|
|
|
|
* @dst: Destination buffer
|
2021-11-10 18:36:56 +08:00
|
|
|
* @dst_pitch: Number of bytes between two consecutive scanlines within dst
|
2020-05-09 22:16:16 +08:00
|
|
|
* @src: Source buffer
|
2019-04-05 17:52:15 +08:00
|
|
|
* @fb: DRM framebuffer
|
|
|
|
* @clip: Clip rectangle area to copy
|
2020-05-09 22:16:16 +08:00
|
|
|
* @cached: Source buffer is mapped cached (eg. not write-combined)
|
|
|
|
*
|
|
|
|
* If @cached is false a temporary buffer is used to cache one pixel line at a
|
|
|
|
* time to speed up slow uncached reads.
|
|
|
|
*
|
|
|
|
* This function does not apply clipping on dst, i.e. the destination
|
2021-11-10 18:36:56 +08:00
|
|
|
* is at the top-left corner.
|
2019-04-05 17:52:15 +08:00
|
|
|
*/
|
2021-11-10 18:36:56 +08:00
|
|
|
void drm_fb_swab(void *dst, unsigned int dst_pitch, const void *src,
|
|
|
|
const struct drm_framebuffer *fb, const struct drm_rect *clip,
|
|
|
|
bool cached)
|
2019-04-05 17:52:15 +08:00
|
|
|
{
|
2020-05-09 22:16:16 +08:00
|
|
|
u8 cpp = fb->format->cpp[0];
|
2022-04-27 22:14:06 +08:00
|
|
|
unsigned long linepixels = drm_rect_width(clip);
|
|
|
|
size_t len = linepixels * cpp;
|
|
|
|
const void *sbuf;
|
|
|
|
void *dbuf;
|
|
|
|
unsigned int y;
|
2020-05-09 22:16:16 +08:00
|
|
|
void *buf = NULL;
|
|
|
|
|
|
|
|
if (WARN_ON_ONCE(cpp != 2 && cpp != 4))
|
2019-04-05 17:52:15 +08:00
|
|
|
return;
|
|
|
|
|
2021-11-10 18:36:56 +08:00
|
|
|
if (!dst_pitch)
|
|
|
|
dst_pitch = len;
|
2022-04-27 22:14:06 +08:00
|
|
|
src += clip_offset(clip, fb->pitches[0], cpp);
|
2021-11-10 18:36:56 +08:00
|
|
|
|
2020-05-09 22:16:16 +08:00
|
|
|
if (!cached)
|
|
|
|
buf = kmalloc(len, GFP_KERNEL);
|
|
|
|
|
2019-04-05 17:52:15 +08:00
|
|
|
for (y = clip->y1; y < clip->y2; y++) {
|
2022-04-27 22:14:06 +08:00
|
|
|
if (buf)
|
|
|
|
sbuf = memcpy(buf, src, len);
|
|
|
|
else
|
|
|
|
sbuf = src;
|
|
|
|
dbuf = dst + clip->x1 * cpp;
|
|
|
|
|
|
|
|
if (cpp == 4)
|
|
|
|
drm_fb_swab32_line(dbuf, sbuf, linepixels);
|
|
|
|
else
|
|
|
|
drm_fb_swab16_line(dbuf, sbuf, linepixels);
|
2020-05-09 22:16:16 +08:00
|
|
|
|
|
|
|
src += fb->pitches[0];
|
2021-11-10 18:36:56 +08:00
|
|
|
dst += dst_pitch;
|
2019-04-05 17:52:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
kfree(buf);
|
|
|
|
}
|
2020-05-09 22:16:16 +08:00
|
|
|
EXPORT_SYMBOL(drm_fb_swab);
|
2019-04-05 17:52:15 +08:00
|
|
|
|
2022-04-27 22:14:08 +08:00
|
|
|
static void drm_fb_xrgb8888_to_rgb332_line(void *dbuf, const void *sbuf, unsigned int pixels,
|
|
|
|
bool swab)
|
2021-09-30 03:11:57 +08:00
|
|
|
{
|
2022-04-27 22:14:08 +08:00
|
|
|
u8 *dbuf8 = dbuf;
|
|
|
|
const __le32 *sbuf32 = sbuf;
|
2021-09-30 03:11:57 +08:00
|
|
|
unsigned int x;
|
|
|
|
u32 pix;
|
|
|
|
|
|
|
|
for (x = 0; x < pixels; x++) {
|
2022-04-27 22:14:08 +08:00
|
|
|
pix = le32_to_cpu(sbuf32[x]);
|
|
|
|
dbuf8[x] = ((pix & 0x00e00000) >> 16) |
|
|
|
|
((pix & 0x0000e000) >> 11) |
|
|
|
|
((pix & 0x000000c0) >> 6);
|
2021-09-30 03:11:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drm_fb_xrgb8888_to_rgb332 - Convert XRGB8888 to RGB332 clip buffer
|
|
|
|
* @dst: RGB332 destination buffer
|
2021-11-10 18:36:57 +08:00
|
|
|
* @dst_pitch: Number of bytes between two consecutive scanlines within dst
|
2021-09-30 03:11:57 +08:00
|
|
|
* @src: XRGB8888 source buffer
|
|
|
|
* @fb: DRM framebuffer
|
|
|
|
* @clip: Clip rectangle area to copy
|
|
|
|
*
|
|
|
|
* Drivers can use this function for RGB332 devices that don't natively support XRGB8888.
|
|
|
|
*/
|
2021-11-10 18:36:57 +08:00
|
|
|
void drm_fb_xrgb8888_to_rgb332(void *dst, unsigned int dst_pitch, const void *src,
|
|
|
|
const struct drm_framebuffer *fb, const struct drm_rect *clip)
|
2021-09-30 03:11:57 +08:00
|
|
|
{
|
|
|
|
size_t width = drm_rect_width(clip);
|
|
|
|
size_t src_len = width * sizeof(u32);
|
|
|
|
unsigned int y;
|
|
|
|
void *sbuf;
|
|
|
|
|
2021-11-10 18:36:57 +08:00
|
|
|
if (!dst_pitch)
|
|
|
|
dst_pitch = width;
|
|
|
|
|
2021-09-30 03:11:57 +08:00
|
|
|
/* Use a buffer to speed up access on buffers with uncached read mapping (i.e. WC) */
|
|
|
|
sbuf = kmalloc(src_len, GFP_KERNEL);
|
|
|
|
if (!sbuf)
|
|
|
|
return;
|
|
|
|
|
|
|
|
src += clip_offset(clip, fb->pitches[0], sizeof(u32));
|
|
|
|
for (y = 0; y < drm_rect_height(clip); y++) {
|
|
|
|
memcpy(sbuf, src, src_len);
|
2022-04-27 22:14:08 +08:00
|
|
|
drm_fb_xrgb8888_to_rgb332_line(dst, sbuf, width, false);
|
2021-09-30 03:11:57 +08:00
|
|
|
src += fb->pitches[0];
|
2021-11-10 18:36:57 +08:00
|
|
|
dst += dst_pitch;
|
2021-09-30 03:11:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
kfree(sbuf);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgb332);
|
|
|
|
|
2022-04-27 22:14:08 +08:00
|
|
|
static void drm_fb_xrgb8888_to_rgb565_line(void *dbuf, const void *sbuf, unsigned int pixels)
|
2019-04-05 17:52:15 +08:00
|
|
|
{
|
2022-04-27 22:14:08 +08:00
|
|
|
u16 *dbuf16 = dbuf;
|
|
|
|
const u32 *sbuf32 = sbuf;
|
2019-04-10 14:38:14 +08:00
|
|
|
unsigned int x;
|
|
|
|
u16 val16;
|
|
|
|
|
|
|
|
for (x = 0; x < pixels; x++) {
|
2022-04-27 22:14:08 +08:00
|
|
|
val16 = ((sbuf32[x] & 0x00F80000) >> 8) |
|
|
|
|
((sbuf32[x] & 0x0000FC00) >> 5) |
|
|
|
|
((sbuf32[x] & 0x000000F8) >> 3);
|
|
|
|
dbuf16[x] = val16;
|
2022-04-27 22:14:07 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-27 22:14:08 +08:00
|
|
|
static void drm_fb_xrgb8888_to_rgb565_swab_line(void *dbuf, const void *sbuf,
|
2022-04-27 22:14:07 +08:00
|
|
|
unsigned int pixels)
|
|
|
|
{
|
2022-04-27 22:14:08 +08:00
|
|
|
u16 *dbuf16 = dbuf;
|
|
|
|
const u32 *sbuf32 = sbuf;
|
2022-04-27 22:14:07 +08:00
|
|
|
unsigned int x;
|
|
|
|
u16 val16;
|
|
|
|
|
|
|
|
for (x = 0; x < pixels; x++) {
|
2022-04-27 22:14:08 +08:00
|
|
|
val16 = ((sbuf32[x] & 0x00F80000) >> 8) |
|
|
|
|
((sbuf32[x] & 0x0000FC00) >> 5) |
|
|
|
|
((sbuf32[x] & 0x000000F8) >> 3);
|
|
|
|
dbuf16[x] = swab16(val16);
|
2019-04-05 17:52:15 +08:00
|
|
|
}
|
2019-04-05 17:52:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drm_fb_xrgb8888_to_rgb565 - Convert XRGB8888 to RGB565 clip buffer
|
|
|
|
* @dst: RGB565 destination buffer
|
2021-11-10 18:36:57 +08:00
|
|
|
* @dst_pitch: Number of bytes between two consecutive scanlines within dst
|
2019-04-05 17:52:17 +08:00
|
|
|
* @vaddr: XRGB8888 source buffer
|
|
|
|
* @fb: DRM framebuffer
|
|
|
|
* @clip: Clip rectangle area to copy
|
2019-04-10 14:38:14 +08:00
|
|
|
* @swab: Swap bytes
|
2019-04-05 17:52:17 +08:00
|
|
|
*
|
|
|
|
* Drivers can use this function for RGB565 devices that don't natively
|
|
|
|
* support XRGB8888.
|
|
|
|
*/
|
2021-11-10 18:36:57 +08:00
|
|
|
void drm_fb_xrgb8888_to_rgb565(void *dst, unsigned int dst_pitch, const void *vaddr,
|
|
|
|
const struct drm_framebuffer *fb, const struct drm_rect *clip,
|
|
|
|
bool swab)
|
2019-04-05 17:52:17 +08:00
|
|
|
{
|
2019-04-10 14:38:14 +08:00
|
|
|
size_t linepixels = clip->x2 - clip->x1;
|
|
|
|
size_t src_len = linepixels * sizeof(u32);
|
|
|
|
size_t dst_len = linepixels * sizeof(u16);
|
|
|
|
unsigned y, lines = clip->y2 - clip->y1;
|
|
|
|
void *sbuf;
|
|
|
|
|
2021-11-10 18:36:57 +08:00
|
|
|
if (!dst_pitch)
|
|
|
|
dst_pitch = dst_len;
|
|
|
|
|
2019-04-10 14:38:14 +08:00
|
|
|
/*
|
|
|
|
* The cma memory is write-combined so reads are uncached.
|
|
|
|
* Speed up by fetching one line at a time.
|
|
|
|
*/
|
|
|
|
sbuf = kmalloc(src_len, GFP_KERNEL);
|
|
|
|
if (!sbuf)
|
|
|
|
return;
|
|
|
|
|
|
|
|
vaddr += clip_offset(clip, fb->pitches[0], sizeof(u32));
|
|
|
|
for (y = 0; y < lines; y++) {
|
|
|
|
memcpy(sbuf, vaddr, src_len);
|
2022-04-27 22:14:07 +08:00
|
|
|
if (swab)
|
|
|
|
drm_fb_xrgb8888_to_rgb565_swab_line(dst, sbuf, linepixels);
|
|
|
|
else
|
|
|
|
drm_fb_xrgb8888_to_rgb565_line(dst, sbuf, linepixels);
|
2019-04-10 14:38:14 +08:00
|
|
|
vaddr += fb->pitches[0];
|
2021-11-10 18:36:57 +08:00
|
|
|
dst += dst_pitch;
|
2019-04-10 14:38:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
kfree(sbuf);
|
2019-04-05 17:52:15 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgb565);
|
|
|
|
|
2019-04-05 17:52:17 +08:00
|
|
|
/**
|
2021-11-10 18:36:57 +08:00
|
|
|
* drm_fb_xrgb8888_to_rgb565_toio - Convert XRGB8888 to RGB565 clip buffer
|
2019-04-10 14:38:14 +08:00
|
|
|
* @dst: RGB565 destination buffer (iomem)
|
2021-11-10 18:36:57 +08:00
|
|
|
* @dst_pitch: Number of bytes between two consecutive scanlines within dst
|
2019-04-05 17:52:17 +08:00
|
|
|
* @vaddr: XRGB8888 source buffer
|
|
|
|
* @fb: DRM framebuffer
|
|
|
|
* @clip: Clip rectangle area to copy
|
2019-04-10 14:38:14 +08:00
|
|
|
* @swab: Swap bytes
|
2019-04-05 17:52:17 +08:00
|
|
|
*
|
|
|
|
* Drivers can use this function for RGB565 devices that don't natively
|
|
|
|
* support XRGB8888.
|
|
|
|
*/
|
2021-11-10 18:36:57 +08:00
|
|
|
void drm_fb_xrgb8888_to_rgb565_toio(void __iomem *dst, unsigned int dst_pitch,
|
|
|
|
const void *vaddr, const struct drm_framebuffer *fb,
|
|
|
|
const struct drm_rect *clip, bool swab)
|
2019-04-05 17:52:17 +08:00
|
|
|
{
|
2019-04-10 14:38:14 +08:00
|
|
|
size_t linepixels = clip->x2 - clip->x1;
|
|
|
|
size_t dst_len = linepixels * sizeof(u16);
|
|
|
|
unsigned y, lines = clip->y2 - clip->y1;
|
|
|
|
void *dbuf;
|
|
|
|
|
2021-11-10 18:36:57 +08:00
|
|
|
if (!dst_pitch)
|
|
|
|
dst_pitch = dst_len;
|
|
|
|
|
2019-04-10 14:38:14 +08:00
|
|
|
dbuf = kmalloc(dst_len, GFP_KERNEL);
|
|
|
|
if (!dbuf)
|
|
|
|
return;
|
|
|
|
|
|
|
|
vaddr += clip_offset(clip, fb->pitches[0], sizeof(u32));
|
|
|
|
for (y = 0; y < lines; y++) {
|
2022-04-27 22:14:07 +08:00
|
|
|
if (swab)
|
|
|
|
drm_fb_xrgb8888_to_rgb565_swab_line(dbuf, vaddr, linepixels);
|
|
|
|
else
|
|
|
|
drm_fb_xrgb8888_to_rgb565_line(dbuf, vaddr, linepixels);
|
2019-04-10 14:38:14 +08:00
|
|
|
memcpy_toio(dst, dbuf, dst_len);
|
|
|
|
vaddr += fb->pitches[0];
|
2021-11-10 18:36:57 +08:00
|
|
|
dst += dst_pitch;
|
2019-04-10 14:38:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
kfree(dbuf);
|
2019-04-05 17:52:17 +08:00
|
|
|
}
|
2021-11-10 18:36:57 +08:00
|
|
|
EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgb565_toio);
|
2019-04-05 17:52:17 +08:00
|
|
|
|
2022-04-27 22:14:08 +08:00
|
|
|
static void drm_fb_xrgb8888_to_rgb888_line(void *dbuf, const void *sbuf, unsigned int pixels)
|
2019-04-05 17:52:18 +08:00
|
|
|
{
|
2022-04-27 22:14:08 +08:00
|
|
|
u8 *dbuf8 = dbuf;
|
|
|
|
const u32 *sbuf32 = sbuf;
|
2019-04-10 14:38:15 +08:00
|
|
|
unsigned int x;
|
2019-04-05 17:52:18 +08:00
|
|
|
|
2019-04-10 14:38:15 +08:00
|
|
|
for (x = 0; x < pixels; x++) {
|
2022-04-27 22:14:08 +08:00
|
|
|
*dbuf8++ = (sbuf32[x] & 0x000000FF) >> 0;
|
|
|
|
*dbuf8++ = (sbuf32[x] & 0x0000FF00) >> 8;
|
|
|
|
*dbuf8++ = (sbuf32[x] & 0x00FF0000) >> 16;
|
2019-04-05 17:52:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-30 03:11:58 +08:00
|
|
|
/**
|
|
|
|
* drm_fb_xrgb8888_to_rgb888 - Convert XRGB8888 to RGB888 clip buffer
|
|
|
|
* @dst: RGB888 destination buffer
|
2021-11-10 18:36:57 +08:00
|
|
|
* @dst_pitch: Number of bytes between two consecutive scanlines within dst
|
2021-09-30 03:11:58 +08:00
|
|
|
* @src: XRGB8888 source buffer
|
|
|
|
* @fb: DRM framebuffer
|
|
|
|
* @clip: Clip rectangle area to copy
|
|
|
|
*
|
|
|
|
* Drivers can use this function for RGB888 devices that don't natively
|
|
|
|
* support XRGB8888.
|
|
|
|
*/
|
2021-11-10 18:36:57 +08:00
|
|
|
void drm_fb_xrgb8888_to_rgb888(void *dst, unsigned int dst_pitch, const void *src,
|
|
|
|
const struct drm_framebuffer *fb, const struct drm_rect *clip)
|
2021-09-30 03:11:58 +08:00
|
|
|
{
|
|
|
|
size_t width = drm_rect_width(clip);
|
|
|
|
size_t src_len = width * sizeof(u32);
|
|
|
|
unsigned int y;
|
|
|
|
void *sbuf;
|
|
|
|
|
2021-11-10 18:36:57 +08:00
|
|
|
if (!dst_pitch)
|
|
|
|
dst_pitch = width * 3;
|
|
|
|
|
2021-09-30 03:11:58 +08:00
|
|
|
/* Use a buffer to speed up access on buffers with uncached read mapping (i.e. WC) */
|
|
|
|
sbuf = kmalloc(src_len, GFP_KERNEL);
|
|
|
|
if (!sbuf)
|
|
|
|
return;
|
|
|
|
|
|
|
|
src += clip_offset(clip, fb->pitches[0], sizeof(u32));
|
|
|
|
for (y = 0; y < drm_rect_height(clip); y++) {
|
|
|
|
memcpy(sbuf, src, src_len);
|
|
|
|
drm_fb_xrgb8888_to_rgb888_line(dst, sbuf, width);
|
|
|
|
src += fb->pitches[0];
|
2021-11-10 18:36:57 +08:00
|
|
|
dst += dst_pitch;
|
2021-09-30 03:11:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
kfree(sbuf);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgb888);
|
|
|
|
|
2019-04-05 17:52:18 +08:00
|
|
|
/**
|
2021-11-10 18:36:57 +08:00
|
|
|
* drm_fb_xrgb8888_to_rgb888_toio - Convert XRGB8888 to RGB888 clip buffer
|
2019-04-11 12:49:32 +08:00
|
|
|
* @dst: RGB565 destination buffer (iomem)
|
2021-11-10 18:36:57 +08:00
|
|
|
* @dst_pitch: Number of bytes between two consecutive scanlines within dst
|
2019-04-05 17:52:18 +08:00
|
|
|
* @vaddr: XRGB8888 source buffer
|
|
|
|
* @fb: DRM framebuffer
|
|
|
|
* @clip: Clip rectangle area to copy
|
|
|
|
*
|
|
|
|
* Drivers can use this function for RGB888 devices that don't natively
|
|
|
|
* support XRGB8888.
|
|
|
|
*/
|
2021-11-10 18:36:57 +08:00
|
|
|
void drm_fb_xrgb8888_to_rgb888_toio(void __iomem *dst, unsigned int dst_pitch,
|
|
|
|
const void *vaddr, const struct drm_framebuffer *fb,
|
|
|
|
const struct drm_rect *clip)
|
2019-04-05 17:52:18 +08:00
|
|
|
{
|
2019-04-10 14:38:15 +08:00
|
|
|
size_t linepixels = clip->x2 - clip->x1;
|
|
|
|
size_t dst_len = linepixels * 3;
|
|
|
|
unsigned y, lines = clip->y2 - clip->y1;
|
|
|
|
void *dbuf;
|
2019-04-05 17:52:18 +08:00
|
|
|
|
2021-11-10 18:36:57 +08:00
|
|
|
if (!dst_pitch)
|
|
|
|
dst_pitch = dst_len;
|
|
|
|
|
2019-04-10 14:38:15 +08:00
|
|
|
dbuf = kmalloc(dst_len, GFP_KERNEL);
|
|
|
|
if (!dbuf)
|
|
|
|
return;
|
|
|
|
|
|
|
|
vaddr += clip_offset(clip, fb->pitches[0], sizeof(u32));
|
|
|
|
for (y = 0; y < lines; y++) {
|
|
|
|
drm_fb_xrgb8888_to_rgb888_line(dbuf, vaddr, linepixels);
|
|
|
|
memcpy_toio(dst, dbuf, dst_len);
|
|
|
|
vaddr += fb->pitches[0];
|
2021-11-10 18:36:57 +08:00
|
|
|
dst += dst_pitch;
|
2019-04-10 14:38:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
kfree(dbuf);
|
2019-04-05 17:52:18 +08:00
|
|
|
}
|
2021-11-10 18:36:57 +08:00
|
|
|
EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgb888_toio);
|
2019-04-05 17:52:18 +08:00
|
|
|
|
2022-04-25 15:59:39 +08:00
|
|
|
static void drm_fb_rgb565_to_xrgb8888_line(void *dbuf, const void *sbuf, unsigned int pixels)
|
|
|
|
{
|
|
|
|
u32 *dbuf32 = dbuf;
|
|
|
|
const u16 *sbuf16 = sbuf;
|
|
|
|
unsigned int x;
|
|
|
|
|
|
|
|
for (x = 0; x < pixels; x++, ++sbuf16, ++dbuf32) {
|
|
|
|
u32 val32 = ((*sbuf16 & 0xf800) << 8) |
|
|
|
|
((*sbuf16 & 0x07e0) << 5) |
|
|
|
|
((*sbuf16 & 0x001f) << 3);
|
|
|
|
*dbuf32 = 0xff000000 | val32 |
|
|
|
|
((val32 >> 3) & 0x00070007) |
|
|
|
|
((val32 >> 2) & 0x00000300);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void drm_fb_rgb565_to_xrgb8888_toio(void __iomem *dst, unsigned int dst_pitch,
|
|
|
|
const void *vaddr, const struct drm_framebuffer *fb,
|
|
|
|
const struct drm_rect *clip)
|
|
|
|
{
|
|
|
|
size_t linepixels = drm_rect_width(clip);
|
|
|
|
size_t dst_len = linepixels * 4;
|
|
|
|
unsigned int y, lines = drm_rect_height(clip);
|
|
|
|
void *dbuf;
|
|
|
|
|
|
|
|
if (!dst_pitch)
|
|
|
|
dst_pitch = dst_len;
|
|
|
|
|
|
|
|
dbuf = kmalloc(dst_len, GFP_KERNEL);
|
|
|
|
if (!dbuf)
|
|
|
|
return;
|
|
|
|
|
|
|
|
vaddr += clip_offset(clip, fb->pitches[0], 2);
|
|
|
|
for (y = 0; y < lines; y++) {
|
|
|
|
drm_fb_rgb565_to_xrgb8888_line(dbuf, vaddr, linepixels);
|
|
|
|
memcpy_toio(dst, dbuf, dst_len);
|
|
|
|
vaddr += fb->pitches[0];
|
|
|
|
dst += dst_pitch;
|
|
|
|
}
|
|
|
|
|
|
|
|
kfree(dbuf);
|
|
|
|
}
|
|
|
|
|
2022-04-25 15:59:38 +08:00
|
|
|
static void drm_fb_rgb888_to_xrgb8888_line(void *dbuf, const void *sbuf, unsigned int pixels)
|
|
|
|
{
|
|
|
|
u32 *dbuf32 = dbuf;
|
|
|
|
const u8 *sbuf8 = sbuf;
|
|
|
|
unsigned int x;
|
|
|
|
|
|
|
|
for (x = 0; x < pixels; x++) {
|
|
|
|
u8 r = *sbuf8++;
|
|
|
|
u8 g = *sbuf8++;
|
|
|
|
u8 b = *sbuf8++;
|
|
|
|
*dbuf32++ = 0xff000000 | (r << 16) | (g << 8) | b;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void drm_fb_rgb888_to_xrgb8888_toio(void __iomem *dst, unsigned int dst_pitch,
|
|
|
|
const void *vaddr, const struct drm_framebuffer *fb,
|
|
|
|
const struct drm_rect *clip)
|
|
|
|
{
|
|
|
|
size_t linepixels = drm_rect_width(clip);
|
|
|
|
size_t dst_len = linepixels * 4;
|
|
|
|
unsigned int y, lines = drm_rect_height(clip);
|
|
|
|
void *dbuf;
|
|
|
|
|
|
|
|
if (!dst_pitch)
|
|
|
|
dst_pitch = dst_len;
|
|
|
|
|
|
|
|
dbuf = kmalloc(dst_len, GFP_KERNEL);
|
|
|
|
if (!dbuf)
|
|
|
|
return;
|
|
|
|
|
|
|
|
vaddr += clip_offset(clip, fb->pitches[0], 3);
|
|
|
|
for (y = 0; y < lines; y++) {
|
|
|
|
drm_fb_rgb888_to_xrgb8888_line(dbuf, vaddr, linepixels);
|
|
|
|
memcpy_toio(dst, dbuf, dst_len);
|
|
|
|
vaddr += fb->pitches[0];
|
|
|
|
dst += dst_pitch;
|
|
|
|
}
|
|
|
|
|
|
|
|
kfree(dbuf);
|
|
|
|
}
|
|
|
|
|
2022-04-27 22:14:08 +08:00
|
|
|
static void drm_fb_xrgb8888_to_xrgb2101010_line(void *dbuf, const void *sbuf, unsigned int pixels)
|
2021-12-12 14:24:06 +08:00
|
|
|
{
|
2022-04-27 22:14:08 +08:00
|
|
|
u32 *dbuf32 = dbuf;
|
|
|
|
const u32 *sbuf32 = sbuf;
|
2021-12-12 14:24:06 +08:00
|
|
|
unsigned int x;
|
|
|
|
u32 val32;
|
|
|
|
|
|
|
|
for (x = 0; x < pixels; x++) {
|
2022-04-27 22:14:08 +08:00
|
|
|
val32 = ((sbuf32[x] & 0x000000FF) << 2) |
|
|
|
|
((sbuf32[x] & 0x0000FF00) << 4) |
|
|
|
|
((sbuf32[x] & 0x00FF0000) << 6);
|
|
|
|
*dbuf32++ = val32 | ((val32 >> 8) & 0x00300C03);
|
2021-12-12 14:24:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drm_fb_xrgb8888_to_xrgb2101010_toio - Convert XRGB8888 to XRGB2101010 clip
|
|
|
|
* buffer
|
|
|
|
* @dst: XRGB2101010 destination buffer (iomem)
|
|
|
|
* @dst_pitch: Number of bytes between two consecutive scanlines within dst
|
|
|
|
* @vaddr: XRGB8888 source buffer
|
|
|
|
* @fb: DRM framebuffer
|
|
|
|
* @clip: Clip rectangle area to copy
|
|
|
|
*
|
|
|
|
* Drivers can use this function for XRGB2101010 devices that don't natively
|
|
|
|
* support XRGB8888.
|
|
|
|
*/
|
|
|
|
void drm_fb_xrgb8888_to_xrgb2101010_toio(void __iomem *dst,
|
|
|
|
unsigned int dst_pitch, const void *vaddr,
|
|
|
|
const struct drm_framebuffer *fb,
|
|
|
|
const struct drm_rect *clip)
|
|
|
|
{
|
|
|
|
size_t linepixels = clip->x2 - clip->x1;
|
|
|
|
size_t dst_len = linepixels * sizeof(u32);
|
|
|
|
unsigned int y, lines = clip->y2 - clip->y1;
|
|
|
|
void *dbuf;
|
|
|
|
|
|
|
|
if (!dst_pitch)
|
|
|
|
dst_pitch = dst_len;
|
|
|
|
|
|
|
|
dbuf = kmalloc(dst_len, GFP_KERNEL);
|
|
|
|
if (!dbuf)
|
|
|
|
return;
|
|
|
|
|
|
|
|
vaddr += clip_offset(clip, fb->pitches[0], sizeof(u32));
|
|
|
|
for (y = 0; y < lines; y++) {
|
|
|
|
drm_fb_xrgb8888_to_xrgb2101010_line(dbuf, vaddr, linepixels);
|
|
|
|
memcpy_toio(dst, dbuf, dst_len);
|
|
|
|
vaddr += fb->pitches[0];
|
|
|
|
dst += dst_pitch;
|
|
|
|
}
|
|
|
|
|
|
|
|
kfree(dbuf);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_fb_xrgb8888_to_xrgb2101010_toio);
|
|
|
|
|
2022-04-27 22:14:08 +08:00
|
|
|
static void drm_fb_xrgb8888_to_gray8_line(void *dbuf, const void *sbuf, unsigned int pixels)
|
2022-02-14 21:37:05 +08:00
|
|
|
{
|
2022-04-27 22:14:08 +08:00
|
|
|
u8 *dbuf8 = dbuf;
|
|
|
|
const u32 *sbuf32 = sbuf;
|
2022-02-14 21:37:05 +08:00
|
|
|
unsigned int x;
|
|
|
|
|
|
|
|
for (x = 0; x < pixels; x++) {
|
2022-04-27 22:14:08 +08:00
|
|
|
u8 r = (*sbuf32 & 0x00ff0000) >> 16;
|
|
|
|
u8 g = (*sbuf32 & 0x0000ff00) >> 8;
|
|
|
|
u8 b = *sbuf32 & 0x000000ff;
|
2022-02-14 21:37:05 +08:00
|
|
|
|
|
|
|
/* ITU BT.601: Y = 0.299 R + 0.587 G + 0.114 B */
|
2022-04-27 22:14:08 +08:00
|
|
|
*dbuf8++ = (3 * r + 6 * g + b) / 10;
|
|
|
|
sbuf32++;
|
2022-02-14 21:37:05 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-05 17:52:15 +08:00
|
|
|
/**
|
|
|
|
* drm_fb_xrgb8888_to_gray8 - Convert XRGB8888 to grayscale
|
|
|
|
* @dst: 8-bit grayscale destination buffer
|
2021-11-10 18:36:57 +08:00
|
|
|
* @dst_pitch: Number of bytes between two consecutive scanlines within dst
|
2019-04-05 17:52:15 +08:00
|
|
|
* @vaddr: XRGB8888 source buffer
|
|
|
|
* @fb: DRM framebuffer
|
|
|
|
* @clip: Clip rectangle area to copy
|
|
|
|
*
|
|
|
|
* Drm doesn't have native monochrome or grayscale support.
|
|
|
|
* Such drivers can announce the commonly supported XR24 format to userspace
|
|
|
|
* and use this function to convert to the native format.
|
|
|
|
*
|
|
|
|
* Monochrome drivers will use the most significant bit,
|
|
|
|
* where 1 means foreground color and 0 background color.
|
|
|
|
*
|
|
|
|
* ITU BT.601 is used for the RGB -> luma (brightness) conversion.
|
|
|
|
*/
|
2021-11-10 18:36:57 +08:00
|
|
|
void drm_fb_xrgb8888_to_gray8(void *dst, unsigned int dst_pitch, const void *vaddr,
|
|
|
|
const struct drm_framebuffer *fb, const struct drm_rect *clip)
|
2019-04-05 17:52:15 +08:00
|
|
|
{
|
2022-02-14 21:37:05 +08:00
|
|
|
unsigned int linepixels = clip->x2 - clip->x1;
|
|
|
|
unsigned int len = linepixels * sizeof(u32);
|
|
|
|
unsigned int y;
|
2019-04-05 17:52:15 +08:00
|
|
|
void *buf;
|
2021-11-10 18:36:57 +08:00
|
|
|
u8 *dst8;
|
|
|
|
u32 *src32;
|
2019-04-05 17:52:15 +08:00
|
|
|
|
|
|
|
if (WARN_ON(fb->format->format != DRM_FORMAT_XRGB8888))
|
|
|
|
return;
|
2021-11-10 18:36:57 +08:00
|
|
|
|
|
|
|
if (!dst_pitch)
|
|
|
|
dst_pitch = drm_rect_width(clip);
|
|
|
|
|
2019-04-05 17:52:15 +08:00
|
|
|
/*
|
|
|
|
* The cma memory is write-combined so reads are uncached.
|
|
|
|
* Speed up by fetching one line at a time.
|
|
|
|
*/
|
|
|
|
buf = kmalloc(len, GFP_KERNEL);
|
|
|
|
if (!buf)
|
|
|
|
return;
|
|
|
|
|
2021-11-10 18:36:57 +08:00
|
|
|
vaddr += clip_offset(clip, fb->pitches[0], sizeof(u32));
|
2019-04-05 17:52:15 +08:00
|
|
|
for (y = clip->y1; y < clip->y2; y++) {
|
2021-11-10 18:36:57 +08:00
|
|
|
dst8 = dst;
|
|
|
|
src32 = memcpy(buf, vaddr, len);
|
2022-02-14 21:37:05 +08:00
|
|
|
drm_fb_xrgb8888_to_gray8_line(dst8, src32, linepixels);
|
2021-11-10 18:36:57 +08:00
|
|
|
vaddr += fb->pitches[0];
|
|
|
|
dst += dst_pitch;
|
2019-04-05 17:52:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
kfree(buf);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_fb_xrgb8888_to_gray8);
|
|
|
|
|
2021-04-30 18:58:33 +08:00
|
|
|
/**
|
2021-11-10 18:36:58 +08:00
|
|
|
* drm_fb_blit_toio - Copy parts of a framebuffer to display memory
|
2021-04-30 18:58:33 +08:00
|
|
|
* @dst: The display memory to copy to
|
|
|
|
* @dst_pitch: Number of bytes between two consecutive scanlines within dst
|
|
|
|
* @dst_format: FOURCC code of the display's color format
|
|
|
|
* @vmap: The framebuffer memory to copy from
|
|
|
|
* @fb: The framebuffer to copy from
|
|
|
|
* @clip: Clip rectangle area to copy
|
|
|
|
*
|
|
|
|
* This function copies parts of a framebuffer to display memory. If the
|
|
|
|
* formats of the display and the framebuffer mismatch, the blit function
|
|
|
|
* will attempt to convert between them.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* 0 on success, or
|
|
|
|
* -EINVAL if the color-format conversion failed, or
|
|
|
|
* a negative error code otherwise.
|
|
|
|
*/
|
2021-11-10 18:36:58 +08:00
|
|
|
int drm_fb_blit_toio(void __iomem *dst, unsigned int dst_pitch, uint32_t dst_format,
|
|
|
|
const void *vmap, const struct drm_framebuffer *fb,
|
|
|
|
const struct drm_rect *clip)
|
2021-04-30 18:58:33 +08:00
|
|
|
{
|
|
|
|
uint32_t fb_format = fb->format->format;
|
|
|
|
|
|
|
|
/* treat alpha channel like filler bits */
|
|
|
|
if (fb_format == DRM_FORMAT_ARGB8888)
|
|
|
|
fb_format = DRM_FORMAT_XRGB8888;
|
|
|
|
if (dst_format == DRM_FORMAT_ARGB8888)
|
|
|
|
dst_format = DRM_FORMAT_XRGB8888;
|
2021-12-12 14:24:06 +08:00
|
|
|
if (fb_format == DRM_FORMAT_ARGB2101010)
|
|
|
|
fb_format = DRM_FORMAT_XRGB2101010;
|
|
|
|
if (dst_format == DRM_FORMAT_ARGB2101010)
|
|
|
|
dst_format = DRM_FORMAT_XRGB2101010;
|
2021-04-30 18:58:33 +08:00
|
|
|
|
|
|
|
if (dst_format == fb_format) {
|
2021-11-10 18:36:55 +08:00
|
|
|
drm_fb_memcpy_toio(dst, dst_pitch, vmap, fb, clip);
|
2021-04-30 18:58:33 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
} else if (dst_format == DRM_FORMAT_RGB565) {
|
|
|
|
if (fb_format == DRM_FORMAT_XRGB8888) {
|
2021-11-10 18:36:58 +08:00
|
|
|
drm_fb_xrgb8888_to_rgb565_toio(dst, dst_pitch, vmap, fb, clip, false);
|
2021-04-30 18:58:33 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} else if (dst_format == DRM_FORMAT_RGB888) {
|
|
|
|
if (fb_format == DRM_FORMAT_XRGB8888) {
|
2021-11-10 18:36:57 +08:00
|
|
|
drm_fb_xrgb8888_to_rgb888_toio(dst, dst_pitch, vmap, fb, clip);
|
2021-04-30 18:58:33 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2022-04-25 15:59:38 +08:00
|
|
|
} else if (dst_format == DRM_FORMAT_XRGB8888) {
|
|
|
|
if (fb_format == DRM_FORMAT_RGB888) {
|
|
|
|
drm_fb_rgb888_to_xrgb8888_toio(dst, dst_pitch, vmap, fb, clip);
|
|
|
|
return 0;
|
2022-04-25 15:59:39 +08:00
|
|
|
} else if (fb_format == DRM_FORMAT_RGB565) {
|
|
|
|
drm_fb_rgb565_to_xrgb8888_toio(dst, dst_pitch, vmap, fb, clip);
|
|
|
|
return 0;
|
2022-04-25 15:59:38 +08:00
|
|
|
}
|
2021-12-12 14:24:06 +08:00
|
|
|
} else if (dst_format == DRM_FORMAT_XRGB2101010) {
|
|
|
|
if (fb_format == DRM_FORMAT_XRGB8888) {
|
|
|
|
drm_fb_xrgb8888_to_xrgb2101010_toio(dst, dst_pitch, vmap, fb, clip);
|
|
|
|
return 0;
|
|
|
|
}
|
2021-04-30 18:58:33 +08:00
|
|
|
}
|
|
|
|
|
2022-04-25 15:59:37 +08:00
|
|
|
drm_warn_once(fb->dev, "No conversion helper from %p4cc to %p4cc found.\n",
|
|
|
|
&fb_format, &dst_format);
|
|
|
|
|
2021-04-30 18:58:33 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2021-11-10 18:36:58 +08:00
|
|
|
EXPORT_SYMBOL(drm_fb_blit_toio);
|
2022-02-14 21:37:06 +08:00
|
|
|
|
|
|
|
|
2022-04-27 22:14:08 +08:00
|
|
|
static void drm_fb_gray8_to_mono_line(void *dbuf, const void *sbuf, unsigned int pixels)
|
drm/format-helper: Fix XRGB888 to monochrome conversion
The conversion functions drm_fb_xrgb8888_to_mono() and
drm_fb_gray8_to_mono_line() do not behave correctly when the
horizontal boundaries of the clip rectangle are not multiples of 8:
a. When x1 % 8 != 0, the calculated pitch is not correct,
b. When x2 % 8 != 0, the pixel data for the last byte is wrong.
Simplify the code and fix (a) by:
1. Removing start_offset, and always storing the first pixel in the
first bit of the monochrome destination buffer.
Drivers that require the first pixel in a byte to be located at an
x-coordinate that is a multiple of 8 can always align the clip
rectangle before calling drm_fb_xrgb8888_to_mono().
Note that:
- The ssd130x driver does not need the alignment, as the
monochrome buffer is a temporary format,
- The repaper driver always updates the full screen, so the clip
rectangle is always aligned.
2. Passing the number of pixels to drm_fb_gray8_to_mono_line(),
instead of the number of bytes, and the number of pixels in the
last byte.
Fix (b) by explicitly setting the target bit, instead of always setting
bit 7 and shifting the value in each loop iteration.
Remove the bogus pitch check, which operates on bytes instead of pixels,
and triggers when e.g. flashing the cursor on a text console with a font
that is 8 pixels wide.
Drop the confusing comment about scanlines, as a pitch in bytes always
contains a multiple of 8 pixels.
While at it, use the drm_rect_height() helper instead of open-coding the
same operation.
Update the comments accordingly.
Fixes: bcf8b616deb87941 ("drm/format-helper: Add drm_fb_xrgb8888_to_mono_reversed()")
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
Acked-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20220317081830.1211400-3-geert@linux-m68k.org
2022-03-17 16:18:27 +08:00
|
|
|
{
|
2022-04-27 22:14:08 +08:00
|
|
|
u8 *dbuf8 = dbuf;
|
|
|
|
const u8 *sbuf8 = sbuf;
|
|
|
|
|
drm/format-helper: Fix XRGB888 to monochrome conversion
The conversion functions drm_fb_xrgb8888_to_mono() and
drm_fb_gray8_to_mono_line() do not behave correctly when the
horizontal boundaries of the clip rectangle are not multiples of 8:
a. When x1 % 8 != 0, the calculated pitch is not correct,
b. When x2 % 8 != 0, the pixel data for the last byte is wrong.
Simplify the code and fix (a) by:
1. Removing start_offset, and always storing the first pixel in the
first bit of the monochrome destination buffer.
Drivers that require the first pixel in a byte to be located at an
x-coordinate that is a multiple of 8 can always align the clip
rectangle before calling drm_fb_xrgb8888_to_mono().
Note that:
- The ssd130x driver does not need the alignment, as the
monochrome buffer is a temporary format,
- The repaper driver always updates the full screen, so the clip
rectangle is always aligned.
2. Passing the number of pixels to drm_fb_gray8_to_mono_line(),
instead of the number of bytes, and the number of pixels in the
last byte.
Fix (b) by explicitly setting the target bit, instead of always setting
bit 7 and shifting the value in each loop iteration.
Remove the bogus pitch check, which operates on bytes instead of pixels,
and triggers when e.g. flashing the cursor on a text console with a font
that is 8 pixels wide.
Drop the confusing comment about scanlines, as a pitch in bytes always
contains a multiple of 8 pixels.
While at it, use the drm_rect_height() helper instead of open-coding the
same operation.
Update the comments accordingly.
Fixes: bcf8b616deb87941 ("drm/format-helper: Add drm_fb_xrgb8888_to_mono_reversed()")
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
Acked-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20220317081830.1211400-3-geert@linux-m68k.org
2022-03-17 16:18:27 +08:00
|
|
|
while (pixels) {
|
|
|
|
unsigned int i, bits = min(pixels, 8U);
|
|
|
|
u8 byte = 0;
|
2022-02-14 21:37:06 +08:00
|
|
|
|
drm/format-helper: Fix XRGB888 to monochrome conversion
The conversion functions drm_fb_xrgb8888_to_mono() and
drm_fb_gray8_to_mono_line() do not behave correctly when the
horizontal boundaries of the clip rectangle are not multiples of 8:
a. When x1 % 8 != 0, the calculated pitch is not correct,
b. When x2 % 8 != 0, the pixel data for the last byte is wrong.
Simplify the code and fix (a) by:
1. Removing start_offset, and always storing the first pixel in the
first bit of the monochrome destination buffer.
Drivers that require the first pixel in a byte to be located at an
x-coordinate that is a multiple of 8 can always align the clip
rectangle before calling drm_fb_xrgb8888_to_mono().
Note that:
- The ssd130x driver does not need the alignment, as the
monochrome buffer is a temporary format,
- The repaper driver always updates the full screen, so the clip
rectangle is always aligned.
2. Passing the number of pixels to drm_fb_gray8_to_mono_line(),
instead of the number of bytes, and the number of pixels in the
last byte.
Fix (b) by explicitly setting the target bit, instead of always setting
bit 7 and shifting the value in each loop iteration.
Remove the bogus pitch check, which operates on bytes instead of pixels,
and triggers when e.g. flashing the cursor on a text console with a font
that is 8 pixels wide.
Drop the confusing comment about scanlines, as a pitch in bytes always
contains a multiple of 8 pixels.
While at it, use the drm_rect_height() helper instead of open-coding the
same operation.
Update the comments accordingly.
Fixes: bcf8b616deb87941 ("drm/format-helper: Add drm_fb_xrgb8888_to_mono_reversed()")
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
Acked-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20220317081830.1211400-3-geert@linux-m68k.org
2022-03-17 16:18:27 +08:00
|
|
|
for (i = 0; i < bits; i++, pixels--) {
|
2022-04-27 22:14:08 +08:00
|
|
|
if (*sbuf8++ >= 128)
|
drm/format-helper: Fix XRGB888 to monochrome conversion
The conversion functions drm_fb_xrgb8888_to_mono() and
drm_fb_gray8_to_mono_line() do not behave correctly when the
horizontal boundaries of the clip rectangle are not multiples of 8:
a. When x1 % 8 != 0, the calculated pitch is not correct,
b. When x2 % 8 != 0, the pixel data for the last byte is wrong.
Simplify the code and fix (a) by:
1. Removing start_offset, and always storing the first pixel in the
first bit of the monochrome destination buffer.
Drivers that require the first pixel in a byte to be located at an
x-coordinate that is a multiple of 8 can always align the clip
rectangle before calling drm_fb_xrgb8888_to_mono().
Note that:
- The ssd130x driver does not need the alignment, as the
monochrome buffer is a temporary format,
- The repaper driver always updates the full screen, so the clip
rectangle is always aligned.
2. Passing the number of pixels to drm_fb_gray8_to_mono_line(),
instead of the number of bytes, and the number of pixels in the
last byte.
Fix (b) by explicitly setting the target bit, instead of always setting
bit 7 and shifting the value in each loop iteration.
Remove the bogus pitch check, which operates on bytes instead of pixels,
and triggers when e.g. flashing the cursor on a text console with a font
that is 8 pixels wide.
Drop the confusing comment about scanlines, as a pitch in bytes always
contains a multiple of 8 pixels.
While at it, use the drm_rect_height() helper instead of open-coding the
same operation.
Update the comments accordingly.
Fixes: bcf8b616deb87941 ("drm/format-helper: Add drm_fb_xrgb8888_to_mono_reversed()")
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
Acked-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20220317081830.1211400-3-geert@linux-m68k.org
2022-03-17 16:18:27 +08:00
|
|
|
byte |= BIT(i);
|
2022-02-14 21:37:06 +08:00
|
|
|
}
|
2022-04-27 22:14:08 +08:00
|
|
|
*dbuf8++ = byte;
|
2022-02-14 21:37:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-03-17 16:18:26 +08:00
|
|
|
* drm_fb_xrgb8888_to_mono - Convert XRGB8888 to monochrome
|
|
|
|
* @dst: monochrome destination buffer (0=black, 1=white)
|
2022-02-14 21:37:06 +08:00
|
|
|
* @dst_pitch: Number of bytes between two consecutive scanlines within dst
|
2022-04-04 23:59:36 +08:00
|
|
|
* @vaddr: XRGB8888 source buffer
|
2022-02-14 21:37:06 +08:00
|
|
|
* @fb: DRM framebuffer
|
|
|
|
* @clip: Clip rectangle area to copy
|
|
|
|
*
|
|
|
|
* DRM doesn't have native monochrome support.
|
|
|
|
* Such drivers can announce the commonly supported XR24 format to userspace
|
|
|
|
* and use this function to convert to the native format.
|
|
|
|
*
|
|
|
|
* This function uses drm_fb_xrgb8888_to_gray8() to convert to grayscale and
|
2022-03-17 16:18:26 +08:00
|
|
|
* then the result is converted from grayscale to monochrome.
|
drm/format-helper: Fix XRGB888 to monochrome conversion
The conversion functions drm_fb_xrgb8888_to_mono() and
drm_fb_gray8_to_mono_line() do not behave correctly when the
horizontal boundaries of the clip rectangle are not multiples of 8:
a. When x1 % 8 != 0, the calculated pitch is not correct,
b. When x2 % 8 != 0, the pixel data for the last byte is wrong.
Simplify the code and fix (a) by:
1. Removing start_offset, and always storing the first pixel in the
first bit of the monochrome destination buffer.
Drivers that require the first pixel in a byte to be located at an
x-coordinate that is a multiple of 8 can always align the clip
rectangle before calling drm_fb_xrgb8888_to_mono().
Note that:
- The ssd130x driver does not need the alignment, as the
monochrome buffer is a temporary format,
- The repaper driver always updates the full screen, so the clip
rectangle is always aligned.
2. Passing the number of pixels to drm_fb_gray8_to_mono_line(),
instead of the number of bytes, and the number of pixels in the
last byte.
Fix (b) by explicitly setting the target bit, instead of always setting
bit 7 and shifting the value in each loop iteration.
Remove the bogus pitch check, which operates on bytes instead of pixels,
and triggers when e.g. flashing the cursor on a text console with a font
that is 8 pixels wide.
Drop the confusing comment about scanlines, as a pitch in bytes always
contains a multiple of 8 pixels.
While at it, use the drm_rect_height() helper instead of open-coding the
same operation.
Update the comments accordingly.
Fixes: bcf8b616deb87941 ("drm/format-helper: Add drm_fb_xrgb8888_to_mono_reversed()")
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
Acked-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20220317081830.1211400-3-geert@linux-m68k.org
2022-03-17 16:18:27 +08:00
|
|
|
*
|
|
|
|
* The first pixel (upper left corner of the clip rectangle) will be converted
|
|
|
|
* and copied to the first bit (LSB) in the first byte of the monochrome
|
|
|
|
* destination buffer.
|
|
|
|
* If the caller requires that the first pixel in a byte must be located at an
|
|
|
|
* x-coordinate that is a multiple of 8, then the caller must take care itself
|
|
|
|
* of supplying a suitable clip rectangle.
|
2022-02-14 21:37:06 +08:00
|
|
|
*/
|
2022-03-17 16:18:26 +08:00
|
|
|
void drm_fb_xrgb8888_to_mono(void *dst, unsigned int dst_pitch, const void *vaddr,
|
|
|
|
const struct drm_framebuffer *fb, const struct drm_rect *clip)
|
2022-02-14 21:37:06 +08:00
|
|
|
{
|
|
|
|
unsigned int linepixels = drm_rect_width(clip);
|
drm/format-helper: Fix XRGB888 to monochrome conversion
The conversion functions drm_fb_xrgb8888_to_mono() and
drm_fb_gray8_to_mono_line() do not behave correctly when the
horizontal boundaries of the clip rectangle are not multiples of 8:
a. When x1 % 8 != 0, the calculated pitch is not correct,
b. When x2 % 8 != 0, the pixel data for the last byte is wrong.
Simplify the code and fix (a) by:
1. Removing start_offset, and always storing the first pixel in the
first bit of the monochrome destination buffer.
Drivers that require the first pixel in a byte to be located at an
x-coordinate that is a multiple of 8 can always align the clip
rectangle before calling drm_fb_xrgb8888_to_mono().
Note that:
- The ssd130x driver does not need the alignment, as the
monochrome buffer is a temporary format,
- The repaper driver always updates the full screen, so the clip
rectangle is always aligned.
2. Passing the number of pixels to drm_fb_gray8_to_mono_line(),
instead of the number of bytes, and the number of pixels in the
last byte.
Fix (b) by explicitly setting the target bit, instead of always setting
bit 7 and shifting the value in each loop iteration.
Remove the bogus pitch check, which operates on bytes instead of pixels,
and triggers when e.g. flashing the cursor on a text console with a font
that is 8 pixels wide.
Drop the confusing comment about scanlines, as a pitch in bytes always
contains a multiple of 8 pixels.
While at it, use the drm_rect_height() helper instead of open-coding the
same operation.
Update the comments accordingly.
Fixes: bcf8b616deb87941 ("drm/format-helper: Add drm_fb_xrgb8888_to_mono_reversed()")
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
Acked-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20220317081830.1211400-3-geert@linux-m68k.org
2022-03-17 16:18:27 +08:00
|
|
|
unsigned int lines = drm_rect_height(clip);
|
2022-02-14 21:37:06 +08:00
|
|
|
unsigned int cpp = fb->format->cpp[0];
|
|
|
|
unsigned int len_src32 = linepixels * cpp;
|
|
|
|
struct drm_device *dev = fb->dev;
|
|
|
|
unsigned int y;
|
|
|
|
u8 *mono = dst, *gray8;
|
|
|
|
u32 *src32;
|
|
|
|
|
|
|
|
if (drm_WARN_ON(dev, fb->format->format != DRM_FORMAT_XRGB8888))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
drm/format-helper: Fix XRGB888 to monochrome conversion
The conversion functions drm_fb_xrgb8888_to_mono() and
drm_fb_gray8_to_mono_line() do not behave correctly when the
horizontal boundaries of the clip rectangle are not multiples of 8:
a. When x1 % 8 != 0, the calculated pitch is not correct,
b. When x2 % 8 != 0, the pixel data for the last byte is wrong.
Simplify the code and fix (a) by:
1. Removing start_offset, and always storing the first pixel in the
first bit of the monochrome destination buffer.
Drivers that require the first pixel in a byte to be located at an
x-coordinate that is a multiple of 8 can always align the clip
rectangle before calling drm_fb_xrgb8888_to_mono().
Note that:
- The ssd130x driver does not need the alignment, as the
monochrome buffer is a temporary format,
- The repaper driver always updates the full screen, so the clip
rectangle is always aligned.
2. Passing the number of pixels to drm_fb_gray8_to_mono_line(),
instead of the number of bytes, and the number of pixels in the
last byte.
Fix (b) by explicitly setting the target bit, instead of always setting
bit 7 and shifting the value in each loop iteration.
Remove the bogus pitch check, which operates on bytes instead of pixels,
and triggers when e.g. flashing the cursor on a text console with a font
that is 8 pixels wide.
Drop the confusing comment about scanlines, as a pitch in bytes always
contains a multiple of 8 pixels.
While at it, use the drm_rect_height() helper instead of open-coding the
same operation.
Update the comments accordingly.
Fixes: bcf8b616deb87941 ("drm/format-helper: Add drm_fb_xrgb8888_to_mono_reversed()")
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
Acked-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20220317081830.1211400-3-geert@linux-m68k.org
2022-03-17 16:18:27 +08:00
|
|
|
* The mono destination buffer contains 1 bit per pixel
|
2022-02-14 21:37:06 +08:00
|
|
|
*/
|
|
|
|
if (!dst_pitch)
|
|
|
|
dst_pitch = DIV_ROUND_UP(linepixels, 8);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The cma memory is write-combined so reads are uncached.
|
|
|
|
* Speed up by fetching one line at a time.
|
|
|
|
*
|
2022-03-17 16:18:26 +08:00
|
|
|
* Also, format conversion from XR24 to monochrome are done
|
|
|
|
* line-by-line but are converted to 8-bit grayscale as an
|
|
|
|
* intermediate step.
|
2022-02-14 21:37:06 +08:00
|
|
|
*
|
|
|
|
* Allocate a buffer to be used for both copying from the cma
|
|
|
|
* memory and to store the intermediate grayscale line pixels.
|
|
|
|
*/
|
|
|
|
src32 = kmalloc(len_src32 + linepixels, GFP_KERNEL);
|
|
|
|
if (!src32)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gray8 = (u8 *)src32 + len_src32;
|
|
|
|
|
|
|
|
vaddr += clip_offset(clip, fb->pitches[0], cpp);
|
|
|
|
for (y = 0; y < lines; y++) {
|
|
|
|
src32 = memcpy(src32, vaddr, len_src32);
|
|
|
|
drm_fb_xrgb8888_to_gray8_line(gray8, src32, linepixels);
|
drm/format-helper: Fix XRGB888 to monochrome conversion
The conversion functions drm_fb_xrgb8888_to_mono() and
drm_fb_gray8_to_mono_line() do not behave correctly when the
horizontal boundaries of the clip rectangle are not multiples of 8:
a. When x1 % 8 != 0, the calculated pitch is not correct,
b. When x2 % 8 != 0, the pixel data for the last byte is wrong.
Simplify the code and fix (a) by:
1. Removing start_offset, and always storing the first pixel in the
first bit of the monochrome destination buffer.
Drivers that require the first pixel in a byte to be located at an
x-coordinate that is a multiple of 8 can always align the clip
rectangle before calling drm_fb_xrgb8888_to_mono().
Note that:
- The ssd130x driver does not need the alignment, as the
monochrome buffer is a temporary format,
- The repaper driver always updates the full screen, so the clip
rectangle is always aligned.
2. Passing the number of pixels to drm_fb_gray8_to_mono_line(),
instead of the number of bytes, and the number of pixels in the
last byte.
Fix (b) by explicitly setting the target bit, instead of always setting
bit 7 and shifting the value in each loop iteration.
Remove the bogus pitch check, which operates on bytes instead of pixels,
and triggers when e.g. flashing the cursor on a text console with a font
that is 8 pixels wide.
Drop the confusing comment about scanlines, as a pitch in bytes always
contains a multiple of 8 pixels.
While at it, use the drm_rect_height() helper instead of open-coding the
same operation.
Update the comments accordingly.
Fixes: bcf8b616deb87941 ("drm/format-helper: Add drm_fb_xrgb8888_to_mono_reversed()")
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
Acked-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20220317081830.1211400-3-geert@linux-m68k.org
2022-03-17 16:18:27 +08:00
|
|
|
drm_fb_gray8_to_mono_line(mono, gray8, linepixels);
|
2022-02-14 21:37:06 +08:00
|
|
|
vaddr += fb->pitches[0];
|
|
|
|
mono += dst_pitch;
|
|
|
|
}
|
|
|
|
|
|
|
|
kfree(src32);
|
|
|
|
}
|
2022-03-17 16:18:26 +08:00
|
|
|
EXPORT_SYMBOL(drm_fb_xrgb8888_to_mono);
|