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

Implement SkCanvas::SaveLayerRec #2962

Open ahmed605 opened 4 months ago

ahmed605 commented 4 months ago

Description of Change

Implement SkCanvas::SaveLayerRec

Bugs Fixed

API Changes

Added:

class SKCanvas {
    public int SaveLayer (SKCanvasSaveLayerRec rec)
}
public enum SKCanvasSaveLayerRecFlags {
    None = 0,
    PreserveLcdText = 2,
    InitializeWithPrevious = 4,
    F16ColorType = 16,
}
public unsafe class SKCanvasSaveLayerRec {
    public SKRect? Bounds { get; set; }
    public SKPaint? Paint { get; set; }
    public SKImageFilter? Backdrop { get; set; }
    public SKCanvasSaveLayerRecFlags Flags { get; set; }
}

Behavioral Changes

None.

Required skia PR

https://github.com/mono/skia/pull/130

PR Checklist

mattleibow commented 3 months ago

Not sure my magic with CI is working with the auto detection of the skia branch (probably because I am not doing it right for forks) so maybe just update the submodule here and we can merge in one go later once the skia PR is merged.

mattleibow commented 1 month ago

/azp run

azure-pipelines[bot] commented 1 month ago
Azure Pipelines could not run because the pipeline triggers exclude this branch/path.
ramezgerges commented 4 weeks ago

@mattleibow Hello, I'm an Uno Platform dev and I'm following up on this PR (and the accompanying mono/skia PR). I haven't actually tested the new APIs yet, but here are my thoughts.

mattleibow commented 3 weeks ago

Thanks for the review @ramezgerges, this makes sense today with the small struct. But, if you look at the latest skia, does your thought still seem valid? The struct is getting fairly large: https://github.com/google/skia/blob/main/include/core/SkCanvas.h#L689 There are new properties to be added - color space, image filters as well as a collection/array of image filters.

Not sure either way here, but at what point to we think a class is better? Will we ever re-use this object for multiple calls?

I was also thinking that due to the large-ish size and potentially fairly complex nature, it should be a class: https://learn.microsoft.com/dotnet/standard/design-guidelines/choosing-between-class-and-struct

However, rules in .NET are just best ideas for most cases, not the law. So, maybe we can break it. But, a struct may still be the best. Not sure if any of this changes anything? Let me know if you still think a struct is better.

ramezgerges commented 3 weeks ago

Thanks for getting back to me, @mattleibow. Just to be clear, the struct-vs-class point is merely a suggestion/observation, and I'm okay with the PR either way.