From patchwork Thu Sep 13 09:19:49 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 183580 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 52D8C2C0088 for ; Thu, 13 Sep 2012 19:41:01 +1000 (EST) Received: from localhost ([::1]:43002 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TC5ut-0003vt-G9 for incoming@patchwork.ozlabs.org; Thu, 13 Sep 2012 05:40:59 -0400 Received: from eggs.gnu.org ([208.118.235.92]:45050) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TC5aa-0003qA-RX for qemu-devel@nongnu.org; Thu, 13 Sep 2012 05:20:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TC5aU-0004i3-0e for qemu-devel@nongnu.org; Thu, 13 Sep 2012 05:20:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:7193) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TC5aT-0004hk-OB for qemu-devel@nongnu.org; Thu, 13 Sep 2012 05:19:53 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q8D9JrOd010486 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 13 Sep 2012 05:19:53 -0400 Received: from rincewind.home.kraxel.org (ovpn-116-20.ams2.redhat.com [10.36.116.20]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q8D9JqBT001379; Thu, 13 Sep 2012 05:19:52 -0400 Received: by rincewind.home.kraxel.org (Postfix, from userid 500) id 56E3D40C80; Thu, 13 Sep 2012 11:19:50 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Thu, 13 Sep 2012 11:19:49 +0200 Message-Id: <1347527989-3986-10-git-send-email-kraxel@redhat.com> In-Reply-To: <1347527989-3986-1-git-send-email-kraxel@redhat.com> References: <1347527989-3986-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: Gerd Hoffmann Subject: [Qemu-devel] [PATCH v2 9/9] fbdev: add display scaling support X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Add support for scaling the guest display. Ctrl-Alt-S hotkey toggles scaling. Signed-off-by: Gerd Hoffmann --- ui/fbdev.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 51 insertions(+), 10 deletions(-) diff --git a/ui/fbdev.c b/ui/fbdev.c index 5e700e8..e586f2d 100644 --- a/ui/fbdev.c +++ b/ui/fbdev.c @@ -81,6 +81,7 @@ static pixman_image_t *surface; static pixman_image_t *framebuffer; static pixman_transform_t transform; static pixman_region16_t dirty; +static double scale; static QEMUCursor *ptr_cursor; static pixman_image_t *ptr_image; @@ -88,6 +89,10 @@ static int ptr_refresh; static int px, py, pw, ph; static int mx, my, mon; +/* options */ +static int use_scale = 1; +static pixman_filter_t pfilter = PIXMAN_FILTER_GOOD; + /* fwd decls */ static int fbdev_activate_vt(int tty, int vtno, bool wait); @@ -182,13 +187,14 @@ static void read_mouse(void *opaque) if (ay < 0) { ay = 0; } - if (ax >= cw) { - ax = cw-1; + if (ax >= cw*scale) { + ax = cw*scale-1; } - if (ay >= ch) { - ay = ch-1; + if (ay >= ch*scale) { + ay = ch*scale-1; } - kbd_mouse_event(ax * 0x7FFF / cw, ay * 0x7FFF / ch, 0, b); + kbd_mouse_event(ax * 0x7FFF / (cw*scale), + ay * 0x7FFF / (ch*scale), 0, b); } else { kbd_mouse_event(x, y, 0, b); } @@ -543,6 +549,12 @@ static void read_mediumraw(void *opaque) "(ctrl-alt-esc) ===\n"); exit(1); } + if (keycode == KEY_S) { + use_scale = !use_scale; + resize_screen++; + redraw_screen++; + continue; + } if (keycode >= KEY_F1 && keycode <= KEY_F10) { fbdev_activate_vt(tty, keycode+1-KEY_F1, false); key_down[keycode] = false; @@ -901,6 +913,11 @@ static void fbdev_render_ptr(DisplayState *ds) pixman_transform_translate(&transform, NULL, pixman_int_to_fixed(-cx), pixman_int_to_fixed(-cy)); + if (use_scale) { + pixman_transform_scale(&transform, NULL, + pixman_double_to_fixed(1/scale), + pixman_double_to_fixed(1/scale)); + } pixman_transform_translate(&transform, NULL, pixman_int_to_fixed(-px), pixman_int_to_fixed(-py)); @@ -926,16 +943,32 @@ static void fbdev_update(DisplayState *ds, int x, int y, int w, int h) } if (resize_screen) { + double xs, ys; + trace_fbdev_dpy_resize(ds_get_width(ds), ds_get_height(ds)); resize_screen = 0; cx = 0; cy = 0; cw = ds_get_width(ds); ch = ds_get_height(ds); - if (ds_get_width(ds) < fb_var.xres) { - cx = (fb_var.xres - ds_get_width(ds)) / 2; - } - if (ds_get_height(ds) < fb_var.yres) { - cy = (fb_var.yres - ds_get_height(ds)) / 2; + + if (use_scale) { + xs = (double)fb_var.xres / cw; + ys = (double)fb_var.yres / ch; + if (xs > ys) { + scale = ys; + cx = (fb_var.xres - ds_get_width(ds)*scale) / 2; + } else { + scale = xs; + cy = (fb_var.yres - ds_get_height(ds)*scale) / 2; + } + } else { + scale = 1; + if (ds_get_width(ds) < fb_var.xres) { + cx = (fb_var.xres - ds_get_width(ds)) / 2; + } + if (ds_get_height(ds) < fb_var.yres) { + cy = (fb_var.yres - ds_get_height(ds)) / 2; + } } if (surface) { pixman_image_unref(surface); @@ -946,7 +979,14 @@ static void fbdev_update(DisplayState *ds, int x, int y, int w, int h) pixman_transform_translate(&transform, NULL, pixman_int_to_fixed(-cx), pixman_int_to_fixed(-cy)); + if (use_scale) { + pixman_transform_scale(&transform, NULL, + pixman_double_to_fixed(1/scale), + pixman_double_to_fixed(1/scale)); + } pixman_image_set_transform(surface, &transform); + + pixman_image_set_filter(surface, pfilter, NULL, 0); } if (redraw_screen) { @@ -1029,6 +1069,7 @@ static void fbdev_cursor_define(DisplayState *ds, QEMUCursor *cursor) cursor->width, cursor->height, cursor->data, cursor->width * 4); + pixman_image_set_filter(ptr_image, pfilter, NULL, 0); } static void fbdev_exit_notifier(Notifier *notifier, void *data)