Browse Source

Made RenderContext not disposable

flabbet 10 months ago
parent
commit
b16ddc077f

+ 1 - 1
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/CombineSeparate/CombineChannelsNode.cs

@@ -126,7 +126,7 @@ public class CombineChannelsNode : RenderNode
             return false;
         }
 
-        using RenderContext context = new(renderOn, frame, resolution, VecI.One);
+        RenderContext context = new(renderOn, frame, resolution, VecI.One);
         
         OnPaint(context, renderOn); 
         

+ 1 - 1
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/CombineSeparate/SeparateChannelsNode.cs

@@ -106,7 +106,7 @@ public class SeparateChannelsNode : Node, IRenderInput, IPreviewRenderable
         if (bounds == null)
             return false;
         
-        using RenderContext context = new(renderOn, frame, resolution, VecI.One);
+        RenderContext context = new(renderOn, frame, resolution, VecI.One);
         
         _paint.ColorFilter = Grayscale.Value ? _redGrayscaleFilter : _redFilter;
         RectD localBounds = new(bounds.Value.X, bounds.Value.Y, bounds.Value.Width / 2, bounds.Value.Height / 2);

+ 8 - 1
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/DebugBlendModeNode.cs

@@ -20,6 +20,7 @@ public class DebugBlendModeNode : Node
 
     public OutputProperty<Texture> Result { get; }
 
+    private Paint blendModeOpacityPaint => new() { BlendMode = DrawingApiBlendMode.SrcOver }; 
     public DebugBlendModeNode()
     {
         Dst = CreateInput<Texture?>(nameof(Dst), "Dst", null);
@@ -37,7 +38,7 @@ public class DebugBlendModeNode : Node
         var size = new VecI(Math.Max(src.Size.X, dst.Size.X), int.Max(src.Size.Y, dst.Size.Y));
         var workingSurface = RequestTexture(0, size);
 
-        workingSurface.DrawingSurface.Canvas.DrawSurface(dst.DrawingSurface, 0, 0, context.BlendModeOpacityPaint);
+        workingSurface.DrawingSurface.Canvas.DrawSurface(dst.DrawingSurface, 0, 0, blendModeOpacityPaint);
 
         _paint.BlendMode = BlendMode.Value;
         workingSurface.DrawingSurface.Canvas.DrawSurface(src.DrawingSurface, 0, 0, _paint);
@@ -47,4 +48,10 @@ public class DebugBlendModeNode : Node
 
 
     public override Node CreateCopy() => new DebugBlendModeNode();
+
+    public override void Dispose()
+    {
+        base.Dispose();
+        _paint.Dispose();
+    }
 }

+ 1 - 1
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/FilterNodes/ApplyFilterNode.cs

@@ -43,7 +43,7 @@ public class ApplyFilterNode : RenderNode, IRenderInput
         if(Background.Value == null)
             return false;
 
-        using RenderContext context = new(renderOn, frame, ChunkResolution.Full, VecI.One);
+        RenderContext context = new(renderOn, frame, ChunkResolution.Full, VecI.One);
         
         int layer = renderOn.Canvas.SaveLayer(_paint);
         Background.Value.Paint(context, renderOn);

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

@@ -107,7 +107,7 @@ public class MergeNode : RenderNode
             return false;
         }
 
-        using RenderContext context = new RenderContext(renderOn, frame, ChunkResolution.Full, VecI.Zero);
+        RenderContext context = new RenderContext(renderOn, frame, ChunkResolution.Full, VecI.Zero);
         Merge(renderOn, context);
 
         return true;

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

@@ -56,7 +56,6 @@ public class ModifyImageLeftNode : Node, IPairNode, IPreviewRenderable
             return false;
         }
 
-        using RenderContext renderContext = new(renderOn, frame, ChunkResolution.Full, VecI.Zero);
         renderOn.Canvas.DrawSurface(Image.Value.DrawingSurface, 0, 0); 
         return true;
     }

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

@@ -50,7 +50,7 @@ public class OutputNode : Node, IRenderInput, IPreviewRenderable
             return false;
         }
         
-        using RenderContext context = new(renderOn, frame, resolution, VecI.One);
+        RenderContext context = new(renderOn, frame, resolution, VecI.One);
         Input.Value.Paint(context, renderOn);
         
         return true;

+ 3 - 3
src/PixiEditor.ChangeableDocument/Rendering/DocumentRenderer.cs

@@ -79,7 +79,7 @@ public class DocumentRenderer : IPreviewRenderable
             return;
         }
         
-        using RenderContext context = new(renderOn, frameTime, resolution, Document.Size);
+        RenderContext context = new(renderOn, frameTime, resolution, Document.Size);
         context.FullRerender = true;
         
         node.Execute(context);
@@ -128,7 +128,7 @@ public class DocumentRenderer : IPreviewRenderable
 
     public bool RenderPreview(DrawingSurface renderOn, ChunkResolution resolution, int frame, string elementToRenderName)
     {
-        using RenderContext context = new(renderOn, frame, resolution, Document.Size);
+        RenderContext context = new(renderOn, frame, resolution, Document.Size);
         Document.NodeGraph.Execute(context);
         
         return true;
@@ -136,7 +136,7 @@ public class DocumentRenderer : IPreviewRenderable
 
     public void RenderDocument(DrawingSurface toRenderOn, KeyFrameTime frameTime)
     {
-        using RenderContext context = new(toRenderOn, frameTime, ChunkResolution.Full, Document.Size) { FullRerender = true };
+        RenderContext context = new(toRenderOn, frameTime, ChunkResolution.Full, Document.Size) { FullRerender = true };
         Document.NodeGraph.Execute(context);
     }
 }

+ 2 - 26
src/PixiEditor.ChangeableDocument/Rendering/RenderContext.cs

@@ -1,23 +1,13 @@
-using System;
-using ChunkyImageLib.DataHolders;
-using PixiEditor.ChangeableDocument.Changeables.Animations;
-using PixiEditor.ChangeableDocument.Changeables.Graph.Interfaces;
-using PixiEditor.ChangeableDocument.Changeables.Interfaces;
-using PixiEditor.DrawingApi.Core.ColorsImpl;
+using PixiEditor.ChangeableDocument.Changeables.Animations;
 using PixiEditor.DrawingApi.Core.Surfaces;
-using PixiEditor.DrawingApi.Core.Surfaces.PaintImpl;
 using PixiEditor.Numerics;
 using BlendMode = PixiEditor.ChangeableDocument.Enums.BlendMode;
 using DrawingApiBlendMode = PixiEditor.DrawingApi.Core.Surfaces.BlendMode;
 
 namespace PixiEditor.ChangeableDocument.Rendering;
 
-public class RenderContext : IDisposable
+public class RenderContext
 {
-    public Paint BlendModePaint = new() { BlendMode = DrawingApiBlendMode.SrcOver };
-    public Paint BlendModeOpacityPaint = new() { BlendMode = DrawingApiBlendMode.SrcOver };
-    public Paint ReplacingPaintWithOpacity = new() { BlendMode = DrawingApiBlendMode.Src };
-
     public double Opacity { get; set; }
 
     public KeyFrameTime FrameTime { get; }
@@ -27,7 +17,6 @@ public class RenderContext : IDisposable
     public DrawingSurface RenderSurface { get; set; }
     public bool FullRerender { get; set; } = false;
 
-    public bool IsDisposed { get; private set; }
 
     public RenderContext(DrawingSurface renderSurface, KeyFrameTime frameTime, ChunkResolution chunkResolution,
         VecI docSize, double opacity = 1) 
@@ -64,17 +53,4 @@ public class RenderContext : IDisposable
             _ => DrawingApiBlendMode.SrcOver,
         };
     }
-
-    public void Dispose()
-    {
-        if (IsDisposed)
-        {
-            return;
-        }
-        
-        IsDisposed = true;
-        BlendModePaint.Dispose();
-        BlendModeOpacityPaint.Dispose();
-        ReplacingPaintWithOpacity.Dispose();
-    }
 }

+ 3 - 3
src/PixiEditor/Models/Rendering/SceneRenderer.cs

@@ -23,7 +23,7 @@ internal class SceneRenderer
     public void RenderScene(DrawingSurface target)
     {
         RenderOnionSkin(target);
-        using RenderContext ctx = new(target, DocumentViewModel.AnimationHandler.ActiveFrameTime, Resolution, Document.Size); 
+        RenderContext ctx = new(target, DocumentViewModel.AnimationHandler.ActiveFrameTime, Resolution, Document.Size); 
         Document.NodeGraph.Execute(ctx);
     }
 
@@ -49,7 +49,7 @@ internal class SceneRenderer
 
             double finalOpacity = onionOpacity * alphaFalloffMultiplier * (animationData.OnionFrames - i + 1);
             
-            using RenderContext onionContext = new(target, frame, Resolution, Document.Size, finalOpacity);
+            RenderContext onionContext = new(target, frame, Resolution, Document.Size, finalOpacity);
             Document.NodeGraph.Execute(onionContext);
         }
         
@@ -63,7 +63,7 @@ internal class SceneRenderer
             }
             
             double finalOpacity = onionOpacity * alphaFalloffMultiplier * (animationData.OnionFrames - i + 1);
-            using RenderContext onionContext = new(target, frame, Resolution, Document.Size, finalOpacity);
+            RenderContext onionContext = new(target, frame, Resolution, Document.Size, finalOpacity);
             Document.NodeGraph.Execute(onionContext);
         }
     }