diff mbox

sdl: Reverse support for video mode setting

Message ID 1377600914-21259-1-git-send-email-lilei@linux.vnet.ibm.com
State New
Headers show

Commit Message

Lei Li Aug. 27, 2013, 10:55 a.m. UTC
Currently, If the setting of video mode failed, qemu will exit. It
should go back to the previous setting if the new screen resolution
failed. This patch fixes LP#1216368, add support to revert to existing
surface for the failure of video mode setting.

Reported-by: Sascha Krissler <sascha@srlabs.de>
Signed-off-by: Lei Li <lilei@linux.vnet.ibm.com>
---
 ui/sdl.c |   23 +++++++++++++++++++----
 1 files changed, 19 insertions(+), 4 deletions(-)

Comments

Lei Li Aug. 30, 2013, 9:03 a.m. UTC | #1
Any comments?

On 08/27/2013 06:55 PM, Lei Li wrote:
> Currently, If the setting of video mode failed, qemu will exit. It
> should go back to the previous setting if the new screen resolution
> failed. This patch fixes LP#1216368, add support to revert to existing
> surface for the failure of video mode setting.
>
> Reported-by: Sascha Krissler <sascha@srlabs.de>
> Signed-off-by: Lei Li <lilei@linux.vnet.ibm.com>
> ---
>   ui/sdl.c |   23 +++++++++++++++++++----
>   1 files changed, 19 insertions(+), 4 deletions(-)
>
> diff --git a/ui/sdl.c b/ui/sdl.c
> index 39a42d6..9d8583c 100644
> --- a/ui/sdl.c
> +++ b/ui/sdl.c
> @@ -86,6 +86,7 @@ static void sdl_update(DisplayChangeListener *dcl,
>   static void do_sdl_resize(int width, int height, int bpp)
>   {
>       int flags;
> +    SDL_Surface *tmp_screen;
>
>       //    printf("resizing to %d %d\n", w, h);
>
> @@ -98,12 +99,26 @@ static void do_sdl_resize(int width, int height, int bpp)
>       if (gui_noframe)
>           flags |= SDL_NOFRAME;
>
> -    real_screen = SDL_SetVideoMode(width, height, bpp, flags);
> +    tmp_screen = SDL_SetVideoMode(width, height, bpp, flags);
>       if (!real_screen) {
> -	fprintf(stderr, "Could not open SDL display (%dx%dx%d): %s\n", width,
> -		height, bpp, SDL_GetError());
> -        exit(1);
> +        if (!tmp_screen) {
> +            fprintf(stderr, "Could not open SDL display (%dx%dx%d): %s\n",
> +                    width, height, bpp, SDL_GetError());
> +            exit(1);
> +        }
> +    } else {
> +        /*
> +         * Revert to the previous video mode if the change of resizing or
> +         * resolution failed.
> +         */
> +        if (!tmp_screen) {
> +            fprintf(stderr, "Failed to set SDL display (%dx%dx%d): %s\n",
> +                    width, height, bpp, SDL_GetError());
> +            return;
> +        }
>       }
> +
> +    real_screen = tmp_screen;
>   }
>
>   static void sdl_switch(DisplayChangeListener *dcl,
diff mbox

Patch

diff --git a/ui/sdl.c b/ui/sdl.c
index 39a42d6..9d8583c 100644
--- a/ui/sdl.c
+++ b/ui/sdl.c
@@ -86,6 +86,7 @@  static void sdl_update(DisplayChangeListener *dcl,
 static void do_sdl_resize(int width, int height, int bpp)
 {
     int flags;
+    SDL_Surface *tmp_screen;
 
     //    printf("resizing to %d %d\n", w, h);
 
@@ -98,12 +99,26 @@  static void do_sdl_resize(int width, int height, int bpp)
     if (gui_noframe)
         flags |= SDL_NOFRAME;
 
-    real_screen = SDL_SetVideoMode(width, height, bpp, flags);
+    tmp_screen = SDL_SetVideoMode(width, height, bpp, flags);
     if (!real_screen) {
-	fprintf(stderr, "Could not open SDL display (%dx%dx%d): %s\n", width, 
-		height, bpp, SDL_GetError());
-        exit(1);
+        if (!tmp_screen) {
+            fprintf(stderr, "Could not open SDL display (%dx%dx%d): %s\n",
+                    width, height, bpp, SDL_GetError());
+            exit(1);
+        }
+    } else {
+        /*
+         * Revert to the previous video mode if the change of resizing or
+         * resolution failed.
+         */
+        if (!tmp_screen) {
+            fprintf(stderr, "Failed to set SDL display (%dx%dx%d): %s\n",
+                    width, height, bpp, SDL_GetError());
+            return;
+        }
     }
+
+    real_screen = tmp_screen;
 }
 
 static void sdl_switch(DisplayChangeListener *dcl,