[mutter] clutter/stage: Set viewport without getting the last allocation



commit 7abf0f1e2da0748efa2a412c2e8cf8fe18c09388
Author: Jonas Dreßler <verdre v0yd nl>
Date:   Sun May 10 01:23:34 2020 +0200

    clutter/stage: Set viewport without getting the last allocation
    
    When getting the last allocation using
    clutter_actor_get_allocation_box(), Clutter will do an immediate
    relayout of the stage in case an actor has an invalid allocation. Since
    the allocation is always invalid when the allocate() vfunc is called,
    clutter_stage_allocate() always forces another allocation cycle.
    
    To fix that, stop comparing the old allocation to the new one to find
    out whether the viewport changed, but instead use the existing check in
    _clutter_stage_set_viewport() and implement the behavior of rounding the
    viewport to the nearest int using roundf() (which should behave just as
    CLUTTER_NEARBYINT()) since we're passing around floats anyway.
    
    https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1247

 clutter/clutter/clutter-stage.c | 30 +++++++-----------------------
 1 file changed, 7 insertions(+), 23 deletions(-)
---
diff --git a/clutter/clutter/clutter-stage.c b/clutter/clutter/clutter-stage.c
index 540f9a1b78..686152329c 100644
--- a/clutter/clutter/clutter-stage.c
+++ b/clutter/clutter/clutter-stage.c
@@ -619,7 +619,6 @@ clutter_stage_allocate (ClutterActor           *self,
 {
   ClutterStagePrivate *priv = CLUTTER_STAGE (self)->priv;
   ClutterActorBox alloc = CLUTTER_ACTOR_BOX_INIT_ZERO;
-  float old_width, old_height;
   float new_width, new_height;
   float width, height;
   cairo_rectangle_int_t window_size;
@@ -628,10 +627,6 @@ clutter_stage_allocate (ClutterActor           *self,
   if (priv->impl == NULL)
     return;
 
-  /* our old allocation */
-  clutter_actor_get_allocation_box (self, &alloc);
-  clutter_actor_box_get_size (&alloc, &old_width, &old_height);
-
   /* the current allocation */
   clutter_actor_box_get_size (box, &width, &height);
 
@@ -719,27 +714,14 @@ clutter_stage_allocate (ClutterActor           *self,
                                        &override);
     }
 
-  /* reset the viewport if the allocation effectively changed */
+  /* set the viewport to the new allocation */
   clutter_actor_get_allocation_box (self, &alloc);
   clutter_actor_box_get_size (&alloc, &new_width, &new_height);
 
-  if (CLUTTER_NEARBYINT (old_width) != CLUTTER_NEARBYINT (new_width) ||
-      CLUTTER_NEARBYINT (old_height) != CLUTTER_NEARBYINT (new_height))
-    {
-      int real_width = CLUTTER_NEARBYINT (new_width);
-      int real_height = CLUTTER_NEARBYINT (new_height);
-
-      _clutter_stage_set_viewport (CLUTTER_STAGE (self),
-                                   0, 0,
-                                   real_width,
-                                   real_height);
-
-      /* Note: we don't assume that set_viewport will queue a full redraw
-       * since it may bail-out early if something preemptively set the
-       * viewport before the stage was really allocated its new size.
-       */
-      queue_full_redraw (CLUTTER_STAGE (self));
-    }
+  _clutter_stage_set_viewport (CLUTTER_STAGE (self),
+                               0, 0,
+                               new_width,
+                               new_height);
 }
 
 typedef struct _Vector4
@@ -2494,6 +2476,8 @@ _clutter_stage_set_viewport (ClutterStage *stage,
 
   priv = stage->priv;
 
+  width = roundf (width);
+  height = roundf (height);
 
   if (x == priv->viewport[0] &&
       y == priv->viewport[1] &&


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