qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] sdl: restore optimized redraw
@ 2018-02-05 13:32 Anatoly Trosinenko
  2018-02-14 18:47 ` Anatoly Trosinenko
  0 siblings, 1 reply; 3+ messages in thread
From: Anatoly Trosinenko @ 2018-02-05 13:32 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Anatoly Trosinenko

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 <anatoly.trosinenko@gmail.com>
---
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 = container_of(dcl, struct sdl2_console, dcl);
     DisplaySurface *surf = qemu_console_surface(dcl->con);
     SDL_Rect rect;
+    size_t surface_data_offset = surface_bytes_per_pixel(surf) * x +
+                                 surface_stride(surf) * y;
 
     assert(!scon->opengl);
 
@@ -46,27 +48,16 @@ void sdl2_2d_update(DisplayChangeListener *dcl,
         return;
     }
 
-    /*
-     * 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 = x;
     rect.y = y;
     rect.w = w;
     rect.h = h;
-#else
-    rect.x = 0;
-    rect.y = 0;
-    rect.w = surface_width(surf);
-    rect.h = 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);
 }
 
-- 
2.14.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] sdl: restore optimized redraw
  2018-02-05 13:32 [Qemu-devel] [PATCH] sdl: restore optimized redraw Anatoly Trosinenko
@ 2018-02-14 18:47 ` Anatoly Trosinenko
  2018-02-16 11:32   ` Gerd Hoffmann
  0 siblings, 1 reply; 3+ messages in thread
From: Anatoly Trosinenko @ 2018-02-14 18:47 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Anatoly Trosinenko

Ping.
Patchwork link: http://patchwork.ozlabs.org/patch/869283/

2018-02-05 16:32 GMT+03:00 Anatoly Trosinenko <anatoly.trosinenko@gmail.com>
:

> 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 <anatoly.trosinenko@gmail.com>
> ---
> 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 = container_of(dcl, struct sdl2_console,
> dcl);
>      DisplaySurface *surf = qemu_console_surface(dcl->con);
>      SDL_Rect rect;
> +    size_t surface_data_offset = surface_bytes_per_pixel(surf) * x +
> +                                 surface_stride(surf) * y;
>
>      assert(!scon->opengl);
>
> @@ -46,27 +48,16 @@ void sdl2_2d_update(DisplayChangeListener *dcl,
>          return;
>      }
>
> -    /*
> -     * 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 = x;
>      rect.y = y;
>      rect.w = w;
>      rect.h = h;
> -#else
> -    rect.x = 0;
> -    rect.y = 0;
> -    rect.w = surface_width(surf);
> -    rect.h = 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);
>  }
>
> --
> 2.14.1
>
>


-- 
С уважением,
Анатолий Тросиненко
e-mail: anatoly.trosinenko@gmail.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH] sdl: restore optimized redraw
  2018-02-14 18:47 ` Anatoly Trosinenko
@ 2018-02-16 11:32   ` Gerd Hoffmann
  0 siblings, 0 replies; 3+ messages in thread
From: Gerd Hoffmann @ 2018-02-16 11:32 UTC (permalink / raw)
  To: Anatoly Trosinenko; +Cc: qemu-devel

On Wed, Feb 14, 2018 at 09:47:19PM +0300, Anatoly Trosinenko wrote:
> Ping.
> Patchwork link: http://patchwork.ozlabs.org/patch/869283/

No review comments, patch is perfect ;)

Sorry for the delay, was busy with other stuff.
Preparing new UI pull request atm, queued the patch.

thanks,
  Gerd

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-02-16 11:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-05 13:32 [Qemu-devel] [PATCH] sdl: restore optimized redraw Anatoly Trosinenko
2018-02-14 18:47 ` Anatoly Trosinenko
2018-02-16 11:32   ` Gerd Hoffmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).