Browse Source

Improved folder performance

Krzysztof Krysiński 3 months ago
parent
commit
783107d03e

+ 37 - 5
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/FolderNode.cs

@@ -11,7 +11,7 @@ using Drawie.Numerics;
 namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
 
 [NodeInfo("Folder")]
-public class FolderNode : StructureNode, IReadOnlyFolderNode, IClipSource, IPreviewRenderable
+public class FolderNode : StructureNode, IReadOnlyFolderNode, IClipSource
 {
     public const string ContentInternalName = "Content";
     private VecI documentSize;
@@ -25,16 +25,16 @@ public class FolderNode : StructureNode, IReadOnlyFolderNode, IClipSource, IPrev
 
     public override Node CreateCopy() => new FolderNode
     {
-        MemberName = MemberName, 
+        MemberName = MemberName,
         ClipToPreviousMember = this.ClipToPreviousMember,
         EmbeddedMask = this.EmbeddedMask?.CloneFromCommitted()
     };
 
     public override VecD GetScenePosition(KeyFrameTime time) =>
-        documentSize / 2f; 
+        documentSize / 2f;
 
     public override VecD GetSceneSize(KeyFrameTime time) =>
-        documentSize; 
+        documentSize;
 
     protected override void OnExecute(RenderContext context)
     {
@@ -172,6 +172,38 @@ public class FolderNode : StructureNode, IReadOnlyFolderNode, IClipSource, IPrev
         return null;
     }
 
+    public override RectD? GetApproxBounds(KeyFrameTime frameTime)
+    {
+        RectD? bounds = null;
+        if (Content.Connection != null)
+        {
+            Content.Connection.Node.TraverseBackwards((n) =>
+            {
+                if (n is StructureNode structureNode)
+                {
+                    RectD? childBounds = structureNode.GetApproxBounds(frameTime);
+                    if (childBounds != null)
+                    {
+                        if (bounds == null)
+                        {
+                            bounds = childBounds;
+                        }
+                        else
+                        {
+                            bounds = bounds.Value.Union(childBounds.Value);
+                        }
+                    }
+                }
+
+                return true;
+            });
+
+            return bounds ?? RectD.Empty;
+        }
+
+        return null;
+    }
+
     public HashSet<Guid> GetLayerNodeGuids()
     {
         HashSet<Guid> guids = new();
@@ -195,7 +227,7 @@ public class FolderNode : StructureNode, IReadOnlyFolderNode, IClipSource, IPrev
             return base.GetPreviewBounds(frame, elementFor);
         }
 
-        return GetTightBounds(frame);
+        return GetApproxBounds(frame);
     }
 
     public override bool RenderPreview(DrawingSurface renderOn, RenderContext context,

+ 5 - 0
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/ImageLayerNode.cs

@@ -47,6 +47,11 @@ public class ImageLayerNode : LayerNode, IReadOnlyImageNode
         return (RectD?)GetLayerImageAtFrame(frameTime.Frame).FindTightCommittedBounds();
     }
 
+    public override RectD? GetApproxBounds(KeyFrameTime frameTime)
+    {
+        return (RectD?)GetLayerImageAtFrame(frameTime.Frame).FindChunkAlignedCommittedBounds();
+    }
+
     protected internal override void DrawLayerInScene(SceneObjectRenderContext ctx,
         DrawingSurface workingSurface,
         bool useFilters = true)

+ 5 - 1
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/LayerNode.cs

@@ -57,10 +57,14 @@ public abstract class LayerNode : StructureNode, IReadOnlyLayerNode, IClipSource
                     BlendMode = Drawie.Backend.Core.Surfaces.BlendMode.SrcOver
                 };
 
-                using var tempSurface = Texture.ForProcessing(context.DocumentSize, context.ProcessingColorSpace);
+                using var tempSurface = Texture.ForProcessing(context.DocumentSize, ColorSpace.CreateSrgb());
                 tempSurface.DrawingSurface.Canvas.Scale((float)context.ChunkResolution.InvertedMultiplier());
+                ColorSpace processingCs = context.ProcessingColorSpace;
+                context.ProcessingColorSpace = ColorSpace.CreateSrgb();
+
                 DrawLayerOnTexture(context, tempSurface.DrawingSurface, useFilters, targetPaint);
 
+                context.ProcessingColorSpace = processingCs;
                 renderOnto.Canvas.DrawSurface(tempSurface.DrawingSurface, 0, 0, blendPaint);
             }
 

+ 1 - 0
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/StructureNode.cs

@@ -279,6 +279,7 @@ public abstract class StructureNode : RenderNode, IReadOnlyStructureNode, IRende
     }
 
     public abstract RectD? GetTightBounds(KeyFrameTime frameTime);
+    public abstract RectD? GetApproxBounds(KeyFrameTime frameTime);
 
     public override void SerializeAdditionalData(Dictionary<string, object> additionalData)
     {

+ 5 - 0
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/VectorLayerNode.cs

@@ -134,6 +134,11 @@ public class VectorLayerNode : LayerNode, ITransformableObject, IReadOnlyVectorN
         return true;
     }
 
+    public override RectD? GetApproxBounds(KeyFrameTime frameTime)
+    {
+        return GetTightBounds(frameTime);
+    }
+
     public override void SerializeAdditionalData(Dictionary<string, object> additionalData)
     {
         base.SerializeAdditionalData(additionalData);