flabbet 1 年之前
父节点
当前提交
97e2bd7b69

+ 1 - 1
src/PixiEditor.AvaloniaUI.Desktop/Program.cs

@@ -19,7 +19,7 @@ public class Program
             .UsePlatformDetect()
             .With(new Win32PlatformOptions()
             {
-                RenderingMode = new Win32RenderingMode[] { Win32RenderingMode.Vulkan, Win32RenderingMode.AngleEgl }
+                RenderingMode = new Win32RenderingMode[] { Win32RenderingMode.Wgl }
             })
             .LogToTrace();
 }

+ 11 - 8
src/PixiEditor.AvaloniaUI/Views/MainWindow.axaml.cs

@@ -59,13 +59,13 @@ internal partial class MainWindow : Window
 
         AsyncImageLoader.ImageLoader.AsyncImageLoader = new DiskCachedWebImageLoader();
         
-        //GRContext recordingContext = GetGrRecordingContext();
+        GRContext recordingContext = GetGrRecordingContext();
 
-        /*SkiaDrawingBackend skiaDrawingBackend = new SkiaDrawingBackend(recordingContext);
-        DrawingBackendApi.SetupBackend(skiaDrawingBackend);*/
+        SkiaDrawingBackend skiaDrawingBackend = new SkiaDrawingBackend { GraphicsContext = recordingContext };
+        DrawingBackendApi.SetupBackend(skiaDrawingBackend);
         
-        SkiaPixiEngine engine = SkiaPixiEngine.Create();
-        engine.SetupBackendWindowLess();
+        /*SkiaPixiEngine engine = SkiaPixiEngine.Create();
+        engine.SetupBackendWindowLess();*/
 
         preferences = services.GetRequiredService<IPreferences>();
         platform = services.GetRequiredService<IPlatform>();
@@ -75,7 +75,7 @@ internal partial class MainWindow : Window
         InitializeComponent();
     }
 
-    /*private static GRContext GetGrRecordingContext()
+    private static GRContext GetGrRecordingContext()
     {
         Compositor compositor = Compositor.TryGetDefaultCompositor();
         var interop = compositor.TryGetCompositionGpuInterop();
@@ -90,13 +90,16 @@ internal partial class MainWindow : Window
             return GRContext.CreateGl(GRGlInterface.Create(glContext.GlInterface.GetProcAddress));
         }
 
+        return null;
+
+        /*
         var contextFactory = AvaloniaLocator.Current.GetRequiredService<IPlatformGraphicsOpenGlContextFactory>();
         var ctx = contextFactory.CreateContext(null);
         ctx.MakeCurrent();
         var ctxInterface = GRGlInterface.Create(ctx.GlInterface.GetProcAddress);
         var grContext = GRContext.CreateGl(ctxInterface);
-        return grContext;
-    }*/
+        return grContext;*/
+    }
 
     public static MainWindow CreateWithRecoveredDocuments(CrashReport report, out bool showMissingFilesDialog)
     {

+ 2 - 2
src/PixiEditor.AvaloniaUI/Views/Rendering/DrawCheckerBackgroundOperation.cs

@@ -32,8 +32,8 @@ internal class DrawCheckerBackgroundOperation : SkiaDrawOperation
 
     public override void Render(ISkiaSharpApiLease lease)
     {
-        var canvas = lease.SkCanvas;
-        canvas.DrawRect(SurfaceRectToRender, _checkerPaint);
+        /*var canvas = lease.SkCanvas;
+        canvas.DrawRect(SurfaceRectToRender, _checkerPaint);*/
     }
 
     public override bool Equals(ICustomDrawOperation? other)

+ 1 - 0
src/PixiEditor.AvaloniaUI/Views/Rendering/Scene.cs

@@ -507,6 +507,7 @@ internal class DrawSceneOperation : SkiaDrawOperation
             return;
         }
         
+        ((SKSurface)Surface.DrawingSurface.Native).Flush(true);
         using Image snapshot = Surface.DrawingSurface.Snapshot(SurfaceRectToRender);
 
         var matrixValues = new float[ColorMatrix.Width * ColorMatrix.Height];

+ 4 - 1
src/PixiEditor.AvaloniaUI/Views/Visuals/SurfaceControl.cs

@@ -198,8 +198,11 @@ internal class DrawSurfaceOperation : SkiaDrawOperation
         }*/
 
         _paint.Color = _paint.Color.WithAlpha((byte)(Opacity * 255));
-        //canvas.DrawSurface((SKSurface)Surface.DrawingSurface.Native, new SKPoint(0, 0), _paint);
+        ((SKSurface)Surface.DrawingSurface.Native).Flush(true);
+        canvas.DrawSurface(((SKSurface)Surface.DrawingSurface.Native), new SKPoint(0, 0), _paint);
         canvas.Restore();
+        
+        canvas.Flush();
     }
 
 

+ 13 - 17
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/ShaderNode.cs

@@ -1,13 +1,14 @@
 using PixiEditor.ChangeableDocument.Changeables.Animations;
+using PixiEditor.ChangeableDocument.Rendering;
 using PixiEditor.DrawingApi.Core.Surface.PaintImpl;
 
 namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
 
 public class ShaderNode : Node
 {
-    public InputProperty<ChunkyImage?> Input { get; set; }
+    public InputProperty<Surface> Input { get; set; }
     public InputProperty<string> Shader { get; set; }
-    public OutputProperty<ChunkyImage?> Output { get; set; }
+    public OutputProperty<Surface> Output { get; set; }
     
     private string _shaderCode = """
                                  half4 main(float2 coord) {
@@ -20,12 +21,16 @@ public class ShaderNode : Node
     
     public ShaderNode()
     {
-        Input = CreateInput<ChunkyImage?>("Input", "INPUT", null);
+        Input = CreateInput<Surface>("Input", "INPUT", null);
         Shader = CreateInput<string>("Shader", "SHADER", "");
-        Output = CreateOutput<ChunkyImage?>("Output", "OUTPUT", null);
+        Output = CreateOutput<Surface>("Output", "OUTPUT", null);
     }
-    
-    protected override ChunkyImage? OnExecute(KeyFrameTime frameTime)
+
+    protected override string NodeUniqueName { get; }
+
+    public override string DisplayName { get; set; }
+
+    protected override Surface? OnExecute(RenderingContext context)
     {
         if (Input.Value == null)
         {
@@ -40,17 +45,8 @@ public class ShaderNode : Node
             return null;
         }
 
-        ChunkyImage output = Input.Value.CloneFromCommitted();
-        output.EnqueueDrawShader(shader);
-        output.CommitChanges();
-        
-        Output.Value = output;
-        return output;
-    }
-
-    public override bool Validate()
-    {
-        return true;
+        Input.Value.DrawingSurface.Canvas.DrawPaint(new Paint {Shader = shader});
+        return Input.Value;
     }
 
     public override Node CreateCopy()

+ 0 - 5
src/PixiEditor.DrawingApi.Core/Surface/ImageData/Image.cs

@@ -50,11 +50,6 @@ namespace PixiEditor.DrawingApi.Core.Surface.ImageData
         {
             return DrawingBackendApi.Current.ImageImplementation.Encode(this);
         }
-        
-        public Pixmap PeekPixels()
-        {
-            return DrawingBackendApi.Current.ImageImplementation.PeekPixels(this);
-        }
 
         public ImgData Encode(EncodedImageFormat format, int quality = 100)
         {

+ 4 - 4
src/PixiEditor.DrawingApi.Skia/Implementations/SkiaSurfaceImplementation.cs

@@ -15,14 +15,14 @@ namespace PixiEditor.DrawingApi.Skia.Implementations
         private readonly SkiaCanvasImplementation _canvasImplementation;
         private readonly SkiaPaintImplementation _paintImplementation;
 
-        public Func<VecI, SKSurface> CreateGpuSurface { get; set; }
+        public GRContext GrContext { get; set; }
 
-        public SkiaSurfaceImplementation(Func<VecI, SKSurface> context, SkiaPixmapImplementation pixmapImplementation, SkiaCanvasImplementation canvasImplementation, SkiaPaintImplementation paintImplementation)
+        public SkiaSurfaceImplementation(GRContext context, SkiaPixmapImplementation pixmapImplementation, SkiaCanvasImplementation canvasImplementation, SkiaPaintImplementation paintImplementation)
         {
             _pixmapImplementation = pixmapImplementation;
             _canvasImplementation = canvasImplementation;
             _paintImplementation = paintImplementation;
-            CreateGpuSurface = context;
+            GrContext = context;
         }
         
         public Pixmap PeekPixels(DrawingSurface drawingSurface)
@@ -91,7 +91,7 @@ namespace PixiEditor.DrawingApi.Skia.Implementations
 
         private SKSurface CreateSkiaSurface(VecI size)
         {
-            return CreateGpuSurface(size);
+            return SKSurface.Create(GrContext, false, new SKImageInfo(size.X, size.Y));
         }
 
         public void Dispose(DrawingSurface drawingSurface)

+ 3 - 3
src/PixiEditor.DrawingApi.Skia/SkiaDrawingBackend.cs

@@ -45,7 +45,7 @@ namespace PixiEditor.DrawingApi.Skia
         private SkiaSurfaceImplementation _surfaceImplementation;
         private GRContext _grContext;
 
-        public SkiaDrawingBackend(Func<VecI, SKSurface> createSurface)
+        public SkiaDrawingBackend()
         {
             ColorImplementation = new SkiaColorImplementation();
             
@@ -82,7 +82,7 @@ namespace PixiEditor.DrawingApi.Skia
             
             SkiaCanvasImplementation canvasImpl = new SkiaCanvasImplementation(paintImpl, imgImpl, bitmapImpl, pathImpl);
             
-            _surfaceImplementation = new SkiaSurfaceImplementation(createSurface, pixmapImpl, canvasImpl, paintImpl);
+            _surfaceImplementation = new SkiaSurfaceImplementation(GraphicsContext, pixmapImpl, canvasImpl, paintImpl);
 
             canvasImpl.SetSurfaceImplementation(_surfaceImplementation);
             imgImpl.SetSurfaceImplementation(_surfaceImplementation);
@@ -92,7 +92,7 @@ namespace PixiEditor.DrawingApi.Skia
         
         public void Setup()
         {
-            
+            _surfaceImplementation.GrContext = GraphicsContext;
         }
     }
 }