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

Fix a memory leak in SKRoundRect #995

Merged
merged 2 commits into from
Nov 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions binding/Binding/SKRoundRect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,21 @@ public void Offset (float dx, float dy)
SkiaApi.sk_rrect_offset (Handle, dx, dy);
}

public SKRoundRect Transform (SKMatrix matrix)
public bool TryTransform (SKMatrix matrix, out SKRoundRect transformed)
{
var destHandle = SkiaApi.sk_rrect_new ();
if (SkiaApi.sk_rrect_transform (Handle, ref matrix, destHandle)) {
return new SKRoundRect (destHandle, true);
transformed = new SKRoundRect (destHandle, true);
return true;
}
transformed = null;
return false;
}

public SKRoundRect Transform (SKMatrix matrix)
{
if (TryTransform (matrix, out var transformed)) {
return transformed;
}
return null;
}
Expand Down
16 changes: 16 additions & 0 deletions tests/Tests/SKRoundRectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,24 @@ public void CanOffset()
Assert.Equal(offset, rrect.Rect);
}

[SkippableFact]
public void WillFailToTransformWithInvalidTransformation()
{
var rect = SKRect.Create(10, 10, 100, 100);
var offset = rect;
offset.Offset(2, 2);

var rrect = new SKRoundRect(rect, 5, 5);
var transformed = rrect.Transform(SKMatrix.MakeRotationDegrees(30));

Assert.Null(transformed);
}

[SkippableFact]
public void CanTransform()
{
var radii = new[] { new SKPoint(5, 5), new SKPoint(5, 5), new SKPoint(5, 5), new SKPoint(5, 5) };

var rect = SKRect.Create(10, 10, 100, 100);
var offset = rect;
offset.Offset(2, 2);
Expand All @@ -231,6 +246,7 @@ public void CanTransform()
var transformed = rrect.Transform(SKMatrix.MakeTranslation(2, 2));

Assert.Equal(offset, transformed.Rect);
Assert.Equal(radii, transformed.Radii);
}
}
}