Skip to contentSkip to conversation

vnc: adapative tight, zrle, zywrle, and bitmap module

PATCH Applied Corentin Chary 7 participants 27 messages Feb 4, 2011 – Feb 25, 2011 Kbuild

lore
Share & tools
lore
#0 lore raw

v3 cover vnc: adapative tight, zrle, zywrle, and bitmap module

From: Corentin Chary <[email protected]>

Hi,

Since v2:
- Fixed some styles issues
- Rebased to current master
- Fixed a Makefile issue (using .c instead of .o)

I rebased the series against current master, it contains:

- Adaptive Tight Encoding: send lossy or lossless updates depending on the update frequency of the screen region. If a lossy update is forced, then it will be refreshed with a lossless update as soon as the update frequency goes back to 0.

- ZRLE/ZYWRLE Encodings: ZYWRLE use less bandwidth than tight, but the result is also probably more lossy. I wanted to make ZRLE/ZYWRLE adaptive, but this is not possible because most of the vnc clients can't switch between ZRLE and ZYWRLE. But a possible solution is to use another encoding for lossless updates, like zlib or tight.

- Bitmap module: create bitmap.h and bitops.h, and remove duplicate code from vnc.c

It was my last series from GSoC 2010 context, if necessary I can send different series for adaptive vnc, zrle and bitmap stuff.

Thanks,

Corentin Chary (16):
vnc: qemu can die if the client is disconnected while updating screen
vnc: don't set the quality if lossy encoding are disabled
vnc: add a way to get the update frequency for a given region
vnc: refresh lossy rect after a given timeout
vnc: tight: use the update frequency to choose between lossy and
lossless
vnc: palette: use a pool to reduce memory allocations
vnc: palette: add palette_init calls
vnc: palette: and fill and color calls.
vnc: Add ZRLE and ZYWRLE encodings.
vnc: fix uint8_t comparisons with negative values
vnc: fix lossy rect refreshing
bitmap: add a generic bitmap and bitops library
vnc: use the new generic bitmap functions
vnc: don't try to send bigger updates that client height
vnc: tight: tweak adaptive tight settings
vnc: add a non-adaptive option

 Makefile.objs                |    2 +
 bitmap.c                     |  256 ++++++++++++++++
 bitmap.h                     |  222 ++++++++++++++
 bitops.c                     |  142 +++++++++
 bitops.h                     |  272 +++++++++++++++++
 osdep.h                      |    4 +
 qemu-options.hx              |    9 +
 ui/vnc-enc-tight.c           |   75 ++++-
 ui/vnc-enc-zrle-template.c   |  263 +++++++++++++++++
 ui/vnc-enc-zrle.c            |  366 +++++++++++++++++++++++
 ui/vnc-enc-zrle.h            |   40 +++
 ui/vnc-enc-zywrle-template.c |  170 +++++++++++
 ui/vnc-enc-zywrle.h          |  659 ++++++++++++++++++++++++++++++++++++++++++
 ui/vnc-jobs-async.c          |    8 +
 ui/vnc-palette.c             |   58 +++-
 ui/vnc-palette.h             |    7 +-
 ui/vnc.c                     |  283 ++++++++++++++-----
 ui/vnc.h                     |   57 ++++-
 18 files changed, 2786 insertions(+), 107 deletions(-)
 create mode 100644 bitmap.c
 create mode 100644 bitmap.h
 create mode 100644 bitops.c
 create mode 100644 bitops.h
 create mode 100644 ui/vnc-enc-zrle-template.c
 create mode 100644 ui/vnc-enc-zrle.c
 create mode 100644 ui/vnc-enc-zrle.h
 create mode 100644 ui/vnc-enc-zywrle-template.c
 create mode 100644 ui/vnc-enc-zywrle.h
Signature · 1 line
1.7.3.4
#1 lore raw

PATCH v3 1/16 vnc: qemu can die if the client is disconnected while updating screen

agraf reported that qemu_mutex_destroy(vs->output_mutex) while failing in vnc_disconnect_finish().

It's because vnc_worker_thread_loop() tries to unlock the mutex while not locked. The unlocking call doesn't fail (pthread bug ?), but the destroy call does.

---
 ui/vnc-jobs-async.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
ui/vnc-jobs-async.c +4 -0
index 6e9cf08..0b5d750 100644
@@ -227,6 +227,10 @@ static int vnc_worker_thread_loop(VncJobQueue *queue)
 
         if (job->vs->csock == -1) {
             vnc_unlock_display(job->vs->vd);
+            /* output mutex must be locked before going to
+             * disconnected:
+             */
+            vnc_lock_output(job->vs);
             goto disconnected;
         }
 
Signature · 1 line
1.7.3.4
#2 lore raw

Re: [Qemu-devel] [PATCH v3 01/16] vnc: qemu can die if the client is disconnected while updating screen

Quoted 9 lines · Corentin Chary

agraf reported that qemu_mutex_destroy(vs->output_mutex) while failing in vnc_disconnect_finish().

It's because vnc_worker_thread_loop() tries to unlock the mutex while not locked. The unlocking call doesn't fail (pthread bug ?), but the destroy call does.

Applied (just this patch) to master, Thanks.

Regards,

Anthony Liguori

Quoted 20 lines
---
  ui/vnc-jobs-async.c |    4 ++++
  1 files changed, 4 insertions(+), 0 deletions(-)
ui/vnc-jobs-async.c +4 -0
index 6e9cf08..0b5d750 100644
@@ -227,6 +227,10 @@ static int vnc_worker_thread_loop(VncJobQueue *queue)
 
          if (job->vs->csock == -1) {
              vnc_unlock_display(job->vs->vd);
+            /* output mutex must be locked before going to
+             * disconnected:
+             */
+            vnc_lock_output(job->vs);
              goto disconnected;
          }
 
#3 lore raw

Re: [Qemu-devel] [PATCH v3 01/16] vnc: qemu can die if the client is disconnected while updating screen

Quoted 4 lines · Anthony Liguori
Quoted 3 lines · Corentin Chary

agraf reported that qemu_mutex_destroy(vs->output_mutex) while failing in vnc_disconnect_finish().

Quoted 8 lines
Quoted 6 lines

It's because vnc_worker_thread_loop() tries to unlock the mutex while not locked. The unlocking call doesn't fail (pthread bug ?), but the destroy call does.

Applied (just this patch) to master, Thanks.

What about the others?

Alex

#4 lore raw

Re: [Qemu-devel] [PATCH v3 01/16] vnc: qemu can die if the client is disconnected while updating screen

In reply to Corentin Chary
Quoted 9 lines · Corentin Chary

agraf reported that qemu_mutex_destroy(vs->output_mutex) while failing in vnc_disconnect_finish().

It's because vnc_worker_thread_loop() tries to unlock the mutex while not locked. The unlocking call doesn't fail (pthread bug ?), but the destroy call does.

Applied 2/16. Thanks!

Regards,

Anthony Liguori

Quoted 20 lines
---
  ui/vnc-jobs-async.c |    4 ++++
  1 files changed, 4 insertions(+), 0 deletions(-)
ui/vnc-jobs-async.c +4 -0
index 6e9cf08..0b5d750 100644
@@ -227,6 +227,10 @@ static int vnc_worker_thread_loop(VncJobQueue *queue)
 
          if (job->vs->csock == -1) {
              vnc_unlock_display(job->vs->vd);
+            /* output mutex must be locked before going to
+             * disconnected:
+             */
+            vnc_lock_output(job->vs);
              goto disconnected;
          }
 
#5 lore raw

Re: [Qemu-devel] [PATCH v3 01/16] vnc: qemu can die if the client is disconnected while updating screen

Quoted 9 lines · Anthony Liguori
Quoted 8 lines · Corentin Chary

agraf reported that qemu_mutex_destroy(vs->output_mutex) while failing in vnc_disconnect_finish().

It's because vnc_worker_thread_loop() tries to unlock the mutex while not locked. The unlocking call doesn't fail (pthread bug ?), but the destroy call does.

Quoted 8 lines
Quoted 2 lines

Applied 2/16.  Thanks!

Regards,

Anthony Liguori

Great, Thanks !

Please also merge these two patchs:
http://patchwork.ozlabs.org/patch/84517/
http://patchwork.ozlabs.org/patch/84496/

Signature · 2 lines
Corentin Chary
http://xf.iksaif.net
#6 lore raw

PATCH v3 2/16 vnc: don't set the quality if lossy encoding are disabled

In reply to Corentin Chary

This should not change the current behavior, but if any new encoding try to use the tight quality, it will always be set to -1 when lossy encodings are disabled.

---
 ui/vnc.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
ui/vnc.c +3 -1
index 560b98d..9c5c5b3 100644
@@ -1780,7 +1780,9 @@ static void set_encodings(VncState *vs, int32_t *encodings, size_t n_encodings)
             vs->tight.compression = (enc & 0x0F);
             break;
         case VNC_ENCODING_QUALITYLEVEL0 ... VNC_ENCODING_QUALITYLEVEL0 + 9:
-            vs->tight.quality = (enc & 0x0F);
+            if (vs->vd->lossy) {
+                vs->tight.quality = (enc & 0x0F);
+            }
             break;
         default:
             VNC_DEBUG("Unknown encoding: %d (0x%.8x): %d\n", i, enc, enc);
Signature · 1 line
1.7.3.4
#7 lore raw

PATCH v3 3/16 vnc: add a way to get the update frequency for a given region

In reply to Corentin Chary

This patch compute the update frequency (in Hz) for each 64x64 rects. Any adaptive encoding can get this value using vnc_update_freq(), and switch to a lossy encoding if the value is too high.

The frequency is pre-calculated every 500ms, based on the last 10 updates per 64x64 rect.

If a 64x64 rect was not updated in the last 2 second, then the frequency became 0, and all the stored timestamp are reseted.

---
 ui/vnc.c |  101 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 ui/vnc.h |   19 +++++++++++
 2 files changed, 120 insertions(+), 0 deletions(-)
ui/vnc.c +101 -0
index 9c5c5b3..6eacd1d 100644
@@ -35,6 +35,8 @@
 #define VNC_REFRESH_INTERVAL_BASE 30
 #define VNC_REFRESH_INTERVAL_INC  50
 #define VNC_REFRESH_INTERVAL_MAX  2000
+static const struct timeval VNC_REFRESH_STATS = { 0, 500000 };
+static const struct timeval VNC_REFRESH_LOSSY = { 2, 0 };
 
 #include "vnc_keysym.h"
 #include "d3des.h"
@@ -2258,6 +2260,99 @@ static int protocol_version(VncState *vs, uint8_t *version, size_t len)
     return 0;
 }
 
+static VncRectStat *vnc_stat_rect(VncDisplay *vd, int x, int y)
+{
+    struct VncSurface *vs = &vd->guest;
+
+    return &vs->stats[y / VNC_STAT_RECT][x / VNC_STAT_RECT];
+}
+
+static void vnc_update_stats(VncDisplay *vd,  struct timeval * tv)
+{
+    int x, y;
+    struct timeval res;
+
+    for (y = 0; y < vd->guest.ds->height; y += VNC_STAT_RECT) {
+        for (x = 0; x < vd->guest.ds->width; x += VNC_STAT_RECT) {
+            VncRectStat *rect = vnc_stat_rect(vd, x, y);
+
+            rect->updated = false;
+        }
+    }
+
+    timersub(tv, &VNC_REFRESH_STATS, &res);
+
+    if (timercmp(&vd->guest.last_freq_check, &res, >)) {
+        return ;
+    }
+    vd->guest.last_freq_check = *tv;
+
+    for (y = 0; y < vd->guest.ds->height; y += VNC_STAT_RECT) {
+        for (x = 0; x < vd->guest.ds->width; x += VNC_STAT_RECT) {
+            VncRectStat *rect= vnc_stat_rect(vd, x, y);
+            int count = ARRAY_SIZE(rect->times);
+            struct timeval min, max;
+
+            if (!timerisset(&rect->times[count - 1])) {
+                continue ;
+            }
+
+            max = rect->times[(rect->idx + count - 1) % count];
+            timersub(tv, &max, &res);
+
+            if (timercmp(&res, &VNC_REFRESH_LOSSY, >)) {
+                rect->freq = 0;
+                memset(rect->times, 0, sizeof (rect->times));
+                continue ;
+            }
+
+            min = rect->times[rect->idx];
+            max = rect->times[(rect->idx + count - 1) % count];
+            timersub(&max, &min, &res);
+
+            rect->freq = res.tv_sec + res.tv_usec / 1000000.;
+            rect->freq /= count;
+            rect->freq = 1. / rect->freq;
+        }
+    }
+}
+
+double vnc_update_freq(VncState *vs, int x, int y, int w, int h)
+{
+    int i, j;
+    double total = 0;
+    int num = 0;
+
+    x =  (x / VNC_STAT_RECT) * VNC_STAT_RECT;
+    y =  (y / VNC_STAT_RECT) * VNC_STAT_RECT;
+
+    for (j = y; j <= y + h; j += VNC_STAT_RECT) {
+        for (i = x; i <= x + w; i += VNC_STAT_RECT) {
+            total += vnc_stat_rect(vs->vd, i, j)->freq;
+            num++;
+        }
+    }
+
+    if (num) {
+        return total / num;
+    } else {
+        return 0;
+    }
+}
+
+static void vnc_rect_updated(VncDisplay *vd, int x, int y, struct timeval * tv)
+{
+    VncRectStat *rect;
+
+    rect = vnc_stat_rect(vd, x, y);
+    if (rect->updated) {
+        return ;
+    }
+    rect->times[rect->idx] = *tv;
+    rect->idx = (rect->idx + 1) % ARRAY_SIZE(rect->times);
+    rect->updated = true;
+}
+
 static int vnc_refresh_server_surface(VncDisplay *vd)
 {
     int y;
@@ -2268,6 +2363,11 @@ static int vnc_refresh_server_surface(VncDisplay *vd)
     VncState *vs;
     int has_dirty = 0;
 
+    struct timeval tv;
+
+    gettimeofday(&tv, NULL);
+    vnc_update_stats(vd, &tv);
+
     /*
      * Walk through the guest dirty map.
      * Check and copy modified bits from guest to server surface.
@@ -2294,6 +2394,7 @@ static int vnc_refresh_server_surface(VncDisplay *vd)
                 if (memcmp(server_ptr, guest_ptr, cmp_bytes) == 0)
                     continue;
                 memcpy(server_ptr, guest_ptr, cmp_bytes);
+                vnc_rect_updated(vd, x, y, &tv);
                 QTAILQ_FOREACH(vs, &vd->clients, next) {
                     vnc_set_bit(vs->dirty[y], (x / 16));
                 }
ui/vnc.h +19 -0
index 4f895be..c0e5ff3 100644
@@ -80,6 +80,10 @@ typedef void VncSendHextileTile(VncState *vs,
 #define VNC_MAX_HEIGHT 2048
 #define VNC_DIRTY_WORDS (VNC_MAX_WIDTH / (16 * 32))
 
+#define VNC_STAT_RECT  64
+#define VNC_STAT_COLS (VNC_MAX_WIDTH / VNC_STAT_RECT)
+#define VNC_STAT_ROWS (VNC_MAX_HEIGHT / VNC_STAT_RECT)
+
 #define VNC_AUTH_CHALLENGE_SIZE 16
 
 typedef struct VncDisplay VncDisplay;
@@ -92,9 +96,23 @@ typedef struct VncDisplay VncDisplay;
 #include "vnc-auth-sasl.h"
 #endif
 
+struct VncRectStat
+{
+    /* time of last 10 updates, to find update frequency */
+    struct timeval times[10];
+    int idx;
+
+    double freq;        /* Update frequency (in Hz) */
+    bool updated;       /* Already updated during this refresh */
+};
+
+typedef struct VncRectStat VncRectStat;
+
 struct VncSurface
 {
+    struct timeval last_freq_check;
     uint32_t dirty[VNC_MAX_HEIGHT][VNC_DIRTY_WORDS];
+    VncRectStat stats[VNC_STAT_ROWS][VNC_STAT_COLS];
     DisplaySurface *ds;
 };
 
@@ -479,6 +497,7 @@ void vnc_framebuffer_update(VncState *vs, int x, int y, int w, int h,
                             int32_t encoding);
 
 void vnc_convert_pixel(VncState *vs, uint8_t *buf, uint32_t v);
+double vnc_update_freq(VncState *vs, int x, int y, int w, int h);
 
 /* Encodings */
 int vnc_send_framebuffer_update(VncState *vs, int x, int y, int w, int h);
Signature · 1 line
1.7.3.4
#8 lore raw

PATCH v3 4/16 vnc: refresh lossy rect after a given timeout

In reply to Corentin Chary

If an adaptive encoding has choosen to send a lossy update based on the result of vnc_update_freq(), then it should advertise it with vnc_sent_lossy_rect(). This will allow to automatically refresh this rect once it's static again.

---
 ui/vnc-jobs-async.c |    2 +
 ui/vnc.c            |   67 ++++++++++++++++++++++++++++++++++++++++++++++++--
 ui/vnc.h            |    3 ++
 3 files changed, 69 insertions(+), 3 deletions(-)
ui/vnc-jobs-async.c +2 -0
index 0b5d750..bfe8e86 100644
@@ -166,6 +166,7 @@ static void vnc_async_encoding_start(VncState *orig, VncState *local)
     local->features = orig->features;
     local->ds = orig->ds;
     local->vd = orig->vd;
+    local->lossy_rect = orig->lossy_rect;
     local->write_pixels = orig->write_pixels;
     local->clientds = orig->clientds;
     local->tight = orig->tight;
@@ -182,6 +183,7 @@ static void vnc_async_encoding_end(VncState *orig, VncState *local)
     orig->tight = local->tight;
     orig->zlib = local->zlib;
     orig->hextile = local->hextile;
+    orig->lossy_rect = local->lossy_rect;
 }
 
 static int vnc_worker_thread_loop(VncJobQueue *queue)
ui/vnc.c +64 -3

119 lines not on this page · raw message

ui/vnc.h +3 -0
index c0e5ff3..57835f1 100644
@@ -217,6 +217,8 @@ struct VncState
 
     DisplayState *ds;
     uint32_t dirty[VNC_MAX_HEIGHT][VNC_DIRTY_WORDS];
+    uint8_t **lossy_rect; /* Not an Array to avoid costly memcpy in
+                           * vnc-jobs-async.c */
 
     VncDisplay *vd;
     int need_update;
@@ -498,6 +500,7 @@ void vnc_framebuffer_update(VncState *vs, int x, int y, int w, int h,
 
 void vnc_convert_pixel(VncState *vs, uint8_t *buf, uint32_t v);
 double vnc_update_freq(VncState *vs, int x, int y, int w, int h);
+void vnc_sent_lossy_rect(VncState *vs, int x, int y, int w, int h);
 
 /* Encodings */
 int vnc_send_framebuffer_update(VncState *vs, int x, int y, int w, int h);
Signature · 1 line
1.7.3.4
#9 lore raw

PATCH v3 5/16 vnc: tight: use the update frequency to choose between lossy and lossless

In reply to Corentin Chary

Use the new update frequency infrastructure to use jpeg for regions with high update frequency.

---
 ui/vnc-enc-tight.c |   75 +++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 62 insertions(+), 13 deletions(-)
ui/vnc-enc-tight.c +62 -13
index af45edd..ad9a9a8 100644
@@ -72,6 +72,26 @@ static const struct {
 static int tight_send_framebuffer_update(VncState *vs, int x, int y,
                                          int w, int h);
 
+#ifdef CONFIG_VNC_JPEG
+static const struct {
+    double jpeg_freq_min;       /* Don't send JPEG if the freq is bellow */
+    double jpeg_freq_threshold; /* Always send JPEG if the freq is above */
+    int jpeg_idx;               /* Allow indexed JPEG */
+    int jpeg_full;              /* Allow full color JPEG */
+} tight_jpeg_conf[] = {
+    { 0,   4,  1, 1 },
+    { 0,   4,  1, 1 },
+    { 0,   4,  1, 1 },
+    { 0,   4,  1, 1 },
+    { 0,   4,  0, 1 },
+    { 0.1, 4,  0, 1 },
+    { 0.2, 4,  0, 1 },
+    { 0.3, 6,  0, 0 },
+    { 0.4, 8,  0, 0 },
+    { 0.5, 10, 0, 0 },
+};
+#endif
+
 #ifdef CONFIG_VNC_PNG
 static const struct {
     int png_zlib_level, png_filters;
@@ -1476,12 +1496,13 @@ static int send_sub_rect_nojpeg(VncState *vs, int x, int y, int w, int h,
 #ifdef CONFIG_VNC_JPEG
 static int send_sub_rect_jpeg(VncState *vs, int x, int y, int w, int h,
                               int bg, int fg, int colors,
-                              VncPalette *palette)
+                              VncPalette *palette, bool force)
 {
     int ret;
 
     if (colors == 0) {
-        if (tight_detect_smooth_image(vs, w, h)) {
+        if (force || (tight_jpeg_conf[vs->tight.quality].jpeg_full &&
+                      tight_detect_smooth_image(vs, w, h))) {
             int quality = tight_conf[vs->tight.quality].jpeg_quality;
 
             ret = send_jpeg_rect(vs, x, y, w, h, quality);
@@ -1493,8 +1514,9 @@ static int send_sub_rect_jpeg(VncState *vs, int x, int y, int w, int h,
     } else if (colors == 2) {
         ret = send_mono_rect(vs, x, y, w, h, bg, fg);
     } else if (colors <= 256) {
-        if (colors > 96 &&
-            tight_detect_smooth_image(vs, w, h)) {
+        if (force || (colors > 96 &&
+                      tight_jpeg_conf[vs->tight.quality].jpeg_idx &&
+                      tight_detect_smooth_image(vs, w, h))) {
             int quality = tight_conf[vs->tight.quality].jpeg_quality;
 
             ret = send_jpeg_rect(vs, x, y, w, h, quality);
@@ -1514,6 +1536,8 @@ static int send_sub_rect(VncState *vs, int x, int y, int w, int h)
     uint32_t bg = 0, fg = 0;
     int colors;
     int ret = 0;
+    bool force_jpeg = false;
+    bool allow_jpeg = true;
 
     vnc_framebuffer_update(vs, x, y, w, h, vs->tight.type);
 
@@ -1521,11 +1545,26 @@ static int send_sub_rect(VncState *vs, int x, int y, int w, int h)
     vnc_raw_send_framebuffer_update(vs, x, y, w, h);
     vnc_tight_stop(vs);
 
+#ifdef CONFIG_VNC_JPEG
+    if (vs->tight.quality != -1) {
+        double freq = vnc_update_freq(vs, x, y, w, h);
+
+        if (freq < tight_jpeg_conf[vs->tight.quality].jpeg_freq_min) {
+            allow_jpeg = false;
+        }
+        if (freq >= tight_jpeg_conf[vs->tight.quality].jpeg_freq_threshold) {
+            force_jpeg = true;
+            vnc_sent_lossy_rect(vs, x, y, w, h);
+        }
+    }
+#endif
+
     colors = tight_fill_palette(vs, x, y, w * h, &fg, &bg, &palette);
 
 #ifdef CONFIG_VNC_JPEG
-    if (vs->tight.quality != (uint8_t)-1) {
-        ret = send_sub_rect_jpeg(vs, x, y, w, h, bg, fg, colors, palette);
+    if (allow_jpeg && vs->tight.quality != (uint8_t)-1) {
+        ret = send_sub_rect_jpeg(vs, x, y, w, h, bg, fg, colors, palette,
+                                 force_jpeg);
     } else {
         ret = send_sub_rect_nojpeg(vs, x, y, w, h, bg, fg, colors, palette);
     }
@@ -1548,7 +1587,8 @@ static int send_sub_rect_solid(VncState *vs, int x, int y, int w, int h)
     return send_solid_rect(vs);
 }
 
-static int send_rect_simple(VncState *vs, int x, int y, int w, int h)
+static int send_rect_simple(VncState *vs, int x, int y, int w, int h,
+                            bool split)
 {
     int max_size, max_width;
     int max_sub_width, max_sub_height;
@@ -1559,7 +1599,7 @@ static int send_rect_simple(VncState *vs, int x, int y, int w, int h)
     max_size = tight_conf[vs->tight.compression].max_rect_size;
     max_width = tight_conf[vs->tight.compression].max_rect_width;
 
-    if (w > max_width || w * h > max_size) {
+    if (split && (w > max_width || w * h > max_size)) {
         max_sub_width = (w > max_width) ? max_width : w;
         max_sub_height = max_size / max_sub_width;
 
@@ -1590,7 +1630,7 @@ static int find_large_solid_color_rect(VncState *vs, int x, int y,
         /* If a rectangle becomes too large, send its upper part now. */
 
         if (dy - y >= max_rows) {
-            n += send_rect_simple(vs, x, y, w, max_rows);
+            n += send_rect_simple(vs, x, y, w, max_rows, true);
             y += max_rows;
             h -= max_rows;
         }
@@ -1629,7 +1669,7 @@ static int find_large_solid_color_rect(VncState *vs, int x, int y,
             /* Send rectangles at top and left to solid-color area. */
 
             if (y_best != y) {
-                n += send_rect_simple(vs, x, y, w, y_best-y);
+                n += send_rect_simple(vs, x, y, w, y_best-y, true);
             }
             if (x_best != x) {
                 n += tight_send_framebuffer_update(vs, x, y_best,
@@ -1656,7 +1696,7 @@ static int find_large_solid_color_rect(VncState *vs, int x, int y,
             return n;
         }
     }
-    return n + send_rect_simple(vs, x, y, w, h);
+    return n + send_rect_simple(vs, x, y, w, h, true);
 }
 
 static int tight_send_framebuffer_update(VncState *vs, int x, int y,
@@ -1671,8 +1711,17 @@ static int tight_send_framebuffer_update(VncState *vs, int x, int y,
         vs->tight.pixel24 = false;
     }
 
-    if (w * h < VNC_TIGHT_MIN_SPLIT_RECT_SIZE)
-        return send_rect_simple(vs, x, y, w, h);
+    if (vs->tight.quality != -1) {
+        double freq = vnc_update_freq(vs, x, y, w, h);
+
+        if (freq > tight_jpeg_conf[vs->tight.quality].jpeg_freq_threshold) {
+            return send_rect_simple(vs, x, y, w, h, false);
+        }
+    }
+
+    if (w * h < VNC_TIGHT_MIN_SPLIT_RECT_SIZE) {
+        return send_rect_simple(vs, x, y, w, h, true);
+    }
 
     /* Calculate maximum number of rows in one non-solid rectangle. */
 
Signature · 1 line
1.7.3.4
#10 lore raw

Re: [Qemu-devel] [PATCH v3 05/16] vnc: tight: use the update frequency to choose between lossy and lossless

ui/vnc-enc-tight.c static int send_sub_rect(VncState *vs, int x, int y, int w, int h) · line 1542

Quoted 13 lines · Corentin Chary

Use the new update frequency infrastructure to use jpeg for regions with high update frequency.

ui/vnc-enc-tight.c +2 -0
@@ -1514,6 +1536,8 @@ static int send_sub_rect(VncState *vs, int x, int y, int w, int h)
     uint32_t bg = 0, fg = 0;
     int colors;
     int ret = 0;
+    bool force_jpeg = false;
+    bool allow_jpeg = true;
 
     vnc_framebuffer_update(vs, x, y, w, h, vs->tight.type);

This (ie git master, since this has been committed) doesn't compile if CONFIG_VNC_JPEG isn't defined:

cam-vm-266:maverick:qemu$ make
CC ui/vnc-enc-tight.o
cc1: warnings being treated as errors ui/vnc-enc-tight.c: In function ‘send_sub_rect’:
ui/vnc-enc-tight.c:1540: error: unused variable ‘allow_jpeg’ ui/vnc-enc-tight.c:1539: error: unused variable ‘force_jpeg’ ui/vnc-enc-tight.c: In function ‘tight_send_framebuffer_update’:
ui/vnc-enc-tight.c:1717: error: ‘tight_jpeg_conf’ undeclared (first use in this function)
ui/vnc-enc-tight.c:1717: error: (Each undeclared identifier is reported only once
ui/vnc-enc-tight.c:1717: error: for each function it appears in.)
make: *** [ui/vnc-enc-tight.o] Error 1

-- PMM

#11 lore raw

PATCH v3 6/16 vnc: palette: use a pool to reduce memory allocations

In reply to Corentin Chary

We now that the palette will never have more than 256 elements. Let's use a pool to reduce malloc calls.

---
 ui/vnc-palette.c |   18 ++----------------
 ui/vnc-palette.h |    3 ++-
 2 files changed, 4 insertions(+), 17 deletions(-)
ui/vnc-palette.c +2 -16
index bff6445..c47420b 100644
@@ -63,23 +63,9 @@ VncPalette *palette_new(size_t max, int bpp)
 
 void palette_destroy(VncPalette *palette)
 {
-    int i;
-
     if (palette == NULL) {
-        return ;
+        qemu_free(palette);
     }
-
-    for (i = 0; i < VNC_PALETTE_HASH_SIZE; i++) {
-        VncPaletteEntry *entry = QLIST_FIRST(&palette->table[i]);
-        while (entry) {
-            VncPaletteEntry *tmp = QLIST_NEXT(entry, next);
-            QLIST_REMOVE(entry, next);
-            qemu_free(entry);
-            entry = tmp;
-        }
-    }
-
-    qemu_free(palette);
 }
 
 int palette_put(VncPalette *palette, uint32_t color)
@@ -97,7 +83,7 @@ int palette_put(VncPalette *palette, uint32_t color)
     if (!entry) {
         VncPaletteEntry *entry;
 
-        entry = qemu_mallocz(sizeof(*entry));
+        entry = &palette->pool[palette->size];
         entry->color = color;
         entry->idx = idx;
         QLIST_INSERT_HEAD(&palette->table[hash], entry, next);
ui/vnc-palette.h +2 -1
index d0645eb..f57d0e7 100644
@@ -34,6 +34,7 @@
 #include <stdint.h>
 
 #define VNC_PALETTE_HASH_SIZE 256
+#define VNC_PALETTE_MAX_SIZE  256
 
 typedef struct VncPaletteEntry {
     int idx;
@@ -42,7 +43,7 @@ typedef struct VncPaletteEntry {
 } VncPaletteEntry;
 
 typedef struct VncPalette {
-    QObject_HEAD;
+    VncPaletteEntry pool[VNC_PALETTE_MAX_SIZE];
     size_t size;
     size_t max;
     int bpp;
Signature · 1 line
1.7.3.4
#12 lore raw

PATCH v3 7/16 vnc: palette: add palette_init calls

In reply to Corentin Chary

This allow to use palette on the stack instead of always allocating them.

---
 ui/vnc-palette.c |    8 +++++++-
 ui/vnc-palette.h |    1 +
 2 files changed, 8 insertions(+), 1 deletions(-)
ui/vnc-palette.c +7 -1
index c47420b..f93250b 100644
@@ -56,9 +56,15 @@ VncPalette *palette_new(size_t max, int bpp)
     VncPalette *palette;
 
     palette = qemu_mallocz(sizeof(*palette));
+    palette_init(palette, max, bpp);
+    return palette;
+}
+
+void palette_init(VncPalette *palette, size_t max, int bpp)
+{
+    memset(palette, 0, sizeof (*palette));
     palette->max = max;
     palette->bpp = bpp;
-    return palette;
 }
 
 void palette_destroy(VncPalette *palette)
ui/vnc-palette.h +1 -0
index f57d0e7..c646e4d 100644
@@ -51,6 +51,7 @@ typedef struct VncPalette {
 } VncPalette;
 
 VncPalette *palette_new(size_t max, int bpp);
+void palette_init(VncPalette *palette, size_t max, int bpp);
 void palette_destroy(VncPalette *palette);
 
 int palette_put(VncPalette *palette, uint32_t color);
Signature · 1 line
1.7.3.4
#13 lore raw

PATCH v3 8/16 vnc: palette: and fill and color calls.

In reply to Corentin Chary

These two helpers are needed for zrle and zywrle.

---
 ui/vnc-palette.c |   32 ++++++++++++++++++++++++++++++++
 ui/vnc-palette.h |    3 +++
 2 files changed, 35 insertions(+), 0 deletions(-)
ui/vnc-palette.c +32 -0
index f93250b..c478060 100644
@@ -126,3 +126,35 @@ void palette_iter(const VncPalette *palette,
         }
     }
 }
+
+uint32_t palette_color(const VncPalette *palette, int idx, bool *found)
+{
+    int i;
+    VncPaletteEntry *entry;
+
+    for (i = 0; i < VNC_PALETTE_HASH_SIZE; i++) {
+        QLIST_FOREACH(entry, &palette->table[i], next) {
+            if (entry->idx == idx) {
+                *found = true;
+                return entry->color;
+            }
+        }
+    }
+
+    *found = false;
+    return -1;
+}
+
+static void palette_fill_cb(int idx, uint32_t color, void *opaque)
+{
+    uint32_t *colors = opaque;
+
+    colors[idx] = color;
+}
+
+size_t palette_fill(const VncPalette *palette,
+                    uint32_t colors[VNC_PALETTE_MAX_SIZE])
+{
+    palette_iter(palette, palette_fill_cb, colors);
+    return palette_size(palette);
+}
ui/vnc-palette.h +3 -0
index c646e4d..3260885 100644
@@ -61,5 +61,8 @@ size_t palette_size(const VncPalette *palette);
 void palette_iter(const VncPalette *palette,
                   void (*iter)(int idx, uint32_t color, void *opaque),
                   void *opaque);
+uint32_t palette_color(const VncPalette *palette, int idx, bool *found);
+size_t palette_fill(const VncPalette *palette,
+                    uint32_t colors[VNC_PALETTE_MAX_SIZE]);
 
 #endif /* VNC_PALETTE_H */
Signature · 1 line
1.7.3.4
#14 lore raw

PATCH v3 9/16 vnc: Add ZRLE and ZYWRLE encodings.

In reply to Corentin Chary

Add ZRLE [1] and ZYWRLE [2] encodings. The code is inspire^W stolen from libvncserver (again), but have been rewriten to match QEMU coding style.

[1] http://www.realvnc.com/docs/rfbproto.pdf
[2] http://micro-vnc.jp/research/remote_desktop_ng/ZYWRLE/publications/

---
 Makefile.objs                |    1 +
 ui/vnc-enc-zrle-template.c   |  263 +++++++++++++++++
 ui/vnc-enc-zrle.c            |  365 +++++++++++++++++++++++
 ui/vnc-enc-zrle.h            |   40 +++
 ui/vnc-enc-zywrle-template.c |  170 +++++++++++
 ui/vnc-enc-zywrle.h          |  659 ++++++++++++++++++++++++++++++++++++++++++
 ui/vnc-jobs-async.c          |    2 +
 ui/vnc.c                     |   15 +
 ui/vnc.h                     |   27 ++-
 9 files changed, 1541 insertions(+), 1 deletions(-)
 create mode 100644 ui/vnc-enc-zrle-template.c
 create mode 100644 ui/vnc-enc-zrle.c
 create mode 100644 ui/vnc-enc-zrle.h
 create mode 100644 ui/vnc-enc-zywrle-template.c
 create mode 100644 ui/vnc-enc-zywrle.h
Makefile.objs +1 -0
index f1c7bfe..9691875 100644
@@ -129,6 +129,7 @@ ui-obj-$(CONFIG_CURSES) += curses.o
 ui-obj-y += vnc.o d3des.o
 ui-obj-y += vnc-enc-zlib.o vnc-enc-hextile.o
 ui-obj-y += vnc-enc-tight.o vnc-palette.o
+ui-obj-y += vnc-enc-zrle.o
 ui-obj-$(CONFIG_VNC_TLS) += vnc-tls.o vnc-auth-vencrypt.o
 ui-obj-$(CONFIG_VNC_SASL) += vnc-auth-sasl.o
 ui-obj-$(CONFIG_COCOA) += cocoa.o
ui/vnc-enc-zrle-template.c new file +263 -0

263 lines not on this page · raw message

ui/vnc-enc-zrle.c new file +365 -0

365 lines not on this page · raw message

ui/vnc-enc-zrle.h new file +40 -0
new file mode 100644
index 0000000..6b18213
@@ -0,0 +1,40 @@
+/*
+ * QEMU VNC display driver: Zlib Run-length Encoding (ZRLE)
+ *
+ * From libvncserver/libvncserver/zrle.c
+ * Copyright (C) 2002 RealVNC Ltd.  All Rights Reserved.
+ * Copyright (C) 2003 Sun Microsystems, Inc.
+ *
+ * Copyright (C) 2010 Corentin Chary <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef VNC_ENCODING_ZRLE_H
+#define VNC_ENCODING_ZRLE_H
+
+/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+ * ZRLE - encoding combining Zlib compression, tiling, palettisation and
+ * run-length encoding.
+ */
+
+#define VNC_ZRLE_TILE_WIDTH  64
+#define VNC_ZRLE_TILE_HEIGHT 64
+
+#endif
ui/vnc-enc-zywrle-template.c new file +170 -0

170 lines not on this page · raw message

ui/vnc-enc-zywrle.h new file +659 -0

659 lines not on this page · raw message

ui/vnc-jobs-async.c +2 -0
index bfe8e86..1d4c5e7 100644
@@ -172,6 +172,7 @@ static void vnc_async_encoding_start(VncState *orig, VncState *local)
     local->tight = orig->tight;
     local->zlib = orig->zlib;
     local->hextile = orig->hextile;
+    local->zrle = orig->zrle;
     local->output =  queue->buffer;
     local->csock = -1; /* Don't do any network work on this thread */
 
@@ -183,6 +184,7 @@ static void vnc_async_encoding_end(VncState *orig, VncState *local)
     orig->tight = local->tight;
     orig->zlib = local->zlib;
     orig->hextile = local->hextile;
+    orig->zrle = local->zrle;
     orig->lossy_rect = local->lossy_rect;
 }
 
ui/vnc.c +15 -0
index 697b836..9920c0e 100644
@@ -696,6 +696,12 @@ int vnc_send_framebuffer_update(VncState *vs, int x, int y, int w, int h)
         case VNC_ENCODING_TIGHT_PNG:
             n = vnc_tight_png_send_framebuffer_update(vs, x, y, w, h);
             break;
+        case VNC_ENCODING_ZRLE:
+            n = vnc_zrle_send_framebuffer_update(vs, x, y, w, h);
+            break;
+        case VNC_ENCODING_ZYWRLE:
+            n = vnc_zywrle_send_framebuffer_update(vs, x, y, w, h);
+            break;
         default:
             vnc_framebuffer_update(vs, x, y, w, h, VNC_ENCODING_RAW);
             n = vnc_raw_send_framebuffer_update(vs, x, y, w, h);
@@ -1028,6 +1034,7 @@ static void vnc_disconnect_finish(VncState *vs)
 
     vnc_zlib_clear(vs);
     vnc_tight_clear(vs);
+    vnc_zrle_clear(vs);
 
 #ifdef CONFIG_VNC_TLS
     vnc_tls_client_cleanup(vs);
@@ -1766,6 +1773,14 @@ static void set_encodings(VncState *vs, int32_t *encodings, size_t n_encodings)
             vs->features |= VNC_FEATURE_ZLIB_MASK;
             vs->vnc_encoding = enc;
             break;
+        case VNC_ENCODING_ZRLE:
+            vs->features |= VNC_FEATURE_ZRLE_MASK;
+            vs->vnc_encoding = enc;
+            break;
+        case VNC_ENCODING_ZYWRLE:
+            vs->features |= VNC_FEATURE_ZYWRLE_MASK;
+            vs->vnc_encoding = enc;
+            break;
         case VNC_ENCODING_DESKTOPRESIZE:
             vs->features |= VNC_FEATURE_RESIZE_MASK;
             break;
ui/vnc.h +26 -1
index 57835f1..706ba3c 100644
@@ -39,6 +39,8 @@
 #include <stdbool.h>
 
 #include "keymaps.h"
+#include "vnc-palette.h"
+#include "vnc-enc-zrle.h"
 
 // #define _VNC_DEBUG 1
 
@@ -180,6 +182,20 @@ typedef struct VncZlib {
     int level;
 } VncZlib;
 
+typedef struct VncZrle {
+    int type;
+    Buffer fb;
+    Buffer zrle;
+    Buffer tmp;
+    Buffer zlib;
+    z_stream stream;
+    VncPalette palette;
+} VncZrle;
+
+typedef struct VncZywrle {
+    int buf[VNC_ZRLE_TILE_WIDTH * VNC_ZRLE_TILE_HEIGHT];
+} VncZywrle;
+
 #ifdef CONFIG_VNC_THREAD
 struct VncRect
 {
@@ -273,7 +289,8 @@ struct VncState
     VncTight tight;
     VncZlib zlib;
     VncHextile hextile;
-
+    VncZrle zrle;
+    VncZywrle zywrle;
 
     Notifier mouse_mode_notifier;
 
@@ -377,6 +394,8 @@ enum {
 #define VNC_FEATURE_COPYRECT                 6
 #define VNC_FEATURE_RICH_CURSOR              7
 #define VNC_FEATURE_TIGHT_PNG                8
+#define VNC_FEATURE_ZRLE                     9
+#define VNC_FEATURE_ZYWRLE                  10
 
 #define VNC_FEATURE_RESIZE_MASK              (1 << VNC_FEATURE_RESIZE)
 #define VNC_FEATURE_HEXTILE_MASK             (1 << VNC_FEATURE_HEXTILE)
@@ -387,6 +406,8 @@ enum {
 #define VNC_FEATURE_COPYRECT_MASK            (1 << VNC_FEATURE_COPYRECT)
 #define VNC_FEATURE_RICH_CURSOR_MASK         (1 << VNC_FEATURE_RICH_CURSOR)
 #define VNC_FEATURE_TIGHT_PNG_MASK           (1 << VNC_FEATURE_TIGHT_PNG)
+#define VNC_FEATURE_ZRLE_MASK                (1 << VNC_FEATURE_ZRLE)
+#define VNC_FEATURE_ZYWRLE_MASK              (1 << VNC_FEATURE_ZYWRLE)
 
 
 /* Client -> Server message IDs */
@@ -521,4 +542,8 @@ int vnc_tight_png_send_framebuffer_update(VncState *vs, int x, int y,
                                           int w, int h);
 void vnc_tight_clear(VncState *vs);
 
+int vnc_zrle_send_framebuffer_update(VncState *vs, int x, int y, int w, int h);
+int vnc_zywrle_send_framebuffer_update(VncState *vs, int x, int y, int w, int h);
+void vnc_zrle_clear(VncState *vs);
+
 #endif /* __QEMU_VNC_H */
Signature · 1 line
1.7.3.4
#15 lore raw

PATCH v3 10/16 vnc: fix uint8_t comparisons with negative values

In reply to Corentin Chary
---
 ui/vnc-enc-tight.c |    4 ++--
 ui/vnc-enc-zrle.c  |    3 ++-
 2 files changed, 4 insertions(+), 3 deletions(-)
ui/vnc-enc-tight.c +2 -2
index ad9a9a8..81024d5 100644
@@ -1546,7 +1546,7 @@ static int send_sub_rect(VncState *vs, int x, int y, int w, int h)
     vnc_tight_stop(vs);
 
 #ifdef CONFIG_VNC_JPEG
-    if (vs->tight.quality != -1) {
+    if (vs->tight.quality != (uint8_t)-1) {
         double freq = vnc_update_freq(vs, x, y, w, h);
 
         if (freq < tight_jpeg_conf[vs->tight.quality].jpeg_freq_min) {
@@ -1711,7 +1711,7 @@ static int tight_send_framebuffer_update(VncState *vs, int x, int y,
         vs->tight.pixel24 = false;
     }
 
-    if (vs->tight.quality != -1) {
+    if (vs->tight.quality != (uint8_t)-1) {
         double freq = vnc_update_freq(vs, x, y, w, h);
 
         if (freq > tight_jpeg_conf[vs->tight.quality].jpeg_freq_threshold) {
ui/vnc-enc-zrle.c +2 -1
index 016a406..917d384 100644
@@ -260,7 +260,8 @@ static int zrle_send_framebuffer_update(VncState *vs, int x, int y,
     int zywrle_level;
 
     if (vs->zrle.type == VNC_ENCODING_ZYWRLE) {
-        if (!vs->vd->lossy || vs->tight.quality < 0 || vs->tight.quality == 9) {
+        if (!vs->vd->lossy || vs->tight.quality == (uint8_t)-1
+            || vs->tight.quality == 9) {
             zywrle_level = 0;
             vs->zrle.type = VNC_ENCODING_ZRLE;
         } else if (vs->tight.quality < 3) {
Signature · 1 line
1.7.3.4
#16 lore raw

PATCH v3 11/16 vnc: fix lossy rect refreshing

In reply to Corentin Chary

The for loop in send_lossy_rect was totally wrong, and we can't call vnc_set_bits() because it does not really do what it should. Use vnc_set_bit() directly instead.

---
 ui/vnc.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)
ui/vnc.c +8 -4
index 9920c0e..8c7cb0d 100644
@@ -2297,8 +2297,8 @@ void vnc_sent_lossy_rect(VncState *vs, int x, int y, int w, int h)
     x /= VNC_STAT_RECT;
     y /= VNC_STAT_RECT;
 
-    for (j = y; j <= y + h; j++) {
-        for (i = x; i <= x + w; i++) {
+    for (j = y; j <= h; j++) {
+        for (i = x; i <= w; i++) {
             vs->lossy_rect[j][i] = 1;
         }
     }
@@ -2315,7 +2315,7 @@ static int vnc_refresh_lossy_rect(VncDisplay *vd, int x, int y)
     x = x / VNC_STAT_RECT * VNC_STAT_RECT;
 
     QTAILQ_FOREACH(vs, &vd->clients, next) {
-        int j;
+        int j, i;
 
         /* kernel send buffers are full -> refresh later */
         if (vs->output.offset) {
@@ -2325,12 +2325,16 @@ static int vnc_refresh_lossy_rect(VncDisplay *vd, int x, int y)
         if (!vs->lossy_rect[sty][stx]) {
             continue;
         }
+
         vs->lossy_rect[sty][stx] = 0;
         for (j = 0; j < VNC_STAT_RECT; ++j) {
-            vnc_set_bits(vs->dirty[y + j], x / 16, VNC_STAT_RECT / 16);
+            for (i = x / 16; i < VNC_STAT_RECT / 16 + x / 16; ++i) {
+                vnc_set_bit(vs->dirty[y + j], i);
+            }
         }
         has_dirty++;
     }
+
     return has_dirty;
 }
 
Signature · 1 line
1.7.3.4
#17 lore raw

PATCH v3 12/16 bitmap: add a generic bitmap and bitops library

In reply to Corentin Chary

Add most used bitmap and bitops functions into bitmap.c and bitops.c. Theses functions are mostly copied from Linux kernel source.

Some of these functions are already redefined in the VNC server. Some of them could be used for some block stuff. The yet yo be submitted NUMA work also need bitmaps.

bitops_ffsl() and bitops_flsl() are here because bitops/bitmap works on unsigned long, not int, and we can't use current code because:
* ffs only works on int
* qemu_fls only works on int
* ffsl is a GNU extension

---
 Makefile.objs |    1 +
 bitmap.c      |  256 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 bitmap.h      |  222 ++++++++++++++++++++++++++++++++++++++++++++++
 bitops.c      |  142 ++++++++++++++++++++++++++++++
 bitops.h      |  272 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 osdep.h       |    4 +
 6 files changed, 897 insertions(+), 0 deletions(-)
 create mode 100644 bitmap.c
 create mode 100644 bitmap.h
 create mode 100644 bitops.c
 create mode 100644 bitops.h
Makefile.objs +1 -0
index 9691875..a4a6450 100644
@@ -100,6 +100,7 @@ common-obj-y += msmouse.o ps2.o
 common-obj-y += qdev.o qdev-properties.o
 common-obj-y += block-migration.o
 common-obj-y += pflib.o
+common-obj-y += bitmap.o bitops.o
 
 common-obj-$(CONFIG_BRLAPI) += baum.o
 common-obj-$(CONFIG_POSIX) += migration-exec.o migration-unix.o migration-fd.o
bitmap.c new file +256 -0

256 lines not on this page · raw message

bitmap.h new file +222 -0

222 lines not on this page · raw message

bitops.c new file +142 -0

142 lines not on this page · raw message

bitops.h new file +272 -0

272 lines not on this page · raw message

osdep.h +4 -0
index 8bd30d7..27eedcf 100644
@@ -57,6 +57,10 @@
 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
 #endif
 
+#ifndef DIV_ROUND_UP
+#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
+#endif
+
 #ifndef ARRAY_SIZE
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
 #endif
Signature · 1 line
1.7.3.4
#18 lore raw

PATCH v3 13/16 vnc: use the new generic bitmap functions

In reply to Corentin Chary

Switch to bitmap.h and bitops.h instead of redefining our own bitmap helpers.

---
 ui/vnc.c |   91 ++++++++++++++-----------------------------------------------
 ui/vnc.h |    7 +++--
 2 files changed, 25 insertions(+), 73 deletions(-)
ui/vnc.c +21 -70
index 8c7cb0d..6c57b0e 100644
@@ -41,13 +41,6 @@ static const struct timeval VNC_REFRESH_LOSSY = { 2, 0 };
 #include "vnc_keysym.h"
 #include "d3des.h"
 
-#define count_bits(c, v) { \
-    for (c = 0; v; v >>= 1) \
-    { \
-        c += v & 1; \
-    } \
-}
-
 static VncDisplay *vnc_display; /* needed for info vnc */
 static DisplayChangeListener *dcl;
 
@@ -378,47 +371,6 @@ static void framebuffer_update_request(VncState *vs, int incremental,
 static void vnc_refresh(void *opaque);
 static int vnc_refresh_server_surface(VncDisplay *vd);
 
-static inline void vnc_set_bit(uint32_t *d, int k)
-{
-    d[k >> 5] |= 1 << (k & 0x1f);
-}
-
-static inline void vnc_clear_bit(uint32_t *d, int k)
-{
-    d[k >> 5] &= ~(1 << (k & 0x1f));
-}
-
-static inline void vnc_set_bits(uint32_t *d, int n, int nb_words)
-{
-    int j;
-
-    j = 0;
-    while (n >= 32) {
-        d[j++] = -1;
-        n -= 32;
-    }
-    if (n > 0)
-        d[j++] = (1 << n) - 1;
-    while (j < nb_words)
-        d[j++] = 0;
-}
-
-static inline int vnc_get_bit(const uint32_t *d, int k)
-{
-    return (d[k >> 5] >> (k & 0x1f)) & 1;
-}
-
-static inline int vnc_and_bits(const uint32_t *d1, const uint32_t *d2,
-                               int nb_words)
-{
-    int i;
-    for(i = 0; i < nb_words; i++) {
-        if ((d1[i] & d2[i]) != 0)
-            return 1;
-    }
-    return 0;
-}
-
 static void vnc_dpy_update(DisplayState *ds, int x, int y, int w, int h)
 {
     int i;
@@ -441,7 +393,7 @@ static void vnc_dpy_update(DisplayState *ds, int x, int y, int w, int h)
 
     for (; y < h; y++)
         for (i = 0; i < w; i += 16)
-            vnc_set_bit(s->dirty[y], (x + i) / 16);
+            set_bit((x + i) / 16, s->dirty[y]);
 }
 
 void vnc_framebuffer_update(VncState *vs, int x, int y, int w, int h,
@@ -780,7 +732,7 @@ static void vnc_dpy_copy(DisplayState *ds, int src_x, int src_y, int dst_x, int
             memmove(dst_row, src_row, cmp_bytes);
             QTAILQ_FOREACH(vs, &vd->clients, next) {
                 if (!vnc_has_feature(vs, VNC_FEATURE_COPYRECT)) {
-                    vnc_set_bit(vs->dirty[y], ((x + dst_x) / 16));
+                    set_bit(((x + dst_x) / 16), vs->dirty[y]);
                 }
             }
         }
@@ -850,10 +802,12 @@ static int find_and_clear_dirty_height(struct VncState *vs,
 
     for (h = 1; h < (vd->server->height - y); h++) {
         int tmp_x;
-        if (!vnc_get_bit(vs->dirty[y + h], last_x))
+        if (!test_bit(last_x, vs->dirty[y + h])) {
             break;
-        for (tmp_x = last_x; tmp_x < x; tmp_x++)
-            vnc_clear_bit(vs->dirty[y + h], tmp_x);
+        }
+        for (tmp_x = last_x; tmp_x < x; tmp_x++) {
+            clear_bit(tmp_x, vs->dirty[y + h]);
+        }
     }
 
     return h;
@@ -905,11 +859,10 @@ static int vnc_update_client(VncState *vs, int has_dirty)
             int x;
             int last_x = -1;
             for (x = 0; x < width / 16; x++) {
-                if (vnc_get_bit(vs->dirty[y], x)) {
+                if (test_and_clear_bit(x, vs->dirty[y])) {
                     if (last_x == -1) {
                         last_x = x;
                     }
-                    vnc_clear_bit(vs->dirty[y], x);
                 } else {
                     if (last_x != -1) {
                         int h = find_and_clear_dirty_height(vs, y, last_x, x);
@@ -1702,8 +1655,7 @@ static void framebuffer_update_request(VncState *vs, int incremental,
     if (!incremental) {
         vs->force_update = 1;
         for (i = 0; i < h; i++) {
-            vnc_set_bits(vs->dirty[y_position + i],
-                         (ds_get_width(vs->ds) / 16), VNC_DIRTY_WORDS);
+            bitmap_set(vs->dirty[y_position + i], x_position / 16, w / 16);
         }
     }
 }
@@ -1842,15 +1794,15 @@ static void set_pixel_format(VncState *vs,
 
     vs->clientds = *(vs->vd->guest.ds);
     vs->clientds.pf.rmax = red_max;
-    count_bits(vs->clientds.pf.rbits, red_max);
+    vs->clientds.pf.rbits = hweight_long(red_max);
     vs->clientds.pf.rshift = red_shift;
     vs->clientds.pf.rmask = red_max << red_shift;
     vs->clientds.pf.gmax = green_max;
-    count_bits(vs->clientds.pf.gbits, green_max);
+    vs->clientds.pf.gbits = hweight_long(green_max);
     vs->clientds.pf.gshift = green_shift;
     vs->clientds.pf.gmask = green_max << green_shift;
     vs->clientds.pf.bmax = blue_max;
-    count_bits(vs->clientds.pf.bbits, blue_max);
+    vs->clientds.pf.bbits = hweight_long(blue_max);
     vs->clientds.pf.bshift = blue_shift;
     vs->clientds.pf.bmask = blue_max << blue_shift;
     vs->clientds.pf.bits_per_pixel = bits_per_pixel;
@@ -2315,7 +2267,7 @@ static int vnc_refresh_lossy_rect(VncDisplay *vd, int x, int y)
     x = x / VNC_STAT_RECT * VNC_STAT_RECT;
 
     QTAILQ_FOREACH(vs, &vd->clients, next) {
-        int j, i;
+        int j;
 
         /* kernel send buffers are full -> refresh later */
         if (vs->output.offset) {
@@ -2328,9 +2280,7 @@ static int vnc_refresh_lossy_rect(VncDisplay *vd, int x, int y)
 
         vs->lossy_rect[sty][stx] = 0;
         for (j = 0; j < VNC_STAT_RECT; ++j) {
-            for (i = x / 16; i < VNC_STAT_RECT / 16 + x / 16; ++i) {
-                vnc_set_bit(vs->dirty[y + j], i);
-            }
+            bitmap_set(vs->dirty[y + j], x / 16, VNC_STAT_RECT / 16);
         }
         has_dirty++;
     }
@@ -2433,7 +2383,7 @@ static int vnc_refresh_server_surface(VncDisplay *vd)
     uint8_t *guest_row;
     uint8_t *server_row;
     int cmp_bytes;
-    uint32_t width_mask[VNC_DIRTY_WORDS];
+    unsigned long width_mask[VNC_DIRTY_WORDS];
     VncState *vs;
     int has_dirty = 0;
 
@@ -2447,12 +2397,14 @@ static int vnc_refresh_server_surface(VncDisplay *vd)
      * Check and copy modified bits from guest to server surface.
      * Update server dirty map.
      */
-    vnc_set_bits(width_mask, (ds_get_width(vd->ds) / 16), VNC_DIRTY_WORDS);
+    bitmap_set(width_mask, 0, (ds_get_width(vd->ds) / 16));
+    bitmap_clear(width_mask, (ds_get_width(vd->ds) / 16),
+                 VNC_DIRTY_WORDS * BITS_PER_LONG);
     cmp_bytes = 16 * ds_get_bytes_per_pixel(vd->ds);
     guest_row  = vd->guest.ds->data;
     server_row = vd->server->data;
     for (y = 0; y < vd->guest.ds->height; y++) {
-        if (vnc_and_bits(vd->guest.dirty[y], width_mask, VNC_DIRTY_WORDS)) {
+        if (bitmap_intersects(vd->guest.dirty[y], width_mask, VNC_DIRTY_WORDS)) {
             int x;
             uint8_t *guest_ptr;
             uint8_t *server_ptr;
@@ -2462,15 +2414,14 @@ static int vnc_refresh_server_surface(VncDisplay *vd)
 
             for (x = 0; x < vd->guest.ds->width;
                     x += 16, guest_ptr += cmp_bytes, server_ptr += cmp_bytes) {
-                if (!vnc_get_bit(vd->guest.dirty[y], (x / 16)))
+                if (!test_and_clear_bit((x / 16), vd->guest.dirty[y]))
                     continue;
-                vnc_clear_bit(vd->guest.dirty[y], (x / 16));
                 if (memcmp(server_ptr, guest_ptr, cmp_bytes) == 0)
                     continue;
                 memcpy(server_ptr, guest_ptr, cmp_bytes);
                 vnc_rect_updated(vd, x, y, &tv);
                 QTAILQ_FOREACH(vs, &vd->clients, next) {
-                    vnc_set_bit(vs->dirty[y], (x / 16));
+                    set_bit((x / 16), vs->dirty[y]);
                 }
                 has_dirty++;
             }
ui/vnc.h +4 -3
index 706ba3c..98a1885 100644
@@ -35,6 +35,7 @@
 #include "console.h"
 #include "monitor.h"
 #include "audio/audio.h"
+#include "bitmap.h"
 #include <zlib.h>
 #include <stdbool.h>
 
@@ -80,7 +81,7 @@ typedef void VncSendHextileTile(VncState *vs,
 
 #define VNC_MAX_WIDTH 2560
 #define VNC_MAX_HEIGHT 2048
-#define VNC_DIRTY_WORDS (VNC_MAX_WIDTH / (16 * 32))
+#define VNC_DIRTY_WORDS (VNC_MAX_WIDTH / (16 * BITS_PER_LONG))
 
 #define VNC_STAT_RECT  64
 #define VNC_STAT_COLS (VNC_MAX_WIDTH / VNC_STAT_RECT)
@@ -113,7 +114,7 @@ typedef struct VncRectStat VncRectStat;
 struct VncSurface
 {
     struct timeval last_freq_check;
-    uint32_t dirty[VNC_MAX_HEIGHT][VNC_DIRTY_WORDS];
+    unsigned long dirty[VNC_MAX_HEIGHT][VNC_DIRTY_WORDS];
     VncRectStat stats[VNC_STAT_ROWS][VNC_STAT_COLS];
     DisplaySurface *ds;
 };
@@ -232,7 +233,7 @@ struct VncState
     int csock;
 
     DisplayState *ds;
-    uint32_t dirty[VNC_MAX_HEIGHT][VNC_DIRTY_WORDS];
+    unsigned long dirty[VNC_MAX_HEIGHT][VNC_DIRTY_WORDS];
     uint8_t **lossy_rect; /* Not an Array to avoid costly memcpy in
                            * vnc-jobs-async.c */
 
Signature · 1 line
1.7.3.4
#19 lore raw

PATCH v3 14/16 vnc: don't try to send bigger updates that client height

In reply to Corentin Chary

Respect client size if it doesn't not support desktop resizing.

---
 ui/vnc.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
ui/vnc.c +5 -5
index 6c57b0e..86c23207 100644
@@ -795,12 +795,11 @@ static void vnc_dpy_cursor_define(QEMUCursor *c)
 }
 
 static int find_and_clear_dirty_height(struct VncState *vs,
-                                       int y, int last_x, int x)
+                                       int y, int last_x, int x, int height)
 {
     int h;
-    VncDisplay *vd = vs->vd;
 
-    for (h = 1; h < (vd->server->height - y); h++) {
+    for (h = 1; h < (height - y); h++) {
         int tmp_x;
         if (!test_bit(last_x, vs->dirty[y + h])) {
             break;
@@ -865,7 +864,8 @@ static int vnc_update_client(VncState *vs, int has_dirty)
                     }
                 } else {
                     if (last_x != -1) {
-                        int h = find_and_clear_dirty_height(vs, y, last_x, x);
+                        int h = find_and_clear_dirty_height(vs, y, last_x, x,
+                                                            height);
 
                         n += vnc_job_add_rect(job, last_x * 16, y,
                                               (x - last_x) * 16, h);
@@ -874,7 +874,7 @@ static int vnc_update_client(VncState *vs, int has_dirty)
                 }
             }
             if (last_x != -1) {
-                int h = find_and_clear_dirty_height(vs, y, last_x, x);
+                int h = find_and_clear_dirty_height(vs, y, last_x, x, height);
                 n += vnc_job_add_rect(job, last_x * 16, y,
                                       (x - last_x) * 16, h);
             }
Signature · 1 line
1.7.3.4
#20 lore raw

PATCH v3 15/16 vnc: tight: tweak adaptive tight settings

In reply to Corentin Chary

The force_jpeg threshold was too low.

---
 ui/vnc-enc-tight.c |   20 ++++++++++----------
 1 files changed, 10 insertions(+), 10 deletions(-)
ui/vnc-enc-tight.c +10 -10
index 81024d5..82c1e96 100644
@@ -79,16 +79,16 @@ static const struct {
     int jpeg_idx;               /* Allow indexed JPEG */
     int jpeg_full;              /* Allow full color JPEG */
 } tight_jpeg_conf[] = {
-    { 0,   4,  1, 1 },
-    { 0,   4,  1, 1 },
-    { 0,   4,  1, 1 },
-    { 0,   4,  1, 1 },
-    { 0,   4,  0, 1 },
-    { 0.1, 4,  0, 1 },
-    { 0.2, 4,  0, 1 },
-    { 0.3, 6,  0, 0 },
-    { 0.4, 8,  0, 0 },
-    { 0.5, 10, 0, 0 },
+    { 0,   8,  1, 1 },
+    { 0,   8,  1, 1 },
+    { 0,   8,  1, 1 },
+    { 0,   8,  1, 1 },
+    { 0,   10, 1, 1 },
+    { 0.1, 10, 1, 1 },
+    { 0.2, 10, 1, 1 },
+    { 0.3, 12, 0, 0 },
+    { 0.4, 14, 0, 0 },
+    { 0.5, 16, 0, 0 },
 };
 #endif
 
Signature · 1 line
1.7.3.4
#21 lore raw

PATCH v3 16/16 vnc: add a non-adaptive option

In reply to Corentin Chary

This option allow to disable adaptive behaviors in some encodings.

---
 qemu-options.hx    |    9 +++++++++
 ui/vnc-enc-tight.c |    2 +-
 ui/vnc.c           |   13 +++++++++----
 ui/vnc.h           |    1 +
 4 files changed, 20 insertions(+), 5 deletions(-)
qemu-options.hx +9 -0
index 945edf3..badb730 100644
@@ -913,6 +913,15 @@ option is set, VNC client may receive lossy framebuffer updates
 depending on its encoding settings. Enabling this option can save
 a lot of bandwidth at the expense of quality.
 
+@item non-adaptive
+
+Disable adaptive encodings. Adaptive encodings are enabled by default.
+An adaptive encoding will try to detect frequently updated screen regions,
+and send updates in these regions using a lossy encoding (like JPEG).
+This can be really helpfull to save bandwidth when playing videos. Disabling
+adaptive encodings allow to restore the original static behavior of encodings
+like Tight.
+
 @end table
 ETEXI
 
ui/vnc-enc-tight.c +1 -1
index 82c1e96..5933394 100644
@@ -1546,7 +1546,7 @@ static int send_sub_rect(VncState *vs, int x, int y, int w, int h)
     vnc_tight_stop(vs);
 
 #ifdef CONFIG_VNC_JPEG
-    if (vs->tight.quality != (uint8_t)-1) {
+    if (!vs->vd->non_adaptive && vs->tight.quality != (uint8_t)-1) {
         double freq = vnc_update_freq(vs, x, y, w, h);
 
         if (freq < tight_jpeg_conf[vs->tight.quality].jpeg_freq_min) {
ui/vnc.c +9 -4
index 86c23207..626b430 100644
@@ -2387,10 +2387,12 @@ static int vnc_refresh_server_surface(VncDisplay *vd)
     VncState *vs;
     int has_dirty = 0;
 
-    struct timeval tv;
+    struct timeval tv = { 0, 0 };
 
-    gettimeofday(&tv, NULL);
-    has_dirty = vnc_update_stats(vd, &tv);
+    if (!vd->non_adaptive) {
+        gettimeofday(&tv, NULL);
+        has_dirty = vnc_update_stats(vd, &tv);
+    }
 
     /*
      * Walk through the guest dirty map.
@@ -2419,7 +2421,8 @@ static int vnc_refresh_server_surface(VncDisplay *vd)
                 if (memcmp(server_ptr, guest_ptr, cmp_bytes) == 0)
                     continue;
                 memcpy(server_ptr, guest_ptr, cmp_bytes);
-                vnc_rect_updated(vd, x, y, &tv);
+                if (!vd->non_adaptive)
+                    vnc_rect_updated(vd, x, y, &tv);
                 QTAILQ_FOREACH(vs, &vd->clients, next) {
                     set_bit((x / 16), vs->dirty[y]);
                 }
@@ -2754,6 +2757,8 @@ int vnc_display_open(DisplayState *ds, const char *display)
 #endif
         } else if (strncmp(options, "lossy", 5) == 0) {
             vs->lossy = true;
+        } else if (strncmp(options, "non-adapative", 13) == 0) {
+            vs->non_adaptive = true;
         }
     }
 
ui/vnc.h +1 -0
index 98a1885..8a1e7b9 100644
@@ -144,6 +144,7 @@ struct VncDisplay
     time_t expires;
     int auth;
     bool lossy;
+    bool non_adaptive;
 #ifdef CONFIG_VNC_TLS
     int subauth; /* Used by VeNCrypt */
     VncDisplayTLS tls;
Signature · 1 line
1.7.3.4
#22 lore raw
In reply to Corentin Chary

Am 04.02.2011 09:05, schrieb Corentin Chary:

Quoted 69 lines

From: Corentin Chary <[email protected]>

Hi,

Since v2:
- Fixed some styles issues
- Rebased to current master
- Fixed a Makefile issue (using .c instead of .o)

I rebased the series against current master, it contains:

- Adaptive Tight Encoding: send lossy or lossless updates depending on the update frequency of the screen region. If a lossy update is forced, then it will be refreshed with a lossless update as soon as the update frequency goes back to 0.

- ZRLE/ZYWRLE Encodings: ZYWRLE use less bandwidth than tight, but the result
is also probably more lossy. I wanted to make ZRLE/ZYWRLE adaptive, but this is not possible because most of the vnc clients can't switch between ZRLE and ZYWRLE. But a possible solution is to use another encoding for lossless updates, like zlib or tight.

- Bitmap module: create bitmap.h and bitops.h, and remove duplicate code from vnc.c

It was my last series from GSoC 2010 context, if necessary I can send different series for adaptive vnc, zrle and bitmap stuff.

Thanks,

Corentin Chary (16):
vnc: qemu can die if the client is disconnected while updating screen
vnc: don't set the quality if lossy encoding are disabled
vnc: add a way to get the update frequency for a given region
vnc: refresh lossy rect after a given timeout
vnc: tight: use the update frequency to choose between lossy and lossless
vnc: palette: use a pool to reduce memory allocations
vnc: palette: add palette_init calls
vnc: palette: and fill and color calls.
vnc: Add ZRLE and ZYWRLE encodings.
vnc: fix uint8_t comparisons with negative values
vnc: fix lossy rect refreshing
bitmap: add a generic bitmap and bitops library
vnc: use the new generic bitmap functions
vnc: don't try to send bigger updates that client height
vnc: tight: tweak adaptive tight settings
vnc: add a non-adaptive option

Makefile.objs | 2 +

bitmap.c | 256 ++++++++++++++++
bitmap.h | 222 ++++++++++++++
bitops.c | 142 +++++++++
bitops.h | 272 +++++++++++++++++

osdep.h | 4 +
qemu-options.hx | 9 +
ui/vnc-enc-tight.c | 75 ++++-
ui/vnc-enc-zrle-template.c | 263 +++++++++++++++++ ui/vnc-enc-zrle.c | 366 +++++++++++++++++++++++ ui/vnc-enc-zrle.h | 40 +++
ui/vnc-enc-zywrle-template.c | 170 +++++++++++ ui/vnc-enc-zywrle.h | 659 ++++++++++++++++++++++++++++++++++++++++++ ui/vnc-jobs-async.c | 8 +
ui/vnc-palette.c | 58 +++-
ui/vnc-palette.h | 7 +-
ui/vnc.c | 283 ++++++++++++++-----
ui/vnc.h | 57 ++++-

18 files changed, 2786 insertions(+), 107 deletions(-)
Quoted 9 lines

create mode 100644 bitmap.c
create mode 100644 bitmap.h
create mode 100644 bitops.c
create mode 100644 bitops.h
create mode 100644 ui/vnc-enc-zrle-template.c
create mode 100644 ui/vnc-enc-zrle.c
create mode 100644 ui/vnc-enc-zrle.h
create mode 100644 ui/vnc-enc-zywrle-template.c
create mode 100644 ui/vnc-enc-zywrle.h

Is there a special reason why you use __always_inline instead of inline in bitops.h?

This breaks compilation for mingw :-(

mingw also fails at timersub() in vnc.c.

#23 lore raw

Am 24.02.2011 22:03, schrieb Stefan Weil:

Quoted 82 lines

Am 04.02.2011 09:05, schrieb Corentin Chary:

Quoted 70 lines

From: Corentin Chary <[email protected]>

Hi,

Since v2:
- Fixed some styles issues
- Rebased to current master
- Fixed a Makefile issue (using .c instead of .o)

I rebased the series against current master, it contains:

- Adaptive Tight Encoding: send lossy or lossless updates depending on the
update frequency of the screen region. If a lossy update is forced, then it will be refreshed with a lossless update as soon as the update frequency goes back to 0.

- ZRLE/ZYWRLE Encodings: ZYWRLE use less bandwidth than tight, but the result
is also probably more lossy. I wanted to make ZRLE/ZYWRLE adaptive, but this is not possible because most of the vnc clients can't switch between ZRLE and ZYWRLE. But a possible solution is to use another encoding for lossless updates, like zlib or tight.

- Bitmap module: create bitmap.h and bitops.h, and remove duplicate code from vnc.c

It was my last series from GSoC 2010 context, if necessary I can send different series for adaptive vnc, zrle and bitmap stuff.

Thanks,

Corentin Chary (16):
vnc: qemu can die if the client is disconnected while updating screen
vnc: don't set the quality if lossy encoding are disabled
vnc: add a way to get the update frequency for a given region
vnc: refresh lossy rect after a given timeout
vnc: tight: use the update frequency to choose between lossy and lossless
vnc: palette: use a pool to reduce memory allocations
vnc: palette: add palette_init calls
vnc: palette: and fill and color calls.
vnc: Add ZRLE and ZYWRLE encodings.
vnc: fix uint8_t comparisons with negative values
vnc: fix lossy rect refreshing
bitmap: add a generic bitmap and bitops library
vnc: use the new generic bitmap functions
vnc: don't try to send bigger updates that client height
vnc: tight: tweak adaptive tight settings
vnc: add a non-adaptive option

Makefile.objs | 2 +

bitmap.c | 256 ++++++++++++++++
bitmap.h | 222 ++++++++++++++
bitops.c | 142 +++++++++
bitops.h | 272 +++++++++++++++++

osdep.h | 4 +
qemu-options.hx | 9 +
ui/vnc-enc-tight.c | 75 ++++-
ui/vnc-enc-zrle-template.c | 263 +++++++++++++++++ ui/vnc-enc-zrle.c | 366 +++++++++++++++++++++++ ui/vnc-enc-zrle.h | 40 +++
ui/vnc-enc-zywrle-template.c | 170 +++++++++++ ui/vnc-enc-zywrle.h | 659 ++++++++++++++++++++++++++++++++++++++++++ ui/vnc-jobs-async.c | 8 +
ui/vnc-palette.c | 58 +++-
ui/vnc-palette.h | 7 +-
ui/vnc.c | 283 ++++++++++++++-----
ui/vnc.h | 57 ++++-

18 files changed, 2786 insertions(+), 107 deletions(-)
Quoted 9 lines

create mode 100644 bitmap.c
create mode 100644 bitmap.h
create mode 100644 bitops.c
create mode 100644 bitops.h
create mode 100644 ui/vnc-enc-zrle-template.c
create mode 100644 ui/vnc-enc-zrle.c
create mode 100644 ui/vnc-enc-zrle.h
create mode 100644 ui/vnc-enc-zywrle-template.c
create mode 100644 ui/vnc-enc-zywrle.h

Quoted 7 lines

Is there a special reason why you use __always_inline instead of inline in bitops.h?

This breaks compilation for mingw :-(

mingw also fails at timersub() in vnc.c.

One more problem:

./bitops.h:192: warning: ‘old’ is used uninitialized in this function

#24 lore raw
In reply to Stefan Weil
Quoted 2 lines

Is there a special reason why you use __always_inline instead of inline in bitops.h?

Because it's not only a hint, I really want this function to be inlined.

Quoted 3 lines

This breaks compilation for mingw :-(

mingw also fails at timersub() in vnc.c.

Then we should defined timersub when not available.

Since I don't have any working mingw toolchain, cool you make a patch for those two ?
Thanks,

Signature · 2 lines
Corentin Chary
http://xf.iksaif.net
#25 lore raw
Quoted 10 lines · Corentin Chary
Quoted 2 lines

Is there a special reason why you use __always_inline instead of inline in bitops.h?

Because it's not only a hint, I really want this function to be inlined.

Quoted 3 lines

This breaks compilation for mingw :-(

mingw also fails at timersub() in vnc.c.

Then we should defined timersub when not available.

There's also this one, struct timeval is missing:

CC ui/vnc-enc-zlib.o
In file included from /src/qemu/ui/vnc.c:27:0:
/src/qemu/ui/vnc.h:105:20: error: array type has incomplete element type /src/qemu/ui/vnc.h:116:20: error: field 'last_freq_check' has incomplete type

Applied
#26 lore raw
In reply to Corentin Chary
Quoted 4 lines · Corentin Chary
Quoted 2 lines

Is there a special reason why you use __always_inline instead of inline in bitops.h?

Because it's not only a hint, I really want this function to be inlined.

I applied a patch which changes this to just inline. See osdep.h.