Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp280762lqo; Thu, 16 May 2024 06:18:46 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXBqUnJPjMv7I1B15N9RiC7nx5pkogPL3yONjutVExUUYe9ziLMSVAmJyKpfuFVQYfIZF+3ZxqY4k2JDDGer3Qbm+AMRsspCefcTsX4XA== X-Google-Smtp-Source: AGHT+IE3xHnQs6gxoM81NW014t8v7rsWsNGdUnSMj/mow0Ji4vk/XdFZ5hm1aoRor0V7Oob9iGTE X-Received: by 2002:a05:6358:6483:b0:194:809a:e7fc with SMTP id e5c5f4694b2df-194809ae922mr763856055d.27.1715865525864; Thu, 16 May 2024 06:18:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715865525; cv=pass; d=google.com; s=arc-20160816; b=YGS2LqW1oFNWVY8Kn73fmQnukrtGmz1iN0IEiO4NmmiqkZ8M5eDkvTFnixoxGac8rH /70ya3lknFBlBSCKNYIikPR2fl78qLOwEsvAah+HcgcWsFxu9H1nda+h9gaUpdiJsVrw /YW6weaWaKsf0cW76r4Lz1jGRHZaLg70qjqUkaJ5D+DA8C7x9OfGb+VX1njwG00U/ze+ RzVMcDbz0vm/DFb3YzhtT163VmIWBhigued37lzVbZ6rvEFEkoZ/7XbaKUgPXclLYGwy bfJZ9HaI64VkNeGL+hhgMICDgueXsUeNf9i00X6f2cLBzPnTe7ybkw1rLtrgaDTRRQ/a Jh7Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=4NUEtLPPG+gknA/6DG8Zyrt9sXcuYUyuc7aw9E6ObTs=; fh=5zsZX+ku5K7/KOEG8/PmwjZDx2OHq0Nmu7y8/HNkT0A=; b=0aDIu8vpypKT+YLQnc0BUgfsTy97oi++V1Vp4HBSLQPaLC+1TJolamer8i7PwBHobM 7GzwFrFpzq1RrdsgT+CDWhWlfCadlVhu+6mDHHRvbWNOO0tbMvFFR8C1vQHaiJXgY9nG AHnCdYSLU9LG7WN57ZaAhL87b4VmCGQDyagyqtE6HEn9QD6T6KJLxjKPLTDzXrVwHZl0 XZ+KpbNm32kkHboi6JLX4kktmpQPMUB/2/tstKhLwNI417k/j6gUbQzyZDSb3v/YTE80 FthjFtSPXmFO1RBY5DXT8eQogcIXIj3DG307TdLwB55mI3L0XD51OgutecKb9wLfcofh Ym2g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=kmLcktsd; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-181096-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181096-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id 41be03b00d2f7-65ce61d448bsi265767a12.61.2024.05.16.06.18.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 06:18:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-181096-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=kmLcktsd; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-181096-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181096-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 815D2B21B32 for ; Thu, 16 May 2024 13:18:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 97625147C72; Thu, 16 May 2024 13:18:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="kmLcktsd" Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) (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 5FDF2145FE0 for ; Thu, 16 May 2024 13:18:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.195 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715865511; cv=none; b=ajofzFOFu8VwZmpe1yxcGsvO2zfCoMbsk+eW/wpT1f3B2c3znq5odGgMFCato41AZlbKwsZhj7Og7oyrnz2qTGjoeHSj0RTHu+bnXyAMEmzkCmMFo5c0vRgSo2Ujaj//x+IS66aZadQvaZzJPi8o8sAi1SHydEAUzmtRFOJB60k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715865511; c=relaxed/simple; bh=1IQN3YQIt9/pGs6sVDiW73WHCdJimhva/zrt+9Ypbqo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=jU0WH9ja+t+chXV3ohPPPWuWDzZ2nmbCi0K0IJbrYp4zRyoc9ZiLjUJru210Y1pndpYBZwB7OUeqp2wyVGC4McGiezKY/QW2CHJluHCeGPTSxzhT+roAO1sWqBURK//kf8zn4LTGVchiyzZU5145eMxd6eWdvzrg+fob12V++0g= 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=kmLcktsd; arc=none smtp.client-ip=217.70.183.195 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 Received: by mail.gandi.net (Postfix) with ESMTPSA id 2FFF560009; Thu, 16 May 2024 13:18:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1715865507; 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=4NUEtLPPG+gknA/6DG8Zyrt9sXcuYUyuc7aw9E6ObTs=; b=kmLcktsd1MZss83SrZqVm248vYUn5BcqYu4CaphQCP5EpwwYBSi4sNX3BStPOfLfC1+OX3 PfuinmXFx6SHW4TAmP4wvtZTTB5M9NFSYv3Szpp/dUMnlegtxZHNeXBwnUVdTCQn0RrobU 0KlH0W4BrMuBAXvuxwNIaHKNjo7bGowiYI3RzbkUOv5oengWdXK+o7hLA36ZpiZjA/cDOz eaZm+p6RoKjc5nVMcCPq4sPOUx/DZA9li8T67wcS1z5qAe9U9g2n5xdZ+Y9jORu5rbuZ2r 2D9PsSLJrhxCLDxV942KHN+RhBUmp08606EqyeQKxvWnpZ3IerEv6pmhfR2elw== From: Louis Chauvet Date: Thu, 16 May 2024 15:18:17 +0200 Subject: [PATCH 1/5] 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: 7bit Message-Id: <20240516-b4-new-color-formats-v1-1-74cf9fe07317@bootlin.com> References: <20240516-b4-new-color-formats-v1-0-74cf9fe07317@bootlin.com> In-Reply-To: <20240516-b4-new-color-formats-v1-0-74cf9fe07317@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 X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=7697; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=1IQN3YQIt9/pGs6sVDiW73WHCdJimhva/zrt+9Ypbqo=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBmRgee4caU8nRDHKwKfmJ/hjX5o2gRX4xNRERn5 KWGkPcbK0qJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZkYHngAKCRAgrS7GWxAs 4u7RD/4x4MmR4LQEYIz7gyN6oofKv6dZVxlgl4DNU6k0oQqJZWAQmLjuzwHLf3UpEAYTM4lXkjB yT8g/6cuTA4etriFtQu5BGcW02fC61ANk0VAkgMgDJlw+4dqX8w8U926FEMxWJxc/aCPRtXBQzW c1r+hALA6TOtDtf0ygvOF804r62vMKnfal8OASelnVHNaCgenVJ17RsW+mJuIjDA07nXGjlNdhe Ieg6TvsDVGlOYAjzzyoAkR/7d0DWIWXqGbOSdszKc+tQXerovghoVld9ktWg1v4vZR6KiZPHtGv 8d5kgcf4xVqZEvqs6yleMmxpdZvswXllB+AP0kTqTowX4GiKjaX4E++jlwz73RCAZBBzyys9fR5 WMQApCvJFy9MJ5a98iqsShhMDfK4H3tmtl+303WHP+Y9TVnIb7JGrpSDgYMUIY3AI9lTzAToKUL laCLgw/g9xENiRdYeD89wuL7Lsg7djZoMj/Lpx1pho8eXQukMWxOQ2i2Qrxq1cGLjEzcpE9ZeFj qXyYSHNWU5EERtOMeversY7GjwtQwgBjJuVM3N+nTvczjWRWOwgzRPWyIwdsjo4huQASZbzX7s0 6UrJdxlP4ekZvH824DA4J0ZcGzPI4N93IuFcEylvipenD4cPdda+O2YzJMxF2ZiIR0QRYHmJBKL D+11D055ci0vblA== 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/vkms_formats.c index 88edf773b11b..d26707cff86e 100644 --- a/drivers/gpu/drm/vkms/vkms_formats.c +++ b/drivers/gpu/drm/vkms/vkms_formats.c @@ -284,6 +284,58 @@ VISIBLE_IF_KUNIT struct pixel_argb_u16 argb_u16_from_yuv888(u8 y, u8 channel_1, } EXPORT_SYMBOL_IF_KUNIT(argb_u16_from_yuv888); +/** + * READ_LINE() - Generic generator for a read_line function which can be used for format with one + * plane and a block_h == block_w == 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. The first argument is always a + * &struct 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_start, \ + int y_start, enum pixel_read_direction direction, int count, \ + struct pixel_argb_u16 out_pixel[]) \ +{ \ + struct pixel_argb_u16 *end = out_pixel + count; \ + int step = 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_pixels); \ + \ + while (out_pixel < end) { \ + pixel_type *(pixel_name) = (pixel_type *)src_pixels; \ + *out_pixel = (callback)(__VA_ARGS__); \ + out_pixel += 1; \ + src_pixels += 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 components 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 components 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 supported by VKMS. * @@ -389,118 +441,19 @@ static void R4_read_line(const struct vkms_plane_state *plane, int x_start, Rx_read_line(plane, x_start, y_start, direction, count, out_pixel); } -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 = out_pixel + count; - u8 *src_pixels; - int step = get_block_step_bytes(plane->frame_info->fb, direction, 0); - - packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0, &src_pixels); - - while (out_pixel < end) { - *out_pixel = argb_u16_from_gray8(*src_pixels); - src_pixels += step; - out_pixel += 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 = out_pixel + count; - u8 *src_pixels; - - packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0, &src_pixels); - - int step = get_block_step_bytes(plane->frame_info->fb, direction, 0); - - while (out_pixel < end) { - u8 *px = (u8 *)src_pixels; - *out_pixel = argb_u16_from_u8888(px[3], px[2], px[1], px[0]); - out_pixel += 1; - src_pixels += 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 = out_pixel + count; - u8 *src_pixels; - - packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0, &src_pixels); - - int step = get_block_step_bytes(plane->frame_info->fb, direction, 0); - - while (out_pixel < end) { - u8 *px = (u8 *)src_pixels; - *out_pixel = argb_u16_from_u8888(255, px[2], px[1], px[0]); - out_pixel += 1; - src_pixels += step; - } -} - -static void ARGB16161616_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 = out_pixel + count; - u8 *src_pixels; - packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0, &src_pixels); +READ_LINE_ARGB8888(XRGB8888_read_line, px, 255, px[2], px[1], px[0]) - int step = get_block_step_bytes(plane->frame_info->fb, direction, 0); +READ_LINE_ARGB8888(ARGB8888_read_line, px, px[3], px[2], px[1], px[0]) - while (out_pixel < end) { - u16 *px = (u16 *)src_pixels; - *out_pixel = argb_u16_from_u16161616(px[3], px[2], px[1], px[0]); - out_pixel += 1; - src_pixels += step; - } -} -static void XRGB16161616_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 = out_pixel + count; - u8 *src_pixels; - - packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0, &src_pixels); +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]); - int step = get_block_step_bytes(plane->frame_info->fb, direction, 0); +READ_LINE(RGB565_read_line, px, u16, argb_u16_from_RGB565, px) - while (out_pixel < end) { - u16 *px = (u16 *)src_pixels; - *out_pixel = argb_u16_from_u16161616(0xFFFF, px[2], px[1], px[0]); - out_pixel += 1; - src_pixels += step; - } -} +READ_LINE(R8_read_line, px, u8, argb_u16_from_gray8, *px) -static void RGB565_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 = out_pixel + count; - u8 *src_pixels; - - packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0, &src_pixels); - - int step = get_block_step_bytes(plane->frame_info->fb, direction, 0); - - while (out_pixel < end) { - u16 *px = (u16 *)src_pixels; - - *out_pixel = argb_u16_from_RGB565(px); - out_pixel += 1; - src_pixels += step; - } -} /* * This callback can be used for YUV formats where U and V values are -- 2.43.2