From patchwork Fri Oct 3 16:55:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 501 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759510624; bh=Z3X2p0AU9f6ah4MUU9LTUsvKR6Iqz84e4hQoIxy9tEs=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=mBn5BGIBTa2xvJn4NSmvE2N7d5mGPJgM/iMC/uWfeYSNCyEBiE4kVVakxgAaiba1F 47D1T878Il3PpQmZ+p4degGgUc2vHBy8+xU0zdkeQYPHAcQRR/iawh3trxhmwZGHaf xSs6vFfoptrdOfQ9eKo32HSAgCQxPDBRFu3gpODIw97mawPwjSF37hBcW3l8xXSM8q h7vchZLash2r09YI5rZGOgWcQY+wDMcn+IPDcpsrv5ytZCkPlwSGV/rrU4rv3yej7k aZ7YGuTmpVe2zlka/HZ6gb7HZnLfWkIMJ7vylS4c6q+CApyqYu+dXLWsaYDjiuMeNs NkazXiyJ7HlNw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id AEB2F67EC5 for ; Fri, 3 Oct 2025 10:57:04 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id nsJu5n3g9ikS for ; Fri, 3 Oct 2025 10:57:04 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759510624; bh=Z3X2p0AU9f6ah4MUU9LTUsvKR6Iqz84e4hQoIxy9tEs=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=mBn5BGIBTa2xvJn4NSmvE2N7d5mGPJgM/iMC/uWfeYSNCyEBiE4kVVakxgAaiba1F 47D1T878Il3PpQmZ+p4degGgUc2vHBy8+xU0zdkeQYPHAcQRR/iawh3trxhmwZGHaf xSs6vFfoptrdOfQ9eKo32HSAgCQxPDBRFu3gpODIw97mawPwjSF37hBcW3l8xXSM8q h7vchZLash2r09YI5rZGOgWcQY+wDMcn+IPDcpsrv5ytZCkPlwSGV/rrU4rv3yej7k aZ7YGuTmpVe2zlka/HZ6gb7HZnLfWkIMJ7vylS4c6q+CApyqYu+dXLWsaYDjiuMeNs NkazXiyJ7HlNw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 9CC0C67E86 for ; Fri, 3 Oct 2025 10:57:04 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759510622; bh=xa4+HtR+JCVOwYHiWxF8KfIOMP5jUzAK1dK+k0qxcgs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=w7sx2XX3L6IuROYS0dT0x3PRgDGAqJVuK8CtxVVX4mxVgvZAk1dmai6Tye/qT4tjq gZtRG13Yhe0+7Bki3h874OzLzWmMEi5tuYG4k5MWz1/dT9omC+XZ9DMeiSLnF3S17k xWCTnL8i3CISqNhXEQhQbk0PEuRc/A+YfYU0OM2+epY7C1I+OYt9DBJKrfe3fey1gX 9QByxp36qaKfUb28NkjNPXrKXsh56bdZmGt3y1ydxVWvg0K0NYAY0nv5a7iX+1bWAH BgyD7cG9A07aNeLUGaJHZDNn1guTZCBqJyJfvii1STMPMimq11vOmmoyKEGp4yfnCZ n+SFlcv4chOkA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 302C867DC0; Fri, 3 Oct 2025 10:57:02 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id cNcEeomi3rOO; Fri, 3 Oct 2025 10:57:02 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1759510618; bh=Ib0yWe30QFndridCh8X5IZp3LHXuySmsNvygX8mBs6Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Fq05esBRxqEWDZ8JrIoX3vEsMVK1SJF5ffRlA9uc7Ez6Pb2yqUS5JlDEr2USLMWXu y5JzQs/scdsRnPYJYh5mtRAV+UJvOAUOhUDQkJOoRZ60oz5BZ60xtmGlcg5nJRZppM HOVK2FxoQNUbqLeh7BE8qM3fOyai8hPgiHnbktdDRF40ydPyN2oN1TgxQiK7/Tuipt z1E7DQD3+qALEcYYVrKjsiffzatpfNR65hvSrI/vG275X6usXUopQc6AXu0IWUoDbq /3ghtfP6m1cmZHJrkqoDZfYryqHc9+T40EHQZFSb7WzMFNtOqifydewJckmNjXlkfN 2lPT8+kcJiLxQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id A900467F45; Fri, 3 Oct 2025 10:56:57 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Fri, 3 Oct 2025 10:55:13 -0600 Message-ID: <20251003165525.440173-21-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251003165525.440173-1-sjg@u-boot.org> References: <20251003165525.440173-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: NML37JNUTEQAKHU4WABPP4G6TY7KCATE X-Message-ID-Hash: NML37JNUTEQAKHU4WABPP4G6TY7KCATE X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 20/22] video: sandbox: Optimise drawing based on damage List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Update sandbox_sdl_sync() to accept an optional damage rectangle and update only the damaged region. This should reduce the amount of work performed by the driver when only a small part of the display needs to be updated. Co-developed-by: Claude Signed-off-by: Simon Glass --- arch/sandbox/cpu/sdl.c | 46 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/arch/sandbox/cpu/sdl.c b/arch/sandbox/cpu/sdl.c index fa431010b11..f4038c2431a 100644 --- a/arch/sandbox/cpu/sdl.c +++ b/arch/sandbox/cpu/sdl.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -232,17 +233,46 @@ int sandbox_sdl_init_display(int width, int height, int log2_bpp, return 0; } -static int copy_to_texture(void *lcd_base) +static int copy_to_texture(void *lcd_base, const struct video_bbox *damage) { char *dest; int pitch, x, y; int src_pitch; void *pixels; char *src; + SDL_Rect rect, *rectp = NULL; int ret; + int x0, y0, x1, y1; + + /* Set up damage region if provided */ + if (damage && damage->x1 > damage->x0 && damage->y1 > damage->y0) { + rect.x = damage->x0; + rect.y = damage->y0; + rect.w = damage->x1 - damage->x0; + rect.h = damage->y1 - damage->y0; + rectp = ▭ + x0 = damage->x0; + y0 = damage->y0; + x1 = damage->x1; + y1 = damage->y1; + } else { + x0 = 0; + y0 = 0; + x1 = sdl.width; + y1 = sdl.height; + } if (sdl.src_depth == sdl.depth) { - SDL_UpdateTexture(sdl.texture, NULL, lcd_base, sdl.pitch); + if (rectp) { + /* Update only the damaged region */ + src_pitch = sdl.width * sdl.src_depth / 8; + src = lcd_base + y0 * src_pitch + + x0 * sdl.src_depth / 8; + SDL_UpdateTexture(sdl.texture, rectp, src, src_pitch); + } else { + SDL_UpdateTexture(sdl.texture, NULL, lcd_base, + sdl.pitch); + } return 0; } @@ -255,7 +285,7 @@ static int copy_to_texture(void *lcd_base) return -EINVAL; } - ret = SDL_LockTexture(sdl.texture, NULL, &pixels, &pitch); + ret = SDL_LockTexture(sdl.texture, rectp, &pixels, &pitch); if (ret) { printf("SDL lock %d: %s\n", ret, SDL_GetError()); return ret; @@ -263,12 +293,12 @@ static int copy_to_texture(void *lcd_base) /* Copy the pixels one by one */ src_pitch = sdl.width * sdl.src_depth / 8; - for (y = 0; y < sdl.height; y++) { + for (y = y0; y < y1; y++) { char val; - dest = pixels + y * pitch; - src = lcd_base + src_pitch * y; - for (x = 0; x < sdl.width; x++, dest += 4) { + dest = pixels + (y - y0) * pitch; + src = lcd_base + src_pitch * y + x0; + for (x = x0; x < x1; x++, dest += 4) { val = *src++; dest[0] = val; dest[1] = val; @@ -289,7 +319,7 @@ int sandbox_sdl_sync(void *lcd_base) if (!sdl.texture) return 0; SDL_RenderClear(sdl.renderer); - ret = copy_to_texture(lcd_base); + ret = copy_to_texture(lcd_base, NULL); if (ret) { printf("copy_to_texture: %d: %s\n", ret, SDL_GetError()); return -EIO;