UpdateRect(s) performance

Hi folks,

here’s a question concerning the update mechanism of libSDL, concerning
mainly the Linux x86/ libX11 front-end of SDL, being my main
development target.

I’ve here an application (to be precise, an emulator) with an optional
SDL front-end that is used to display the results of the emulation process
and to mirror the internal state of the emulated hardware screen on the
display of the emulating system. The goal should be an optimal refresh
rate of 50fps, i.e. the refresh rate of the emulated hardware. In my
working environment, it makes sense to upsample the display since the
original resolution of (typically) 320x192 is too low to be displayable
on a reasonable monitor - plus it looks blury on a TFT due to its own
upsampling mechanism.

The current mechanism collects the hardware output of the emulator in
a frame buffer, then checks which lines of this frame buffer have changed
and updates these lines by means of SDL/UpdateRects, possibly combining
adjacent rectangles into bigger rectangles to improve performance.
(Hence, a classical “delta buffer” approach is used here)

Unfortunately, the UpdateRects() function is quite slowish. It’s even
noticably slower than using proper X11 calls and drawing the rectangles
by means of X11 directly. I also tried the “svga” and the “dga” video
front-ends of libSDL, but no avail.

I further checked the performance of the program using standard profiling
methods (gprof) and cache profilers (cachegrind, aka valgrind). Most of
the time is spend in the SDL UpdateRects() method. This doesn’t sound that
surprising if you compute how much data has to be pushed around the bus for
updating an (upsampled) 1280x1024 display, but then on the other hand, libX11
manages this easely. (My guess: It uses hardware acceleration of the graphics
card and doesn’t perform the rendering itself, making it faster. Would this
be possible within libSDL?)


  1. Any ideas to speedup the display refresh?
  2. Is there any interface within libSDL to draw (a couple of) rectangles
    in a very fast way? The FillRectangle() (sp?) call just renders into an
    off-screen buffer, also requiring an UpdateRects(), being even slower… )-:

Thanks for the help,

Thomas Richter