Explorar o código

Fixed tests and avalonia versions

Krzysztof Krysiński hai 1 semana
pai
achega
c7b4b73c3c

+ 1 - 1
samples/Directory.Build.props

@@ -1,7 +1,7 @@
 <Project>
 <Project>
     <PropertyGroup>
     <PropertyGroup>
         <CodeAnalysisRuleSet>../Custom.ruleset</CodeAnalysisRuleSet>
         <CodeAnalysisRuleSet>../Custom.ruleset</CodeAnalysisRuleSet>
-		    <AvaloniaVersion>11.3.6</AvaloniaVersion>
+		    <AvaloniaVersion>11.3.9-cibuild0004033-alpha</AvaloniaVersion>
     </PropertyGroup>
     </PropertyGroup>
     <ItemGroup>
     <ItemGroup>
         <PackageReference Include="StyleCop.Analyzers" Version="1.1.118" />
         <PackageReference Include="StyleCop.Analyzers" Version="1.1.118" />

+ 1 - 1
src/PixiEditor/Helpers/SurfaceHelpers.cs

@@ -40,7 +40,7 @@ public static class SurfaceHelpers
 
 
     public static unsafe byte[] ToByteArray(this Surface surface, ColorType colorType = ColorType.Bgra8888, AlphaType alphaType = AlphaType.Premul, ColorSpace colorSpace = null)
     public static unsafe byte[] ToByteArray(this Surface surface, ColorType colorType = ColorType.Bgra8888, AlphaType alphaType = AlphaType.Premul, ColorSpace colorSpace = null)
     {
     {
-        using var ctx = IDrawieInteropContext.Current.EnsureContext();
+        using var ctx = DrawingBackendApi.Current.RenderingDispatcher.EnsureContext();
         int width = surface.Size.X;
         int width = surface.Size.X;
         int height = surface.Size.Y;
         int height = surface.Size.Y;
         var imageInfo = new ImageInfo(width, height, colorType, alphaType, colorSpace == null ? surface.ImageInfo.ColorSpace : colorSpace);
         var imageInfo = new ImageInfo(width, height, colorType, alphaType, colorSpace == null ? surface.ImageInfo.ColorSpace : colorSpace);

+ 71 - 0
src/PixiEditor/Models/Serialization/Factories/Paintables/TexturePaintableSerializationFactory.cs

@@ -0,0 +1,71 @@
+using Drawie.Backend.Core.ColorsImpl.Paintables;
+using Silk.NET.OpenGL;
+
+namespace PixiEditor.Models.Serialization.Factories.Paintables;
+
+public class TexturePaintableSerializationFactory : SerializationFactory<byte[], TexturePaintable>,
+    IPaintableSerializationFactory
+{
+    public override string DeserializationId { get; } = "PixiEditor.TexturePaintable";
+
+    private readonly TextureSerializationFactory textureFactory = new TextureSerializationFactory();
+
+    public override byte[] Serialize(TexturePaintable original)
+    {
+        ByteBuilder builder = new();
+        Serialize(original, builder);
+
+        return builder.Build();
+    }
+
+    public override bool TryDeserialize(object serialized, out TexturePaintable original,
+        (string serializerName, string serializerVersion) serializerData)
+    {
+        if (serialized is not byte[] bytes)
+        {
+            original = null!;
+            return false;
+        }
+
+        ByteExtractor extractor = new(bytes);
+        original = TryDeserialize(extractor) as TexturePaintable;
+
+        return true;
+    }
+
+    public Paintable TryDeserialize(ByteExtractor extractor)
+    {
+        return TryDeserialize(extractor, default);
+    }
+
+    public Paintable TryDeserialize(ByteExtractor extractor,
+        (string serializerName, string serializerVersion) serializerData)
+    {
+        textureFactory.Config = Config;
+        textureFactory.ResourceLocator = ResourceLocator;
+
+        int length = extractor.GetInt();
+        var textureData = extractor.GetByteSpan(length).ToArray();
+        if (textureFactory.TryDeserialize(textureData, out var tex, serializerData))
+        {
+            return new TexturePaintable(tex);
+        }
+
+        return null!;
+    }
+
+    public void Serialize(Paintable paintable, ByteBuilder builder)
+    {
+        if (paintable is not TexturePaintable texturePaintable)
+        {
+            throw new ArgumentException("Paintable is not a TexturePaintable", nameof(paintable));
+        }
+
+        textureFactory.Config = Config;
+        textureFactory.ResourceLocator = ResourceLocator;
+
+        var array = textureFactory.Serialize(texturePaintable.Image);
+        builder.AddInt(array.Length);
+        builder.AddByteArray(array);
+    }
+}

+ 1 - 1
tests/ChunkyImageLibTest/ChunkyImageTests.cs

@@ -21,7 +21,7 @@ public class ChunkyImageTests : PixiEditorTest
         image.EnqueueDrawRectangle(new(new(5, 5), new(80, 80), 0, 0, 2, Colors.AliceBlue, Colors.Snow));
         image.EnqueueDrawRectangle(new(new(5, 5), new(80, 80), 0, 0, 2, Colors.AliceBlue, Colors.Snow));
         using (Chunk target = Chunk.Create(ColorSpace.CreateSrgb()))
         using (Chunk target = Chunk.Create(ColorSpace.CreateSrgb()))
         {
         {
-            image.DrawMostUpToDateChunkOn(new(0, 0), ChunkResolution.Full, target.Surface.DrawingSurface, VecI.Zero);
+            image.DrawMostUpToDateChunkOn(new(0, 0), ChunkResolution.Full, target.Surface.DrawingSurface.Canvas, VecI.Zero);
             image.CancelChanges();
             image.CancelChanges();
             image.EnqueueResize(new(ChunkyImage.FullChunkSize * 4, ChunkyImage.FullChunkSize * 4));
             image.EnqueueResize(new(ChunkyImage.FullChunkSize * 4, ChunkyImage.FullChunkSize * 4));
             image.EnqueueDrawRectangle(new(VecD.Zero, image.CommittedSize, 0, 0, 2, Colors.AliceBlue, Colors.Snow,
             image.EnqueueDrawRectangle(new(VecD.Zero, image.CommittedSize, 0, 0, 2, Colors.AliceBlue, Colors.Snow,

+ 1 - 1
tests/Directory.Build.props

@@ -1,7 +1,7 @@
 <Project>
 <Project>
     <PropertyGroup>
     <PropertyGroup>
         <CodeAnalysisRuleSet>../Custom.ruleset</CodeAnalysisRuleSet>
         <CodeAnalysisRuleSet>../Custom.ruleset</CodeAnalysisRuleSet>
-		<AvaloniaVersion>11.3.6</AvaloniaVersion>
+		<AvaloniaVersion>11.3.9-cibuild0004033-alpha</AvaloniaVersion>
     </PropertyGroup>
     </PropertyGroup>
     <ItemGroup>
     <ItemGroup>
         <PackageReference Include="StyleCop.Analyzers" Version="1.1.118" />
         <PackageReference Include="StyleCop.Analyzers" Version="1.1.118" />

+ 22 - 0
tests/PixiEditor.Backend.Tests/MockDocument.cs

@@ -1,5 +1,6 @@
 using Drawie.Backend.Core.Surfaces.ImageData;
 using Drawie.Backend.Core.Surfaces.ImageData;
 using Drawie.Numerics;
 using Drawie.Numerics;
+using PixiEditor.ChangeableDocument.Changeables.Graph;
 using PixiEditor.ChangeableDocument.Changeables.Graph.Interfaces;
 using PixiEditor.ChangeableDocument.Changeables.Graph.Interfaces;
 using PixiEditor.ChangeableDocument.Changeables.Interfaces;
 using PixiEditor.ChangeableDocument.Changeables.Interfaces;
 using PixiEditor.ChangeableDocument.Rendering;
 using PixiEditor.ChangeableDocument.Rendering;
@@ -74,6 +75,7 @@ public class MockDocument : IReadOnlyDocument
 
 
     public IReadOnlyReferenceLayer? ReferenceLayer { get; }
     public IReadOnlyReferenceLayer? ReferenceLayer { get; }
     public DocumentRenderer Renderer { get; }
     public DocumentRenderer Renderer { get; }
+    public IReadOnlyBlackboard Blackboard { get; }
     public ColorSpace ProcessingColorSpace { get; }
     public ColorSpace ProcessingColorSpace { get; }
     public void InitProcessingColorSpace(ColorSpace processingColorSpace)
     public void InitProcessingColorSpace(ColorSpace processingColorSpace)
     {
     {
@@ -89,4 +91,24 @@ public class MockDocument : IReadOnlyDocument
     {
     {
         throw new NotImplementedException();
         throw new NotImplementedException();
     }
     }
+
+    public ICrossDocumentPipe<IReadOnlyNodeGraph> CreateGraphPipe()
+    {
+        throw new NotImplementedException();
+    }
+
+    public IReadOnlyDocument Clone(bool preserveDocumentId = false)
+    {
+        throw new NotImplementedException();
+    }
+
+    public IReadOnlyStructureNode[] GetStructureTreeInOrder()
+    {
+        throw new NotImplementedException();
+    }
+
+    public object Clone()
+    {
+        throw new NotImplementedException();
+    }
 }
 }

+ 3 - 2
tests/PixiEditor.Backend.Tests/NodeSystemTests.cs

@@ -24,7 +24,8 @@ public class NodeSystemTests : PixiEditorTest
     private Type[] knownNonSerializableTypes = new[]
     private Type[] knownNonSerializableTypes = new[]
     {
     {
         typeof(Filter),
         typeof(Filter),
-        typeof(Painter)
+        typeof(Painter),
+        typeof(Object) // Objects are assumed to be only passed from other node and not serialized directly
     };
     };
 
 
     public NodeSystemTests(ITestOutputHelper output)
     public NodeSystemTests(ITestOutputHelper output)
@@ -98,7 +99,7 @@ public class NodeSystemTests : PixiEditorTest
             Assert.NotNull(node);
             Assert.NotNull(node);
 
 
             Dictionary<string, object> data = new Dictionary<string, object>();
             Dictionary<string, object> data = new Dictionary<string, object>();
-            node.SerializeAdditionalData(data);
+            node.SerializeAdditionalData(target, data);
             Assert.NotNull(data);
             Assert.NotNull(data);
         }
         }
     }
     }

+ 1 - 1
tests/PixiEditor.Tests/BlendingTests.cs

@@ -75,7 +75,7 @@ public class BlendingTests : PixiEditorTest
         secondImageLayer.BlendMode.NonOverridenValue = blendMode;
         secondImageLayer.BlendMode.NonOverridenValue = blendMode;
 
 
         Surface output = Surface.ForProcessing(VecI.One, ColorSpace.CreateSrgbLinear());
         Surface output = Surface.ForProcessing(VecI.One, ColorSpace.CreateSrgbLinear());
-        graph.Execute(new RenderContext(output.DrawingSurface, 0, ChunkResolution.Full, VecI.One, VecI.One, ColorSpace.CreateSrgbLinear(), SamplingOptions.Default, 1));
+        graph.Execute(new RenderContext(output.DrawingSurface.Canvas, 0, ChunkResolution.Full, VecI.One, VecI.One, ColorSpace.CreateSrgbLinear(), SamplingOptions.Default, new NodeGraph(), 1));
 
 
         Color result = output.GetSrgbPixel(VecI.Zero);
         Color result = output.GetSrgbPixel(VecI.Zero);
         Assert.Equal(expectedColor, result.ToRgbHex());
         Assert.Equal(expectedColor, result.ToRgbHex());

+ 1 - 1
tests/PixiEditor.Tests/PixiEditor.Tests.csproj

@@ -12,7 +12,7 @@
 
 
     <ItemGroup>
     <ItemGroup>
         <PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
         <PackageReference Include="Avalonia" Version="$(AvaloniaVersion)" />
-        <PackageReference Include="Avalonia.Headless.XUnit" Version="$(AvaloniaVersion)" />
+        <PackageReference Include="Avalonia.Headless.XUnit" Version="11.3.8" />
         <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
         <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
         <PackageReference Include="xunit" Version="2.9.2"/>
         <PackageReference Include="xunit" Version="2.9.2"/>
         <PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
         <PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">

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

@@ -8,6 +8,7 @@ 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;
 using Drawie.Numerics;
 using Drawie.Numerics;
+using PixiEditor.ChangeableDocument.Rendering.ContextData;
 using PixiEditor.Models.IO;
 using PixiEditor.Models.IO;
 using PixiEditor.Models.Position;
 using PixiEditor.Models.Position;
 using Xunit.Abstractions;
 using Xunit.Abstractions;
@@ -96,9 +97,13 @@ public class RenderTests : FullPixiEditorTest
             0,
             0,
             document.SizeBindable / 2f,
             document.SizeBindable / 2f,
             document.SizeBindable,
             document.SizeBindable,
-            Matrix3X3.Identity, null, "DEFAULT", SamplingOptions.Default, document.SizeBindable, ChunkResolution.Half,
+            new ViewportData(),
+            new PointerInfo(),
+            new KeyboardInfo(),
+            new EditorData(),
+            null, "DEFAULT", SamplingOptions.Default, document.SizeBindable, ChunkResolution.Half,
             Guid.NewGuid(), false, false, () => { });
             Guid.NewGuid(), false, false, () => { });
-        using var output = document.SceneRenderer.RenderScene(info, new AffectedArea(), null);
+        using var output = document.SceneRenderer.RenderScene(info, new AffectedArea());
 
 
         Color expectedColor = Colors.Yellow;
         Color expectedColor = Colors.Yellow;
 
 

+ 31 - 0
tests/PixiEditor.Tests/SerializationTests.cs

@@ -1,7 +1,11 @@
 using Avalonia.Headless.XUnit;
 using Avalonia.Headless.XUnit;
+using Drawie.Backend.Core;
 using Drawie.Backend.Core.Bridge;
 using Drawie.Backend.Core.Bridge;
+using Drawie.Backend.Core.ColorsImpl;
 using Drawie.Backend.Core.ColorsImpl.Paintables;
 using Drawie.Backend.Core.ColorsImpl.Paintables;
 using Drawie.Backend.Core.Surfaces.ImageData;
 using Drawie.Backend.Core.Surfaces.ImageData;
+using Drawie.Backend.Core.Surfaces.PaintImpl;
+using Drawie.Numerics;
 using Drawie.Skia;
 using Drawie.Skia;
 using DrawiEngine;
 using DrawiEngine;
 using PixiEditor.ChangeableDocument.Changeables.Interfaces;
 using PixiEditor.ChangeableDocument.Changeables.Interfaces;
@@ -11,6 +15,7 @@ using PixiEditor.Models.Serialization;
 using PixiEditor.Models.Serialization.Factories;
 using PixiEditor.Models.Serialization.Factories;
 using PixiEditor.Models.Serialization.Factories.Paintables;
 using PixiEditor.Models.Serialization.Factories.Paintables;
 using PixiEditor.Parser.Skia.Encoders;
 using PixiEditor.Parser.Skia.Encoders;
+using PixiEditor.ViewModels.Document;
 
 
 namespace PixiEditor.Tests;
 namespace PixiEditor.Tests;
 
 
@@ -50,6 +55,32 @@ public class SerializationTests : PixiEditorTest
         }
         }
     }
     }
 
 
+    [Fact]
+    public void TestTexturePaintableFactory()
+    {
+        Texture texture = new Texture(new VecI(32, 32));
+        texture.DrawingSurface.Canvas.DrawCircle(16, 16, 16, new Paint() { Color = Colors.Red, BlendMode = Drawie.Backend.Core.Surfaces.BlendMode.Src });
+        TexturePaintable paintable = new TexturePaintable(texture);
+        TexturePaintableSerializationFactory factory = new TexturePaintableSerializationFactory();
+        factory.Config = new SerializationConfig(new QoiEncoder(), ColorSpace.CreateSrgbLinear());
+        var serialized = factory.Serialize(paintable);
+        var deserialized = (TexturePaintable)factory.Deserialize(serialized, default);
+
+        Assert.NotNull(deserialized);
+        var deserializedImage = deserialized.Image;
+        Assert.NotNull(deserializedImage);
+        Assert.Equal(texture.Size, deserializedImage.Size);
+        for (int y = 0; y < texture.Size.Y; y++)
+        {
+            for (int x = 0; x < texture.Size.X; x++)
+            {
+                Color originalPixel = texture.GetSrgbPixel(new VecI(x, y));
+                Color deserializedPixel = deserializedImage.GetSrgbPixel(new VecI(x, y));
+                Assert.Equal(originalPixel, deserializedPixel);
+            }
+        }
+    }
+
     [AvaloniaTheory]
     [AvaloniaTheory]
     [InlineData("Fibi")]
     [InlineData("Fibi")]
     [InlineData("Pond")]
     [InlineData("Pond")]