9ae3a8
From fd7f778fd9bd7b99ce790081544b28adede189b2 Mon Sep 17 00:00:00 2001
9ae3a8
From: Gerd Hoffmann <kraxel@redhat.com>
9ae3a8
Date: Wed, 22 Feb 2017 12:36:19 +0100
9ae3a8
Subject: [PATCH 01/24] ui/vnc: introduce VNC_DIRTY_PIXELS_PER_BIT macro
9ae3a8
MIME-Version: 1.0
9ae3a8
Content-Type: text/plain; charset=UTF-8
9ae3a8
Content-Transfer-Encoding: 8bit
9ae3a8
9ae3a8
RH-Author: Gerd Hoffmann <kraxel@redhat.com>
9ae3a8
Message-id: <1487766986-6329-2-git-send-email-kraxel@redhat.com>
9ae3a8
Patchwork-id: 73972
9ae3a8
O-Subject: [RHEL-7.4 qemu-kvm PATCH 1/8] ui/vnc: introduce VNC_DIRTY_PIXELS_PER_BIT macro
9ae3a8
Bugzilla: 1377977
9ae3a8
RH-Acked-by: Thomas Huth <thuth@redhat.com>
9ae3a8
RH-Acked-by: Marc-André Lureau <mlureau@redhat.com>
9ae3a8
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
9ae3a8
9ae3a8
From: Peter Lieven <pl@kamp.de>
9ae3a8
9ae3a8
Signed-off-by: Peter Lieven <pl@kamp.de>
9ae3a8
Reviewed-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
9ae3a8
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
9ae3a8
(cherry picked from commit b4c85ddcec24c60616aad9b3b7fc36ce19ba3ca4)
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 ui/vnc.c | 65 ++++++++++++++++++++++++++++++++++++++++------------------------
9ae3a8
 ui/vnc.h |  6 +++++-
9ae3a8
 2 files changed, 46 insertions(+), 25 deletions(-)
9ae3a8
9ae3a8
diff --git a/ui/vnc.c b/ui/vnc.c
9ae3a8
index a0e2d33..0c799ed 100644
9ae3a8
--- a/ui/vnc.c
9ae3a8
+++ b/ui/vnc.c
9ae3a8
@@ -442,17 +442,19 @@ static void vnc_dpy_update(DisplayChangeListener *dcl,
9ae3a8
        iteration.  otherwise, if (x % 16) != 0, the last iteration may span
9ae3a8
        two 16-pixel blocks but we only mark the first as dirty
9ae3a8
     */
9ae3a8
-    w += (x % 16);
9ae3a8
-    x -= (x % 16);
9ae3a8
+    w += (x % VNC_DIRTY_PIXELS_PER_BIT);
9ae3a8
+    x -= (x % VNC_DIRTY_PIXELS_PER_BIT);
9ae3a8
 
9ae3a8
     x = MIN(x, width);
9ae3a8
     y = MIN(y, height);
9ae3a8
     w = MIN(x + w, width) - x;
9ae3a8
     h = MIN(h, height);
9ae3a8
 
9ae3a8
-    for (; y < h; y++)
9ae3a8
-        for (i = 0; i < w; i += 16)
9ae3a8
-            set_bit((x + i) / 16, s->dirty[y]);
9ae3a8
+    for (; y < h; y++) {
9ae3a8
+        for (i = 0; i < w; i += VNC_DIRTY_PIXELS_PER_BIT) {
9ae3a8
+            set_bit((x + i) / VNC_DIRTY_PIXELS_PER_BIT, s->dirty[y]);
9ae3a8
+        }
9ae3a8
+    }
9ae3a8
 }
9ae3a8
 
9ae3a8
 void vnc_framebuffer_update(VncState *vs, int x, int y, int w, int h,
9ae3a8
@@ -769,11 +771,12 @@ static void vnc_dpy_copy(DisplayChangeListener *dcl,
9ae3a8
         y = dst_y + h - 1;
9ae3a8
         inc = -1;
9ae3a8
     }
9ae3a8
-    w_lim = w - (16 - (dst_x % 16));
9ae3a8
-    if (w_lim < 0)
9ae3a8
+    w_lim = w - (VNC_DIRTY_PIXELS_PER_BIT - (dst_x % VNC_DIRTY_PIXELS_PER_BIT));
9ae3a8
+    if (w_lim < 0) {
9ae3a8
         w_lim = w;
9ae3a8
-    else
9ae3a8
-        w_lim = w - (w_lim % 16);
9ae3a8
+    } else {
9ae3a8
+        w_lim = w - (w_lim % VNC_DIRTY_PIXELS_PER_BIT);
9ae3a8
+    }
9ae3a8
     for (i = 0; i < h; i++) {
9ae3a8
         for (x = 0; x <= w_lim;
9ae3a8
                 x += s, src_row += cmp_bytes, dst_row += cmp_bytes) {
9ae3a8
@@ -781,10 +784,11 @@ static void vnc_dpy_copy(DisplayChangeListener *dcl,
9ae3a8
                 if ((s = w - w_lim) == 0)
9ae3a8
                     break;
9ae3a8
             } else if (!x) {
9ae3a8
-                s = (16 - (dst_x % 16));
9ae3a8
+                s = (VNC_DIRTY_PIXELS_PER_BIT -
9ae3a8
+                    (dst_x % VNC_DIRTY_PIXELS_PER_BIT));
9ae3a8
                 s = MIN(s, w_lim);
9ae3a8
             } else {
9ae3a8
-                s = 16;
9ae3a8
+                s = VNC_DIRTY_PIXELS_PER_BIT;
9ae3a8
             }
9ae3a8
             cmp_bytes = s * VNC_SERVER_FB_BYTES;
9ae3a8
             if (memcmp(src_row, dst_row, cmp_bytes) == 0)
9ae3a8
@@ -792,7 +796,8 @@ static void vnc_dpy_copy(DisplayChangeListener *dcl,
9ae3a8
             memmove(dst_row, src_row, cmp_bytes);
9ae3a8
             QTAILQ_FOREACH(vs, &vd->clients, next) {
9ae3a8
                 if (!vnc_has_feature(vs, VNC_FEATURE_COPYRECT)) {
9ae3a8
-                    set_bit(((x + dst_x) / 16), vs->dirty[y]);
9ae3a8
+                    set_bit(((x + dst_x) / VNC_DIRTY_PIXELS_PER_BIT),
9ae3a8
+                            vs->dirty[y]);
9ae3a8
                 }
9ae3a8
             }
9ae3a8
         }
9ae3a8
@@ -911,7 +916,7 @@ static int vnc_update_client(VncState *vs, int has_dirty)
9ae3a8
         for (y = 0; y < height; y++) {
9ae3a8
             int x;
9ae3a8
             int last_x = -1;
9ae3a8
-            for (x = 0; x < width / 16; x++) {
9ae3a8
+            for (x = 0; x < width / VNC_DIRTY_PIXELS_PER_BIT; x++) {
9ae3a8
                 if (test_and_clear_bit(x, vs->dirty[y])) {
9ae3a8
                     if (last_x == -1) {
9ae3a8
                         last_x = x;
9ae3a8
@@ -921,16 +926,22 @@ static int vnc_update_client(VncState *vs, int has_dirty)
9ae3a8
                         int h = find_and_clear_dirty_height(vs, y, last_x, x,
9ae3a8
                                                             height);
9ae3a8
 
9ae3a8
-                        n += vnc_job_add_rect(job, last_x * 16, y,
9ae3a8
-                                              (x - last_x) * 16, h);
9ae3a8
+                        n += vnc_job_add_rect(job,
9ae3a8
+                                              last_x * VNC_DIRTY_PIXELS_PER_BIT,
9ae3a8
+                                              y,
9ae3a8
+                                              (x - last_x) *
9ae3a8
+                                              VNC_DIRTY_PIXELS_PER_BIT,
9ae3a8
+                                              h);
9ae3a8
                     }
9ae3a8
                     last_x = -1;
9ae3a8
                 }
9ae3a8
             }
9ae3a8
             if (last_x != -1) {
9ae3a8
                 int h = find_and_clear_dirty_height(vs, y, last_x, x, height);
9ae3a8
-                n += vnc_job_add_rect(job, last_x * 16, y,
9ae3a8
-                                      (x - last_x) * 16, h);
9ae3a8
+                n += vnc_job_add_rect(job, last_x * VNC_DIRTY_PIXELS_PER_BIT,
9ae3a8
+                                      y,
9ae3a8
+                                      (x - last_x) * VNC_DIRTY_PIXELS_PER_BIT,
9ae3a8
+                                      h);
9ae3a8
             }
9ae3a8
         }
9ae3a8
 
9ae3a8
@@ -1861,7 +1872,7 @@ static void framebuffer_update_request(VncState *vs, int incremental,
9ae3a8
                                        int w, int h)
9ae3a8
 {
9ae3a8
     int i;
9ae3a8
-    const size_t width = surface_width(vs->vd->ds) / 16;
9ae3a8
+    const size_t width = surface_width(vs->vd->ds) / VNC_DIRTY_PIXELS_PER_BIT;
9ae3a8
     const size_t height = surface_height(vs->vd->ds);
9ae3a8
 
9ae3a8
     if (y_position > height) {
9ae3a8
@@ -2573,7 +2584,9 @@ static int vnc_refresh_lossy_rect(VncDisplay *vd, int x, int y)
9ae3a8
 
9ae3a8
         vs->lossy_rect[sty][stx] = 0;
9ae3a8
         for (j = 0; j < VNC_STAT_RECT; ++j) {
9ae3a8
-            bitmap_set(vs->dirty[y + j], x / 16, VNC_STAT_RECT / 16);
9ae3a8
+            bitmap_set(vs->dirty[y + j],
9ae3a8
+                       x / VNC_DIRTY_PIXELS_PER_BIT,
9ae3a8
+                       VNC_STAT_RECT / VNC_DIRTY_PIXELS_PER_BIT);
9ae3a8
         }
9ae3a8
         has_dirty++;
9ae3a8
     }
9ae3a8
@@ -2720,17 +2733,21 @@ static int vnc_refresh_server_surface(VncDisplay *vd)
9ae3a8
             }
9ae3a8
             server_ptr = server_row;
9ae3a8
 
9ae3a8
-            for (x = 0; x + 15 < width;
9ae3a8
-                    x += 16, guest_ptr += cmp_bytes, server_ptr += cmp_bytes) {
9ae3a8
-                if (!test_and_clear_bit((x / 16), vd->guest.dirty[y]))
9ae3a8
+            for (x = 0; x + VNC_DIRTY_PIXELS_PER_BIT - 1 < width;
9ae3a8
+                 x += VNC_DIRTY_PIXELS_PER_BIT, guest_ptr += cmp_bytes,
9ae3a8
+                 server_ptr += cmp_bytes) {
9ae3a8
+                if (!test_and_clear_bit((x / VNC_DIRTY_PIXELS_PER_BIT),
9ae3a8
+                    vd->guest.dirty[y])) {
9ae3a8
                     continue;
9ae3a8
-                if (memcmp(server_ptr, guest_ptr, cmp_bytes) == 0)
9ae3a8
+                }
9ae3a8
+                if (memcmp(server_ptr, guest_ptr, cmp_bytes) == 0) {
9ae3a8
                     continue;
9ae3a8
+                }
9ae3a8
                 memcpy(server_ptr, guest_ptr, cmp_bytes);
9ae3a8
                 if (!vd->non_adaptive)
9ae3a8
                     vnc_rect_updated(vd, x, y, &tv;;
9ae3a8
                 QTAILQ_FOREACH(vs, &vd->clients, next) {
9ae3a8
-                    set_bit((x / 16), vs->dirty[y]);
9ae3a8
+                    set_bit((x / VNC_DIRTY_PIXELS_PER_BIT), vs->dirty[y]);
9ae3a8
                 }
9ae3a8
                 has_dirty++;
9ae3a8
             }
9ae3a8
diff --git a/ui/vnc.h b/ui/vnc.h
9ae3a8
index 0efc5c6..561f383 100644
9ae3a8
--- a/ui/vnc.h
9ae3a8
+++ b/ui/vnc.h
9ae3a8
@@ -81,8 +81,12 @@ typedef void VncSendHextileTile(VncState *vs,
9ae3a8
 #define VNC_MAX_WIDTH 2560
9ae3a8
 #define VNC_MAX_HEIGHT 2048
9ae3a8
 
9ae3a8
+/* VNC_DIRTY_PIXELS_PER_BIT is the number of dirty pixels represented
9ae3a8
+ * by one bit in the dirty bitmap */
9ae3a8
+#define VNC_DIRTY_PIXELS_PER_BIT 16
9ae3a8
+
9ae3a8
 /* VNC_DIRTY_BITS is the number of bits in the dirty bitmap. */
9ae3a8
-#define VNC_DIRTY_BITS (VNC_MAX_WIDTH / 16)
9ae3a8
+#define VNC_DIRTY_BITS (VNC_MAX_WIDTH / VNC_DIRTY_PIXELS_PER_BIT)
9ae3a8
 
9ae3a8
 #define VNC_STAT_RECT  64
9ae3a8
 #define VNC_STAT_COLS (VNC_MAX_WIDTH / VNC_STAT_RECT)
9ae3a8
-- 
9ae3a8
1.8.3.1
9ae3a8