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

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