qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 2/2] Add option to preserve aspect in SDL display sc


From: Michal Suchanek
Subject: [Qemu-devel] [PATCH 2/2] Add option to preserve aspect in SDL display scaling.
Date: Mon, 27 Sep 2010 15:42:20 +0200
User-agent: Sup/0.11

The output is not centered.

I am not sure how to achieve that because SDL just sets a "video mode"
which starts at upper left corner of the window.

It would be possible to make the mode larger but then the zoom routines
would have to take an offset.


Signed-off-by: Michal Suchanek <address@hidden>
---
 qemu-options.hx |   13 +++++++++++++
 ui/sdl.c        |   13 +++++++++++--
 vl.c            |    4 ++++
 3 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/qemu-options.hx b/qemu-options.hx
index fd96b6a..bd25396 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -629,6 +629,19 @@ workspace more convenient.
 ETEXI
 
 #ifdef CONFIG_SDL
+DEF("keep-aspect", 0, QEMU_OPTION_preserve_aspect,
+    "-keep-aspect    preserve aspect ratio of display output\n",
+    QEMU_ARCH_ALL)
+#endif
+STEXI
address@hidden -keep-aspect
address@hidden -keep-aspect
+Normally the SDL output scales the guest display to fill the SDL window. With
+this option the guest display is scaled as large as possible preserving the
+aspect ratio possibly leaving some empty space in the window.
+ETEXI
+
+#ifdef CONFIG_SDL
 DEF("alt-grab", 0, QEMU_OPTION_alt_grab,
     "-alt-grab       use Ctrl-Alt-Shift to grab mouse (instead of Ctrl-Alt)\n",
     QEMU_ARCH_ALL)
diff --git a/ui/sdl.c b/ui/sdl.c
index f599d42..5ac9a77 100644
--- a/ui/sdl.c
+++ b/ui/sdl.c
@@ -38,6 +38,7 @@
 #include "x_keymap.h"
 #include "sdl_zoom.h"
 
+int sdl_preserve_aspect = 0;
 static DisplayChangeListener *dcl;
 static SDL_Surface *real_screen;
 static SDL_Surface *guest_screen = NULL;
@@ -65,12 +66,12 @@ static Notifier mouse_mode_notifier;
 
 static void sdl_update(DisplayState *ds, int x, int y, int w, int h)
 {
-    //    printf("updating x=%d y=%d w=%d h=%d\n", x, y, w, h);
     SDL_Rect rec;
     rec.x = x;
     rec.y = y;
     rec.w = w;
     rec.h = h;
+    //fprintf(stderr, "SDL updating x=%d y=%d w=%d h=%d\n", x, y, w, h);
 
     if (guest_screen) {
         if (!scaling_active) {
@@ -105,7 +106,7 @@ static void do_sdl_resize(int new_width, int new_height, 
int bpp)
 {
     int flags;
 
-    //    printf("resizing to %d %d\n", w, h);
+    fprintf(stderr, "SDL resizing to %d %d\n", new_width, new_height);
 
     flags = SDL_HWSURFACE|SDL_ASYNCBLIT|SDL_HWACCEL|SDL_RESIZABLE;
     if (gui_fullscreen)
@@ -113,6 +114,14 @@ static void do_sdl_resize(int new_width, int new_height, 
int bpp)
     if (gui_noframe)
         flags |= SDL_NOFRAME;
 
+    if (guest_screen) {
+        float wr = (float)new_width / (float) guest_screen->w,
+              hr = (float)new_height / (float) guest_screen->h,
+              r = (wr > hr) ? hr : wr;
+        new_width = (float)guest_screen->w * r + 0.5;
+        new_height = (float)guest_screen->h * r + 0.5;
+        fprintf(stderr, "SDL adjusting resize to %d %d\n", new_width, 
new_height);
+    }
     width = new_width;
     height = new_height;
     real_screen = SDL_SetVideoMode(width, height, bpp, flags);
diff --git a/vl.c b/vl.c
index ee641bc..67d35bb 100644
--- a/vl.c
+++ b/vl.c
@@ -193,6 +193,7 @@ QEMUClock *rtc_clock;
 int vga_interface_type = VGA_NONE;
 static int full_screen = 0;
 #ifdef CONFIG_SDL
+extern int sdl_preserve_aspect;
 static int no_frame = 0;
 #endif
 int no_quit = 0;
@@ -2421,6 +2422,9 @@ int main(int argc, char **argv, char **envp)
             case QEMU_OPTION_no_frame:
                 no_frame = 1;
                 break;
+            case QEMU_OPTION_preserve_aspect:
+                sdl_preserve_aspect = 1;
+                break;
             case QEMU_OPTION_alt_grab:
                 alt_grab = 1;
                 break;
-- 
1.7.1



reply via email to

[Prev in Thread] Current Thread [Next in Thread]