From e68bb751091da4f36497cc28b17edc3733becd39 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Fri, 2 Jan 2026 08:42:41 -0700 Subject: [PATCH] video: Optimise video_flush_copy() for full-line damage When copying partial framebuffer regions line by line, there is overhead from multiple memcpy() calls. Optimise video_flush_copy() to detect when entire lines are being copied (damage spans full width) and perform a single memcpy() for the whole region instead of looping line by line. Also invert the early-exit check to reduce nesting. Co-developed-by: Claude Signed-off-by: Simon Glass --- drivers/video/video-uclass.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c index 2789c352113..75b13481380 100644 --- a/drivers/video/video-uclass.c +++ b/drivers/video/video-uclass.c @@ -507,16 +507,25 @@ static void video_flush_copy(struct udevice *vid) if (!priv->copy_fb) return; - if (damage->x1 && damage->y1) { - int lstart = damage->x0 * VNBYTES(priv->bpix); - int lend = damage->x1 * VNBYTES(priv->bpix); + if (!damage->x1 || !damage->y1) + return; + + int lstart = damage->x0 * VNBYTES(priv->bpix); + int llen = damage->x1 * VNBYTES(priv->bpix) - lstart; + + /* Copy entire region at once if full lines are damaged */ + if (!lstart && llen == priv->line_length) { + ulong offset = damage->y0 * priv->line_length; + ulong len = (damage->y1 - damage->y0) * priv->line_length; + + memcpy(priv->copy_fb + offset, priv->fb + offset, len); + } else { int y; for (y = damage->y0; y < damage->y1; y++) { - ulong offset = (y * priv->line_length) + lstart; - ulong len = lend - lstart; + ulong offset = y * priv->line_length + lstart; - memcpy(priv->copy_fb + offset, priv->fb + offset, len); + memcpy(priv->copy_fb + offset, priv->fb + offset, llen); } } }