-
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
Closed
Closed
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e3f335e
Backport new compatible methods for SKImageFilter
maxkatz6 19c3b67
Make SKRuntimeEffect slightly more compatible with 3.0
maxkatz6 79c8274
Backport SKCanvas.SetMatrix compatible with 3.0
maxkatz6 2951193
Backport SKPath.Transform compatbile with 3.0
maxkatz6 a0ff234
Revert "Make SKRuntimeEffect slightly more compatible with 3.0"
maxkatz6 38d70a5
Remove SKCanvas.SetMatrix(in SKMatrix)
maxkatz6 ee5c52e
Remove SKPath.Transform(in SKMatrix)
maxkatz6 0772de4
Use
maxkatz6 07b711e
Merge branch 'release/2.x' into backport-some-new-APIs
maxkatz6 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,13 +74,22 @@ protected override void Dispose (bool disposing) => | |
|
||
// CreateMatrix | ||
|
||
public static SKImageFilter CreateMatrix(ref SKMatrix matrix) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
{ | ||
fixed (SKMatrix* m = &matrix) | ||
return GetObject(SkiaApi.sk_imagefilter_new_matrix(m, default, IntPtr.Zero)); | ||
} | ||
|
||
public static SKImageFilter CreateMatrix(SKMatrix matrix, SKFilterQuality quality, SKImageFilter input = null) | ||
{ | ||
return GetObject(SkiaApi.sk_imagefilter_new_matrix(&matrix, quality, input == null ? IntPtr.Zero : input.Handle)); | ||
} | ||
|
||
// CreateAlphaThreshold | ||
|
||
public static SKImageFilter CreateAlphaThreshold (SKRectI region, float innerThreshold, float outerThreshold) => | ||
CreateAlphaThreshold (region, innerThreshold, outerThreshold, null); | ||
|
||
public static SKImageFilter CreateAlphaThreshold(SKRectI region, float innerThreshold, float outerThreshold, SKImageFilter input = null) | ||
{ | ||
var reg = new SKRegion (); | ||
|
@@ -98,6 +107,12 @@ public static SKImageFilter CreateAlphaThreshold(SKRegion region, float innerThr | |
|
||
// CreateBlur | ||
|
||
public static SKImageFilter CreateBlur (float sigmaX, float sigmaY) => | ||
CreateBlur (sigmaX, sigmaY, SKShaderTileMode.Decal, null); | ||
|
||
public static SKImageFilter CreateBlur (float sigmaX, float sigmaY, SKShaderTileMode tileMode) => | ||
CreateBlur (sigmaX, sigmaY, tileMode, null); | ||
|
||
public static SKImageFilter CreateBlur (float sigmaX, float sigmaY, SKImageFilter input = null, SKImageFilter.CropRect cropRect = null) => | ||
CreateBlur (sigmaX, sigmaY, SKShaderTileMode.Decal, input, cropRect); | ||
|
||
|
@@ -106,6 +121,9 @@ public static SKImageFilter CreateBlur (float sigmaX, float sigmaY, SKShaderTile | |
|
||
// CreateColorFilter | ||
|
||
public static SKImageFilter CreateColorFilter (SKColorFilter cf) => | ||
CreateColorFilter (cf, null); | ||
|
||
public static SKImageFilter CreateColorFilter(SKColorFilter cf, SKImageFilter input = null, SKImageFilter.CropRect cropRect = null) | ||
{ | ||
if (cf == null) | ||
|
@@ -131,6 +149,9 @@ public static SKImageFilter CreateCompose(SKImageFilter outer, SKImageFilter inn | |
public static SKImageFilter CreateDisplacementMapEffect (SKDisplacementMapEffectChannelSelectorType xChannelSelector, SKDisplacementMapEffectChannelSelectorType yChannelSelector, float scale, SKImageFilter displacement, SKImageFilter input = null, SKImageFilter.CropRect cropRect = null) => | ||
CreateDisplacementMapEffect (xChannelSelector.ToColorChannel (), yChannelSelector.ToColorChannel (), scale, displacement, input, cropRect); | ||
|
||
public static SKImageFilter CreateDisplacementMapEffect (SKColorChannel xChannelSelector, SKColorChannel yChannelSelector, float scale, SKImageFilter displacement) => | ||
CreateDisplacementMapEffect (xChannelSelector, yChannelSelector, scale, displacement, null); | ||
|
||
public static SKImageFilter CreateDisplacementMapEffect (SKColorChannel xChannelSelector, SKColorChannel yChannelSelector, float scale, SKImageFilter displacement, SKImageFilter input = null, SKImageFilter.CropRect cropRect = null) | ||
{ | ||
if (displacement == null) | ||
|
@@ -147,6 +168,9 @@ public static SKImageFilter CreateDropShadow (float dx, float dy, float sigmaX, | |
? CreateDropShadowOnly (dx, dy, sigmaX, sigmaY, color, input, cropRect) | ||
: CreateDropShadow (dx, dy, sigmaX, sigmaY, color, input, cropRect); | ||
|
||
public static SKImageFilter CreateDropShadow (float dx, float dy, float sigmaX, float sigmaY, SKColor color) => | ||
CreateDropShadow (dx, dy, sigmaX, sigmaY, color, null); | ||
|
||
public static SKImageFilter CreateDropShadow (float dx, float dy, float sigmaX, float sigmaY, SKColor color, SKImageFilter input = null, SKImageFilter.CropRect cropRect = null) => | ||
GetObject (SkiaApi.sk_imagefilter_new_drop_shadow (dx, dy, sigmaX, sigmaY, (uint)color, input == null ? IntPtr.Zero : input.Handle, cropRect == null ? IntPtr.Zero : cropRect.Handle)); | ||
|
||
|
@@ -155,6 +179,9 @@ public static SKImageFilter CreateDropShadowOnly (float dx, float dy, float sigm | |
|
||
// Create*LitDiffuse | ||
|
||
public static SKImageFilter CreateDistantLitDiffuse (SKPoint3 direction, SKColor lightColor, float surfaceScale, float kd) => | ||
CreateDistantLitDiffuse (direction, lightColor, surfaceScale, kd, null); | ||
|
||
public static SKImageFilter CreateDistantLitDiffuse(SKPoint3 direction, SKColor lightColor, float surfaceScale, float kd, SKImageFilter input = null, SKImageFilter.CropRect cropRect = null) | ||
{ | ||
return GetObject(SkiaApi.sk_imagefilter_new_distant_lit_diffuse(&direction, (uint)lightColor, surfaceScale, kd, input == null ? IntPtr.Zero : input.Handle, cropRect == null ? IntPtr.Zero : cropRect.Handle)); | ||
|
@@ -172,6 +199,9 @@ public static SKImageFilter CreateSpotLitDiffuse(SKPoint3 location, SKPoint3 tar | |
|
||
// Create*LitSpecular | ||
|
||
public static SKImageFilter CreateDistantLitSpecular (SKPoint3 direction, SKColor lightColor, float surfaceScale, float ks, float shininess) => | ||
CreateDistantLitSpecular (direction, lightColor, surfaceScale, ks, shininess, null); | ||
|
||
public static SKImageFilter CreateDistantLitSpecular(SKPoint3 direction, SKColor lightColor, float surfaceScale, float ks, float shininess, SKImageFilter input = null, SKImageFilter.CropRect cropRect = null) | ||
{ | ||
return GetObject(SkiaApi.sk_imagefilter_new_distant_lit_specular(&direction, (uint)lightColor, surfaceScale, ks, shininess, input == null ? IntPtr.Zero : input.Handle, cropRect == null ? IntPtr.Zero : cropRect.Handle)); | ||
|
@@ -189,6 +219,9 @@ public static SKImageFilter CreateSpotLitSpecular(SKPoint3 location, SKPoint3 ta | |
|
||
// CreateMagnifier | ||
|
||
public static SKImageFilter CreateMagnifier (SKRect src, float inset) => | ||
CreateMagnifier (src, inset, null); | ||
|
||
public static SKImageFilter CreateMagnifier(SKRect src, float inset, SKImageFilter input = null, SKImageFilter.CropRect cropRect = null) | ||
{ | ||
return GetObject(SkiaApi.sk_imagefilter_new_magnifier(&src, inset, input == null ? IntPtr.Zero : input.Handle, cropRect == null ? IntPtr.Zero : cropRect.Handle)); | ||
|
@@ -201,6 +234,9 @@ public static SKImageFilter CreateMagnifier(SKRect src, float inset, SKImageFilt | |
public static SKImageFilter CreateMatrixConvolution (SKSizeI kernelSize, float[] kernel, float gain, float bias, SKPointI kernelOffset, SKMatrixConvolutionTileMode tileMode, bool convolveAlpha, SKImageFilter input = null, SKImageFilter.CropRect cropRect = null) => | ||
CreateMatrixConvolution (kernelSize, kernel, gain, bias, kernelOffset, tileMode.ToShaderTileMode (), convolveAlpha, input, cropRect); | ||
|
||
public static SKImageFilter CreateMatrixConvolution (SKSizeI kernelSize, System.ReadOnlySpan<float> kernel, float gain, float bias, SKPointI kernelOffset, SKShaderTileMode tileMode, bool convolveAlpha) => | ||
CreateMatrixConvolution (kernelSize, kernel.ToArray (), gain, bias, kernelOffset, tileMode, convolveAlpha); | ||
|
||
public static SKImageFilter CreateMatrixConvolution (SKSizeI kernelSize, float[] kernel, float gain, float bias, SKPointI kernelOffset, SKShaderTileMode tileMode, bool convolveAlpha, SKImageFilter input = null, SKImageFilter.CropRect cropRect = null) | ||
{ | ||
if (kernel == null) | ||
|
@@ -214,6 +250,12 @@ public static SKImageFilter CreateMatrixConvolution (SKSizeI kernelSize, float[] | |
|
||
// CreateMerge | ||
|
||
public static SKImageFilter CreateMerge (SKImageFilter first, SKImageFilter second) => | ||
CreateMerge (new[] { first, second }); | ||
|
||
public static SKImageFilter CreateMerge (System.ReadOnlySpan<SKImageFilter> filters) => | ||
CreateMerge (filters.ToArray ()); | ||
|
||
[EditorBrowsable (EditorBrowsableState.Never)] | ||
[Obsolete("Use CreateMerge(SKImageFilter, SKImageFilter, SKImageFilter.CropRect) instead.")] | ||
public static SKImageFilter CreateMerge(SKImageFilter first, SKImageFilter second, SKBlendMode mode, SKImageFilter.CropRect cropRect = null) | ||
|
@@ -249,6 +291,9 @@ public static SKImageFilter CreateMerge(SKImageFilter[] filters, SKImageFilter.C | |
|
||
// CreateDilate | ||
|
||
public static SKImageFilter CreateDilate (int radiusX, int radiusY) => | ||
CreateDilate (radiusX, radiusY, null); | ||
|
||
public static SKImageFilter CreateDilate(int radiusX, int radiusY, SKImageFilter input = null, SKImageFilter.CropRect cropRect = null) => | ||
CreateDilate ((float)radiusX, (float)radiusY, input, cropRect); | ||
|
||
|
@@ -259,6 +304,9 @@ public static SKImageFilter CreateDilate(float radiusX, float radiusY, SKImageFi | |
|
||
// CreateErode | ||
|
||
public static SKImageFilter CreateErode (int radiusX, int radiusY) => | ||
CreateErode (radiusX, radiusY, null); | ||
|
||
public static SKImageFilter CreateErode(int radiusX, int radiusY, SKImageFilter input = null, SKImageFilter.CropRect cropRect = null) => | ||
CreateErode ((float)radiusX, (float)radiusY, input, cropRect); | ||
|
||
|
@@ -269,6 +317,9 @@ public static SKImageFilter CreateErode(float radiusX, float radiusY, SKImageFil | |
|
||
// CreateOffset | ||
|
||
public static SKImageFilter CreateOffset (float dx, float dy) => | ||
CreateOffset (dx, dy, null); | ||
|
||
public static SKImageFilter CreateOffset(float dx, float dy, SKImageFilter input = null, SKImageFilter.CropRect cropRect = null) | ||
{ | ||
return GetObject(SkiaApi.sk_imagefilter_new_offset(dx, dy, input == null ? IntPtr.Zero : input.Handle, cropRect == null ? IntPtr.Zero : cropRect.Handle)); | ||
|
@@ -301,6 +352,9 @@ public static SKImageFilter CreateTile(SKRect src, SKRect dst, SKImageFilter inp | |
|
||
// CreateBlendMode | ||
|
||
public static SKImageFilter CreateBlendMode (SKBlendMode mode, SKImageFilter background, SKImageFilter foreground = null) => | ||
CreateBlendMode (mode, background, foreground, null); | ||
|
||
public static SKImageFilter CreateBlendMode(SKBlendMode mode, SKImageFilter background, SKImageFilter foreground = null, SKImageFilter.CropRect cropRect = null) | ||
{ | ||
if (background == null) | ||
|
@@ -310,6 +364,9 @@ public static SKImageFilter CreateBlendMode(SKBlendMode mode, SKImageFilter back | |
|
||
// CreateArithmetic | ||
|
||
public static SKImageFilter CreateArithmetic (float k1, float k2, float k3, float k4, bool enforcePMColor, SKImageFilter background) => | ||
CreateArithmetic (k1, k2, k3, k4, enforcePMColor, background, null); | ||
|
||
public static SKImageFilter CreateArithmetic(float k1, float k2, float k3, float k4, bool enforcePMColor, SKImageFilter background, SKImageFilter foreground = null, SKImageFilter.CropRect cropRect = null) | ||
{ | ||
if (background == null) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 specifyin
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.