Browse Source

Fixed misuse of init working surface

flabbet 1 year ago
parent
commit
ba728d426b

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

@@ -39,8 +39,8 @@ public class FolderNode : StructureNode, IReadOnlyFolderNode
 
         VecI size = Content.Value?.Size ?? Background.Value?.Size ?? VecI.Zero;
         
-        var outputWorkingSurface = TryInitWorkingSurface(size, context, 0);
-        var filterlessWorkingSurface = TryInitWorkingSurface(size, context, 1);
+        var outputWorkingSurface = RequestTexture(0, size); 
+        var filterlessWorkingSurface = RequestTexture(1, size); 
         
         if (Background.Value != null)
         {

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

@@ -23,6 +23,9 @@ public class ImageLayerNode : LayerNode, IReadOnlyImageNode
     private VecI size;
     private ChunkyImage layerImage => keyFrames[0]?.Data as ChunkyImage;
 
+    protected Dictionary<(ChunkResolution, int), Texture> workingSurfaces =
+        new Dictionary<(ChunkResolution, int), Texture>();
+
     private static readonly Paint clearPaint = new()
     {
         BlendMode = DrawingApi.Core.Surfaces.BlendMode.Src,
@@ -136,6 +139,21 @@ public class ImageLayerNode : LayerNode, IReadOnlyImageNode
         return outputWorkingSurface;
     }
 
+    protected Texture TryInitWorkingSurface(VecI imageSize, RenderingContext context, int id)
+    {
+        ChunkResolution targetResolution = context.ChunkResolution;
+        bool hasSurface = workingSurfaces.TryGetValue((targetResolution, id), out Texture workingSurface);
+        VecI targetSize = (VecI)(imageSize * targetResolution.Multiplier());
+
+        if (!hasSurface || workingSurface.Size != targetSize || workingSurface.IsDisposed)
+        {
+            workingSurfaces[(targetResolution, id)] = new Texture(targetSize);
+            workingSurface = workingSurfaces[(targetResolution, id)];
+        }
+
+        return workingSurface;
+    }
+
     private void DrawLayer(ChunkyImage frameImage, RenderingContext context, Texture workingSurface, bool shouldClear,
         bool useFilters = true)
     {

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

@@ -30,7 +30,6 @@ public abstract class StructureNode : Node, IReadOnlyStructureNode, IBackgroundI
     
     public string DisplayName => MemberName;
 
-    protected Dictionary<(ChunkResolution, int), Texture> workingSurfaces = new Dictionary<(ChunkResolution, int), Texture>();
     private Paint maskPaint = new Paint() { BlendMode = DrawingApi.Core.Surfaces.BlendMode.DstIn };
     protected Paint blendPaint = new Paint();
 
@@ -54,21 +53,6 @@ public abstract class StructureNode : Node, IReadOnlyStructureNode, IBackgroundI
 
     protected abstract override Texture? OnExecute(RenderingContext context);
 
-    protected Texture TryInitWorkingSurface(VecI imageSize, RenderingContext context, int id)
-    {
-        ChunkResolution targetResolution = context.ChunkResolution;
-        bool hasSurface = workingSurfaces.TryGetValue((targetResolution, id), out Texture workingSurface);
-        VecI targetSize = (VecI)(imageSize * targetResolution.Multiplier());
-
-        if (!hasSurface || workingSurface.Size != targetSize || workingSurface.IsDisposed)
-        {
-            workingSurfaces[(targetResolution, id)] = new Texture(targetSize);
-            workingSurface = workingSurfaces[(targetResolution, id)];
-        }
-
-        return workingSurface;
-    }
-
     protected void ApplyMaskIfPresent(Texture surface, RenderingContext context)
     {
         if (Mask.Value != null && MaskIsVisible.Value)