Skip to contentSkip to conversation

sdl: Avoid unnecessary resizing of the display surface

PATCH In review Stefan Weil 2 participants 3 messages May 1, 2012 – May 4, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sdl: Avoid unnecessary resizing of the display surface

If neither width nor height changes, nothing has to be done.

Cc Anthony Liguori <[email protected]>

---

This patch improves SDL for any host (for example with remote X displays), but the main reason why I wrote it was another problem:

On w32 / w64 hosts, qemu-system-arm has a deadlock when it calls sdl_resize_displaysurface during Linux boot. One thread waits for a critical region, another thread waits inside SDL_SetVideoMode.

The patch avoids this problem. Paolo, maybe you have an idea what could cause the deadlock. Debugging on wxx is terrible - up to now, I did not succeed in analysing the lock situation with gdb.

Regards,
Stefan W.

 ui/sdl.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
ui/sdl.c +5 -2
index 8700b7a..8c1c71c 100644
@@ -224,8 +224,11 @@ static void sdl_free_displaysurface(DisplaySurface *surface)
 
 static DisplaySurface* sdl_resize_displaysurface(DisplaySurface *surface, int width, int height)
 {
-    sdl_free_displaysurface(surface);
-    return sdl_create_displaysurface(width, height);
+    if (surface->width != width || surface->height != height) {
+        sdl_free_displaysurface(surface);
+        surface = sdl_create_displaysurface(width, height);
+    }
+    return surface;
 }
 
 /* generic keyboard conversion */
Signature · 1 line
1.7.9
#1 lore raw

Il 01/05/2012 07:53, Stefan Weil ha scritto:

Quoted 9 lines

If neither width nor height changes, nothing has to be done.

Cc Anthony Liguori <[email protected]>

---

This patch improves SDL for any host (for example with remote X displays), but the main reason why I wrote it was another problem:

Quoted 6 lines

On w32 / w64 hosts, qemu-system-arm has a deadlock when it calls sdl_resize_displaysurface during Linux boot. One thread waits for a critical region, another thread waits inside SDL_SetVideoMode.

The patch avoids this problem. Paolo, maybe you have an idea what could cause the deadlock.

No idea---honestly, my w32 interest is limited to replacing hacks with proper solutions. :) It turns out that in many cases you can fix bugs along the way and that helps having people look at your patches...

Paolo

#2 lore raw
In reply to Stefan Weil

Am 01.05.2012 07:53, schrieb Stefan Weil:

Quoted 32 lines

If neither width nor height changes, nothing has to be done.

Cc Anthony Liguori<[email protected]>

---

This patch improves SDL for any host (for example with remote X displays), but the main reason why I wrote it was another problem:

On w32 / w64 hosts, qemu-system-arm has a deadlock when it calls sdl_resize_displaysurface during Linux boot. One thread waits for a critical region, another thread waits inside SDL_SetVideoMode.

The patch avoids this problem. Paolo, maybe you have an idea what could cause the deadlock. Debugging on wxx is terrible - up to now, I did not succeed in analysing the lock situation with gdb.

Regards,
Stefan W.

  ui/sdl.c |    7 +++++--
  1 files changed, 5 insertions(+), 2 deletions(-)
ui/sdl.c +0 -0
index 8700b7a..8c1c71c 100644
@@ -224,8 +224,11 @@ static void sdl_free_displaysurface(DisplaySurface *surface)
 
  static DisplaySurface* sdl_resize_displaysurface(DisplaySurface *surface, int width, int height)
  {

ui/sdl.c static void sdl_free_displaysurface(DisplaySurface *surface) · line 234

Quoted 10 lines
ui/sdl.c +5 -2
-    sdl_free_displaysurface(surface);
-    return sdl_create_displaysurface(width, height);
+    if (surface->width != width || surface->height != height) {
+        sdl_free_displaysurface(surface);
+        surface = sdl_create_displaysurface(width, height);
+    }
+    return surface;
  }
 
  /* generic keyboard conversion */

Please don't apply this patch. It is not complete and can cause a crash (seen on w32 when resizing the SDL window).

I'll send an update.

Regards,
Stefan W.