linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Zimmermann <tzimmermann@suse.de>
To: "Aditya Garg" <gargaditya08@live.com>,
	"maarten.lankhorst@linux.intel.com"
	<maarten.lankhorst@linux.intel.com>,
	"mripard@kernel.org" <mripard@kernel.org>,
	"airlied@gmail.com" <airlied@gmail.com>,
	"daniel@ffwll.ch" <daniel@ffwll.ch>,
	"Jiri Kosina" <jikos@kernel.org>,
	"bentiss@kernel.org" <bentiss@kernel.org>,
	"Thomas Weißschuh" <thomas@t-8ch.de>
Cc: Orlando Chamberlain <orlandoch.dev@gmail.com>,
	Kerem Karabay <kekrby@gmail.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	"linux-input@vger.kernel.org" <linux-input@vger.kernel.org>,
	"dri-devel@lists.freedesktop.org"
	<dri-devel@lists.freedesktop.org>
Subject: Re: [PATCH v5 9/10] drm/format-helper: Add conversion from XRGB8888 to BGR888
Date: Fri, 27 Sep 2024 09:52:29 +0200	[thread overview]
Message-ID: <32f5a048-47cb-45f7-9140-25b089c81628@suse.de> (raw)
In-Reply-To: <ECFD946D-2DCD-46DE-A86C-616496D1ACE7@live.com>

Hi

Am 17.08.24 um 13:51 schrieb Aditya Garg:
> From: Kerem Karabay <kekrby@gmail.com>
>
> Add XRGB8888 emulation helper for devices that only support BGR888.
>
> Signed-off-by: Kerem Karabay <kekrby@gmail.com>
> Signed-off-by: Aditya Garg <gargaditya08@live.com>
> ---
>   drivers/gpu/drm/drm_format_helper.c           | 54 +++++++++++++
>   .../gpu/drm/tests/drm_format_helper_test.c    | 81 +++++++++++++++++++
>   include/drm/drm_format_helper.h               |  3 +
>   3 files changed, 138 insertions(+)
>
> diff --git a/drivers/gpu/drm/drm_format_helper.c b/drivers/gpu/drm/drm_format_helper.c
> index b1be458ed..28c0e76a1 100644
> --- a/drivers/gpu/drm/drm_format_helper.c
> +++ b/drivers/gpu/drm/drm_format_helper.c
> @@ -702,6 +702,57 @@ void drm_fb_xrgb8888_to_rgb888(struct iosys_map *dst, const unsigned int *dst_pi
>   }
>   EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgb888);
>   
> +static void drm_fb_xrgb8888_to_bgr888_line(void *dbuf, const void *sbuf, unsigned int pixels)
> +{
> +	u8 *dbuf8 = dbuf;
> +	const __le32 *sbuf32 = sbuf;
> +	unsigned int x;
> +	u32 pix;
> +
> +	for (x = 0; x < pixels; x++) {
> +		pix = le32_to_cpu(sbuf32[x]);
> +		/* write red-green-blue to output in little endianness */
> +		*dbuf8++ = (pix & 0x00FF0000) >> 16;
> +		*dbuf8++ = (pix & 0x0000FF00) >> 8;
> +		*dbuf8++ = (pix & 0x000000FF) >> 0;

I know the file is inconsistent, but I'd prefer lower-case numbers 
(0xff) here. Apart from that

Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>

Best regards
Thomas

> +	}
> +}
> +
> +/**
> + * drm_fb_xrgb8888_to_bgr888 - Convert XRGB8888 to BGR888 clip buffer
> + * @dst: Array of BGR888 destination buffers
> + * @dst_pitch: Array of numbers of bytes between the start of two consecutive scanlines
> + *             within @dst; can be NULL if scanlines are stored next to each other.
> + * @src: Array of XRGB8888 source buffers
> + * @fb: DRM framebuffer
> + * @clip: Clip rectangle area to copy
> + * @state: Transform and conversion state
> + *
> + * This function copies parts of a framebuffer to display memory and converts the
> + * color format during the process. Destination and framebuffer formats must match. The
> + * parameters @dst, @dst_pitch and @src refer to arrays. Each array must have at
> + * least as many entries as there are planes in @fb's format. Each entry stores the
> + * value for the format's respective color plane at the same index.
> + *
> + * This function does not apply clipping on @dst (i.e. the destination is at the
> + * top-left corner).
> + *
> + * Drivers can use this function for BGR888 devices that don't natively
> + * support XRGB8888.
> + */
> +void drm_fb_xrgb8888_to_bgr888(struct iosys_map *dst, const unsigned int *dst_pitch,
> +			       const struct iosys_map *src, const struct drm_framebuffer *fb,
> +			       const struct drm_rect *clip, struct drm_format_conv_state *state)
> +{
> +	static const u8 dst_pixsize[DRM_FORMAT_MAX_PLANES] = {
> +		3,
> +	};
> +
> +	drm_fb_xfrm(dst, dst_pitch, dst_pixsize, src, fb, clip, false, state,
> +		    drm_fb_xrgb8888_to_bgr888_line);
> +}
> +EXPORT_SYMBOL(drm_fb_xrgb8888_to_bgr888);
> +
>   static void drm_fb_xrgb8888_to_argb8888_line(void *dbuf, const void *sbuf, unsigned int pixels)
>   {
>   	__le32 *dbuf32 = dbuf;
> @@ -1035,6 +1086,9 @@ int drm_fb_blit(struct iosys_map *dst, const unsigned int *dst_pitch, uint32_t d
>   		} else if (dst_format == DRM_FORMAT_RGB888) {
>   			drm_fb_xrgb8888_to_rgb888(dst, dst_pitch, src, fb, clip, state);
>   			return 0;
> +		} else if (dst_format == DRM_FORMAT_BGR888) {
> +			drm_fb_xrgb8888_to_bgr888(dst, dst_pitch, src, fb, clip, state);
> +			return 0;
>   		} else if (dst_format == DRM_FORMAT_ARGB8888) {
>   			drm_fb_xrgb8888_to_argb8888(dst, dst_pitch, src, fb, clip, state);
>   			return 0;
> diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c
> index 08992636e..35cd3405d 100644
> --- a/drivers/gpu/drm/tests/drm_format_helper_test.c
> +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c
> @@ -60,6 +60,11 @@ struct convert_to_rgb888_result {
>   	const u8 expected[TEST_BUF_SIZE];
>   };
>   
> +struct convert_to_bgr888_result {
> +	unsigned int dst_pitch;
> +	const u8 expected[TEST_BUF_SIZE];
> +};
> +
>   struct convert_to_argb8888_result {
>   	unsigned int dst_pitch;
>   	const u32 expected[TEST_BUF_SIZE];
> @@ -107,6 +112,7 @@ struct convert_xrgb8888_case {
>   	struct convert_to_argb1555_result argb1555_result;
>   	struct convert_to_rgba5551_result rgba5551_result;
>   	struct convert_to_rgb888_result rgb888_result;
> +	struct convert_to_bgr888_result bgr888_result;
>   	struct convert_to_argb8888_result argb8888_result;
>   	struct convert_to_xrgb2101010_result xrgb2101010_result;
>   	struct convert_to_argb2101010_result argb2101010_result;
> @@ -151,6 +157,10 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
>   			.dst_pitch = TEST_USE_DEFAULT_PITCH,
>   			.expected = { 0x00, 0x00, 0xFF },
>   		},
> +		.bgr888_result = {
> +			.dst_pitch = TEST_USE_DEFAULT_PITCH,
> +			.expected = { 0xFF, 0x00, 0x00 },
> +		},
>   		.argb8888_result = {
>   			.dst_pitch = TEST_USE_DEFAULT_PITCH,
>   			.expected = { 0xFFFF0000 },
> @@ -217,6 +227,10 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
>   			.dst_pitch = TEST_USE_DEFAULT_PITCH,
>   			.expected = { 0x00, 0x00, 0xFF },
>   		},
> +		.bgr888_result = {
> +			.dst_pitch = TEST_USE_DEFAULT_PITCH,
> +			.expected = { 0xFF, 0x00, 0x00 },
> +		},
>   		.argb8888_result = {
>   			.dst_pitch = TEST_USE_DEFAULT_PITCH,
>   			.expected = { 0xFFFF0000 },
> @@ -330,6 +344,15 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
>   				0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00,
>   			},
>   		},
> +		.bgr888_result = {
> +			.dst_pitch = TEST_USE_DEFAULT_PITCH,
> +			.expected = {
> +				0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00,
> +				0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00,
> +				0x00, 0x00, 0xFF, 0xFF, 0x00, 0xFF,
> +				0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF,
> +			},
> +		},
>   		.argb8888_result = {
>   			.dst_pitch = TEST_USE_DEFAULT_PITCH,
>   			.expected = {
> @@ -468,6 +491,17 @@ static struct convert_xrgb8888_case convert_xrgb8888_cases[] = {
>   				0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
>   			},
>   		},
> +		.bgr888_result = {
> +			.dst_pitch = 15,
> +			.expected = {
> +				0x0E, 0x44, 0x9C, 0x11, 0x4D, 0x05, 0xA8, 0xF3, 0x03,
> +				0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> +				0x6C, 0xF0, 0x73, 0x0E, 0x44, 0x9C, 0x11, 0x4D, 0x05,
> +				0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> +				0xA8, 0x03, 0x03, 0x6C, 0xF0, 0x73, 0x0E, 0x44, 0x9C,
> +				0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
> +			},
> +		},
>   		.argb8888_result = {
>   			.dst_pitch = 20,
>   			.expected = {
> @@ -914,6 +948,52 @@ static void drm_test_fb_xrgb8888_to_rgb888(struct kunit *test)
>   	KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
>   }
>   
> +static void drm_test_fb_xrgb8888_to_bgr888(struct kunit *test)
> +{
> +	const struct convert_xrgb8888_case *params = test->param_value;
> +	const struct convert_to_bgr888_result *result = &params->bgr888_result;
> +	size_t dst_size;
> +	u8 *buf = NULL;
> +	__le32 *xrgb8888 = NULL;
> +	struct iosys_map dst, src;
> +
> +	struct drm_framebuffer fb = {
> +		.format = drm_format_info(DRM_FORMAT_XRGB8888),
> +		.pitches = { params->pitch, 0, 0 },
> +	};
> +
> +	dst_size = conversion_buf_size(DRM_FORMAT_BGR888, result->dst_pitch,
> +				       &params->clip, 0);
> +	KUNIT_ASSERT_GT(test, dst_size, 0);
> +
> +	buf = kunit_kzalloc(test, dst_size, GFP_KERNEL);
> +	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, buf);
> +	iosys_map_set_vaddr(&dst, buf);
> +
> +	xrgb8888 = cpubuf_to_le32(test, params->xrgb8888, TEST_BUF_SIZE);
> +	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xrgb8888);
> +	iosys_map_set_vaddr(&src, xrgb8888);
> +
> +	/*
> +	 * BGR888 expected results are already in little-endian
> +	 * order, so there's no need to convert the test output.
> +	 */
> +	drm_fb_xrgb8888_to_bgr888(&dst, &result->dst_pitch, &src, &fb, &params->clip,
> +				  &fmtcnv_state);
> +	KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
> +
> +	buf = dst.vaddr; /* restore original value of buf */
> +	memset(buf, 0, dst_size);
> +
> +	int blit_result = 0;
> +
> +	blit_result = drm_fb_blit(&dst, &result->dst_pitch, DRM_FORMAT_BGR888, &src, &fb, &params->clip,
> +				  &fmtcnv_state);
> +
> +	KUNIT_EXPECT_FALSE(test, blit_result);
> +	KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
> +}
> +
>   static void drm_test_fb_xrgb8888_to_argb8888(struct kunit *test)
>   {
>   	const struct convert_xrgb8888_case *params = test->param_value;
> @@ -1851,6 +1931,7 @@ static struct kunit_case drm_format_helper_test_cases[] = {
>   	KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_argb1555, convert_xrgb8888_gen_params),
>   	KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_rgba5551, convert_xrgb8888_gen_params),
>   	KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_rgb888, convert_xrgb8888_gen_params),
> +	KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_bgr888, convert_xrgb8888_gen_params),
>   	KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_argb8888, convert_xrgb8888_gen_params),
>   	KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_xrgb2101010, convert_xrgb8888_gen_params),
>   	KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_argb2101010, convert_xrgb8888_gen_params),
> diff --git a/include/drm/drm_format_helper.h b/include/drm/drm_format_helper.h
> index 428d81afe..aa1604d92 100644
> --- a/include/drm/drm_format_helper.h
> +++ b/include/drm/drm_format_helper.h
> @@ -96,6 +96,9 @@ void drm_fb_xrgb8888_to_rgba5551(struct iosys_map *dst, const unsigned int *dst_
>   void drm_fb_xrgb8888_to_rgb888(struct iosys_map *dst, const unsigned int *dst_pitch,
>   			       const struct iosys_map *src, const struct drm_framebuffer *fb,
>   			       const struct drm_rect *clip, struct drm_format_conv_state *state);
> +void drm_fb_xrgb8888_to_bgr888(struct iosys_map *dst, const unsigned int *dst_pitch,
> +			       const struct iosys_map *src, const struct drm_framebuffer *fb,
> +			       const struct drm_rect *clip, struct drm_format_conv_state *state);
>   void drm_fb_xrgb8888_to_argb8888(struct iosys_map *dst, const unsigned int *dst_pitch,
>   				 const struct iosys_map *src, const struct drm_framebuffer *fb,
>   				 const struct drm_rect *clip, struct drm_format_conv_state *state);

-- 
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)


  reply	other threads:[~2024-09-27  7:52 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-17 11:44 [PATCH v5 0/10] Touch Bar support for T2 Macs Aditya Garg
2024-08-17 11:45 ` [PATCH v5 1/10] HID: hid-appletb-bl: add driver for the backlight of Apple Touch Bars Aditya Garg
2024-08-17 11:46 ` [PATCH v5 2/10] HID: hid-appletb-kbd: add driver for the keyboard mode Aditya Garg
2024-09-27 15:39   ` Benjamin Tissoires
2024-09-28  5:56     ` Aditya Garg
2024-08-17 11:47 ` [PATCH v5 3/10] HID: hid-appletb-kbd: add support for fn toggle between media and function mode Aditya Garg
2024-08-17 11:48 ` [PATCH v5 4/10] HID: multitouch: support getting the contact ID from HID_DG_TRANSDUCER_INDEX fields Aditya Garg
2024-09-27 15:56   ` Benjamin Tissoires
2024-08-17 11:48 ` [PATCH v5 5/10] HID: multitouch: support getting the tip state from HID_DG_TOUCH fields Aditya Garg
2024-08-17 11:49 ` [PATCH v5 6/10] HID: multitouch: take cls->maxcontacts into account for devices without a HID_DG_CONTACTMAX field too Aditya Garg
2024-08-17 11:50 ` [PATCH v5 7/10] HID: multitouch: allow specifying if a device is direct in a class Aditya Garg
2024-09-27 15:59   ` Benjamin Tissoires
2024-08-17 11:50 ` [PATCH v5 8/10] HID: multitouch: add device ID for Apple Touch Bars Aditya Garg
2024-08-17 11:51 ` [PATCH v5 9/10] drm/format-helper: Add conversion from XRGB8888 to BGR888 Aditya Garg
2024-09-27  7:52   ` Thomas Zimmermann [this message]
2024-08-17 11:52 ` [PATCH v5 10/10] drm/tiny: add driver for Apple Touch Bars in x86 Macs Aditya Garg
2024-09-27  7:42   ` mripard
2024-09-27 16:48     ` Aditya Garg
2024-09-27  7:48   ` Thomas Zimmermann
2024-09-27 16:49     ` Aditya Garg
2025-02-15 13:43     ` [RFC PATCH " Aditya Garg
2025-02-17  8:04       ` Thomas Zimmermann
2025-02-17 11:43         ` Aditya Garg
2024-08-31 12:37 ` [PATCH v5 0/10] Touch Bar support for T2 Macs Aditya Garg
2024-09-11 12:21   ` Jiri Kosina
2024-09-17 10:06     ` [PATCH v5 0/10] [DRM REVIEW NEEDED] " Aditya Garg
2024-09-26 17:50     ` [WHY SUCH DELAY!] " Aditya Garg
2024-09-26 18:03       ` Jiri Kosina
2024-09-26 18:05         ` Aditya Garg
2024-09-26 18:11           ` Jiri Kosina
2024-09-26 20:37         ` Dave Airlie
2024-09-26 20:39           ` Jiri Kosina
2024-09-27 15:22       ` Benjamin Tissoires
2024-09-27 16:42         ` Aditya Garg

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=32f5a048-47cb-45f7-9140-25b089c81628@suse.de \
    --to=tzimmermann@suse.de \
    --cc=airlied@gmail.com \
    --cc=bentiss@kernel.org \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gargaditya08@live.com \
    --cc=jikos@kernel.org \
    --cc=kekrby@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=orlandoch.dev@gmail.com \
    --cc=thomas@t-8ch.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;
as well as URLs for NNTP newsgroup(s).