Blame SOURCES/kvm-ui-vnc-introduce-VNC_DIRTY_PIXELS_PER_BIT-macro.patch

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