SKPath optimizations on lower scale factors

94 views
Skip to first unread message

j0hnny

unread,
Apr 9, 2022, 6:30:19โ€ฏAM4/9/22
to skia-discuss
Hi all ๐Ÿ‘‹

i'm drawing 100 SKPath objects each with 100 points, these are generated only once and re-used during draws. I'm manipulating the canvas matrix via pinch and pan gestures and noticed that on higher scale values the rendering performance drops significantly and resource usage (getResourceCacheUsage)ย of the GRContext changes with every frame. As shown in the video this is only the case for scale operations, not for translations on the matrix - an invalidation is indicated in a color change of the paths.

Here is a screen-recording from my iPad Pro (M1):

I know that i could render the paths onto an SKBitmap and reuse that during gesture usage, but i'm really curious why on lower scale values the resource count stays the same and performance is so much better - can someone explain to me what is happening under the hood?

Thank you ๐Ÿ™Œ

Brian Osman

unread,
Apr 11, 2022, 9:07:35โ€ฏAM4/11/22
to skia-d...@googlegroups.com
I can't say for sure what's happening precisely in your situation, but in general: Skia has several different techniques for path rendering. It chooses which one to use based on numerous factors, including the properties of the path, but also the final (transformed) size of the path. Most of the techniques cache some amount of information on the GPU, but each technique has different rules for how it can reuse that cached information. For example: when certain paths are small enough, Skia generates a signed distance field of the path, which can be reused to draw that same path even at a different scale (up to a certain limit). When paths get larger, Skia tends to use other techniques that may involve linearizing the curves. Those techniques will require the data to be re-generated after any scale change.

One thing to note: requesting an MSAA surface will tend to speed up path rendering, and provide more consistent performance, so you may want to try that.

--
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/9d9c99f1-00fd-45fc-a2bc-fe89e50f99afn%40googlegroups.com.

j0hnny

unread,
Apr 12, 2022, 4:13:03โ€ฏAM4/12/22
to skia-discuss
Thank you for your reply and the explanations. It's good info for me to know that "something" is happening under the hood. Best practice for complex canvas content is probably to cache the content into an SKBitmap or SKImage during pinch / pan gesture operations, right?
Reply all
Reply to author
Forward
0 new messages