[gtk+/broadway: 214/246] broadway: Add serial tracking and roundtripping



commit d4e2414d4a5cf4c78cca3ef0bc93983a4503b8e4
Author: Alexander Larsson <alexl redhat com>
Date:   Thu Mar 10 14:58:47 2011 +0100

    broadway: Add serial tracking and roundtripping

 gdk/broadway/broadway-demo.c       |    2 +-
 gdk/broadway/broadway.c            |   18 ++++++++++++++----
 gdk/broadway/broadway.h            |    6 +++++-
 gdk/broadway/broadway.js           |    5 ++++-
 gdk/broadway/gdkdisplay-broadway.c |   16 ++++++++++++++--
 gdk/broadway/gdkdisplay-broadway.h |    1 +
 gdk/broadway/gdkeventsource.c      |   19 +++++++++++--------
 gdk/broadway/gdkwindow-broadway.c  |    4 +++-
 8 files changed, 53 insertions(+), 18 deletions(-)
---
diff --git a/gdk/broadway/broadway-demo.c b/gdk/broadway/broadway-demo.c
index 96c177b..d46b336 100644
--- a/gdk/broadway/broadway-demo.c
+++ b/gdk/broadway/broadway-demo.c
@@ -223,7 +223,7 @@ main (int argc, char *argv[])
 {
   BroadwayOutput *output;
 
-  output = broadway_output_new (STDOUT_FILENO);
+  output = broadway_output_new (STDOUT_FILENO, 1);
   demo2(output);
 
   return 0;
diff --git a/gdk/broadway/broadway.c b/gdk/broadway/broadway.c
index 78b473c..40a93b4 100644
--- a/gdk/broadway/broadway.c
+++ b/gdk/broadway/broadway.c
@@ -1,4 +1,3 @@
-#include <glib.h>
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -450,6 +449,7 @@ struct BroadwayOutput {
   int fd;
   gzFile *zfd;
   int error;
+  guint32 serial;
 };
 
 static void
@@ -537,13 +537,14 @@ send_boundary (BroadwayOutput *output)
 }
 
 BroadwayOutput *
-broadway_output_new(int fd)
+broadway_output_new(int fd, guint32 serial)
 {
   BroadwayOutput *output;
 
   output = g_new0 (BroadwayOutput, 1);
 
   output->fd = fd;
+  output->serial = serial;
 
   broadway_output_write_header (output);
 
@@ -565,6 +566,12 @@ broadway_output_free (BroadwayOutput *output)
   free (output);
 }
 
+guint32
+broadway_output_get_next_serial (BroadwayOutput *output)
+{
+  return output->serial;
+}
+
 int
 broadway_output_flush (BroadwayOutput *output)
 {
@@ -578,7 +585,7 @@ broadway_output_flush (BroadwayOutput *output)
  *                     Core rendering operations                        *
  ************************************************************************/
 
-#define HEADER_LEN 1
+#define HEADER_LEN (1+6)
 
 static void
 append_uint16 (guint32 v, char *buf, int *p)
@@ -601,6 +608,7 @@ write_header(BroadwayOutput *output, char *buf, char op)
 
   p = 0;
   buf[p++] = op;
+  append_uint32 (output->serial++, buf, &p);
 
   return p;
 }
@@ -1008,7 +1016,9 @@ broadway_output_put_rgba (BroadwayOutput *output,  int id, int x, int y,
       len = strlen (url);
       append_uint32 (len, buf, &p);
 
-      broadway_output_write (output, buf, 16);
+      assert (p == sizeof (buf));
+
+      broadway_output_write (output, buf, sizeof (buf));
 
       broadway_output_write (output, url, len);
 
diff --git a/gdk/broadway/broadway.h b/gdk/broadway/broadway.h
index 0f7a7eb..8c8589e 100644
--- a/gdk/broadway/broadway.h
+++ b/gdk/broadway/broadway.h
@@ -1,3 +1,5 @@
+#include <glib.h>
+
 typedef struct BroadwayOutput BroadwayOutput;
 
 typedef struct  {
@@ -5,10 +7,12 @@ typedef struct  {
     int width, height;
 } BroadwayRect;
 
-BroadwayOutput *broadway_output_new             (int             fd);
+BroadwayOutput *broadway_output_new             (int             fd,
+						 guint32         serial);
 void            broadway_output_free            (BroadwayOutput *output);
 int             broadway_output_flush           (BroadwayOutput *output);
 int             broadway_output_has_error       (BroadwayOutput *output);
+guint32         broadway_output_get_next_serial (BroadwayOutput *output);
 void            broadway_output_new_surface     (BroadwayOutput *output,
 						 int             id,
 						 int             x,
diff --git a/gdk/broadway/broadway.js b/gdk/broadway/broadway.js
index 85f5448..c0f17f7 100644
--- a/gdk/broadway/broadway.js
+++ b/gdk/broadway/broadway.js
@@ -63,6 +63,7 @@ function createXHR()
   return null;
 }
 
+var last_serial = 0;
 var surfaces = {};
 var outstanding_commands = new Array();
 var input_socket = null;
@@ -89,6 +90,8 @@ function handleCommands(cmd_obj)
 
   while (i < cmd.length) {
     var command = cmd[i++];
+    last_serial = base64_32(cmd, i);
+    i = i + 6;
     switch (command) {
       /* create new surface */
       case 's':
@@ -277,7 +280,7 @@ function get_surface_id(ev) {
 function send_input(cmd, args)
 {
   if (input_socket != null) {
-      input_socket.send(cmd + args.join(","));
+      input_socket.send(cmd + ([last_serial].concat(args)).join(","));
   }
 }
 
diff --git a/gdk/broadway/gdkdisplay-broadway.c b/gdk/broadway/gdkdisplay-broadway.c
index fa89a8c..67c9b45 100644
--- a/gdk/broadway/gdkdisplay-broadway.c
+++ b/gdk/broadway/gdkdisplay-broadway.c
@@ -61,6 +61,7 @@ gdk_event_init (GdkDisplay *display)
 
   broadway_display = GDK_BROADWAY_DISPLAY (display);
   broadway_display->event_source = _gdk_broadway_event_source_new (display);
+  broadway_display->saved_serial = 1;
 }
 
 static void
@@ -350,7 +351,14 @@ start_output (HttpRequest *request)
   fd = g_socket_get_fd (socket);
   set_fd_blocking (fd);
   /* We dup this because otherwise it'll be closed with the request SocketConnection */
-  broadway_display->output = broadway_output_new (dup(fd));
+
+  if (broadway_display->output)
+    {
+      broadway_display->saved_serial = broadway_output_get_next_serial (broadway_display->output);
+      broadway_output_free (broadway_display->output);
+    }
+
+  broadway_display->output = broadway_output_new (dup(fd), broadway_display->saved_serial);
   _gdk_broadway_resync_windows ();
   http_request_free (request);
 }
@@ -715,7 +723,11 @@ gdk_broadway_display_list_devices (GdkDisplay *display)
 static gulong
 gdk_broadway_display_get_next_serial (GdkDisplay *display)
 {
-  return 0;
+  GdkBroadwayDisplay *broadway_display;
+  broadway_display = GDK_BROADWAY_DISPLAY (display);
+  if (broadway_display->output)
+    return broadway_output_get_next_serial (broadway_display->output);
+  return broadway_display->saved_serial;
 }
 
 
diff --git a/gdk/broadway/gdkdisplay-broadway.h b/gdk/broadway/gdkdisplay-broadway.h
index c335fee..aeed2a9 100644
--- a/gdk/broadway/gdkdisplay-broadway.h
+++ b/gdk/broadway/gdkdisplay-broadway.h
@@ -81,6 +81,7 @@ struct _GdkBroadwayDisplay
 
   GSocketService *service;
   BroadwayOutput *output;
+  guint32 saved_serial;
   HttpRequest *input;
 };
 
diff --git a/gdk/broadway/gdkeventsource.c b/gdk/broadway/gdkeventsource.c
index c4e2002..8a6912c 100644
--- a/gdk/broadway/gdkeventsource.c
+++ b/gdk/broadway/gdkeventsource.c
@@ -97,6 +97,7 @@ _gdk_broadway_events_got_input (GdkDisplay *display,
   GdkWindow *root, *window;
   char *p;
   int x, y, button, id, dir,key;
+  guint32 serial;
   guint64 time;
   GdkEvent *event = NULL;
   char cmd;
@@ -107,6 +108,8 @@ _gdk_broadway_events_got_input (GdkDisplay *display,
 
   p = (char *)message;
   cmd = *p++;
+  serial = (guint32)strtol(p, &p, 10);
+  p++; /* Skip , */
   switch (cmd) {
   case 'm':
     id = strtol(p, &p, 10);
@@ -137,7 +140,7 @@ _gdk_broadway_events_got_input (GdkDisplay *display,
 	    gdk_event_set_device (event, display->core_pointer);
 
 	    node = _gdk_event_queue_append (display, event);
-	    _gdk_windowing_got_event (display, node, event, 0);
+	    _gdk_windowing_got_event (display, node, event, serial);
 
 	    event = gdk_event_new (GDK_FOCUS_CHANGE);
 	    event->focus_change.window = g_object_ref (display_broadway->mouse_in_toplevel);
@@ -145,7 +148,7 @@ _gdk_broadway_events_got_input (GdkDisplay *display,
 	    gdk_event_set_device (event, display->core_pointer);
 
 	    node = _gdk_event_queue_append (display, event);
-	    _gdk_windowing_got_event (display, node, event, 0);
+	    _gdk_windowing_got_event (display, node, event, serial);
 	  }
 
 	/* TODO: Unset when it dies */
@@ -165,7 +168,7 @@ _gdk_broadway_events_got_input (GdkDisplay *display,
 	    gdk_event_set_device (event, display->core_pointer);
 
 	    node = _gdk_event_queue_append (display, event);
-	    _gdk_windowing_got_event (display, node, event, 0);
+	    _gdk_windowing_got_event (display, node, event, serial);
 
 	    event = gdk_event_new (GDK_FOCUS_CHANGE);
 	    event->focus_change.window = g_object_ref (window);
@@ -173,7 +176,7 @@ _gdk_broadway_events_got_input (GdkDisplay *display,
 	    gdk_event_set_device (event, display->core_pointer);
 
 	    node = _gdk_event_queue_append (display, event);
-	    _gdk_windowing_got_event (display, node, event, 0);
+	    _gdk_windowing_got_event (display, node, event, serial);
 
 	  }
       }
@@ -190,7 +193,7 @@ _gdk_broadway_events_got_input (GdkDisplay *display,
 	gdk_event_set_device (event, display->core_pointer);
 
 	node = _gdk_event_queue_append (display, event);
-	_gdk_windowing_got_event (display, node, event, 0);
+	_gdk_windowing_got_event (display, node, event, serial);
       }
 
     break;
@@ -223,7 +226,7 @@ _gdk_broadway_events_got_input (GdkDisplay *display,
 	gdk_event_set_device (event, display->core_pointer);
 
 	node = _gdk_event_queue_append (display, event);
-	_gdk_windowing_got_event (display, node, event, 0);
+	_gdk_windowing_got_event (display, node, event, serial);
       }
 
     break;
@@ -255,7 +258,7 @@ _gdk_broadway_events_got_input (GdkDisplay *display,
 	gdk_event_set_device (event, display->core_pointer);
 
 	node = _gdk_event_queue_append (display, event);
-	_gdk_windowing_got_event (display, node, event, 0);
+	_gdk_windowing_got_event (display, node, event, serial);
       }
 
     break;
@@ -277,7 +280,7 @@ _gdk_broadway_events_got_input (GdkDisplay *display,
 	gdk_event_set_device (event, display->core_pointer);
 
 	node = _gdk_event_queue_append (display, event);
-	_gdk_windowing_got_event (display, node, event, 0);
+	_gdk_windowing_got_event (display, node, event, serial);
       }
 
     break;
diff --git a/gdk/broadway/gdkwindow-broadway.c b/gdk/broadway/gdkwindow-broadway.c
index 9a909c4..3e23db7 100644
--- a/gdk/broadway/gdkwindow-broadway.c
+++ b/gdk/broadway/gdkwindow-broadway.c
@@ -186,6 +186,7 @@ dirty_flush_idle (gpointer data)
 
   if (!broadway_output_flush (display->output))
     {
+      display->saved_serial = broadway_output_get_next_serial (display->output);
       broadway_output_free (display->output);
       display->output = NULL;
     }
@@ -662,7 +663,8 @@ gdk_window_broadway_move_resize (GdkWindow *window,
       gdk_event_set_device (event, GDK_DISPLAY_OBJECT (broadway_display)->core_pointer);
 
       node = _gdk_event_queue_append (GDK_DISPLAY_OBJECT (broadway_display), event);
-      _gdk_windowing_got_event (GDK_DISPLAY_OBJECT (broadway_display), node, event, 0);
+      _gdk_windowing_got_event (GDK_DISPLAY_OBJECT (broadway_display), node, event,
+				_gdk_display_get_next_serial (GDK_DISPLAY (broadway_display)) - 1);
     }
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]