peterdelevoryas / rpms / qemu

Forked from rpms/qemu 2 years ago
Clone

Blame 0507-spice-send-updates-only-for-changed-screen-content.patch

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