From nobody Tue Feb 10 01:30:55 2026 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B74C76E2AE for ; Wed, 14 Aug 2024 08:19:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.198 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723623591; cv=none; b=bF2m0Ozjm8yOXXVLLTk4fc9s14DLmwSONYw2Ej2SSw4NiexVoR13+lNqDCeC52RGjmJ2deP8Yfi5FfFUaIrTPQzKvR2ibrNB8Eptggqr6KjDAxxlQ7hbVfctzHnO5vvvTuHNdnfqITjJsQTfY+0avV2f7A4FNmjGC0dnSyRWJ10= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723623591; c=relaxed/simple; bh=61wrT+opDbJNU/QfX9tV7dco/mpoqSN98WVUgQF83xs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KV4jnZw1Ji0DWOzVdUPbC6J97E2RD1hst5y6jZyQinF/6VQ77oDpxOCZpYWpGvCycsixpEHk0RH2s16M6sQjd4fYyQOJ1dXEvqD1a0967LvpggKvd+BcYgC3mSc38FSHSR1jg5zDgf40E+sjlT+H7j9nH9C8jvdT63ML9hy5nww= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=PKRFQmdQ; arc=none smtp.client-ip=217.70.183.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="PKRFQmdQ" Received: by mail.gandi.net (Postfix) with ESMTPSA id A23DDC0009; Wed, 14 Aug 2024 08:19:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1723623586; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bu6viIhSnWEgk66jXAPqJNV5YI/xtHGtsXjAa8vmFoY=; b=PKRFQmdQqPk5Sa8ROniRn1YIFSYcSpDb0BUM71GUHjXjTlau2MS6Eru9r7MW4Ca0fZnEoC 7C2/bZO59SjkTPXIol30Lzfz3+2BFpIY2G2afNZ4UG/R1bPV0CqJPOdQduSjQZpJVQnum4 BES7KTmVC2cyR8c62V/RemxbKhjHVGeXRnUxUEx67dD52cydJWqEdksDy6czON2O3i5plc WyyUpSgsJJrF/l5gicoJ0+GCquZnX50if3pzVvsJir36a7ZZ0+swSaS7UixaUlQ9fi+8P9 5GO5vKRZTlaJWqthmcPr0FXp0cjneTazykaQqgyOD8eDR18zn7GJw1rUvJeKfw== From: Louis Chauvet Date: Wed, 14 Aug 2024 10:19:34 +0200 Subject: [PATCH v2 1/8] drm/vkms: Create helpers macro to avoid code duplication in format callbacks Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240814-b4-new-color-formats-v2-1-8b3499cfe90e@bootlin.com> References: <20240814-b4-new-color-formats-v2-0-8b3499cfe90e@bootlin.com> In-Reply-To: <20240814-b4-new-color-formats-v2-0-8b3499cfe90e@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie Cc: dri-devel@lists.freedesktop.org, arthurgrillo@riseup.net, linux-kernel@vger.kernel.org, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, marcheu@google.com, nicolejadeyee@google.com, Louis Chauvet , 20240809-yuv-v10-0-1a7c764166f7@bootlin.com X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=7762; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=61wrT+opDbJNU/QfX9tV7dco/mpoqSN98WVUgQF83xs=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBmvGiewd7aiG/MsG8j8TbEvGKXALbY0rBr8W0C0 PK6KpqqXHSJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZrxongAKCRAgrS7GWxAs 4jI0D/9M8Ia0bPO1onu5fapA0CKsoSdQZCLNbZoEqSMTtHVAKPabrNPKtv1r3TxKdVsOpA8TWqj +LdBIDe+R1eJMMwM0s+VeGcv/1owgdVPFe8BfFFWoGLNoC9rtfMnEXi+Msv/n9wqXKPKwKdehF/ SjxePici57dWhvqEONYugJc11go20GVvn031cTykKUsfHk7t2Nnr+qMfruKiHCirAPuQx/bcMSq YZc8SHBkAP+8/6Z+wRQPCgNcNf7m3BeXfi3gpmZS07ZBvAEImUvJoDVhK9upgbPup/Ym5EZ3WaB KI5Jr4oHUbGD3b1imCoh3Yt6vqrfoaY1CVEK3dJQpSMrwjYzL/vvSVYcDqTIJ9IoFZhjq1RNOtb nKVXymkGVhgN8GCz5JtYisfeIzXX0xB/WGRAehwi9k+oNr2VW4aCzmelWvlU5grEXt+TML57wgv CEpuSH0X617AKCjYE2tamRVBvp1S4EfFrlqmASOv4cj0m/2+c07wm7SH6QIA7+2k6f293zinxE5 xtPl4X4eAJWZ5n8416W3fo3dqeEdvN/HktqH2F1UA1pB2w926H5dRHVQzne6Ks5mDvm7KyU1i/N Mzuv3JM4W4exTnDgxvL3rqWBKOD4Zom1TSxMD582PxFL/xhXNn9F6aP42ljl8CtARfGxT+M4gyU DxSGxZenJ4kjqcg== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com The callback functions for line conversion are almost identical for some format. The generic READ_LINE macro generate all the required boilerplate to process a line. Two overrides of this macro have been added to avoid duplication of the same arguments every time. Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_formats.c | 163 +++++++++++++-------------------= ---- 1 file changed, 58 insertions(+), 105 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_formats.c b/drivers/gpu/drm/vkms/vkm= s_formats.c index 3065086a7ea4..a03e07874b9f 100644 --- a/drivers/gpu/drm/vkms/vkms_formats.c +++ b/drivers/gpu/drm/vkms/vkms_formats.c @@ -290,6 +290,58 @@ VISIBLE_IF_KUNIT struct pixel_argb_u16 argb_u16_from_y= uv888(u8 y, u8 channel_1, } EXPORT_SYMBOL_IF_KUNIT(argb_u16_from_yuv888); =20 +/** + * READ_LINE() - Generic generator for a read_line function which can be u= sed for format with one + * plane and a block_h =3D=3D block_w =3D=3D 1. + * + * @function_name: Function name to generate + * @pixel_name: temporary pixel name used in the @__VA_ARGS__ parameters + * @pixel_type: Used to specify the type you want to cast the pixel pointer + * @callback: Callback to call for each pixels. This fonction should take = @__VA_ARGS__ as parameter + * and return a pixel_argb_u16 + * @__VA_ARGS__: Argument to pass inside the callback. You can use @pixel_= name to access current + * pixel. + */ +#define READ_LINE(function_name, pixel_name, pixel_type, callback, ...) = \ +static void function_name(const struct vkms_plane_state *plane, int x_star= t, \ + int y_start, enum pixel_read_direction direction, int count, \ + struct pixel_argb_u16 out_pixel[]) \ +{ \ + struct pixel_argb_u16 *end =3D out_pixel + count; \ + int step =3D get_block_step_bytes(plane->frame_info->fb, direction, 0); = \ + u8 *src_pixels; \ + \ + packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0, &src_pixel= s); \ + \ + while (out_pixel < end) { \ + pixel_type *(pixel_name) =3D (pixel_type *)src_pixels; \ + *out_pixel =3D (callback)(__VA_ARGS__); \ + out_pixel +=3D 1; \ + src_pixels +=3D step; \ + } \ +} + +/** + * READ_LINE_ARGB8888() - Generic generator for ARGB8888 formats. + * The pixel type used is u8, so pixel_name[0]..pixel_name[n] are the n co= mponents of the pixel. + * + * @function_name: Function name to generate + * @pixel_name: temporary pixel to use in @a, @r, @g and @b parameters + * @a, @r, @g, @b: value of each channel + */ +#define READ_LINE_ARGB8888(function_name, pixel_name, a, r, g, b) \ + READ_LINE(function_name, pixel_name, u8, argb_u16_from_u8888, a, r, g, b) +/** + * READ_LINE_ARGB16161616() - Generic generator for ARGB16161616 formats. + * The pixel type used is u8, so pixel_name[0]..pixel_name[n] are the n co= mponents of the pixel. + * + * @function_name: Function name to generate + * @pixel_name: temporary pixel to use in @a, @r, @g and @b parameters + * @a, @r, @g, @b: value of each channel + */ +#define READ_LINE_16161616(function_name, pixel_name, a, r, g, b) \ + READ_LINE(function_name, pixel_name, u16, argb_u16_from_u16161616, a, r, = g, b) + /* * The following functions are read_line function for each pixel format su= pported by VKMS. * @@ -376,118 +428,19 @@ static void R4_read_line(const struct vkms_plane_sta= te *plane, int x_start, Rx_read_line(plane, x_start, y_start, direction, count, out_pixel); } =20 -static void R8_read_line(const struct vkms_plane_state *plane, int x_start, - int y_start, enum pixel_read_direction direction, int count, - struct pixel_argb_u16 out_pixel[]) -{ - struct pixel_argb_u16 *end =3D out_pixel + count; - u8 *src_pixels; - int step =3D get_block_step_bytes(plane->frame_info->fb, direction, 0); - - packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0, &src_pixel= s); - - while (out_pixel < end) { - *out_pixel =3D argb_u16_from_gray8(*src_pixels); - src_pixels +=3D step; - out_pixel +=3D 1; - } -} - -static void ARGB8888_read_line(const struct vkms_plane_state *plane, int x= _start, int y_start, - enum pixel_read_direction direction, int count, - struct pixel_argb_u16 out_pixel[]) -{ - struct pixel_argb_u16 *end =3D out_pixel + count; - u8 *src_pixels; - - packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0, &src_pixel= s); - - int step =3D get_block_step_bytes(plane->frame_info->fb, direction, 0); - - while (out_pixel < end) { - u8 *px =3D (u8 *)src_pixels; - *out_pixel =3D argb_u16_from_u8888(px[3], px[2], px[1], px[0]); - out_pixel +=3D 1; - src_pixels +=3D step; - } -} - -static void XRGB8888_read_line(const struct vkms_plane_state *plane, int x= _start, int y_start, - enum pixel_read_direction direction, int count, - struct pixel_argb_u16 out_pixel[]) -{ - struct pixel_argb_u16 *end =3D out_pixel + count; - u8 *src_pixels; - - packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0, &src_pixel= s); - - int step =3D get_block_step_bytes(plane->frame_info->fb, direction, 0); - - while (out_pixel < end) { - u8 *px =3D (u8 *)src_pixels; - *out_pixel =3D argb_u16_from_u8888(255, px[2], px[1], px[0]); - out_pixel +=3D 1; - src_pixels +=3D step; - } -} - -static void ARGB16161616_read_line(const struct vkms_plane_state *plane, i= nt x_start, - int y_start, enum pixel_read_direction direction, int count, - struct pixel_argb_u16 out_pixel[]) -{ - struct pixel_argb_u16 *end =3D out_pixel + count; - u8 *src_pixels; - - packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0, &src_pixel= s); - - int step =3D get_block_step_bytes(plane->frame_info->fb, direction, 0); - - while (out_pixel < end) { - u16 *px =3D (u16 *)src_pixels; - *out_pixel =3D argb_u16_from_u16161616(px[3], px[2], px[1], px[0]); - out_pixel +=3D 1; - src_pixels +=3D step; - } -} - -static void XRGB16161616_read_line(const struct vkms_plane_state *plane, i= nt x_start, - int y_start, enum pixel_read_direction direction, int count, - struct pixel_argb_u16 out_pixel[]) -{ - struct pixel_argb_u16 *end =3D out_pixel + count; - u8 *src_pixels; - - packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0, &src_pixel= s); =20 - int step =3D get_block_step_bytes(plane->frame_info->fb, direction, 0); +READ_LINE_ARGB8888(XRGB8888_read_line, px, 255, px[2], px[1], px[0]) =20 - while (out_pixel < end) { - __le16 *px =3D (__le16 *)src_pixels; - *out_pixel =3D argb_u16_from_le16161616(cpu_to_le16(0xFFFF), px[2], px[1= ], px[0]); - out_pixel +=3D 1; - src_pixels +=3D step; - } -} +READ_LINE_ARGB8888(ARGB8888_read_line, px, px[3], px[2], px[1], px[0]) =20 -static void RGB565_read_line(const struct vkms_plane_state *plane, int x_s= tart, - int y_start, enum pixel_read_direction direction, int count, - struct pixel_argb_u16 out_pixel[]) -{ - struct pixel_argb_u16 *end =3D out_pixel + count; - u8 *src_pixels; =20 - packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0, &src_pixel= s); +READ_LINE_16161616(ARGB16161616_read_line, px, px[3], px[2], px[1], px[0]); +READ_LINE_16161616(XRGB16161616_read_line, px, 0xFFFF, px[2], px[1], px[0]= ); =20 - int step =3D get_block_step_bytes(plane->frame_info->fb, direction, 0); +READ_LINE(RGB565_read_line, px, __le16, argb_u16_from_RGB565, px) =20 - while (out_pixel < end) { - __le16 *px =3D (__le16 *)src_pixels; +READ_LINE(R8_read_line, px, u8, argb_u16_from_gray8, *px) =20 - *out_pixel =3D argb_u16_from_RGB565(px); - out_pixel +=3D 1; - src_pixels +=3D step; - } -} =20 /* * This callback can be used for YUV formats where U and V values are --=20 2.44.2