[PATCH 4/6] expo: Allow changing scene_img data

Simon Glass sjg at chromium.org
Sat May 24 17:41:10 CEST 2025


In some cases we want to change the image data used by a scene_img. Add
a function to handle this.

Adjust the BMP function to use a const for the data, since it is not
allowed to change it.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 boot/scene.c              | 13 +++++++++++++
 drivers/video/video_bmp.c |  4 ++--
 include/expo.h            | 13 ++++++++++++-
 include/video.h           |  2 +-
 test/boot/expo.c          |  6 ++++++
 5 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/boot/scene.c b/boot/scene.c
index 61b943e2b52..5d2d6617491 100644
--- a/boot/scene.c
+++ b/boot/scene.c
@@ -1173,6 +1173,19 @@ void scene_highlight_first(struct scene *scn)
 	}
 }
 
+int scene_img_set_data(struct scene *scn, uint id, const void *data, int size)
+{
+	struct scene_obj_img *img;
+
+	img = scene_obj_find(scn, id, SCENEOBJT_IMAGE);
+	if (!img)
+		return log_msg_ret("sid", -ENOENT);
+	img->data = data;
+	/* TODO: Consider using an abuf for the image */
+
+	return 0;
+}
+
 static int scene_obj_open(struct scene *scn, struct scene_obj *obj)
 {
 	int ret;
diff --git a/drivers/video/video_bmp.c b/drivers/video/video_bmp.c
index 1f267d45812..478b8fbe5fd 100644
--- a/drivers/video/video_bmp.c
+++ b/drivers/video/video_bmp.c
@@ -242,10 +242,10 @@ static void video_splash_align_axis(int *axis, unsigned long panel_size,
 	*axis = max(0, (int)axis_alignment);
 }
 
-void video_bmp_get_info(void *bmp_image, ulong *widthp, ulong *heightp,
+void video_bmp_get_info(const void *bmp_image, ulong *widthp, ulong *heightp,
 			uint *bpixp)
 {
-	struct bmp_image *bmp = bmp_image;
+	const struct bmp_image *bmp = bmp_image;
 
 	*widthp = get_unaligned_le32(&bmp->header.width);
 	*heightp = get_unaligned_le32(&bmp->header.height);
diff --git a/include/expo.h b/include/expo.h
index 6acbc54c648..522f6a93f98 100644
--- a/include/expo.h
+++ b/include/expo.h
@@ -368,7 +368,7 @@ static inline bool scene_obj_can_highlight(const struct scene_obj *obj)
  */
 struct scene_obj_img {
 	struct scene_obj obj;
-	char *data;
+	const char *data;
 };
 
 /**
@@ -708,6 +708,17 @@ void scene_highlight_first(struct scene *scn);
  */
 void scene_set_highlight_id(struct scene *scn, uint id);
 
+/**
+ * scene_img_set_data() - Set the image data for an image object
+ *
+ * @scn: Scene to update
+ * @id: ID of existing image obejct
+ * @data: Image data to use
+ * @size: Size of image data
+ * Returns: 0 if OK, -ENOENT if @id is invalid
+ */
+int scene_img_set_data(struct scene *scn, uint id, const void *data, int size);
+
 /**
  * scene_set_open() - Set whether an item is open or not
  *
diff --git a/include/video.h b/include/video.h
index 2fbf8a9598a..5b539eafb89 100644
--- a/include/video.h
+++ b/include/video.h
@@ -310,7 +310,7 @@ void video_sync_all(void);
  * @heightp: Returns height in pixels
  * @bpixp: Returns log2 of bits per pixel
  */
-void video_bmp_get_info(void *bmp_image, ulong *widthp, ulong *heightp,
+void video_bmp_get_info(const void *bmp_image, ulong *widthp, ulong *heightp,
 			uint *bpixp);
 
 /**
diff --git a/test/boot/expo.c b/test/boot/expo.c
index b025e48469f..239591ff6cd 100644
--- a/test/boot/expo.c
+++ b/test/boot/expo.c
@@ -262,6 +262,7 @@ static int expo_object_attr(struct unit_test_state *uts)
 	struct expo *exp;
 	ulong start_mem;
 	char name[100];
+	char image[10];
 	ofnode node;
 	char *data;
 	int id;
@@ -305,6 +306,11 @@ static int expo_object_attr(struct unit_test_state *uts)
 	ut_assertok(expo_setup_theme(exp, node));
 	ut_asserteq(30, txt->gen.font_size);
 
+	/* try setting up a fake image */
+	strcpy(image, "wibble");
+	ut_assertok(scene_img_set_data(scn, OBJ_LOGO, image, sizeof(image)));
+	ut_asserteq_str("wibble", img->data);
+
 	expo_destroy(exp);
 
 	ut_assertok(ut_check_delta(start_mem));
-- 
2.43.0

base-commit: e3ced530e543c9f24cbc66430abc6109ce8df015
branch: expa


More information about the U-Boot mailing list