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 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
This commit is contained in:
Simon Glass
2026-01-02 08:42:41 -07:00
parent 3f453d0110
commit e68bb75109

View File

@@ -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);
}
}
}