From nobody Mon Apr 29 05:30:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1517837631285861.2056880669396; Mon, 5 Feb 2018 05:33:51 -0800 (PST) Received: from localhost ([::1]:44144 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eigu3-0001Pm-I8 for importer@patchew.org; Mon, 05 Feb 2018 08:33:47 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48835) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eigt0-0000sY-Et for qemu-devel@nongnu.org; Mon, 05 Feb 2018 08:32:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eigsx-00044M-CC for qemu-devel@nongnu.org; Mon, 05 Feb 2018 08:32:42 -0500 Received: from mail-lf0-x241.google.com ([2a00:1450:4010:c07::241]:34906) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eigsx-00043P-4B for qemu-devel@nongnu.org; Mon, 05 Feb 2018 08:32:39 -0500 Received: by mail-lf0-x241.google.com with SMTP id a204so41747798lfa.2 for ; Mon, 05 Feb 2018 05:32:38 -0800 (PST) Received: from tro-notebook.lan ([185.16.100.222]) by smtp.gmail.com with ESMTPSA id f77sm1851767lfe.96.2018.02.05.05.32.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Feb 2018 05:32:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=kL1GoSqI5Mnm7lHe1wx5fuuzZbHdlvDgUg3Me0Y/XDw=; b=WSXhEkj+u1nTqX08QWZQUFLEzZaW3CD+CF31B8NahxUoZjTZkZ51ncKLw7J3X3rzMu K/R2XPvXJtvvn+2LQPR5OxBe1oZd/LkvZzHI0HqT6hnCCvL1BhF+458n76M0S7v02daC xpX8t/VMX2HHghyWjkHLYTmDUIeC62zBNDDfVHtxW+n+JAidBObpvCd12CzEHxUMA1Zk f6cq6WEr57/9m+e3AiZOmLih9UuZWTFoa6Zw8+tsAQz3JpmO3N3XoPvzrj/jldG2EVO2 E4J8aJAe1RF5JRyTelpA64vLJQkHBF4PLjP9QapBE15XuKRk+VgC21kykJ+oPJi8AntE uxEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=kL1GoSqI5Mnm7lHe1wx5fuuzZbHdlvDgUg3Me0Y/XDw=; b=ngCJfrASpbsJ4UdJSjZQvpvLvj2NMhEChf7/sbsWF9oz+pgmhe5QKmdWNf3PGSFA7d S6I4MIUf0+6g7GFDJ9yfFRn29dOvPy0lLFXvhkjFDLwMFO9BTXq38qzauXkyWhQfrdcQ 4W7N5luy7g3OAExgtE4q3suNFfADhST2Q8bsALAy6u8WVCNvSh87fTOoePDB3dQZuuS8 s8cwM3LY6fV1AmYRRUOpp2/NRrjUSgvZ3OxgHPIECcJ/BfXUGsFHk0POyAeDc3ZKLFcH FZwouwbMwWtyR0HcoNNghLn1QGEx7qP8LfmthqnlM+8ajyMmpPBsSAkxooTX8EyKS3M+ q7hg== X-Gm-Message-State: AKwxytd+ac/WuLUnMJZQD/gcA7sJm+8Za1DnBSXcDDG9aKPjhwEV2zli QEvDXryPe/1/+RUIZ1xB1Zw8qaIg X-Google-Smtp-Source: AH8x2251fkAH6wpCgHix560d9c1KRQRxjTC+QU6XjKWJ+KyQNB6BGqShhz8sDwqZDKGj9I9PvK7ThA== X-Received: by 10.25.143.143 with SMTP id s15mr31941456lfk.129.1517837557299; Mon, 05 Feb 2018 05:32:37 -0800 (PST) From: Anatoly Trosinenko To: qemu-devel@nongnu.org Date: Mon, 5 Feb 2018 16:32:28 +0300 Message-Id: <20180205133228.25082-1-anatoly.trosinenko@gmail.com> X-Mailer: git-send-email 2.14.1 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4010:c07::241 Subject: [Qemu-devel] [PATCH] sdl: restore optimized redraw X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gerd Hoffmann , Anatoly Trosinenko Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The documentation on SDL_RenderPresent function states that "the backbuffer should be considered invalidated after each present", so copy the entire texture on each redraw. On the other hand, SDL_UpdateTexture function is described as "fairly slow function", so restrict it to just the changed pixels. Also added SDL_RenderClear call, as suggested in the documentation page on SDL_RenderPresent. Signed-off-by: Anatoly Trosinenko --- I managed to reproduce some flicker when using SDL 2D UI (and #if 1) and it disappeared after this patch. I don't know the original testcase, though. Hope I correctly calculated the offset. :) Meanwhile, is it correct to calculate surface_data_offset before assert, is everything always initialized enough at this point even if assert fails? ui/sdl2-2d.c | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/ui/sdl2-2d.c b/ui/sdl2-2d.c index 8ab68d67b9..1f34817bae 100644 --- a/ui/sdl2-2d.c +++ b/ui/sdl2-2d.c @@ -36,6 +36,8 @@ void sdl2_2d_update(DisplayChangeListener *dcl, struct sdl2_console *scon =3D container_of(dcl, struct sdl2_console, d= cl); DisplaySurface *surf =3D qemu_console_surface(dcl->con); SDL_Rect rect; + size_t surface_data_offset =3D surface_bytes_per_pixel(surf) * x + + surface_stride(surf) * y; =20 assert(!scon->opengl); =20 @@ -46,27 +48,16 @@ void sdl2_2d_update(DisplayChangeListener *dcl, return; } =20 - /* - * SDL2 seems to do some double-buffering, and trying to only - * update the changed areas results in only one of the two buffers - * being updated. Which flickers alot. So lets not try to be - * clever do a full update every time ... - */ -#if 0 rect.x =3D x; rect.y =3D y; rect.w =3D w; rect.h =3D h; -#else - rect.x =3D 0; - rect.y =3D 0; - rect.w =3D surface_width(surf); - rect.h =3D surface_height(surf); -#endif - - SDL_UpdateTexture(scon->texture, NULL, surface_data(surf), + + SDL_UpdateTexture(scon->texture, &rect, + surface_data(surf) + surface_data_offset, surface_stride(surf)); - SDL_RenderCopy(scon->real_renderer, scon->texture, &rect, &rect); + SDL_RenderClear(scon->real_renderer); + SDL_RenderCopy(scon->real_renderer, scon->texture, NULL, NULL); SDL_RenderPresent(scon->real_renderer); } =20 --=20 2.14.1