Blame 0506-spice-add-screen-mirror.patch

5544c1
From 9f4c601032d7a27e8856517a1a020c9988667ed3 Mon Sep 17 00:00:00 2001
93b7e3
From: Gerd Hoffmann <kraxel@redhat.com>
93b7e3
Date: Wed, 5 Sep 2012 09:35:57 +0200
5544c1
Subject: [PATCH] spice: add screen mirror
93b7e3
93b7e3
Create a screen mirror, keep there a copy of the most recent update
93b7e3
passed on to spice-server.
93b7e3
93b7e3
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
93b7e3
---
93b7e3
 ui/spice-display.c | 32 ++++++++++++++++++++++----------
93b7e3
 ui/spice-display.h |  1 +
93b7e3
 2 files changed, 23 insertions(+), 10 deletions(-)
93b7e3
93b7e3
diff --git a/ui/spice-display.c b/ui/spice-display.c
93b7e3
index 6f68f28..973cd53 100644
93b7e3
--- a/ui/spice-display.c
93b7e3
+++ b/ui/spice-display.c
93b7e3
@@ -171,8 +171,8 @@ static void qemu_spice_create_one_update(SimpleSpiceDisplay *ssd,
93b7e3
     QXLDrawable *drawable;
93b7e3
     QXLImage *image;
93b7e3
     QXLCommand *cmd;
93b7e3
-    uint8_t *src, *dst;
93b7e3
-    int by, bw, bh;
93b7e3
+    uint8_t *src, *mirror, *dst;
93b7e3
+    int by, bw, bh, offset, bytes;
93b7e3
     struct timespec time_space;
93b7e3
 
93b7e3
     trace_qemu_spice_create_update(
93b7e3
@@ -216,19 +216,18 @@ static void qemu_spice_create_one_update(SimpleSpiceDisplay *ssd,
93b7e3
     image->bitmap.palette = 0;
93b7e3
     image->bitmap.format = SPICE_BITMAP_FMT_32BIT;
93b7e3
 
93b7e3
-    if (ssd->conv == NULL) {
93b7e3
-        PixelFormat dst = qemu_default_pixelformat(32);
93b7e3
-        ssd->conv = qemu_pf_conv_get(&dst, &ssd->ds->surface->pf);
93b7e3
-        assert(ssd->conv);
93b7e3
-    }
93b7e3
-
93b7e3
-    src = ds_get_data(ssd->ds) +
93b7e3
+    offset =
93b7e3
         rect->top * ds_get_linesize(ssd->ds) +
93b7e3
         rect->left * ds_get_bytes_per_pixel(ssd->ds);
93b7e3
+    bytes = ds_get_bytes_per_pixel(ssd->ds) * bw;
93b7e3
+    src = ds_get_data(ssd->ds) + offset;
93b7e3
+    mirror = ssd->ds_mirror + offset;
93b7e3
     dst = update->bitmap;
93b7e3
     for (by = 0; by < bh; by++) {
93b7e3
-        qemu_pf_conv_run(ssd->conv, dst, src, bw);
93b7e3
+        memcpy(mirror, src, bytes);
93b7e3
+        qemu_pf_conv_run(ssd->conv, dst, mirror, bw);
93b7e3
         src += ds_get_linesize(ssd->ds);
93b7e3
+        mirror += ds_get_linesize(ssd->ds);
93b7e3
         dst += image->bitmap.stride;
93b7e3
     }
93b7e3
 
93b7e3
@@ -243,6 +242,17 @@ static void qemu_spice_create_update(SimpleSpiceDisplay *ssd)
93b7e3
     if (qemu_spice_rect_is_empty(&ssd->dirty)) {
93b7e3
         return;
93b7e3
     };
93b7e3
+
93b7e3
+    if (ssd->conv == NULL) {
93b7e3
+        PixelFormat dst = qemu_default_pixelformat(32);
93b7e3
+        ssd->conv = qemu_pf_conv_get(&dst, &ssd->ds->surface->pf);
93b7e3
+        assert(ssd->conv);
93b7e3
+    }
93b7e3
+    if (ssd->ds_mirror == NULL) {
93b7e3
+        int size = ds_get_height(ssd->ds) * ds_get_linesize(ssd->ds);
93b7e3
+        ssd->ds_mirror = g_malloc0(size);
93b7e3
+    }
93b7e3
+
93b7e3
     qemu_spice_create_one_update(ssd, &ssd->dirty);
93b7e3
     memset(&ssd->dirty, 0, sizeof(ssd->dirty));
93b7e3
 }
93b7e3
@@ -358,6 +368,8 @@ void qemu_spice_display_resize(SimpleSpiceDisplay *ssd)
93b7e3
     memset(&ssd->dirty, 0, sizeof(ssd->dirty));
93b7e3
     qemu_pf_conv_put(ssd->conv);
93b7e3
     ssd->conv = NULL;
93b7e3
+    g_free(ssd->ds_mirror);
93b7e3
+    ssd->ds_mirror = NULL;
93b7e3
 
93b7e3
     qemu_mutex_lock(&ssd->lock);
93b7e3
     while ((update = QTAILQ_FIRST(&ssd->updates)) != NULL) {
93b7e3
diff --git a/ui/spice-display.h b/ui/spice-display.h
93b7e3
index 3fcb6fe..dea41c1 100644
93b7e3
--- a/ui/spice-display.h
93b7e3
+++ b/ui/spice-display.h
93b7e3
@@ -72,6 +72,7 @@ typedef struct SimpleSpiceUpdate SimpleSpiceUpdate;
93b7e3
 
93b7e3
 struct SimpleSpiceDisplay {
93b7e3
     DisplayState *ds;
93b7e3
+    uint8_t *ds_mirror;
93b7e3
     void *buf;
93b7e3
     int bufsize;
93b7e3
     QXLWorker *worker;
93b7e3
-- 
5544c1
1.7.12.1
93b7e3