Browse Source

Ensure context and redering improvement

Krzysztof Krysiński 2 months ago
parent
commit
d6ba9dcff2

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

@@ -5,6 +5,7 @@ using PixiEditor.ChangeableDocument.ChangeInfos.Properties;
 using PixiEditor.ChangeableDocument.Helpers;
 using PixiEditor.ChangeableDocument.Helpers;
 using PixiEditor.ChangeableDocument.Rendering;
 using PixiEditor.ChangeableDocument.Rendering;
 using Drawie.Backend.Core;
 using Drawie.Backend.Core;
+using Drawie.Backend.Core.Bridge;
 using Drawie.Backend.Core.ColorsImpl;
 using Drawie.Backend.Core.ColorsImpl;
 using Drawie.Backend.Core.Numerics;
 using Drawie.Backend.Core.Numerics;
 using Drawie.Backend.Core.Surfaces;
 using Drawie.Backend.Core.Surfaces;
@@ -246,6 +247,7 @@ public abstract class StructureNode : RenderNode, IReadOnlyStructureNode, IRende
 
 
         VecI targetSize = img.LatestSize;
         VecI targetSize = img.LatestSize;
 
 
+        var ctx = DrawingBackendApi.Current.RenderingDispatcher.EnsureContext();
         renderSurface = RequestTexture(textureId, targetSize, processingColorSpace, false);
         renderSurface = RequestTexture(textureId, targetSize, processingColorSpace, false);
 
 
         int saved = renderSurface.DrawingSurface.Canvas.Save();
         int saved = renderSurface.DrawingSurface.Canvas.Save();
@@ -263,6 +265,7 @@ public abstract class StructureNode : RenderNode, IReadOnlyStructureNode, IRende
         }
         }
 
 
         renderSurface.DrawingSurface.Canvas.RestoreToCount(saved);
         renderSurface.DrawingSurface.Canvas.RestoreToCount(saved);
+        ctx?.Dispose();
     }
     }
 
 
     protected void ApplyRasterClip(DrawingSurface toClip, DrawingSurface clipSource)
     protected void ApplyRasterClip(DrawingSurface toClip, DrawingSurface clipSource)

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

@@ -56,15 +56,13 @@ internal class SceneRenderer : IDisposable
             var rendered = RenderGraph(target, resolution, targetOutput, finalGraph);
             var rendered = RenderGraph(target, resolution, targetOutput, finalGraph);
             cachedTextures[adjustedTargetOutput] = rendered;
             cachedTextures[adjustedTargetOutput] = rendered;
         }
         }
-        else
-        {
-            var cachedTexture = cachedTextures[adjustedTargetOutput];
-            Matrix3X3 matrixDiff = SolveMatrixDiff(target, cachedTexture);
-            int saved = target.Canvas.Save();
-            target.Canvas.SetMatrix(matrixDiff);
-            target.Canvas.DrawSurface(cachedTexture.DrawingSurface, 0, 0);
-            target.Canvas.RestoreToCount(saved);
-        }
+
+        var cachedTexture = cachedTextures[adjustedTargetOutput];
+        Matrix3X3 matrixDiff = SolveMatrixDiff(target, cachedTexture);
+        int saved = target.Canvas.Save();
+        target.Canvas.SetMatrix(matrixDiff);
+        target.Canvas.DrawSurface(cachedTexture.DrawingSurface, 0, 0);
+        target.Canvas.RestoreToCount(saved);
     }
     }
 
 
     private Texture RenderGraph(DrawingSurface target, ChunkResolution resolution, string? targetOutput,
     private Texture RenderGraph(DrawingSurface target, ChunkResolution resolution, string? targetOutput,
@@ -263,7 +261,8 @@ internal class SceneRenderer : IDisposable
 
 
             double finalOpacity = onionOpacity * alphaFalloffMultiplier * (animationData.OnionFrames - i + 1);
             double finalOpacity = onionOpacity * alphaFalloffMultiplier * (animationData.OnionFrames - i + 1);
 
 
-            RenderContext onionContext = new(target, frame, resolution, renderOutputSize, Document.Size, Document.ProcessingColorSpace,
+            RenderContext onionContext = new(target, frame, resolution, renderOutputSize, Document.Size,
+                Document.ProcessingColorSpace,
                 finalOpacity);
                 finalOpacity);
             onionContext.TargetOutput = targetOutput;
             onionContext.TargetOutput = targetOutput;
             finalGraph.Execute(onionContext);
             finalGraph.Execute(onionContext);
@@ -279,7 +278,8 @@ internal class SceneRenderer : IDisposable
             }
             }
 
 
             double finalOpacity = onionOpacity * alphaFalloffMultiplier * (animationData.OnionFrames - i + 1);
             double finalOpacity = onionOpacity * alphaFalloffMultiplier * (animationData.OnionFrames - i + 1);
-            RenderContext onionContext = new(target, frame, resolution, renderOutputSize, Document.Size, Document.ProcessingColorSpace,
+            RenderContext onionContext = new(target, frame, resolution, renderOutputSize, Document.Size,
+                Document.ProcessingColorSpace,
                 finalOpacity);
                 finalOpacity);
             onionContext.TargetOutput = targetOutput;
             onionContext.TargetOutput = targetOutput;
             finalGraph.Execute(onionContext);
             finalGraph.Execute(onionContext);