qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/3] local cursor patches.
@ 2010-05-05 12:51 Gerd Hoffmann
  2010-05-05 12:51 ` [Qemu-devel] [PATCH 1/3] cursor: add cursor functions Gerd Hoffmann
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Gerd Hoffmann @ 2010-05-05 12:51 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

  Hi,

Local cursor bits, rehashed after discussions with anthony.

cheers,
  Gerd

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Qemu-devel] [PATCH 1/3] cursor: add cursor functions.
  2010-05-05 12:51 [Qemu-devel] [PATCH 0/3] local cursor patches Gerd Hoffmann
@ 2010-05-05 12:51 ` Gerd Hoffmann
  2010-05-06 18:12   ` Blue Swirl
  2010-05-05 12:51 ` [Qemu-devel] [PATCH 2/3] use new cursor struct + functions for vmware vga and sdl Gerd Hoffmann
  2010-05-05 12:51 ` [Qemu-devel] [PATCH 3/3] vnc: rich cursor support Gerd Hoffmann
  2 siblings, 1 reply; 15+ messages in thread
From: Gerd Hoffmann @ 2010-05-05 12:51 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

Add a new cursor type to console.h and a bunch of functions to
deal with cursors the (new) cursor.c file.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 Makefile.objs |    3 +-
 console.h     |   24 ++++++-
 cursor.c      |  208 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 232 insertions(+), 3 deletions(-)
 create mode 100644 cursor.c

diff --git a/Makefile.objs b/Makefile.objs
index ecdd53e..1ee6e9d 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -48,7 +48,8 @@ common-obj-y = $(block-obj-y)
 common-obj-y += $(net-obj-y)
 common-obj-y += $(qobject-obj-y)
 common-obj-$(CONFIG_LINUX) += $(fsdev-obj-$(CONFIG_LINUX))
-common-obj-y += readline.o console.o async.o qemu-error.o
+common-obj-y += readline.o console.o cursor.o async.o qemu-error.o
+
 common-obj-y += tcg-runtime.o host-utils.o
 common-obj-y += irq.o ioport.o input.o
 common-obj-$(CONFIG_PTIMER) += ptimer.o
diff --git a/console.h b/console.h
index 6def115..88861cb 100644
--- a/console.h
+++ b/console.h
@@ -126,6 +126,27 @@ struct DisplaySurface {
     struct PixelFormat pf;
 };
 
+/* cursor data format is 32bit RGBA */
+typedef struct QEMUCursor {
+    int                 width, height;
+    int                 hot_x, hot_y;
+    int                 refcount;
+    uint32_t            data[];
+} QEMUCursor;
+
+QEMUCursor *cursor_alloc(int width, int height);
+void cursor_get(QEMUCursor *c);
+void cursor_put(QEMUCursor *c);
+QEMUCursor *cursor_builtin_hidden(void);
+QEMUCursor *cursor_builtin_left_ptr(void);
+void cursor_print_ascii_art(QEMUCursor *c, const char *prefix);
+int cursor_get_mono_bpl(QEMUCursor *c);
+void cursor_set_mono(QEMUCursor *c,
+                     uint32_t foreground, uint32_t background, uint8_t *image,
+                     int transparent, uint8_t *mask);
+void cursor_get_mono_image(QEMUCursor *c, int foreground, uint8_t *mask);
+void cursor_get_mono_mask(QEMUCursor *c, int transparent, uint8_t *mask);
+
 struct DisplayChangeListener {
     int idle;
     uint64_t gui_timer_interval;
@@ -158,8 +179,7 @@ struct DisplayState {
     struct DisplayChangeListener* listeners;
 
     void (*mouse_set)(int x, int y, int on);
-    void (*cursor_define)(int width, int height, int bpp, int hot_x, int hot_y,
-                          uint8_t *image, uint8_t *mask);
+    void (*cursor_define)(QEMUCursor *cursor);
 
     struct DisplayState *next;
 };
diff --git a/cursor.c b/cursor.c
new file mode 100644
index 0000000..3995a31
--- /dev/null
+++ b/cursor.c
@@ -0,0 +1,208 @@
+#include "qemu-common.h"
+#include "console.h"
+
+static const char cursor_hidden_32[32*32];
+static const char cursor_left_ptr_32[32*32] = {
+    "                                "
+    " X                              "
+    " XX                             "
+    " X.X                            "
+    " X..X                           "
+    " X...X                          "
+    " X....X                         "
+    " X.....X                        "
+    " X......X                       "
+    " X.......X                      "
+    " X........X                     "
+    " X.....XXXXX                    "
+    " X..X..X                        "
+    " X.X X..X                       "
+    " XX  X..X                       "
+    " X    X..X                      "
+    "      X..X                      "
+    "       X..X                     "
+    "       X..X                     "
+    "        XX                      "
+    "                                "
+};
+
+/* for creating built-in cursors */
+static void cursor_parse_ascii_art(QEMUCursor *c, const char *ptr)
+{
+    int i, pixels;
+
+    pixels = c->width * c->height;
+    for (i = 0; i < pixels; i++) {
+        switch (ptr[i]) {
+        case 'X': /* black */
+            c->data[i] = 0xff000000;
+            break;
+        case '.': /* white */
+            c->data[i] = 0xffffffff;
+            break;
+        case ' ': /* transparent */
+        default:
+            c->data[i] = 0x00000000;
+            break;
+        }
+    }
+}
+
+/* nice for debugging */
+void cursor_print_ascii_art(QEMUCursor *c, const char *prefix)
+{
+    uint32_t *data = c->data;
+    int x,y;
+
+    for (y = 0; y < c->height; y++) {
+        fprintf(stderr, "%s: %2d: |", prefix, y);
+        for (x = 0; x < c->width; x++, data++) {
+            if ((*data & 0xff000000) != 0xff000000) {
+                fprintf(stderr, " "); /* transparent */
+            } else if ((*data & 0x00ffffff) == 0x00ffffff) {
+                fprintf(stderr, "."); /* white */
+            } else if ((*data & 0x00ffffff) == 0x00000000) {
+                fprintf(stderr, "X"); /* black */
+            } else {
+                fprintf(stderr, "o"); /* other */
+            }
+        }
+        fprintf(stderr, "|\n");
+    }
+}
+
+QEMUCursor *cursor_builtin_hidden(void)
+{
+    QEMUCursor *c;
+
+    c = cursor_alloc(32, 32);
+    cursor_parse_ascii_art(c, cursor_hidden_32);
+    return c;
+}
+
+QEMUCursor *cursor_builtin_left_ptr(void)
+{
+    QEMUCursor *c;
+
+    c = cursor_alloc(32, 32);
+    cursor_parse_ascii_art(c, cursor_left_ptr_32);
+    c->hot_x = 1;
+    c->hot_y = 1;
+    return c;
+}
+
+QEMUCursor *cursor_alloc(int width, int height)
+{
+    QEMUCursor *c;
+    int datasize = width * height * sizeof(uint32_t);
+
+    c = qemu_mallocz(sizeof(QEMUCursor) + datasize);
+    c->width  = width;
+    c->height = height;
+    c->refcount = 1;
+    return c;
+}
+
+void cursor_get(QEMUCursor *c)
+{
+    c->refcount++;
+}
+
+void cursor_put(QEMUCursor *c)
+{
+    if (c == NULL)
+        return;
+    c->refcount--;
+    if (c->refcount)
+        return;
+    qemu_free(c);
+}
+
+int cursor_get_mono_bpl(QEMUCursor *c)
+{
+    return (c->width + 7) / 8;
+}
+
+void cursor_set_mono(QEMUCursor *c,
+                     uint32_t foreground, uint32_t background, uint8_t *image,
+                     int transparent, uint8_t *mask)
+{
+    uint32_t *data = c->data;
+    uint8_t bit;
+    int x,y,bpl;
+
+    bpl = cursor_get_mono_bpl(c);
+    for (y = 0; y < c->height; y++) {
+        bit = 0x80;
+        for (x = 0; x < c->width; x++, data++) {
+            if (transparent && mask[x/8] & bit) {
+                *data = 0x00000000;
+            } else if (!transparent && !(mask[x/8] & bit)) {
+                *data = 0x00000000;
+            } else if (image[x/8] & bit) {
+                *data = 0xff000000 | foreground;
+            } else {
+                *data = 0xff000000 | background;
+            }
+            bit >>= 1;
+            if (bit == 0) {
+                bit = 0x80;
+            }
+        }
+        mask  += bpl;
+        image += bpl;
+    }
+}
+
+void cursor_get_mono_image(QEMUCursor *c, int foreground, uint8_t *image)
+{
+    uint32_t *data = c->data;
+    uint8_t bit;
+    int x,y,bpl;
+
+    bpl = cursor_get_mono_bpl(c);
+    memset(image, 0, bpl * c->height);
+    for (y = 0; y < c->height; y++) {
+        bit = 0x80;
+        for (x = 0; x < c->width; x++, data++) {
+            if (((*data & 0xff000000) == 0xff000000) &&
+                ((*data & 0x00ffffff) == foreground)) {
+                image[x/8] |= bit;
+            }
+            bit >>= 1;
+            if (bit == 0) {
+                bit = 0x80;
+            }
+        }
+        image += bpl;
+    }
+}
+
+void cursor_get_mono_mask(QEMUCursor *c, int transparent, uint8_t *mask)
+{
+    uint32_t *data = c->data;
+    uint8_t bit;
+    int x,y,bpl;
+
+    bpl = cursor_get_mono_bpl(c);
+    memset(mask, 0, bpl * c->height);
+    for (y = 0; y < c->height; y++) {
+        bit = 0x80;
+        for (x = 0; x < c->width; x++, data++) {
+            if ((*data & 0xff000000) != 0xff000000) {
+                if (transparent != 0) {
+                    mask[x/8] |= bit;
+                }
+            } else {
+                if (transparent == 0) {
+                    mask[x/8] |= bit;
+                }
+            }
+            bit >>= 1;
+            if (bit == 0) {
+                bit = 0x80;
+            }
+        }
+        mask += bpl;
+    }
+}
-- 
1.6.6.1

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [Qemu-devel] [PATCH 2/3] use new cursor struct + functions for vmware vga and sdl.
  2010-05-05 12:51 [Qemu-devel] [PATCH 0/3] local cursor patches Gerd Hoffmann
  2010-05-05 12:51 ` [Qemu-devel] [PATCH 1/3] cursor: add cursor functions Gerd Hoffmann
@ 2010-05-05 12:51 ` Gerd Hoffmann
  2010-05-05 12:51 ` [Qemu-devel] [PATCH 3/3] vnc: rich cursor support Gerd Hoffmann
  2 siblings, 0 replies; 15+ messages in thread
From: Gerd Hoffmann @ 2010-05-05 12:51 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann


Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/vmware_vga.c |   40 +++++++++++++++++++++++++++++++++++-----
 sdl.c           |   52 +++++++++++++---------------------------------------
 2 files changed, 48 insertions(+), 44 deletions(-)

diff --git a/hw/vmware_vga.c b/hw/vmware_vga.c
index e709369..bf2a699 100644
--- a/hw/vmware_vga.c
+++ b/hw/vmware_vga.c
@@ -477,13 +477,43 @@ struct vmsvga_cursor_definition_s {
 static inline void vmsvga_cursor_define(struct vmsvga_state_s *s,
                 struct vmsvga_cursor_definition_s *c)
 {
-    int i;
-    for (i = SVGA_BITMAP_SIZE(c->width, c->height) - 1; i >= 0; i --)
-        c->mask[i] = ~c->mask[i];
+    QEMUCursor *qc;
+    int i, pixels;
+
+    qc = cursor_alloc(c->width, c->height);
+    qc->hot_x = c->hot_x;
+    qc->hot_y = c->hot_y;
+    switch (c->bpp) {
+    case 1:
+        cursor_set_mono(qc, 0xffffff, 0x000000, (void*)c->image,
+                        1, (void*)c->mask);
+#ifdef DEBUG
+        cursor_print_ascii_art(qc, "vmware/mono");
+#endif
+        break;
+    case 32:
+        /* fill alpha channel from mask, set color to zero */
+        cursor_set_mono(qc, 0x000000, 0x000000, (void*)c->mask,
+                        1, (void*)c->mask);
+        /* add in rgb values */
+        pixels = c->width * c->height;
+        for (i = 0; i < pixels; i++) {
+            qc->data[i] |= c->image[i] & 0xffffff;
+        }
+#ifdef DEBUG
+        cursor_print_ascii_art(qc, "vmware/32bit");
+#endif
+        break;
+    default:
+        fprintf(stderr, "%s: unhandled bpp %d, using fallback cursor\n",
+                __FUNCTION__, c->bpp);
+        cursor_put(qc);
+        qc = cursor_builtin_left_ptr();
+    }
 
     if (s->vga.ds->cursor_define)
-        s->vga.ds->cursor_define(c->width, c->height, c->bpp, c->hot_x, c->hot_y,
-                        (uint8_t *) c->image, (uint8_t *) c->mask);
+        s->vga.ds->cursor_define(qc);
+    cursor_put(qc);
 }
 #endif
 
diff --git a/sdl.c b/sdl.c
index 16a48e9..7c9ddbf 100644
--- a/sdl.c
+++ b/sdl.c
@@ -778,49 +778,23 @@ static void sdl_mouse_warp(int x, int y, int on)
     guest_x = x, guest_y = y;
 }
 
-static void sdl_mouse_define(int width, int height, int bpp,
-                             int hot_x, int hot_y,
-                             uint8_t *image, uint8_t *mask)
+static void sdl_mouse_define(QEMUCursor *c)
 {
-    uint8_t sprite[256], *line;
-    int x, y, dst, bypl, src = 0;
+    uint8_t *image, *mask;
+    int bpl;
+
     if (guest_sprite)
         SDL_FreeCursor(guest_sprite);
 
-    memset(sprite, 0, 256);
-    bypl = ((width * bpp + 31) >> 5) << 2;
-    for (y = 0, dst = 0; y < height; y ++, image += bypl) {
-        line = image;
-        for (x = 0; x < width; x ++, dst ++) {
-            switch (bpp) {
-            case 32:
-                src = *(line ++); src |= *(line ++); src |= *(line ++); line++;
-                break;
-            case 24:
-                src = *(line ++); src |= *(line ++); src |= *(line ++);
-                break;
-            case 16:
-            case 15:
-                src = *(line ++); src |= *(line ++);
-                break;
-            case 8:
-                src = *(line ++);
-                break;
-            case 4:
-                src = 0xf & (line[x >> 1] >> ((x & 1)) << 2);
-                break;
-            case 2:
-                src = 3 & (line[x >> 2] >> ((x & 3)) << 1);
-                break;
-            case 1:
-                src = 1 & (line[x >> 3] >> (x & 7));
-                break;
-            }
-            if (!src)
-                sprite[dst >> 3] |= (1 << (~dst & 7)) & mask[dst >> 3];
-        }
-    }
-    guest_sprite = SDL_CreateCursor(sprite, mask, width, height, hot_x, hot_y);
+    bpl = cursor_get_mono_bpl(c);
+    image = qemu_mallocz(bpl * c->height);
+    mask  = qemu_mallocz(bpl * c->height);
+    cursor_get_mono_image(c, 0x000000, image);
+    cursor_get_mono_mask(c, 0, mask);
+    guest_sprite = SDL_CreateCursor(image, mask, c->width, c->height,
+                                    c->hot_x, c->hot_y);
+    qemu_free(image);
+    qemu_free(mask);
 
     if (guest_cursor &&
             (gui_grab || kbd_mouse_is_absolute() || absolute_enabled))
-- 
1.6.6.1

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [Qemu-devel] [PATCH 3/3] vnc: rich cursor support.
  2010-05-05 12:51 [Qemu-devel] [PATCH 0/3] local cursor patches Gerd Hoffmann
  2010-05-05 12:51 ` [Qemu-devel] [PATCH 1/3] cursor: add cursor functions Gerd Hoffmann
  2010-05-05 12:51 ` [Qemu-devel] [PATCH 2/3] use new cursor struct + functions for vmware vga and sdl Gerd Hoffmann
@ 2010-05-05 12:51 ` Gerd Hoffmann
  2 siblings, 0 replies; 15+ messages in thread
From: Gerd Hoffmann @ 2010-05-05 12:51 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

Uses VNC_ENCODING_RICH_CURSOR.  Adding XCURSOR support should be
possible without much trouble.  Shouldn't be needed though as
RICH_CURSOR is a superset of XCURSOR.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 vnc.c        |   67 +++++++++++++++++++++++++++++++++++++++++++++++++++-------
 vnc.h        |    8 ++++++-
 vnchextile.h |    7 +++--
 3 files changed, 70 insertions(+), 12 deletions(-)

diff --git a/vnc.c b/vnc.c
index b1a3fdb..b97eae7 100644
--- a/vnc.c
+++ b/vnc.c
@@ -554,7 +554,8 @@ static void vnc_dpy_resize(DisplayState *ds)
 }
 
 /* fastest code */
-static void vnc_write_pixels_copy(VncState *vs, void *pixels, int size)
+static void vnc_write_pixels_copy(VncState *vs, struct PixelFormat *pf,
+                                  void *pixels, int size)
 {
     vnc_write(vs, pixels, size);
 }
@@ -604,12 +605,12 @@ void vnc_convert_pixel(VncState *vs, uint8_t *buf, uint32_t v)
     }
 }
 
-static void vnc_write_pixels_generic(VncState *vs, void *pixels1, int size)
+static void vnc_write_pixels_generic(VncState *vs, struct PixelFormat *pf,
+                                     void *pixels1, int size)
 {
     uint8_t buf[4];
-    VncDisplay *vd = vs->vd;
 
-    if (vd->server->pf.bytes_per_pixel == 4) {
+    if (pf->bytes_per_pixel == 4) {
         uint32_t *pixels = pixels1;
         int n, i;
         n = size >> 2;
@@ -617,7 +618,7 @@ static void vnc_write_pixels_generic(VncState *vs, void *pixels1, int size)
             vnc_convert_pixel(vs, buf, pixels[i]);
             vnc_write(vs, buf, vs->clientds.pf.bytes_per_pixel);
         }
-    } else if (vd->server->pf.bytes_per_pixel == 2) {
+    } else if (pf->bytes_per_pixel == 2) {
         uint16_t *pixels = pixels1;
         int n, i;
         n = size >> 1;
@@ -625,7 +626,7 @@ static void vnc_write_pixels_generic(VncState *vs, void *pixels1, int size)
             vnc_convert_pixel(vs, buf, pixels[i]);
             vnc_write(vs, buf, vs->clientds.pf.bytes_per_pixel);
         }
-    } else if (vd->server->pf.bytes_per_pixel == 1) {
+    } else if (pf->bytes_per_pixel == 1) {
         uint8_t *pixels = pixels1;
         int n, i;
         n = size;
@@ -646,7 +647,7 @@ void vnc_raw_send_framebuffer_update(VncState *vs, int x, int y, int w, int h)
 
     row = vd->server->data + y * ds_get_linesize(vs->ds) + x * ds_get_bytes_per_pixel(vs->ds);
     for (i = 0; i < h; i++) {
-        vs->write_pixels(vs, row, w * ds_get_bytes_per_pixel(vs->ds));
+        vs->write_pixels(vs, &vd->server->pf, row, w * ds_get_bytes_per_pixel(vs->ds));
         row += ds_get_linesize(vs->ds);
     }
 }
@@ -752,6 +753,50 @@ static void vnc_dpy_copy(DisplayState *ds, int src_x, int src_y, int dst_x, int
     }
 }
 
+static void vnc_mouse_set(int x, int y, int visible)
+{
+    /* can we ask the client(s) to move the pointer ??? */
+}
+
+static int vnc_cursor_define(VncState *vs)
+{
+    QEMUCursor *c = vs->vd->cursor;
+    PixelFormat pf = qemu_default_pixelformat(32);
+    int isize;
+
+    if (vnc_has_feature(vs, VNC_FEATURE_RICH_CURSOR)) {
+        vnc_write_u8(vs,  VNC_MSG_SERVER_FRAMEBUFFER_UPDATE);
+        vnc_write_u8(vs,  0);  /*  padding     */
+        vnc_write_u16(vs, 1);  /*  # of rects  */
+        vnc_framebuffer_update(vs, c->hot_x, c->hot_y, c->width, c->height,
+                               VNC_ENCODING_RICH_CURSOR);
+        isize = c->width * c->height * vs->clientds.pf.bytes_per_pixel;
+        vnc_write_pixels_generic(vs, &pf, c->data, isize);
+        vnc_write(vs, vs->vd->cursor_mask, vs->vd->cursor_msize);
+        return 0;
+    }
+    return -1;
+}
+
+static void vnc_dpy_cursor_define(QEMUCursor *c)
+{
+    VncDisplay *vd = vnc_display;
+    VncState *vs;
+
+    cursor_put(vd->cursor);
+    qemu_free(vd->cursor_mask);
+
+    vd->cursor = c;
+    cursor_get(vd->cursor);
+    vd->cursor_msize = cursor_get_mono_bpl(c) * c->height;
+    vd->cursor_mask = qemu_mallocz(vd->cursor_msize);
+    cursor_get_mono_mask(c, 0, vd->cursor_mask);
+
+    QTAILQ_FOREACH(vs, &vd->clients, next) {
+        vnc_cursor_define(vs);
+    }
+}
+
 static int find_and_clear_dirty_height(struct VncState *vs,
                                        int y, int last_x, int x)
 {
@@ -1622,6 +1667,9 @@ static void set_encodings(VncState *vs, int32_t *encodings, size_t n_encodings)
         case VNC_ENCODING_POINTER_TYPE_CHANGE:
             vs->features |= VNC_FEATURE_POINTER_TYPE_CHANGE_MASK;
             break;
+        case VNC_ENCODING_RICH_CURSOR:
+            vs->features |= VNC_FEATURE_RICH_CURSOR_MASK;
+            break;
         case VNC_ENCODING_EXT_KEY_EVENT:
             send_ext_key_event_ack(vs);
             break;
@@ -1642,8 +1690,9 @@ static void set_encodings(VncState *vs, int32_t *encodings, size_t n_encodings)
             break;
         }
     }
-
     check_pointer_type_change(&vs->mouse_mode_notifier);
+    if (vs->vd->cursor)
+        vnc_cursor_define(vs);
 }
 
 static void set_pixel_conversion(VncState *vs)
@@ -2288,6 +2337,8 @@ void vnc_display_init(DisplayState *ds)
     dcl->dpy_resize = vnc_dpy_resize;
     dcl->dpy_setdata = vnc_dpy_setdata;
     register_displaychangelistener(ds, dcl);
+    ds->mouse_set = vnc_mouse_set;
+    ds->cursor_define = vnc_dpy_cursor_define;
 }
 
 
diff --git a/vnc.h b/vnc.h
index 1aa71b0..0d39897 100644
--- a/vnc.h
+++ b/vnc.h
@@ -61,7 +61,7 @@ typedef struct VncState VncState;
 
 typedef int VncReadEvent(VncState *vs, uint8_t *data, size_t len);
 
-typedef void VncWritePixels(VncState *vs, void *data, int size);
+typedef void VncWritePixels(VncState *vs, struct PixelFormat *pf, void *data, int size);
 
 typedef void VncSendHextileTile(VncState *vs,
                                 int x, int y, int w, int h,
@@ -101,6 +101,10 @@ struct VncDisplay
     kbd_layout_t *kbd_layout;
     int lock_key_sync;
 
+    QEMUCursor *cursor;
+    int cursor_msize;
+    uint8_t *cursor_mask;
+
     struct VncSurface guest;   /* guest visible surface (aka ds->surface) */
     DisplaySurface *server;  /* vnc server surface */
 
@@ -273,6 +277,7 @@ enum {
 #define VNC_FEATURE_TIGHT                    4
 #define VNC_FEATURE_ZLIB                     5
 #define VNC_FEATURE_COPYRECT                 6
+#define VNC_FEATURE_RICH_CURSOR              7
 
 #define VNC_FEATURE_RESIZE_MASK              (1 << VNC_FEATURE_RESIZE)
 #define VNC_FEATURE_HEXTILE_MASK             (1 << VNC_FEATURE_HEXTILE)
@@ -281,6 +286,7 @@ enum {
 #define VNC_FEATURE_TIGHT_MASK               (1 << VNC_FEATURE_TIGHT)
 #define VNC_FEATURE_ZLIB_MASK                (1 << VNC_FEATURE_ZLIB)
 #define VNC_FEATURE_COPYRECT_MASK            (1 << VNC_FEATURE_COPYRECT)
+#define VNC_FEATURE_RICH_CURSOR_MASK         (1 << VNC_FEATURE_RICH_CURSOR)
 
 
 /* Client -> Server message IDs */
diff --git a/vnchextile.h b/vnchextile.h
index 78ed8c4..b9f9f5e 100644
--- a/vnchextile.h
+++ b/vnchextile.h
@@ -189,16 +189,17 @@ static void CONCAT(send_hextile_tile_, NAME)(VncState *vs,
     vnc_write_u8(vs, flags);
     if (n_colors < 4) {
 	if (flags & 0x02)
-	    vs->write_pixels(vs, last_bg, sizeof(pixel_t));
+	    vs->write_pixels(vs, &vd->server->pf, last_bg, sizeof(pixel_t));
 	if (flags & 0x04)
-	    vs->write_pixels(vs, last_fg, sizeof(pixel_t));
+	    vs->write_pixels(vs, &vd->server->pf, last_fg, sizeof(pixel_t));
 	if (n_subtiles) {
 	    vnc_write_u8(vs, n_subtiles);
 	    vnc_write(vs, data, n_data);
 	}
     } else {
 	for (j = 0; j < h; j++) {
-	    vs->write_pixels(vs, row, w * ds_get_bytes_per_pixel(vs->ds));
+	    vs->write_pixels(vs, &vd->server->pf, row,
+                             w * ds_get_bytes_per_pixel(vs->ds));
 	    row += ds_get_linesize(vs->ds);
 	}
     }
-- 
1.6.6.1

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] [PATCH 1/3] cursor: add cursor functions.
  2010-05-05 12:51 ` [Qemu-devel] [PATCH 1/3] cursor: add cursor functions Gerd Hoffmann
@ 2010-05-06 18:12   ` Blue Swirl
  2010-05-06 19:27     ` Gerd Hoffmann
  2010-05-07  7:05     ` [Qemu-devel] " Paolo Bonzini
  0 siblings, 2 replies; 15+ messages in thread
From: Blue Swirl @ 2010-05-06 18:12 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: qemu-devel

On 5/5/10, Gerd Hoffmann <kraxel@redhat.com> wrote:
> Add a new cursor type to console.h and a bunch of functions to
>  deal with cursors the (new) cursor.c file.
>
>  Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
>  ---
>   Makefile.objs |    3 +-
>   console.h     |   24 ++++++-
>   cursor.c      |  208 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>   3 files changed, 232 insertions(+), 3 deletions(-)
>   create mode 100644 cursor.c
>
>  diff --git a/Makefile.objs b/Makefile.objs
>  index ecdd53e..1ee6e9d 100644
>  --- a/Makefile.objs
>  +++ b/Makefile.objs
>  @@ -48,7 +48,8 @@ common-obj-y = $(block-obj-y)
>   common-obj-y += $(net-obj-y)
>   common-obj-y += $(qobject-obj-y)
>   common-obj-$(CONFIG_LINUX) += $(fsdev-obj-$(CONFIG_LINUX))
>  -common-obj-y += readline.o console.o async.o qemu-error.o
>  +common-obj-y += readline.o console.o cursor.o async.o qemu-error.o
>  +
>   common-obj-y += tcg-runtime.o host-utils.o
>   common-obj-y += irq.o ioport.o input.o
>   common-obj-$(CONFIG_PTIMER) += ptimer.o
>  diff --git a/console.h b/console.h
>  index 6def115..88861cb 100644
>  --- a/console.h
>  +++ b/console.h
>  @@ -126,6 +126,27 @@ struct DisplaySurface {
>      struct PixelFormat pf;
>   };
>
>  +/* cursor data format is 32bit RGBA */
>  +typedef struct QEMUCursor {
>  +    int                 width, height;
>  +    int                 hot_x, hot_y;
>  +    int                 refcount;
>  +    uint32_t            data[];
>  +} QEMUCursor;
>  +
>  +QEMUCursor *cursor_alloc(int width, int height);
>  +void cursor_get(QEMUCursor *c);
>  +void cursor_put(QEMUCursor *c);
>  +QEMUCursor *cursor_builtin_hidden(void);
>  +QEMUCursor *cursor_builtin_left_ptr(void);
>  +void cursor_print_ascii_art(QEMUCursor *c, const char *prefix);
>  +int cursor_get_mono_bpl(QEMUCursor *c);
>  +void cursor_set_mono(QEMUCursor *c,
>  +                     uint32_t foreground, uint32_t background, uint8_t *image,
>  +                     int transparent, uint8_t *mask);
>  +void cursor_get_mono_image(QEMUCursor *c, int foreground, uint8_t *mask);
>  +void cursor_get_mono_mask(QEMUCursor *c, int transparent, uint8_t *mask);
>  +
>   struct DisplayChangeListener {
>      int idle;
>      uint64_t gui_timer_interval;
>  @@ -158,8 +179,7 @@ struct DisplayState {
>      struct DisplayChangeListener* listeners;
>
>      void (*mouse_set)(int x, int y, int on);
>  -    void (*cursor_define)(int width, int height, int bpp, int hot_x, int hot_y,
>  -                          uint8_t *image, uint8_t *mask);
>  +    void (*cursor_define)(QEMUCursor *cursor);
>
>      struct DisplayState *next;
>   };
>  diff --git a/cursor.c b/cursor.c
>  new file mode 100644
>  index 0000000..3995a31
>  --- /dev/null
>  +++ b/cursor.c
>  @@ -0,0 +1,208 @@
>  +#include "qemu-common.h"
>  +#include "console.h"
>  +
>  +static const char cursor_hidden_32[32*32];
>  +static const char cursor_left_ptr_32[32*32] = {
>  +    "                                "
>  +    " X                              "
>  +    " XX                             "
>  +    " X.X                            "
>  +    " X..X                           "
>  +    " X...X                          "
>  +    " X....X                         "
>  +    " X.....X                        "
>  +    " X......X                       "
>  +    " X.......X                      "
>  +    " X........X                     "
>  +    " X.....XXXXX                    "
>  +    " X..X..X                        "
>  +    " X.X X..X                       "
>  +    " XX  X..X                       "
>  +    " X    X..X                      "
>  +    "      X..X                      "
>  +    "       X..X                     "
>  +    "       X..X                     "
>  +    "        XX                      "
>  +    "                                "
>  +};

Is this format standard? How about using X bitmap format instead:
$ cat /usr/include/X11/bitmaps/left_ptr
#define left_ptr_width 16
#define left_ptr_height 16
#define left_ptr_x_hot 3
#define left_ptr_y_hot 1
static char left_ptr_bits[] = {
   0x00, 0x00, 0x08, 0x00, 0x18, 0x00, 0x38, 0x00, 0x78, 0x00, 0xf8, 0x00,
   0xf8, 0x01, 0xf8, 0x03, 0xf8, 0x07, 0xf8, 0x00, 0xd8, 0x00, 0x88, 0x01,
   0x80, 0x01, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00};

Then there would be no need of parsing.

>  +
>  +/* for creating built-in cursors */
>  +static void cursor_parse_ascii_art(QEMUCursor *c, const char *ptr)
>  +{
>  +    int i, pixels;
>  +
>  +    pixels = c->width * c->height;
>  +    for (i = 0; i < pixels; i++) {
>  +        switch (ptr[i]) {
>  +        case 'X': /* black */
>  +            c->data[i] = 0xff000000;
>  +            break;
>  +        case '.': /* white */
>  +            c->data[i] = 0xffffffff;
>  +            break;
>  +        case ' ': /* transparent */
>  +        default:
>  +            c->data[i] = 0x00000000;
>  +            break;
>  +        }
>  +    }
>  +}
>  +
>  +/* nice for debugging */
>  +void cursor_print_ascii_art(QEMUCursor *c, const char *prefix)
>  +{
>  +    uint32_t *data = c->data;
>  +    int x,y;
>  +
>  +    for (y = 0; y < c->height; y++) {
>  +        fprintf(stderr, "%s: %2d: |", prefix, y);
>  +        for (x = 0; x < c->width; x++, data++) {
>  +            if ((*data & 0xff000000) != 0xff000000) {
>  +                fprintf(stderr, " "); /* transparent */
>  +            } else if ((*data & 0x00ffffff) == 0x00ffffff) {
>  +                fprintf(stderr, "."); /* white */
>  +            } else if ((*data & 0x00ffffff) == 0x00000000) {
>  +                fprintf(stderr, "X"); /* black */
>  +            } else {
>  +                fprintf(stderr, "o"); /* other */
>  +            }
>  +        }
>  +        fprintf(stderr, "|\n");
>  +    }
>  +}
>  +
>  +QEMUCursor *cursor_builtin_hidden(void)
>  +{
>  +    QEMUCursor *c;
>  +
>  +    c = cursor_alloc(32, 32);
>  +    cursor_parse_ascii_art(c, cursor_hidden_32);
>  +    return c;
>  +}
>  +
>  +QEMUCursor *cursor_builtin_left_ptr(void)
>  +{
>  +    QEMUCursor *c;
>  +
>  +    c = cursor_alloc(32, 32);
>  +    cursor_parse_ascii_art(c, cursor_left_ptr_32);
>  +    c->hot_x = 1;
>  +    c->hot_y = 1;
>  +    return c;
>  +}
>  +
>  +QEMUCursor *cursor_alloc(int width, int height)
>  +{
>  +    QEMUCursor *c;
>  +    int datasize = width * height * sizeof(uint32_t);
>  +
>  +    c = qemu_mallocz(sizeof(QEMUCursor) + datasize);
>  +    c->width  = width;
>  +    c->height = height;
>  +    c->refcount = 1;
>  +    return c;
>  +}
>  +
>  +void cursor_get(QEMUCursor *c)
>  +{
>  +    c->refcount++;
>  +}
>  +
>  +void cursor_put(QEMUCursor *c)
>  +{
>  +    if (c == NULL)
>  +        return;
>  +    c->refcount--;
>  +    if (c->refcount)
>  +        return;
>  +    qemu_free(c);
>  +}
>  +
>  +int cursor_get_mono_bpl(QEMUCursor *c)
>  +{
>  +    return (c->width + 7) / 8;
>  +}
>  +
>  +void cursor_set_mono(QEMUCursor *c,
>  +                     uint32_t foreground, uint32_t background, uint8_t *image,
>  +                     int transparent, uint8_t *mask)
>  +{
>  +    uint32_t *data = c->data;
>  +    uint8_t bit;
>  +    int x,y,bpl;
>  +
>  +    bpl = cursor_get_mono_bpl(c);
>  +    for (y = 0; y < c->height; y++) {
>  +        bit = 0x80;
>  +        for (x = 0; x < c->width; x++, data++) {
>  +            if (transparent && mask[x/8] & bit) {
>  +                *data = 0x00000000;
>  +            } else if (!transparent && !(mask[x/8] & bit)) {
>  +                *data = 0x00000000;
>  +            } else if (image[x/8] & bit) {
>  +                *data = 0xff000000 | foreground;
>  +            } else {
>  +                *data = 0xff000000 | background;
>  +            }
>  +            bit >>= 1;
>  +            if (bit == 0) {
>  +                bit = 0x80;
>  +            }
>  +        }
>  +        mask  += bpl;
>  +        image += bpl;
>  +    }
>  +}
>  +
>  +void cursor_get_mono_image(QEMUCursor *c, int foreground, uint8_t *image)
>  +{
>  +    uint32_t *data = c->data;
>  +    uint8_t bit;
>  +    int x,y,bpl;
>  +
>  +    bpl = cursor_get_mono_bpl(c);
>  +    memset(image, 0, bpl * c->height);
>  +    for (y = 0; y < c->height; y++) {
>  +        bit = 0x80;
>  +        for (x = 0; x < c->width; x++, data++) {
>  +            if (((*data & 0xff000000) == 0xff000000) &&
>  +                ((*data & 0x00ffffff) == foreground)) {
>  +                image[x/8] |= bit;
>  +            }
>  +            bit >>= 1;
>  +            if (bit == 0) {
>  +                bit = 0x80;
>  +            }
>  +        }
>  +        image += bpl;
>  +    }
>  +}
>  +
>  +void cursor_get_mono_mask(QEMUCursor *c, int transparent, uint8_t *mask)
>  +{
>  +    uint32_t *data = c->data;
>  +    uint8_t bit;
>  +    int x,y,bpl;
>  +
>  +    bpl = cursor_get_mono_bpl(c);
>  +    memset(mask, 0, bpl * c->height);
>  +    for (y = 0; y < c->height; y++) {
>  +        bit = 0x80;
>  +        for (x = 0; x < c->width; x++, data++) {
>  +            if ((*data & 0xff000000) != 0xff000000) {
>  +                if (transparent != 0) {
>  +                    mask[x/8] |= bit;
>  +                }
>  +            } else {
>  +                if (transparent == 0) {
>  +                    mask[x/8] |= bit;
>  +                }
>  +            }
>  +            bit >>= 1;
>  +            if (bit == 0) {
>  +                bit = 0x80;
>  +            }
>  +        }
>  +        mask += bpl;
>  +    }
>  +}
>
> --
>  1.6.6.1
>
>
>
>

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] [PATCH 1/3] cursor: add cursor functions.
  2010-05-06 18:12   ` Blue Swirl
@ 2010-05-06 19:27     ` Gerd Hoffmann
  2010-05-06 19:42       ` Blue Swirl
  2010-05-07  7:05     ` [Qemu-devel] " Paolo Bonzini
  1 sibling, 1 reply; 15+ messages in thread
From: Gerd Hoffmann @ 2010-05-06 19:27 UTC (permalink / raw)
  To: Blue Swirl; +Cc: qemu-devel

>>   +static const char cursor_left_ptr_32[32*32] = {
>>   +    "                                "
>>   +    " X                              "
>>   +    " XX                             "
>>   +    " X.X                            "
>>   +    " X..X                           "
>>   +    " X...X                          "
>>   +    " X....X                         "
>>   +    " X.....X                        "
>>   +    " X......X                       "
>>   +    " X.......X                      "
>>   +    " X........X                     "
>>   +    " X.....XXXXX                    "
>>   +    " X..X..X                        "
>>   +    " X.X X..X                       "
>>   +    " XX  X..X                       "
>>   +    " X    X..X                      "
>>   +    "      X..X                      "
>>   +    "       X..X                     "
>>   +    "       X..X                     "
>>   +    "        XX                      "
>>   +    "                                "
>>   +};
>
> Is this format standard?

Inspiried by xpm but simplified a bit as full xpm support just for a 
built-in fallback cursor would have been overkill.  The nice thing about 
xpm is that you can use any text editor for editing icons.

> How about using X bitmap format instead:
> $ cat /usr/include/X11/bitmaps/left_ptr

> Then there would be no need of parsing.

Well.  You still would have to convert it as qemu internal cursor format 
is defined as 32bit depth, rgb with alpha channel.  So it doesn't buy 
you that much.

cheers,
   Gerd

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] [PATCH 1/3] cursor: add cursor functions.
  2010-05-06 19:27     ` Gerd Hoffmann
@ 2010-05-06 19:42       ` Blue Swirl
  0 siblings, 0 replies; 15+ messages in thread
From: Blue Swirl @ 2010-05-06 19:42 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: qemu-devel

On 5/6/10, Gerd Hoffmann <kraxel@redhat.com> wrote:
> >
> > >  +static const char cursor_left_ptr_32[32*32] = {
> > >  +    "                                "
> > >  +    " X                              "
> > >  +    " XX                             "
> > >  +    " X.X                            "
> > >  +    " X..X                           "
> > >  +    " X...X                          "
> > >  +    " X....X                         "
> > >  +    " X.....X                        "
> > >  +    " X......X                       "
> > >  +    " X.......X                      "
> > >  +    " X........X                     "
> > >  +    " X.....XXXXX                    "
> > >  +    " X..X..X                        "
> > >  +    " X.X X..X                       "
> > >  +    " XX  X..X                       "
> > >  +    " X    X..X                      "
> > >  +    "      X..X                      "
> > >  +    "       X..X                     "
> > >  +    "       X..X                     "
> > >  +    "        XX                      "
> > >  +    "                                "
> > >  +};
> > >
> >
> > Is this format standard?
> >
>
>  Inspiried by xpm but simplified a bit as full xpm support just for a
> built-in fallback cursor would have been overkill.  The nice thing about xpm
> is that you can use any text editor for editing icons.

But for X bitmaps, you can use any real drawing program. The same
would also apply to full xpm. But read on.

> > How about using X bitmap format instead:
> > $ cat /usr/include/X11/bitmaps/left_ptr
> >
>
>
> > Then there would be no need of parsing.
> >
>
>  Well.  You still would have to convert it as qemu internal cursor format is
> defined as 32bit depth, rgb with alpha channel.  So it doesn't buy you that
> much.

There's still more wasted memory compared to binary format.

I think the best would be to store only the 32 bit image and perform
any conversions offline. This was the approach with for example
keyboard tables, we don't convert them at startup but the original
tables are retained as comments.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Qemu-devel] Re: [PATCH 1/3] cursor: add cursor functions.
  2010-05-06 18:12   ` Blue Swirl
  2010-05-06 19:27     ` Gerd Hoffmann
@ 2010-05-07  7:05     ` Paolo Bonzini
  2010-05-07 15:23       ` Blue Swirl
  1 sibling, 1 reply; 15+ messages in thread
From: Paolo Bonzini @ 2010-05-07  7:05 UTC (permalink / raw)
  To: Blue Swirl; +Cc: Gerd Hoffmann, qemu-devel

On 05/06/2010 08:12 PM, Blue Swirl wrote:
> On 5/5/10, Gerd Hoffmann<kraxel@redhat.com>  wrote:
>> Add a new cursor type to console.h and a bunch of functions to
>>   deal with cursors the (new) cursor.c file.
>>
>>   Signed-off-by: Gerd Hoffmann<kraxel@redhat.com>
>>   ---
>>    Makefile.objs |    3 +-
>>    console.h     |   24 ++++++-
>>    cursor.c      |  208 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>>    3 files changed, 232 insertions(+), 3 deletions(-)
>>    create mode 100644 cursor.c
>>
>>   diff --git a/Makefile.objs b/Makefile.objs
>>   index ecdd53e..1ee6e9d 100644
>>   --- a/Makefile.objs
>>   +++ b/Makefile.objs
>>   @@ -48,7 +48,8 @@ common-obj-y = $(block-obj-y)
>>    common-obj-y += $(net-obj-y)
>>    common-obj-y += $(qobject-obj-y)
>>    common-obj-$(CONFIG_LINUX) += $(fsdev-obj-$(CONFIG_LINUX))
>>   -common-obj-y += readline.o console.o async.o qemu-error.o
>>   +common-obj-y += readline.o console.o cursor.o async.o qemu-error.o
>>   +
>>    common-obj-y += tcg-runtime.o host-utils.o
>>    common-obj-y += irq.o ioport.o input.o
>>    common-obj-$(CONFIG_PTIMER) += ptimer.o
>>   diff --git a/console.h b/console.h
>>   index 6def115..88861cb 100644
>>   --- a/console.h
>>   +++ b/console.h
>>   @@ -126,6 +126,27 @@ struct DisplaySurface {
>>       struct PixelFormat pf;
>>    };
>>
>>   +/* cursor data format is 32bit RGBA */
>>   +typedef struct QEMUCursor {
>>   +    int                 width, height;
>>   +    int                 hot_x, hot_y;
>>   +    int                 refcount;
>>   +    uint32_t            data[];
>>   +} QEMUCursor;
>>   +
>>   +QEMUCursor *cursor_alloc(int width, int height);
>>   +void cursor_get(QEMUCursor *c);
>>   +void cursor_put(QEMUCursor *c);
>>   +QEMUCursor *cursor_builtin_hidden(void);
>>   +QEMUCursor *cursor_builtin_left_ptr(void);
>>   +void cursor_print_ascii_art(QEMUCursor *c, const char *prefix);
>>   +int cursor_get_mono_bpl(QEMUCursor *c);
>>   +void cursor_set_mono(QEMUCursor *c,
>>   +                     uint32_t foreground, uint32_t background, uint8_t *image,
>>   +                     int transparent, uint8_t *mask);
>>   +void cursor_get_mono_image(QEMUCursor *c, int foreground, uint8_t *mask);
>>   +void cursor_get_mono_mask(QEMUCursor *c, int transparent, uint8_t *mask);
>>   +
>>    struct DisplayChangeListener {
>>       int idle;
>>       uint64_t gui_timer_interval;
>>   @@ -158,8 +179,7 @@ struct DisplayState {
>>       struct DisplayChangeListener* listeners;
>>
>>       void (*mouse_set)(int x, int y, int on);
>>   -    void (*cursor_define)(int width, int height, int bpp, int hot_x, int hot_y,
>>   -                          uint8_t *image, uint8_t *mask);
>>   +    void (*cursor_define)(QEMUCursor *cursor);
>>
>>       struct DisplayState *next;
>>    };
>>   diff --git a/cursor.c b/cursor.c
>>   new file mode 100644
>>   index 0000000..3995a31
>>   --- /dev/null
>>   +++ b/cursor.c
>>   @@ -0,0 +1,208 @@
>>   +#include "qemu-common.h"
>>   +#include "console.h"
>>   +
>>   +static const char cursor_hidden_32[32*32];
>>   +static const char cursor_left_ptr_32[32*32] = {
>>   +    "                                "
>>   +    " X                              "
>>   +    " XX                             "
>>   +    " X.X                            "
>>   +    " X..X                           "
>>   +    " X...X                          "
>>   +    " X....X                         "
>>   +    " X.....X                        "
>>   +    " X......X                       "
>>   +    " X.......X                      "
>>   +    " X........X                     "
>>   +    " X.....XXXXX                    "
>>   +    " X..X..X                        "
>>   +    " X.X X..X                       "
>>   +    " XX  X..X                       "
>>   +    " X    X..X                      "
>>   +    "      X..X                      "
>>   +    "       X..X                     "
>>   +    "       X..X                     "
>>   +    "        XX                      "
>>   +    "                                "
>>   +};
>
> Is this format standard? How about using X bitmap format instead:
> $ cat /usr/include/X11/bitmaps/left_ptr
> #define left_ptr_width 16
> #define left_ptr_height 16
> #define left_ptr_x_hot 3
> #define left_ptr_y_hot 1
> static char left_ptr_bits[] = {
>     0x00, 0x00, 0x08, 0x00, 0x18, 0x00, 0x38, 0x00, 0x78, 0x00, 0xf8, 0x00,
>     0xf8, 0x01, 0xf8, 0x03, 0xf8, 0x07, 0xf8, 0x00, 0xd8, 0x00, 0x88, 0x01,
>     0x80, 0x01, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00};
>
> Then there would be no need of parsing.

You would need _two_ bitmaps (e.g. mask and cursor, so that mask=1 gives 
transparent, mask=0 cursor=0 gives black and mask=0 cursor=1 gives white).

Paolo

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Qemu-devel] Re: [PATCH 1/3] cursor: add cursor functions.
  2010-05-07  7:05     ` [Qemu-devel] " Paolo Bonzini
@ 2010-05-07 15:23       ` Blue Swirl
  2010-05-19  8:16         ` Gerd Hoffmann
  0 siblings, 1 reply; 15+ messages in thread
From: Blue Swirl @ 2010-05-07 15:23 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: Gerd Hoffmann, qemu-devel

On 5/7/10, Paolo Bonzini <pbonzini@redhat.com> wrote:
> On 05/06/2010 08:12 PM, Blue Swirl wrote:
>
> > On 5/5/10, Gerd Hoffmann<kraxel@redhat.com>  wrote:
> >
> > > Add a new cursor type to console.h and a bunch of functions to
> > >  deal with cursors the (new) cursor.c file.
> > >
> > >  Signed-off-by: Gerd Hoffmann<kraxel@redhat.com>
> > >  ---
> > >   Makefile.objs |    3 +-
> > >   console.h     |   24 ++++++-
> > >   cursor.c      |  208
> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> > >   3 files changed, 232 insertions(+), 3 deletions(-)
> > >   create mode 100644 cursor.c
> > >
> > >  diff --git a/Makefile.objs b/Makefile.objs
> > >  index ecdd53e..1ee6e9d 100644
> > >  --- a/Makefile.objs
> > >  +++ b/Makefile.objs
> > >  @@ -48,7 +48,8 @@ common-obj-y = $(block-obj-y)
> > >   common-obj-y += $(net-obj-y)
> > >   common-obj-y += $(qobject-obj-y)
> > >   common-obj-$(CONFIG_LINUX) += $(fsdev-obj-$(CONFIG_LINUX))
> > >  -common-obj-y += readline.o console.o async.o qemu-error.o
> > >  +common-obj-y += readline.o console.o cursor.o async.o qemu-error.o
> > >  +
> > >   common-obj-y += tcg-runtime.o host-utils.o
> > >   common-obj-y += irq.o ioport.o input.o
> > >   common-obj-$(CONFIG_PTIMER) += ptimer.o
> > >  diff --git a/console.h b/console.h
> > >  index 6def115..88861cb 100644
> > >  --- a/console.h
> > >  +++ b/console.h
> > >  @@ -126,6 +126,27 @@ struct DisplaySurface {
> > >      struct PixelFormat pf;
> > >   };
> > >
> > >  +/* cursor data format is 32bit RGBA */
> > >  +typedef struct QEMUCursor {
> > >  +    int                 width, height;
> > >  +    int                 hot_x, hot_y;
> > >  +    int                 refcount;
> > >  +    uint32_t            data[];
> > >  +} QEMUCursor;
> > >  +
> > >  +QEMUCursor *cursor_alloc(int width, int height);
> > >  +void cursor_get(QEMUCursor *c);
> > >  +void cursor_put(QEMUCursor *c);
> > >  +QEMUCursor *cursor_builtin_hidden(void);
> > >  +QEMUCursor *cursor_builtin_left_ptr(void);
> > >  +void cursor_print_ascii_art(QEMUCursor *c, const char
> *prefix);
> > >  +int cursor_get_mono_bpl(QEMUCursor *c);
> > >  +void cursor_set_mono(QEMUCursor *c,
> > >  +                     uint32_t foreground, uint32_t background, uint8_t
> *image,
> > >  +                     int transparent, uint8_t *mask);
> > >  +void cursor_get_mono_image(QEMUCursor *c, int
> foreground, uint8_t *mask);
> > >  +void cursor_get_mono_mask(QEMUCursor *c, int
> transparent, uint8_t *mask);
> > >  +
> > >   struct DisplayChangeListener {
> > >      int idle;
> > >      uint64_t gui_timer_interval;
> > >  @@ -158,8 +179,7 @@ struct DisplayState {
> > >      struct DisplayChangeListener* listeners;
> > >
> > >      void (*mouse_set)(int x, int y, int on);
> > >  -    void (*cursor_define)(int width, int height, int bpp, int hot_x,
> int hot_y,
> > >  -                          uint8_t *image, uint8_t *mask);
> > >  +    void (*cursor_define)(QEMUCursor *cursor);
> > >
> > >      struct DisplayState *next;
> > >   };
> > >  diff --git a/cursor.c b/cursor.c
> > >  new file mode 100644
> > >  index 0000000..3995a31
> > >  --- /dev/null
> > >  +++ b/cursor.c
> > >  @@ -0,0 +1,208 @@
> > >  +#include "qemu-common.h"
> > >  +#include "console.h"
> > >  +
> > >  +static const char cursor_hidden_32[32*32];
> > >  +static const char cursor_left_ptr_32[32*32] = {
> > >  +    "                                "
> > >  +    " X                              "
> > >  +    " XX                             "
> > >  +    " X.X                            "
> > >  +    " X..X                           "
> > >  +    " X...X                          "
> > >  +    " X....X                         "
> > >  +    " X.....X                        "
> > >  +    " X......X                       "
> > >  +    " X.......X                      "
> > >  +    " X........X                     "
> > >  +    " X.....XXXXX                    "
> > >  +    " X..X..X                        "
> > >  +    " X.X X..X                       "
> > >  +    " XX  X..X                       "
> > >  +    " X    X..X                      "
> > >  +    "      X..X                      "
> > >  +    "       X..X                     "
> > >  +    "       X..X                     "
> > >  +    "        XX                      "
> > >  +    "                                "
> > >  +};
> > >
> >
> > Is this format standard? How about using X bitmap format instead:
> > $ cat /usr/include/X11/bitmaps/left_ptr
> > #define left_ptr_width 16
> > #define left_ptr_height 16
> > #define left_ptr_x_hot 3
> > #define left_ptr_y_hot 1
> > static char left_ptr_bits[] = {
> >    0x00, 0x00, 0x08, 0x00, 0x18, 0x00, 0x38, 0x00, 0x78, 0x00, 0xf8, 0x00,
> >    0xf8, 0x01, 0xf8, 0x03, 0xf8, 0x07, 0xf8, 0x00, 0xd8, 0x00, 0x88, 0x01,
> >    0x80, 0x01, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00};
> >
> > Then there would be no need of parsing.
> >
>
>  You would need _two_ bitmaps (e.g. mask and cursor, so that mask=1 gives
> transparent, mask=0 cursor=0 gives black and mask=0 cursor=1 gives white).

Yes, but it's still packed more efficiently.

There's yet another way:
#define _ 0,
#define X 0xff000000,
#define o 0xffffffff,
{
 _ _ _ X o X _ _ _
}
#undef _
#undef X
#undef o

This would not allow any drawing tool use, but there are no
conversions at startup.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Qemu-devel] Re: [PATCH 1/3] cursor: add cursor functions.
  2010-05-07 15:23       ` Blue Swirl
@ 2010-05-19  8:16         ` Gerd Hoffmann
  2010-05-19 18:57           ` Blue Swirl
  0 siblings, 1 reply; 15+ messages in thread
From: Gerd Hoffmann @ 2010-05-19  8:16 UTC (permalink / raw)
  To: Blue Swirl; +Cc: Paolo Bonzini, qemu-devel

>>> Then there would be no need of parsing.
>>
>>   You would need _two_ bitmaps (e.g. mask and cursor, so that mask=1 gives
>> transparent, mask=0 cursor=0 gives black and mask=0 cursor=1 gives white).
>
> Yes, but it's still packed more efficiently.

Well.  You can't have both.  We can have a efficiently packed format 
(i.e. two bitmaps).  Or we can do it in a way which doesn't need 
parsing, but that wouldn't be the most compact format ...

> There's yet another way:
> #define _ 0,
> #define X 0xff000000,
> #define o 0xffffffff,
> {
>   _ _ _ X o X _ _ _
> }
> #undef _
> #undef X
> #undef o

Neat idea ;)

cheers,
   Gerd

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Qemu-devel] Re: [PATCH 1/3] cursor: add cursor functions.
  2010-05-19  8:16         ` Gerd Hoffmann
@ 2010-05-19 18:57           ` Blue Swirl
  2010-05-19 19:08             ` Anthony Liguori
  0 siblings, 1 reply; 15+ messages in thread
From: Blue Swirl @ 2010-05-19 18:57 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: Paolo Bonzini, qemu-devel

On 5/19/10, Gerd Hoffmann <kraxel@redhat.com> wrote:
> >
> > >
> > > > Then there would be no need of parsing.
> > > >
> > >
> > >  You would need _two_ bitmaps (e.g. mask and cursor, so that mask=1
> gives
> > > transparent, mask=0 cursor=0 gives black and mask=0 cursor=1 gives
> white).
> > >
> >
> > Yes, but it's still packed more efficiently.
> >
>
>  Well.  You can't have both.  We can have a efficiently packed format (i.e.
> two bitmaps).  Or we can do it in a way which doesn't need parsing, but that
> wouldn't be the most compact format ...

You're right, so packing or introducing a small conversion function is
not critical. I'd still prefer a standard format if possible.

> > There's yet another way:
> > #define _ 0,
> > #define X 0xff000000,
> > #define o 0xffffffff,
> > {
> >  _ _ _ X o X _ _ _
> > }
> > #undef _
> > #undef X
> > #undef o
> >
>
>  Neat idea ;)
>
>  cheers,
>   Gerd
>
>

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] Re: [PATCH 1/3] cursor: add cursor functions.
  2010-05-19 18:57           ` Blue Swirl
@ 2010-05-19 19:08             ` Anthony Liguori
  2010-05-20 12:49               ` Gerd Hoffmann
  0 siblings, 1 reply; 15+ messages in thread
From: Anthony Liguori @ 2010-05-19 19:08 UTC (permalink / raw)
  To: Blue Swirl; +Cc: Paolo Bonzini, Gerd Hoffmann, qemu-devel

On 05/19/2010 01:57 PM, Blue Swirl wrote:
> On 5/19/10, Gerd Hoffmann<kraxel@redhat.com>  wrote:
>    
>>>        
>>>>          
>>>>> Then there would be no need of parsing.
>>>>>
>>>>>            
>>>>   You would need _two_ bitmaps (e.g. mask and cursor, so that mask=1
>>>>          
>> gives
>>      
>>>> transparent, mask=0 cursor=0 gives black and mask=0 cursor=1 gives
>>>>          
>> white).
>>      
>>>>          
>>> Yes, but it's still packed more efficiently.
>>>
>>>        
>>   Well.  You can't have both.  We can have a efficiently packed format (i.e.
>> two bitmaps).  Or we can do it in a way which doesn't need parsing, but that
>> wouldn't be the most compact format ...
>>      
> You're right, so packing or introducing a small conversion function is
> not critical. I'd still prefer a standard format if possible.
>    

Personally, I'd rather see Gerd's original format but read from a file 
instead of hard coded in a .c file.  IOW, a 
/usr/share/qemu/default-cursor.qpm that contained the appropriate 
strings.  A couple extra lines that made it an xpm I think would be 
worth it too.

Regards,

Anthony Liguori

>>> There's yet another way:
>>> #define _ 0,
>>> #define X 0xff000000,
>>> #define o 0xffffffff,
>>> {
>>>   _ _ _ X o X _ _ _
>>> }
>>> #undef _
>>> #undef X
>>> #undef o
>>>
>>>        
>>   Neat idea ;)
>>
>>   cheers,
>>    Gerd
>>
>>
>>      
>    

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] Re: [PATCH 1/3] cursor: add cursor functions.
  2010-05-19 19:08             ` Anthony Liguori
@ 2010-05-20 12:49               ` Gerd Hoffmann
  2010-05-20 13:17                 ` Anthony Liguori
  0 siblings, 1 reply; 15+ messages in thread
From: Gerd Hoffmann @ 2010-05-20 12:49 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: Blue Swirl, Paolo Bonzini, qemu-devel

[-- Attachment #1: Type: text/plain, Size: 1005 bytes --]

   Hi,

>>> Well. You can't have both. We can have a efficiently packed format (i.e.
>>> two bitmaps). Or we can do it in a way which doesn't need parsing,
>>> but that
>>> wouldn't be the most compact format ...
>> You're right, so packing or introducing a small conversion function is
>> not critical. I'd still prefer a standard format if possible.
>
> Personally, I'd rather see Gerd's original format but read from a file
> instead of hard coded in a .c file. IOW, a
> /usr/share/qemu/default-cursor.qpm that contained the appropriate
> strings. A couple extra lines that made it an xpm I think would be worth
> it too.

xpms are designed to be easily #include-able, and parsing them that way 
is easier than loading them at runtime.  At least without adding a 
dependency to libXpm.

So how about the following incremental RfC patch?  It adds the cursors 
as separate files which are standard xpm format.  Nevertheless they are 
compiled in, i.e. they can't be changed at runtime.

cheers,
   Gerd


[-- Attachment #2: 0001-cursor-switch-to-xpm.patch --]
[-- Type: text/plain, Size: 7423 bytes --]

From 7066e5a759ec887191601e6a96deab59a1dda721 Mon Sep 17 00:00:00 2001
From: Gerd Hoffmann <kraxel@redhat.com>
Date: Thu, 20 May 2010 14:39:26 +0200
Subject: [PATCH] cursor: switch to xpm

---
 cursor.c            |   94 ++++++++++++++++++++++++++-------------------------
 cursor_hidden.xpm   |   37 ++++++++++++++++++++
 cursor_left_ptr.xpm |   39 +++++++++++++++++++++
 3 files changed, 124 insertions(+), 46 deletions(-)
 create mode 100644 cursor_hidden.xpm
 create mode 100644 cursor_left_ptr.xpm

diff --git a/cursor.c b/cursor.c
index 3995a31..dfb9eef 100644
--- a/cursor.c
+++ b/cursor.c
@@ -1,51 +1,57 @@
 #include "qemu-common.h"
 #include "console.h"
 
-static const char cursor_hidden_32[32*32];
-static const char cursor_left_ptr_32[32*32] = {
-    "                                "
-    " X                              "
-    " XX                             "
-    " X.X                            "
-    " X..X                           "
-    " X...X                          "
-    " X....X                         "
-    " X.....X                        "
-    " X......X                       "
-    " X.......X                      "
-    " X........X                     "
-    " X.....XXXXX                    "
-    " X..X..X                        "
-    " X.X X..X                       "
-    " XX  X..X                       "
-    " X    X..X                      "
-    "      X..X                      "
-    "       X..X                     "
-    "       X..X                     "
-    "        XX                      "
-    "                                "
-};
+#include "cursor_hidden.xpm"
+#include "cursor_left_ptr.xpm"
 
 /* for creating built-in cursors */
-static void cursor_parse_ascii_art(QEMUCursor *c, const char *ptr)
+static QEMUCursor *cursor_parse_xpm(const char *xpm[])
 {
-    int i, pixels;
-
-    pixels = c->width * c->height;
-    for (i = 0; i < pixels; i++) {
-        switch (ptr[i]) {
-        case 'X': /* black */
-            c->data[i] = 0xff000000;
-            break;
-        case '.': /* white */
-            c->data[i] = 0xffffffff;
-            break;
-        case ' ': /* transparent */
-        default:
-            c->data[i] = 0x00000000;
-            break;
+    QEMUCursor *c;
+    uint32_t ctab[128];
+    unsigned int width, height, colors, chars;
+    unsigned int line = 0, i, r, g, b, x, y, pixel;
+    char name[16];
+    uint8_t idx;
+
+    /* parse header line: width, height, #colors, #chars */
+    if (sscanf(xpm[line], "%d %d %d %d", &width, &height, &colors, &chars) != 4) {
+        fprintf(stderr, "%s: header parse error: \"%s\"\n",
+                __FUNCTION__, xpm[line]);
+        return NULL;
+    }
+    if (chars != 1) {
+        fprintf(stderr, "%s: chars != 1 not supported\n", __FUNCTION__);
+        return NULL;
+    }
+    line++;
+
+    /* parse color table */
+    for (i = 0; i < colors; i++, line++) {
+        if (sscanf(xpm[line], "%c c %15s", &idx, name) == 2) {
+            if (sscanf(name, "#%02x%02x%02x", &r, &g, &b) == 3) {
+                ctab[idx] = (0xff << 24) | (b << 16) | (g << 8) | r;
+                continue;
+            }
+            if (strcmp(name, "None") == 0) {
+                ctab[idx] = 0x00000000;
+                continue;
+            }
         }
+        fprintf(stderr, "%s: color parse error: \"%s\"\n",
+                __FUNCTION__, xpm[line]);
+        return NULL;
     }
+
+    /* parse pixel data */
+    c = cursor_alloc(width, height);
+    for (pixel = 0, y = 0; y < height; y++, line++) {
+        for (x = 0; x < height; x++, pixel++) {
+            idx = xpm[line][x];
+            c->data[pixel] = ctab[idx];
+        }
+    }
+    return c;
 }
 
 /* nice for debugging */
@@ -75,8 +81,7 @@ QEMUCursor *cursor_builtin_hidden(void)
 {
     QEMUCursor *c;
 
-    c = cursor_alloc(32, 32);
-    cursor_parse_ascii_art(c, cursor_hidden_32);
+    c = cursor_parse_xpm(cursor_hidden_xpm);
     return c;
 }
 
@@ -84,10 +89,7 @@ QEMUCursor *cursor_builtin_left_ptr(void)
 {
     QEMUCursor *c;
 
-    c = cursor_alloc(32, 32);
-    cursor_parse_ascii_art(c, cursor_left_ptr_32);
-    c->hot_x = 1;
-    c->hot_y = 1;
+    c = cursor_parse_xpm(cursor_left_ptr_xpm);
     return c;
 }
 
diff --git a/cursor_hidden.xpm b/cursor_hidden.xpm
new file mode 100644
index 0000000..354e7a9
--- /dev/null
+++ b/cursor_hidden.xpm
@@ -0,0 +1,37 @@
+/* XPM */
+static const char *cursor_hidden_xpm[] = {
+    "32 32 1 1",
+    "  c None",
+    "                                ",
+    "                                ",
+    "                                ",
+    "                                ",
+    "                                ",
+    "                                ",
+    "                                ",
+    "                                ",
+    "                                ",
+    "                                ",
+    "                                ",
+    "                                ",
+    "                                ",
+    "                                ",
+    "                                ",
+    "                                ",
+    "                                ",
+    "                                ",
+    "                                ",
+    "                                ",
+    "                                ",
+    "                                ",
+    "                                ",
+    "                                ",
+    "                                ",
+    "                                ",
+    "                                ",
+    "                                ",
+    "                                ",
+    "                                ",
+    "                                ",
+    "                                ",
+};
diff --git a/cursor_left_ptr.xpm b/cursor_left_ptr.xpm
new file mode 100644
index 0000000..6c9ada9
--- /dev/null
+++ b/cursor_left_ptr.xpm
@@ -0,0 +1,39 @@
+/* XPM */
+static const char *cursor_left_ptr_xpm[] = {
+    "32 32 3 1",
+    "X c #000000",
+    ". c #ffffff",
+    "  c None",
+    "X                               ",
+    "XX                              ",
+    "X.X                             ",
+    "X..X                            ",
+    "X...X                           ",
+    "X....X                          ",
+    "X.....X                         ",
+    "X......X                        ",
+    "X.......X                       ",
+    "X........X                      ",
+    "X.....XXXXX                     ",
+    "X..X..X                         ",
+    "X.X X..X                        ",
+    "XX  X..X                        ",
+    "X    X..X                       ",
+    "     X..X                       ",
+    "      X..X                      ",
+    "      X..X                      ",
+    "       XX                       ",
+    "                                ",
+    "                                ",
+    "                                ",
+    "                                ",
+    "                                ",
+    "                                ",
+    "                                ",
+    "                                ",
+    "                                ",
+    "                                ",
+    "                                ",
+    "                                ",
+    "                                ",
+};
-- 
1.6.6.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [Qemu-devel] Re: [PATCH 1/3] cursor: add cursor functions.
  2010-05-20 12:49               ` Gerd Hoffmann
@ 2010-05-20 13:17                 ` Anthony Liguori
  0 siblings, 0 replies; 15+ messages in thread
From: Anthony Liguori @ 2010-05-20 13:17 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: Blue Swirl, Paolo Bonzini, qemu-devel

On 05/20/2010 07:49 AM, Gerd Hoffmann wrote:
>   Hi,
>
>>>> Well. You can't have both. We can have a efficiently packed format 
>>>> (i.e.
>>>> two bitmaps). Or we can do it in a way which doesn't need parsing,
>>>> but that
>>>> wouldn't be the most compact format ...
>>> You're right, so packing or introducing a small conversion function is
>>> not critical. I'd still prefer a standard format if possible.
>>
>> Personally, I'd rather see Gerd's original format but read from a file
>> instead of hard coded in a .c file. IOW, a
>> /usr/share/qemu/default-cursor.qpm that contained the appropriate
>> strings. A couple extra lines that made it an xpm I think would be worth
>> it too.
>
> xpms are designed to be easily #include-able, and parsing them that 
> way is easier than loading them at runtime.  At least without adding a 
> dependency to libXpm.
>
> So how about the following incremental RfC patch?  It adds the cursors 
> as separate files which are standard xpm format.  Nevertheless they 
> are compiled in, i.e. they can't be changed at runtime.

That works for me.   Nice job.

Regards,

Anthony Liguori

> cheers,
>   Gerd
>

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Qemu-devel] [PATCH 3/3] vnc: rich cursor support.
  2010-05-21  9:54 [Qemu-devel] [PATCH 0/3] cursor patches Gerd Hoffmann
@ 2010-05-21  9:54 ` Gerd Hoffmann
  0 siblings, 0 replies; 15+ messages in thread
From: Gerd Hoffmann @ 2010-05-21  9:54 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

Uses VNC_ENCODING_RICH_CURSOR.  Adding XCURSOR support should be
possible without much trouble.  Shouldn't be needed though as
RICH_CURSOR is a superset of XCURSOR.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 vnc.c        |   70 +++++++++++++++++++++++++++++++++++++++++++++++++++------
 vnc.h        |    8 +++++-
 vnchextile.h |    7 +++--
 3 files changed, 73 insertions(+), 12 deletions(-)

diff --git a/vnc.c b/vnc.c
index 1f7ad73..11ae3e5 100644
--- a/vnc.c
+++ b/vnc.c
@@ -49,6 +49,8 @@
 static VncDisplay *vnc_display; /* needed for info vnc */
 static DisplayChangeListener *dcl;
 
+static int vnc_cursor_define(VncState *vs);
+
 static char *addr_to_string(const char *format,
                             struct sockaddr_storage *sa,
                             socklen_t salen) {
@@ -549,12 +551,16 @@ static void vnc_dpy_resize(DisplayState *ds)
                 vnc_flush(vs);
             }
         }
+        if (vs->vd->cursor) {
+            vnc_cursor_define(vs);
+        }
         memset(vs->dirty, 0xFF, sizeof(vs->dirty));
     }
 }
 
 /* fastest code */
-static void vnc_write_pixels_copy(VncState *vs, void *pixels, int size)
+static void vnc_write_pixels_copy(VncState *vs, struct PixelFormat *pf,
+                                  void *pixels, int size)
 {
     vnc_write(vs, pixels, size);
 }
@@ -604,12 +610,12 @@ void vnc_convert_pixel(VncState *vs, uint8_t *buf, uint32_t v)
     }
 }
 
-static void vnc_write_pixels_generic(VncState *vs, void *pixels1, int size)
+static void vnc_write_pixels_generic(VncState *vs, struct PixelFormat *pf,
+                                     void *pixels1, int size)
 {
     uint8_t buf[4];
-    VncDisplay *vd = vs->vd;
 
-    if (vd->server->pf.bytes_per_pixel == 4) {
+    if (pf->bytes_per_pixel == 4) {
         uint32_t *pixels = pixels1;
         int n, i;
         n = size >> 2;
@@ -617,7 +623,7 @@ static void vnc_write_pixels_generic(VncState *vs, void *pixels1, int size)
             vnc_convert_pixel(vs, buf, pixels[i]);
             vnc_write(vs, buf, vs->clientds.pf.bytes_per_pixel);
         }
-    } else if (vd->server->pf.bytes_per_pixel == 2) {
+    } else if (pf->bytes_per_pixel == 2) {
         uint16_t *pixels = pixels1;
         int n, i;
         n = size >> 1;
@@ -625,7 +631,7 @@ static void vnc_write_pixels_generic(VncState *vs, void *pixels1, int size)
             vnc_convert_pixel(vs, buf, pixels[i]);
             vnc_write(vs, buf, vs->clientds.pf.bytes_per_pixel);
         }
-    } else if (vd->server->pf.bytes_per_pixel == 1) {
+    } else if (pf->bytes_per_pixel == 1) {
         uint8_t *pixels = pixels1;
         int n, i;
         n = size;
@@ -646,7 +652,7 @@ void vnc_raw_send_framebuffer_update(VncState *vs, int x, int y, int w, int h)
 
     row = vd->server->data + y * ds_get_linesize(vs->ds) + x * ds_get_bytes_per_pixel(vs->ds);
     for (i = 0; i < h; i++) {
-        vs->write_pixels(vs, row, w * ds_get_bytes_per_pixel(vs->ds));
+        vs->write_pixels(vs, &vd->server->pf, row, w * ds_get_bytes_per_pixel(vs->ds));
         row += ds_get_linesize(vs->ds);
     }
 }
@@ -752,6 +758,50 @@ static void vnc_dpy_copy(DisplayState *ds, int src_x, int src_y, int dst_x, int
     }
 }
 
+static void vnc_mouse_set(int x, int y, int visible)
+{
+    /* can we ask the client(s) to move the pointer ??? */
+}
+
+static int vnc_cursor_define(VncState *vs)
+{
+    QEMUCursor *c = vs->vd->cursor;
+    PixelFormat pf = qemu_default_pixelformat(32);
+    int isize;
+
+    if (vnc_has_feature(vs, VNC_FEATURE_RICH_CURSOR)) {
+        vnc_write_u8(vs,  VNC_MSG_SERVER_FRAMEBUFFER_UPDATE);
+        vnc_write_u8(vs,  0);  /*  padding     */
+        vnc_write_u16(vs, 1);  /*  # of rects  */
+        vnc_framebuffer_update(vs, c->hot_x, c->hot_y, c->width, c->height,
+                               VNC_ENCODING_RICH_CURSOR);
+        isize = c->width * c->height * vs->clientds.pf.bytes_per_pixel;
+        vnc_write_pixels_generic(vs, &pf, c->data, isize);
+        vnc_write(vs, vs->vd->cursor_mask, vs->vd->cursor_msize);
+        return 0;
+    }
+    return -1;
+}
+
+static void vnc_dpy_cursor_define(QEMUCursor *c)
+{
+    VncDisplay *vd = vnc_display;
+    VncState *vs;
+
+    cursor_put(vd->cursor);
+    qemu_free(vd->cursor_mask);
+
+    vd->cursor = c;
+    cursor_get(vd->cursor);
+    vd->cursor_msize = cursor_get_mono_bpl(c) * c->height;
+    vd->cursor_mask = qemu_mallocz(vd->cursor_msize);
+    cursor_get_mono_mask(c, 0, vd->cursor_mask);
+
+    QTAILQ_FOREACH(vs, &vd->clients, next) {
+        vnc_cursor_define(vs);
+    }
+}
+
 static int find_and_clear_dirty_height(struct VncState *vs,
                                        int y, int last_x, int x)
 {
@@ -1628,6 +1678,9 @@ static void set_encodings(VncState *vs, int32_t *encodings, size_t n_encodings)
         case VNC_ENCODING_POINTER_TYPE_CHANGE:
             vs->features |= VNC_FEATURE_POINTER_TYPE_CHANGE_MASK;
             break;
+        case VNC_ENCODING_RICH_CURSOR:
+            vs->features |= VNC_FEATURE_RICH_CURSOR_MASK;
+            break;
         case VNC_ENCODING_EXT_KEY_EVENT:
             send_ext_key_event_ack(vs);
             break;
@@ -1648,7 +1701,6 @@ static void set_encodings(VncState *vs, int32_t *encodings, size_t n_encodings)
             break;
         }
     }
-
     check_pointer_type_change(&vs->mouse_mode_notifier);
 }
 
@@ -2294,6 +2346,8 @@ void vnc_display_init(DisplayState *ds)
     dcl->dpy_resize = vnc_dpy_resize;
     dcl->dpy_setdata = vnc_dpy_setdata;
     register_displaychangelistener(ds, dcl);
+    ds->mouse_set = vnc_mouse_set;
+    ds->cursor_define = vnc_dpy_cursor_define;
 }
 
 
diff --git a/vnc.h b/vnc.h
index 1aa71b0..0d39897 100644
--- a/vnc.h
+++ b/vnc.h
@@ -61,7 +61,7 @@ typedef struct VncState VncState;
 
 typedef int VncReadEvent(VncState *vs, uint8_t *data, size_t len);
 
-typedef void VncWritePixels(VncState *vs, void *data, int size);
+typedef void VncWritePixels(VncState *vs, struct PixelFormat *pf, void *data, int size);
 
 typedef void VncSendHextileTile(VncState *vs,
                                 int x, int y, int w, int h,
@@ -101,6 +101,10 @@ struct VncDisplay
     kbd_layout_t *kbd_layout;
     int lock_key_sync;
 
+    QEMUCursor *cursor;
+    int cursor_msize;
+    uint8_t *cursor_mask;
+
     struct VncSurface guest;   /* guest visible surface (aka ds->surface) */
     DisplaySurface *server;  /* vnc server surface */
 
@@ -273,6 +277,7 @@ enum {
 #define VNC_FEATURE_TIGHT                    4
 #define VNC_FEATURE_ZLIB                     5
 #define VNC_FEATURE_COPYRECT                 6
+#define VNC_FEATURE_RICH_CURSOR              7
 
 #define VNC_FEATURE_RESIZE_MASK              (1 << VNC_FEATURE_RESIZE)
 #define VNC_FEATURE_HEXTILE_MASK             (1 << VNC_FEATURE_HEXTILE)
@@ -281,6 +286,7 @@ enum {
 #define VNC_FEATURE_TIGHT_MASK               (1 << VNC_FEATURE_TIGHT)
 #define VNC_FEATURE_ZLIB_MASK                (1 << VNC_FEATURE_ZLIB)
 #define VNC_FEATURE_COPYRECT_MASK            (1 << VNC_FEATURE_COPYRECT)
+#define VNC_FEATURE_RICH_CURSOR_MASK         (1 << VNC_FEATURE_RICH_CURSOR)
 
 
 /* Client -> Server message IDs */
diff --git a/vnchextile.h b/vnchextile.h
index 78ed8c4..b9f9f5e 100644
--- a/vnchextile.h
+++ b/vnchextile.h
@@ -189,16 +189,17 @@ static void CONCAT(send_hextile_tile_, NAME)(VncState *vs,
     vnc_write_u8(vs, flags);
     if (n_colors < 4) {
 	if (flags & 0x02)
-	    vs->write_pixels(vs, last_bg, sizeof(pixel_t));
+	    vs->write_pixels(vs, &vd->server->pf, last_bg, sizeof(pixel_t));
 	if (flags & 0x04)
-	    vs->write_pixels(vs, last_fg, sizeof(pixel_t));
+	    vs->write_pixels(vs, &vd->server->pf, last_fg, sizeof(pixel_t));
 	if (n_subtiles) {
 	    vnc_write_u8(vs, n_subtiles);
 	    vnc_write(vs, data, n_data);
 	}
     } else {
 	for (j = 0; j < h; j++) {
-	    vs->write_pixels(vs, row, w * ds_get_bytes_per_pixel(vs->ds));
+	    vs->write_pixels(vs, &vd->server->pf, row,
+                             w * ds_get_bytes_per_pixel(vs->ds));
 	    row += ds_get_linesize(vs->ds);
 	}
     }
-- 
1.6.6.1

^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2010-05-21  9:54 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-05 12:51 [Qemu-devel] [PATCH 0/3] local cursor patches Gerd Hoffmann
2010-05-05 12:51 ` [Qemu-devel] [PATCH 1/3] cursor: add cursor functions Gerd Hoffmann
2010-05-06 18:12   ` Blue Swirl
2010-05-06 19:27     ` Gerd Hoffmann
2010-05-06 19:42       ` Blue Swirl
2010-05-07  7:05     ` [Qemu-devel] " Paolo Bonzini
2010-05-07 15:23       ` Blue Swirl
2010-05-19  8:16         ` Gerd Hoffmann
2010-05-19 18:57           ` Blue Swirl
2010-05-19 19:08             ` Anthony Liguori
2010-05-20 12:49               ` Gerd Hoffmann
2010-05-20 13:17                 ` Anthony Liguori
2010-05-05 12:51 ` [Qemu-devel] [PATCH 2/3] use new cursor struct + functions for vmware vga and sdl Gerd Hoffmann
2010-05-05 12:51 ` [Qemu-devel] [PATCH 3/3] vnc: rich cursor support Gerd Hoffmann
  -- strict thread matches above, loose matches on Subject: below --
2010-05-21  9:54 [Qemu-devel] [PATCH 0/3] cursor patches Gerd Hoffmann
2010-05-21  9:54 ` [Qemu-devel] [PATCH 3/3] vnc: rich cursor support Gerd Hoffmann

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).