فهرست منبع

CocoaSpice: improved drawing latency

There is a BUG in OSX/iOS where TCP_NOPUSH is broken and causes a huge amount of latency. We patch spice server to not use it anymore and this makes everything nice again. See: http://lists.danga.com/pipermail/memcached/2005-March/001240.html

Additionally, the drawing is handled in the background and no longer as part of the invalidate event callback. This shouldn't be a real issue but it's good practice I guess.
osy 6 سال پیش
والد
کامیت
122f0eb3c7
2فایلهای تغییر یافته به همراه61 افزوده شده و 7 حذف شده
  1. 3 1
      CocoaSpice/CSDisplayMetal.m
  2. 58 6
      patches/spice-0.14.1.patch

+ 3 - 1
CocoaSpice/CSDisplayMetal.m

@@ -73,7 +73,9 @@ static void cs_invalidate(SpiceChannel *channel,
     CSDisplayMetal *self = (__bridge CSDisplayMetal *)data;
     CSDisplayMetal *self = (__bridge CSDisplayMetal *)data;
     CGRect rect = CGRectIntersection(CGRectMake(x, y, w, h), self->_visibleArea);
     CGRect rect = CGRectIntersection(CGRectMake(x, y, w, h), self->_visibleArea);
     if (!CGRectIsEmpty(rect)) {
     if (!CGRectIsEmpty(rect)) {
-        [self drawRegion:rect];
+        dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{
+            [self drawRegion:rect];
+        });
     }
     }
 }
 }
 
 

+ 58 - 6
patches/spice-0.14.1.patch

@@ -1,6 +1,6 @@
 diff -aur a/Makefile.in b/Makefile.in
 diff -aur a/Makefile.in b/Makefile.in
 --- a/Makefile.in	2018-08-22 04:32:02.000000000 -0700
 --- a/Makefile.in	2018-08-22 04:32:02.000000000 -0700
-+++ b/Makefile.in	2019-03-30 12:26:29.000000000 -0700
++++ b/Makefile.in	2019-04-23 11:52:06.000000000 -0700
 @@ -422,7 +422,7 @@
 @@ -422,7 +422,7 @@
  valgrind_tools = @valgrind_tools@
  valgrind_tools = @valgrind_tools@
  NULL = 
  NULL = 
@@ -12,8 +12,60 @@ diff -aur a/Makefile.in b/Makefile.in
  DISTCHECK_CONFIGURE_FLAGS = \
  DISTCHECK_CONFIGURE_FLAGS = \
 diff -aur a/server/red-stream.c b/server/red-stream.c
 diff -aur a/server/red-stream.c b/server/red-stream.c
 --- a/server/red-stream.c	2018-07-23 03:01:37.000000000 -0700
 --- a/server/red-stream.c	2018-07-23 03:01:37.000000000 -0700
-+++ b/server/red-stream.c	2019-03-30 11:00:26.000000000 -0700
-@@ -352,8 +352,16 @@
++++ b/server/red-stream.c	2019-04-24 09:26:53.000000000 -0700
+@@ -39,7 +39,7 @@
+ #include "reds.h"
+ 
+ // compatibility for *BSD systems
+-#ifndef TCP_CORK
++#if !defined(TCP_CORK) && !defined(__APPLE__)
+ #define TCP_CORK TCP_NOPUSH
+ #endif
+ 
+@@ -100,6 +100,7 @@
+     SpiceCoreInterfaceInternal *core;
+ };
+ 
++#if !defined(__APPLE__) // TCP_CORK doesn't exist and TCP_NOPUSH is broken
+ /**
+  * Set TCP_CORK on socket
+  */
+@@ -109,6 +110,7 @@
+     SPICE_VERIFY(sizeof(enabled) == sizeof(int));
+     return setsockopt(socket, IPPROTO_TCP, TCP_CORK, &enabled, sizeof(enabled));
+ }
++#endif
+ 
+ static ssize_t stream_write_cb(RedStream *s, const void *buf, size_t size)
+ {
+@@ -223,6 +225,7 @@
+ 
+ bool red_stream_set_auto_flush(RedStream *s, bool auto_flush)
+ {
++#if !defined(__APPLE__)
+     if (s->priv->use_cork == !auto_flush) {
+         return true;
+     }
+@@ -239,15 +242,18 @@
+         socket_set_cork(s->socket, 0);
+         s->priv->corked = false;
+     }
++#endif
+     return true;
+ }
+ 
+ void red_stream_flush(RedStream *s)
+ {
++#if !defined(__APPLE__)
+     if (s->priv->corked) {
+         socket_set_cork(s->socket, 0);
+         socket_set_cork(s->socket, 1);
+     }
++#endif
+ }
+ 
+ #if HAVE_SASL
+@@ -352,8 +358,16 @@
          memcpy(CMSG_DATA(cmsg), &fd, fd_size);
          memcpy(CMSG_DATA(cmsg), &fd, fd_size);
      }
      }
  
  
@@ -32,7 +84,7 @@ diff -aur a/server/red-stream.c b/server/red-stream.c
      return r;
      return r;
 diff -aur a/server/red-worker.c b/server/red-worker.c
 diff -aur a/server/red-worker.c b/server/red-worker.c
 --- a/server/red-worker.c	2018-08-09 04:09:22.000000000 -0700
 --- a/server/red-worker.c	2018-08-09 04:09:22.000000000 -0700
-+++ b/server/red-worker.c	2019-03-30 11:02:48.000000000 -0700
++++ b/server/red-worker.c	2019-04-23 11:52:06.000000000 -0700
 @@ -1391,7 +1391,9 @@
 @@ -1391,7 +1391,9 @@
          spice_error("create thread failed %d", r);
          spice_error("create thread failed %d", r);
      }
      }
@@ -44,8 +96,8 @@ diff -aur a/server/red-worker.c b/server/red-worker.c
      return r == 0;
      return r == 0;
  }
  }
 diff -aur a/server/reds.c b/server/reds.c
 diff -aur a/server/reds.c b/server/reds.c
---- a/server/reds.c  2018-08-09 04:09:22.000000000 -0700
-+++ b/server/reds.c  2019-03-31 10:39:25.000000000 -0700
+--- a/server/reds.c	2018-08-09 04:09:22.000000000 -0700
++++ b/server/reds.c	2019-04-23 11:52:06.000000000 -0700
 @@ -3555,6 +3555,7 @@
 @@ -3555,6 +3555,7 @@
  static const char* parse_next_video_codec(const char *codecs, char **encoder,
  static const char* parse_next_video_codec(const char *codecs, char **encoder,
                                            char **codec)
                                            char **codec)