[Concept,02/36] video: Pass context to vidconsole_set_cursor_pos()

Message ID 20260120231814.2033069-3-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>

Add a ctx parameter to vidconsole_set_cursor_pos() to allow callers to
specify which vidconsole context to use. If NULL is passed, the function
falls back to using the default context from vidconsole_priv.

This enables text-input objects to use their own context for cursor
positioning.

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

 boot/expo_test.c                  | 10 +++++-----
 boot/scene.c                      |  4 ++--
 boot/scene_txtin.c                |  2 +-
 cmd/video.c                       |  2 +-
 drivers/video/vidconsole-uclass.c |  6 +++---
 include/video_console.h           |  3 ++-
 6 files changed, 14 insertions(+), 13 deletions(-)
  

Patch

diff --git a/boot/expo_test.c b/boot/expo_test.c
index a5ad571eedb..ae4e70ceede 100644
--- a/boot/expo_test.c
+++ b/boot/expo_test.c
@@ -180,14 +180,14 @@  int expo_test_render(struct expo *exp)
 	snprintf(buf, sizeof(buf), "frame  %6d", test->render_count);
 	x = vid_priv->xsize - 18 * ctx->x_charsize;
 	y = 10;
-	vidconsole_set_cursor_pos(exp->cons, x, y);
+	vidconsole_set_cursor_pos(exp->cons, NULL, x, y);
 	vidconsole_put_string(exp->cons, buf);
 
 	/* Display FPS on next line (only if non-zero) */
 	if (test->fps_last > 0) {
 		snprintf(buf, sizeof(buf), "fps    %6d", test->fps_last);
 		y += ctx->y_charsize;
-		vidconsole_set_cursor_pos(exp->cons, x, y);
+		vidconsole_set_cursor_pos(exp->cons, NULL, x, y);
 		vidconsole_put_string(exp->cons, buf);
 	}
 
@@ -196,7 +196,7 @@  int expo_test_render(struct expo *exp)
 		 test->render_avg_us / 1000,
 		 (test->render_avg_us % 1000) / 100);
 	y += ctx->y_charsize;
-	vidconsole_set_cursor_pos(exp->cons, x, y);
+	vidconsole_set_cursor_pos(exp->cons, NULL, x, y);
 	vidconsole_put_string(exp->cons, buf);
 
 	/* Display average sync time in milliseconds on next line */
@@ -204,7 +204,7 @@  int expo_test_render(struct expo *exp)
 		 test->sync_avg_us / 1000,
 		 (test->sync_avg_us % 1000) / 100);
 	y += ctx->y_charsize;
-	vidconsole_set_cursor_pos(exp->cons, x, y);
+	vidconsole_set_cursor_pos(exp->cons, NULL, x, y);
 	vidconsole_put_string(exp->cons, buf);
 
 	/* Display average poll time in milliseconds on next line */
@@ -212,7 +212,7 @@  int expo_test_render(struct expo *exp)
 		 test->poll_avg_us / 1000,
 		 (test->poll_avg_us % 1000) / 100);
 	y += ctx->y_charsize;
-	vidconsole_set_cursor_pos(exp->cons, x, y);
+	vidconsole_set_cursor_pos(exp->cons, NULL, x, y);
 	vidconsole_put_string(exp->cons, buf);
 
 	return 0;
diff --git a/boot/scene.c b/boot/scene.c
index 306625361b4..16814d53b65 100644
--- a/boot/scene.c
+++ b/boot/scene.c
@@ -685,7 +685,7 @@  static int scene_txt_render(struct expo *exp, struct udevice *dev,
 	bbox.y1 = obj->bbox.y1;
 
 	if (!mline) {
-		vidconsole_set_cursor_pos(cons, x, y);
+		vidconsole_set_cursor_pos(cons, NULL, x, y);
 		draw_string(cons, str, strlen(str),
 			    obj->flags & SCENEOF_PASSWORD);
 	}
@@ -704,7 +704,7 @@  static int scene_txt_render(struct expo *exp, struct udevice *dev,
 		y = obj->bbox.y0 + offset.yofs + mline->bbox.y0;
 		if (y > bbox.y1)
 			break;	/* clip this line and any following */
-		vidconsole_set_cursor_pos(cons, x, y);
+		vidconsole_set_cursor_pos(cons, NULL, x, y);
 		draw_string(cons, str + mline->start, mline->len,
 			    obj->flags & SCENEOF_PASSWORD);
 	}
diff --git a/boot/scene_txtin.c b/boot/scene_txtin.c
index d1aa24dac9f..fd7cefa1d5b 100644
--- a/boot/scene_txtin.c
+++ b/boot/scene_txtin.c
@@ -126,7 +126,7 @@  int scene_txtin_open(struct scene *scn, struct scene_obj *obj,
 	if (!txt)
 		return log_msg_ret("cur", -ENOENT);
 
-	vidconsole_set_cursor_pos(cons, txt->obj.bbox.x0, txt->obj.bbox.y0);
+	vidconsole_set_cursor_pos(cons, NULL, txt->obj.bbox.x0, txt->obj.bbox.y0);
 	vidconsole_entry_start(cons);
 	cli_cread_init(&scn->cls, abuf_data(&tin->buf), tin->line_chars);
 	scn->cls.insert = true;
diff --git a/cmd/video.c b/cmd/video.c
index 4f00ffa2f77..5c228b48058 100644
--- a/cmd/video.c
+++ b/cmd/video.c
@@ -85,7 +85,7 @@  static int do_video_write(struct cmd_tbl *cmdtp, int flag, int argc,
 		row = hextoul(colon + 1, NULL);
 
 		if (use_pixels)
-			vidconsole_set_cursor_pos(dev, col, row);
+			vidconsole_set_cursor_pos(dev, NULL, col, row);
 		else
 			vidconsole_position_cursor(dev, col, row);
 
diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c
index 05426138b09..17366d2de40 100644
--- a/drivers/video/vidconsole-uclass.c
+++ b/drivers/video/vidconsole-uclass.c
@@ -130,10 +130,10 @@  static char *parsenum(char *s, int *num)
 	return end;
 }
 
-void vidconsole_set_cursor_pos(struct udevice *dev, int x, int y)
+void vidconsole_set_cursor_pos(struct udevice *dev, void *ctxp, int x, int y)
 {
 	struct vidconsole_priv *priv = dev_get_uclass_priv(dev);
-	struct vidconsole_ctx *ctx = vidconsole_ctx_from_priv(priv);
+	struct vidconsole_ctx *ctx = ctxp ? ctxp : vidconsole_ctx_from_priv(priv);
 
 	/* Hide cursor at old position if it's visible */
 	vidconsole_hide_cursor(dev);
@@ -964,7 +964,7 @@  void vidconsole_position_cursor(struct udevice *dev, unsigned col, unsigned row)
 
 	x = min_t(short, col * ctx->x_charsize, vid_priv->xsize - 1);
 	y = min_t(short, row * ctx->y_charsize, vid_priv->ysize - 1);
-	vidconsole_set_cursor_pos(dev, x, y);
+	vidconsole_set_cursor_pos(dev, NULL, x, y);
 }
 
 void vidconsole_set_quiet(struct udevice *dev, bool quiet)
diff --git a/include/video_console.h b/include/video_console.h
index 0e9784c8e3c..a91b2a510b4 100644
--- a/include/video_console.h
+++ b/include/video_console.h
@@ -774,10 +774,11 @@  int vidconsole_clear_and_reset(struct udevice *dev);
  * updated to the same position, so that a newline will return to @x
  *
  * @dev:	video console device to update
+ * @ctx:	vidconsole context to use, or NULL to use the default
  * @x:		x position from left in pixels
  * @y:		y position from top in pixels
  */
-void vidconsole_set_cursor_pos(struct udevice *dev, int x, int y);
+void vidconsole_set_cursor_pos(struct udevice *dev, void *ctx, int x, int y);
 
 /**
  * vidconsole_list_fonts() - List the available fonts