SkiaSharp: [BUG] SKSurface.ReadPixels is super slow

Description

I’m using SkiaSharp with a OpenGL backend and I’m drawing on a SkSurface wich is super fast, took around 0.25ms. To get the rendered pixel data I’m using SkSurface.ReadPixels to copy the data to a buffer. But this calls are super slow ~30ms. Is there any chance to speed it up? Or getting a direct pointer to the pixeldata?

Code var _info = new SKImageInfo(1920, 1080, SKColorType.Bgra8888); var _glContext = GlContext.Create(); var _glContext.MakeCurrent(); var _glInterface = GRGlInterface.Create(); var _context = GRContext.CreateGl(_glInterface); var _buffer = Marshal.AllocHGlobal(_info.BytesSize); _surface = SKSurface.Create(_context, true, _info);

// doing the actual drawing like _surface.Canvas.Draw…

_surface.ReadPixels(_info, _buffer, _info.RowBytes, 0, 0));

Basic Information

  • Version with issue: 2.80.0-preview.24
  • IDE: Rider 2020.1
  • Platform Target Frameworks: .Net Core 3.1
    • macOS 10.15.5 (currently only tested here)

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 1
  • Comments: 28 (20 by maintainers)

Most upvoted comments

@mattleibow I found a silly bug in SkiaSharp, in

SkiaSharp\binding\Binding\SKSurface.cs

		public static SKSurface Create (GRContext context, bool budgeted, SKImageInfo info, int sampleCount, GRSurfaceOrigin origin) =>
			Create (context, budgeted, info, sampleCount, GRSurfaceOrigin.BottomLeft, null, false);

As you can see the origin is not passed to the Create function, GRSurfaceOrigin.BottomLeft is passed.

This causes the pixel flip.

I will patch this, and see what happens 😃

Okay, I’ll try to reproduce your test case on Monday; I’m curious what is causing this, and what can be done about it.