SkBitmap surface and multiple threads.

711 views
Skip to first unread message

Corey Lucier

unread,
Mar 9, 2016, 2:39:09 PM3/9/16
to skia-discuss
Is it feasible to write to one SkBitmap raster surface from multiple threads? If each owned a different quadrant for instance. Perhaps with one SkCanvas/Surface each owning a particular portion of the image?

Thanks,

Corey

Mike Reed

unread,
Mar 9, 2016, 3:01:42 PM3/9/16
to skia-d...@googlegroups.com
SkSurface and SkCanvas are both NOT thread-safe. Only SkImage and SkPicture are.

Thus to shard a large drawing across multiple threads, you need a separate instance of a surface/canvas in each thread.

--
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 post to this group, send email to skia-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/skia-discuss.
For more options, visit https://groups.google.com/d/optout.

Mike Klein

unread,
Mar 9, 2016, 3:07:27 PM3/9/16
to skia-d...@googlegroups.com
Mike's right, but you can certainly have all those SkSurfaces point at the same backing pixel memory, using something like SkSurface::NewRasterDirect.
We're quite careful to never read or write outside the clip.

Corey Lucier

unread,
Mar 9, 2016, 3:20:59 PM3/9/16
to skia-discuss
Yes conceptually I want a portion of my scene to an low-res offscreen layer using a thread pool...

Once complete, I want multiple threads to be able to render snippets from this offscreen in parallel as they see fit (no writing while reading).

So sounds like when everyone is working on this SkImage in a parallel (assuming they spin up a surface and canvas for the region they own), shouldn't be a problem.

-C


Reply all
Reply to author
Forward
0 new messages