Remove the fixed size stream and support any display size.

Signed-off-by: Frediano Ziglio <fzig...@redhat.com>
---
 server/stream-channel.c | 33 +++++++++++++++++++++++++++------
 1 file changed, 27 insertions(+), 6 deletions(-)

diff --git a/server/stream-channel.c b/server/stream-channel.c
index be119f8..2ea7c57 100644
--- a/server/stream-channel.c
+++ b/server/stream-channel.c
@@ -61,6 +61,7 @@ struct StreamChannel {
     CommonGraphicsChannel parent;
 
     int stream_id;
+    unsigned width, height;
 };
 
 struct StreamChannelClass {
@@ -71,6 +72,7 @@ G_DEFINE_TYPE(StreamChannel, stream_channel, 
TYPE_COMMON_GRAPHICS_CHANNEL)
 
 enum {
     RED_PIPE_ITEM_TYPE_SURFACE_CREATE = RED_PIPE_ITEM_TYPE_COMMON_LAST,
+    RED_PIPE_ITEM_TYPE_SURFACE_DESTROY,
     RED_PIPE_ITEM_TYPE_FILL_SURFACE,
     RED_PIPE_ITEM_TYPE_STREAM_CREATE,
     RED_PIPE_ITEM_TYPE_STREAM_DATA,
@@ -144,12 +146,12 @@ stream_channel_client_new(StreamChannel *channel, 
RedClient *client, RedsStream 
 }
 
 static void
-fill_base(SpiceMarshaller *m)
+fill_base(SpiceMarshaller *m, const StreamChannel *channel)
 {
     SpiceMsgDisplayBase base;
 
     base.surface_id = 0;
-    base.box = (SpiceRect) { 0, 0, 1024, 768 };
+    base.box = (SpiceRect) { 0, 0, channel->width, channel->height };
     base.clip = (SpiceClip) { SPICE_CLIP_TYPE_NONE, NULL };
 
     spice_marshall_DisplayBase(m, &base);
@@ -160,18 +162,28 @@ stream_channel_send_item(RedChannelClient *rcc, 
RedPipeItem *pipe_item)
 {
     SpiceMarshaller *m = red_channel_client_get_marshaller(rcc);
     StreamChannelClient *client = STREAM_CHANNEL_CLIENT(rcc);
+    StreamChannel *channel = 
STREAM_CHANNEL(red_channel_client_get_channel(rcc));
 
     switch (pipe_item->type) {
     case RED_PIPE_ITEM_TYPE_SURFACE_CREATE: {
         red_channel_client_init_send_data(rcc, 
SPICE_MSG_DISPLAY_SURFACE_CREATE);
-        SpiceMsgSurfaceCreate surface_create = { 0, 1024, 768, 
SPICE_SURFACE_FMT_32_xRGB, SPICE_SURFACE_FLAGS_PRIMARY };
+        SpiceMsgSurfaceCreate surface_create = {
+            0, channel->width, channel->height,
+            SPICE_SURFACE_FMT_32_xRGB, SPICE_SURFACE_FLAGS_PRIMARY
+        };
         spice_marshall_msg_display_surface_create(m, &surface_create);
         break;
     }
+    case RED_PIPE_ITEM_TYPE_SURFACE_DESTROY: {
+        red_channel_client_init_send_data(rcc, 
SPICE_MSG_DISPLAY_SURFACE_DESTROY);
+        SpiceMsgSurfaceDestroy surface_destroy = { 0 };
+        spice_marshall_msg_display_surface_destroy(m, &surface_destroy);
+        break;
+    }
     case RED_PIPE_ITEM_TYPE_FILL_SURFACE: {
         red_channel_client_init_send_data(rcc, SPICE_MSG_DISPLAY_DRAW_FILL);
 
-        fill_base(m);
+        fill_base(m, channel);
 
         SpiceFill fill;
         fill.brush = (SpiceBrush) { SPICE_BRUSH_TYPE_SOLID, { .color = 0 } };
@@ -275,7 +287,7 @@ stream_channel_connect(RedChannel *red_channel, RedClient 
*red_client, RedsStrea
     // "emulate" dcc_start
     // TODO only if "surface"
     red_channel_client_pipe_add_empty_msg(rcc, 
SPICE_MSG_DISPLAY_INVAL_ALL_PALETTES);
-    // TODO pass proper data
+    // pass proper data
     red_channel_client_pipe_add_type(rcc, RED_PIPE_ITEM_TYPE_SURFACE_CREATE);
     // surface data
     red_channel_client_pipe_add_type(rcc, RED_PIPE_ITEM_TYPE_FILL_SURFACE);
@@ -321,6 +333,8 @@ static void
 stream_channel_init(StreamChannel *channel)
 {
     channel->stream_id = -1;
+    channel->width = 1024;
+    channel->height = 768;
 }
 
 static RedPipeItem *
@@ -339,7 +353,14 @@ stream_channel_change_format(StreamChannel *channel, const 
struct StreamMsgStrea
     // send destroy old stream
     red_channel_pipes_add_type(red_channel, RED_PIPE_ITEM_TYPE_STREAM_DESTROY);
 
-    // TODO send new create surface if required
+    // send new create surface if required
+    if (channel->width != fmt->width || channel->height != fmt->height) {
+        channel->width = fmt->width;
+        channel->height = fmt->height;
+        red_channel_pipes_add_type(red_channel, 
RED_PIPE_ITEM_TYPE_SURFACE_DESTROY);
+        red_channel_pipes_add_type(red_channel, 
RED_PIPE_ITEM_TYPE_SURFACE_CREATE);
+        // TODO monitors config ??
+    }
 
     // allocate a new stream id
     channel->stream_id = (channel->stream_id + 1) % 40;
-- 
git-series 0.9.1
_______________________________________________
Spice-devel mailing list
Spice-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/spice-devel

Reply via email to