public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Alexander Graf <agraf@csgraf.de>
To: u-boot@lists.denx.de
Cc: Matthias Brugger <mbrugger@suse.com>,
	Heinrich Schuchardt <xypron.glpk@gmx.de>,
	Anatolij Gustschin <agust@denx.de>,
	Simon Glass <sjg@chromium.org>, Da Xue <da@libre.computer>,
	Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	Jagan Teki <jagan@amarulasolutions.com>,
	Andre Przywara <andre.przywara@arm.com>,
	Neil Armstrong <neil.armstrong@linaro.org>,
	Philipp Tomsich <philipp.tomsich@vrull.eu>,
	Kever Yang <kever.yang@rock-chips.com>,
	Patrick Delaunay <patrick.delaunay@foss.st.com>,
	Patrice Chotard <patrice.chotard@foss.st.com>,
	uboot-stm32@st-md-mailman.stormreply.com,
	u-boot-amlogic@groups.io
Subject: [PATCH v4 1/9] dm: video: Add damage tracking API
Date: Tue,  3 Jan 2023 22:49:56 +0100	[thread overview]
Message-ID: <20230103215004.22646-2-agraf@csgraf.de> (raw)
In-Reply-To: <20230103215004.22646-1-agraf@csgraf.de>

We are going to introduce image damage tracking to fasten up screen
refresh on large displays. This patch adds damage tracking for up to
one rectangle of the screen which is typically enough to hold blt or
text print updates. Callers into this API and a reduced dcache flush
code path will follow in later patches.

Signed-off-by: Alexander Graf <agraf@csgraf.de>
Reported-by: Da Xue <da@libre.computer>

---

v1 -> v2:

  - Remove ifdefs

v2 -> v3:

  - Adapt Kconfig to DM always

v3 -> v4:

  - Move damage clear from patch 6 to this one
  - Simplify first damage logic
  - Remove VIDEO_DAMAGE default for ARM
---
 drivers/video/Kconfig        | 13 ++++++++++++
 drivers/video/video-uclass.c | 41 ++++++++++++++++++++++++++++++++++++
 include/video.h              | 29 +++++++++++++++++++++++--
 3 files changed, 81 insertions(+), 2 deletions(-)

diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index f539977d9b..826a1a6587 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -62,6 +62,19 @@ config VIDEO_COPY
 	  To use this, your video driver must set @copy_base in
 	  struct video_uc_plat.
 
+config VIDEO_DAMAGE
+	bool "Enable damage tracking of frame buffer regions"
+	help
+	  On some machines (most ARM), the display frame buffer resides in
+	  RAM. To make the display controller pick up screen updates, we
+	  have to flush frame buffer contents from CPU caches into RAM which
+	  can be a slow operation.
+
+	  This feature adds damage tracking to collect information about regions
+	  that received updates. When we want to sync, we then only flush
+	  regions of the frame buffer that were modified before, speeding up
+	  screen refreshes significantly.
+
 config BACKLIGHT_PWM
 	bool "Generic PWM based Backlight Driver"
 	depends on BACKLIGHT && DM_PWM
diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c
index 0ce376ca3f..d18c8cd2b1 100644
--- a/drivers/video/video-uclass.c
+++ b/drivers/video/video-uclass.c
@@ -21,6 +21,8 @@
 #include <dm/device_compat.h>
 #include <dm/device-internal.h>
 #include <dm/uclass-internal.h>
+#include <linux/types.h>
+#include <linux/bitmap.h>
 #ifdef CONFIG_SANDBOX
 #include <asm/sdl.h>
 #endif
@@ -254,6 +256,37 @@ void video_set_default_colors(struct udevice *dev, bool invert)
 	priv->colour_bg = video_index_to_colour(priv, back);
 }
 
+/* Notify about changes in the frame buffer */
+int video_damage(struct udevice *vid, int x, int y, int width, int height)
+{
+	struct video_priv *priv = dev_get_uclass_priv(vid);
+	int endx = x + width;
+	int endy = y + height;
+
+	if (!CONFIG_IS_ENABLED(VIDEO_DAMAGE))
+		return 0;
+
+	if (x > priv->xsize)
+		return 0;
+
+	if (y > priv->ysize)
+		return 0;
+
+	if (endx > priv->xsize)
+		endx = priv->xsize;
+
+	if (endy > priv->ysize)
+		endy = priv->ysize;
+
+	/* Span a rectangle across all old and new damage */
+	priv->damage.x = min(x, priv->damage.x);
+	priv->damage.y = min(y, priv->damage.y);
+	priv->damage.endx = max(endx, priv->damage.endx);
+	priv->damage.endy = max(endy, priv->damage.endy);
+
+	return 0;
+}
+
 /* Flush video activity to the caches */
 int video_sync(struct udevice *vid, bool force)
 {
@@ -288,6 +321,14 @@ int video_sync(struct udevice *vid, bool force)
 		last_sync = get_timer(0);
 	}
 #endif
+
+	if (CONFIG_IS_ENABLED(VIDEO_DAMAGE)) {
+		priv->damage.x = priv->xsize;
+		priv->damage.y = priv->ysize;
+		priv->damage.endx = 0;
+		priv->damage.endy = 0;
+	}
+
 	return 0;
 }
 
diff --git a/include/video.h b/include/video.h
index 43f2e2c02f..4b35e97f79 100644
--- a/include/video.h
+++ b/include/video.h
@@ -109,6 +109,12 @@ struct video_priv {
 	void *fb;
 	int fb_size;
 	void *copy_fb;
+	struct {
+		int x;
+		int y;
+		int endx;
+		int endy;
+	} damage;
 	int line_length;
 	u32 colour_fg;
 	u32 colour_bg;
@@ -211,8 +217,9 @@ int video_fill(struct udevice *dev, u32 colour);
  * @return: 0 on success, error code otherwise
  *
  * Some frame buffers are cached or have a secondary frame buffer. This
- * function syncs these up so that the current contents of the U-Boot frame
- * buffer are displayed to the user.
+ * function syncs the damaged parts of them up so that the current contents
+ * of the U-Boot frame buffer are displayed to the user. It clears the damage
+ * buffer.
  */
 int video_sync(struct udevice *vid, bool force);
 
@@ -332,6 +339,24 @@ static inline int video_sync_copy_all(struct udevice *dev)
 
 #endif
 
+/**
+ * video_damage() - Notify the video subsystem about screen updates.
+ *
+ * @vid:	Device to sync
+ * @x:	        Upper left X coordinate of the damaged rectangle
+ * @y:	        Upper left Y coordinate of the damaged rectangle
+ * @width:	Width of the damaged rectangle
+ * @height:	Height of the damaged rectangle
+ *
+ * @return: 0
+ *
+ * Some frame buffers are cached or have a secondary frame buffer. This
+ * function notifies the video subsystem about rectangles that were updated
+ * within the frame buffer. They may only get written to the screen on the
+ * next call to video_sync().
+ */
+int video_damage(struct udevice *vid, int x, int y, int width, int height);
+
 /**
  * video_is_active() - Test if one video device it active
  *
-- 
2.37.1 (Apple Git-137.1)


  reply	other threads:[~2023-01-03 21:50 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-03 21:49 [PATCH v4 0/9] Add video damage tracking Alexander Graf
2023-01-03 21:49 ` Alexander Graf [this message]
2023-01-07  0:13   ` [PATCH v4 1/9] dm: video: Add damage tracking API Simon Glass
2023-01-03 21:49 ` [PATCH v4 2/9] dm: video: Add damage notification on display clear Alexander Graf
2023-01-07  0:13   ` Simon Glass
2023-01-03 21:49 ` [PATCH v4 3/9] vidconsole: Add damage notifications to all vidconsole drivers Alexander Graf
2023-01-07  0:13   ` Simon Glass
2023-01-03 21:49 ` [PATCH v4 4/9] video: Add damage notification on bmp display Alexander Graf
2023-01-07  0:13   ` Simon Glass
2023-01-03 21:50 ` [PATCH v4 5/9] efi_loader: GOP: Add damage notification on BLT Alexander Graf
2023-01-04 12:50   ` Heinrich Schuchardt
2023-01-03 21:50 ` [PATCH v4 6/9] video: Only dcache flush damaged lines Alexander Graf
2023-01-03 21:50 ` [PATCH v4 7/9] video: Use VIDEO_DAMAGE for VIDEO_COPY Alexander Graf
2023-01-07  0:13   ` Simon Glass
2023-01-07 22:40     ` Heinrich Schuchardt
2023-01-08 15:48       ` Simon Glass
2023-01-03 21:50 ` [PATCH v4 8/9] video: Always compile cache flushing code Alexander Graf
2023-01-07  0:13   ` Simon Glass
2023-01-03 21:50 ` [PATCH v4 9/9] video: Enable VIDEO_DAMAGE for drivers that need it Alexander Graf
2023-01-04 12:32   ` Neil Armstrong
2023-01-07  0:13   ` Simon Glass
2023-01-07  0:13 ` [PATCH v4 0/9] Add video damage tracking Simon Glass
2023-04-14  7:35 ` Antonio Murdaca
2023-04-19  1:45   ` Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230103215004.22646-2-agraf@csgraf.de \
    --to=agraf@csgraf.de \
    --cc=agust@denx.de \
    --cc=andre.przywara@arm.com \
    --cc=da@libre.computer \
    --cc=ilias.apalodimas@linaro.org \
    --cc=jagan@amarulasolutions.com \
    --cc=kever.yang@rock-chips.com \
    --cc=mbrugger@suse.com \
    --cc=neil.armstrong@linaro.org \
    --cc=patrice.chotard@foss.st.com \
    --cc=patrick.delaunay@foss.st.com \
    --cc=philipp.tomsich@vrull.eu \
    --cc=sjg@chromium.org \
    --cc=u-boot-amlogic@groups.io \
    --cc=u-boot@lists.denx.de \
    --cc=uboot-stm32@st-md-mailman.stormreply.com \
    --cc=xypron.glpk@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox