[Concept,21/22] video: sandbox: Add sync() method for video

Message ID 20251003165525.440173-22-sjg@u-boot.org
State New
Headers
Series video: Enhancements to support a pointer |

Commit Message

Simon Glass Oct. 3, 2025, 4:55 p.m. UTC
  From: Simon Glass <sjg@chromium.org>

At present, video_sync() has a special case for sandbox. Remove this and
add a sync() method in the sandbox_sdl driver instead.

The sync() method checks the VIDSYNC_FLUSH flag and skips sync operation
if it's not set, avoiding unnecessary SDL updates.

If CONFIG_VIDEO_DAMAGE is enabled, the SDL portion accepts an optional
damage rectangle parameter to support only updating the damaged region.

Use the struct video_bbox definition from the video_defs.h header as
this avoids trying to include too many U-Boot headers in code that is
build with system headers.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
---

 arch/sandbox/cpu/sdl.c         |  5 +++--
 arch/sandbox/include/asm/sdl.h |  7 +++++--
 drivers/video/sandbox_sdl.c    | 19 +++++++++++++++++++
 drivers/video/video-uclass.c   |  4 ----
 4 files changed, 27 insertions(+), 8 deletions(-)
  

Patch

diff --git a/arch/sandbox/cpu/sdl.c b/arch/sandbox/cpu/sdl.c
index f4038c2431a..246fa37d457 100644
--- a/arch/sandbox/cpu/sdl.c
+++ b/arch/sandbox/cpu/sdl.c
@@ -12,6 +12,7 @@ 
 #include <linux/input.h>
 #include <SDL2/SDL.h>
 #include <asm/state.h>
+#include <video_defs.h>
 
 /**
  * struct buf_info - a data buffer holding audio data
@@ -311,7 +312,7 @@  static int copy_to_texture(void *lcd_base, const struct video_bbox *damage)
 	return 0;
 }
 
-int sandbox_sdl_sync(void *lcd_base)
+int sandbox_sdl_sync(void *lcd_base, const struct video_bbox *damage)
 {
 	struct SDL_Rect rect;
 	int ret;
@@ -319,7 +320,7 @@  int sandbox_sdl_sync(void *lcd_base)
 	if (!sdl.texture)
 		return 0;
 	SDL_RenderClear(sdl.renderer);
-	ret = copy_to_texture(lcd_base, NULL);
+	ret = copy_to_texture(lcd_base, damage);
 	if (ret) {
 		printf("copy_to_texture: %d: %s\n", ret, SDL_GetError());
 		return -EIO;
diff --git a/arch/sandbox/include/asm/sdl.h b/arch/sandbox/include/asm/sdl.h
index 735652de6bd..93d934f9c54 100644
--- a/arch/sandbox/include/asm/sdl.h
+++ b/arch/sandbox/include/asm/sdl.h
@@ -10,6 +10,7 @@ 
 #include <video.h>
 
 struct mouse_event;
+struct video_bbox;
 
 #ifdef CONFIG_SANDBOX_SDL
 
@@ -42,9 +43,10 @@  int sandbox_sdl_remove_display(void);
  * user can see it.
  *
  * @lcd_base: Base of frame buffer
+ * @damage: Optional damage rectangle to limit the update region (may be NULL)
  * Return: 0 if screen was updated, -ENODEV is there is no screen.
  */
-int sandbox_sdl_sync(void *lcd_base);
+int sandbox_sdl_sync(void *lcd_base, const struct video_bbox *damage);
 
 /**
  * sandbox_sdl_scan_keys() - scan for pressed keys
@@ -129,7 +131,8 @@  static inline int sandbox_sdl_remove_display(void)
 	return -ENODEV;
 }
 
-static inline int sandbox_sdl_sync(void *lcd_base)
+static inline int sandbox_sdl_sync(void *lcd_base,
+				   const struct video_bbox *damage)
 {
 	return -ENODEV;
 }
diff --git a/drivers/video/sandbox_sdl.c b/drivers/video/sandbox_sdl.c
index 69dfa930273..67b4b6c7911 100644
--- a/drivers/video/sandbox_sdl.c
+++ b/drivers/video/sandbox_sdl.c
@@ -127,6 +127,24 @@  static int sandbox_sdl_bind(struct udevice *dev)
 	return ret;
 }
 
+static int sandbox_sdl_video_sync(struct udevice *vid, uint flags)
+{
+	struct video_priv *priv = dev_get_uclass_priv(vid);
+	const struct video_bbox *damage = NULL;
+
+	if (!(flags & VIDSYNC_FLUSH))
+		return 0;
+
+	if (IS_ENABLED(CONFIG_VIDEO_DAMAGE))
+		damage = &priv->damage;
+
+	return sandbox_sdl_sync(priv->fb, damage);
+}
+
+static const struct video_ops sandbox_sdl_ops = {
+	.sync = sandbox_sdl_video_sync,
+};
+
 static const struct udevice_id sandbox_sdl_ids[] = {
 	{ .compatible = "sandbox,lcd-sdl" },
 	{ }
@@ -139,5 +157,6 @@  U_BOOT_DRIVER(sandbox_lcd_sdl) = {
 	.bind	= sandbox_sdl_bind,
 	.probe	= sandbox_sdl_probe,
 	.remove	= sandbox_sdl_remove,
+	.ops	= &sandbox_sdl_ops,
 	.plat_auto	= sizeof(struct sandbox_sdl_plat),
 };
diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c
index a8849cf6289..491dd23bff0 100644
--- a/drivers/video/video-uclass.c
+++ b/drivers/video/video-uclass.c
@@ -522,10 +522,6 @@  int video_manual_sync(struct udevice *vid, uint flags)
 	if (IS_ENABLED(CONFIG_VIDEO_COPY) && (flags & VIDSYNC_COPY))
 		video_flush_dcache(vid, true);
 
-#if defined(CONFIG_VIDEO_SANDBOX_SDL)
-	/* to see the copy framebuffer, use priv->copy_fb */
-	sandbox_sdl_sync(priv->fb);
-#endif
 	priv->last_sync = get_timer(0);
 
 	if (IS_ENABLED(CONFIG_VIDEO_DAMAGE)) {