Blame SOURCES/0010-stream-device-Create-channel-for-stream-device.patch

ad1357
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
ad1357
From: Frediano Ziglio <fziglio@redhat.com>
ad1357
Date: Sat, 21 Jan 2017 14:02:29 +0000
ad1357
Subject: [spice-server] stream-device: Create channel for stream device
ad1357
ad1357
So can be used by the device to communicate with the clients.
ad1357
ad1357
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
ad1357
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
ad1357
---
ad1357
 server/stream-channel.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++--
ad1357
 server/stream-device.c  | 14 +++++++++++++
ad1357
 2 files changed, 64 insertions(+), 2 deletions(-)
ad1357
ad1357
diff --git a/server/stream-channel.c b/server/stream-channel.c
ad1357
index df6936513..baf3d58a6 100644
ad1357
--- a/server/stream-channel.c
ad1357
+++ b/server/stream-channel.c
ad1357
@@ -19,6 +19,8 @@
ad1357
 #include <config.h>
ad1357
 #endif
ad1357
 
ad1357
+#include <common/generated_server_marshallers.h>
ad1357
+
ad1357
 #include "red-channel-client.h"
ad1357
 #include "stream-channel.h"
ad1357
 #include "reds.h"
ad1357
@@ -64,6 +66,13 @@ struct StreamChannelClass {
ad1357
 
ad1357
 G_DEFINE_TYPE(StreamChannel, stream_channel, RED_TYPE_CHANNEL)
ad1357
 
ad1357
+enum {
ad1357
+    RED_PIPE_ITEM_TYPE_SURFACE_CREATE = RED_PIPE_ITEM_TYPE_COMMON_LAST,
ad1357
+    RED_PIPE_ITEM_TYPE_FILL_SURFACE,
ad1357
+};
ad1357
+
ad1357
+#define PRIMARY_SURFACE_ID 0
ad1357
+
ad1357
 static void stream_channel_client_on_disconnect(RedChannelClient *rcc);
ad1357
 
ad1357
 static void
ad1357
@@ -103,9 +112,46 @@ stream_channel_client_new(StreamChannel *channel, RedClient *client, RedsStream
ad1357
 }
ad1357
 
ad1357
 static void
ad1357
+fill_base(SpiceMarshaller *m)
ad1357
+{
ad1357
+    SpiceMsgDisplayBase base;
ad1357
+
ad1357
+    base.surface_id = PRIMARY_SURFACE_ID;
ad1357
+    base.box = (SpiceRect) { 0, 0, 1024, 768 };
ad1357
+    base.clip = (SpiceClip) { SPICE_CLIP_TYPE_NONE, NULL };
ad1357
+
ad1357
+    spice_marshall_DisplayBase(m, &base);
ad1357
+}
ad1357
+
ad1357
+static void
ad1357
 stream_channel_send_item(RedChannelClient *rcc, RedPipeItem *pipe_item)
ad1357
 {
ad1357
+    SpiceMarshaller *m = red_channel_client_get_marshaller(rcc);
ad1357
+
ad1357
     switch (pipe_item->type) {
ad1357
+    case RED_PIPE_ITEM_TYPE_SURFACE_CREATE: {
ad1357
+        red_channel_client_init_send_data(rcc, SPICE_MSG_DISPLAY_SURFACE_CREATE);
ad1357
+        SpiceMsgSurfaceCreate surface_create = {
ad1357
+            PRIMARY_SURFACE_ID,
ad1357
+            1024, 768,
ad1357
+            SPICE_SURFACE_FMT_32_xRGB, SPICE_SURFACE_FLAGS_PRIMARY
ad1357
+        };
ad1357
+        spice_marshall_msg_display_surface_create(m, &surface_create);
ad1357
+        break;
ad1357
+    }
ad1357
+    case RED_PIPE_ITEM_TYPE_FILL_SURFACE: {
ad1357
+        red_channel_client_init_send_data(rcc, SPICE_MSG_DISPLAY_DRAW_FILL);
ad1357
+
ad1357
+        fill_base(m);
ad1357
+
ad1357
+        SpiceFill fill;
ad1357
+        fill.brush = (SpiceBrush) { SPICE_BRUSH_TYPE_SOLID, { .color = 0 } };
ad1357
+        fill.rop_descriptor = SPICE_ROPD_OP_PUT;
ad1357
+        fill.mask = (SpiceQMask) { 0, { 0, 0 }, NULL };
ad1357
+        SpiceMarshaller *brush_pat_out, *mask_bitmap_out;
ad1357
+        spice_marshall_Fill(m, &fill, &brush_pat_out, &mask_bitmap_out);
ad1357
+        break;
ad1357
+    }
ad1357
     default:
ad1357
         spice_error("invalid pipe item type");
ad1357
     }
ad1357
@@ -169,8 +215,10 @@ stream_channel_connect(RedChannel *red_channel, RedClient *red_client, RedsStrea
ad1357
     // "emulate" dcc_start
ad1357
     // TODO only if "surface"
ad1357
     red_channel_client_pipe_add_empty_msg(rcc, SPICE_MSG_DISPLAY_INVAL_ALL_PALETTES);
ad1357
-    // TODO red_surface_create_item_new
ad1357
-    // TODO surface data ??
ad1357
+    // TODO pass proper data
ad1357
+    red_channel_client_pipe_add_type(rcc, RED_PIPE_ITEM_TYPE_SURFACE_CREATE);
ad1357
+    // surface data
ad1357
+    red_channel_client_pipe_add_type(rcc, RED_PIPE_ITEM_TYPE_FILL_SURFACE);
ad1357
     // TODO monitor configs ??
ad1357
     red_channel_client_pipe_add_empty_msg(rcc, SPICE_MSG_DISPLAY_MARK);
ad1357
 }
ad1357
diff --git a/server/stream-device.c b/server/stream-device.c
ad1357
index 58edb3d11..0c9173ae0 100644
ad1357
--- a/server/stream-device.c
ad1357
+++ b/server/stream-device.c
ad1357
@@ -22,6 +22,8 @@
ad1357
 #include <spice/stream-device.h>
ad1357
 
ad1357
 #include "char-device.h"
ad1357
+#include "stream-channel.h"
ad1357
+#include "reds.h"
ad1357
 
ad1357
 #define TYPE_STREAM_DEVICE stream_device_get_type()
ad1357
 
ad1357
@@ -37,9 +39,11 @@ typedef struct StreamDeviceClass StreamDeviceClass;
ad1357
 
ad1357
 struct StreamDevice {
ad1357
     RedCharDevice parent;
ad1357
+
ad1357
     StreamDevHeader hdr;
ad1357
     uint8_t hdr_pos;
ad1357
     bool has_error;
ad1357
+    StreamChannel *stream_channel;
ad1357
 };
ad1357
 
ad1357
 struct StreamDeviceClass {
ad1357
@@ -204,7 +208,10 @@ stream_device_connect(RedsState *reds, SpiceCharDeviceInstance *sin)
ad1357
 {
ad1357
     SpiceCharDeviceInterface *sif;
ad1357
 
ad1357
+    StreamChannel *stream_channel = stream_channel_new(reds, 1); // TODO id
ad1357
+
ad1357
     StreamDevice *dev = stream_device_new(sin, reds);
ad1357
+    dev->stream_channel = stream_channel;
ad1357
 
ad1357
     sif = spice_char_device_get_interface(sin);
ad1357
     if (sif->state) {
ad1357
@@ -217,6 +224,13 @@ stream_device_connect(RedsState *reds, SpiceCharDeviceInstance *sin)
ad1357
 static void
ad1357
 stream_device_dispose(GObject *object)
ad1357
 {
ad1357
+    StreamDevice *dev = STREAM_DEVICE(object);
ad1357
+
ad1357
+    if (dev->stream_channel) {
ad1357
+        // close all current connections and drop the reference
ad1357
+        red_channel_destroy(RED_CHANNEL(dev->stream_channel));
ad1357
+        dev->stream_channel = NULL;
ad1357
+    }
ad1357
 }
ad1357
 
ad1357
 static void