Browse Source

Fixed canvas not updating on content changes

Krzysztof Krysiński 4 months ago
parent
commit
d7a7c59b8c

+ 8 - 0
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Node.cs

@@ -48,6 +48,8 @@ public abstract class Node : IReadOnlyNode, IDisposable
     protected internal bool IsDisposed => _isDisposed;
     protected internal bool IsDisposed => _isDisposed;
     private bool _isDisposed;
     private bool _isDisposed;
 
 
+    private int lastContentCacheHash = -1;
+
     protected virtual int GetContentCacheHash()
     protected virtual int GetContentCacheHash()
     {
     {
         return 0;
         return 0;
@@ -91,6 +93,10 @@ public abstract class Node : IReadOnlyNode, IDisposable
             changed |= lastFrameTime.Frame != context.FrameTime.Frame || Math.Abs(lastFrameTime.NormalizedTime - context.FrameTime.NormalizedTime) > float.Epsilon;
             changed |= lastFrameTime.Frame != context.FrameTime.Frame || Math.Abs(lastFrameTime.NormalizedTime - context.FrameTime.NormalizedTime) > float.Epsilon;
         }
         }
 
 
+        int contentCacheHash = GetContentCacheHash();
+
+        changed |= contentCacheHash != lastContentCacheHash;
+
         return changed;
         return changed;
     }
     }
 
 
@@ -102,6 +108,8 @@ public abstract class Node : IReadOnlyNode, IDisposable
         }
         }
 
 
         lastFrameTime = context.FrameTime;
         lastFrameTime = context.FrameTime;
+
+        lastContentCacheHash = GetContentCacheHash();
     }
     }
 
 
     public void TraverseBackwards(Func<IReadOnlyNode, IInputProperty, bool> action)
     public void TraverseBackwards(Func<IReadOnlyNode, IInputProperty, bool> action)

+ 2 - 14
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/StructureNode.cs

@@ -79,9 +79,6 @@ public abstract class StructureNode : RenderNode, IReadOnlyStructureNode, IRende
         ColorFilter = ColorFilter.CreateCompose(Nodes.Filters.AlphaGrayscaleFilter, Nodes.Filters.MaskFilter)
         ColorFilter = ColorFilter.CreateCompose(Nodes.Filters.AlphaGrayscaleFilter, Nodes.Filters.MaskFilter)
     };
     };
 
 
-    private int maskCacheHash = 0;
-    private int clipCacheHash = 0;
-
     protected StructureNode()
     protected StructureNode()
     {
     {
         Painter filterlessPainter = new Painter(OnFilterlessPaint);
         Painter filterlessPainter = new Painter(OnFilterlessPaint);
@@ -212,18 +209,9 @@ public abstract class StructureNode : RenderNode, IReadOnlyStructureNode, IRende
         }
         }
     }
     }
 
 
-    protected override bool CacheChanged(RenderContext context)
-    {
-        int cacheHash = EmbeddedMask?.GetCacheHash() ?? 0;
-        int clipHash = ClipToPreviousMember ? 1 : 0;
-        return base.CacheChanged(context) || maskCacheHash != cacheHash || clipHash != clipCacheHash;
-    }
-
-    protected override void UpdateCache(RenderContext context)
+    protected override int GetContentCacheHash()
     {
     {
-        base.UpdateCache(context);
-        maskCacheHash = EmbeddedMask?.GetCacheHash() ?? 0;
-        clipCacheHash = ClipToPreviousMember ? 1 : 0;
+        return HashCode.Combine(base.GetContentCacheHash(), EmbeddedMask?.GetCacheHash() ?? 0, ClipToPreviousMember ? 1 : 0);
     }
     }
 
 
     public virtual void RenderChunk(VecI chunkPos, ChunkResolution resolution, KeyFrameTime frameTime, ColorSpace processingColorSpace)
     public virtual void RenderChunk(VecI chunkPos, ChunkResolution resolution, KeyFrameTime frameTime, ColorSpace processingColorSpace)

+ 2 - 10
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/VectorLayerNode.cs

@@ -40,8 +40,6 @@ public class VectorLayerNode : LayerNode, ITransformableObject, IReadOnlyVectorN
     IReadOnlyShapeVectorData IReadOnlyVectorNode.ShapeData => ShapeData;
     IReadOnlyShapeVectorData IReadOnlyVectorNode.ShapeData => ShapeData;
 
 
 
 
-    private int lastCacheHash;
-
     public override VecD GetScenePosition(KeyFrameTime time) => ShapeData?.TransformedAABB.Center ?? VecD.Zero;
     public override VecD GetScenePosition(KeyFrameTime time) => ShapeData?.TransformedAABB.Center ?? VecD.Zero;
     public override VecD GetSceneSize(KeyFrameTime time) => ShapeData?.TransformedAABB.Size ?? VecD.Zero;
     public override VecD GetSceneSize(KeyFrameTime time) => ShapeData?.TransformedAABB.Size ?? VecD.Zero;
 
 
@@ -142,15 +140,9 @@ public class VectorLayerNode : LayerNode, ITransformableObject, IReadOnlyVectorN
         infos.Add(new VectorShape_ChangeInfo(Id, affected));
         infos.Add(new VectorShape_ChangeInfo(Id, affected));
     }
     }
 
 
-    protected override bool CacheChanged(RenderContext context)
-    {
-        return base.CacheChanged(context) || (ShapeData?.GetCacheHash() ?? -1) != lastCacheHash;
-    }
-
-    protected override void UpdateCache(RenderContext context)
+    protected override int GetContentCacheHash()
     {
     {
-        base.UpdateCache(context);
-        lastCacheHash = ShapeData?.GetCacheHash() ?? -1;
+        return HashCode.Combine(base.GetContentCacheHash(), ShapeData?.GetCacheHash() ?? 0);
     }
     }
 
 
     public override RectD? GetTightBounds(KeyFrameTime frameTime)
     public override RectD? GetTightBounds(KeyFrameTime frameTime)