[Spice-devel] [PATCH v3 2/2] display-channel: Handle timeout for joining drawables

Frediano Ziglio fziglio at redhat.com
Fri Mar 3 11:46:27 UTC 2017


The previous patch join correctly the commands however if there
are no more commands the command joined is delayed till new
commands arrive. This patch introduce a timeout (currently 10 ms)
after the command is executed.

Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 server/display-channel-private.h |  7 +++++++-
 server/display-channel.c         | 34 ++++++++++++++++++++++++---------
 2 files changed, 32 insertions(+), 9 deletions(-)

diff --git a/server/display-channel-private.h b/server/display-channel-private.h
index 62e03b6..a58630f 100644
--- a/server/display-channel-private.h
+++ b/server/display-channel-private.h
@@ -20,6 +20,11 @@
 
 #include "display-channel.h"
 
+// Timeout after rendering last saved joinable drawable.
+// This is slightly more than CMD_RING_POLL_TIMEOUT to prevent some unprobable
+// cases leading handle the drawing even if there are pending commands to join.
+#define JOINABLE_TIMEOUT 12 // ms
+
 #define NUM_DRAWABLES 1000
 typedef struct _Drawable _Drawable;
 struct _Drawable {
@@ -69,6 +74,8 @@ struct DisplayChannelPrivate
 
     int gl_draw_async_count;
 
+    uint32_t joinable_generation;
+    SpiceTimer *joinable_timeout;
     RedDrawable *joinable_drawable;
 
 /* TODO: some day unify this, make it more runtime.. */
diff --git a/server/display-channel.c b/server/display-channel.c
index e95741f..c85fa0d 100644
--- a/server/display-channel.c
+++ b/server/display-channel.c
@@ -79,6 +79,8 @@ display_channel_finalize(GObject *object)
     DisplayChannel *self = DISPLAY_CHANNEL(object);
 
     red_drawable_unref(self->priv->joinable_drawable);
+    SpiceCoreInterfaceInternal* core = red_channel_get_core_interface(RED_CHANNEL(self));
+    core->timer_remove(core, self->priv->joinable_timeout);
 
     display_channel_destroy_surfaces(self);
     image_cache_reset(&self->priv->image_cache);
@@ -1376,17 +1378,23 @@ display_channel_process_draw_single(DisplayChannel *display, RedDrawable *red_dr
     drawable_unref(drawable);
 }
 
+static void display_joinable_timeout(void *opaque)
+{
+    DisplayChannel *display = opaque;
+    if (display->priv->joinable_drawable) {
+        display_channel_process_draw_single(display, display->priv->joinable_drawable,
+                                            display->priv->joinable_generation);
+        red_drawable_unref(display->priv->joinable_drawable);
+        display->priv->joinable_drawable = NULL;
+    }
+}
+
 void display_channel_process_draw(DisplayChannel *display, RedDrawable *red_drawable,
                                   uint32_t process_commands_generation)
 {
     if (!red_drawable_joinable(red_drawable)) {
         // Not joinable, process all
-        if (display->priv->joinable_drawable) {
-            display_channel_process_draw_single(display, display->priv->joinable_drawable,
-                                                process_commands_generation);
-            red_drawable_unref(display->priv->joinable_drawable);
-            display->priv->joinable_drawable = NULL;
-        }
+        display_joinable_timeout(display);
         display_channel_process_draw_single(display, red_drawable, process_commands_generation);
         return;
     }
@@ -1397,14 +1405,16 @@ void display_channel_process_draw(DisplayChannel *display, RedDrawable *red_draw
             red_drawable = red_drawable_join(display->priv->joinable_drawable, red_drawable);
         } else {
             // They can't be joined
-            display_channel_process_draw_single(display, display->priv->joinable_drawable,
-                                                process_commands_generation);
-            red_drawable_unref(display->priv->joinable_drawable);
+            display_joinable_timeout(display);
         }
     }
 
     // Try to join with next one
     red_drawable_ref(red_drawable);
+
+    SpiceCoreInterfaceInternal* core = red_channel_get_core_interface(RED_CHANNEL(display));
+    core->timer_start(core, display->priv->joinable_timeout, JOINABLE_TIMEOUT);
+    display->priv->joinable_generation = process_commands_generation;
     display->priv->joinable_drawable = red_drawable;
 }
 
@@ -2275,6 +2285,12 @@ display_channel_constructed(GObject *object)
     self->priv->stream_video = SPICE_STREAM_VIDEO_OFF;
     display_channel_init_streams(self);
 
+    SpiceCoreInterfaceInternal* core = red_channel_get_core_interface(channel);
+    self->priv->joinable_timeout = core->timer_add(core, display_joinable_timeout, self);
+    if (!self->priv->joinable_timeout) {
+        spice_error("joinable timer create failed");
+    }
+
     red_channel_set_cap(channel, SPICE_DISPLAY_CAP_MONITORS_CONFIG);
     red_channel_set_cap(channel, SPICE_DISPLAY_CAP_PREF_COMPRESSION);
     red_channel_set_cap(channel, SPICE_DISPLAY_CAP_PREF_VIDEO_CODEC_TYPE);
-- 
git-series 0.9.1


More information about the Spice-devel mailing list