Browse Source

Some tests and changed rendering code yolo

Krzysztof Krysiński 5 months ago
parent
commit
def9d9fb0f

+ 1 - 1
src/Drawie

@@ -1 +1 @@
-Subproject commit 0cdc4c6e877d730774a3d9c99880bc2013a4b0c6
+Subproject commit fb19e6a170698609840b6602178a26da2fc289b7

+ 24 - 9
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/LayerNode.cs

@@ -44,7 +44,6 @@ public abstract class LayerNode : StructureNode, IReadOnlyLayerNode, IClipSource
                 blendPaint.BlendMode = RenderContext.GetDrawingBlendMode(BlendMode.Value);
             }
 
-            // TODO: Very low performance when in folder
             if (AllowHighDpiRendering || renderOnto.DeviceClipBounds.Size == context.DocumentSize)
             {
                 DrawLayerInScene(context, renderOnto, useFilters);
@@ -57,32 +56,39 @@ public abstract class LayerNode : StructureNode, IReadOnlyLayerNode, IClipSource
                     BlendMode = Drawie.Backend.Core.Surfaces.BlendMode.SrcOver
                 };
 
-                using var tempSurface = Texture.ForProcessing(context.DocumentSize, ColorSpace.CreateSrgb());
+                using var tempSurface = Texture.ForProcessing(context.DocumentSize, context.ProcessingColorSpace);
                 tempSurface.DrawingSurface.Canvas.Scale((float)context.ChunkResolution.InvertedMultiplier());
-                ColorSpace processingCs = context.ProcessingColorSpace;
-                context.ProcessingColorSpace = ColorSpace.CreateSrgb();
 
                 DrawLayerOnTexture(context, tempSurface.DrawingSurface, useFilters, targetPaint);
 
-                context.ProcessingColorSpace = processingCs;
+                blendPaint.SetFilters(null);
                 renderOnto.Canvas.DrawSurface(tempSurface.DrawingSurface, 0, 0, blendPaint);
             }
 
             return;
         }
 
-        VecI size = renderOnto.DeviceClipBounds.Size + renderOnto.DeviceClipBounds.Pos;
+        VecI size = AllowHighDpiRendering
+            ? renderOnto.DeviceClipBounds.Size + renderOnto.DeviceClipBounds.Pos
+            : context.DocumentSize;
         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);
+        if (AllowHighDpiRendering)
+        {
+            outputWorkingSurface.DrawingSurface.Canvas.SetMatrix(renderOnto.Canvas.TotalMatrix);
+            renderOnto.Canvas.SetMatrix(Matrix3X3.Identity);
+        }
 
-        renderOnto.Canvas.SetMatrix(Matrix3X3.Identity);
+        using var paint = new Paint
+        {
+            Color = new Color(255, 255, 255, 255), BlendMode = Drawie.Backend.Core.Surfaces.BlendMode.SrcOver
+        };
 
-        DrawLayerOnTexture(context, outputWorkingSurface.DrawingSurface, useFilters, blendPaint);
+        DrawLayerOnTexture(context, outputWorkingSurface.DrawingSurface, false, paint);
 
         ApplyMaskIfPresent(outputWorkingSurface.DrawingSurface, context);
 
@@ -105,6 +111,15 @@ public abstract class LayerNode : StructureNode, IReadOnlyLayerNode, IClipSource
         }
 
         blendPaint.BlendMode = RenderContext.GetDrawingBlendMode(BlendMode.Value);
+        if (useFilters)
+        {
+            blendPaint.SetFilters(Filters.Value);
+        }
+        else
+        {
+            blendPaint.SetFilters(null);
+        }
+
         DrawWithResolution(outputWorkingSurface.DrawingSurface, renderOnto, context.ChunkResolution);
 
         renderOnto.Canvas.RestoreToCount(saved);

+ 1 - 0
tests/PixiEditor.Tests/PixiEditorTest.cs

@@ -31,6 +31,7 @@ public class PixiEditorTest
         var app = new TestingApp();
         app.Initialize(engine);
         IWindow window = app.CreateMainWindow();
+        window.IsVisible = false;
         window.Initialize();
         DrawingBackendApi.InitializeBackend(engine.RenderApi);
     }

+ 5 - 7
tests/PixiEditor.Tests/RenderTests.cs

@@ -1,20 +1,18 @@
 using Avalonia.Headless.XUnit;
 using Drawie.Backend.Core;
-using Drawie.Backend.Core.ColorsImpl;
-using Drawie.Backend.Core.Surfaces;
-using Drawie.Backend.Core.Surfaces.ImageData;
-using Drawie.Numerics;
-using PixiEditor.ChangeableDocument.Changeables.Animations;
 using PixiEditor.Models.IO;
-using PixiEditor.ViewModels.Document;
 
 namespace PixiEditor.Tests;
 
 public class RenderTests : FullPixiEditorTest
 {
     [AvaloniaTheory]
-    [InlineData("fibi")]
+    [InlineData("Fibi")]
     [InlineData("Pond")]
+    [InlineData("SmlPxlCircShadWithMask")]
+    [InlineData("SmallPixelArtCircleShadow")]
+    [InlineData("SmlPxlCircShadWithMaskClipped")]
+    [InlineData("SmlPxlCircShadWithMaskClippedInFolder")]
     public void TestThatPixiFilesRenderTheSameResultAsSavedPng(string fileName)
     {
         string pixiFile = Path.Combine("TestFiles", "RenderTests", fileName + ".pixi");

+ 0 - 0
tests/PixiEditor.Tests/TestFiles/RenderTests/fibi.pixi → tests/PixiEditor.Tests/TestFiles/RenderTests/Fibi.pixi


+ 0 - 0
tests/PixiEditor.Tests/TestFiles/RenderTests/fibi.png → tests/PixiEditor.Tests/TestFiles/RenderTests/Fibi.png


BIN
tests/PixiEditor.Tests/TestFiles/RenderTests/Pond.png


BIN
tests/PixiEditor.Tests/TestFiles/RenderTests/SmallPixelArtCircleShadow.pixi


BIN
tests/PixiEditor.Tests/TestFiles/RenderTests/SmallPixelArtCircleShadow.png


BIN
tests/PixiEditor.Tests/TestFiles/RenderTests/SmlPxlCircShadWithMask.pixi


BIN
tests/PixiEditor.Tests/TestFiles/RenderTests/SmlPxlCircShadWithMask.png


BIN
tests/PixiEditor.Tests/TestFiles/RenderTests/SmlPxlCircShadWithMaskClipped.pixi


BIN
tests/PixiEditor.Tests/TestFiles/RenderTests/SmlPxlCircShadWithMaskClipped.png


BIN
tests/PixiEditor.Tests/TestFiles/RenderTests/SmlPxlCircShadWithMaskClippedInFolder.pixi


BIN
tests/PixiEditor.Tests/TestFiles/RenderTests/SmlPxlCircShadWithMaskClippedInFolder.png