RazrFalcon / resvg

An SVG rendering library.
Mozilla Public License 2.0
2.74k stars 220 forks source link

RFC: Replace tiny-skia with native CoreGraphics support on Apple platforms #650

Closed schwa closed 1 year ago

schwa commented 1 year ago

This is more a request for comment than a bug report.

I'm wondering about the feasibility of replacing tiny-skia with native Apple CoreGraphics/Quartz rendering support. Using native CoreGraphics rendering can/could would have several potential benefits on Apple platforms - naming optimisation, use of native fonts and colorspace handling, rendering directly to a context (i.e. a UI view or something else) instead of a intermediate pixel buffer etc.

Is resvg heavily tied to tiny-skia or is there some form of abstraction layer? If tied to tiny-skia would a "tiny-skia-cg" replacement library be a viable option perhaps?

Any thoughts on this topic appreciated. Thanks in advance.

notgull commented 1 year ago

resvg is just a renderer built on top of usvg, you can write another renderer on top of it.

I was planning on doing that but with piet instead of tiny-skia, that way anything that implements piet can be used as a backend. In your case you would be able to use piet-coregraphics.

RazrFalcon commented 1 year ago

There are no real benefits in using CoreGraphics instead of tiny-skia. CoreGraphics isn't really that fast, so performance would be the same, if not worse. Its stroking algorithm is pure garbage. It doesn't support gradient spread modes. Patters support is also buggy. Believe me, I worked with CG a lot.

As for text, aka CoreText, there are no benefits either. You still need a custom text layout implementation on top of it. And do not forget that SVG treats text as paths, therefore we cannot use native glyph renderer either.

As for color management, it doesn't really matter either, since SVG is strictly sRGB, at least for now.

rendering directly to a context (i.e. a UI view or something else) instead of a intermediate pixel buffer etc.

You can do this already, sort of. resvg/tiny-skia can draw on user-provided bytes. Also, SVG requires intermediate layers during rendering, unlike your typical raster file format, meaning that avoiding the base layer allocation doesn't matter much.

Can you do this to begin with? Yes! You can easily fork resvg, because all the heavily lifting is done by usvg. resvg is designed to have swappable renderers. I simply do not provide any other one.