[Concept,17/36] video: Pass context to vidconsole_show/hide_cursor()

Message ID 20260120231814.2033069-18-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 vctx parameter to vidconsole_show_cursor() and
vidconsole_hide_cursor() to allow passing in a specific vidconsole
context. If NULL, the default context from priv is used.

Update all callers accordingly.

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

 boot/scene_txtin.c                |  2 +-
 drivers/video/vidconsole-uclass.c | 20 ++++++++++----------
 include/video_console.h           | 10 ++++++----
 test/dm/video.c                   |  4 ++--
 4 files changed, 19 insertions(+), 17 deletions(-)
  

Patch

diff --git a/boot/scene_txtin.c b/boot/scene_txtin.c
index 296b2fb1a1b..007f827f776 100644
--- a/boot/scene_txtin.c
+++ b/boot/scene_txtin.c
@@ -84,7 +84,7 @@  int scene_txtin_render_deps(struct scene *scn, struct scene_obj *obj,
 		if (ret)
 			return log_msg_ret("sav", ret);
 
-		vidconsole_show_cursor(cons);
+		vidconsole_show_cursor(cons, NULL);
 	}
 
 	return 0;
diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c
index 6258513b07e..7b23a0a68ac 100644
--- a/drivers/video/vidconsole-uclass.c
+++ b/drivers/video/vidconsole-uclass.c
@@ -76,7 +76,7 @@  static int vidconsole_back(struct udevice *dev, struct vidconsole_ctx *ctx)
 	}
 
 	/* Hide cursor at old position if it's visible */
-	vidconsole_hide_cursor(dev);
+	vidconsole_hide_cursor(dev, ctx);
 
 	ctx->xcur_frac -= VID_TO_POS(ctx->x_charsize);
 	if (ctx->xcur_frac < ctx->xstart_frac) {
@@ -136,10 +136,10 @@  static char *parsenum(char *s, int *num)
 void vidconsole_set_cursor_pos(struct udevice *dev, void *vctx, int x, int y)
 {
 	struct vidconsole_priv *priv = dev_get_uclass_priv(dev);
-	struct vidconsole_ctx *ctx = vctx ? vctx : vidconsole_ctx_from_priv(priv);
+	struct vidconsole_ctx *ctx = vctx ?: vidconsole_ctx_from_priv(priv);
 
 	/* Hide cursor at old position if it's visible */
-	vidconsole_hide_cursor(dev);
+	vidconsole_hide_cursor(dev, ctx);
 
 	ctx->xcur_frac = VID_TO_POS(x);
 	ctx->xstart_frac = ctx->xcur_frac;
@@ -147,7 +147,7 @@  void vidconsole_set_cursor_pos(struct udevice *dev, void *vctx, int x, int y)
 
 	/* make sure not to kern against the previous character */
 	ctx->last_ch = 0;
-	vidconsole_entry_start(dev, NULL);
+	vidconsole_entry_start(dev, ctx);
 }
 
 /**
@@ -494,7 +494,7 @@  int vidconsole_put_char(struct udevice *dev, char ch)
 	int cp, ret;
 
 	/* Hide cursor to avoid artifacts */
-	vidconsole_hide_cursor(dev);
+	vidconsole_hide_cursor(dev, ctx);
 
 	if (ansi->escape) {
 		vidconsole_escape_char(dev, ctx, ch);
@@ -767,10 +767,10 @@  int vidconsole_entry_restore(struct udevice *dev, struct abuf *buf)
 }
 
 #ifdef CONFIG_CURSOR
-int vidconsole_show_cursor(struct udevice *dev)
+int vidconsole_show_cursor(struct udevice *dev, void *vctx)
 {
 	struct vidconsole_priv *priv = dev_get_uclass_priv(dev);
-	struct vidconsole_ctx *ctx = vidconsole_ctx_from_priv(priv);
+	struct vidconsole_ctx *ctx = vctx ?: vidconsole_ctx_from_priv(priv);
 	struct vidconsole_ops *ops = vidconsole_get_ops(dev);
 	struct vidconsole_cursor *curs = &ctx->curs;
 	int ret;
@@ -808,10 +808,10 @@  int vidconsole_show_cursor(struct udevice *dev)
 	return 0;
 }
 
-int vidconsole_hide_cursor(struct udevice *dev)
+int vidconsole_hide_cursor(struct udevice *dev, void *vctx)
 {
 	struct vidconsole_priv *priv = dev_get_uclass_priv(dev);
-	struct vidconsole_ctx *ctx = vidconsole_ctx_from_priv(priv);
+	struct vidconsole_ctx *ctx = vctx ?: vidconsole_ctx_from_priv(priv);
 	struct vidconsole_cursor *curs = &ctx->curs;
 	int ret;
 
@@ -1015,7 +1015,7 @@  void vidconsole_idle(struct udevice *dev)
 		 * but vidconsole_show_cursor() calls get_cursor_info() to
 		 * recalc the position anyway.
 		 */
-		vidconsole_show_cursor(dev);
+		vidconsole_show_cursor(dev, ctx);
 	}
 }
 
diff --git a/include/video_console.h b/include/video_console.h
index 2b299661e1b..6b8278123da 100644
--- a/include/video_console.h
+++ b/include/video_console.h
@@ -580,9 +580,10 @@  int vidconsole_entry_restore(struct udevice *dev, struct abuf *buf);
  * Shows a cursor at the current position.
  *
  * @dev: Console device to use
+ * @vctx: Vidconsole context to use, or NULL to use default
  * Return: 0 if OK, -ve on error
  */
-int vidconsole_show_cursor(struct udevice *dev);
+int vidconsole_show_cursor(struct udevice *dev, void *vctx);
 
 /**
  * vidconsole_hide_cursor() - Hide the cursor
@@ -590,9 +591,10 @@  int vidconsole_show_cursor(struct udevice *dev);
  * Hides the cursor if it's currently visible
  *
  * @dev: Console device to use
+ * @vctx: Vidconsole context to use, or NULL to use default
  * Return: 0 if OK, -ve on error
  */
-int vidconsole_hide_cursor(struct udevice *dev);
+int vidconsole_hide_cursor(struct udevice *dev, void *vctx);
 
 /**
  * vidconsole_readline_start() - Enable cursor for a video console
@@ -633,12 +635,12 @@  void vidconsole_readline_start_all(bool indent);
  */
 void vidconsole_readline_end_all(void);
 #else
-static inline int vidconsole_show_cursor(struct udevice *dev)
+static inline int vidconsole_show_cursor(struct udevice *dev, void *vctx)
 {
 	return 0;
 }
 
-static inline int vidconsole_hide_cursor(struct udevice *dev)
+static inline int vidconsole_hide_cursor(struct udevice *dev, void *vctx)
 {
 	return 0;
 }
diff --git a/test/dm/video.c b/test/dm/video.c
index e4599be30a8..ef0c0c5265b 100644
--- a/test/dm/video.c
+++ b/test/dm/video.c
@@ -1198,7 +1198,7 @@  static int check_cursor_backspace(struct unit_test_state *uts,
 	with_a = video_compress_fb(uts, dev, false);
 
 	/* Show cursor at current position (after 'a') */
-	ut_assertok(vidconsole_show_cursor(con));
+	ut_assertok(vidconsole_show_cursor(con, NULL));
 	ut_assert(curs->visible);
 	ut_assert(curs->saved);
 	ut_asserteq(exp_height, curs->height);
@@ -1223,7 +1223,7 @@  static int check_cursor_backspace(struct unit_test_state *uts,
 	ut_assert(after_idle != with_a);
 
 	/* Hide the cursor */
-	ut_assertok(vidconsole_hide_cursor(con));
+	ut_assertok(vidconsole_hide_cursor(con, NULL));
 	ut_assert(curs->enabled);
 	ut_assert(!curs->visible);
 	ut_assert(!curs->saved);