diff --git a/binding/Binding/SKMatrix.cs b/binding/Binding/SKMatrix.cs index df951e0c..3c21f140 100644 --- a/binding/Binding/SKMatrix.cs +++ b/binding/Binding/SKMatrix.cs @@ -346,7 +346,7 @@ typeMask = Mask.Scale | Mask.RectStaysRect public bool TryInvert (out SKMatrix inverse) { - return SkiaApi.sk_matrix_try_invert (ref this, out inverse) != 0; + return SkiaApi.sk_matrix_try_invert (ref this, out inverse); } public static void Concat (ref SKMatrix target, SKMatrix first, SKMatrix second) diff --git a/binding/Binding/SkiaApi.cs b/binding/Binding/SkiaApi.cs index 8d54bacc..55e20bb1 100755 --- a/binding/Binding/SkiaApi.cs +++ b/binding/Binding/SkiaApi.cs @@ -1510,7 +1510,8 @@ namespace SkiaSharp // matrix [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] - public extern static int sk_matrix_try_invert (ref SKMatrix matrix, out SKMatrix result); + [return: MarshalAs (UnmanagedType.I1)] + public extern static bool sk_matrix_try_invert (ref SKMatrix matrix, out SKMatrix result); [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] public extern static void sk_matrix_concat (ref SKMatrix target, ref SKMatrix first, ref SKMatrix second); [DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)] diff --git a/externals/skia b/externals/skia index ae5b1605..1cd54720 160000 --- a/externals/skia +++ b/externals/skia @@ -1 +1 @@ -Subproject commit ae5b160550244321c26510b6520270de275bbdcf +Subproject commit 1cd54720ac6d215cd9086b18ef7582a4a85dd42f diff --git a/tests/Tests/SKCanvasTest.cs b/tests/Tests/SKCanvasTest.cs index 5e6e5e3f..6ec74053 100644 --- a/tests/Tests/SKCanvasTest.cs +++ b/tests/Tests/SKCanvasTest.cs @@ -156,6 +156,20 @@ namespace SkiaSharp.Tests } } + [SkippableFact] + public void TotalMatrixIsCorrect() + { + using (var bitmap = new SKBitmap(new SKImageInfo(100, 100))) + using (var canvas = new SKCanvas(bitmap)) + { + canvas.Translate(10, 20); + Assert.Equal(SKMatrix.MakeTranslation(10, 20).Values, canvas.TotalMatrix.Values); + + canvas.Translate(10, 20); + Assert.Equal(SKMatrix.MakeTranslation(20, 40).Values, canvas.TotalMatrix.Values); + } + } + [SkippableFact] public void SvgCanvasSavesFile() { diff --git a/tests/Tests/SKMatrixTests.cs b/tests/Tests/SKMatrixTests.cs index 7ac613e1..c503b24a 100644 --- a/tests/Tests/SKMatrixTests.cs +++ b/tests/Tests/SKMatrixTests.cs @@ -145,6 +145,48 @@ namespace SkiaSharp.Tests Assert.Equal(results, actualResults); } + [SkippableFact] + public void MatrixCanInvert() + { + var m = SKMatrix.MakeTranslation(10, 20); + Assert.True(m.TryInvert(out var inverse)); + Assert.Equal(SKMatrix.MakeTranslation(-10, -20).Values, inverse.Values); + } + + [SkippableFact] + public void MatrixCanConcat() + { + var a = SKMatrix.MakeTranslation(10, 20); + var b = SKMatrix.MakeTranslation(5, 7); + var c = new SKMatrix(); + + SKMatrix.Concat(ref c, ref a, ref b); + + Assert.Equal(SKMatrix.MakeTranslation(15, 27).Values, c.Values); + } + + [SkippableFact] + public void MatrixCanPreConcat() + { + var a = SKMatrix.MakeTranslation(10, 20); + var b = SKMatrix.MakeTranslation(5, 7); + + SKMatrix.PreConcat(ref a, ref b); + + Assert.Equal(SKMatrix.MakeTranslation(15, 27).Values, a.Values); + } + + [SkippableFact] + public void MatrixCanPostConcat() + { + var a = SKMatrix.MakeTranslation(10, 20); + var b = SKMatrix.MakeTranslation(5, 7); + + SKMatrix.PostConcat(ref a, ref b); + + Assert.Equal(SKMatrix.MakeTranslation(15, 27).Values, a.Values); + } + [SkippableFact] public void MatrixMapsPoints() {