what is safe in skia-multithreading?

78 views
Skip to first unread message

Red Artist

unread,
Mar 31, 2024, 2:53:37 PMMar 31
to skia-discuss
There's a really really old thread at https://groups.google.com/g/skia-discuss/c/-G1cyl1QD9E from 2012.

I was wondering about the current status of multi-threading support in skia. 
I know you can't touch openGL between multiple threads, so any surface (and its sub-canvases) created with render target or backend texture should not be touched from another thread.

1. Is it okay to share a ref counted objects (eg: shader or data or effect etc..) between the threads? eg: taking a base shader and in multiple threads, compose it with different shaders. or assign it to different paints and use it to render to different canvases?

2. Is it okay to share any skia object between threads, as long as they are properly wrapped in a mutex? eg: A paint or data object locked before passing it as an argument to some function and unlocked after. 

3. can we use a RwLock here to simultaneously use a skia object in multiple threads as long as there's nobody mutating the paint/data? (XOR mutability like rust)

Another weird situation is lifetimes of objects which are in the "command buffer" of canvas before flush.
1. I wrap paragraph or shader or paint inside a mutex
2. lock mutex, use them when drawing to a canvas.
3. unlock mutex
4. In another thread, someone locks the mutex and modifies the object (or deletes it by replacing it with a new object)
5. Is it safe to call canvas flush now? or does the canvas still hold on to those objects in the background somehow?



Reply all
Reply to author
Forward
0 new messages