Skip to content

Commit

Permalink
sdl: restore optimized redraw
Browse files Browse the repository at this point in the history
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 <[email protected]>
Message-id: [email protected]
Signed-off-by: Gerd Hoffmann <[email protected]>
  • Loading branch information
atrosinenko authored and kraxel committed Feb 16, 2018
1 parent d49b87f commit 2ab858c
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions ui/sdl2-2d.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

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

Expand Down

0 comments on commit 2ab858c

Please sign in to comment.