Blame SOURCES/0001-compositor-Don-t-emit-size-changed-when-only-positio.patch

9501a8
From a8d0870c6e9c9d2269c2b856cd2d83949fef4154 Mon Sep 17 00:00:00 2001
9501a8
From: Daniel van Vugt <daniel.van.vugt@canonical.com>
9501a8
Date: Tue, 7 May 2019 18:08:13 +0800
9501a8
Subject: [PATCH 1/2] compositor: Don't emit size-changed when only position
9501a8
 changes
9501a8
9501a8
Waking up gnome-shell and triggering JavaScript listeners of
9501a8
`size-changed` every time a window was only moved was wasting a lot
9501a8
of CPU.
9501a8
9501a8
This cuts the CPU requirement for dragging windows by around 22%.
9501a8
9501a8
https://gitlab.gnome.org/GNOME/mutter/merge_requests/568
9501a8
---
9501a8
 src/compositor/compositor.c                |  8 +++-
9501a8
 src/compositor/meta-window-actor-private.h | 12 +++++-
9501a8
 src/compositor/meta-window-actor.c         | 43 ++++++++++++++++++----
9501a8
 3 files changed, 52 insertions(+), 11 deletions(-)
9501a8
9501a8
diff --git a/src/compositor/compositor.c b/src/compositor/compositor.c
9501a8
index 8c924d256..abf7de57d 100644
9501a8
--- a/src/compositor/compositor.c
9501a8
+++ b/src/compositor/compositor.c
9501a8
@@ -1070,8 +1070,12 @@ meta_compositor_sync_window_geometry (MetaCompositor *compositor,
9501a8
                                       gboolean did_placement)
9501a8
 {
9501a8
   MetaWindowActor *window_actor = META_WINDOW_ACTOR (meta_window_get_compositor_private (window));
9501a8
-  meta_window_actor_sync_actor_geometry (window_actor, did_placement);
9501a8
-  meta_plugin_manager_event_size_changed (compositor->plugin_mgr, window_actor);
9501a8
+  MetaWindowActorChanges changes;
9501a8
+
9501a8
+  changes = meta_window_actor_sync_actor_geometry (window_actor, did_placement);
9501a8
+
9501a8
+  if (changes & META_WINDOW_ACTOR_CHANGE_SIZE)
9501a8
+    meta_plugin_manager_event_size_changed (compositor->plugin_mgr, window_actor);
9501a8
 }
9501a8
 
9501a8
 static void
9501a8
diff --git a/src/compositor/meta-window-actor-private.h b/src/compositor/meta-window-actor-private.h
9501a8
index ce5e7eadc..acd649d07 100644
9501a8
--- a/src/compositor/meta-window-actor-private.h
9501a8
+++ b/src/compositor/meta-window-actor-private.h
9501a8
@@ -12,6 +12,12 @@
9501a8
 
9501a8
 MetaWindowActor *meta_window_actor_new (MetaWindow *window);
9501a8
 
9501a8
+typedef enum
9501a8
+{
9501a8
+  META_WINDOW_ACTOR_CHANGE_SIZE     = 1 << 0,
9501a8
+  META_WINDOW_ACTOR_CHANGE_POSITION = 1 << 1
9501a8
+} MetaWindowActorChanges;
9501a8
+
9501a8
 void meta_window_actor_queue_destroy   (MetaWindowActor *self);
9501a8
 
9501a8
 void meta_window_actor_show (MetaWindowActor *self,
9501a8
@@ -43,8 +49,10 @@ void     meta_window_actor_set_unredirected    (MetaWindowActor *self,
9501a8
                                                 gboolean         unredirected);
9501a8
 
9501a8
 gboolean meta_window_actor_effect_in_progress  (MetaWindowActor *self);
9501a8
-void     meta_window_actor_sync_actor_geometry (MetaWindowActor *self,
9501a8
-                                                gboolean         did_placement);
9501a8
+
9501a8
+MetaWindowActorChanges meta_window_actor_sync_actor_geometry (MetaWindowActor *self,
9501a8
+                                                              gboolean         did_placement);
9501a8
+
9501a8
 void     meta_window_actor_update_shape        (MetaWindowActor *self);
9501a8
 void     meta_window_actor_update_opacity      (MetaWindowActor *self);
9501a8
 void     meta_window_actor_mapped              (MetaWindowActor *self);
9501a8
diff --git a/src/compositor/meta-window-actor.c b/src/compositor/meta-window-actor.c
9501a8
index 120b0432c..afe2bab6e 100644
9501a8
--- a/src/compositor/meta-window-actor.c
9501a8
+++ b/src/compositor/meta-window-actor.c
9501a8
@@ -1299,12 +1299,14 @@ meta_window_actor_queue_destroy (MetaWindowActor *self)
9501a8
     clutter_actor_destroy (CLUTTER_ACTOR (self));
9501a8
 }
9501a8
 
9501a8
-void
9501a8
+MetaWindowActorChanges
9501a8
 meta_window_actor_sync_actor_geometry (MetaWindowActor *self,
9501a8
                                        gboolean         did_placement)
9501a8
 {
9501a8
   MetaWindowActorPrivate *priv = self->priv;
9501a8
   MetaRectangle window_rect;
9501a8
+  ClutterActor *actor = CLUTTER_ACTOR (self);
9501a8
+  MetaWindowActorChanges changes = 0;
9501a8
 
9501a8
   meta_window_get_buffer_rect (priv->window, &window_rect);
9501a8
 
9501a8
@@ -1322,15 +1324,42 @@ meta_window_actor_sync_actor_geometry (MetaWindowActor *self,
9501a8
    * updates.
9501a8
    */
9501a8
   if (is_frozen (self) && !did_placement)
9501a8
-    return;
9501a8
+    return META_WINDOW_ACTOR_CHANGE_POSITION | META_WINDOW_ACTOR_CHANGE_SIZE;
9501a8
 
9501a8
   if (meta_window_actor_effect_in_progress (self))
9501a8
-    return;
9501a8
+    return META_WINDOW_ACTOR_CHANGE_POSITION | META_WINDOW_ACTOR_CHANGE_SIZE;
9501a8
+
9501a8
+  if (clutter_actor_has_allocation (actor))
9501a8
+    {
9501a8
+      ClutterActorBox box;
9501a8
+      float old_x, old_y;
9501a8
+      float old_width, old_height;
9501a8
+
9501a8
+      clutter_actor_get_allocation_box (actor, &box);
9501a8
+
9501a8
+      old_x = box.x1;
9501a8
+      old_y = box.y1;
9501a8
+      old_width = box.x2 - box.x1;
9501a8
+      old_height = box.y2 - box.y1;
9501a8
+
9501a8
+      if (old_x != window_rect.x || old_y != window_rect.y)
9501a8
+        changes |= META_WINDOW_ACTOR_CHANGE_POSITION;
9501a8
+
9501a8
+      if (old_width != window_rect.width || old_height != window_rect.height)
9501a8
+        changes |= META_WINDOW_ACTOR_CHANGE_SIZE;
9501a8
+    }
9501a8
+  else
9501a8
+    {
9501a8
+      changes = META_WINDOW_ACTOR_CHANGE_POSITION | META_WINDOW_ACTOR_CHANGE_SIZE;
9501a8
+    }
9501a8
+
9501a8
+  if (changes & META_WINDOW_ACTOR_CHANGE_POSITION)
9501a8
+    clutter_actor_set_position (actor, window_rect.x, window_rect.y);
9501a8
+
9501a8
+  if (changes & META_WINDOW_ACTOR_CHANGE_SIZE)
9501a8
+    clutter_actor_set_size (actor, window_rect.width, window_rect.height);
9501a8
 
9501a8
-  clutter_actor_set_position (CLUTTER_ACTOR (self),
9501a8
-                              window_rect.x, window_rect.y);
9501a8
-  clutter_actor_set_size (CLUTTER_ACTOR (self),
9501a8
-                          window_rect.width, window_rect.height);
9501a8
+  return changes;
9501a8
 }
9501a8
 
9501a8
 void
9501a8
-- 
9501a8
2.21.0
9501a8