[Spice-devel] [PATCH RFC 10/12] Add get_dummy_drawable

Frediano Ziglio fziglio at redhat.com
Fri Jul 15 13:49:35 UTC 2016


This function allows to create a RedDrawable command passing
some raw data.
Actually the data has to be a buffer free-able with free and with
a depth of 32 bit.

Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 server/display-channel.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 server/red-worker.c      |  4 +++-
 2 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/server/display-channel.c b/server/display-channel.c
index 073d45e..2154878 100644
--- a/server/display-channel.c
+++ b/server/display-channel.c
@@ -23,6 +23,8 @@
 static void drawable_draw(DisplayChannel *display, Drawable *drawable);
 static Drawable *display_channel_drawable_try_new(DisplayChannel *display,
                                                   int process_commands_generation);
+static RedDrawable *get_dummy_drawable(DisplayChannel *display, int w, int h, int y_0_top,
+                                       uint8_t *data, uint32_t data_size);
 
 uint32_t display_channel_generate_uid(DisplayChannel *display)
 {
@@ -2032,3 +2034,43 @@ void display_channel_gl_draw_done(DisplayChannel *display)
 {
     set_gl_draw_async_count(display, display->gl_draw_async_count - 1);
 }
+
+/**
+ * Returns a RedDrawable with a bitmap image pointing to the data image
+ * we provide
+ */
+static RedDrawable *get_dummy_drawable(DisplayChannel *display, int w, int h, int y_0_top,
+                                       uint8_t *data, uint32_t data_size)
+{
+    SpiceChunks *chunks = spice_chunks_new(1);
+    chunks->flags = SPICE_CHUNKS_FLAGS_FREE;
+    chunks->data_size = data_size;
+    chunks->chunk[0].data = data;
+    chunks->chunk[0].len = data_size;
+
+    SpiceImage *image = spice_new0(SpiceImage, 1);
+    image->descriptor.type = SPICE_IMAGE_TYPE_BITMAP;
+    image->descriptor.width = w;
+    image->descriptor.height = h;
+    image->u.bitmap.x = w;
+    image->u.bitmap.y = h;
+    image->u.bitmap.format = SPICE_BITMAP_FMT_32BIT;
+    image->u.bitmap.flags = y_0_top ? 0: SPICE_BITMAP_FLAGS_TOP_DOWN;
+    image->u.bitmap.stride = w * 4;
+    image->u.bitmap.data = chunks;
+
+    RedDrawable *red = spice_new0(RedDrawable, 1);
+    red->refs = 1;
+    red->effect = QXL_EFFECT_OPAQUE;
+    red->type = QXL_DRAW_COPY;
+    red->bbox.bottom = h;
+    red->bbox.right = w;
+    red->surface_deps[0] = -1;
+    red->surface_deps[1] = -1;
+    red->surface_deps[2] = -1;
+    red->u.copy.src_area = red->bbox;
+    red->u.copy.rop_descriptor = SPICE_ROPD_OP_PUT;
+    red->u.copy.src_bitmap = image;
+
+    return red;
+}
diff --git a/server/red-worker.c b/server/red-worker.c
index 9238632..9eac0ad 100644
--- a/server/red-worker.c
+++ b/server/red-worker.c
@@ -128,7 +128,9 @@ void red_drawable_unref(RedDrawable *red_drawable)
     if (--red_drawable->refs) {
         return;
     }
-    red_qxl_release_resource(red_drawable->qxl, red_drawable->release_info_ext);
+    if (red_drawable->qxl) {
+        red_qxl_release_resource(red_drawable->qxl, red_drawable->release_info_ext);
+    }
     red_put_drawable(red_drawable);
     free(red_drawable);
 }
-- 
2.7.4



More information about the Spice-devel mailing list