From patchwork Tue Jan 20 23:17:48 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1694 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=1768951213; bh=85esZ88RJ/0/6S8C6mi9vs0nXq5hD/xCaIIuLQM+yTI=; 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=Mn0vpzICV24F5DfsDsfiYLWsXWuVusP5OOx5JeAYaDjFaVuubfhOfPdD90HY0ln6n A3LzmZs+b9kAEOAa7SifAi6BXkKKxLNBKo2dtRyG4WZR6NwOWER5hWQHFcZb2OTGlc E7xgaYZPgxcxaTZ8GGpY6RgQM7zh3I2IyI4dC1GTEegboHcV0WMSXqrtDMuPAUxuXq t2+/aJ6rSaCIhhgZD2fFeLs7mUKv8+6LS8Bb3Uxw4TjySMDeE1ttdK9iy1UoqREPQw dShebte7cx8EPt+9g4CL49rIlX5hYIUJTxq1u2hKLx7GQREDXXGe29wGe/dadXiN5B 880AmRi9QmgHw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 6A99C693E3 for ; Tue, 20 Jan 2026 16:20:13 -0700 (MST) 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 LHgjnBlRJmyS for ; Tue, 20 Jan 2026 16:20:13 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768951213; bh=85esZ88RJ/0/6S8C6mi9vs0nXq5hD/xCaIIuLQM+yTI=; 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=Mn0vpzICV24F5DfsDsfiYLWsXWuVusP5OOx5JeAYaDjFaVuubfhOfPdD90HY0ln6n A3LzmZs+b9kAEOAa7SifAi6BXkKKxLNBKo2dtRyG4WZR6NwOWER5hWQHFcZb2OTGlc E7xgaYZPgxcxaTZ8GGpY6RgQM7zh3I2IyI4dC1GTEegboHcV0WMSXqrtDMuPAUxuXq t2+/aJ6rSaCIhhgZD2fFeLs7mUKv8+6LS8Bb3Uxw4TjySMDeE1ttdK9iy1UoqREPQw dShebte7cx8EPt+9g4CL49rIlX5hYIUJTxq1u2hKLx7GQREDXXGe29wGe/dadXiN5B 880AmRi9QmgHw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 58B736957E for ; Tue, 20 Jan 2026 16:20:13 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768951211; bh=Wk8rO8y+xZNBlEk4u5nYRwrFb7eTFNPnJCkaccieZSA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E+7qM2UTioWk6JufJgfZXpS4omtfh346bqoOUKi1lf1nIrHIVQOe/2ZVWseSAbgri RGC1jQz9goL2OC8Ckk8uxPQ0fH6+NovnPqlhbflmq184IEiZai+Pe73l40z7uv8mzv SVRZYWJCjH8Avlq9v0y7gmn2fuPMj0GnR0fnKkZC/LYpH3IWnHIPAIdtUef46V3/1e kaSskt6c0dC3DhrJUY3IrX67lWZEYt/gSqY1Ye+f3IiligZNtEzar1dkDDs9rZ5DFV PmyCFwrZZ52HzWgf9UWtUHrhYbaqRDiNIW++HaqaW2k6OjJom3APARPl4dWUaoVDOt Cqux52rKLJBWA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id B7E80693E3; Tue, 20 Jan 2026 16:20:11 -0700 (MST) 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 kJq7A54vJz4B; Tue, 20 Jan 2026 16:20:11 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768951207; bh=4Leim3ewp7owwvrYCv0LNS0oT7+eozcOhOysuGn1l3Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nn1mvlXDspTZa6eYM+wyY4unZK8zp+umHZtrFPrkpLopyBOFOv5Ik1zwd6rS0o9KP 5E5ELjkwfCb0aOnaWtsPTqZ3g92ff+n50F8T83ypOdj6lLZlvRxjCTCVpV849QcYb3 T1AZWd1uTnXHzhWKcXrkC6kBJzDD1HqezcSvsPXr/jV40EDKwa4TmPObyqrONUDHHF 8SHHrjb9jrWapR7Tx7D6bPy1it23Fr3f0s7aRfCoQEwHxka1+ZY29EyG66Ml2/lT6e drXY/MAOGzUvcoCdFfP9fIPpSwLY+0CIJhEuk1xkS9btaub+8eP1mxJ5HyZygsClWB zh1jIViosqFgw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 61EDC6913F; Tue, 20 Jan 2026 16:20:07 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Tue, 20 Jan 2026 16:17:48 -0700 Message-ID: <20260120231814.2033069-22-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260120231814.2033069-1-sjg@u-boot.org> References: <20260120231814.2033069-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: V2NP6B5HUNKRWZOECVFVUOAGBA52QPCU X-Message-ID-Hash: V2NP6B5HUNKRWZOECVFVUOAGBA52QPCU 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: Simon Glass , "Claude Opus 4 . 5" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 21/36] video: Pass context to select_font() method 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 Add a context parameter to the select_font() method so that font selection can be done for a specific context rather than always using the default. The vidconsole_select_font() wrapper handles NULL by using the default context, so callers can pass NULL if they don't have a specific context. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- boot/expo_test.c | 2 +- boot/scene.c | 4 ++-- cmd/font.c | 4 ++-- drivers/video/console_core.c | 3 ++- drivers/video/console_truetype.c | 6 +++--- drivers/video/vidconsole-uclass.c | 7 +++++-- drivers/video/vidconsole_internal.h | 3 ++- include/video_console.h | 8 ++++++-- test/dm/video.c | 26 +++++++++++++------------- 9 files changed, 36 insertions(+), 27 deletions(-) diff --git a/boot/expo_test.c b/boot/expo_test.c index 2d5ba7c0f4c..1de597ea603 100644 --- a/boot/expo_test.c +++ b/boot/expo_test.c @@ -135,7 +135,7 @@ int expo_test_render(struct expo *exp) test->render_delta_us = get_timer_us(test->base_time_us); /* Select 8x16 font for test display */ - ret = vidconsole_select_font(exp->cons, "8x16", 0); + ret = vidconsole_select_font(exp->cons, NULL, "8x16", 0); if (ret && ret != -ENOSYS) return log_msg_ret("font", ret); diff --git a/boot/scene.c b/boot/scene.c index e504cb29d51..58be46cb7ee 100644 --- a/boot/scene.c +++ b/boot/scene.c @@ -647,10 +647,10 @@ static int scene_txt_render(struct expo *exp, struct udevice *dev, return -ENOTSUPP; if (gen->font_name || gen->font_size) { - ret = vidconsole_select_font(cons, gen->font_name, + ret = vidconsole_select_font(cons, NULL, gen->font_name, gen->font_size); } else { - ret = vidconsole_select_font(cons, NULL, 0); + ret = vidconsole_select_font(cons, NULL, NULL, 0); } if (ret && ret != -ENOSYS) return log_msg_ret("font", ret); diff --git a/cmd/font.c b/cmd/font.c index 79218779a2d..ca759df79a3 100644 --- a/cmd/font.c +++ b/cmd/font.c @@ -46,7 +46,7 @@ static int do_font_select(struct cmd_tbl *cmdtp, int flag, int argc, name = argv[1]; if (argc == 3) size = dectoul(argv[2], NULL); - ret = vidconsole_select_font(dev, name, size); + ret = vidconsole_select_font(dev, NULL, name, size); if (ret) { printf("Failed (error %d)\n", ret); return CMD_RET_FAILURE; @@ -75,7 +75,7 @@ static int do_font_size(struct cmd_tbl *cmdtp, int flag, int argc, } else { size = dectoul(argv[1], NULL); - ret = vidconsole_select_font(dev, font_name, size); + ret = vidconsole_select_font(dev, NULL, font_name, size); if (ret) { printf("Failed (error %d)\n", ret); return CMD_RET_FAILURE; diff --git a/drivers/video/console_core.c b/drivers/video/console_core.c index ecb0b9dab89..5cb1b3fb2b7 100644 --- a/drivers/video/console_core.c +++ b/drivers/video/console_core.c @@ -369,7 +369,8 @@ int console_fixed_putc_xy(struct udevice *dev, void *vctx, uint x_frac, uint y, return VID_TO_POS(fontdata->width); } -int console_simple_select_font(struct udevice *dev, const char *name, uint size) +int console_simple_select_font(struct udevice *dev, void *ctx, const char *name, + uint size) { struct video_fontdata *font; diff --git a/drivers/video/console_truetype.c b/drivers/video/console_truetype.c index b3884bddd72..af880ad5597 100644 --- a/drivers/video/console_truetype.c +++ b/drivers/video/console_truetype.c @@ -973,10 +973,10 @@ static int get_metrics(struct udevice *dev, const char *name, uint size, return 0; } -static int truetype_select_font(struct udevice *dev, const char *name, - uint size) +static int truetype_select_font(struct udevice *dev, void *vctx, + const char *name, uint size) { - struct console_tt_ctx *ctx = vidconsole_ctx(dev); + struct console_tt_ctx *ctx = vctx; struct console_tt_metrics *met; struct video_fontdata *fontdata; int ret; diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c index 6ef86abc4ce..c0eee7d75fd 100644 --- a/drivers/video/vidconsole-uclass.c +++ b/drivers/video/vidconsole-uclass.c @@ -647,14 +647,17 @@ int vidconsole_get_font_size(struct udevice *dev, const char **name, uint *sizep return 0; } -int vidconsole_select_font(struct udevice *dev, const char *name, uint size) +int vidconsole_select_font(struct udevice *dev, void *ctx, const char *name, + uint size) { struct vidconsole_ops *ops = vidconsole_get_ops(dev); + if (!ctx) + ctx = vidconsole_ctx(dev); if (!ops->select_font) return -ENOSYS; - return ops->select_font(dev, name, size); + return ops->select_font(dev, ctx, name, size); } int vidconsole_measure(struct udevice *dev, const char *name, uint size, diff --git a/drivers/video/vidconsole_internal.h b/drivers/video/vidconsole_internal.h index 8b598b26b13..e1e89f6524a 100644 --- a/drivers/video/vidconsole_internal.h +++ b/drivers/video/vidconsole_internal.h @@ -181,7 +181,8 @@ int console_simple_get_font(struct udevice *dev, int seq, struct vidfont_info *i * Internal function to be used in as ops. * See details in video_console.h select_font function **/ -int console_simple_select_font(struct udevice *dev, const char *name, uint size); +int console_simple_select_font(struct udevice *dev, void *ctx, const char *name, + uint size); /** * Normal console putc_xy function that can be called by other console drivers diff --git a/include/video_console.h b/include/video_console.h index 297049cb851..c5fc0577670 100644 --- a/include/video_console.h +++ b/include/video_console.h @@ -334,11 +334,13 @@ struct vidconsole_ops { * select_font() - Select a particular font by name / size * * @dev: Device to adjust + * @ctx: Context to use * @name: Font name to use (NULL to use default) * @size: Font size to use (0 to use default) * Returns: 0 on success, -ENOENT if no such font */ - int (*select_font)(struct udevice *dev, const char *name, uint size); + int (*select_font)(struct udevice *dev, void *ctx, const char *name, + uint size); /** * measure() - Measure the bounding box of some text @@ -487,10 +489,12 @@ int vidconsole_get_font(struct udevice *dev, int seq, * vidconsole_select_font() - Select a particular font by name / size * * @dev: Device to adjust + * @ctx: Context to use (NULL to use default) * @name: Font name to use (NULL to use default) * @size: Font size to use (0 to use default) */ -int vidconsole_select_font(struct udevice *dev, const char *name, uint size); +int vidconsole_select_font(struct udevice *dev, void *ctx, const char *name, + uint size); /** * vidconsole_measure() - Measure the bounding box of some text diff --git a/test/dm/video.c b/test/dm/video.c index 7a58a64c0f9..b4a1200e481 100644 --- a/test/dm/video.c +++ b/test/dm/video.c @@ -259,7 +259,7 @@ static int dm_test_video_text(struct unit_test_state *uts) ut_assertok(select_vidconsole(uts, "vidconsole0")); ut_assertok(video_get_nologo(uts, &dev)); ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con)); - ut_assertok(vidconsole_select_font(con, "8x16", 0)); + ut_assertok(vidconsole_select_font(con, NULL, "8x16", 0)); ut_asserteq(46, video_compress_fb(uts, dev, false)); ut_assertok(video_check_copy_fb(uts, dev)); @@ -301,7 +301,7 @@ static int dm_test_video_text_12x22(struct unit_test_state *uts) ut_assertok(select_vidconsole(uts, "vidconsole0")); ut_assertok(video_get_nologo(uts, &dev)); ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con)); - ut_assertok(vidconsole_select_font(con, "12x22", 0)); + ut_assertok(vidconsole_select_font(con, NULL, "12x22", 0)); ut_asserteq(46, video_compress_fb(uts, dev, false)); ut_assertok(video_check_copy_fb(uts, dev)); @@ -342,7 +342,7 @@ static int dm_test_video_chars(struct unit_test_state *uts) ut_assertok(select_vidconsole(uts, "vidconsole0")); ut_assertok(video_get_nologo(uts, &dev)); ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con)); - ut_assertok(vidconsole_select_font(con, "8x16", 0)); + ut_assertok(vidconsole_select_font(con, NULL, "8x16", 0)); vidconsole_put_string(con, NULL, test_string); ut_asserteq(466, video_compress_fb(uts, dev, false)); ut_assertok(video_check_copy_fb(uts, dev)); @@ -361,7 +361,7 @@ static int dm_test_video_ansi(struct unit_test_state *uts) ut_assertok(select_vidconsole(uts, "vidconsole0")); ut_assertok(video_get_nologo(uts, &dev)); ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con)); - ut_assertok(vidconsole_select_font(con, "8x16", 0)); + ut_assertok(vidconsole_select_font(con, NULL, "8x16", 0)); /* reference clear: */ video_clear(con->parent); @@ -414,7 +414,7 @@ static int check_vidconsole_output(struct unit_test_state *uts, int rot, ut_assertok(video_get_nologo(uts, &dev)); ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con)); - ut_assertok(vidconsole_select_font(con, "8x16", 0)); + ut_assertok(vidconsole_select_font(con, NULL, "8x16", 0)); ut_asserteq(46, video_compress_fb(uts, dev, false)); ut_assertok(video_check_copy_fb(uts, dev)); @@ -1165,11 +1165,11 @@ static int dm_test_video_font_switch(struct unit_test_state *uts) vidconsole_put_string(con, NULL, truetype_text); /* Switch to bitmap font */ - ut_assertok(vidconsole_select_font(con, "8x16", 0)); + ut_assertok(vidconsole_select_font(con, NULL, "8x16", 0)); vidconsole_put_string(con, NULL, bitmap_text); /* Switch back to TrueType font */ - ut_assertok(vidconsole_select_font(con, NULL, 0)); + ut_assertok(vidconsole_select_font(con, NULL, NULL, 0)); vidconsole_put_string(con, NULL, final_truetype_text); ut_asserteq(14892, video_compress_fb(uts, dev, false)); @@ -1242,7 +1242,7 @@ static int dm_test_video_backspace_normal(struct unit_test_state *uts) ut_assertok(select_vidconsole(uts, "vidconsole0")); ut_assertok(video_get_nologo(uts, &dev)); ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con)); - ut_assertok(vidconsole_select_font(con, "8x16", 0)); + ut_assertok(vidconsole_select_font(con, NULL, "8x16", 0)); ut_assertok(check_cursor_backspace(uts, dev, con, 16)); return 0; @@ -1256,7 +1256,7 @@ static int dm_test_video_backspace_truetype(struct unit_test_state *uts) ut_assertok(video_get_nologo(uts, &dev)); ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con)); - ut_assertok(vidconsole_select_font(con, NULL, 30)); + ut_assertok(vidconsole_select_font(con, NULL, NULL, 30)); ut_assertok(check_cursor_backspace(uts, dev, con, 30)); return 0; @@ -1271,7 +1271,7 @@ static int dm_test_video_cmd(struct unit_test_state *uts) ut_assertok(select_vidconsole(uts, "vidconsole0")); ut_assertok(video_get_nologo(uts, &dev)); ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con)); - ut_assertok(vidconsole_select_font(con, "8x16", 0)); + ut_assertok(vidconsole_select_font(con, NULL, "8x16", 0)); ut_assertok(run_command("setcurs 10 5", 0)); @@ -1412,7 +1412,7 @@ static int dm_test_video_sync_damage(struct unit_test_state *uts) ut_assertok(select_vidconsole(uts, "vidconsole0")); ut_assertok(video_get_nologo(uts, &dev)); ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con)); - ut_assertok(vidconsole_select_font(con, "8x16", 0)); + ut_assertok(vidconsole_select_font(con, NULL, "8x16", 0)); priv = dev_get_uclass_priv(dev); /* Use manual sync to prevent interference with the test */ @@ -1561,7 +1561,7 @@ static int dm_test_video_entry_save(struct unit_test_state *uts) ut_assertok(select_vidconsole(uts, "vidconsole0")); ut_assertok(video_get_nologo(uts, &dev)); ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con)); - ut_assertok(vidconsole_select_font(con, "8x16", 0)); + ut_assertok(vidconsole_select_font(con, NULL, "8x16", 0)); ut_assertok(check_entry_save(uts, con)); @@ -1576,7 +1576,7 @@ static int dm_test_video_entry_save_tt(struct unit_test_state *uts) ut_assertok(video_get_nologo(uts, &dev)); ut_assertok(uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con)); - ut_assertok(vidconsole_select_font(con, NULL, 30)); + ut_assertok(vidconsole_select_font(con, NULL, NULL, 30)); ut_assertok(check_entry_save(uts, con));