From patchwork Fri Sep 19 20:14:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 351 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=1758312963; bh=Uw8zJaZ6p06sAipoBXxM/n8Y0lJIOGyW06cf3WGmqT0=; 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=v7F4GApW7g9hrOhs8j3oYXrxceamRMjDRBHVDTjwHafm8XBBUq9+vMAwyRxSlLJ+y xCnPhaYiWAhZhft2B286qkvlYFa8d7Cc/6DEzzswNpgC7e8U2GATdBJRgkG6OcGAba 0mA667B+OOccwQD1EOiF/71q0jX9TBb5kOqxXK4PvUKrsZXzvFGqlsV0CdEyhVIRxA 4yRYSHROiTX/FU5ZBVNgNt7Hx6rVexx0XJe9bRw6WCKwJcOpWPHCVMXs8A6Ozl7Vve kF91IX/T2Gqo/CWdY88GX6kfDFgSeFy9jMX2RAxz80h3cPlA+meWk+BdUMx2nnfSeD iX7rsfHtezgpQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 3999B67C70 for ; Fri, 19 Sep 2025 14:16:03 -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 Xvqn556jCDPd for ; Fri, 19 Sep 2025 14:16:03 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1758312962; bh=Uw8zJaZ6p06sAipoBXxM/n8Y0lJIOGyW06cf3WGmqT0=; 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=ahvSp8FAgi9X57PRHfdbBHP1wjWkfMyPUZI7uRbBu1m7d1rUKqRNGLrnaa09YZHFH 8jI28+u3jbqVZqMO6MRWzPSq9ffT6TG2x3e/+WIctMY35QCKMv5AgOrcjpsa4Wy7A9 U01P3wu58L8SvmSZPUcmI8dAFB3RTfk5+15PinASCus6E62V6efYVSzmRzHI/5NyNY ZZPNcQdx9TXspx35JIT7NrH/O4nF76UH/ckv9StT/obWKFZzxg/jTyuTL4hJB0Omkg m+Kpjh2c4wc+onDreSpOJPjwAtUy1zD0CEfqhiGBZMJ4BV0eW5NGWs7O8QV+9/roYN RdGcDdw8jh9Vg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 1BFDD67B3B for ; Fri, 19 Sep 2025 14:16:02 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1758312960; bh=oEwIc+swvxhvUpNt0PS6sEekoIJ+L9yQEw0w7N9okvU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Chzj4aJa1nEO/tdbierL2J0S+8MlsjQwsvAn62tATLxIiZSDSiKMVVVdg/hTmdykQ 0rwn/crbW0WVzqX+/ejhosSOkbFb5ccG6KDtTdhcSqNUs48pNOqWUCCLO01A0Rlg2V SZqt5yHvQi724WQVsQfLK9BcFEHR4PfrmIKlde80kvvJGDrMCQDkJAy+Gn4d6EB8x5 5oU+g8A9gcuG3wLoezKmR8jSm7Rk4j37V9nPl8pkWZcgCOc3p74XTb6jE44jPqfjwP sxVq6Q/f92+GKKnnP48psRqNqKPd1TTp7DGqJNRoi6ZEtF0Y38zuZKnM6AqBu68p4T SVbexzfgn556w== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C234C67C75; Fri, 19 Sep 2025 14:16:00 -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 cnjGd6-tvc_2; Fri, 19 Sep 2025 14:16:00 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1758312958; bh=lttb+dZCH2/largQQFAmMfR8OFYz0C8i55bRxUDdcik=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hach2Zjwh8qET/D4375+JywasCGtmJZgKsniQ3OBafkljaoB5JRxOIq4J2nFukJw7 cEarbKOm3Ce7kMcpuhhJ/nc/oi1hTErwLauRiIn87jWUWQVO84a80bZPd20BAaJaNM xE6oAkK/6264N4QnRZIJtS9hRHzIcAK9eqoadA5ZSHvdzlSs+hvR1vSWQVENx6/Ed5 OI1D/Vr2zya95dp1W7J2iCqR0/1AkuRjxCRCqsJulirVP4rXHaoi/gGvRrL06cE1BL cp7qicNGknwrK6Rp6dIKo/RPnEEdW7ltbKzNWDhOeBZsTSbxDlp4BQ4McFL8PYp+vd oIA7DmIvABDrA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 14E8B67C0E; Fri, 19 Sep 2025 14:15:58 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Fri, 19 Sep 2025 14:14:16 -0600 Message-ID: <20250919201507.4024144-10-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250919201507.4024144-1-sjg@u-boot.org> References: <20250919201507.4024144-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: O7FSTLDM7SXVQTIVHBWI5PVXIZCNO6OS X-Message-ID-Hash: O7FSTLDM7SXVQTIVHBWI5PVXIZCNO6OS 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 09/42] video: console: Put fixed-font rendering into a shared file 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 Move fixed-font, character-rendering from console_normal.c into a shared function in console_core.c. This will allow truetype to use the fixed fonts as well as its own. Co-developed-by: Claude --- drivers/video/console_core.c | 33 ++++++++++++++++++++++++ drivers/video/console_normal.c | 39 ++++++----------------------- drivers/video/vidconsole_internal.h | 24 ++++++++++++++++++ 3 files changed, 64 insertions(+), 32 deletions(-) diff --git a/drivers/video/console_core.c b/drivers/video/console_core.c index 939363653f6..4b75a5b6e12 100644 --- a/drivers/video/console_core.c +++ b/drivers/video/console_core.c @@ -228,6 +228,39 @@ int console_simple_get_font(struct udevice *dev, int seq, struct vidfont_info *i return info->name ? 0 : -ENOENT; } +int console_fixed_putc_xy(struct udevice *dev, uint x_frac, uint y, int cp, + struct video_fontdata *fontdata) +{ + struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); + struct udevice *vid = dev->parent; + struct video_priv *vid_priv = dev_get_uclass_priv(vid); + int pbytes = VNBYTES(vid_priv->bpix); + int x, linenum, ret; + void *start, *line; + u8 ch = console_utf_to_cp437(cp); + uchar *pfont = fontdata->video_fontdata + + ch * fontdata->char_pixel_bytes; + + if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac) + return -EAGAIN; + linenum = y; + x = VID_TO_PIXEL(x_frac); + start = vid_priv->fb + linenum * vid_priv->line_length + x * pbytes; + line = start; + + ret = fill_char_vertically(pfont, &line, vid_priv, fontdata, NORMAL_DIRECTION); + if (ret) + return ret; + + video_damage(dev->parent, + x, + y, + fontdata->width, + fontdata->height); + + return VID_TO_POS(fontdata->width); +} + int console_simple_select_font(struct udevice *dev, const char *name, uint size) { struct video_fontdata *font; diff --git a/drivers/video/console_normal.c b/drivers/video/console_normal.c index a39b04bd73c..9509f81f40f 100644 --- a/drivers/video/console_normal.c +++ b/drivers/video/console_normal.c @@ -68,41 +68,11 @@ static int console_move_rows(struct udevice *dev, uint rowdst, return 0; } -static int console_putc_xy(struct udevice *dev, uint x_frac, uint y, int cp) +int console_normal_putc_xy(struct udevice *dev, uint x_frac, uint y, int cp) { - struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); - struct udevice *vid = dev->parent; - struct video_priv *vid_priv = dev_get_uclass_priv(vid); struct console_simple_priv *priv = dev_get_priv(dev); - struct video_fontdata *fontdata = priv->fontdata; - int pbytes = VNBYTES(vid_priv->bpix); - int x, linenum, ret; - void *start, *line; - u8 ch = console_utf_to_cp437(cp); - uchar *pfont = fontdata->video_fontdata + - ch * fontdata->char_pixel_bytes; - - if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac) - return -EAGAIN; - linenum = y; - x = VID_TO_PIXEL(x_frac); - start = vid_priv->fb + linenum * vid_priv->line_length + x * pbytes; - line = start; - if (x_frac + VID_TO_POS(vc_priv->x_charsize) > vc_priv->xsize_frac) - return -EAGAIN; - - ret = fill_char_vertically(pfont, &line, vid_priv, fontdata, NORMAL_DIRECTION); - if (ret) - return ret; - - video_damage(dev->parent, - x, - y, - fontdata->width, - fontdata->height); - - return VID_TO_POS(fontdata->width); + return console_fixed_putc_xy(dev, x_frac, y, cp, priv->fontdata); } static int __maybe_unused console_set_cursor_visible(struct udevice *dev, @@ -134,6 +104,11 @@ static int __maybe_unused console_set_cursor_visible(struct udevice *dev, return 0; } +static int console_putc_xy(struct udevice *dev, uint x_frac, uint y, int cp) +{ + return console_normal_putc_xy(dev, x_frac, y, cp); +} + struct vidconsole_ops console_ops = { .putc_xy = console_putc_xy, .move_rows = console_move_rows, diff --git a/drivers/video/vidconsole_internal.h b/drivers/video/vidconsole_internal.h index bb0277ee451..af2cca8791c 100644 --- a/drivers/video/vidconsole_internal.h +++ b/drivers/video/vidconsole_internal.h @@ -146,6 +146,30 @@ int console_simple_get_font(struct udevice *dev, int seq, struct vidfont_info *i **/ int console_simple_select_font(struct udevice *dev, const char *name, uint size); +/** + * Normal console putc_xy function that can be called by other console drivers + * + * @param dev console device + * @param x_frac fractional X position + * @param y Y position in pixels + * @param cp Unicode code point + * @returns width in fractional pixels, or -ve on error + */ +int console_normal_putc_xy(struct udevice *dev, uint x_frac, uint y, int cp); + +/** + * Fixed font putc_xy function that can be called with explicit font data + * + * @param dev console device + * @param x_frac fractional X position + * @param y Y position in pixels + * @param cp Unicode code point + * @param fontdata font data to use for rendering + * @returns width in fractional pixels, or -ve on error + */ +int console_fixed_putc_xy(struct udevice *dev, uint x_frac, uint y, int cp, + struct video_fontdata *fontdata); + /** * Internal function to convert Unicode code points to code page 437. * Used by video consoles using bitmap fonts.