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 543 forks source link

[FEATURE] Expose SkCanvas::SaveLayerRec API #2773

Open ahmed605 opened 9 months ago

ahmed605 commented 9 months ago

Is your feature request related to a problem?

SkCanvas::SaveLayerRec is missing from SkiaSharp's API surface, this API is very useful for implementing backdrop effects/filters, we need this API in order to implement CompositionBackdropBrush properly in Uno Platform.

Describe the solution you would like

It would be great if SkCanvas::SaveLayerRec got exposed in SkiaSharp

Describe alternatives you have considered

We currently use a combination of SKCanvas.SaveLayer(SKPaint), SKCanvas.DrawSurface(SKSurface, SKRect), and SKCanvas.Restore() as a workaround, but it isn't ideal and has few issues (e.g. need to downscale the canvas manually, no custom clipping, slower since it's not optimized for backdrop effects unlike SkCanvas::SaveLayerRec, image filter of SKPaint isn't fully applied to the saved region (due to scaling miscalculations?), etc...)

Additional context

No response

Code of Conduct

Gillibald commented 8 months ago

This is also needed to make ClearType work with layering. Otherwise parameters like pixel geometry or sub pixel text are not preserved for the created layer.

Youssef1313 commented 4 months ago

@mattleibow What are the chances we can have this in SkiaSharp 3?

Gillibald commented 4 months ago

It does not require too much work. The native layer needs to expose the missing API and a new struct needs to be mapped.

mattleibow commented 1 month ago

@Gillibald @Youssef1313 @ahmed605 I have updated the PRs, let me know if the class-based API will work. Do you see any issues with this?