From nobody Fri Nov 22 03:53:32 2024 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) (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 A027F1E1338; Mon, 18 Nov 2024 18:28:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.196 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731954518; cv=none; b=hXCJMFfVXDS0BJk6qLD6OZSHeRnSYqj5hHQwMzQBbEOeiU0N/SAGqrBbuki8OcBH/DPjUqbt9Uj+byTdV/mH7GnA0v8NbtJwVqJlw9MBuOZ1HDjbabSMAM+lmr2JNt7PBGxcNdLbKNBkGP5EpVFdV+kUjpOht8mn9gV/kpJkI4c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731954518; c=relaxed/simple; bh=U2uuDNXylIww1C2iIse1SldLLFIaLgZgPM9EJr7nGnE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=k8grkDJlaei2DHoNMb198hR4Wr84bQn4+TCwNlLMfseq2AsZnxZH2fks3hesOdiy+jdEJOjSDooOWAsADjUdOnzWUCgY8EpbCK3pDU22aTBrywwhpao5x7znHFU3y68WJSNbdKXss+M5WH+LmhGLhNbXpnvDn3cv9WJlZDW/ipM= 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=TBMYDuoG; arc=none smtp.client-ip=217.70.183.196 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="TBMYDuoG" Received: by mail.gandi.net (Postfix) with ESMTPSA id AA23DE000C; Mon, 18 Nov 2024 18:28:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1731954515; 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=vK9ytFaaPEDEsPnjBisZ9VIJq0X6SRCq0EddMMj7WU4=; b=TBMYDuoGbQoeVBnULviy+mtXVC8BC09/y9jGZ/Qi16zaoMy55a8uWW/R8a7arxKjxErm7O 7yoiG4UOn64wvyXbh6NofF4JCEmBElgshnsqjmuJPP9snixKuZWy83KLbRdUDOf3AJB6oD pmgEwtcQF9w6YteHZslqGhz0zARYLWmxkSeSf3Umcwgk/2hhsHC6nXypYrfqd43csYTiDs dsvEUiuLICemm6fADxdIRjMm49s1upzss8AFaf5DCcgf1uVqSJkjRuslepuKZgmuTKhDST omROF2kHxqa62BeuS5puhFHC4IeQxaAPFJd4YkHs0CRKx8IjnNQUtFgJhnDG/g== From: Louis Chauvet Date: Mon, 18 Nov 2024 19:28:21 +0100 Subject: [PATCH v14 6/9] drm/vkms: Avoid computing blending limits inside pre_mul_alpha_blend 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: <20241118-yuv-v14-6-2dbc2f1e222c@bootlin.com> References: <20241118-yuv-v14-0-2dbc2f1e222c@bootlin.com> In-Reply-To: <20241118-yuv-v14-0-2dbc2f1e222c@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Jonathan Corbet , Louis Chauvet , Simona Vetter , Helen Koike , rdunlap@infradead.org, arthurgrillo@riseup.net, pekka.paalanen@haloniitty.fi, Simona Vetter Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, thomas.petazzoni@bootlin.com, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, seanpaul@google.com, marcheu@google.com, nicolejadeyee@google.com, Pekka Paalanen , =?utf-8?q?Jos=C3=A9_Exp=C3=B3sito?= X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=4191; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=U2uuDNXylIww1C2iIse1SldLLFIaLgZgPM9EJr7nGnE=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnO4dGYi25stMLgzG6NcF6PvkI30j0f4DVCPcYp OJw5/OExf6JAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZzuHRgAKCRAgrS7GWxAs 4p9qEACeMh6xi7K2/oh8ZWR7VasIaub/cbx97/MVcFtuJyKpz00B1DFzNF7lCKJmjru9ysx6jQn XM/zMWDtVL7Kp6cyMvdgrVtH11+xfc5nV9vOJChvQDk0D/erxq7zCCWsWXE64nVwcmZRqIZZvn3 Y0A9HG5by2N3YrUGyWPmBswX8cGTpbO2BcaBodXQtj2gVA1Dx8ozpiT0J4yN546IGe9K+afOCwX s8zRfV/NAZbu20BQB8mKRt0epha/xGnk8QkVu8ypDn/tXkrOaQjvsWllW3nTWt6bvG/NWIkHZSx RNaHR/k303oFz12cVa0d87YQF7Mm12oB3SX3BUSdDEHmHL8GobwpCQwB/pDocnC6ws4JGfPqR1z GAKW8cu3TFEakeeIoI56Xi2PL+iL8klG27OyDGoAl950Z1JPTABkqQ6fLwi4+rjEMNOdvKXMUrD s7l+JoP+t8RAfvVVYZUfDCyY8YfIHsQB/KFYvUB+LvzAUXlWeqpii0IX3pab8vnwVWIdo5yHwnj jzEX7TYZGQpmLTAj/CLEdftMri5/zd/a9YQiGu87Rni4LvbLO+duUkYL1MrRMpt6pcuDoiD0g2S 7e9ISQ3u8aTXkktEU7X12WUFXvR2nc+05AUsE9hAWEDssyhJ91p8hgvFlr3Aner65Hv1EedUHfR DN/X0gwjAxa0+ag== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com The pre_mul_alpha_blend is dedicated to blending, so to avoid mixing different concepts (coordinate calculation and color management), extract the x_limit and x_dst computation outside of this helper. It also increases the maintainability by grouping the computation related to coordinates in the same place: the loop in `blend`. Reviewed-by: Pekka Paalanen Reviewed-by: Jos=C3=A9 Exp=C3=B3sito Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_composer.c | 40 +++++++++++++++++---------------= ---- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_composer.c b/drivers/gpu/drm/vkms/vk= ms_composer.c index 9d1ec06b986fd81949a09e67136dd9bd5c76bf46..e406ab4b14fd4288816565b3cab= ec93cea5834ae 100644 --- a/drivers/gpu/drm/vkms/vkms_composer.c +++ b/drivers/gpu/drm/vkms/vkms_composer.c @@ -24,34 +24,30 @@ static u16 pre_mul_blend_channel(u16 src, u16 dst, u16 = alpha) =20 /** * pre_mul_alpha_blend - alpha blending equation - * @frame_info: Source framebuffer's metadata * @stage_buffer: The line with the pixels from src_plane * @output_buffer: A line buffer that receives all the blends output + * @x_start: The start offset + * @pixel_count: The number of pixels to blend * - * Using the information from the `frame_info`, this blends only the - * necessary pixels from the `stage_buffer` to the `output_buffer` - * using premultiplied blend formula. + * The pixels [0;@pixel_count) in stage_buffer are blended at [@x_start;@x= _start+@pixel_count) in + * output_buffer. * * The current DRM assumption is that pixel color values have been already * pre-multiplied with the alpha channel values. See more * drm_plane_create_blend_mode_property(). Also, this formula assumes a * completely opaque background. */ -static void pre_mul_alpha_blend(struct vkms_frame_info *frame_info, - struct line_buffer *stage_buffer, - struct line_buffer *output_buffer) +static void pre_mul_alpha_blend(const struct line_buffer *stage_buffer, + struct line_buffer *output_buffer, int x_start, int pixel_count) { - int x_dst =3D frame_info->dst.x1; - struct pixel_argb_u16 *out =3D output_buffer->pixels + x_dst; - struct pixel_argb_u16 *in =3D stage_buffer->pixels; - int x_limit =3D min_t(size_t, drm_rect_width(&frame_info->dst), - stage_buffer->n_pixels); - - for (int x =3D 0; x < x_limit; x++) { - out[x].a =3D (u16)0xffff; - out[x].r =3D pre_mul_blend_channel(in[x].r, out[x].r, in[x].a); - out[x].g =3D pre_mul_blend_channel(in[x].g, out[x].g, in[x].a); - out[x].b =3D pre_mul_blend_channel(in[x].b, out[x].b, in[x].a); + struct pixel_argb_u16 *out =3D &output_buffer->pixels[x_start]; + const struct pixel_argb_u16 *in =3D stage_buffer->pixels; + + for (int i =3D 0; i < pixel_count; i++) { + out[i].a =3D (u16)0xffff; + out[i].r =3D pre_mul_blend_channel(in[i].r, out[i].r, in[i].a); + out[i].g =3D pre_mul_blend_channel(in[i].g, out[i].g, in[i].a); + out[i].b =3D pre_mul_blend_channel(in[i].b, out[i].b, in[i].a); } } =20 @@ -183,7 +179,7 @@ static void blend(struct vkms_writeback_job *wb, { struct vkms_plane_state **plane =3D crtc_state->active_planes; u32 n_active_planes =3D crtc_state->num_active_planes; - int y_pos; + int y_pos, x_dst, pixel_count; =20 const struct pixel_argb_u16 background_color =3D { .a =3D 0xffff }; =20 @@ -201,14 +197,16 @@ static void blend(struct vkms_writeback_job *wb, =20 /* The active planes are composed associatively in z-order. */ for (size_t i =3D 0; i < n_active_planes; i++) { + x_dst =3D plane[i]->frame_info->dst.x1; + pixel_count =3D min_t(int, drm_rect_width(&plane[i]->frame_info->dst), + (int)stage_buffer->n_pixels); y_pos =3D get_y_pos(plane[i]->frame_info, y); =20 if (!check_limit(plane[i]->frame_info, y_pos)) continue; =20 vkms_compose_row(stage_buffer, plane[i], y_pos); - pre_mul_alpha_blend(plane[i]->frame_info, stage_buffer, - output_buffer); + pre_mul_alpha_blend(stage_buffer, output_buffer, x_dst, pixel_count); } =20 apply_lut(crtc_state, output_buffer); --=20 2.47.0