Kaynağa Gözat

Fixed vector layers rasterizing in certain setups

Krzysztof Krysiński 4 ay önce
ebeveyn
işleme
7edaf6b147

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

@@ -3,6 +3,7 @@ using PixiEditor.ChangeableDocument.Changeables.Graph.Interfaces;
 using PixiEditor.ChangeableDocument.Rendering;
 using Drawie.Backend.Core;
 using Drawie.Backend.Core.ColorsImpl;
+using Drawie.Backend.Core.Numerics;
 using Drawie.Backend.Core.Surfaces;
 using Drawie.Backend.Core.Surfaces.PaintImpl;
 using Drawie.Numerics;
@@ -67,8 +68,6 @@ public class FolderNode : StructureNode, IReadOnlyFolderNode, IClipSource, IPrev
             return;
         }
 
-        RectD bounds = RectD.Create(VecI.Zero, sceneContext.DocumentSize);
-
         if (sceneContext.TargetPropertyOutput == Output)
         {
             if (Background.Value != null)
@@ -76,19 +75,24 @@ public class FolderNode : StructureNode, IReadOnlyFolderNode, IClipSource, IPrev
                 blendPaint.BlendMode = RenderContext.GetDrawingBlendMode(BlendMode.Value);
             }
 
-            RenderFolderContent(sceneContext, bounds, true);
+            RenderFolderContent(sceneContext, true);
         }
         else if (sceneContext.TargetPropertyOutput == FilterlessOutput ||
                  sceneContext.TargetPropertyOutput == RawOutput)
         {
-            RenderFolderContent(sceneContext, bounds, false);
+            RenderFolderContent(sceneContext, false);
         }
     }
 
-    private void RenderFolderContent(SceneObjectRenderContext sceneContext, RectD bounds, bool useFilters)
+    private void RenderFolderContent(SceneObjectRenderContext sceneContext, bool useFilters)
     {
-        VecI size = (VecI)bounds.Size;
+        VecI size = sceneContext.RenderSurface.DeviceClipBounds.Size + sceneContext.RenderSurface.DeviceClipBounds.Pos;
         var outputWorkingSurface = RequestTexture(0, size, sceneContext.ProcessingColorSpace, true);
+        outputWorkingSurface.DrawingSurface.Canvas.Save();
+        outputWorkingSurface.DrawingSurface.Canvas.SetMatrix(sceneContext.RenderSurface.Canvas.TotalMatrix);
+
+        int saved = sceneContext.RenderSurface.Canvas.Save();
+        sceneContext.RenderSurface.Canvas.SetMatrix(Matrix3X3.Identity);
 
         blendPaint.ImageFilter = null;
         blendPaint.ColorFilter = null;
@@ -100,6 +104,10 @@ public class FolderNode : StructureNode, IReadOnlyFolderNode, IClipSource, IPrev
         if (Background.Value != null && sceneContext.TargetPropertyOutput != RawOutput)
         {
             Texture tempSurface = RequestTexture(1, outputWorkingSurface.Size, sceneContext.ProcessingColorSpace);
+            tempSurface.DrawingSurface.Canvas.Save();
+            tempSurface.DrawingSurface.Canvas.SetMatrix(outputWorkingSurface.DrawingSurface.Canvas.TotalMatrix);
+
+            outputWorkingSurface.DrawingSurface.Canvas.SetMatrix(Matrix3X3.Identity);
             if (Background.Connection.Node is IClipSource clipSource && ClipToPreviousMember)
             {
                 DrawClipSource(tempSurface.DrawingSurface, clipSource, sceneContext);
@@ -112,6 +120,9 @@ public class FolderNode : StructureNode, IReadOnlyFolderNode, IClipSource, IPrev
 
         blendPaint.BlendMode = RenderContext.GetDrawingBlendMode(BlendMode.Value);
         sceneContext.RenderSurface.Canvas.DrawSurface(outputWorkingSurface.DrawingSurface, 0, 0, blendPaint);
+
+        sceneContext.RenderSurface.Canvas.RestoreToCount(saved);
+        outputWorkingSurface.DrawingSurface.Canvas.Restore();
     }
 
     private void AdjustPaint(bool useFilters)

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

@@ -31,13 +31,11 @@ public abstract class LayerNode : StructureNode, IReadOnlyLayerNode, IClipSource
         blendPaint.Color = new Color(255, 255, 255, 255);
         blendPaint.BlendMode = Drawie.Backend.Core.Surfaces.BlendMode.SrcOver;
 
-        VecI targetSize = GetTargetSize(sceneContext);
-
-        RenderContent(targetSize, sceneContext, sceneContext.RenderSurface,
+        RenderContent(sceneContext, sceneContext.RenderSurface,
             sceneContext.TargetPropertyOutput != FilterlessOutput);
     }
 
-    private void RenderContent(VecI size, SceneObjectRenderContext context, DrawingSurface renderOnto, bool useFilters)
+    private void RenderContent(SceneObjectRenderContext context, DrawingSurface renderOnto, bool useFilters)
     {
         if (!HasOperations())
         {
@@ -50,9 +48,16 @@ public abstract class LayerNode : StructureNode, IReadOnlyLayerNode, IClipSource
             return;
         }
 
+        VecI size = renderOnto.DeviceClipBounds.Size + renderOnto.DeviceClipBounds.Pos;
+        int saved = renderOnto.Canvas.Save();
+
         var outputWorkingSurface =
             TryInitWorkingSurface(size, context.ChunkResolution, context.ProcessingColorSpace, 1);
         outputWorkingSurface.DrawingSurface.Canvas.Clear();
+        outputWorkingSurface.DrawingSurface.Canvas.Save();
+        outputWorkingSurface.DrawingSurface.Canvas.SetMatrix(renderOnto.Canvas.TotalMatrix);
+
+        renderOnto.Canvas.SetMatrix(Matrix3X3.Identity);
 
         DrawLayerOnTexture(context, outputWorkingSurface.DrawingSurface, useFilters);
 
@@ -61,6 +66,12 @@ public abstract class LayerNode : StructureNode, IReadOnlyLayerNode, IClipSource
         if (Background.Value != null)
         {
             Texture tempSurface = TryInitWorkingSurface(size, context.ChunkResolution, context.ProcessingColorSpace, 4);
+
+            tempSurface.DrawingSurface.Canvas.Save();
+            tempSurface.DrawingSurface.Canvas.SetMatrix(outputWorkingSurface.DrawingSurface.Canvas.TotalMatrix);
+
+            outputWorkingSurface.DrawingSurface.Canvas.SetMatrix(Matrix3X3.Identity);
+
             tempSurface.DrawingSurface.Canvas.Clear();
             if (Background.Connection is { Node: IClipSource clipSource } && ClipToPreviousMember)
             {
@@ -72,6 +83,9 @@ public abstract class LayerNode : StructureNode, IReadOnlyLayerNode, IClipSource
 
         blendPaint.BlendMode = RenderContext.GetDrawingBlendMode(BlendMode.Value);
         DrawWithResolution(outputWorkingSurface.DrawingSurface, renderOnto, context.ChunkResolution);
+
+        renderOnto.Canvas.RestoreToCount(saved);
+        outputWorkingSurface.DrawingSurface.Canvas.Restore();
     }
 
     protected internal virtual void DrawLayerOnTexture(SceneObjectRenderContext ctx,
@@ -168,6 +182,6 @@ public abstract class LayerNode : StructureNode, IReadOnlyLayerNode, IClipSource
 
     void IClipSource.DrawClipSource(SceneObjectRenderContext context, DrawingSurface drawOnto)
     {
-        RenderContent(GetTargetSize(context), context, drawOnto, false);
+        RenderContent(context, drawOnto, false);
     }
 }

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

@@ -176,6 +176,7 @@ public class VectorLayerNode : LayerNode, ITransformableObject, IReadOnlyVectorN
         {
             ShapeData = (ShapeVectorData?)ShapeData?.Clone(),
             ClipToPreviousMember = this.ClipToPreviousMember,
+            EmbeddedMask = this.EmbeddedMask?.CloneFromCommitted(),
             AllowHighDpiRendering = this.AllowHighDpiRendering
         };
     }