From patchwork Fri Oct 3 16:55:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 495 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759510606; bh=J1Nq8AWo9Nclz9VNw2NfbihMb7u60ymRdsRuVj8KcFA=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=cO+rlXIKhI+9O0R2bYssBypvu1Yn/aCxAcPfWqmXArV3YtecwOjZRKM3yaW8230rG t/PFdIXBe3cpWd4t1jEftEZh+1PvzXCfyDJvYnNons9Iq1deph7I8q/IIDew9BbTy2 WJaIBjeEpyEg5LpvzxHYr9Nkbah+4/uYBzs2iu/Y+ISMvSO85OO9ukdJsSvPBoSbOP RxKFmBcuFfUXO+tOlEvsdVVMPMbM9mOtdrq46nk9d6Ff0yz0dAuN9Y1IteoDCXKqkz bamwjBfmDqVEwMnkIqgq64XD6nzHnl1EVB/ft3iZQCYrm6RO2NnQZMaUQ4bgVz6fG4 WLrJh7fPJ797Q== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 6DCE767F49 for ; Fri, 3 Oct 2025 10:56:46 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id jvUrwk7rOwS3 for ; Fri, 3 Oct 2025 10:56:46 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759510604; bh=J1Nq8AWo9Nclz9VNw2NfbihMb7u60ymRdsRuVj8KcFA=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=uoP/dbfMwvaC0tK6HnxSd5UaaaJ/XkVn30XviJQC8Oj2SBtad0P1xnwCodk874hgw 99rWGJnKJLiASUcdmRD9zW9bl8c4yVaEjnFINfprtLCiWZpEF3IuCpyu2i463Yoftr d70cvHd6MJcAqNssYvNHlk050xE/ssqMG6OosEOtiwMCFQlwJl3DMa34EhfCl4f4U/ mWZLtIWsJcDjh0CJQwXE88rSmfCRgszxhqHvlGGml6PSpO7neovmozAvKiOW80Pn8E Lgee/XBxr7HXpjgu3wpkDYWsZFoe1hg8i/3X2VrEaTHRa5aPDQtKv5wc3dRqHq+swh kHREREUmqTpQQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 5FDCE67E82 for ; Fri, 3 Oct 2025 10:56:44 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759510601; bh=JhA+0RJNJIgl3Xo0U92fYrFuwJpFQlNDBWvO726CCH0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Fle31+Nzx9NJX1Qldcok6XmlFhaIMuVr7fEnPfzqjUwVtw/b5U0uUQDYTYx7HLtcX 8HEuRWgEQGVEadwi/m3jnLTvLWYJdIclTov4/vbPh0zTTgk+UpocG8kCwF6SmSJ+So PwCzt9tkuSlD5y4fYmZmNCYoO8HUhtn2lROjpSU1JK3Q+9AymuGEs7gY72V2PIa9mm r2wG5ogpag6T1BA8OWAcfufgxfqVDbrU02ePEEvNr1TiXNGEt40QFdI3i0GrFCpZtF Kj0kmbY7C+Ll5qiBoTv2vdAeN2rx/P+7iBTGsiyC5iXE6oLaSlyXp0msrK3ByKvyyo 0iGFFdyIPKpPQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id E30F867E7C; Fri, 3 Oct 2025 10:56:41 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id Uf11FaWNLPMk; Fri, 3 Oct 2025 10:56:41 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759510597; bh=KHdCoNbr8yc1C5bfMc0cHUBxdycNPGCqKRqRu3x63cI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E7THDf3/TQ/JJUb/s8uyVbTRPDuqrK08W7awcldz9cu2CBWmOYmQJJbmagLXvtB4I dHJx0oWUgPOKXhZz47QRYlnJP5Ke8bP4mVRZTtTvLEYlptVslfMimM2qap6WqgKYkE QdLoVuci+CPtHLhLNkY6zY//wx15wcB+xTLfcZG7IY9+80W5DomyWKTRBpFtNjJWRq HWRyq6OQY0PUI78uT09IGgi2i3jM71DHi7KGi7DcbCAuO2F+RvSIFTi3lPGjszgBIq L4hY/fdNXRMCrk3wt5PwBbY/k3mJXSHGI43PVu1TXza7FmC1VHoiUjFxKDf2+PPjJ8 46mIvHPP6+S2g== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 69CF167F4F; Fri, 3 Oct 2025 10:56:37 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Fri, 3 Oct 2025 10:55:07 -0600 Message-ID: <20251003165525.440173-15-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251003165525.440173-1-sjg@u-boot.org> References: <20251003165525.440173-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 62CZUASLFOQUO7OKVCJK6R3QBFBSNKOW X-Message-ID-Hash: 62CZUASLFOQUO7OKVCJK6R3QBFBSNKOW X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 14/22] video: Add a struct video_bbox for damage tracking List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Replace the anonymous struct in video_priv with struct video_bbox for the damage field. Update all references from xstart/ystart/xend/yend to x0/y0/x1/y1 to match the video_bbox field names. Add local video_bbox pointers in functions that access damage fields repeatedly to improve readability. Co-developed-by: Claude Signed-off-by: Simon Glass --- drivers/video/video-uclass.c | 36 +++++++++++++++++++---------------- include/video.h | 13 ++----------- include/video_defs.h | 37 ++++++++++++++++++++++++++++++++++++ test/dm/video.c | 34 +++++++++++++++++---------------- 4 files changed, 77 insertions(+), 43 deletions(-) diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c index f5cd1727fce..5c2cb251683 100644 --- a/drivers/video/video-uclass.c +++ b/drivers/video/video-uclass.c @@ -411,6 +411,7 @@ void video_set_default_colors(struct udevice *dev, bool invert) void video_damage(struct udevice *vid, int x, int y, int width, int height) { struct video_priv *priv = dev_get_uclass_priv(vid); + struct video_bbox *damage = &priv->damage; int xend = x + width; int yend = y + height; @@ -427,10 +428,10 @@ void video_damage(struct udevice *vid, int x, int y, int width, int height) yend = priv->ysize; /* Span a rectangle across all old and new damage */ - priv->damage.xstart = min(x, priv->damage.xstart); - priv->damage.ystart = min(y, priv->damage.ystart); - priv->damage.xend = max(xend, priv->damage.xend); - priv->damage.yend = max(yend, priv->damage.yend); + damage->x0 = min(x, damage->x0); + damage->y0 = min(y, damage->y0); + damage->x1 = max(xend, damage->x1); + damage->y1 = max(yend, damage->y1); } #endif @@ -457,12 +458,12 @@ static void video_flush_dcache(struct udevice *vid, bool use_copy) return; } - if (priv->damage.xend && priv->damage.yend) { - int lstart = priv->damage.xstart * VNBYTES(priv->bpix); - int lend = priv->damage.xend * VNBYTES(priv->bpix); + if (priv->damage.x1 && priv->damage.y1) { + int lstart = priv->damage.x0 * VNBYTES(priv->bpix); + int lend = priv->damage.x1 * VNBYTES(priv->bpix); int y; - for (y = priv->damage.ystart; y < priv->damage.yend; y++) { + for (y = priv->damage.y0; y < priv->damage.y1; y++) { ulong start = fb + (y * priv->line_length) + lstart; ulong end = start + lend - lstart; @@ -477,16 +478,17 @@ static void video_flush_dcache(struct udevice *vid, bool use_copy) static void video_flush_copy(struct udevice *vid) { struct video_priv *priv = dev_get_uclass_priv(vid); + struct video_bbox *damage = &priv->damage; if (!priv->copy_fb) return; - if (priv->damage.xend && priv->damage.yend) { - int lstart = priv->damage.xstart * VNBYTES(priv->bpix); - int lend = priv->damage.xend * VNBYTES(priv->bpix); + if (damage->x1 && damage->y1) { + int lstart = damage->x0 * VNBYTES(priv->bpix); + int lend = damage->x1 * VNBYTES(priv->bpix); int y; - for (y = priv->damage.ystart; y < priv->damage.yend; y++) { + for (y = damage->y0; y < damage->y1; y++) { ulong offset = (y * priv->line_length) + lstart; ulong len = lend - lstart; @@ -527,10 +529,12 @@ int video_sync(struct udevice *vid, bool force) priv->last_sync = get_timer(0); if (IS_ENABLED(CONFIG_VIDEO_DAMAGE)) { - priv->damage.xstart = priv->xsize; - priv->damage.ystart = priv->ysize; - priv->damage.xend = 0; - priv->damage.yend = 0; + struct video_bbox *damage = &priv->damage; + + damage->x0 = priv->xsize; + damage->y0 = priv->ysize; + damage->x1 = 0; + damage->y1 = 0; } return 0; diff --git a/include/video.h b/include/video.h index 1ad5868e2f6..92dca60a872 100644 --- a/include/video.h +++ b/include/video.h @@ -90,11 +90,7 @@ enum video_format { * @fb_size: Frame buffer size * @copy_fb: Copy of the frame buffer to keep up to date; see struct * video_uc_plat - * @damage: A bounding box of framebuffer regions updated since last sync - * @damage.xstart: X start position in pixels from the left - * @damage.ystart: Y start position in pixels from the top - * @damage.xend: X end position in pixels from the left - * @damage.xend: Y end position in pixels from the top + * @damage: Bounding box of framebuffer regions updated since last sync * @line_length: Length of each frame buffer line, in bytes. This can be * set by the driver, but if not, the uclass will set it after * probing @@ -124,12 +120,7 @@ struct video_priv { void *fb; int fb_size; void *copy_fb; - struct { - int xstart; - int ystart; - int xend; - int yend; - } damage; + struct video_bbox damage; int line_length; u32 colour_fg; u32 colour_bg; diff --git a/include/video_defs.h b/include/video_defs.h index 6bd822dc99e..c17959e3146 100644 --- a/include/video_defs.h +++ b/include/video_defs.h @@ -12,4 +12,41 @@ /* Maximum length of an embedded image name */ #define VIDEO_IMAGE_NAMELEN 16 +#ifndef __ASSEMBLY__ + +#include + +/** + * struct video_bbox - Represents a bounding box for video operations + * + * The bounding box is only valid if x1 > x0 and y1 > y0. An invalid bounding + * box (where x1 <= x0 or y1 <= y0) indicates that there is no area to process. + * + * @x0: X start position in pixels from the left + * @y0: Y start position in pixels from the top + * @x1: X end position in pixels from the left + * @y1: Y end position in pixels from the top + */ +struct video_bbox { + int x0; + int y0; + int x1; + int y1; +}; + +/** + * video_bbox_valid() - Check if a bounding box is valid + * + * A valid bounding box has x1 > x0 and y1 > y0. An invalid/inverted bounding + * box (where x1 <= x0 or y1 <= y0) indicates that there is no area to process. + * + * @bbox: Bounding box to check + * Return: true if valid, false if invalid/inverted + */ +static inline bool video_bbox_valid(const struct video_bbox *bbox) +{ + return bbox->x1 > bbox->x0 && bbox->y1 > bbox->y0; +} +#endif /* __ASSEMBLY__ */ + #endif /* __VIDEO_DEFS_H */ diff --git a/test/dm/video.c b/test/dm/video.c index 3defa184b14..7ada4c75bf7 100644 --- a/test/dm/video.c +++ b/test/dm/video.c @@ -903,32 +903,34 @@ static int dm_test_video_damage(struct unit_test_state *uts) ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con)); priv = dev_get_uclass_priv(dev); + struct video_bbox *damage = &priv->damage; + vidconsole_position_cursor(con, 14, 10); vidconsole_put_string(con, test_string_2); - ut_asserteq(449, priv->damage.xstart); - ut_asserteq(325, priv->damage.ystart); - ut_asserteq(661, priv->damage.xend); - ut_asserteq(350, priv->damage.yend); + ut_asserteq(449, damage->x0); + ut_asserteq(325, damage->y0); + ut_asserteq(661, damage->x1); + ut_asserteq(350, damage->y1); vidconsole_position_cursor(con, 7, 5); vidconsole_put_string(con, test_string_1); - ut_asserteq(225, priv->damage.xstart); - ut_asserteq(164, priv->damage.ystart); - ut_asserteq(661, priv->damage.xend); - ut_asserteq(350, priv->damage.yend); + ut_asserteq(225, damage->x0); + ut_asserteq(164, damage->y0); + ut_asserteq(661, damage->x1); + ut_asserteq(350, damage->y1); vidconsole_position_cursor(con, 21, 15); vidconsole_put_string(con, test_string_3); - ut_asserteq(225, priv->damage.xstart); - ut_asserteq(164, priv->damage.ystart); - ut_asserteq(1280, priv->damage.xend); - ut_asserteq(510, priv->damage.yend); + ut_asserteq(225, damage->x0); + ut_asserteq(164, damage->y0); + ut_asserteq(1280, damage->x1); + ut_asserteq(510, damage->y1); video_sync(dev, true); - ut_asserteq(priv->xsize, priv->damage.xstart); - ut_asserteq(priv->ysize, priv->damage.ystart); - ut_asserteq(0, priv->damage.xend); - ut_asserteq(0, priv->damage.yend); + ut_asserteq(priv->xsize, damage->x0); + ut_asserteq(priv->ysize, damage->y0); + ut_asserteq(0, damage->x1); + ut_asserteq(0, damage->y1); ut_asserteq(7335, video_compress_fb(uts, dev, false)); ut_assertok(video_check_copy_fb(uts, dev));