Draw directly to SKSurface

19 views
Skip to first unread message

Tiko Tiko

unread,
Jul 17, 2024, 9:22:36 AM (5 days ago) Jul 17
to skia-discuss

Assuming I am using the CPU renderer (NOT GPU), i.e the back buffer is in RAM, not GPU memory

Is it possible to get a reference to the buffer Skia is writing to so I can do my own rendering to it?

I'm not looking to get a copy and then write back, I want to draw directly to the memory itself for best performance? is this possible?

So basically, I want to do something like :

private void skiaView_PaintSurface(object sender, SKPaintSurfaceEventArgs e) { var canvas = e.Surface.Canvas; canvas.Clear(SKColors.White); // normal rendering canvas.DrawLine(....); fixed(byte buffer* = canvas.Surface.GetBuffer()) { // write to the actual buffer skia is using buffer[0] = ... } }


Thanks

Tiko Tiko

unread,
Jul 17, 2024, 9:23:43 AM (5 days ago) Jul 17
to skia-discuss
Forgot to mention that this is in C# (I am using SkiaSharp)

Brian Osman

unread,
Jul 17, 2024, 9:27:28 AM (5 days ago) Jul 17
to skia-d...@googlegroups.com
In Skia native, this is generally done using SkSurface::peekPixels - that method fills in an SkPixmap object, which has the address of the buffer, as well as other information you'd need (like the pixel stride, format, etc). It looks like SkiaSharp does expose peekPixels, so you probably need to look at how that's exposed there.

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/d53dd179-238b-485a-9c9d-c547b1435fc7n%40googlegroups.com.

Mike Reed

unread,
Jul 18, 2024, 10:40:16 AM (4 days ago) Jul 18
to skia-d...@googlegroups.com
Another sneaky way is to create the SkSurface with a buffer that you created/own... if that's possible.



--
"I think I can safely say that nobody understands quantum mechanics." -- Richard Feynman
"It ain't what you don't know that gets you into trouble. It's what you know for sure that just ain't so." -- Mark Twain
"I am pleased to see that we have differences" -- Surak

Reply all
Reply to author
Forward
0 new messages