SkiaSharp icon indicating copy to clipboard operation
SkiaSharp copied to clipboard

[FEATURE] Expose existing RTree optimization option on SkPictureRecorder.BeginRecording()

Open kcoop opened this issue 2 years ago • 5 comments

We're looking to pan and zoom some SkiaSharp's SkPictures that consist of a reasonably large number of simple operations (~25K, text, lines, rect fills). We're finding a zoomed and translated DrawPicture is rendering on the order of 5 fps on recent model iOS devices, which is clearly unacceptable.

But yay! It turns out Skia has had built in support for RTree-based operations culling for a long time, and it looks very promising:

https://groups.google.com/g/skia-discuss/c/EPOuhhloIF4/m/rZyakh1fBwAJ https://bugs.chromium.org/p/chromium/issues/detail?id=485597#c22

But oh no! SkiaSharp doesn't expose this functionality, either in C# or the C wrappers in the Mono fork of Skia.

But yay! The fix looks very straightforward - just exposing the constructor of an RTreeFactory instance, and passing it as an extra parameter to BeginRecording().

I've created forks of both SkiaSharp and mono/skia, and implemented a swag at a simple C# api, C wrappers, and some smoke tests. You can find the (fairly small, simple, but unvetted) changes here:

https://github.com/mono/SkiaSharp/compare/main...kcoop:SkiaSharp:kcoop-rtree https://github.com/mono/skia/compare/xamarin-mobile-bindings...kcoop:mono-skia:kcoop-rtree

This seems like a valuable, big bang for the buck PR. Very small change, and who wouldn't want significant rendering improvements for large-ish documents by simply adding a bool? I'm happy to do what's needed to make this happen.

[Edited to remove noise - I've now discovered this repo uses submodules to build mono/skia]

kcoop avatar Feb 03 '23 19:02 kcoop

I would be interested in that feature as well. I want to record draw calls and then replay them with different zoom and translation. Right now this is very slow when only rendering a tiny part of the actual recorded calls (i.e. when zooming in). Any chance to get this feature merged?

TwinkyDaniel avatar Apr 11 '24 13:04 TwinkyDaniel

I have added this to the list of things for v3. I'll have a look and merge some things.

Thanks!

mattleibow avatar Apr 13 '24 07:04 mattleibow

When do you plan 3.0? Any chance to get this merged earlier? Can we do something to help?

TwinkyDaniel avatar Apr 15 '24 06:04 TwinkyDaniel

This would definitely help with drawing apps, even UI apps, and rendering SVG's with zoom as I use SKPicture extensively there :)

wieslawsoltes avatar Apr 15 '24 08:04 wieslawsoltes

When do you plan 3.0? Any chance to get this merged earlier? Can we do something to help?

If there is a PR, we can easily backport a smaller change like this. SkiaSharp is less scary than all these repos and files.

mattleibow avatar Apr 15 '24 20:04 mattleibow