[Concept,10/14] expo: Add damage tracking

Message ID 20251006165452.1675349-11-sjg@u-boot.org
State New
Headers
Series expo: Continue development of expo with mouse |

Commit Message

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

As a few step towards making rendering more efficient, add support for
tracking video damage within an expo.

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

 boot/expo.c    | 30 ++++++++++++++++++++++++++++++
 include/expo.h | 23 +++++++++++++++++++++++
 2 files changed, 53 insertions(+)
  

Patch

diff --git a/boot/expo.c b/boot/expo.c
index 295b779dce8..5cbe06b1c28 100644
--- a/boot/expo.c
+++ b/boot/expo.c
@@ -536,3 +536,33 @@  void expo_exit_mode(struct expo *exp)
 {
 	video_manual_sync(exp->display, false);
 }
+
+void expo_damage_reset(struct expo *exp)
+{
+	exp->damage.x0 = 0;
+	exp->damage.y0 = 0;
+	exp->damage.x1 = 0;
+	exp->damage.y1 = 0;
+}
+
+void expo_damage_add(struct expo *exp, const struct vid_bbox *bbox)
+{
+	/* If bbox is invalid (empty), do nothing */
+	if (bbox->x1 <= bbox->x0 || bbox->y1 <= bbox->y0)
+		return;
+
+	/* If current damage is empty, set it to the new bbox */
+	if (exp->damage.x1 <= exp->damage.x0 || exp->damage.y1 <= exp->damage.y0) {
+		exp->damage = *bbox;
+	} else {
+		/* Expand damage area to include new bbox */
+		if (bbox->x0 < exp->damage.x0)
+			exp->damage.x0 = bbox->x0;
+		if (bbox->y0 < exp->damage.y0)
+			exp->damage.y0 = bbox->y0;
+		if (bbox->x1 > exp->damage.x1)
+			exp->damage.x1 = bbox->x1;
+		if (bbox->y1 > exp->damage.y1)
+			exp->damage.y1 = bbox->y1;
+	}
+}
diff --git a/include/expo.h b/include/expo.h
index a6e6b2b780b..487b58fb916 100644
--- a/include/expo.h
+++ b/include/expo.h
@@ -135,6 +135,7 @@  struct expo_theme {
  * @mouse_ptr: Pointer to mouse pointer image data (BMP format)
  * @mouse_size: Size of mouse pointer (width and height in pixels)
  * @mouse_pos: Current mouse position
+ * @damage: Bounding box of the area that needs to be redrawn
  * @priv: Private data for the controller
  * @done: Indicates that a cedit session is complete and the user has quit
  * @save: Indicates that cedit data should be saved, rather than discarded
@@ -160,6 +161,7 @@  struct expo {
 	const void *mouse_ptr;
 	struct vid_size mouse_size;
 	struct vid_pos mouse_pos;
+	struct vid_bbox damage;
 	void *priv;
 	bool done;
 	bool save;
@@ -1197,4 +1199,25 @@  void expo_enter_mode(struct expo *exp);
  */
 void expo_exit_mode(struct expo *exp);
 
+/**
+ * expo_damage_reset() - Reset the damage tracking area
+ *
+ * @exp: Expo to reset damage tracking for
+ *
+ * Clears the damage area, indicating that no part of the display needs
+ * to be redrawn.
+ */
+void expo_damage_reset(struct expo *exp);
+
+/**
+ * expo_damage_add() - Add a damaged area to the expo damage tracking
+ *
+ * @exp: Expo to add damage to
+ * @bbox: Bounding box of the damaged area to add
+ *
+ * Expands the current damage area to include the new damaged region.
+ * If there is no existing damage, the damage area is set to the new region.
+ */
+void expo_damage_add(struct expo *exp, const struct vid_bbox *bbox);
+
 #endif /*__EXPO_H */