Browse Source

Surface impl more stuff

flabbet 2 years ago
parent
commit
96df1dd0db

+ 1 - 1
src/PixiEditor.DrawingApi.Core/Surface/DrawingSurface.cs

@@ -12,7 +12,7 @@ namespace PixiEditor.DrawingApi.Core.Surface
         public DrawingSurfaceProperties Properties { get; private set; }
         public Canvas Canvas { get; private set; }
         
-        internal DrawingSurface(IntPtr objPtr) : base(objPtr)
+        public DrawingSurface(IntPtr objPtr) : base(objPtr)
         {
         }
         

+ 18 - 6
src/PixiEditor.DrawingApi.Skia/Implementations/SkiaSurfaceImplementation.cs

@@ -23,33 +23,45 @@ namespace PixiEditor.DrawingApi.Skia.Implementations
 
         public DrawingSurface Create(ImageInfo imageInfo, IntPtr pixels, int rowBytes)
         {
-            throw new NotImplementedException();
+            SKSurface skSurface = SKSurface.Create(imageInfo.ToSkImageInfo(), pixels, rowBytes);
+            DrawingSurface surface = new DrawingSurface(skSurface.Handle);
+            ManagedInstances[skSurface.Handle] = skSurface;
+            return surface;
         }
 
         public bool ReadPixels(DrawingSurface drawingSurface, ImageInfo dstInfo, IntPtr dstPixels, int dstRowBytes, int srcX,
             int srcY)
         {
-            throw new NotImplementedException();
+            return ManagedInstances[drawingSurface.ObjectPointer]
+                .ReadPixels(dstInfo.ToSkImageInfo(), dstPixels, dstRowBytes, srcX, srcY);
         }
 
         public void Draw(DrawingSurface drawingSurface, Canvas surfaceToDraw, int x, int y, Paint drawingPaint)
         {
-            throw new NotImplementedException();
+            ManagedInstances[drawingSurface.ObjectPointer].Draw(surfaceToDraw, x, y, drawingPaint);
         }
 
         public DrawingSurface Create(ImageInfo imageInfo, IntPtr pixelBuffer)
         {
-            throw new NotImplementedException();
+            SKSurface skSurface = SKSurface.Create(imageInfo.ToSkImageInfo(), pixelBuffer);
+            DrawingSurface surface = new DrawingSurface(skSurface.Handle);
+            ManagedInstances[skSurface.Handle] = skSurface;
+            return surface;
         }
 
         public DrawingSurface Create(Pixmap pixmap)
         {
-            throw new NotImplementedException();
+            SKSurface skSurface = SKSurface.Create(pixmap);
+            DrawingSurface surface = new DrawingSurface(skSurface.Handle);
+            ManagedInstances[skSurface.Handle] = skSurface;
         }
 
         public DrawingSurface Create(ImageInfo imageInfo)
         {
-            throw new NotImplementedException();
+            SKSurface skSurface = SKSurface.Create(imageInfo.ToSkImageInfo());
+            DrawingSurface surface = new DrawingSurface(skSurface.Handle);
+            ManagedInstances[skSurface.Handle] = skSurface;
+            return surface;
         }
     }
 }

+ 5 - 2
src/PixiEditor.DrawingApi.Skia/SkiaDrawingBackend.cs

@@ -36,10 +36,13 @@ namespace PixiEditor.DrawingApi.Skia
             PathImplementation = pathImpl;
             
             MatrixImplementation = new SkiaMatrixImplementation();
-            
-            PixmapImplementation = new SkiaPixmapImplementation();
+
+            SkiaPixmapImplementation pixmapImpl = new SkiaPixmapImplementation();
+            PixmapImplementation = pixmapImpl;
 
             ColorSpaceImplementation = new SkiaColorSpaceImplementation();
+
+            SurfaceImplementation = new SkiaSurfaceImplementation(pixmapImpl);
             
             CanvasImplementation = new SkiaCanvasImplementation(paintImpl, imgImpl, pathImpl);
         }