Browse Source

Fixed color space conversion

flabbet 8 months ago
parent
commit
a4cba96e29

+ 1 - 1
src/Drawie

@@ -1 +1 @@
-Subproject commit 854d16f252074444ccc8705c3ff9bb52288d1bbf
+Subproject commit 54e24062eba5e133998933b58a4aa30316c63780

+ 1 - 1
src/PixiEditor.ChangeableDocument/Changeables/Graph/Interfaces/IReadOnlyNode.cs

@@ -14,7 +14,7 @@ public interface IReadOnlyNode
     public IReadOnlyList<IReadOnlyKeyFrameData> KeyFrames { get; }
     public VecD Position { get; }
     string DisplayName { get; }
-
+    
     public void Execute(RenderContext context);
     
     /// <summary>

+ 14 - 0
src/PixiEditor.ChangeableDocument/Changeables/Graph/NodeGraph.cs

@@ -71,6 +71,7 @@ public class NodeGraph : IReadOnlyNodeGraph, IDisposable
     public void Execute(RenderContext context)
     {
         if (OutputNode == null) return;
+        if(!CanExecute()) return;
 
         var queue = CalculateExecutionQueue(OutputNode);
         
@@ -88,4 +89,17 @@ public class NodeGraph : IReadOnlyNodeGraph, IDisposable
             }
         }
     }
+    
+    private bool CanExecute()
+    {
+        foreach (var node in Nodes)
+        {
+            if (node.IsDisposed)
+            {
+                return false;
+            }
+        }
+
+        return true;
+    }
 }

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

@@ -41,7 +41,7 @@ public abstract class Node : IReadOnlyNode, IDisposable
 
     protected virtual bool ExecuteOnlyOnCacheChange => false;
 
-    protected bool IsDisposed => _isDisposed;
+    protected internal bool IsDisposed => _isDisposed;
     private bool _isDisposed;
 
     private Dictionary<int, Texture> _managedTextures = new();

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

@@ -1,12 +1,8 @@
 using ChunkyImageLib.DataHolders;
 using Drawie.Backend.Core;
-using Drawie.Backend.Core.ColorsImpl;
-using PixiEditor.ChangeableDocument.Changeables.Animations;
 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.Graph.Interfaces;
 using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
 using PixiEditor.Models.Handlers;
@@ -49,9 +45,7 @@ internal class SceneRenderer
         
         if(texture != null)
         {
-            using Texture srgbTexture = Texture.ForDisplay(Document.Size);
-            srgbTexture.DrawingSurface.Canvas.DrawSurface(texture.DrawingSurface, 0, 0);
-            target.Canvas.DrawSurface(srgbTexture.DrawingSurface, 0, 0);
+            target.Canvas.DrawSurface(texture.DrawingSurface, 0, 0);
             texture.Dispose();
         }
     }

+ 26 - 79
src/PixiEditor/Views/Rendering/Scene.cs

@@ -128,7 +128,10 @@ internal class Scene : Zoombox.Zoombox, ICustomHitTest
     private string info = string.Empty;
     private bool initialized = false;
     private RenderApiResources resources;
-    private DrawingSurface renderSurface;
+
+    private DrawingSurface framebuffer;
+    private Texture renderTexture;
+
     private PixelSize lastSize = PixelSize.Empty;
     private Cursor lastCursor;
 
@@ -249,13 +252,13 @@ internal class Scene : Zoombox.Zoombox, ICustomHitTest
 
     private void RenderScene(RectD bounds)
     {
-        DrawCheckerboard(bounds);
-        DrawOverlays(renderSurface, bounds, OverlayRenderSorting.Background);
-        SceneRenderer.RenderScene(renderSurface, CalculateResolution());
-        DrawOverlays(renderSurface, bounds, OverlayRenderSorting.Foreground);
+        DrawCheckerboard(renderTexture.DrawingSurface, bounds);
+        DrawOverlays(renderTexture.DrawingSurface, bounds, OverlayRenderSorting.Background);
+        SceneRenderer.RenderScene(renderTexture.DrawingSurface, CalculateResolution());
+        DrawOverlays(renderTexture.DrawingSurface, bounds, OverlayRenderSorting.Foreground);
     }
 
-    private void DrawCheckerboard(RectD dirtyBounds)
+    private void DrawCheckerboard(DrawingSurface surface, RectD dirtyBounds)
     {
         if (checkerBitmap == null) return;
 
@@ -271,7 +274,7 @@ internal class Scene : Zoombox.Zoombox, ICustomHitTest
             FilterQuality = FilterQuality.None
         };
 
-        renderSurface.Canvas.DrawRect(operationSurfaceRectToRender, checkerPaint);
+        surface.Canvas.DrawRect(operationSurfaceRectToRender, checkerPaint);
     }
 
     private void DrawOverlays(DrawingSurface renderSurface, RectD dirtyBounds, OverlayRenderSorting sorting)
@@ -584,8 +587,11 @@ internal class Scene : Zoombox.Zoombox, ICustomHitTest
     protected void FreeGraphicsResources()
     {
         resources?.DisposeAsync();
-        renderSurface?.Dispose();
-        renderSurface = null;
+        framebuffer?.Dispose();
+        framebuffer = null;
+
+        renderTexture?.Dispose();
+        renderTexture = null;
         resources = null;
     }
 
@@ -598,26 +604,31 @@ internal class Scene : Zoombox.Zoombox, ICustomHitTest
                 return;
             }
 
-            if (renderSurface == null || lastSize != size)
+            if (framebuffer == null || lastSize != size)
             {
                 resources.CreateTemporalObjects(size);
 
                 VecI sizeVec = new VecI(size.Width, size.Height);
 
-                renderSurface?.Dispose();
+                framebuffer?.Dispose();
+                renderTexture?.Dispose();
 
-                renderSurface =
+                framebuffer =
                     DrawingBackendApi.Current.CreateRenderSurface(sizeVec,
                         resources.Texture, SurfaceOrigin.BottomLeft);
 
+                renderTexture = Texture.ForDisplay(sizeVec);
+
                 lastSize = size;
             }
 
             resources.Render(size, () =>
             {
-                renderSurface.Canvas.Clear();
-                Draw(renderSurface);
-                renderSurface.Flush();
+                framebuffer.Canvas.Clear();
+                renderTexture.DrawingSurface.Canvas.Clear();
+                Draw(renderTexture.DrawingSurface);
+                framebuffer.Canvas.DrawSurface(renderTexture.DrawingSurface, 0, 0);
+                framebuffer.Flush();
             });
         }
     }
@@ -699,67 +710,3 @@ internal class Scene : Zoombox.Zoombox, ICustomHitTest
         return Bounds.Contains(point);
     }
 }
-
-internal class DrawSceneOperation : SkiaDrawOperation
-{
-    public DocumentViewModel Document { get; set; }
-    public VecD ContentPosition { get; set; }
-    public double Scale { get; set; }
-    public double ResolutionScale { get; set; }
-    public double Angle { get; set; }
-    public bool FlipX { get; set; }
-    public bool FlipY { get; set; }
-    public Rect ViewportBounds { get; }
-
-
-    public Action<DrawingSurface> RenderScene;
-
-    private Texture renderTexture;
-
-    private double opacity;
-
-    public DrawSceneOperation(Action<DrawingSurface> renderAction, DocumentViewModel document, VecD contentPosition,
-        double scale,
-        double resolutionScale,
-        double opacity,
-        double angle, bool flipX, bool flipY, Rect dirtyBounds, Rect viewportBounds,
-        Texture renderTexture) : base(dirtyBounds)
-    {
-        RenderScene = renderAction;
-        Document = document;
-        ContentPosition = contentPosition;
-        Scale = scale;
-        Angle = angle;
-        FlipX = flipX;
-        FlipY = flipY;
-        ViewportBounds = viewportBounds;
-        ResolutionScale = resolutionScale;
-        this.opacity = opacity;
-        this.renderTexture = renderTexture;
-    }
-
-    public override void Render(ISkiaSharpApiLease lease)
-    {
-        if (Document == null) return;
-
-        SKCanvas canvas = lease.SkCanvas;
-
-        int count = canvas.Save();
-
-        //using var ctx = DrawingBackendApi.Current.RenderOnDifferentGrContext(lease.GrContext);
-
-        DrawingSurface surface = DrawingSurface.FromNative(lease.SkSurface);
-
-        surface.Canvas.DrawSurface(renderTexture.DrawingSurface, 0, 0);
-
-        RenderScene?.Invoke(surface);
-
-        canvas.RestoreToCount(count);
-        DrawingSurface.Unmanage(surface);
-    }
-
-    public override bool Equals(ICustomDrawOperation? other)
-    {
-        return false;
-    }
-}