Skip to content
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
wants to merge 9 commits into from
7 changes: 7 additions & 0 deletions binding/Binding/SKCanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,13 @@ public void SetMatrix (SKMatrix matrix)
SkiaApi.sk_canvas_set_matrix (Handle, &matrix);
}

public void SetMatrix (in SKMatrix matrix)
Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

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.

{
fixed (SKMatrix* ptr = &matrix) {
SkiaApi.sk_canvas_set_matrix (Handle, ptr);
}
}

public SKMatrix TotalMatrix {
get {
SKMatrix matrix;
Expand Down
57 changes: 57 additions & 0 deletions binding/Binding/SKImageFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,22 @@ protected override void Dispose (bool disposing) =>

// CreateMatrix

public static SKImageFilter CreateMatrix(ref SKMatrix matrix)
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 ();
Expand All @@ -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);

Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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));

Expand All @@ -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));
Expand All @@ -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));
Expand All @@ -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));
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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));
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions binding/Binding/SKPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,24 @@ public SKRect ComputeTightBounds ()
return rect;
}

public void Transform (in SKMatrix matrix)
{
fixed (SKMatrix* m = &matrix)
SkiaApi.sk_path_transform (Handle, m);
}

public void Transform (SKMatrix matrix) =>
SkiaApi.sk_path_transform (Handle, &matrix);

public void Transform (in SKMatrix matrix, SKPath destination)
{
if (destination == null)
throw new ArgumentNullException (nameof (destination));

fixed (SKMatrix* m = &matrix)
SkiaApi.sk_path_transform_to_dest (Handle, m, destination.Handle);
}

public void Transform (SKMatrix matrix, SKPath destination)
{
if (destination == null)
Expand Down