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

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