5544c1b
From e2da4b3f683ae63a55b8e50903a164f704be9e1d Mon Sep 17 00:00:00 2001
93b7e38
From: Gerd Hoffmann <kraxel@redhat.com>
93b7e38
Date: Wed, 5 Sep 2012 10:41:42 +0200
5544c1b
Subject: [PATCH] spice: send updates only for changed screen content
93b7e38
93b7e38
when creating screen updates go compare the current guest screen
93b7e38
against the mirror (which holds the most recent update sent), then
93b7e38
only create updates for the screen areas which did actually change.
93b7e38
93b7e38
[ v2: drop redundant qemu_spice_create_one_update call ]
93b7e38
93b7e38
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
93b7e38
---
93b7e38
 ui/spice-display.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
93b7e38
 1 file changed, 55 insertions(+), 1 deletion(-)
93b7e38
93b7e38
diff --git a/ui/spice-display.c b/ui/spice-display.c
93b7e38
index 973cd53..d062765 100644
93b7e38
--- a/ui/spice-display.c
93b7e38
+++ b/ui/spice-display.c
93b7e38
@@ -239,6 +239,13 @@ static void qemu_spice_create_one_update(SimpleSpiceDisplay *ssd,
93b7e38
 
93b7e38
 static void qemu_spice_create_update(SimpleSpiceDisplay *ssd)
93b7e38
 {
93b7e38
+    static const int blksize = 32;
93b7e38
+    int blocks = (ds_get_width(ssd->ds) + blksize - 1) / blksize;
93b7e38
+    int dirty_top[blocks];
93b7e38
+    int y, yoff, x, xoff, blk, bw;
93b7e38
+    int bpp = ds_get_bytes_per_pixel(ssd->ds);
93b7e38
+    uint8_t *guest, *mirror;
93b7e38
+
93b7e38
     if (qemu_spice_rect_is_empty(&ssd->dirty)) {
93b7e38
         return;
93b7e38
     };
93b7e38
@@ -253,7 +260,54 @@ static void qemu_spice_create_update(SimpleSpiceDisplay *ssd)
93b7e38
         ssd->ds_mirror = g_malloc0(size);
93b7e38
     }
93b7e38
 
93b7e38
-    qemu_spice_create_one_update(ssd, &ssd->dirty);
93b7e38
+    for (blk = 0; blk < blocks; blk++) {
93b7e38
+        dirty_top[blk] = -1;
93b7e38
+    }
93b7e38
+
93b7e38
+    guest = ds_get_data(ssd->ds);
93b7e38
+    mirror = ssd->ds_mirror;
93b7e38
+    for (y = ssd->dirty.top; y < ssd->dirty.bottom; y++) {
93b7e38
+        yoff = y * ds_get_linesize(ssd->ds);
93b7e38
+        for (x = ssd->dirty.left; x < ssd->dirty.right; x += blksize) {
93b7e38
+            xoff = x * bpp;
93b7e38
+            blk = x / blksize;
93b7e38
+            bw = MIN(blksize, ssd->dirty.right - x);
93b7e38
+            if (memcmp(guest + yoff + xoff,
93b7e38
+                       mirror + yoff + xoff,
93b7e38
+                       bw * bpp) == 0) {
93b7e38
+                if (dirty_top[blk] != -1) {
93b7e38
+                    QXLRect update = {
93b7e38
+                        .top    = dirty_top[blk],
93b7e38
+                        .bottom = y,
93b7e38
+                        .left   = x,
93b7e38
+                        .right  = x + bw,
93b7e38
+                    };
93b7e38
+                    qemu_spice_create_one_update(ssd, &update);
93b7e38
+                    dirty_top[blk] = -1;
93b7e38
+                }
93b7e38
+            } else {
93b7e38
+                if (dirty_top[blk] == -1) {
93b7e38
+                    dirty_top[blk] = y;
93b7e38
+                }
93b7e38
+            }
93b7e38
+        }
93b7e38
+    }
93b7e38
+
93b7e38
+    for (x = ssd->dirty.left; x < ssd->dirty.right; x += blksize) {
93b7e38
+        blk = x / blksize;
93b7e38
+        bw = MIN(blksize, ssd->dirty.right - x);
93b7e38
+        if (dirty_top[blk] != -1) {
93b7e38
+            QXLRect update = {
93b7e38
+                .top    = dirty_top[blk],
93b7e38
+                .bottom = ssd->dirty.bottom,
93b7e38
+                .left   = x,
93b7e38
+                .right  = x + bw,
93b7e38
+            };
93b7e38
+            qemu_spice_create_one_update(ssd, &update);
93b7e38
+            dirty_top[blk] = -1;
93b7e38
+        }
93b7e38
+    }
93b7e38
+
93b7e38
     memset(&ssd->dirty, 0, sizeof(ssd->dirty));
93b7e38
 }
93b7e38
 
93b7e38
-- 
5544c1b
1.7.12.1
93b7e38