[NUI] Improve LayoutController.Process performance (#2755)
authorhuiyueun <35286162+huiyueun@users.noreply.github.com>
Mon, 22 Mar 2021 01:20:07 +0000 (10:20 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Tue, 30 Mar 2021 06:51:02 +0000 (15:51 +0900)
Signed-off-by: huiyu.eun <huiyu.eun@samsung.com>
src/Tizen.NUI/src/internal/Layouting/LayoutController.cs
src/Tizen.NUI/src/public/BaseComponents/View.cs
src/Tizen.NUI/src/public/Layouting/AbsoluteLayout.cs
src/Tizen.NUI/src/public/Layouting/FlexLayout.cs
src/Tizen.NUI/src/public/Layouting/LayoutGroup.cs

index 30915d6..ca6e17e 100755 (executable)
@@ -161,61 +161,56 @@ namespace Tizen.NUI
 
         // Traverse the tree looking for a root node that is a layout.
         // Once found, it's children can be assigned Layouts and the Measure process started.
-        private void FindRootLayouts(View rootNode)
+        private void FindRootLayouts(View rootNode, float parentWidth, float parentHeight)
         {
             if (rootNode.Layout != null)
             {
                 NUILog.Debug("LayoutController Root found:" + rootNode.Name);
                 // rootNode has a layout, start measuring and layouting from here.
-                MeasureAndLayout(rootNode);
+                MeasureAndLayout(rootNode, parentWidth, parentHeight);
             }
             else
             {
+                float rootWidth = rootNode.SizeWidth;
+                float rootHeight = rootNode.SizeHeight;
                 // Search children of supplied node for a layout.
                 for (uint i = 0; i < rootNode.ChildCount; i++)
                 {
                     View view = rootNode.GetChildAt(i);
-                    FindRootLayouts(view);
+                    FindRootLayouts(view, rootWidth, rootHeight);
                 }
             }
         }
 
         // Starts of the actual measuring and layouting from the given root node.
         // Can be called from multiple starting roots but in series.
-        void MeasureAndLayout(View root)
+        // Get parent View's Size.  If using Legacy size negotiation then should have been set already.
+        // Parent not a View so assume it's a Layer which is the size of the window.
+        void MeasureAndLayout(View root, float parentWidth, float parentHeight)
         {
-            if (root != null)
+            float positionX = root.PositionX;
+            float positionY = root.PositionY;
+
+            // Determine measure specification for root.
+            // The root layout policy could be an exact size, be match parent or wrap children.
+            // If wrap children then at most it can be the root parent size.
+            // If match parent then should be root parent size.
+            // If exact then should be that size limited by the root parent size.
+            MeasureSpecification parentWidthSpecification = CreateMeasureSpecification(parentWidth, root.WidthSpecification);
+            MeasureSpecification parentHeightSpecification = CreateMeasureSpecification(parentHeight, root.HeightSpecification);
+
+            // Start at root with it's parent's widthSpecification and heightSpecification
+            MeasureHierarchy(root, parentWidthSpecification, parentHeightSpecification);
+
+            // Start at root which was just measured.
+            PerformLayout(root, new LayoutLength(positionX),
+                                 new LayoutLength(positionY),
+                                 new LayoutLength(positionX) + root.Layout.MeasuredWidth.Size,
+                                 new LayoutLength(positionY) + root.Layout.MeasuredHeight.Size);
+
+            if (SetupCoreAnimation() && OverrideCoreAnimation == false)
             {
-                // Get parent MeasureSpecification, this could be the Window or View with an exact size.
-                Container parentNode = root.GetParent();
-                Position rootPosition = root.Position2D;
-
-                // Get parent View's Size.  If using Legacy size negotiation then should have been set already.
-                // Parent not a View so assume it's a Layer which is the size of the window.
-                View parentView = parentNode as View;
-                Size rootSize = parentView ? new Size(parentView.Size2D) : new Size(window.Size);
-
-                // Determine measure specification for root.
-                // The root layout policy could be an exact size, be match parent or wrap children.
-                // If wrap children then at most it can be the root parent size.
-                // If match parent then should be root parent size.
-                // If exact then should be that size limited by the root parent size.
-                MeasureSpecification parentWidthSpecification = CreateMeasureSpecification(rootSize.Width, root.WidthSpecification);
-                MeasureSpecification parentHeightSpecification = CreateMeasureSpecification(rootSize.Height, root.HeightSpecification);
-
-                // Start at root with it's parent's widthSpecification and heightSpecification
-                MeasureHierarchy(root, parentWidthSpecification, parentHeightSpecification);
-
-                // Start at root which was just measured.
-                PerformLayout(root, new LayoutLength(rootPosition.X),
-                                     new LayoutLength(rootPosition.Y),
-                                     new LayoutLength(rootPosition.X) + root.Layout.MeasuredWidth.Size,
-                                     new LayoutLength(rootPosition.Y) + root.Layout.MeasuredHeight.Size);
-
-                if (SetupCoreAnimation() && OverrideCoreAnimation == false)
-                {
-                    PlayAnimation();
-                }
+                PlayAnimation();
             }
         }
 
@@ -242,21 +237,19 @@ namespace Tizen.NUI
         /// </summary>
         private void Process(int id)
         {
+            Vector2 windowSize = window.GetSize();
+            float width = windowSize.Width;
+            float height = windowSize.Height;
             // First layer in the Window should be the default layer (index 0 )
-            uint numberOfLayers = window.LayerCount;
-            for (uint layerIndex = 0; layerIndex < numberOfLayers; layerIndex++)
+            foreach (Layer layer in window.LayersChildren)
             {
-                Layer layer = window.GetLayer(layerIndex);
-                if (layer != null)
+                foreach (View view in layer.Children)
                 {
-                    for (uint i = 0; i < layer.ChildCount; i++)
-                    {
-                        View view = layer.GetChildAt(i);
-                        FindRootLayouts(view);
-                    }
+                    FindRootLayouts(view, width, height);
                 }
             }
-
+            windowSize.Dispose();
+            windowSize = null;
         }
 
         /// <summary>
@@ -269,11 +262,7 @@ namespace Tizen.NUI
             // No -  reached leaf or no layouts set
             //
             // If in a leaf View with no layout, it's natural size is bubbled back up.
-
-            if (root.Layout != null)
-            {
-                root.Layout.Measure(widthSpec, heightSpec);
-            }
+            root.Layout?.Measure(widthSpec, heightSpec);
         }
 
         /// <summary>
@@ -281,10 +270,7 @@ namespace Tizen.NUI
         /// </summary>
         private void PerformLayout(View root, LayoutLength left, LayoutLength top, LayoutLength right, LayoutLength bottom)
         {
-            if (root.Layout != null)
-            {
-                root.Layout.Layout(left, top, right, bottom);
-            }
+            root.Layout?.Layout(left, top, right, bottom);
         }
 
         /// <summary>
index c10764b..e7aa1fd 100755 (executable)
@@ -2453,18 +2453,20 @@ namespace Tizen.NUI.BaseComponents
                     // Do not try to set Margins or Padding on a null Layout (when a layout is being removed from a View)
                     if (value != null)
                     {
-                        if (Margin.Top != 0 || Margin.Bottom != 0 || Margin.Start != 0 || Margin.End != 0)
+                        Extents margin = Margin;
+                        Extents padding = Padding;
+                        if (margin.Top != 0 || margin.Bottom != 0 || margin.Start != 0 || margin.End != 0)
                         {
                             // If View already has a margin set then store it in Layout instead.
-                            value.Margin = Margin;
+                            value.Margin = margin;
                             SetValue(MarginProperty, new Extents(0, 0, 0, 0));
                             NotifyPropertyChanged();
                         }
 
-                        if (Padding.Top != 0 || Padding.Bottom != 0 || Padding.Start != 0 || Padding.End != 0)
+                        if (padding.Top != 0 || padding.Bottom != 0 || padding.Start != 0 || padding.End != 0)
                         {
                             // If View already has a padding set then store it in Layout instead.
-                            value.Padding = Padding;
+                            value.Padding = padding;
 
                             // If Layout is a LayoutItem then it could be a View that handles it's own padding.
                             // Let the View keeps it's padding.  Still store Padding in Layout to reduce code paths.
index 7a96f7e..08e55f0 100755 (executable)
@@ -52,9 +52,8 @@ namespace Tizen.NUI
 
                 // Determine the width and height needed by the children using their given position and size.
                 // Children could overlap so find the right most child.
-                Position2D childPosition = childLayout.Owner.Position2D;
-                float childRight = childLayout.MeasuredWidth.Size.AsDecimal() + childPosition.X;
-                float childBottom = childLayout.MeasuredHeight.Size.AsDecimal() + childPosition.Y;
+                float childRight = childLayout.MeasuredWidth.Size.AsDecimal() + childLayout.Owner.PositionX;
+                float childBottom = childLayout.MeasuredHeight.Size.AsDecimal() + childLayout.Owner.PositionY;
 
                 if (maxWidth < childRight)
                     maxWidth = childRight;
@@ -94,10 +93,8 @@ namespace Tizen.NUI
                 LayoutLength childWidth = childLayout.MeasuredWidth.Size;
                 LayoutLength childHeight = childLayout.MeasuredHeight.Size;
 
-                Position2D childPosition = childLayout.Owner.Position2D;
-
-                LayoutLength childLeft = new LayoutLength(childPosition.X);
-                LayoutLength childTop = new LayoutLength(childPosition.Y);
+                LayoutLength childLeft = new LayoutLength(childLayout.Owner.PositionX);
+                LayoutLength childTop = new LayoutLength(childLayout.Owner.PositionY);
 
                 childLayout.Layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight, true);
             }
index 577cec2..311152c 100755 (executable)
@@ -650,17 +650,18 @@ namespace Tizen.NUI
             }
 
             LayoutItem childLayout = child.Layout;
+            Extents margin = child.Margin;
 
             MeasureSpecification childWidthMeasureSpec = GetChildMeasureSpecification(
                                     new MeasureSpecification(
-                                        new LayoutLength(parentMeasureSpecificationWidth.Size - (child.Margin.Start + child.Margin.End)),
+                                        new LayoutLength(parentMeasureSpecificationWidth.Size - (margin.Start + margin.End)),
                                         parentMeasureSpecificationWidth.Mode),
                                     new LayoutLength(Padding.Start + Padding.End),
                                     new LayoutLength(child.WidthSpecification));
 
             MeasureSpecification childHeightMeasureSpec = GetChildMeasureSpecification(
                                     new MeasureSpecification(
-                                        new LayoutLength(parentMeasureSpecificationHeight.Size - (child.Margin.Top + child.Margin.Bottom)),
+                                        new LayoutLength(parentMeasureSpecificationHeight.Size - (margin.Top + margin.Bottom)),
                                         parentMeasureSpecificationHeight.Mode),
                                     new LayoutLength(Padding.Top + Padding.Bottom),
                                     new LayoutLength(child.HeightSpecification));
index 42ee43f..e32a0f8 100755 (executable)
@@ -444,8 +444,8 @@ namespace Tizen.NUI
                 if (childLayout != null)
                 {
                     // Use position if explicitly set to child otherwise will be top left.
-                    var childLeft = new LayoutLength(childLayout.Owner.Position2D.X);
-                    var childTop = new LayoutLength(childLayout.Owner.Position2D.Y);
+                    var childLeft = new LayoutLength(childLayout.Owner.PositionX);
+                    var childTop = new LayoutLength(childLayout.Owner.PositionY);
 
                     View owner = Owner;
 
@@ -474,10 +474,8 @@ namespace Tizen.NUI
                 LayoutLength childWidth = childLayout.MeasuredWidth.Size;
                 LayoutLength childHeight = childLayout.MeasuredHeight.Size;
 
-                Position2D childPosition = childLayout.Owner.Position2D;
-
-                LayoutLength childPositionX = new LayoutLength(childPosition.X);
-                LayoutLength childPositionY = new LayoutLength(childPosition.Y);
+                LayoutLength childPositionX = new LayoutLength(childLayout.Owner.PositionX);
+                LayoutLength childPositionY = new LayoutLength(childLayout.Owner.PositionY);
 
                 childLayout.Layout(childPositionX, childPositionY, childPositionX + childWidth, childPositionY + childHeight, true);
             }
@@ -605,17 +603,18 @@ namespace Tizen.NUI
             }
 
             View childOwner = child.Owner;
+            Extents margin = childOwner.Margin;
 
             MeasureSpecification childWidthMeasureSpec = GetChildMeasureSpecification(
                         new MeasureSpecification(
-                            new LayoutLength(parentWidthMeasureSpec.Size + widthUsed - (childOwner.Margin.Start + childOwner.Margin.End)),
+                            new LayoutLength(parentWidthMeasureSpec.Size + widthUsed - (margin.Start + margin.End)),
                             parentWidthMeasureSpec.Mode),
                         new LayoutLength(Padding.Start + Padding.End),
                         new LayoutLength(childOwner.WidthSpecification));
 
             MeasureSpecification childHeightMeasureSpec = GetChildMeasureSpecification(
                         new MeasureSpecification(
-                            new LayoutLength(parentHeightMeasureSpec.Size + heightUsed - (childOwner.Margin.Top + childOwner.Margin.Bottom)),
+                            new LayoutLength(parentHeightMeasureSpec.Size + heightUsed - (margin.Top + margin.Bottom)),
                             parentHeightMeasureSpec.Mode),
                         new LayoutLength(Padding.Top + Padding.Bottom),
                         new LayoutLength(childOwner.HeightSpecification));