mono / SkiaSharp

SkiaSharp is a cross-platform 2D graphics API for .NET platforms based on Google's Skia Graphics Library. It provides a comprehensive 2D API that can be used across mobile, server and desktop models to render images.
MIT License
4.54k stars 542 forks source link

[FEATURE] Add caching in DrawShapedText #3032

Open MichaelRumpler opened 1 month ago

MichaelRumpler commented 1 month ago

Is your feature request related to a problem?

The DrawShapedText method is meant to be an easy replacement for DrawText which adds text shaping via HarfBuzz but otherwise uses the same parameters as DrawText. It creates and disposes a SKShaper at every call which is very slow.

Describe the solution you would like

The SKShaper should not be created and disposed at every call. It should be cached and reused instead.

Furthermore also the result of the text shaping should be cached. This would improve the performance even more.

Describe alternatives you have considered

There is an overload of DrawShapedText which takes a SKShaper and does not create/dispose it at every call, but people need to have more insider knowledge of HarfBuzzSharp to use it. Also the caching of the results is something which everybody has to do to use HarfBuzz efficiently. It would be better if it was built in.

Additional context

I wrote a blog post about this problem. It also includes benchmarks which show the possible improvement.

Code of Conduct