Browse Source

Seems like render is working

Krzysztof Krysiński 3 months ago
parent
commit
0b8da9665c

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

@@ -99,7 +99,7 @@ public class FolderNode : StructureNode, IReadOnlyFolderNode, IClipSource
 
         Content.Value?.Paint(sceneContext, outputWorkingSurface.DrawingSurface);
 
-        ApplyMaskIfPresent(outputWorkingSurface.DrawingSurface, sceneContext);
+        ApplyMaskIfPresent(outputWorkingSurface.DrawingSurface, sceneContext, sceneContext.ChunkResolution);
 
         if (Background.Value != null && sceneContext.TargetPropertyOutput != RawOutput)
         {

+ 3 - 2
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/ImageLayerNode.cs

@@ -67,11 +67,12 @@ public class ImageLayerNode : LayerNode, IReadOnlyImageNode
 
     protected internal override void DrawLayerOnTexture(SceneObjectRenderContext ctx,
         DrawingSurface workingSurface,
+        ChunkResolution resolution,
         bool useFilters, Paint paint)
     {
         int scaled = workingSurface.Canvas.Save();
-        workingSurface.Canvas.Translate(GetScenePosition(ctx.FrameTime) * ctx.ChunkResolution.Multiplier());
-        workingSurface.Canvas.Scale((float)ctx.ChunkResolution.Multiplier());
+        workingSurface.Canvas.Translate(GetScenePosition(ctx.FrameTime) * resolution.Multiplier());
+        workingSurface.Canvas.Scale((float)resolution.Multiplier());
 
         DrawLayerOnto(ctx, workingSurface, useFilters, paint);
 

+ 29 - 13
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/LayerNode.cs

@@ -56,13 +56,13 @@ public abstract class LayerNode : StructureNode, IReadOnlyLayerNode, IClipSource
                     BlendMode = Drawie.Backend.Core.Surfaces.BlendMode.SrcOver
                 };
 
-                using var tempSurface = Texture.ForProcessing(context.DocumentSize, context.ProcessingColorSpace);
-                tempSurface.DrawingSurface.Canvas.Scale((float)context.ChunkResolution.InvertedMultiplier());
+                var tempSurface = TryInitWorkingSurface(context.DocumentSize, context.ChunkResolution,
+                    context.ProcessingColorSpace, 22);
 
-                DrawLayerOnTexture(context, tempSurface.DrawingSurface, useFilters, targetPaint);
+                DrawLayerOnTexture(context, tempSurface.DrawingSurface, context.ChunkResolution, useFilters, targetPaint);
 
                 blendPaint.SetFilters(null);
-                renderOnto.Canvas.DrawSurface(tempSurface.DrawingSurface, 0, 0, blendPaint);
+                DrawWithResolution(tempSurface.DrawingSurface, renderOnto, context.ChunkResolution);
             }
 
             return;
@@ -73,8 +73,10 @@ public abstract class LayerNode : StructureNode, IReadOnlyLayerNode, IClipSource
             : context.DocumentSize;
         int saved = renderOnto.Canvas.Save();
 
+        var adjustedResolution = AllowHighDpiRendering ? ChunkResolution.Full : context.ChunkResolution;
+
         var outputWorkingSurface =
-            TryInitWorkingSurface(size, context.ChunkResolution, context.ProcessingColorSpace, 1);
+            TryInitWorkingSurface(size, adjustedResolution, context.ProcessingColorSpace, 1);
         outputWorkingSurface.DrawingSurface.Canvas.Clear();
         outputWorkingSurface.DrawingSurface.Canvas.Save();
         if (AllowHighDpiRendering)
@@ -88,18 +90,25 @@ public abstract class LayerNode : StructureNode, IReadOnlyLayerNode, IClipSource
             Color = new Color(255, 255, 255, 255), BlendMode = Drawie.Backend.Core.Surfaces.BlendMode.SrcOver
         };
 
-        DrawLayerOnTexture(context, outputWorkingSurface.DrawingSurface, false, paint);
+        DrawLayerOnTexture(context, outputWorkingSurface.DrawingSurface, adjustedResolution, false, paint);
 
-        ApplyMaskIfPresent(outputWorkingSurface.DrawingSurface, context);
+        ApplyMaskIfPresent(outputWorkingSurface.DrawingSurface, context, adjustedResolution);
 
         if (Background.Value != null)
         {
-            Texture tempSurface = TryInitWorkingSurface(size, context.ChunkResolution, context.ProcessingColorSpace, 4);
+            Texture tempSurface = TryInitWorkingSurface(size, adjustedResolution, context.ProcessingColorSpace, 4);
 
             tempSurface.DrawingSurface.Canvas.Save();
-            tempSurface.DrawingSurface.Canvas.SetMatrix(outputWorkingSurface.DrawingSurface.Canvas.TotalMatrix);
-
-            outputWorkingSurface.DrawingSurface.Canvas.SetMatrix(Matrix3X3.Identity);
+            if (AllowHighDpiRendering)
+            {
+                tempSurface.DrawingSurface.Canvas.SetMatrix(outputWorkingSurface.DrawingSurface.Canvas.TotalMatrix);
+                outputWorkingSurface.DrawingSurface.Canvas.SetMatrix(Matrix3X3.Identity);
+            }
+            else
+            {
+                tempSurface.DrawingSurface.Canvas.Scale(
+                    (float)context.ChunkResolution.Multiplier());
+            }
 
             tempSurface.DrawingSurface.Canvas.Clear();
             if (Background.Connection is { Node: IClipSource clipSource } && ClipToPreviousMember)
@@ -120,7 +129,7 @@ public abstract class LayerNode : StructureNode, IReadOnlyLayerNode, IClipSource
             blendPaint.SetFilters(null);
         }
 
-        DrawWithResolution(outputWorkingSurface.DrawingSurface, renderOnto, context.ChunkResolution);
+        DrawWithResolution(outputWorkingSurface.DrawingSurface, renderOnto, adjustedResolution);
 
         renderOnto.Canvas.RestoreToCount(saved);
         outputWorkingSurface.DrawingSurface.Canvas.Restore();
@@ -128,10 +137,11 @@ public abstract class LayerNode : StructureNode, IReadOnlyLayerNode, IClipSource
 
     protected internal virtual void DrawLayerOnTexture(SceneObjectRenderContext ctx,
         DrawingSurface workingSurface,
+        ChunkResolution resolution,
         bool useFilters, Paint paint)
     {
         int scaled = workingSurface.Canvas.Save();
-        workingSurface.Canvas.Scale((float)ctx.ChunkResolution.Multiplier());
+        workingSurface.Canvas.Scale((float)resolution.Multiplier());
 
         DrawLayerOnto(ctx, workingSurface, useFilters, paint);
 
@@ -219,9 +229,15 @@ public abstract class LayerNode : StructureNode, IReadOnlyLayerNode, IClipSource
 
         if (!hasSurface || workingSurface.Size != targetSize || workingSurface.IsDisposed)
         {
+            workingSurface?.Dispose();
             workingSurfaces[(targetResolution, id)] = Texture.ForProcessing(targetSize, processingCs);
             workingSurface = workingSurfaces[(targetResolution, id)];
         }
+        else
+        {
+            workingSurface.DrawingSurface.Canvas.SetMatrix(Matrix3X3.Identity);
+            workingSurface.DrawingSurface.Canvas.Clear();
+        }
 
         return workingSurface;
     }

+ 30 - 18
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/StructureNode.cs

@@ -47,13 +47,15 @@ public abstract class StructureNode : RenderNode, IReadOnlyStructureNode, IRende
     public ChunkyImage? EmbeddedMask { get; set; }
 
     protected Texture renderedMask;
-    protected static readonly Paint replacePaint = new Paint() { BlendMode = Drawie.Backend.Core.Surfaces.BlendMode.Src };
+
+    protected static readonly Paint replacePaint =
+        new Paint() { BlendMode = Drawie.Backend.Core.Surfaces.BlendMode.Src };
 
     protected static readonly Paint clearPaint = new Paint()
     {
         BlendMode = Drawie.Backend.Core.Surfaces.BlendMode.Src, Color = Colors.Transparent
     };
-    
+
     protected static readonly Paint clipPaint = new Paint()
     {
         BlendMode = Drawie.Backend.Core.Surfaces.BlendMode.DstIn
@@ -70,12 +72,16 @@ public abstract class StructureNode : RenderNode, IReadOnlyStructureNode, IRende
         set => DisplayName = value;
     }
 
-    protected Paint maskPaint = new Paint() { BlendMode = Drawie.Backend.Core.Surfaces.BlendMode.DstIn, ColorFilter = Nodes.Filters.MaskFilter };
+    protected Paint maskPaint = new Paint()
+    {
+        BlendMode = Drawie.Backend.Core.Surfaces.BlendMode.DstIn, ColorFilter = Nodes.Filters.MaskFilter
+    };
+
     protected Paint blendPaint = new Paint() { BlendMode = Drawie.Backend.Core.Surfaces.BlendMode.SrcOver };
 
     protected Paint maskPreviewPaint = new Paint()
     {
-        BlendMode = Drawie.Backend.Core.Surfaces.BlendMode.SrcOver, 
+        BlendMode = Drawie.Backend.Core.Surfaces.BlendMode.SrcOver,
         ColorFilter = ColorFilter.CreateCompose(Nodes.Filters.AlphaGrayscaleFilter, Nodes.Filters.MaskFilter)
     };
 
@@ -141,22 +147,22 @@ public abstract class StructureNode : RenderNode, IReadOnlyStructureNode, IRende
     {
         RenderForOutput(context, renderTarget, FilterlessOutput);
     }
-    
+
     private void OnRawPaint(RenderContext context, DrawingSurface renderTarget)
     {
         RenderForOutput(context, renderTarget, RawOutput);
     }
-    
+
     public abstract VecD GetScenePosition(KeyFrameTime frameTime);
     public abstract VecD GetSceneSize(KeyFrameTime frameTime);
 
     public void RenderForOutput(RenderContext context, DrawingSurface renderTarget, RenderOutputProperty output)
     {
-        if(IsDisposed)
+        if (IsDisposed)
         {
             return;
         }
-        
+
         var renderObjectContext = CreateSceneContext(context, renderTarget, output);
 
         int renderSaved = renderTarget.Canvas.Save();
@@ -185,16 +191,16 @@ public abstract class StructureNode : RenderNode, IReadOnlyStructureNode, IRende
 
     public abstract void Render(SceneObjectRenderContext sceneContext);
 
-    protected void ApplyMaskIfPresent(DrawingSurface surface, RenderContext context)
+    protected void ApplyMaskIfPresent(DrawingSurface surface, RenderContext context, ChunkResolution renderResolution)
     {
         if (MaskIsVisible.Value)
         {
             if (CustomMask.Value != null)
             {
                 int layer = surface.Canvas.SaveLayer(maskPaint);
-                surface.Canvas.Scale((float)context.ChunkResolution.Multiplier());
+                surface.Canvas.Scale((float)renderResolution.Multiplier());
                 CustomMask.Value.Paint(context, surface);
-                
+
                 surface.Canvas.RestoreToCount(layer);
             }
             else if (EmbeddedMask != null)
@@ -206,9 +212,12 @@ public abstract class StructureNode : RenderNode, IReadOnlyStructureNode, IRende
                         ChunkResolution.Full,
                         surface, VecI.Zero, maskPaint);
                 }
-                else if(renderedMask != null)
+                else if (renderedMask != null)
                 {
+                    int saved = surface.Canvas.Save();
+                    surface.Canvas.Scale((float)renderResolution.Multiplier());
                     surface.Canvas.DrawSurface(renderedMask.DrawingSurface, 0, 0, maskPaint);
+                    surface.Canvas.RestoreToCount(saved);
                 }
             }
         }
@@ -216,10 +225,12 @@ public abstract class StructureNode : RenderNode, IReadOnlyStructureNode, IRende
 
     protected override int GetContentCacheHash()
     {
-        return HashCode.Combine(base.GetContentCacheHash(), EmbeddedMask?.GetCacheHash() ?? 0, ClipToPreviousMember ? 1 : 0);
+        return HashCode.Combine(base.GetContentCacheHash(), EmbeddedMask?.GetCacheHash() ?? 0,
+            ClipToPreviousMember ? 1 : 0);
     }
 
-    public virtual void RenderChunk(VecI chunkPos, ChunkResolution resolution, KeyFrameTime frameTime, ColorSpace processingColorSpace)
+    public virtual void RenderChunk(VecI chunkPos, ChunkResolution resolution, KeyFrameTime frameTime,
+        ColorSpace processingColorSpace)
     {
         RenderChunkyImageChunk(chunkPos, resolution, EmbeddedMask, 55, processingColorSpace, ref renderedMask);
     }
@@ -234,11 +245,11 @@ public abstract class StructureNode : RenderNode, IReadOnlyStructureNode, IRende
         }
 
         VecI targetSize = img.LatestSize;
-        
+
         renderSurface = RequestTexture(textureId, targetSize, processingColorSpace, false);
 
         int saved = renderSurface.DrawingSurface.Canvas.Save();
-        
+
         if (!img.DrawMostUpToDateChunkOn(
                 chunkPos,
                 ChunkResolution.Full,
@@ -250,7 +261,7 @@ public abstract class StructureNode : RenderNode, IReadOnlyStructureNode, IRende
             renderSurface.DrawingSurface.Canvas.DrawRect(new RectD(chunkPos * chunkSize, new VecD(chunkSize)),
                 clearPaint);
         }
-        
+
         renderSurface.DrawingSurface.Canvas.RestoreToCount(saved);
     }
 
@@ -288,6 +299,7 @@ public abstract class StructureNode : RenderNode, IReadOnlyStructureNode, IRende
         {
             additionalData["embeddedMask"] = EmbeddedMask;
         }
+
         if (ClipToPreviousMember)
         {
             additionalData["clipToPreviousMember"] = ClipToPreviousMember;
@@ -309,7 +321,7 @@ public abstract class StructureNode : RenderNode, IReadOnlyStructureNode, IRende
 
             infos.Add(new StructureMemberMask_ChangeInfo(Id, mask != null));
         }
-        
+
         if (data.TryGetValue("clipToPreviousMember", out var clip))
         {
             ClipToPreviousMember = (bool)clip;

+ 8 - 0
src/PixiEditor/Models/Rendering/SceneRenderer.cs

@@ -27,6 +27,8 @@ internal class SceneRenderer : IDisposable
     private KeyFrameTime lastFrameTime;
     private Dictionary<Guid, bool> lastFramesVisibility = new();
 
+    private ChunkResolution? lastResolution;
+
     public SceneRenderer(IReadOnlyDocument trackerDocument, IDocument documentViewModel)
     {
         Document = trackerDocument;
@@ -120,6 +122,12 @@ internal class SceneRenderer : IDisposable
             return true;
         }
 
+        if (lastResolution != resolution)
+        {
+            lastResolution = resolution;
+            return true;
+        }
+
         if (lastHighResRendering != HighResRendering)
         {
             lastHighResRendering = HighResRendering;