[gtk+] [broadway] Combine window move and resize into one op



commit f4bef2c7207dd0d238f0547479998d794433b74c
Author: Alexander Larsson <alexl redhat com>
Date:   Tue Apr 12 11:11:36 2011 +0200

    [broadway] Combine window move and resize into one op
    
    This way we avoid sending a configure event for the inbetween state
    if we're resizeing and moving at the same time.

 gdk/broadway/broadway-demo.c      |    2 +-
 gdk/broadway/broadway.c           |   54 ++++++++++--------
 gdk/broadway/broadway.h           |   16 +++---
 gdk/broadway/broadway.js          |  110 ++++++++++++++++++-------------------
 gdk/broadway/gdkwindow-broadway.c |   26 ++++-----
 5 files changed, 104 insertions(+), 104 deletions(-)
---
diff --git a/gdk/broadway/broadway-demo.c b/gdk/broadway/broadway-demo.c
index 70c5ff9..0ce3081 100644
--- a/gdk/broadway/broadway-demo.c
+++ b/gdk/broadway/broadway-demo.c
@@ -186,7 +186,7 @@ demo2 (BroadwayOutput *output)
 	  broadway_output_put_rgba (output, 0, 0, 0, 800, 600, 800*4,
 				    cairo_image_surface_get_data(old_surface));
 	}
-      broadway_output_move_surface (output, 0, 100 + i, 100 + i);
+      broadway_output_move_resize_surface (output, 0, 1, 100 + i, 100 + i, 0, 0, 0);
 
       rects[0].x = 500;
       rects[0].y = 0;
diff --git a/gdk/broadway/broadway.c b/gdk/broadway/broadway.c
index 493efb8..3917145 100644
--- a/gdk/broadway/broadway.c
+++ b/gdk/broadway/broadway.c
@@ -747,38 +747,42 @@ broadway_output_destroy_surface(BroadwayOutput *output,  int id)
   broadway_output_write (output, buf, sizeof (buf));
 }
 
-void
-broadway_output_move_surface(BroadwayOutput *output,  int id, int x, int y)
-{
-  char buf[HEADER_LEN + 9];
-  int p;
-
-  p = write_header (output, buf, 'm');
-
-  append_uint16 (id, buf, &p);
-  append_uint16 (x, buf, &p);
-  append_uint16 (y, buf, &p);
-
-  assert (p == sizeof (buf));
-
-  broadway_output_write (output, buf, sizeof (buf));
-}
 
 void
-broadway_output_resize_surface(BroadwayOutput *output,  int id, int w, int h)
+broadway_output_move_resize_surface (BroadwayOutput *output,
+				     int             id,
+				     gboolean        has_pos,
+				     int             x,
+				     int             y,
+				     gboolean        has_size,
+				     int             w,
+				     int             h)
 {
-  char buf[HEADER_LEN + 9];
+  char buf[HEADER_LEN+3+1+6+6];
   int p;
+  int val;
 
-  p = write_header (output, buf, 'r');
+  if (!has_pos && !has_size)
+    return;
 
-  append_uint16 (id, buf, &p);
-  append_uint16 (w, buf, &p);
-  append_uint16 (h, buf, &p);
+  p = write_header (output, buf, 'm');
 
-  assert (p == sizeof (buf));
+  val = (!!has_pos) | ((!!has_size) << 1);
+  append_uint16 (id, buf, &p);
+  buf[p++] = val + '0';
+  if (has_pos)
+    {
+      append_uint16 (x, buf, &p);
+      append_uint16 (y, buf, &p);
+    }
+  if (has_size)
+    {
+      append_uint16 (w, buf, &p);
+      append_uint16 (h, buf, &p);
+    }
+  assert (p <= sizeof (buf));
 
-  broadway_output_write (output, buf, sizeof (buf));
+  broadway_output_write (output, buf, p);
 }
 
 void
diff --git a/gdk/broadway/broadway.h b/gdk/broadway/broadway.h
index 86df4df..fce53a3 100644
--- a/gdk/broadway/broadway.h
+++ b/gdk/broadway/broadway.h
@@ -26,14 +26,14 @@ void            broadway_output_hide_surface    (BroadwayOutput *output,
 						 int             id);
 void            broadway_output_destroy_surface (BroadwayOutput *output,
 						 int             id);
-void            broadway_output_move_surface    (BroadwayOutput *output,
-						 int             id,
-						 int             x,
-						 int             y);
-void            broadway_output_resize_surface  (BroadwayOutput *output,
-						 int             id,
-						 int             w,
-						 int             h);
+void            broadway_output_move_resize_surface (BroadwayOutput *output,
+						     int             id,
+						     gboolean        has_pos,
+						     int             x,
+						     int             y,
+						     gboolean        has_size,
+						     int             w,
+						     int             h);
 void            broadway_output_set_transient_for (BroadwayOutput *output,
 						   int             id,
 						   int             parent_id);
diff --git a/gdk/broadway/broadway.js b/gdk/broadway/broadway.js
index e7bf513..c5f202d 100644
--- a/gdk/broadway/broadway.js
+++ b/gdk/broadway/broadway.js
@@ -638,12 +638,21 @@ function cmdDeleteSurface(id)
     delete surfaces[id];
 }
 
-function cmdMoveSurface(id, x, y)
+function cmdMoveResizeSurface(id, has_pos, x, y, has_size, w, h)
 {
     var surface = surfaces[id];
-    surface.positioned = true;
-    surface.x = x;
-    surface.y = y;
+    if (has_pos) {
+	surface.positioned = true;
+	surface.x = x;
+	surface.y = y;
+    }
+    if (has_size) {
+	surface.width = w;
+	surface.height = h;
+    }
+
+    /* Flush any outstanding draw ops before (possibly) changing size */
+    flushSurface(surface);
 
     if (surface.visible) {
 	if (surface.window) {
@@ -651,51 +660,39 @@ function cmdMoveSurface(id, x, y)
 	     * However this isn't *strictly* invalid, as any WM could have done whatever it
 	     * wanted with the positioning of the window.
 	     */
-	    surface.window.moveTo(surface.x, surface.y);
+	    if (has_pos)
+		surface.window.moveTo(surface.x, surface.y);
+	    if (has_size)
+		resizeBrowserWindow(surface.window, w, h);
 	} else {
-	    var xOffset = surface.x;
-	    var yOffset = surface.y;
+	    if (has_size)
+		resizeCanvas(surface.canvas, w, h);
 
-	    var transientToplevel = getTransientToplevel(surface);
-	    if (transientToplevel) {
-		xOffset = surface.x - transientToplevel.x;
-		yOffset = surface.y - transientToplevel.y;
-	    }
+	    if (has_pos) {
+		var xOffset = surface.x;
+		var yOffset = surface.y;
 
-	    var element = surface.canvas;
-	    if (surface.frame) {
-		element = surface.frame;
-		var offset = getFrameOffset(surface);
-		xOffset -= offset.x;
-		yOffset -= offset.y;
-	    }
+		var transientToplevel = getTransientToplevel(surface);
+		if (transientToplevel) {
+		    xOffset = surface.x - transientToplevel.x;
+		    yOffset = surface.y - transientToplevel.y;
+		}
 
-	    element.style["left"] = xOffset + "px";
-	    element.style["top"] = yOffset + "px";
-	}
-    }
+		var element = surface.canvas;
+		if (surface.frame) {
+		    element = surface.frame;
+		    var offset = getFrameOffset(surface);
+		    xOffset -= offset.x;
+		    yOffset -= offset.y;
+		}
 
-    if (surface.window) {
-	updateBrowserWindowGeometry(surface.window, true);
-    } else {
-	sendConfigureNotify(surface);
+		element.style["left"] = xOffset + "px";
+		element.style["top"] = yOffset + "px";
+	    }
+	}
     }
-}
-
-function cmdResizeSurface(id, w, h)
-{
-    var surface = surfaces[id];
-
-    surface.width = w;
-    surface.height = h;
-
-    /* Flush any outstanding draw ops before changing size */
-    flushSurface(surface);
-
-    resizeCanvas(surface.canvas, w, h);
 
     if (surface.window) {
-	resizeBrowserWindow(surface.window, w, h);
 	updateBrowserWindowGeometry(surface.window, true);
     } else {
 	sendConfigureNotify(surface);
@@ -776,21 +773,22 @@ function handleCommands(cmdObj)
 	case 'm': // Move a surface
 	    id = base64_16(cmd, i);
 	    i = i + 3;
-	    x = base64_16(cmd, i);
-	    i = i + 3;
-	    y = base64_16(cmd, i);
-	    i = i + 3;
-	    cmdMoveSurface(id, x, y);
-	    break;
-
-	case 'r': // Resize a surface
-	    id = base64_16(cmd, i);
-	    i = i + 3;
-	    w = base64_16(cmd, i);
-	    i = i + 3;
-	    h = base64_16(cmd, i);
-	    i = i + 3;
-	    cmdResizeSurface(id, w, h);
+	    var ops = cmd.charCodeAt(i++) - 48;
+	    var has_pos = ops & 1;
+	    if (has_pos) {
+		x = base64_16s(cmd, i);
+		i = i + 3;
+		y = base64_16s(cmd, i);
+		i = i + 3;
+	    }
+	    var has_size = ops & 2;
+	    if (has_size) {
+		w = base64_16(cmd, i);
+		i = i + 3;
+		h = base64_16(cmd, i);
+		i = i + 3;
+	    }
+	    cmdMoveResizeSurface(id, has_pos, x, y, has_size, w, h);
 	    break;
 
 	case 'i': // Put image data surface
diff --git a/gdk/broadway/gdkwindow-broadway.c b/gdk/broadway/gdkwindow-broadway.c
index 34a1ae6..6b0a713 100644
--- a/gdk/broadway/gdkwindow-broadway.c
+++ b/gdk/broadway/gdkwindow-broadway.c
@@ -598,6 +598,7 @@ gdk_window_broadway_move_resize (GdkWindow *window,
   GdkWindowImplBroadway *impl = GDK_WINDOW_IMPL_BROADWAY (window->impl);
   GdkBroadwayDisplay *broadway_display;
   gboolean changed;
+  gboolean with_resize;
 
   changed = FALSE;
 
@@ -607,17 +608,12 @@ gdk_window_broadway_move_resize (GdkWindow *window,
       changed = TRUE;
       window->x = x;
       window->y = y;
-      if (broadway_display->output != NULL)
-	{
-	  broadway_output_move_surface (broadway_display->output,
-					impl->id, x, y);
-	  queue_dirty_flush (broadway_display);
-	}
     }
 
-
+  with_resize = FALSE;
   if (width > 0 || height > 0)
     {
+      with_resize = TRUE;
       if (width < 1)
 	width = 1;
 
@@ -633,13 +629,6 @@ gdk_window_broadway_move_resize (GdkWindow *window,
 	  impl->dirty = TRUE;
 	  impl->last_synced = FALSE;
 
-	  if (broadway_display->output != NULL)
-	    {
-	      broadway_output_resize_surface (broadway_display->output,
-					      impl->id, width, height);
-	      queue_dirty_flush (broadway_display);
-	    }
-
 	  window->width = width;
 	  window->height = height;
 	  _gdk_broadway_window_resize_surface (window);
@@ -651,6 +640,15 @@ gdk_window_broadway_move_resize (GdkWindow *window,
       GdkEvent *event;
       GList *node;
 
+      if (broadway_display->output != NULL)
+	{
+	  broadway_output_move_resize_surface (broadway_display->output,
+					       impl->id,
+					       with_move, window->x, window->y,
+					       with_resize, window->width, window->height);
+	  queue_dirty_flush (broadway_display);
+	}
+
       event = gdk_event_new (GDK_CONFIGURE);
       event->configure.window = g_object_ref (window);
       event->configure.x = window->x;



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