tizen/src/maru_sdl.c: Fix improper operations with SDL surfaces.
authorEvgeny Voevodin <e.voevodin@samsung.com>
Wed, 11 Jul 2012 10:09:23 +0000 (14:09 +0400)
committerEvgeny Voevodin <e.voevodin@samsung.com>
Fri, 13 Jul 2012 05:28:00 +0000 (09:28 +0400)
The bug is that vga_hw_update() invokes dpy_update() where
qemu_ds_update() is called.
qemu_ds_update() sends a signal to thread run_qemu_update() waiting
to be released and to invoke qemu_update().
After this happens there are two ways possible:
1. run_qemu_update() is released, got mutex and qemu_update() is called.
   Simultaneously qemu_ds_refresh() is waiting on the mutex to perform
   SDL_SetVideoMode(). This is most common way.
2. If we unlucky,
   vga_hw_update() returns and qemu_ds_refresh() gets mutex before
   run_qemu_update() is released. In this way SDL_SetVideoMode() is called
   before qemu_update() is invoked. This leads qemu_update() to operate on
   invalidated surface_qemu.
So, to solve this problem we can add a flag indicating that qemu_update()
finished it's work and that we free to invoke SDL_SetVideoMode().
Or we can simply move vga_hw_update() invocation after SDL_SetVideoMode() call.
We chose the second variant as more efficient.

Signed-off-by: Evgeny Voevodin <e.voevodin@samsung.com>
tizen/src/maru_sdl.c

index 91720a08a68ef4e97a2dcfc2567b6136a0830f54..83d6c0a7f14aadeb06b5010eafe81e6d155ed8b1 100644 (file)
@@ -225,8 +225,6 @@ static void qemu_ds_refresh(DisplayState *ds)
 {
     SDL_Event ev1, *ev = &ev1;
 
-    vga_hw_update();
-
     // surface may be NULL in init func.
     qemu_display_surface = ds->surface;
 
@@ -259,10 +257,7 @@ static void qemu_ds_refresh(DisplayState *ds)
                 }
 
                 pthread_mutex_lock(&sdl_mutex);
-#ifndef TARGET_ARM
-                /* FIXME: For some reason quit should be called here for x86*/
-                SDL_Quit(); //The returned surface is freed by SDL_Quit and must not be freed by the caller
-#endif
+
                 surface_screen = SDL_SetVideoMode(w, h, SDL_BPP, SDL_FLAGS);
                 if (surface_screen == NULL) {
                     ERR("Could not open SDL display (%dx%dx%d): %s\n", w, h, SDL_BPP, SDL_GetError());
@@ -282,6 +277,8 @@ static void qemu_ds_refresh(DisplayState *ds)
         }
     }
 
+    vga_hw_update();
+
 #ifdef TARGET_ARM
 #ifdef SDL_THREAD
     pthread_mutex_lock(&sdl_mutex);