From patchwork Thu Feb 1 17:31:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 195410 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2719:b0:106:209c:c626 with SMTP id hl25csp334219dyb; Thu, 1 Feb 2024 09:57:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IGJjV7jdCp6yV612x7h/sWsBckndT6UoP+/MDI6zzGBdn+h903atfPrRmIkvyItqgSjIiZ0 X-Received: by 2002:a05:6358:718b:b0:178:a197:15e with SMTP id t11-20020a056358718b00b00178a197015emr5459767rwt.32.1706810254710; Thu, 01 Feb 2024 09:57:34 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706810254; cv=pass; d=google.com; s=arc-20160816; b=Wtlj2qiy3DgTLmca1Q/G9NAse2RFWR0FbUHlffjQS8YNFDbjezrk+swmJogcyFyRHe wEhgiMf9z0eUzgKx1+YWRV4s3I5vqEdOE8p39pYPEsbAPvqhCtEXv1hhI4eIAlrjxjb8 4HCUyDGtaBJHNTYPG9ZCSmybNrv+crBeBRSmpETUrT5/FlA/u7H2B+Uyd0KKDxityz6T OKBQVvxlMmpX8Dgz8UlNGV5cBVxc0pP1Ntlk4OwzeWH6f7fSta3sYtRqQdGQ+ywdlNs2 KwskCogIXCfBWV3G/guU1QglbDBvRupYKU+1+Tve8VpcsS52QYPyN6O8hOTkl/iM2AU+ ZtgQ== 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=y+aqzxTPAUjOzIodHPzxeC6qMPaNLGnJXnuBentQENE=; fh=sxn8Hv2ljiMlahi1M2ktHN4xmYG+z8q1il58NeCwIKA=; b=N53HLfCQPvs8Ss8HCNhjBtoJshaUGDKdGm2+s6A8FzB2qsz0G9QtS6pm41oG6r2yMB e3GABvH7WY3velJH9pXWjtYLVSx7KicmG7mMy3nKRnTK1lJg9vmJMTMemOudDYNusPim HOqMj+3lXFTA59Cc6nykNTN3gHPOHb3AV988ds8fZVl76InRJGKe6QF9Dbq0YOpNp1zh vZ/Qx3ORFj+T1ihPejf9dfignikpxczYFTY2T+TU3Nnrap5MsLeWQB7XAPKkfPv67sVg bEIkAFQ2ZB7Q7Xiv1lRQ3K8gDZf3opqNdNj6bia2VE+kMLtB4W3lUGyVHKtMVg722ekO 1duQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=o4NwI2W7; 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-48595-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48595-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com X-Forwarded-Encrypted: i=1; AJvYcCX2MlvWbXvbqncnuAL8ugQHoxr0Y1uWWn2rFaoDbkLZfdlbREVELwOp0WPmW4krDfUqRgAB0JjRuBnhhj0zRD/PotohhA== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id l192-20020a6391c9000000b005cf9e5947fbsi75320pge.270.2024.02.01.09.57.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 09:57:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-48595-ouuuleilei=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=o4NwI2W7; 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-48595-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48595-ouuuleilei=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 DECE2B2D7EF for ; Thu, 1 Feb 2024 17:33:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 36F765C055; Thu, 1 Feb 2024 17:32:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="o4NwI2W7" Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (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 9C11484025 for ; Thu, 1 Feb 2024 17:32:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706808742; cv=none; b=bq83zL5b5rSToNpLsOHmjOyNnfcURpuHd07jQR4HralU9Ig0q4pdHR7mNgk/ER7QhK59K1uRsAsT4PaAkkjgfmc78nT8i80NBoe3Z5+GZQAsWnrGqcl1sytrBTau+/xK2KW6I+dQGUn2GDQW7TednlGTg+O/g4xBfHHBEvYDf2I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706808742; c=relaxed/simple; bh=sy6XOjKiwgGLJghXuUCDDipZtMBjZVoiNnbEzSMpZZE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=sf3l+3Pb0XUUexuBui55KHhVzxqh3AW/KuzyU4OK+2zAd6YHfP5ovjd7YcanPDiQ1nLGV/7lpuzuNTS7+oc2voF7ZhAhj5agjyXQQcdEkF+MLvd4UIzkJ8B3JMFUlCAe8ug4+oj6sb7F84lKzNP9tW+heLe3GtyhPPg3n4jk+3c= 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=o4NwI2W7; arc=none smtp.client-ip=217.70.183.197 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 1E23B1C000E; Thu, 1 Feb 2024 17:32:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1706808732; 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=y+aqzxTPAUjOzIodHPzxeC6qMPaNLGnJXnuBentQENE=; b=o4NwI2W71cP/524XS5XZd+wR6dynrd7bQz1YYFr85lIod0g7wnCEVb5vMnkvfFa4swnFa6 Vga1gARfj5bJ4msfrmpsnust9S++UbhaLijPItbdzjUqSpZtYTV35ugOmwnlntXZ+9lfam uJftslgpJgj5g70KbaSDZfl4zGTDb5UP4ZWqeiSikA3jiebmiiYid8XZKd9QXevyUeoIVh fDmCB5CoGVdj+DFAUoIg4NVT0tnzc/n4iZ0Cz/xZCT9/jQ0UOrpkF+h7J+jAlBG8Pr+FkM CTYn91NG3ddpR1Y0LytRlrgqt5mb3zN/BNOlE23tdqRBEeojZORxMfxNUlKV8w== From: Louis Chauvet Date: Thu, 01 Feb 2024 18:31:31 +0100 Subject: [PATCH 1/2] drm/vkms: Create a type to check a function pointer validity Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240201-yuv-v1-1-3ca376f27632@bootlin.com> References: <20240201-yuv-v1-0-3ca376f27632@bootlin.com> In-Reply-To: <20240201-yuv-v1-0-3ca376f27632@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 , marcheu@google.com, seanpaul@google.com, nicolejadeyee@google.com Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Louis Chauvet , thomas.petazzoni@bootlin.com, miquel.raynal@bootlin.com X-Mailer: b4 0.12.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=3051; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=sy6XOjKiwgGLJghXuUCDDipZtMBjZVoiNnbEzSMpZZE=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBlu9WZSdSr1fJmjjmgoEgdMXRsHSkHazV7I02+1oIU rS216fCJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZbvVmQAKCRAgrS7GWxAs4lx2D/ 9gzX3KmylHrfqn4EdZ5irvLsNj7XKSNitiwqJLoic7NSfewZYK0ZTimaTYAqOJWUGC+1W7wWv8Y/Ah ujjMwiIwHX4ee+EmgvT5nFbtlNxwUbS/6YoGHh5z+JoAdCzZA3paPGkfLcRexE4W0KQFP23tsWD18F rb2Tlkqn5gHrT9PLwSV0VTiWfAi4KUv8fnc7CAyv/6BLnP5pRYHfOLo4TcTL/AztLn3hu4z27VytY3 Jd7Glyf8Y7Pc4fU0arCO8WrcI0+KaLp7NsEBM9bXJKYYUOncvYxiCBwUT5bibv9fZVU3t/0BLrDRRa VWQUXmKd48TfrZD0F/vNEnvOllKijrIg6usH81Qcm2hgBvNbIfIHokg9IoMKJH14fwlOJfLdtrfNOS ICe8GWq8r1njHfduxaUaTFBAnCFRcybcq/5qQdz3l2mNU6LJipXQKUvl46AHT26eHjVIGk33y+vQJN 0B7uU6HXys4vdlLpj8TsVHtlV8v7nPiG5N39l2NEjlWZ3nv1HAV6dWXA1SjJGMDUqQKftYSYaZMMGW qrCqrJ+E4SAR7w8If6pZXTaINxjhRvL+N+ZAPDIqwMH/OTxpJne5tJmwV3Jz/M6OyQ8kfw3k9k3Q56 b7qTPQxXPPYvKBVUcO2rvl3An1HvyBXGzH+NZHQPifz2RqVzzSZv9aItU2pQ== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789720269721057745 X-GMAIL-MSGID: 1789720269721057745 Add the pixel_read_t type to check function prototype in structures and functions. It avoids casting to (void *) and at the same occasion allows the compiler to check the type properly. Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_drv.h | 17 +++++++++++++++-- drivers/gpu/drm/vkms/vkms_formats.c | 4 ++-- drivers/gpu/drm/vkms/vkms_formats.h | 2 +- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h index 51349a0c32d8..cb20bab26cae 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.h +++ b/drivers/gpu/drm/vkms/vkms_drv.h @@ -48,6 +48,20 @@ struct vkms_writeback_job { void (*pixel_write)(u8 *dst_pixels, struct pixel_argb_u16 *in_pixel); }; +/** + * typedef pixel_read_t - These functions are used to read the pixels in the source frame, convert + * them to argb16 and write them to out_pixel. + * It assumes that src_pixels point to a valid pixel (not a block, or a block of 1x1 pixel) + * + * @src_pixels: Source pointer to a pixel + * @out_pixel: Pointer where to write the pixel value + * @encoding: Color encoding to use (mainly used for YUV formats) + * @range: Color range to use (mainly used for YUV formats) + */ +typedef void (*pixel_read_t)(u8 **src_pixels, int y, + struct pixel_argb_u16 *out_pixel, enum drm_color_encoding enconding, + enum drm_color_range range); + /** * vkms_plane_state - Driver specific plane state * @base: base plane state @@ -56,8 +70,7 @@ struct vkms_writeback_job { struct vkms_plane_state { struct drm_shadow_plane_state base; struct vkms_frame_info *frame_info; - void (*pixel_read)(u8 **src_buffer, struct pixel_argb_u16 *out_pixel, - enum drm_color_encoding enconding, enum drm_color_range range); + pixel_read_t pixel_read; }; struct vkms_plane { diff --git a/drivers/gpu/drm/vkms/vkms_formats.c b/drivers/gpu/drm/vkms/vkms_formats.c index e06bbd7c0a67..c6376db58d38 100644 --- a/drivers/gpu/drm/vkms/vkms_formats.c +++ b/drivers/gpu/drm/vkms/vkms_formats.c @@ -390,7 +390,7 @@ void vkms_writeback_row(struct vkms_writeback_job *wb, wb->pixel_write(dst_pixels, &in_pixels[x]); } -void *get_pixel_conversion_function(u32 format) +pixel_read_t get_pixel_conversion_function(u32 format) { switch (format) { case DRM_FORMAT_ARGB8888: @@ -420,7 +420,7 @@ void *get_pixel_conversion_function(u32 format) case DRM_FORMAT_YVU444: return &planar_yvu_to_argb_u16; default: - return NULL; + return (pixel_read_t)NULL; } } diff --git a/drivers/gpu/drm/vkms/vkms_formats.h b/drivers/gpu/drm/vkms/vkms_formats.h index 0cf835292cec..04e31e126ab1 100644 --- a/drivers/gpu/drm/vkms/vkms_formats.h +++ b/drivers/gpu/drm/vkms/vkms_formats.h @@ -5,7 +5,7 @@ #include "vkms_drv.h" -void *get_pixel_conversion_function(u32 format); +pixel_read_t get_pixel_conversion_function(u32 format); void *get_pixel_write_function(u32 format); From patchwork Thu Feb 1 17:31:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 195408 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2719:b0:106:209c:c626 with SMTP id hl25csp320463dyb; Thu, 1 Feb 2024 09:33:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IEmiqDbgvWxsAGgCVNeo5JDN3tsK0oZtIa3ibDn70JeWMTccfkE3fzTSC2+v23r3P/6sLaa X-Received: by 2002:a05:6808:14c8:b0:3be:add9:76fb with SMTP id f8-20020a05680814c800b003beadd976fbmr6171331oiw.12.1706808792538; Thu, 01 Feb 2024 09:33:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706808792; cv=pass; d=google.com; s=arc-20160816; b=S6H/RUVJlNPSxsCVdR+eKD0jwNwfMzUf9F1yBlb0YBawPhjXEs+z/c1z8+0IOvdyXI wtrPUSu5HKEukB32NpPzMmXRMSg14LOJ1PHJHpf+Hh/4cyR4gh2dPAfHdqvkCv9+dQE6 W/vEnXKiD9ETVjZewee0mslIZLEDqlbFCQj8sErlo9rJp9Xo/m0uO3YCqJsTjOSXQckR JI8WK8LIxNUN8TYpNtvbNLmU/kImeo4QXq2jADmgNVFPhyxLk9RQPH/Oz3yHt8GmTQ5E loEkzqctznHeEZyaUcJ1mOXdIU76oaEwPe9cQKTr+isxlKmj6J8T640Y5OYTvuoyAfgu 5DAg== 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=w3zxaDJx0ige/xrGelusoCYKzSbgA6rlzzgnKpQREhA=; fh=UJjCsXaNoT26zmKUs7wXFJ8b2B5+IPHgIbGT8+13IZ8=; b=n4nEKlNGIHXAnJP0ulOK5PBcKulJgbssuRS9bNATAtBGf6VnoCx144qbLVDY2yzqyA iW0dQc85urmC+2XQwI3eUO/IMa9233bCGV/x14sCtB2T2cdgph1D+2+/sLCDO7wJ2hwH mu4JvesHxz1/dMiOFlzoMpNDNysoLVQfACbdSDtRYGkKCJvlXeFcRfgGoF4fUrE58iSn vyB4l6GwPnmb3lsX1+mkdJniGgREI8Um8dWapYaPTO14uuUCVfLCgqoyN4vvHkhn+iYF apLU3hEa+sEItFMZlL6Id7yJZbmrCDIP07V+55UV3QNlhbhXUEX0vLHfuTedTQMhrKym gK4g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=GKaN44fN; 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-48596-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48596-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com X-Forwarded-Encrypted: i=1; AJvYcCVX5iz0grj8iOqZGPit0lZ85f+SMBFaBR9Vt34sM4W5pgaOplUW39Xt8jyBmxp4iYTNe7fbScfD1qe3yhDDZKrAfjSSLQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id l15-20020a05622a174f00b0042bf6ee0e6dsi1195627qtk.76.2024.02.01.09.33.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 09:33:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-48596-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=GKaN44fN; 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-48596-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48596-ouuuleilei=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 45A931C26EDA for ; Thu, 1 Feb 2024 17:33:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 93DAD5C05E; Thu, 1 Feb 2024 17:32:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="GKaN44fN" Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (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 8401F84027 for ; Thu, 1 Feb 2024 17:32:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706808743; cv=none; b=lr7MdsXgs1fhyp8Askak3iRU/mwYCDAPQPOpDfv8/5warS/CMLoDg9kHICScsnzjyRmQyaBqG6dC/0H1iateTspboPbIRO+oVIs6v9L2zeR+57qDJV+CSQASlSSjl3JSbKI/Tn7ktXWetAaWi0Yup78l0xGUvkuBxc0XDAx4oA8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706808743; c=relaxed/simple; bh=Lyvp37yqP/RKGqGObubMXl4szy7JAwmzZhexN7cT3RY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=oaVqZYSmw+FeTSitJg3dT2U8yRATvn+Fmv9v+6ePOVhCzya80PZ1PMOJYAZE1akL3xsjuJc4P00BYjZxNchgdDBSgrR6f1/CxZ8fL83w0Lag4H3eZmKsJllivM0md+/UBXSMqOu2auhyIwj37FucGdOph+UgKwUGQyTbsLg9t3w= 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=GKaN44fN; arc=none smtp.client-ip=217.70.183.197 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 180691C000B; Thu, 1 Feb 2024 17:32:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1706808732; 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=w3zxaDJx0ige/xrGelusoCYKzSbgA6rlzzgnKpQREhA=; b=GKaN44fNIPV1Q3EWB45XLQBsfN24J28ISFD43uu+ngs+is/9nKz+gcL+1fvcdGimGjJHwY f/UsdfzOf+HQwMHT2nROXP84j+eZcyYo2L/Y/m1yi6FfkmQ1jsJ/M0QSlIbaRMYBsqO9Kp Z1BYsAAcy+XDteXWe1/09Lff6xN9XCYBLoag+Wyz23oKmh6d0aiWHqR2Uywk2fRVCIJaL/ EcAB6iT5AzO45MJYH9SX2ieAfuXRJbD3QKo9AUnux4OayeYnu1zmhv98WKMaLqVatgSlaG IoHVbN8QTQtYOuoN0nVsWk6WxyhJGpVQBOFpQ7XAK6o0xi0mzyk6Tzy0XkvMRQ== From: Louis Chauvet Date: Thu, 01 Feb 2024 18:31:32 +0100 Subject: [PATCH 2/2] drm/vkms: Use a simpler composition function Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240201-yuv-v1-2-3ca376f27632@bootlin.com> References: <20240201-yuv-v1-0-3ca376f27632@bootlin.com> In-Reply-To: <20240201-yuv-v1-0-3ca376f27632@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 , marcheu@google.com, seanpaul@google.com, nicolejadeyee@google.com Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Louis Chauvet , thomas.petazzoni@bootlin.com, miquel.raynal@bootlin.com X-Mailer: b4 0.12.1 X-Developer-Signature: v=1; a=openpgp-sha256; l=25546; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=Lyvp37yqP/RKGqGObubMXl4szy7JAwmzZhexN7cT3RY=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBlu9WZN+h0hVSORpgCsnNgPV3oNEnfy78OJ2TZx6Uk FWszM9OJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZbvVmQAKCRAgrS7GWxAs4keKD/ 9iYIHu+QsSQBi1SNKIGSIvJrvqhGO+pJqNubzaebjCgoxnY9DxjzaCqS9Isc4Cw+dKgJoQPKOxYmjZ f7zZye/8+AiFpNd8lGgmAGkzffeNVw9TciajNLlOaYw/tRca/g5d9NChLh9WsJkTern7wri0/jMLcy gnKV5lsEheLhkyDzdafRPlDxXBubzariATSOKnAY1yPkGMQ9Ah0spU00TROkifkMsYi5nc5h2Y5NoB sBj+P3svpie6urXSyckKnMZzV+8VjfHn1MH36Vd2ZW4X7fgM3WCSVgTEgYT7Pi1Kvt4ZIu4udcwlz8 gx/XIu4pACUN/Dysc5L18jlYa5GrbLxbfubPQshVV6BYbm4VFdBXWzDp1SYu7zoZssmQBO3MQAnLW8 rBbB95fPy468pAUtw9Af3XgtVJyutQLcAj2DsbIxih6y7yZ4Awctb0rQyviziqB49nWUApZtXs9+6T tPlKL9BL5NMMHJ//j1UjxcbDH7BUTZ1GYfnIJjxllJi1quq5yGS/Sd8A7v2clBHZ0qe52/LDUe1x2D po/wDiUh/te4YwkpYza+wI2ba9Wy6nBW2SIsQObE85ngYNU7dVN4m8C2cPKCB+pENxVKRSBjZcQQAq wtu63wPmIpTNLu7XZSn37O1evYyQ8pkZKJR6sk+VcbEXpailezRMZFZf37Rw== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789718736029564828 X-GMAIL-MSGID: 1789718736029564828 Change the composition algorithm to iterate over pixels instead of lines. It allows a simpler management of rotation and pixel access for complex formats. This new algorithm allows read_pixel function to have access to x/y coordinates and make it possible to read the correct thing in a block when block_w and block_h are not 1. The iteration pixel-by-pixel in the same method also allows a simpler management of rotation with drm_rect_* helpers. This way it's not needed anymore to have misterious switch-case distributed in multiple places. This patch is tested with IGT: - kms_plane@pixel_format - kms_plane@pixel-format-source-clamping - kms_plane@plane-position-covered - kms_plane@plane-position-hole - kms_plane@plane-position-hole-dpms - kms_plane@plane-panning-top-left - kms_plane@plane-panning-bottom-right - kms_plane@test-odd-size-with-yuv - See [1] - kms_cursor_crc@cursor-size-change - kms_cursor_crc@cursor-alpha-opaque - kms_cursor_crc@cursor-alpha-transparent - kms_cursor_crc@cursor-dpms - kms_cursor_crc@cursor-onscreen-* - kms_cursor_crc@cursor-offscreen-* - kms_cursor_crc@cursor-sliding-* - kms_cursor_crc@cursor-random-* - kms_cursor_crc@cursor-rapid-movement-* - FAIL, but with Overflow of CRC buffer - kms_rotation_crc@primary-rotation-* - See [1] - kms_rotation_crc@sprite-rotation-* - See [1] - kms_rotation_crc@cursor-rotation-* - See [1] - kms_rotation_crc@sprite-rotation-90-pos-100-0 - See [1] - kms_rotation_crc@multiplane-rotation - See [1] - kms_rotation_crc@multiplane-rotation-cropping-* - See [1] [1]: https://lore.kernel.org/igt-dev/20240201-kms_tests-v1-0-bc34c5d28b3f@bootlin.com/T/#t Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_composer.c | 97 +++++++++----- drivers/gpu/drm/vkms/vkms_drv.h | 21 ++- drivers/gpu/drm/vkms/vkms_formats.c | 250 ++++++++++++++++++----------------- drivers/gpu/drm/vkms/vkms_plane.c | 13 +- 4 files changed, 221 insertions(+), 160 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_composer.c b/drivers/gpu/drm/vkms/vkms_composer.c index 3c99fb8b54e2..4c5439209907 100644 --- a/drivers/gpu/drm/vkms/vkms_composer.c +++ b/drivers/gpu/drm/vkms/vkms_composer.c @@ -43,7 +43,7 @@ static void pre_mul_alpha_blend(struct vkms_frame_info *frame_info, { int x_dst = frame_info->dst.x1; struct pixel_argb_u16 *out = output_buffer->pixels + x_dst; - struct pixel_argb_u16 *in = stage_buffer->pixels; + struct pixel_argb_u16 *in = stage_buffer->pixels + x_dst; int x_limit = min_t(size_t, drm_rect_width(&frame_info->dst), stage_buffer->n_pixels); @@ -55,33 +55,6 @@ static void pre_mul_alpha_blend(struct vkms_frame_info *frame_info, } } -static int get_y_pos(struct vkms_frame_info *frame_info, int y) -{ - if (frame_info->rotation & DRM_MODE_REFLECT_Y) - return drm_rect_height(&frame_info->rotated) - y - 1; - - switch (frame_info->rotation & DRM_MODE_ROTATE_MASK) { - case DRM_MODE_ROTATE_90: - return frame_info->rotated.x2 - y - 1; - case DRM_MODE_ROTATE_270: - return y + frame_info->rotated.x1; - default: - return y; - } -} - -static bool check_limit(struct vkms_frame_info *frame_info, int pos) -{ - if (drm_rotation_90_or_270(frame_info->rotation)) { - if (pos >= 0 && pos < drm_rect_width(&frame_info->rotated)) - return true; - } else { - if (pos >= frame_info->rotated.y1 && pos < frame_info->rotated.y2) - return true; - } - - return false; -} static void fill_background(const struct pixel_argb_u16 *background_color, struct line_buffer *output_buffer) @@ -182,18 +155,74 @@ static void blend(struct vkms_writeback_job *wb, const struct pixel_argb_u16 background_color = { .a = 0xffff }; size_t crtc_y_limit = crtc_state->base.crtc->mode.vdisplay; + size_t crtc_x_limit = crtc_state->base.crtc->mode.hdisplay; + /* + * Iterating over each pixel to simplify the handling of rotations by using drm_rect_* + * helpers. + * Iteration per pixel also allosw a simple management of complex pixel formats. + * + * If needed, this triple loop might be a good place for optimizations. + */ for (size_t y = 0; y < crtc_y_limit; y++) { fill_background(&background_color, output_buffer); /* The active planes are composed associatively in z-order. */ for (size_t i = 0; i < n_active_planes; i++) { - y_pos = get_y_pos(plane[i]->frame_info, y); - - if (!check_limit(plane[i]->frame_info, y_pos)) - continue; - - vkms_compose_row(stage_buffer, plane[i], y_pos); + for (size_t x = 0; x < crtc_x_limit; x++) { + /* + * @x and @y are the coordinate in the output crtc. + * @dst_px is used to easily check if a pixel must be blended. + * @src_px is used to handle rotation. Just before blending, it + * will contain the coordinate of the wanted source pixel in + * the source buffer. + * @tmp_src is the conversion of src rectangle to integer. + */ + + struct drm_rect dst_px = DRM_RECT_INIT(x, y, 1, 1); + struct drm_rect src_px = DRM_RECT_INIT(x, y, 1, 1); + struct drm_rect tmp_src; + + drm_rect_fp_to_int(&tmp_src, &plane[i]->frame_info->src); + + /* + * Check that dst_px is inside the plane output + * Note: This is destructive for dst_px, if you need this + * rectangle you have to do a copy + */ + if (!drm_rect_intersect(&dst_px, &plane[i]->frame_info->dst)) + continue; + + /* + * Transform the coordinate x/y from the crtc to coordinates into + * coordinates for the src buffer. + * + * First step is to cancel the offset of the dst buffer. + * Then t will have to invert the rotation. This assumes that + * dst = drm_rect_rotate(src, rotation) (dst and src have the + * space size, but can be rotated). + * And then, apply the offset of the source rectangle to the + * coordinate. + */ + drm_rect_translate(&src_px, -plane[i]->frame_info->dst.x1, + -plane[i]->frame_info->dst.y1); + drm_rect_rotate_inv(&src_px, + drm_rect_width(&tmp_src), + drm_rect_height(&tmp_src), + plane[i]->frame_info->rotation); + drm_rect_translate(&src_px, tmp_src.x1, tmp_src.y1); + + /* + * Now, as the src_px contains the correct position, we can use + * it to convert the pixel color + */ + plane[i]->pixel_read(plane[i]->frame_info, + src_px.x1, + src_px.y1, + &stage_buffer->pixels[x], + plane[i]->base.base.color_encoding, + plane[i]->base.base.color_range); + } pre_mul_alpha_blend(plane[i]->frame_info, stage_buffer, output_buffer); } diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h index cb20bab26cae..ba3c063adc5f 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.h +++ b/drivers/gpu/drm/vkms/vkms_drv.h @@ -25,10 +25,20 @@ #define VKMS_LUT_SIZE 256 +/** + * struct vkms_frame_info - structure to store the state of a frame + * + * @fb: backing drm framebuffer + * @src: source rectangle of this frame in the source framebuffer + * @dst: destination rectangle in the crtc buffer + * @map: see drm_shadow_plane_state@data + * @rotation: rotation applied to the source. + * + * @src and @dst should have the same size modulo the rotation. + */ struct vkms_frame_info { struct drm_framebuffer *fb; struct drm_rect src, dst; - struct drm_rect rotated; struct iosys_map map[DRM_FORMAT_MAX_PLANES]; unsigned int rotation; }; @@ -51,14 +61,15 @@ struct vkms_writeback_job { /** * typedef pixel_read_t - These functions are used to read the pixels in the source frame, convert * them to argb16 and write them to out_pixel. - * It assumes that src_pixels point to a valid pixel (not a block, or a block of 1x1 pixel) * - * @src_pixels: Source pointer to a pixel + * @frame_info: Frame used as source for the pixel value + * @x: X (width) coordinate in the source buffer + * @y: Y (height) coordinate in the source buffer * @out_pixel: Pointer where to write the pixel value * @encoding: Color encoding to use (mainly used for YUV formats) * @range: Color range to use (mainly used for YUV formats) */ -typedef void (*pixel_read_t)(u8 **src_pixels, int y, +typedef void (*pixel_read_t)(struct vkms_frame_info *frame_info, int x, int y, struct pixel_argb_u16 *out_pixel, enum drm_color_encoding enconding, enum drm_color_range range); @@ -66,6 +77,8 @@ typedef void (*pixel_read_t)(u8 **src_pixels, int y, * vkms_plane_state - Driver specific plane state * @base: base plane state * @frame_info: data required for composing computation + * @pixel_read: function to read a pixel in this plane. The creator of a vkms_plane_state must + * ensure that this pointer is valid */ struct vkms_plane_state { struct drm_shadow_plane_state base; diff --git a/drivers/gpu/drm/vkms/vkms_formats.c b/drivers/gpu/drm/vkms/vkms_formats.c index c6376db58d38..8ff85ffda94f 100644 --- a/drivers/gpu/drm/vkms/vkms_formats.c +++ b/drivers/gpu/drm/vkms/vkms_formats.c @@ -11,79 +11,88 @@ #include "vkms_formats.h" -static size_t pixel_offset(const struct vkms_frame_info *frame_info, int x, int y, size_t index) + +/** + * packed_pixels_offset() - Get the offset of the block containing the pixel at coordinates x/y + * + * @frame_info: Buffer metadata + * @x: The x coordinate of the wanted pixel in the buffer + * @y: The y coordinate of the wanted pixel in the buffer + * @plane: The index of the plane to use + * + * The caller must be aware that this offset is not always a pointer to a pixel. If individual + * pixel values are needed, they have to be extracted from the block. + */ +static size_t packed_pixels_offset(const struct vkms_frame_info *frame_info, int x, int y, size_t plane) { struct drm_framebuffer *fb = frame_info->fb; - - return fb->offsets[index] + (y * fb->pitches[index]) - + (x * fb->format->cpp[index]); + const struct drm_format_info *format = frame_info->fb->format; + /* Directly using x and y to multiply pitches and format->ccp is not sufficient because + * in some formats a block can represent multiple pixels. + * + * Dividing x and y by the block size allows to extract the correct offset of the block + * containing the pixel. + */ + return fb->offsets[plane] + + (y / drm_format_info_block_width(format, plane)) * fb->pitches[plane] + + (x / drm_format_info_block_height(format, plane)) * format->char_per_block[plane]; } /* - * packed_pixels_addr - Get the pointer to pixel of a given pair of coordinates + * packed_pixels_addr - Get the pointer to the block containing the pixel at the given coordinate * * @frame_info: Buffer metadata - * @x: The x(width) coordinate of the 2D buffer - * @y: The y(Heigth) coordinate of the 2D buffer + * @x: The x(width) coordinate inside the 2D buffer + * @y: The y(Heigth) coordinate inside the 2D buffer * @index: The index of the plane on the 2D buffer * - * Takes the information stored in the frame_info, a pair of coordinates, and - * returns the address of the first color channel on the desired index. The - * format's specific subsample is applied. + * Takes the information stored in the frame_info, a pair of coordinates, and returns the address + * of the block containing this pixel. + * The caller must be aware that this pointer is sometimes not directly a pixel, it needs some + * additional work to extract pixel color from this block. */ static void *packed_pixels_addr(const struct vkms_frame_info *frame_info, int x, int y, size_t index) { - int vsub = index == 0 ? 1 : frame_info->fb->format->vsub; - int hsub = index == 0 ? 1 : frame_info->fb->format->hsub; - size_t offset = pixel_offset(frame_info, x / hsub, y / vsub, index); - - return (u8 *)frame_info->map[0].vaddr + offset; + return (u8 *)frame_info->map[0].vaddr + packed_pixels_offset(frame_info, x, y, index); } -static void *get_packed_src_addr(const struct vkms_frame_info *frame_info, int y, size_t index) +static void ARGB8888_to_argb_u16(struct vkms_frame_info *frame_info, int x, int y, + struct pixel_argb_u16 *out_pixel, enum drm_color_encoding encoding, + enum drm_color_range range) { - int x_src = frame_info->src.x1 >> 16; - int y_src = y - frame_info->rotated.y1 + (frame_info->src.y1 >> 16); - - return packed_pixels_addr(frame_info, x_src, y_src, index); -} + u8 *src_pixel = packed_pixels_addr(frame_info, x, y, 0); -static int get_x_position(const struct vkms_frame_info *frame_info, int limit, int x) -{ - if (frame_info->rotation & (DRM_MODE_REFLECT_X | DRM_MODE_ROTATE_270)) - return limit - x - 1; - return x; -} - -static void ARGB8888_to_argb_u16(u8 **src_pixels, struct pixel_argb_u16 *out_pixel, - enum drm_color_encoding encoding, enum drm_color_range range) -{ /* * The 257 is the "conversion ratio". This number is obtained by the * (2^16 - 1) / (2^8 - 1) division. Which, in this case, tries to get * the best color value in a pixel format with more possibilities. * A similar idea applies to others RGB color conversions. */ - out_pixel->a = (u16)src_pixels[0][3] * 257; - out_pixel->r = (u16)src_pixels[0][2] * 257; - out_pixel->g = (u16)src_pixels[0][1] * 257; - out_pixel->b = (u16)src_pixels[0][0] * 257; + out_pixel->a = (u16)src_pixel[3] * 257; + out_pixel->r = (u16)src_pixel[2] * 257; + out_pixel->g = (u16)src_pixel[1] * 257; + out_pixel->b = (u16)src_pixel[0] * 257; } -static void XRGB8888_to_argb_u16(u8 **src_pixels, struct pixel_argb_u16 *out_pixel, - enum drm_color_encoding encoding, enum drm_color_range range) +static void XRGB8888_to_argb_u16(struct vkms_frame_info *frame_info, int x, int y, + struct pixel_argb_u16 *out_pixel, enum drm_color_encoding encoding, + enum drm_color_range range) { + u8 *src_pixel = packed_pixels_addr(frame_info, x, y, 0); out_pixel->a = (u16)0xffff; - out_pixel->r = (u16)src_pixels[0][2] * 257; - out_pixel->g = (u16)src_pixels[0][1] * 257; - out_pixel->b = (u16)src_pixels[0][0] * 257; + out_pixel->r = (u16)src_pixel[2] * 257; + out_pixel->g = (u16)src_pixel[1] * 257; + out_pixel->b = (u16)src_pixel[0] * 257; } -static void ARGB16161616_to_argb_u16(u8 **src_pixels, struct pixel_argb_u16 *out_pixel, - enum drm_color_encoding encoding, enum drm_color_range range) +static void ARGB16161616_to_argb_u16(struct vkms_frame_info *frame_info, int x, int y, + struct pixel_argb_u16 *out_pixel, + enum drm_color_encoding encoding, + enum drm_color_range range) { - u16 *pixels = (u16 *)src_pixels[0]; + u8 *src_pixel = packed_pixels_addr(frame_info, x, y, 0); + u16 *pixels = (u16 *)src_pixel; out_pixel->a = le16_to_cpu(pixels[3]); out_pixel->r = le16_to_cpu(pixels[2]); @@ -91,10 +100,13 @@ static void ARGB16161616_to_argb_u16(u8 **src_pixels, struct pixel_argb_u16 *out out_pixel->b = le16_to_cpu(pixels[0]); } -static void XRGB16161616_to_argb_u16(u8 **src_pixels, struct pixel_argb_u16 *out_pixel, - enum drm_color_encoding encoding, enum drm_color_range range) +static void XRGB16161616_to_argb_u16(struct vkms_frame_info *frame_info, int x, int y, + struct pixel_argb_u16 *out_pixel, + enum drm_color_encoding encoding, + enum drm_color_range range) { - u16 *pixels = (u16 *)src_pixels[0]; + u8 *src_pixel = packed_pixels_addr(frame_info, x, y, 0); + u16 *pixels = (u16 *)src_pixel; out_pixel->a = (u16)0xffff; out_pixel->r = le16_to_cpu(pixels[2]); @@ -102,10 +114,12 @@ static void XRGB16161616_to_argb_u16(u8 **src_pixels, struct pixel_argb_u16 *out out_pixel->b = le16_to_cpu(pixels[0]); } -static void RGB565_to_argb_u16(u8 **src_pixels, struct pixel_argb_u16 *out_pixel, - enum drm_color_encoding encoding, enum drm_color_range range) +static void RGB565_to_argb_u16(struct vkms_frame_info *frame_info, int x, int y, + struct pixel_argb_u16 *out_pixel, enum drm_color_encoding encoding, + enum drm_color_range range) { - u16 *pixels = (u16 *)src_pixels[0]; + u8 *src_pixel = packed_pixels_addr(frame_info, x, y, 0); + u16 *pixels = (u16 *)src_pixel; s64 fp_rb_ratio = drm_fixp_div(drm_int2fixp(65535), drm_int2fixp(31)); s64 fp_g_ratio = drm_fixp_div(drm_int2fixp(65535), drm_int2fixp(63)); @@ -121,12 +135,19 @@ static void RGB565_to_argb_u16(u8 **src_pixels, struct pixel_argb_u16 *out_pixel out_pixel->b = drm_fixp2int_round(drm_fixp_mul(fp_b, fp_rb_ratio)); } +/** + * ycbcr2rgb() - helper to convert ycbcr 8 bits to rbg 16 bits + * + * @m: conversion matrix to use + * @y, @cb, @cr: component of the ycbcr pixel + * @r, @g, @b: pointers to write the rbg pixel + */ static void ycbcr2rgb(const s16 m[3][3], u8 y, u8 cb, u8 cr, u8 y_offset, u8 *r, u8 *g, u8 *b) { s32 y_16, cb_16, cr_16; s32 r_16, g_16, b_16; - y_16 = y - y_offset; + y_16 = y - y_offset; cb_16 = cb - 128; cr_16 = cr - 128; @@ -139,6 +160,14 @@ static void ycbcr2rgb(const s16 m[3][3], u8 y, u8 cb, u8 cr, u8 y_offset, u8 *r, *b = clamp(b_16, 0, 0xffff) >> 8; } +/** + * yuv_u8_to_argb_u16() - helper to convert yuv 8 bits to argb 16 bits + * + * @argb_u16: pointer to write the converted pixel + * @yuv_u8: pointer to the source yuv pixel + * @encoding: encoding to use + * @range: range to use + */ VISIBLE_IF_KUNIT void yuv_u8_to_argb_u16(struct pixel_argb_u16 *argb_u16, const struct pixel_yuv_u8 *yuv_u8, enum drm_color_encoding encoding, @@ -205,104 +234,89 @@ VISIBLE_IF_KUNIT void yuv_u8_to_argb_u16(struct pixel_argb_u16 *argb_u16, } EXPORT_SYMBOL_IF_KUNIT(yuv_u8_to_argb_u16); -static void semi_planar_yuv_to_argb_u16(u8 **src_pixels, struct pixel_argb_u16 *out_pixel, +static void semi_planar_yuv_to_argb_u16(struct vkms_frame_info *frame_info, int x, + int y, struct pixel_argb_u16 *out_pixel, enum drm_color_encoding encoding, enum drm_color_range range) { struct pixel_yuv_u8 yuv_u8; - yuv_u8.y = src_pixels[0][0]; - yuv_u8.u = src_pixels[1][0]; - yuv_u8.v = src_pixels[1][1]; + /* Subsampling must be applied for semi-planar yuv formats */ + int vsub = frame_info->fb->format->vsub; + int hsub = frame_info->fb->format->hsub; + + u8 *src_y = packed_pixels_addr(frame_info, x, y, 0); + u8 *src_uv = packed_pixels_addr(frame_info, x / hsub, y / vsub, 1); + + yuv_u8.y = src_y[0]; + yuv_u8.u = src_uv[0]; + yuv_u8.v = src_uv[1]; yuv_u8_to_argb_u16(out_pixel, &yuv_u8, encoding, range); } -static void semi_planar_yvu_to_argb_u16(u8 **src_pixels, struct pixel_argb_u16 *out_pixel, +static void semi_planar_yvu_to_argb_u16(struct vkms_frame_info *frame_info, int x, + int y, struct pixel_argb_u16 *out_pixel, enum drm_color_encoding encoding, enum drm_color_range range) { struct pixel_yuv_u8 yuv_u8; - yuv_u8.y = src_pixels[0][0]; - yuv_u8.v = src_pixels[1][0]; - yuv_u8.u = src_pixels[1][1]; + /* Subsampling must be applied for semi-planar yuv formats */ + int vsub = frame_info->fb->format->vsub ? frame_info->fb->format->vsub : 1; + int hsub = frame_info->fb->format->hsub ? frame_info->fb->format->hsub : 1; + u8 *src_y = packed_pixels_addr(frame_info, x, y, 0); + u8 *src_vu = packed_pixels_addr(frame_info, x / hsub, y / vsub, 1); + + yuv_u8.y = src_y[0]; + yuv_u8.v = src_vu[0]; + yuv_u8.u = src_vu[1]; yuv_u8_to_argb_u16(out_pixel, &yuv_u8, encoding, range); } -static void planar_yuv_to_argb_u16(u8 **src_pixels, struct pixel_argb_u16 *out_pixel, - enum drm_color_encoding encoding, enum drm_color_range range) +static void planar_yuv_to_argb_u16(struct vkms_frame_info *frame_info, int x, int y, + struct pixel_argb_u16 *out_pixel, + enum drm_color_encoding encoding, + enum drm_color_range range) { struct pixel_yuv_u8 yuv_u8; - yuv_u8.y = src_pixels[0][0]; - yuv_u8.u = src_pixels[1][0]; - yuv_u8.v = src_pixels[2][0]; + /* Subsampling must be applied for planar yuv formats */ + int vsub = frame_info->fb->format->vsub ? frame_info->fb->format->vsub : 1; + int hsub = frame_info->fb->format->hsub ? frame_info->fb->format->hsub : 1; + + u8 *src_y = packed_pixels_addr(frame_info, x, y, 0); + u8 *src_u = packed_pixels_addr(frame_info, x / hsub, y / vsub, 1); + u8 *src_v = packed_pixels_addr(frame_info, x / hsub, y / vsub, 2); + + yuv_u8.y = src_y[0]; + yuv_u8.u = src_u[0]; + yuv_u8.v = src_v[0]; yuv_u8_to_argb_u16(out_pixel, &yuv_u8, encoding, range); } -static void planar_yvu_to_argb_u16(u8 **src_pixels, struct pixel_argb_u16 *out_pixel, - enum drm_color_encoding encoding, enum drm_color_range range) +static void planar_yvu_to_argb_u16(struct vkms_frame_info *frame_info, int x, int y, + struct pixel_argb_u16 *out_pixel, + enum drm_color_encoding encoding, + enum drm_color_range range) { struct pixel_yuv_u8 yuv_u8; - yuv_u8.y = src_pixels[0][0]; - yuv_u8.v = src_pixels[1][0]; - yuv_u8.u = src_pixels[2][0]; + /* Subsampling must be applied for semi-planar yuv formats */ + int vsub = frame_info->fb->format->vsub ? frame_info->fb->format->vsub : 1; + int hsub = frame_info->fb->format->hsub ? frame_info->fb->format->hsub : 1; - yuv_u8_to_argb_u16(out_pixel, &yuv_u8, encoding, range); -} + u8 *src_y = packed_pixels_addr(frame_info, x, y, 0); + u8 *src_u = packed_pixels_addr(frame_info, x / hsub, y / vsub, 1); + u8 *src_v = packed_pixels_addr(frame_info, x / hsub, y / vsub, 2); -/** - * vkms_compose_row - compose a single row of a plane - * @stage_buffer: output line with the composed pixels - * @plane: state of the plane that is being composed - * @y: y coordinate of the row - * - * This function composes a single row of a plane. It gets the source pixels - * through the y coordinate (see get_packed_src_addr()) and goes linearly - * through the source pixel, reading the pixels and converting it to - * ARGB16161616 (see the pixel_read() callback). For rotate-90 and rotate-270, - * the source pixels are not traversed linearly. The source pixels are queried - * on each iteration in order to traverse the pixels vertically. - */ -void vkms_compose_row(struct line_buffer *stage_buffer, struct vkms_plane_state *plane, int y) -{ - struct pixel_argb_u16 *out_pixels = stage_buffer->pixels; - struct vkms_frame_info *frame_info = plane->frame_info; - const struct drm_format_info *frame_format = frame_info->fb->format; - int limit = min_t(size_t, drm_rect_width(&frame_info->dst), stage_buffer->n_pixels); - u8 *src_pixels[DRM_FORMAT_MAX_PLANES]; - - enum drm_color_encoding encoding = plane->base.base.color_encoding; - enum drm_color_range range = plane->base.base.color_range; - - for (size_t i = 0; i < frame_format->num_planes; i++) - src_pixels[i] = get_packed_src_addr(frame_info, y, i); - - for (size_t x = 0; x < limit; x++) { - int x_pos = get_x_position(frame_info, limit, x); - - bool shoud_inc = !((x + 1) % frame_format->num_planes); - - if (drm_rotation_90_or_270(frame_info->rotation)) { - for (size_t i = 0; i < frame_format->num_planes; i++) { - src_pixels[i] = get_packed_src_addr(frame_info, - x + frame_info->rotated.y1, i); - if (!i || shoud_inc) - src_pixels[i] += frame_format->cpp[i] * y; - } - } - - plane->pixel_read(src_pixels, &out_pixels[x_pos], encoding, range); - - for (size_t i = 0; i < frame_format->num_planes; i++) { - if (!i || shoud_inc) - src_pixels[i] += frame_format->cpp[i]; - } - } + yuv_u8.y = src_y[0]; + yuv_u8.v = src_u[0]; + yuv_u8.u = src_v[0]; + + yuv_u8_to_argb_u16(out_pixel, &yuv_u8, encoding, range); } /* diff --git a/drivers/gpu/drm/vkms/vkms_plane.c b/drivers/gpu/drm/vkms/vkms_plane.c index 932736fc3ee9..d818ed246a46 100644 --- a/drivers/gpu/drm/vkms/vkms_plane.c +++ b/drivers/gpu/drm/vkms/vkms_plane.c @@ -118,13 +118,20 @@ static void vkms_plane_atomic_update(struct drm_plane *plane, return; fmt = fb->format->format; + pixel_read_t pixel_read = get_pixel_conversion_function(fmt); + + if (!pixel_read) { + DRM_WARN("The requested pixel format is not supported by VKMS. The new state is " + "not applied.\n"); + return; + } + vkms_plane_state = to_vkms_plane_state(new_state); shadow_plane_state = &vkms_plane_state->base; frame_info = vkms_plane_state->frame_info; memcpy(&frame_info->src, &new_state->src, sizeof(struct drm_rect)); memcpy(&frame_info->dst, &new_state->dst, sizeof(struct drm_rect)); - memcpy(&frame_info->rotated, &new_state->dst, sizeof(struct drm_rect)); frame_info->fb = fb; memcpy(&frame_info->map, &shadow_plane_state->data, sizeof(frame_info->map)); drm_framebuffer_get(frame_info->fb); @@ -134,10 +141,8 @@ static void vkms_plane_atomic_update(struct drm_plane *plane, DRM_MODE_REFLECT_X | DRM_MODE_REFLECT_Y); - drm_rect_rotate(&frame_info->rotated, drm_rect_width(&frame_info->rotated), - drm_rect_height(&frame_info->rotated), frame_info->rotation); - vkms_plane_state->pixel_read = get_pixel_conversion_function(fmt); + vkms_plane_state->pixel_read = pixel_read; } static int vkms_plane_atomic_check(struct drm_plane *plane,