-
Notifications
You must be signed in to change notification settings - Fork 549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[release/2.x] Backport some new APIs from 3.0 to 2.x allowing smoother migration. #2756
Conversation
This reverts commit 19c3b67.
@mattleibow I went through breaking changes page, and these changes were the low hanging fruits of what can be backported from 3.0 to 2.x. Which is also enough for Avalonia to run both versions. Initially I also planned to backport some new SKRuntimeEffect methods (which we don't need), but it feels a bit intrusive, as I am not sure what to pass as isOpaque parameter. I also didn't want to mark obsolete any old APIs that are going to be removed in 3.0. And I am not sure what to do about SKFilterQuality. Looks like 3.0 still handles SKFilterQuality well everywhere, except SKPaint and DrawImage
And that would be enough? Without changing 3.0. |
binding/Binding/SKCanvas.cs
Outdated
@@ -952,6 +952,13 @@ public void SetMatrix (SKMatrix matrix) | |||
SkiaApi.sk_canvas_set_matrix (Handle, &matrix); | |||
} | |||
|
|||
public void SetMatrix (in SKMatrix matrix) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: C# will always prefer more specific overload. Which means for 2.x builds old code will still use old SetMatrix(SKMatrix)
, unless they specify in
explicitly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One annoying thing is that this will make this method ambiguous to visual basic... VB appears not to be able to distinguish between in/ref and nothing. I know we have a scattering of ref and nothing in 2.x and I tried to clean this all up. However, maybe this is making migrations a bit more annoying.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, you are right. Just tested locally, and found this issue confirming it dotnet/vblang#505
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the only choice would be to use reflection/UnsafeAccessor then. I don't really want to modify SkiaSharp 3.0 API surface.
What do you think if instead of adding members to existing classes you added them as extension methods in a class called |
@workgroupengineering this extension method would have to be added to 3.0 as well. So, it can be binary compatible. Imo, it would add more unwanted API surface to maintain. |
binding/Binding/SKCanvas.cs
Outdated
@@ -952,6 +952,13 @@ public void SetMatrix (SKMatrix matrix) | |||
SkiaApi.sk_canvas_set_matrix (Handle, &matrix); | |||
} | |||
|
|||
public void SetMatrix (in SKMatrix matrix) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One annoying thing is that this will make this method ambiguous to visual basic... VB appears not to be able to distinguish between in/ref and nothing. I know we have a scattering of ref and nothing in 2.x and I tried to clean this all up. However, maybe this is making migrations a bit more annoying.
binding/Binding/SKImageFilter.cs
Outdated
@@ -74,13 +74,22 @@ internal SKImageFilter(IntPtr handle, bool owns) | |||
|
|||
// CreateMatrix | |||
|
|||
public static SKImageFilter CreateMatrix(ref SKMatrix matrix) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is in
in 3.x.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
@mattleibow update the PR, removed "in" overloads that will break VB. Current PR changes will already help with some migration, though not ideal. |
Ok. Afk right now but will look tonight or tomorrow. I also think I may have some idea of how to do something quite nice for compat. It is an idea still, but it is coming together nicely. |
This was idea and my testing of prototypes seemed to work nicely. |
@mattleibow I like your idea. Closing this PR then. |
Although, wait, that kind of API changes of this PR cannot be added to 3.0, as it already has these methods :D Unless we add back overloads with SKImageFilter and SKImageFilter.CropRect: Imo, for these methods specifically, it would be simpler to get this PR to 2.88 with overloads without optional parameters, keeping common API. |
Ah yeah. Both. We can backport anything too ugly to do - such as croprect. I'm working on making 2.x shippable again. |
I did some looking around and I had to also remove the default args from the existing ones. #2810 For example, if there is this: public static SKImageFilter CreatePaint(SKPaint paint, SKImageFilter.CropRect cropRect = null) And we just add: public static SKImageFilter CreatePaint (SKPaint paint) People that are using it like this: SKImageFilter.CreatePaint(mypaint); Will now get an ambiguous overload as both match. So I removed the |
Thanks for this PR. I am going to close this one as I think I got all the APIs from 3.x in my PR and a few more things: #2810 |
Description of Change
With these changes Avalonia should be able to work with both 2.x and 3.0 referenced (need to double check once nightly builds are there).
API Changes
Added:
Behavioral Changes
None.
Required skia PR
None.
PR Checklist