[gtk+/wip/alexl/broadway4: 72/96] broadway: Use textures to configure window contents



commit cc7423855b5ce92081828c863b5ba3ecbb970e4f
Author: Alexander Larsson <alexl redhat com>
Date:   Sat Nov 18 20:36:57 2017 +0100

    broadway: Use textures to configure window contents
    
    Instead of using the old buffer code, just use textures to define the
    window contents.

 gdk/broadway/broadway-buffer.c     |  528 ------------------------------------
 gdk/broadway/broadway-buffer.h     |   20 --
 gdk/broadway/broadway-output.c     |   44 +---
 gdk/broadway/broadway-output.h     |    6 +-
 gdk/broadway/broadway-protocol.h   |    6 +-
 gdk/broadway/broadway-server.c     |  212 +--------------
 gdk/broadway/broadway-server.h     |    7 +-
 gdk/broadway/broadway.js           |   68 ++----
 gdk/broadway/broadwayd.c           |   18 +-
 gdk/broadway/gdkbroadway-server.c  |  218 +---------------
 gdk/broadway/gdkbroadway-server.h  |    4 +-
 gdk/broadway/gdkdisplay-broadway.c |    1 +
 gdk/broadway/gdkwindow-broadway.c  |   28 ++-
 gdk/broadway/gdkwindow-broadway.h  |    1 +
 gdk/broadway/meson.build           |    3 +-
 15 files changed, 79 insertions(+), 1085 deletions(-)
---
diff --git a/gdk/broadway/broadway-output.c b/gdk/broadway/broadway-output.c
index b9a86da..770fa43 100644
--- a/gdk/broadway/broadway-output.c
+++ b/gdk/broadway/broadway-output.c
@@ -287,48 +287,14 @@ broadway_output_set_transient_for (BroadwayOutput *output,
 }
 
 void
-broadway_output_put_buffer (BroadwayOutput *output,
-                            int             id,
-                            BroadwayBuffer *prev_buffer,
-                            BroadwayBuffer *buffer)
+broadway_output_window_update (BroadwayOutput *output,
+                              int             id,
+                              guint32         texture)
 {
-  gsize len;
-  int w, h;
-  GZlibCompressor *compressor;
-  GOutputStream *out, *out_mem;
-  GString *encoded;
-
-  write_header (output, BROADWAY_OP_PUT_BUFFER);
-
-  w = broadway_buffer_get_width (buffer);
-  h = broadway_buffer_get_height (buffer);
+  write_header (output, BROADWAY_OP_WINDOW_UPDATE);
 
   append_uint16 (output, id);
-  append_uint16 (output, w);
-  append_uint16 (output, h);
-
-  encoded = g_string_new ("");
-  broadway_buffer_encode (buffer, prev_buffer, encoded);
-
-  compressor = g_zlib_compressor_new (G_ZLIB_COMPRESSOR_FORMAT_RAW, -1);
-  out_mem = g_memory_output_stream_new_resizable ();
-  out = g_converter_output_stream_new (out_mem, G_CONVERTER (compressor));
-  g_object_unref (compressor);
-
-  if (!g_output_stream_write_all (out, encoded->str, encoded->len,
-                                  NULL, NULL, NULL) ||
-      !g_output_stream_close (out, NULL, NULL))
-    g_warning ("compression failed");
-
-
-  len = g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (out_mem));
-  append_uint32 (output, len);
-
-  g_string_append_len (output->buf, g_memory_output_stream_get_data (G_MEMORY_OUTPUT_STREAM (out_mem)), len);
-
-  g_string_free (encoded, TRUE);
-  g_object_unref (out);
-  g_object_unref (out_mem);
+  append_uint32 (output, texture);
 }
 
 void
diff --git a/gdk/broadway/broadway-output.h b/gdk/broadway/broadway-output.h
index 784ae17..7c69e3b 100644
--- a/gdk/broadway/broadway-output.h
+++ b/gdk/broadway/broadway-output.h
@@ -4,7 +4,6 @@
 #include <glib.h>
 #include <gio/gio.h>
 #include "broadway-protocol.h"
-#include "broadway-buffer.h"
 
 typedef struct BroadwayOutput BroadwayOutput;
 
@@ -54,10 +53,9 @@ void            broadway_output_move_resize_surface (BroadwayOutput *output,
 void            broadway_output_set_transient_for (BroadwayOutput *output,
                                                   int             id,
                                                   int             parent_id);
-void            broadway_output_put_buffer      (BroadwayOutput *output,
+void            broadway_output_window_update   (BroadwayOutput *output,
                                                 int             id,
-                                                 BroadwayBuffer *prev_buffer,
-                                                 BroadwayBuffer *buffer);
+                                                guint32         texture);
 void            broadway_output_upload_texture (BroadwayOutput *output,
                                                guint32 id,
                                                GBytes *texture);
diff --git a/gdk/broadway/broadway-protocol.h b/gdk/broadway/broadway-protocol.h
index 2fa93d4..3bf963f 100644
--- a/gdk/broadway/broadway-protocol.h
+++ b/gdk/broadway/broadway-protocol.h
@@ -41,7 +41,7 @@ typedef enum {
   BROADWAY_OP_REQUEST_AUTH = 'l',
   BROADWAY_OP_AUTH_OK = 'L',
   BROADWAY_OP_DISCONNECTED = 'D',
-  BROADWAY_OP_PUT_BUFFER = 'b',
+  BROADWAY_OP_WINDOW_UPDATE = 'b',
   BROADWAY_OP_SET_SHOW_KEYBOARD = 'k',
   BROADWAY_OP_UPLOAD_TEXTURE = 't',
   BROADWAY_OP_RELEASE_TEXTURE = 'T',
@@ -193,9 +193,7 @@ typedef struct {
 typedef struct {
   BroadwayRequestBase base;
   guint32 id;
-  char name[36];
-  guint32 width;
-  guint32 height;
+  guint32 texture;
 } BroadwayRequestUpdate;
 
 typedef struct {
diff --git a/gdk/broadway/broadway-server.c b/gdk/broadway/broadway-server.c
index 6d5dde8..8d86a9e 100644
--- a/gdk/broadway/broadway-server.c
+++ b/gdk/broadway/broadway-server.c
@@ -116,12 +116,7 @@ struct BroadwayWindow {
   gboolean is_temp;
   gboolean visible;
   gint32 transient_for;
-
-  BroadwayBuffer *buffer;
-  gboolean buffer_synced;
-
-  char *cached_surface_name;
-  cairo_surface_t *cached_surface;
+  guint32 texture;
 };
 
 static void broadway_server_resync_windows (BroadwayServer *server);
@@ -826,87 +821,6 @@ broadway_server_block_for_input (BroadwayServer *server, char op,
 }
 #endif
 
-static void *
-map_named_shm (char *name, gsize size)
-{
-#ifdef G_OS_UNIX
-
-  int fd;
-  void *ptr;
-  char *filename = NULL;
-
-  fd = shm_open (name, O_RDONLY, 0600);
-  if (fd == -1)
-    {
-      filename = g_build_filename (g_get_tmp_dir (), name, NULL);
-      fd = open (filename, O_RDONLY);
-      if (fd == -1)
-       {
-         perror ("Failed to map shm");
-         g_free (filename);
-
-         return NULL;
-       }
-    }
-
-  ptr = mmap (0, size, PROT_READ, MAP_SHARED, fd, 0);
-
-  (void) close (fd);
-
-  if (filename)
-    {
-      unlink (filename);
-      g_free (filename);
-    }
-  else
-    shm_unlink (name);
-
-  return ptr;
-
-#elif defined(G_OS_WIN32)
-
-  int fd;
-  void *ptr;
-  char *shmpath;
-  void *map = ((void *)-1);
-
-  if (*name == '/')
-    ++name;
-  shmpath = g_build_filename (g_get_tmp_dir (), name, NULL);
-
-  fd = open(shmpath, O_RDONLY, 0600);
-  if (fd == -1)
-    {
-      g_free (shmpath);
-      perror ("Failed to shm_open");
-      return NULL;
-    }
-
-  if (size == 0)
-    ptr = map;
-  else
-    {
-      HANDLE h, fm;
-      h = (HANDLE)_get_osfhandle (fd);
-      fm = CreateFileMapping (h, NULL, PAGE_READONLY, 0, (DWORD)size, NULL);
-      ptr = MapViewOfFile (fm, FILE_MAP_READ, 0, 0, (size_t)size);
-      CloseHandle (fm);
-    }
-
-  (void) close(fd);
-
-  remove (shmpath);
-  g_free (shmpath);
-
-  return ptr;
-
-#else
-#error "No shm mapping supported"
-
-  return NULL;
-#endif
-}
-
 static const char *
 parse_line (const char *line, const char *key)
 {
@@ -1463,10 +1377,6 @@ broadway_server_destroy_window (BroadwayServer *server,
       g_hash_table_remove (server->id_ht,
                           GINT_TO_POINTER (id));
 
-      g_free (window->cached_surface_name);
-      if (window->cached_surface != NULL)
-       cairo_surface_destroy (window->cached_surface);
-
       g_free (window);
     }
 }
@@ -1601,39 +1511,22 @@ broadway_server_has_client (BroadwayServer *server)
 }
 
 void
-broadway_server_window_update (BroadwayServer *server,
-                              gint id,
-                              cairo_surface_t *surface)
+broadway_server_window_update (BroadwayServer   *server,
+                              gint              id,
+                              guint32           texture)
 {
   BroadwayWindow *window;
-  BroadwayBuffer *buffer;
-
-  if (surface == NULL)
-    return;
 
   window = g_hash_table_lookup (server->id_ht,
                                GINT_TO_POINTER (id));
   if (window == NULL)
     return;
 
-  g_assert (window->width == cairo_image_surface_get_width (surface));
-  g_assert (window->height == cairo_image_surface_get_height (surface));
-
-  buffer = broadway_buffer_create (window->width, window->height,
-                                   cairo_image_surface_get_data (surface),
-                                   cairo_image_surface_get_stride (surface));
+  window->texture = texture;
 
   if (server->output != NULL)
-    {
-      window->buffer_synced = TRUE;
-      broadway_output_put_buffer (server->output, window->id,
-                                  window->buffer, buffer);
-    }
-
-  if (window->buffer)
-    broadway_buffer_destroy (window->buffer);
-
-  window->buffer = buffer;
+    broadway_output_window_update (server->output, window->id,
+                                  window->texture);
 }
 
 guint32
@@ -1788,78 +1681,6 @@ broadway_server_ungrab_pointer (BroadwayServer *server,
   return serial;
 }
 
-static const cairo_user_data_key_t shm_cairo_key;
-
-typedef struct {
-  void *data;
-  gsize data_size;
-} ShmSurfaceData;
-
-static void
-shm_data_unmap (void *_data)
-{
-  ShmSurfaceData *data = _data;
-#ifdef G_OS_UNIX
-  munmap (data->data, data->data_size);
-#elif defined(G_OS_WIN32)
-  UnmapViewOfFile (data->data);
-#endif
-  g_free (data);
-}
-
-cairo_surface_t *
-broadway_server_open_surface (BroadwayServer *server,
-                             guint32 id,
-                             char *name,
-                             int width,
-                             int height)
-{
-  BroadwayWindow *window;
-  ShmSurfaceData *data;
-  cairo_surface_t *surface;
-  gsize size;
-  void *ptr;
-
-  window = g_hash_table_lookup (server->id_ht,
-                               GINT_TO_POINTER (id));
-  if (window == NULL)
-    return NULL;
-
-  if (window->cached_surface_name != NULL &&
-      strcmp (name, window->cached_surface_name) == 0)
-    return cairo_surface_reference (window->cached_surface);
-
-  size = width * height * sizeof (guint32);
-
-  ptr = map_named_shm (name, size);
-
-  if (ptr == NULL)
-    return NULL;
-
-  data = g_new0 (ShmSurfaceData, 1);
-
-  data->data = ptr;
-  data->data_size = size;
-
-  surface = cairo_image_surface_create_for_data ((guchar *)data->data,
-                                                CAIRO_FORMAT_ARGB32,
-                                                width, height,
-                                                width * sizeof (guint32));
-  g_assert (surface != NULL);
-
-  cairo_surface_set_user_data (surface, &shm_cairo_key,
-                              data, shm_data_unmap);
-
-  g_free (window->cached_surface_name);
-  window->cached_surface_name = g_strdup (name);
-
-  if (window->cached_surface != NULL)
-    cairo_surface_destroy (window->cached_surface);
-  window->cached_surface = cairo_surface_reference (surface);
-
-  return surface;
-}
-
 guint32
 broadway_server_new_window (BroadwayServer *server,
                            int x,
@@ -1929,7 +1750,6 @@ broadway_server_resync_windows (BroadwayServer *server)
       if (window->id == 0)
        continue; /* Skip root */
 
-      window->buffer_synced = FALSE;
       broadway_output_new_surface (server->output,
                                   window->id,
                                   window->x,
@@ -1948,18 +1768,14 @@ broadway_server_resync_windows (BroadwayServer *server)
        continue; /* Skip root */
 
       if (window->transient_for != -1)
-       broadway_output_set_transient_for (server->output, window->id, window->transient_for);
+       broadway_output_set_transient_for (server->output, window->id,
+                                          window->transient_for);
+
+      broadway_output_window_update (server->output, window->id,
+                                    window->texture);
+
       if (window->visible)
-       {
-         broadway_output_show_surface (server->output, window->id);
-
-         if (window->buffer != NULL)
-           {
-             window->buffer_synced = TRUE;
-              broadway_output_put_buffer (server->output, window->id,
-                                          NULL, window->buffer);
-           }
-       }
+       broadway_output_show_surface (server->output, window->id);
     }
 
   if (server->show_keyboard)
diff --git a/gdk/broadway/broadway-server.h b/gdk/broadway/broadway-server.h
index 7cb7694..422488c 100644
--- a/gdk/broadway/broadway-server.h
+++ b/gdk/broadway/broadway-server.h
@@ -84,7 +84,7 @@ cairo_surface_t   * broadway_server_create_surface           (int
                                                              int               height);
 void                broadway_server_window_update            (BroadwayServer   *server,
                                                              gint              id,
-                                                             cairo_surface_t  *surface);
+                                                             guint32           texture);
 gboolean            broadway_server_window_move_resize       (BroadwayServer   *server,
                                                              gint              id,
                                                              gboolean          with_move,
@@ -94,10 +94,5 @@ gboolean            broadway_server_window_move_resize       (BroadwayServer   *
                                                              int               height);
 void                broadway_server_focus_window             (BroadwayServer   *server,
                                                               gint              new_focused_window);
-cairo_surface_t * broadway_server_open_surface (BroadwayServer *server,
-                                               guint32 id,
-                                               char *name,
-                                               int width,
-                                               int height);
 
 #endif /* __BROADWAY_SERVER__ */
diff --git a/gdk/broadway/broadway.js b/gdk/broadway/broadway.js
index 12578d7..b268e0d 100644
--- a/gdk/broadway/broadway.js
+++ b/gdk/broadway/broadway.js
@@ -67,25 +67,6 @@ function logStackTrace(len) {
        log(callstack[i]);
 }
 
-function resizeCanvas(canvas, w, h)
-{
-    /* Canvas resize clears the data, so we need to save it first */
-    var tmpCanvas = canvas.ownerDocument.createElement("canvas");
-    tmpCanvas.width = canvas.width;
-    tmpCanvas.height = canvas.height;
-    var tmpContext = tmpCanvas.getContext("2d");
-    tmpContext.globalCompositeOperation = "copy";
-    tmpContext.drawImage(canvas, 0, 0, tmpCanvas.width, tmpCanvas.height);
-
-    canvas.width = w;
-    canvas.height = h;
-
-    var context = canvas.getContext("2d");
-
-    context.globalCompositeOperation = "copy";
-    context.drawImage(tmpCanvas, 0, 0, tmpCanvas.width, tmpCanvas.height);
-}
-
 var grab = new Object();
 grab.window = null;
 grab.ownerEvents = false;
@@ -160,15 +141,15 @@ function cmdCreateSurface(id, x, y, width, height, isTemp)
     surface.visible = false;
     surface.imageData = null;
 
-    var canvas = document.createElement("canvas");
-    canvas.width = width;
-    canvas.height = height;
-    canvas.surface = surface;
-    surface.canvas = canvas;
+    var image = new Image();
+    image.width = width;
+    image.height = height;
+    image.surface = surface;
+    surface.image = image;
     var toplevelElement;
 
-    toplevelElement = canvas;
-    document.body.appendChild(canvas);
+    toplevelElement = image;
+    document.body.appendChild(image);
 
     surface.toplevelElement = toplevelElement;
     toplevelElement.style["position"] = "absolute";
@@ -268,8 +249,8 @@ function cmdDeleteSurface(id)
     var i = stackingOrder.indexOf(surface);
     if (i >= 0)
        stackingOrder.splice(i, 1);
-    var canvas = surface.canvas;
-    canvas.parentNode.removeChild(canvas);
+    var image = surface.image;
+    image.parentNode.removeChild(image);
     delete surfaces[id];
 }
 
@@ -286,15 +267,17 @@ function cmdMoveResizeSurface(id, has_pos, x, y, has_size, w, h)
        surface.height = h;
     }
 
-    if (has_size)
-       resizeCanvas(surface.canvas, w, h);
+    if (has_size) {
+       surface.image.width = w;
+       surface.image.height = h;
+    }
 
     if (surface.visible) {
        if (has_pos) {
            var xOffset = surface.x;
            var yOffset = surface.y;
 
-           var element = surface.canvas;
+           var element = surface.image;
 
            element.style["left"] = xOffset + "px";
            element.style["top"] = yOffset + "px";
@@ -512,21 +495,12 @@ function decodeBuffer(context, oldData, w, h, data, debug)
     return imageData;
 }
 
-function cmdPutBuffer(id, w, h, compressed)
+function cmdWindowUpdate(id, texture_id)
 {
     var surface = surfaces[id];
-    var context = surface.canvas.getContext("2d");
-
-    var inflate = new Zlib.RawInflate(compressed);
-    var data = inflate.decompress();
-
-    var imageData = decodeBuffer (context, surface.imageData, w, h, data, debugDecoding);
-    context.putImageData(imageData, 0, 0);
-
-    if (debugDecoding)
-        imageData = decodeBuffer (context, surface.imageData, w, h, data, false);
+    var texture_url = textures[texture];
 
-    surface.imageData = imageData;
+    surface.image.src = texture_url;
 }
 
 function cmdUploadTexture(id, data)
@@ -631,12 +605,10 @@ function handleCommands(cmd)
            cmdLowerSurface(id);
            break;
 
-       case 'b': // Put image buffer
+       case 'b': // Update window
            id = cmd.get_16();
-           w = cmd.get_16();
-           h = cmd.get_16();
-            var data = cmd.get_data();
-            cmdPutBuffer(id, w, h, data);
+           texture = cmd.get_32();
+            cmdWindowUpdate(id, texture);
             break;
 
        case 't': // Upload texture
diff --git a/gdk/broadway/broadwayd.c b/gdk/broadway/broadwayd.c
index ee0cd5f..2706cc9 100644
--- a/gdk/broadway/broadwayd.c
+++ b/gdk/broadway/broadwayd.c
@@ -225,7 +225,6 @@ client_handle_request (BroadwayClient *client,
   BroadwayReplyQueryMouse reply_query_mouse;
   BroadwayReplyGrabPointer reply_grab_pointer;
   BroadwayReplyUngrabPointer reply_ungrab_pointer;
-  cairo_surface_t *surface;
   guint32 before_serial, now_serial;
   guint32 global_id;
   int fd;
@@ -284,18 +283,11 @@ client_handle_request (BroadwayClient *client,
                                                request->set_transient_for.parent);
       break;
     case BROADWAY_REQUEST_UPDATE:
-      surface = broadway_server_open_surface (server,
-                                             request->update.id,
-                                             request->update.name,
-                                             request->update.width,
-                                             request->update.height);
-      if (surface != NULL)
-       {
-         broadway_server_window_update (server,
-                                        request->update.id,
-                                        surface);
-         cairo_surface_destroy (surface);
-       }
+      global_id = GPOINTER_TO_INT (g_hash_table_lookup (client->textures,
+                                                       GINT_TO_POINTER (request->update.texture)));
+      broadway_server_window_update (server,
+                                    request->update.id,
+                                    global_id);
       break;
     case BROADWAY_REQUEST_UPLOAD_TEXTURE:
       if (client->fds == NULL)
diff --git a/gdk/broadway/gdkbroadway-server.c b/gdk/broadway/gdkbroadway-server.c
index 2ee75ab..4023833 100644
--- a/gdk/broadway/gdkbroadway-server.c
+++ b/gdk/broadway/gdkbroadway-server.c
@@ -552,229 +552,15 @@ _gdk_broadway_server_window_set_transient_for (GdkBroadwayServer *server,
                                    BROADWAY_REQUEST_SET_TRANSIENT_FOR);
 }
 
-static void *
-map_named_shm (char *name, gsize size, gboolean *is_shm)
-{
-#ifdef G_OS_UNIX
-
-  char *filename = NULL;
-  int fd;
-  void *ptr;
-  int res;
-
-  fd = shm_open(name, O_RDWR|O_CREAT|O_EXCL, 0600);
-  if (fd == -1)
-    {
-      if (errno == EEXIST)
-       return NULL;
-
-      filename = g_build_filename (g_get_tmp_dir (), name, NULL);
-
-      fd = open (filename, O_RDWR | O_CREAT | O_EXCL, 0600);
-      g_free (filename);
-      if (fd == -1)
-       {
-         if (errno != EEXIST)
-           g_error ("Unable to allocate shared mem for window");
-         return NULL;
-       }
-      else
-       *is_shm = FALSE;
-    }
-  else
-    *is_shm = TRUE;
-
-  res = ftruncate (fd, size);
-  g_assert (res != -1);
-
-#ifdef HAVE_POSIX_FALLOCATE
-  res = posix_fallocate (fd, 0, size);
-  if (res != 0 && errno == ENOSPC)
-    {
-      if (filename)
-       unlink (filename);
-      else
-       shm_unlink (name);
-      g_error ("Not enough shared memory for window surface");
-    }
-#endif
-
-  ptr = mmap(0, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
-
-  (void) close(fd);
-
-  return ptr;
-
-#elif defined(G_OS_WIN32)
-
-  int fd;
-  void *ptr;
-  char *shmpath;
-  void *map = ((void *)-1);
-  int res;
-
-  if (*name == '/')
-    ++name;
-  shmpath = g_build_filename (g_get_tmp_dir (), name, NULL);
-
-  fd = open(shmpath, O_RDWR|O_CREAT|O_EXCL, 0600);
-  g_free (shmpath);
-  if (fd == -1)
-    {
-      if (errno != EEXIST)
-       g_error ("Unable to allocate shared mem for window");
-      return NULL;
-    }
-
-  *is_shm = TRUE;
-  res = ftruncate (fd, size);
-  g_assert (res != -1);
-  
-  if (size == 0)
-    ptr = map;
-  else
-    {
-      HANDLE h, fm;
-      h = (HANDLE)_get_osfhandle (fd);
-      fm = CreateFileMapping (h, NULL, PAGE_READWRITE, 0, (DWORD)size, NULL);
-      ptr = MapViewOfFile (fm, FILE_MAP_WRITE, 0, 0, (size_t)size);
-      CloseHandle (fm);
-    }
-
-  (void) close(fd);
-
-  return ptr;
-
-#else
-#error "No shm mapping supported"
-
-  return NULL;
-#endif
-}
-
-static char
-make_valid_fs_char (char c)
-{
-  char chars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890";
-
-  return chars[c % (sizeof (chars) - 1)];
-}
-
-/* name must have at least space for 34 bytes */
-static gpointer
-create_random_shm (char *name, gsize size, gboolean *is_shm)
-{
-  guint32 r;
-  int i, o;
-  gpointer ptr;
-
-  while (TRUE)
-    {
-      o = 0;
-      name[o++] = '/';
-      name[o++] = 'b';
-      name[o++] = 'd';
-      name[o++] = 'w';
-      name[o++] = '-';
-      for (i = 0; i < 32/4 - 1; i++)
-       {
-         r = g_random_int ();
-         name[o++] = make_valid_fs_char ((r >> 0) & 0xff);
-         name[o++] = make_valid_fs_char ((r >> 8) & 0xff);
-         name[o++] = make_valid_fs_char ((r >> 16) & 0xff);
-         name[o++] = make_valid_fs_char ((r >> 24) & 0xff);
-       }
-      name[o++] = 0;
-
-      ptr = map_named_shm (name, size, is_shm);
-      if (ptr)
-       return ptr;
-    }
-}
-
-static const cairo_user_data_key_t gdk_broadway_shm_cairo_key;
-
-typedef struct {
-  char name[36];
-  void *data;
-  gsize data_size;
-  gboolean is_shm;
-} BroadwayShmSurfaceData;
-
-static void
-shm_data_destroy (void *_data)
-{
-  BroadwayShmSurfaceData *data = _data;
-
-#ifdef G_OS_UNIX
-
-  munmap (data->data, data->data_size);
-  if (data->is_shm)
-    shm_unlink (data->name);
-  else
-    {
-      char *filename = g_build_filename (g_get_tmp_dir (), data->name, NULL);
-      unlink (filename);
-      g_free (filename);
-    }
-
-#elif defined(G_OS_WIN32)
-
-  char *name = data->name;
-  char *shmpath;
-
-  if (*name == '/')
-    ++name;
-
-  shmpath = g_build_filename (g_get_tmp_dir (), name, NULL);
-  UnmapViewOfFile (data->data);
-  remove (shmpath);
-  g_free (shmpath);
-
-#endif
-
-  g_free (data);
-}
-
-cairo_surface_t *
-_gdk_broadway_server_create_surface (int                 width,
-                                    int                 height)
-{
-  BroadwayShmSurfaceData *data;
-  cairo_surface_t *surface;
-
-  data = g_new (BroadwayShmSurfaceData, 1);
-  data->data_size = width * height * sizeof (guint32);
-  data->data = create_random_shm (data->name, data->data_size, &data->is_shm);
-
-  surface = cairo_image_surface_create_for_data ((guchar *)data->data,
-                                                CAIRO_FORMAT_ARGB32, width, height, width * sizeof 
(guint32));
-  g_assert (surface != NULL);
-  
-  cairo_surface_set_user_data (surface, &gdk_broadway_shm_cairo_key,
-                              data, shm_data_destroy);
-
-  return surface;
-}
-
 void
 _gdk_broadway_server_window_update (GdkBroadwayServer *server,
                                    gint id,
-                                   cairo_surface_t *surface)
+                                   guint32 texture)
 {
   BroadwayRequestUpdate msg;
-  BroadwayShmSurfaceData *data;
-
-  if (surface == NULL)
-    return;
-
-  data = cairo_surface_get_user_data (surface, &gdk_broadway_shm_cairo_key);
-  g_assert (data != NULL);
 
   msg.id = id;
-  memcpy (msg.name, data->name, 36);
-  msg.width = cairo_image_surface_get_width (surface);
-  msg.height = cairo_image_surface_get_height (surface);
+  msg.texture = texture;
 
   gdk_broadway_server_send_message (server, msg,
                                    BROADWAY_REQUEST_UPDATE);
diff --git a/gdk/broadway/gdkbroadway-server.h b/gdk/broadway/gdkbroadway-server.h
index ea16e55..91554e5 100644
--- a/gdk/broadway/gdkbroadway-server.h
+++ b/gdk/broadway/gdkbroadway-server.h
@@ -63,11 +63,9 @@ guint32             gdk_broadway_server_upload_texture           (GdkBroadwaySer
                                                                   GdkTexture         *texture);
 void                gdk_broadway_server_release_texture          (GdkBroadwayServer  *server,
                                                                   guint32             id);
-cairo_surface_t   *_gdk_broadway_server_create_surface           (int                 width,
-                                                                 int                 height);
 void               _gdk_broadway_server_window_update            (GdkBroadwayServer  *server,
                                                                  gint                id,
-                                                                 cairo_surface_t    *surface);
+                                                                 guint32             texture);
 gboolean           _gdk_broadway_server_window_move_resize       (GdkBroadwayServer  *server,
                                                                  gint                id,
                                                                  gboolean            with_move,
diff --git a/gdk/broadway/gdkdisplay-broadway.c b/gdk/broadway/gdkdisplay-broadway.c
index c5eede1..aa2c0f6 100644
--- a/gdk/broadway/gdkdisplay-broadway.c
+++ b/gdk/broadway/gdkdisplay-broadway.c
@@ -30,6 +30,7 @@
 #include "gdkinternals.h"
 #include "gdkdeviceprivate.h"
 #include "gdkdevicemanager-broadway.h"
+#include <gdk/gdktextureprivate.h>
 
 #include <glib.h>
 #include <glib/gprintf.h>
diff --git a/gdk/broadway/gdkwindow-broadway.c b/gdk/broadway/gdkwindow-broadway.c
index ce02f97..2f05c31 100644
--- a/gdk/broadway/gdkwindow-broadway.c
+++ b/gdk/broadway/gdkwindow-broadway.c
@@ -36,6 +36,7 @@
 #include "gdkinternals.h"
 #include "gdkdeviceprivate.h"
 #include "gdkeventsource.h"
+#include <gdk/gdktextureprivate.h>
 
 #include <stdlib.h>
 #include <stdio.h>
@@ -112,11 +113,26 @@ update_dirty_windows_and_sync (void)
 
       if (impl->dirty)
        {
+         GdkTexture *texture;
+         guint32 texture_id;
+
          impl->dirty = FALSE;
          updated_surface = TRUE;
+
+         if (impl->texture_id)
+           gdk_broadway_server_release_texture (display->server, impl->texture_id);
+         impl->texture_id = 0;
+
+         texture = gdk_texture_new_for_surface (impl->surface);
+         texture_id =  gdk_broadway_server_upload_texture (display->server, texture);
+         g_object_unref (texture);
+
+         impl->texture_id = texture_id;
+
          _gdk_broadway_server_window_update (display->server,
                                              impl->id,
-                                             impl->surface);
+                                             texture_id);
+
        }
     }
 
@@ -246,8 +262,9 @@ _gdk_broadway_window_resize_surface (GdkWindow *window)
     {
       cairo_surface_destroy (impl->surface);
 
-      impl->surface = _gdk_broadway_server_create_surface (gdk_window_get_width (impl->wrapper),
-                                                          gdk_window_get_height (impl->wrapper));
+      impl->surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
+                                                 gdk_window_get_width (impl->wrapper),
+                                                 gdk_window_get_height (impl->wrapper));
     }
 
   if (impl->ref_surface)
@@ -283,7 +300,7 @@ gdk_window_broadway_ref_cairo_surface (GdkWindow *window)
 
   /* Create actual backing store if missing */
   if (!impl->surface)
-    impl->surface = _gdk_broadway_server_create_surface (w, h);
+    impl->surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, w, h);
 
   /* Create a destroyable surface referencing the real one */
   if (!impl->ref_surface)
@@ -334,6 +351,9 @@ _gdk_broadway_window_destroy (GdkWindow *window,
   g_hash_table_remove (broadway_display->id_ht, GINT_TO_POINTER (impl->id));
 
   _gdk_broadway_server_destroy_window (broadway_display->server, impl->id);
+  if (impl->texture_id)
+    gdk_broadway_server_release_texture (broadway_display->server, impl->texture_id);
+
 }
 
 /* This function is called when the XWindow is really gone.
diff --git a/gdk/broadway/gdkwindow-broadway.h b/gdk/broadway/gdkwindow-broadway.h
index 5fe7c78..4a2a727 100644
--- a/gdk/broadway/gdkwindow-broadway.h
+++ b/gdk/broadway/gdkwindow-broadway.h
@@ -55,6 +55,7 @@ struct _GdkWindowImplBroadway
   GdkCursor *cursor;
 
   int id;
+  int texture_id;
 
   gboolean visible;
   gboolean maximized;
diff --git a/gdk/broadway/meson.build b/gdk/broadway/meson.build
index 4534a9d..70b11a2 100644
--- a/gdk/broadway/meson.build
+++ b/gdk/broadway/meson.build
@@ -1,5 +1,4 @@
 gdk_broadway_sources = files([
-  'broadway-buffer.c',
   'broadway-output.c',
   'broadway-server.c',
   'broadwayd.c',
@@ -60,7 +59,7 @@ broadwayjs_h = custom_target('broadwayjs.h',
 
 executable('gtk4-broadwayd',
   clienthtml_h, broadwayjs_h,
-  'broadwayd.c', 'broadway-server.c', 'broadway-buffer.c', 'broadway-output.c',
+  'broadwayd.c', 'broadway-server.c', 'broadway-output.c',
   include_directories: [confinc, gdkinc],
   c_args: ['-DGDK_COMPILATION', '-DG_LOG_DOMAIN="Gdk"', ],
   dependencies : [broadwayd_syslib, gdk_deps],


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