From: Daniel Vetter <daniel@ffwll.ch>
To: "Noralf Trønnes" <noralf@tronnes.org>
Cc: Daniel Vetter <daniel@ffwll.ch>,
dri-devel@lists.freedesktop.org, peter@stuge.se,
linus.walleij@linaro.org, Thomas Zimmermann <tzimmermann@suse.de>
Subject: Re: [PATCH 2/7] drm/format-helper: Add drm_fb_xrgb8888_to_rgb332()
Date: Thu, 2 Sep 2021 16:24:09 +0200 [thread overview]
Message-ID: <YTDeibTXOvMzRV0P@phenom.ffwll.local> (raw)
In-Reply-To: <848f5d65-8bad-0d69-18dd-ae81549283b4@tronnes.org>
On Thu, Sep 02, 2021 at 04:08:14PM +0200, Noralf Trønnes wrote:
>
>
> Den 31.08.2021 14.23, skrev Daniel Vetter:
> > On Mon, Aug 30, 2021 at 02:08:14PM +0200, Noralf Trønnes wrote:
> >>
> >>
> >> Den 17.08.2021 15.56, skrev Daniel Vetter:
> >>> On Tue, Aug 17, 2021 at 02:29:12PM +0200, Noralf Trønnes wrote:
> >>>> Add XRGB8888 emulation support for devices that can only do RGB332.
> >>>>
> >>>> Cc: Thomas Zimmermann <tzimmermann@suse.de>
> >>>> Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
> >>>> ---
> >>>> drivers/gpu/drm/drm_format_helper.c | 47 +++++++++++++++++++++++++++++
> >>>> include/drm/drm_format_helper.h | 2 ++
> >>>> 2 files changed, 49 insertions(+)
> >>>>
> >>>> diff --git a/drivers/gpu/drm/drm_format_helper.c b/drivers/gpu/drm/drm_format_helper.c
> >>>> index 5231104b1498..53b426da7467 100644
> >>>> --- a/drivers/gpu/drm/drm_format_helper.c
> >>>> +++ b/drivers/gpu/drm/drm_format_helper.c
> >>>> @@ -135,6 +135,53 @@ void drm_fb_swab(void *dst, void *src, struct drm_framebuffer *fb,
> >>>> }
> >>>> EXPORT_SYMBOL(drm_fb_swab);
> >>>>
> >>>> +static void drm_fb_xrgb8888_to_rgb332_line(u8 *dbuf, u32 *sbuf, unsigned int pixels)
> >>>> +{
> >>>> + unsigned int x;
> >>>> +
> >>>> + for (x = 0; x < pixels; x++)
> >>>> + dbuf[x] = ((sbuf[x] & 0x00e00000) >> 16) |
> >>>
> >>> I think for 2/3 bits correct rounding would be useful, not just masking.
> >>> i.e. before you shift add 0x00100000 here, and similar below.
> >>>
> >>
> >> Math isn't my strongest side and my brain failed to turn this into code.
> >
> > Essentially add half of the lowest bit before you mask, so
> >
> > ((sbuf[x] + 0x10) & 0xe0 )
> >
>
> But what if the value is 0xff, it overflows:
Your math is better than mine ...
> ((0xff + 0x10) & 0xe0 ) == 0x00
>
> Should it be OR?
>
> ((0xff | 0x10) & 0xe0 ) == 0xe0
Probably need a max on top to limit the overflow:
max(sbuf[x] + 0x10, 0xe)
But also maybe really not worth the head-scratching :-)
-Daniel
>
> Noralf.
>
> > I dropped the shift to make it clear what's going on. If you're mask is
> > 0xc0, then you simply add 0x20 before masking.
> >
> >>> Also I just realized we've totally ignored endianess on these, which is
> >>> not great, because strictly speaking all the drm_fourcc codes should be
> >>> little endian. But I'm also not sure that's worth fixing ...
> >>>
> >>
> >> Is it as simple as using le32_to_cpu()?
> >
> > I think so.
> >
> > Plus on any format that has u16 output we'd need a cpu_to_le16 wrapped
> > around the entire thing.
> > -Daniel
> >
> >> static void drm_fb_xrgb8888_to_rgb332_line(u8 *dbuf, __le32 *sbuf,
> >> unsigned int pixels)
> >> {
> >> unsigned int x;
> >> u32 pix;
> >>
> >> for (x = 0; x < pixels; x++) {
> >> pix = le32_to_cpu(sbuf[x]);
> >> dbuf[x] = ((pix & 0x00e00000) >> 16) |
> >> ((pix & 0x0000e000) >> 11) |
> >> ((pix & 0x000000c0) >> 6);
> >> }
> >> }
> >>
> >> Noralf.
> >>
> >>> Either way, lgtm:
> >>>
> >>> Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
> >>>
> >>>> + ((sbuf[x] & 0x0000e000) >> 11) |
> >>>> + ((sbuf[x] & 0x000000c0) >> 6);
> >>>> +}
> >>>> +
> >>>> +/**
> >>>> + * drm_fb_xrgb8888_to_rgb332 - Convert XRGB8888 to RGB332 clip buffer
> >>>> + * @dst: RGB332 destination buffer
> >>>> + * @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.
> >>>> + *
> >>>> + * This function does not apply clipping on dst, i.e. the destination is a small buffer
> >>>> + * containing the clip rect only.
> >>>> + */
> >>>> +void drm_fb_xrgb8888_to_rgb332(void *dst, void *src, struct drm_framebuffer *fb,
> >>>> + struct drm_rect *clip)
> >>>> +{
> >>>> + size_t width = drm_rect_width(clip);
> >>>> + size_t src_len = width * sizeof(u32);
> >>>> + unsigned int y;
> >>>> + void *sbuf;
> >>>> +
> >>>> + /* 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_rgb332_line(dst, sbuf, width);
> >>>> + src += fb->pitches[0];
> >>>> + dst += width;
> >>>> + }
> >>>> +
> >>>> + kfree(sbuf);
> >>>> +}
> >>>> +EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgb332);
> >>>> +
> >>>> static void drm_fb_xrgb8888_to_rgb565_line(u16 *dbuf, u32 *sbuf,
> >>>> unsigned int pixels,
> >>>> bool swab)
> >>>> diff --git a/include/drm/drm_format_helper.h b/include/drm/drm_format_helper.h
> >>>> index 4e0258a61311..d0809aff5cf8 100644
> >>>> --- a/include/drm/drm_format_helper.h
> >>>> +++ b/include/drm/drm_format_helper.h
> >>>> @@ -16,6 +16,8 @@ void drm_fb_memcpy_dstclip(void __iomem *dst, unsigned int dst_pitch, void *vadd
> >>>> struct drm_rect *clip);
> >>>> void drm_fb_swab(void *dst, void *src, struct drm_framebuffer *fb,
> >>>> struct drm_rect *clip, bool cached);
> >>>> +void drm_fb_xrgb8888_to_rgb332(void *dst, void *vaddr, struct drm_framebuffer *fb,
> >>>> + struct drm_rect *clip);
> >>>> void drm_fb_xrgb8888_to_rgb565(void *dst, void *vaddr,
> >>>> struct drm_framebuffer *fb,
> >>>> struct drm_rect *clip, bool swab);
> >>>> --
> >>>> 2.32.0
> >>>>
> >>>
> >
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
next prev parent reply other threads:[~2021-09-02 14:24 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-17 12:29 [PATCH 0/7] drm/gud: Add some more pixel formats Noralf Trønnes
2021-08-17 12:29 ` [PATCH 1/7] drm/fourcc: Add R8 to drm_format_info Noralf Trønnes
2021-08-17 13:59 ` Daniel Vetter
2021-08-17 14:17 ` Daniel Vetter
2021-08-17 12:29 ` [PATCH 2/7] drm/format-helper: Add drm_fb_xrgb8888_to_rgb332() Noralf Trønnes
2021-08-17 13:56 ` Daniel Vetter
2021-08-17 16:03 ` Peter Stuge
2021-08-30 12:08 ` Noralf Trønnes
2021-08-31 12:23 ` Daniel Vetter
2021-09-02 14:08 ` Noralf Trønnes
2021-09-02 14:24 ` Daniel Vetter [this message]
2021-08-17 12:29 ` [PATCH 3/7] drm/format-helper: Add drm_fb_xrgb8888_to_rgb888() Noralf Trønnes
2021-08-17 14:05 ` Daniel Vetter
2021-08-17 12:29 ` [PATCH 4/7] drm/gud: Add GUD_PIXEL_FORMAT_R8 Noralf Trønnes
2021-08-17 12:29 ` [PATCH 5/7] drm/gud: Add GUD_PIXEL_FORMAT_RGB332 Noralf Trønnes
2021-08-17 12:29 ` [PATCH 6/7] drm/gud: Add GUD_PIXEL_FORMAT_RGB888 Noralf Trønnes
2021-08-17 12:29 ` [PATCH 7/7] drm/gud: Add module parameter to control emulation: xrgb8888 Noralf Trønnes
2021-08-17 13:49 ` Daniel Vetter
2021-08-17 14:12 ` Noralf Trønnes
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=YTDeibTXOvMzRV0P@phenom.ffwll.local \
--to=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=linus.walleij@linaro.org \
--cc=noralf@tronnes.org \
--cc=peter@stuge.se \
--cc=tzimmermann@suse.de \
/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