Browse Source

Fixed exporting scaling and color space rendering in high dpi mode

flabbet 7 months ago
parent
commit
fb57c6da6e

+ 14 - 3
src/PixiEditor.ChangeableDocument/Rendering/DocumentRenderer.cs

@@ -5,6 +5,7 @@ using PixiEditor.ChangeableDocument.Changeables.Graph.Interfaces;
 using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
 using PixiEditor.ChangeableDocument.Changeables.Interfaces;
 using Drawie.Backend.Core;
+using Drawie.Backend.Core.Numerics;
 using Drawie.Backend.Core.Surfaces;
 using Drawie.Backend.Core.Surfaces.ImageData;
 using Drawie.Backend.Core.Surfaces.PaintImpl;
@@ -179,23 +180,33 @@ public class DocumentRenderer : IPreviewRenderable
         return true;
     }
 
-    public void RenderDocument(DrawingSurface toRenderOn, KeyFrameTime frameTime)
+    public void RenderDocument(DrawingSurface toRenderOn, KeyFrameTime frameTime, VecI renderSize)
     {
         IsBusy = true;
 
-        if (renderTexture == null || renderTexture.Size != Document.Size)
+        if (renderTexture == null || renderTexture.Size != renderSize)
         {
             renderTexture?.Dispose();
-            renderTexture = Texture.ForProcessing(Document.Size, Document.ProcessingColorSpace);
+            renderTexture = Texture.ForProcessing(renderSize, Document.ProcessingColorSpace);
         }
 
+        renderTexture.DrawingSurface.Canvas.Save();
         renderTexture.DrawingSurface.Canvas.Clear();
+
+        renderTexture.DrawingSurface.Canvas.SetMatrix(toRenderOn.Canvas.TotalMatrix);
+        toRenderOn.Canvas.Save();
+        toRenderOn.Canvas.SetMatrix(Matrix3X3.Identity);
+        
         RenderContext context =
             new(renderTexture.DrawingSurface, frameTime, ChunkResolution.Full, Document.Size,
                 Document.ProcessingColorSpace) { FullRerender = true };
         Document.NodeGraph.Execute(context);
 
         toRenderOn.Canvas.DrawSurface(renderTexture.DrawingSurface, 0, 0);
+        
+        renderTexture.DrawingSurface.Canvas.Restore();
+        toRenderOn.Canvas.Restore();
+        
         IsBusy = false;
     }
     

+ 1 - 1
src/PixiEditor/Models/Controllers/ClipboardController.cs

@@ -148,7 +148,7 @@ internal static class ClipboardController
         using Surface documentSurface = new Surface(document.SizeBindable);
 
         document.Renderer.RenderDocument(documentSurface.DrawingSurface,
-            document.AnimationDataViewModel.ActiveFrameTime);
+            document.AnimationDataViewModel.ActiveFrameTime, document.SizeBindable);
 
         Surface surfaceToCopy = new Surface((VecI)copyArea.Size.Ceiling());
         using Paint paint = new Paint();

+ 19 - 1
src/PixiEditor/Models/Rendering/SceneRenderer.cs

@@ -1,5 +1,6 @@
 using ChunkyImageLib.DataHolders;
 using Drawie.Backend.Core;
+using Drawie.Backend.Core.Numerics;
 using PixiEditor.ChangeableDocument.Changeables.Interfaces;
 using PixiEditor.ChangeableDocument.Rendering;
 using Drawie.Backend.Core.Surfaces;
@@ -35,13 +36,25 @@ internal class SceneRenderer
     {
         DrawingSurface renderTarget = target;
         Texture? renderTexture = null;
+        bool restoreCanvas = false;
 
         if (!HighResRendering || !HighDpiRenderNodePresent(Document.NodeGraph))
         {
             renderTexture = Texture.ForProcessing(Document.Size, Document.ProcessingColorSpace);
-
             renderTarget = renderTexture.DrawingSurface;
         }
+        else
+        {
+            renderTexture = Texture.ForProcessing(renderTarget.DeviceClipBounds.Size, Document.ProcessingColorSpace);
+            renderTarget = renderTexture.DrawingSurface;
+            
+            target.Canvas.Save();
+            renderTarget.Canvas.Save();
+            
+            renderTarget.Canvas.SetMatrix(target.Canvas.TotalMatrix);
+            target.Canvas.SetMatrix(Matrix3X3.Identity);
+            restoreCanvas = true;
+        }
 
         RenderContext context = new(renderTarget, DocumentViewModel.AnimationHandler.ActiveFrameTime,
             resolution, Document.Size, Document.ProcessingColorSpace);
@@ -52,6 +65,11 @@ internal class SceneRenderer
         {
             target.Canvas.DrawSurface(renderTexture.DrawingSurface, 0, 0);
             renderTexture.Dispose();
+
+            if (restoreCanvas)
+            {
+                target.Canvas.Restore();
+            }
         }
     }
 

+ 1 - 1
src/PixiEditor/ViewModels/Document/DocumentViewModel.cs

@@ -507,7 +507,7 @@ internal partial class DocumentViewModel : PixiObservableObject, IDocument
                 VecD scaling = new VecD(renderSize.X / (double)SizeBindable.X, renderSize.Y / (double)SizeBindable.Y);
 
                 finalSurface.DrawingSurface.Canvas.Scale((float)scaling.X, (float)scaling.Y);
-                Renderer.RenderDocument(finalSurface.DrawingSurface, frameTime);
+                Renderer.RenderDocument(finalSurface.DrawingSurface, frameTime, renderSize);
 
                 finalSurface.DrawingSurface.Canvas.Restore();
             });