|
@@ -4,6 +4,7 @@ using PixiEditor.DrawingApi.Core.Numerics;
|
|
using PixiEditor.DrawingApi.Core.Surfaces;
|
|
using PixiEditor.DrawingApi.Core.Surfaces;
|
|
using PixiEditor.DrawingApi.Core.Surfaces.ImageData;
|
|
using PixiEditor.DrawingApi.Core.Surfaces.ImageData;
|
|
using PixiEditor.DrawingApi.Core.Surfaces.PaintImpl;
|
|
using PixiEditor.DrawingApi.Core.Surfaces.PaintImpl;
|
|
|
|
+using PixiEditor.Numerics;
|
|
using SkiaSharp;
|
|
using SkiaSharp;
|
|
|
|
|
|
namespace PixiEditor.DrawingApi.Skia.Implementations
|
|
namespace PixiEditor.DrawingApi.Skia.Implementations
|
|
@@ -14,16 +15,24 @@ namespace PixiEditor.DrawingApi.Skia.Implementations
|
|
private readonly SkiaCanvasImplementation _canvasImplementation;
|
|
private readonly SkiaCanvasImplementation _canvasImplementation;
|
|
private readonly SkiaPaintImplementation _paintImplementation;
|
|
private readonly SkiaPaintImplementation _paintImplementation;
|
|
|
|
|
|
- public SkiaSurfaceImplementation(SkiaPixmapImplementation pixmapImplementation, SkiaCanvasImplementation canvasImplementation, SkiaPaintImplementation paintImplementation)
|
|
|
|
|
|
+ public GRContext GrContext { get; set; }
|
|
|
|
+
|
|
|
|
+ public SkiaSurfaceImplementation(GRContext context, SkiaPixmapImplementation pixmapImplementation, SkiaCanvasImplementation canvasImplementation, SkiaPaintImplementation paintImplementation)
|
|
{
|
|
{
|
|
_pixmapImplementation = pixmapImplementation;
|
|
_pixmapImplementation = pixmapImplementation;
|
|
_canvasImplementation = canvasImplementation;
|
|
_canvasImplementation = canvasImplementation;
|
|
_paintImplementation = paintImplementation;
|
|
_paintImplementation = paintImplementation;
|
|
|
|
+ GrContext = context;
|
|
}
|
|
}
|
|
|
|
|
|
public Pixmap PeekPixels(DrawingSurface drawingSurface)
|
|
public Pixmap PeekPixels(DrawingSurface drawingSurface)
|
|
{
|
|
{
|
|
SKPixmap pixmap = ManagedInstances[drawingSurface.ObjectPointer].PeekPixels();
|
|
SKPixmap pixmap = ManagedInstances[drawingSurface.ObjectPointer].PeekPixels();
|
|
|
|
+ if (pixmap == null)
|
|
|
|
+ {
|
|
|
|
+ return drawingSurface.Snapshot().PeekPixels();
|
|
|
|
+ }
|
|
|
|
+
|
|
return _pixmapImplementation.CreateFrom(pixmap);
|
|
return _pixmapImplementation.CreateFrom(pixmap);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -38,34 +47,58 @@ namespace PixiEditor.DrawingApi.Skia.Implementations
|
|
{
|
|
{
|
|
SKCanvas canvas = _canvasImplementation[surfaceToDraw.ObjectPointer];
|
|
SKCanvas canvas = _canvasImplementation[surfaceToDraw.ObjectPointer];
|
|
SKPaint paint = _paintImplementation[drawingPaint.ObjectPointer];
|
|
SKPaint paint = _paintImplementation[drawingPaint.ObjectPointer];
|
|
- ManagedInstances[drawingSurface.ObjectPointer].Draw(canvas, x, y, paint);
|
|
|
|
|
|
+ var instance = ManagedInstances[drawingSurface.ObjectPointer];
|
|
|
|
+ instance.Draw(canvas, x, y, paint);
|
|
}
|
|
}
|
|
|
|
|
|
public DrawingSurface Create(ImageInfo imageInfo, IntPtr pixels, int rowBytes)
|
|
public DrawingSurface Create(ImageInfo imageInfo, IntPtr pixels, int rowBytes)
|
|
{
|
|
{
|
|
- SKSurface skSurface = SKSurface.Create(imageInfo.ToSkImageInfo(), pixels, rowBytes);
|
|
|
|
|
|
+ SKSurface skSurface = CreateSkiaSurface(imageInfo.Size, imageInfo.GpuBacked);
|
|
|
|
+
|
|
|
|
+ var canvas = skSurface.Canvas;
|
|
|
|
+ canvas.DrawImage(SKImage.FromPixelCopy(imageInfo.ToSkImageInfo(), pixels, rowBytes), new SKPoint(0, 0));
|
|
|
|
+
|
|
return CreateDrawingSurface(skSurface);
|
|
return CreateDrawingSurface(skSurface);
|
|
}
|
|
}
|
|
|
|
|
|
public DrawingSurface Create(ImageInfo imageInfo, IntPtr pixelBuffer)
|
|
public DrawingSurface Create(ImageInfo imageInfo, IntPtr pixelBuffer)
|
|
{
|
|
{
|
|
- SKSurface skSurface = SKSurface.Create(imageInfo.ToSkImageInfo(), pixelBuffer);
|
|
|
|
|
|
+ SKSurface skSurface = CreateSkiaSurface(imageInfo.Size, imageInfo.GpuBacked);
|
|
|
|
+
|
|
|
|
+ var canvas = skSurface.Canvas;
|
|
|
|
+ canvas.DrawImage(SKImage.FromPixelCopy(imageInfo.ToSkImageInfo(), pixelBuffer), new SKPoint(0, 0));
|
|
|
|
+
|
|
return CreateDrawingSurface(skSurface);
|
|
return CreateDrawingSurface(skSurface);
|
|
}
|
|
}
|
|
|
|
|
|
public DrawingSurface Create(Pixmap pixmap)
|
|
public DrawingSurface Create(Pixmap pixmap)
|
|
{
|
|
{
|
|
SKPixmap skPixmap = _pixmapImplementation[pixmap.ObjectPointer];
|
|
SKPixmap skPixmap = _pixmapImplementation[pixmap.ObjectPointer];
|
|
- SKSurface skSurface = SKSurface.Create(skPixmap);
|
|
|
|
|
|
+ SKImageInfo info = skPixmap.Info;
|
|
|
|
+ SKSurface skSurface = CreateSkiaSurface(new VecI(info.Width, info.Height), true);
|
|
|
|
+
|
|
|
|
+ var canvas = skSurface.Canvas;
|
|
|
|
+ canvas.DrawImage(SKImage.FromPixels(skPixmap), new SKPoint(0, 0));
|
|
|
|
+
|
|
return CreateDrawingSurface(skSurface);
|
|
return CreateDrawingSurface(skSurface);
|
|
}
|
|
}
|
|
|
|
|
|
public DrawingSurface Create(ImageInfo imageInfo)
|
|
public DrawingSurface Create(ImageInfo imageInfo)
|
|
{
|
|
{
|
|
- SKSurface skSurface = SKSurface.Create(imageInfo.ToSkImageInfo());
|
|
|
|
|
|
+ SKSurface skSurface = CreateSkiaSurface(imageInfo.Size, imageInfo.GpuBacked);
|
|
return CreateDrawingSurface(skSurface);
|
|
return CreateDrawingSurface(skSurface);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private SKSurface CreateSkiaSurface(VecI size, bool gpu)
|
|
|
|
+ {
|
|
|
|
+ if (!gpu)
|
|
|
|
+ {
|
|
|
|
+ return SKSurface.Create(new SKImageInfo(size.X, size.Y));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return SKSurface.Create(GrContext, false, new SKImageInfo(size.X, size.Y));
|
|
|
|
+ }
|
|
|
|
+
|
|
public void Dispose(DrawingSurface drawingSurface)
|
|
public void Dispose(DrawingSurface drawingSurface)
|
|
{
|
|
{
|
|
ManagedInstances[drawingSurface.ObjectPointer].Dispose();
|
|
ManagedInstances[drawingSurface.ObjectPointer].Dispose();
|
|
@@ -84,7 +117,13 @@ namespace PixiEditor.DrawingApi.Skia.Implementations
|
|
|
|
|
|
DrawingSurface surface = new DrawingSurface(skSurface.Handle, canvas);
|
|
DrawingSurface surface = new DrawingSurface(skSurface.Handle, canvas);
|
|
ManagedInstances[skSurface.Handle] = skSurface;
|
|
ManagedInstances[skSurface.Handle] = skSurface;
|
|
|
|
+
|
|
return surface;
|
|
return surface;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public void Flush(DrawingSurface drawingSurface)
|
|
|
|
+ {
|
|
|
|
+ ManagedInstances[drawingSurface.ObjectPointer].Flush(true);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|