[gtk+/wip/alexl/broadway4: 71/96] broadway: Actually upload textures to client



commit a4636a06a72eb30681d1625048d7a45fc6ca129e
Author: Alexander Larsson <alexl redhat com>
Date:   Sat Nov 18 17:36:38 2017 +0100

    broadway: Actually upload textures to client

 gdk/broadway/broadway-output.c   |   20 ++++++++++++++++++++
 gdk/broadway/broadway-output.h   |    5 +++++
 gdk/broadway/broadway-protocol.h |    2 ++
 gdk/broadway/broadway-server.c   |   17 ++++++++++++++++-
 gdk/broadway/broadway.js         |   26 ++++++++++++++++++++++++++
 5 files changed, 69 insertions(+), 1 deletions(-)
---
diff --git a/gdk/broadway/broadway-output.c b/gdk/broadway/broadway-output.c
index 4434447..b9a86da 100644
--- a/gdk/broadway/broadway-output.c
+++ b/gdk/broadway/broadway-output.c
@@ -330,3 +330,23 @@ broadway_output_put_buffer (BroadwayOutput *output,
   g_object_unref (out);
   g_object_unref (out_mem);
 }
+
+void
+broadway_output_upload_texture (BroadwayOutput *output,
+                               guint32 id,
+                               GBytes *texture)
+{
+  gsize len = g_bytes_get_size (texture);
+  write_header (output, BROADWAY_OP_UPLOAD_TEXTURE);
+  append_uint32 (output, id);
+  append_uint32 (output, (guint32)len);
+  g_string_append_len (output->buf, g_bytes_get_data (texture, NULL), len);
+}
+
+void
+broadway_output_release_texture (BroadwayOutput *output,
+                                guint32 id)
+{
+  write_header (output, BROADWAY_OP_RELEASE_TEXTURE);
+  append_uint32 (output, id);
+}
diff --git a/gdk/broadway/broadway-output.h b/gdk/broadway/broadway-output.h
index 0ccda24..784ae17 100644
--- a/gdk/broadway/broadway-output.h
+++ b/gdk/broadway/broadway-output.h
@@ -58,6 +58,11 @@ void            broadway_output_put_buffer      (BroadwayOutput *output,
                                                 int             id,
                                                  BroadwayBuffer *prev_buffer,
                                                  BroadwayBuffer *buffer);
+void            broadway_output_upload_texture (BroadwayOutput *output,
+                                               guint32 id,
+                                               GBytes *texture);
+void            broadway_output_release_texture (BroadwayOutput *output,
+                                                guint32 id);
 void            broadway_output_grab_pointer    (BroadwayOutput *output,
                                                 int id,
                                                 gboolean owner_event);
diff --git a/gdk/broadway/broadway-protocol.h b/gdk/broadway/broadway-protocol.h
index 58e6434..2fa93d4 100644
--- a/gdk/broadway/broadway-protocol.h
+++ b/gdk/broadway/broadway-protocol.h
@@ -43,6 +43,8 @@ typedef enum {
   BROADWAY_OP_DISCONNECTED = 'D',
   BROADWAY_OP_PUT_BUFFER = 'b',
   BROADWAY_OP_SET_SHOW_KEYBOARD = 'k',
+  BROADWAY_OP_UPLOAD_TEXTURE = 't',
+  BROADWAY_OP_RELEASE_TEXTURE = 'T',
 } BroadwayOpType;
 
 typedef struct {
diff --git a/gdk/broadway/broadway-server.c b/gdk/broadway/broadway-server.c
index d7e5516..6d5dde8 100644
--- a/gdk/broadway/broadway-server.c
+++ b/gdk/broadway/broadway-server.c
@@ -1647,6 +1647,9 @@ broadway_server_upload_texture (BroadwayServer   *server,
                        GINT_TO_POINTER (id),
                        g_bytes_ref (texture));
 
+  if (server->output)
+    broadway_output_upload_texture (server->output, id, texture);
+
   return id;
 }
 
@@ -1655,6 +1658,9 @@ broadway_server_release_texture (BroadwayServer   *server,
                                 guint32           id)
 {
   g_hash_table_remove (server->textures, GINT_TO_POINTER (id));
+
+  if (server->output)
+    broadway_output_release_texture (server->output, id);
 }
 
 gboolean
@@ -1901,12 +1907,21 @@ broadway_server_new_window (BroadwayServer *server,
 static void
 broadway_server_resync_windows (BroadwayServer *server)
 {
+  GHashTableIter iter;
+  gpointer key, value;
   GList *l;
 
   if (server->output == NULL)
     return;
 
-  /* First create all windows */
+  /* First upload all textures */
+  g_hash_table_iter_init (&iter, server->textures);
+  while (g_hash_table_iter_next (&iter, &key, &value))
+    broadway_output_upload_texture (server->output,
+                                   GPOINTER_TO_INT (key),
+                                   (GBytes *)value);
+
+  /* Then create all windows */
   for (l = server->toplevels; l != NULL; l = l->next)
     {
       BroadwayWindow *window = l->data;
diff --git a/gdk/broadway/broadway.js b/gdk/broadway/broadway.js
index b134d85..12578d7 100644
--- a/gdk/broadway/broadway.js
+++ b/gdk/broadway/broadway.js
@@ -99,6 +99,7 @@ var lastTimeStamp = 0;
 var realWindowWithMouse = 0;
 var windowWithMouse = 0;
 var surfaces = {};
+var textures = {};
 var stackingOrder = [];
 var outstandingCommands = new Array();
 var inputSocket = null;
@@ -528,6 +529,20 @@ function cmdPutBuffer(id, w, h, compressed)
     surface.imageData = imageData;
 }
 
+function cmdUploadTexture(id, data)
+{
+    var blob = new Blob([data],{type: "image/png"});
+    var url = window.URL.createObjectURL(blob);
+    textures[id] = url;
+}
+
+function cmdReleaseTexture(id)
+{
+    var url = textures[id];
+    window.URL.revokeObjectURL(url);
+    delete textures[id];
+}
+
 function cmdGrabPointer(id, ownerEvents)
 {
     doGrab(id, ownerEvents, false);
@@ -624,6 +639,17 @@ function handleCommands(cmd)
             cmdPutBuffer(id, w, h, data);
             break;
 
+       case 't': // Upload texture
+           id = cmd.get_32();
+            var data = cmd.get_data();
+            cmdUploadTexture(id, data);
+            break;
+
+       case 'T': // Upload texture
+           id = cmd.get_32();
+            cmdReleaseTexture(id);
+            break;
+
        case 'g': // Grab
            id = cmd.get_16();
            var ownerEvents = cmd.get_bool ();


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