qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH 8/9] fbdev: add mouse pointer support
Date: Tue, 18 Sep 2012 09:17:13 +0200	[thread overview]
Message-ID: <1347952634-12286-9-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1347952634-12286-1-git-send-email-kraxel@redhat.com>

Add mouse_set and cursor_define DisplayChangeListener callbacks
and mouse pointer rendering support.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 ui/fbdev.c |   95 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 95 insertions(+), 0 deletions(-)

diff --git a/ui/fbdev.c b/ui/fbdev.c
index 4cb4d1d..6835fef 100644
--- a/ui/fbdev.c
+++ b/ui/fbdev.c
@@ -82,6 +82,12 @@ static pixman_image_t             *framebuffer;
 static pixman_transform_t         transform;
 static pixman_region16_t          dirty;
 
+static QEMUCursor                 *ptr_cursor;
+static pixman_image_t             *ptr_image;
+static int                        ptr_refresh;
+static int                        px, py, pw, ph;
+static int                        mx, my, mon;
+
 /* fwd decls */
 static int fbdev_activate_vt(int tty, int vtno, bool wait);
 
@@ -876,6 +882,51 @@ static void fbdev_render(DisplayState *ds)
     pixman_region_init(&dirty);
 }
 
+static void fbdev_unrender_ptr(DisplayState *ds)
+{
+    if (!pw && !ph) {
+        return;
+    }
+    pixman_region_union_rect(&dirty, &dirty, px, py, pw, ph);
+    ph = pw = 0;
+}
+
+static void fbdev_render_ptr(DisplayState *ds)
+{
+    pixman_region16_t region;
+    pixman_transform_t transform;
+
+    if (!mon || !ptr_image) {
+        return;
+    }
+    if (mx < 0 || mx >= cw || my < 0 || my >= ch) {
+        return;
+    }
+
+    px = mx - ptr_cursor->hot_x;
+    py = my - ptr_cursor->hot_y;
+    pw = ptr_cursor->width;
+    ph = ptr_cursor->height;
+
+    pixman_transform_init_identity(&transform);
+    pixman_transform_translate(&transform, NULL,
+                               pixman_int_to_fixed(-cx),
+                               pixman_int_to_fixed(-cy));
+    pixman_transform_translate(&transform, NULL,
+                               pixman_int_to_fixed(-px),
+                               pixman_int_to_fixed(-py));
+    pixman_image_set_transform(ptr_image, &transform);
+
+    pixman_region_init_rect(&region, 0, 0, pw, ph);
+    pixman_image_set_clip_region(ptr_image, &region);
+
+    pixman_image_composite(PIXMAN_OP_OVER, ptr_image, NULL, framebuffer,
+                           0, 0, 0, 0, 0, 0, fb_var.xres, fb_var.yres);
+
+    pixman_region_fini(&region);
+    ptr_refresh = 0;
+}
+
 /* -------------------------------------------------------------------- */
 /* qemu interfaces                                                      */
 
@@ -917,6 +968,9 @@ static void fbdev_update(DisplayState *ds, int x, int y, int w, int h)
     }
 
     pixman_region_union_rect(&dirty, &dirty, x, y, w, h);
+    if (ptr_image && mon && pw && ph) {
+        ptr_refresh++;
+    }
 }
 
 static void fbdev_resize(DisplayState *ds)
@@ -953,9 +1007,48 @@ static void fbdev_refresh(DisplayState *ds)
         fbdev_update(ds, 0, 0, 0, 0);
     }
 
+    if (ptr_refresh) {
+        fbdev_unrender_ptr(ds);
+    }
     if (pixman_region_not_empty(&dirty)) {
         fbdev_render(ds);
     }
+    if (ptr_refresh) {
+        fbdev_render_ptr(ds);
+    }
+}
+
+static void fbdev_mouse_set(DisplayState *ds, int x, int y, int on)
+{
+    ptr_refresh++;
+    mx = x;
+    my = y;
+    mon = on;
+}
+
+static void fbdev_cursor_define(DisplayState *ds, QEMUCursor *cursor)
+{
+    ptr_refresh++;
+
+    if (ptr_cursor) {
+        cursor_put(ptr_cursor);
+        ptr_cursor = NULL;
+    }
+    if (ptr_image) {
+        pixman_image_unref(ptr_image);
+        ptr_image = NULL;
+    }
+
+    if (!cursor) {
+        return;
+    }
+
+    ptr_cursor = cursor;
+    cursor_get(ptr_cursor);
+    ptr_image = pixman_image_create_bits(PIXMAN_a8r8g8b8,
+                                         cursor->width, cursor->height,
+                                         cursor->data,
+                                         cursor->width * 4);
 }
 
 static void fbdev_exit_notifier(Notifier *notifier, void *data)
@@ -984,6 +1077,8 @@ int fbdev_display_init(DisplayState *ds, const char *device)
     dcl->dpy_resize  = fbdev_resize;
     dcl->dpy_setdata = fbdev_setdata;
     dcl->dpy_refresh = fbdev_refresh;
+    dcl->dpy_mouse_set = fbdev_mouse_set;
+    dcl->dpy_cursor_define = fbdev_cursor_define;
     register_displaychangelistener(ds, dcl);
 
     trace_fbdev_enabled();
-- 
1.7.1

  parent reply	other threads:[~2012-09-18  7:17 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-18  7:17 [Qemu-devel] [PULL 0/9] linux framebuffer display driver Gerd Hoffmann
2012-09-18  7:17 ` [Qemu-devel] [PATCH 1/9] QLIST-ify display change listeners Gerd Hoffmann
2012-09-18  7:17 ` [Qemu-devel] [PATCH 2/9] add unregister_displaychangelistener Gerd Hoffmann
2012-09-18 10:54   ` Stefano Stabellini
2012-09-18  7:17 ` [Qemu-devel] [PATCH 3/9] move set_mouse + cursor_define callbacks Gerd Hoffmann
2012-09-18 14:10   ` Stefano Stabellini
2012-09-18 16:31     ` Gerd Hoffmann
2012-09-18 16:44       ` Stefano Stabellini
2012-09-18  7:17 ` [Qemu-devel] [PATCH 4/9] fbdev: add linux framebuffer display driver Gerd Hoffmann
2012-09-18 15:01   ` Stefano Stabellini
2012-09-19  5:19     ` Gerd Hoffmann
2012-09-19 18:37   ` Blue Swirl
2012-09-18  7:17 ` [Qemu-devel] [PATCH 5/9] fbdev: add monitor command to enable/disable Gerd Hoffmann
2012-09-18 12:47   ` Luiz Capitulino
2012-09-18  7:17 ` [Qemu-devel] [PATCH 6/9] fbdev: make configurable at compile time Gerd Hoffmann
2012-09-18  7:17 ` [Qemu-devel] [PATCH 7/9] fbdev: move to pixman Gerd Hoffmann
2012-09-18 15:01   ` Stefano Stabellini
2012-09-19  5:51     ` Gerd Hoffmann
2012-09-18 19:14   ` Anthony Liguori
2012-09-18 21:08     ` Anthony Liguori
2012-11-26 18:42     ` Alexander Graf
2012-11-26 20:01       ` Gerd Hoffmann
2012-11-26 20:05         ` Alexander Graf
2012-09-18 20:30   ` Søren Sandmann
2012-09-19  5:56     ` Gerd Hoffmann
2012-09-18  7:17 ` Gerd Hoffmann [this message]
2012-09-18  7:17 ` [Qemu-devel] [PATCH 9/9] fbdev: add display scaling support Gerd Hoffmann
2012-09-18 15:02   ` Stefano Stabellini
2012-09-19  5:52     ` Gerd Hoffmann
  -- strict thread matches above, loose matches on Subject: below --
2012-09-19 11:15 [Qemu-devel] [PATCH v4 0/9] linux framebuffer display driver Gerd Hoffmann
2012-09-19 11:15 ` [Qemu-devel] [PATCH 8/9] fbdev: add mouse pointer support Gerd Hoffmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1347952634-12286-9-git-send-email-kraxel@redhat.com \
    --to=kraxel@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).