Avalonia icon indicating copy to clipboard operation
Avalonia copied to clipboard

[Experiment] Make Avalonia.Skia compatible with both SkiaSharp 2.88 and 3.0

Open maxkatz6 opened this issue 4 months ago • 9 comments

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:

  1. If we are running on 2.88 (runtime check) - call original API directly
  2. 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:

  1. macOS + metal render
  2. All pages on ControlCatalog and RenderDemo

What doesn't work yet:

  1. For some reason RenderDemo app can "crash" and return 0 code. No exception. Need to debug further.
  2. BuildGlyphRunGeometry throws NRE for some reason on some RenderDemo pages. But text rendering works fine otherwise.

maxkatz6 avatar Feb 06 '24 05:02 maxkatz6

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]

avaloniaui-bot avatar Feb 06 '24 06:02 avaloniaui-bot

@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?

maxkatz6 avatar Feb 06 '24 06:02 maxkatz6

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]

avaloniaui-bot avatar Feb 06 '24 07:02 avaloniaui-bot

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.

maxkatz6 avatar Feb 06 '24 07:02 maxkatz6

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) image

BAndysc avatar Feb 06 '24 12:02 BAndysc

@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

mattleibow avatar Feb 06 '24 15:02 mattleibow

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.

mattleibow avatar Feb 06 '24 15:02 mattleibow

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]

avaloniaui-bot avatar Feb 15 '24 07:02 avaloniaui-bot

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.

maxkatz6 avatar Feb 15 '24 09:02 maxkatz6

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]

avaloniaui-bot avatar Mar 06 '24 05:03 avaloniaui-bot

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]

avaloniaui-bot avatar Mar 07 '24 04:03 avaloniaui-bot

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]

avaloniaui-bot avatar Mar 07 '24 05:03 avaloniaui-bot

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]

avaloniaui-bot avatar Mar 07 '24 06:03 avaloniaui-bot