Browse Source

Improved rendering resampling

Krzysztof Krysiński 3 weeks ago
parent
commit
ba923d60a6

+ 1 - 1
src/Drawie

@@ -1 +1 @@
-Subproject commit 7c3cc858aba521829b0a5369267ea05107e79807
+Subproject commit 1ec31f39432d2a1e94cd72e84d12f5f782e51d79

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

@@ -139,7 +139,14 @@ public class ImageLayerNode : LayerNode, IReadOnlyImageNode
         }
         else
         {
-            workingSurface.Canvas.DrawSurface(fullResrenderedSurface.DrawingSurface, -topLeft, paint);
+            var samplingOptions = SamplingOptions.Default;
+            if (ctx.ChunkResolution != ChunkResolution.Full)
+            {
+                samplingOptions = new SamplingOptions(FilterMode.Linear, MipmapMode.Linear);
+            }
+
+            using var snapshot = fullResrenderedSurface.DrawingSurface.Snapshot();
+            workingSurface.Canvas.DrawImage(snapshot, -(float)topLeft.X, -(float)topLeft.Y, samplingOptions, paint);
         }
 
         workingSurface.Canvas.RestoreToCount(saved);

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

@@ -155,7 +155,13 @@ public abstract class LayerNode : StructureNode, IReadOnlyLayerNode, IClipSource
         float multiplier = (float)resolution.InvertedMultiplier();
         target.Canvas.Scale(multiplier, multiplier);
 
-        target.Canvas.DrawSurface(source, 0, 0, blendPaint);
+        using var snapshot = source.Snapshot();
+        SamplingOptions samplingOptions =
+            target.DeviceClipBounds.Size.LengthSquared < source.DeviceClipBounds.Size.LengthSquared
+                ? new SamplingOptions(FilterMode.Linear, MipmapMode.Linear)
+                : SamplingOptions.Default;
+
+        target.Canvas.DrawImage(snapshot, 0, 0, samplingOptions, blendPaint);
 
         target.Canvas.RestoreToCount(scaled);
     }

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

@@ -4,6 +4,7 @@ using Drawie.Backend.Core.Numerics;
 using PixiEditor.ChangeableDocument.Changeables.Interfaces;
 using PixiEditor.ChangeableDocument.Rendering;
 using Drawie.Backend.Core.Surfaces;
+using Drawie.Backend.Core.Surfaces.PaintImpl;
 using Drawie.Numerics;
 using PixiEditor.ChangeableDocument.Changeables.Animations;
 using PixiEditor.ChangeableDocument.Changeables.Graph.Interfaces;
@@ -64,7 +65,14 @@ internal class SceneRenderer : IDisposable
         Matrix3X3 matrixDiff = SolveMatrixDiff(target, cachedTexture);
         int saved = target.Canvas.Save();
         target.Canvas.SetMatrix(matrixDiff);
-        target.Canvas.DrawSurface(cachedTexture.DrawingSurface, 0, 0);
+        using var img = cachedTexture.DrawingSurface.Snapshot();
+        SamplingOptions samplingOptions = SamplingOptions.Default;
+        if (matrixDiff.ScaleX < 1 || matrixDiff.ScaleY < 1)
+        {
+            samplingOptions = new SamplingOptions(FilterMode.Linear, MipmapMode.Linear);
+        }
+
+        target.Canvas.DrawImage(img, 0, 0, samplingOptions);
         target.Canvas.RestoreToCount(saved);
     }
 
@@ -110,7 +118,9 @@ internal class SceneRenderer : IDisposable
 
         if (renderTexture != null)
         {
-            target.Canvas.DrawSurface(renderTexture.DrawingSurface, 0, 0);
+            using var snapshot = renderTexture.DrawingSurface.Snapshot();
+            SamplingOptions samplingOptions = resolution == ChunkResolution.Full ? SamplingOptions.Default : new SamplingOptions(FilterMode.Linear, MipmapMode.Linear);
+            target.Canvas.DrawImage(snapshot, 0, 0, samplingOptions);
             target.Canvas.RestoreToCount(restoreCanvasTo);
         }
 
@@ -168,7 +178,9 @@ internal class SceneRenderer : IDisposable
         }
 
         bool renderInDocumentSize = RenderInOutputSize(finalGraph);
-        VecI compareSize = renderInDocumentSize ? (VecI)(Document.Size * resolution.Multiplier()) : target.DeviceClipBounds.Size;
+        VecI compareSize = renderInDocumentSize
+            ? (VecI)(Document.Size * resolution.Multiplier())
+            : target.DeviceClipBounds.Size;
 
         if (cachedTexture.DrawingSurface.DeviceClipBounds.Size != compareSize)
         {