[Concept,27/36] video: Pass context to get_font_size()

Message ID 20260120231814.2033069-28-sjg@u-boot.org
State New
Headers
Series video: Add multiple-context support to vidconsole (part F) |

Commit Message

Simon Glass Jan. 20, 2026, 11:17 p.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

Update the get_font_size() ops method and vidconsole_get_font_size()
wrapper to take a context parameter. This allows callers to query
the font size for a specific context rather than always using the
default.

The wrapper gets the default context if NULL is passed, while the
driver implementations expect a valid context.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---

 cmd/font.c                          | 2 +-
 drivers/video/console_core.c        | 3 ++-
 drivers/video/console_truetype.c    | 5 +++--
 drivers/video/vidconsole-uclass.c   | 7 +++++--
 drivers/video/vidconsole_internal.h | 3 ++-
 include/video_console.h             | 8 ++++++--
 test/cmd/font.c                     | 6 +++---
 7 files changed, 22 insertions(+), 12 deletions(-)
  

Patch

diff --git a/cmd/font.c b/cmd/font.c
index ca759df79a3..6607fcc1373 100644
--- a/cmd/font.c
+++ b/cmd/font.c
@@ -64,7 +64,7 @@  static int do_font_size(struct cmd_tbl *cmdtp, int flag, int argc,
 
 	if (uclass_first_device_err(UCLASS_VIDEO_CONSOLE, &dev))
 		return CMD_RET_FAILURE;
-	ret = vidconsole_get_font_size(dev, &font_name, &size);
+	ret = vidconsole_get_font_size(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 483639e65c4..c26a35e435d 100644
--- a/drivers/video/console_core.c
+++ b/drivers/video/console_core.c
@@ -319,7 +319,8 @@  int console_probe(struct udevice *dev)
 	return 0;
 }
 
-const char *console_simple_get_font_size(struct udevice *dev, uint *sizep)
+const char *console_simple_get_font_size(struct udevice *dev, void *ctx,
+					 uint *sizep)
 {
 	struct console_simple_priv *priv = dev_get_priv(dev);
 
diff --git a/drivers/video/console_truetype.c b/drivers/video/console_truetype.c
index de2992ec748..f797dbe16f9 100644
--- a/drivers/video/console_truetype.c
+++ b/drivers/video/console_truetype.c
@@ -1234,9 +1234,10 @@  static int truetype_get_cursor_info(struct udevice *dev, void *vctx)
 	return 0;
 }
 
-const char *console_truetype_get_font_size(struct udevice *dev, uint *sizep)
+const char *console_truetype_get_font_size(struct udevice *dev, void *vctx,
+					   uint *sizep)
 {
-	struct console_tt_ctx *ctx = vidconsole_ctx(dev);
+	struct console_tt_ctx *ctx = vctx;
 
 	if (ctx->cur_fontdata) {
 		/* Using fixed font */
diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c
index b5a129d82b7..83872b54b5d 100644
--- a/drivers/video/vidconsole-uclass.c
+++ b/drivers/video/vidconsole-uclass.c
@@ -636,14 +636,17 @@  int vidconsole_get_font(struct udevice *dev, int seq,
 	return ops->get_font(dev, seq, info);
 }
 
-int vidconsole_get_font_size(struct udevice *dev, const char **name, uint *sizep)
+int vidconsole_get_font_size(struct udevice *dev, void *ctx, const char **name,
+			     uint *sizep)
 {
 	struct vidconsole_ops *ops = vidconsole_get_ops(dev);
 
+	if (!ctx)
+		ctx = vidconsole_ctx(dev);
 	if (!ops->get_font_size)
 		return -ENOSYS;
 
-	*name = ops->get_font_size(dev, sizep);
+	*name = ops->get_font_size(dev, ctx, sizep);
 	return 0;
 }
 
diff --git a/drivers/video/vidconsole_internal.h b/drivers/video/vidconsole_internal.h
index 60ff7bed758..23d29fea081 100644
--- a/drivers/video/vidconsole_internal.h
+++ b/drivers/video/vidconsole_internal.h
@@ -170,7 +170,8 @@  int console_probe(struct udevice *dev);
  * Internal function to be used in as ops.
  * See details in video_console.h get_font_size function
  **/
-const char *console_simple_get_font_size(struct udevice *dev, uint *sizep);
+const char *console_simple_get_font_size(struct udevice *dev, void *ctx,
+					 uint *sizep);
 
 /**
  * Internal function to be used in as ops.
diff --git a/include/video_console.h b/include/video_console.h
index 500a5974a57..6d635fd5971 100644
--- a/include/video_console.h
+++ b/include/video_console.h
@@ -325,10 +325,12 @@  struct vidconsole_ops {
 	 * get_font_size() - get the current font name and size
 	 *
 	 * @dev: vidconsole device
+	 * @ctx: vidconsole context to use (cannot be NULL)
 	 * @sizep: Place to put the font size (nominal height in pixels)
 	 * Returns: Current font name
 	 */
-	const char *(*get_font_size)(struct udevice *dev, uint *sizep);
+	const char *(*get_font_size)(struct udevice *dev, void *ctx,
+				     uint *sizep);
 
 	/**
 	 * select_font() - Select a particular font by name / size
@@ -842,11 +844,13 @@  void vidconsole_list_fonts(struct udevice *dev);
  * vidconsole_get_font_size() - get the current font name and size
  *
  * @dev: vidconsole device
+ * @ctx: vidconsole context to use (NULL to use default)
  * @sizep: Place to put the font size (nominal height in pixels)
  * @name: pointer to font name, a placeholder for result
  * Return: 0 if OK, -ENOSYS if not implemented in driver
  */
-int vidconsole_get_font_size(struct udevice *dev, const char **name, uint *sizep);
+int vidconsole_get_font_size(struct udevice *dev, void *ctx, const char **name,
+			     uint *sizep);
 
 /**
  * vidconsole_set_quiet() - Select whether the console should output stdio
diff --git a/test/cmd/font.c b/test/cmd/font.c
index 4991608e267..eab832347cb 100644
--- a/test/cmd/font.c
+++ b/test/cmd/font.c
@@ -43,7 +43,7 @@  static int font_test_base(struct unit_test_state *uts)
 
 	ut_assert_console_end();
 
-	ut_assertok(vidconsole_get_font_size(dev, &name, &size));
+	ut_assertok(vidconsole_get_font_size(dev, NULL, &name, &size));
 	if (IS_ENABLED(CONFIG_CONSOLE_TRUETYPE_ANKACODER))
 		ut_asserteq_str("ankacoder_c75_r", name);
 	else if (IS_ENABLED(CONFIG_CONSOLE_TRUETYPE_NIMBUS))
@@ -71,7 +71,7 @@  static int font_test_base(struct unit_test_state *uts)
 	ut_assertok(ret);
 	ut_assert_console_end();
 
-	ut_assertok(vidconsole_get_font_size(dev, &name, &size));
+	ut_assertok(vidconsole_get_font_size(dev, NULL, &name, &size));
 	ut_asserteq_str("cantoraone_regular", name);
 	ut_asserteq(40, size);
 	ut_assertok(ut_check_console_end(uts));
@@ -90,7 +90,7 @@  static int font_test_base(struct unit_test_state *uts)
 	ut_assertok(run_command("font select", 0));
 	ut_assertok(ut_check_console_end(uts));
 
-	ut_assertok(vidconsole_get_font_size(dev, &name, &size));
+	ut_assertok(vidconsole_get_font_size(dev, NULL, &name, &size));
 	ut_asserteq_str("nimbus_sans_l_regular", name);
 	ut_asserteq(CONFIG_CONSOLE_TRUETYPE_SIZE, size);