Avalonia
Avalonia copied to clipboard
[Experiment] Make Avalonia.Skia compatible with both SkiaSharp 2.88 and 3.0
What does the pull request do?
We have a very little choice but try to sit on both chairs with SkiaSharp. Otherwise, Avalonia is going to be locked on 2.88 version until 12.0 release which won't happen this year.
For the most part SkiaSharp 3.0 is binary compatible with SkiaSharp 2.88. But not 100%, so it still breaks Avalonia rendering backend.
Ideally, my approach with this PR and that compat is general is something like this:
- If we are running on 2.88 (runtime check) - call original API directly
- If we are running on 3.0 - try to call reflection
Note: this PR doesn't attempt to use SKSamplingOptions instead of old deprecated API as it was done in https://github.com/AvaloniaUI/Avalonia/pull/12729. In other words, we will use deprecated API until Avalonia fully migrates to 3.0 as a minimum version.
What's tested so far:
- macOS + metal render
- All pages on ControlCatalog and RenderDemo
What doesn't work yet:
- For some reason RenderDemo app can "crash" and return 0 code. No exception. Need to debug further.
- BuildGlyphRunGeometry throws NRE for some reason on some RenderDemo pages. But text rendering works fine otherwise.
You can test this PR using the following package version. 11.1.999-cibuild0044485-beta
. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]
@mattleibow hi! IIRC there was a document that tracks all breaking changes between 2.88 and 3.0 but can't find it now. Do you still have it?
You can test this PR using the following package version. 11.1.999-cibuild0044493-beta
. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]
If anybody want/can test these packages in your apps with updated SkiaSharp to 3.0 previews, I would appreciate help with testing. Before agreeing on this approach with reusing the same Avalonia.Skia assembly, I want to know if it really works on majority of apps at least.
I've tried this in my App with skia 3.0.0-preview.1.8, I didn't spot any bugs (tho the app is not graphically intensive), but I have notice the default for the image scaling/antialiasing option has changed. Is intentional? (top screenshot is the old skia, the bottom one is the preview) (macOS @ net8)
@mattleibow hi! IIRC there was a document that tracks all breaking changes between 2.88 and 3.0 but can't find it now. Do you still have it?
I think this file and sibling files: https://github.com/mono/SkiaSharp/blob/main/changelogs/SkiaSharp/3.0.0/SkiaSharp.humanreadable.md
If there are some APIs that are used and it is simple to add back, we can maybe add them back into SkiaSharp. I am hoping to ease the treansition if possible, but not at the cost of complex code/hacks. So, depending on what you need, I can potentially add some apis into 2.x or back into 3.x. Can't promise, but some easy wins to reduce breaks is nice to have.
You can test this PR using the following package version. 11.1.999-cibuild0044970-beta
. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]
We don't need that reflection after we use builds with this PR included https://github.com/mono/SkiaSharp/pull/2756
~I still don't know what's wrong with antialiasing in 3.0. FilterQuality is obsolete, but as I can see it still should be supported more or less.~ Nevermind, native side of Skia doesn't use SkCompatPaint.getFilterQuality anymore. It would be a bit harder to support.
You can test this PR using the following package version. 11.1.999-cibuild0045750-beta
. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]
You can test this PR using the following package version. 11.1.999-cibuild0045818-beta
. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]
You can test this PR using the following package version. 11.1.999-cibuild0045826-beta
. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]
You can test this PR using the following package version. 11.1.999-cibuild0045834-beta
. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]