diff --git a/externals/skia b/externals/skia index fa96269312..47de7965be 160000 --- a/externals/skia +++ b/externals/skia @@ -1 +1 @@ -Subproject commit fa96269312596c08d76f645f9038a60de2464410 +Subproject commit 47de7965be076311e824589b0464a4e1e08d54eb diff --git a/tests/Tests/SKCodecTest.cs b/tests/Tests/SKCodecTest.cs index a75efcc797..356e0db1f8 100644 --- a/tests/Tests/SKCodecTest.cs +++ b/tests/Tests/SKCodecTest.cs @@ -17,6 +17,17 @@ public void MinBufferedBytesNeededHasAValue () Assert.True (SKCodec.MinBufferedBytesNeeded > 0); } + [SkippableFact] + public unsafe void StreamLosesOwnershipTddoCodecButIsNotForgotten() + { + var codec = SKCodec.Create(Path.Combine(PathToImages, "color-wheel.png")); + + for (var i = 0; i < 1000; ++i) + { + Assert.Equal(SKCodecResult.Success, codec.GetPixels(out _)); + } + } + [SkippableFact] public unsafe void ReleaseDataWasInvokedOnlyAfterTheCodecWasFinished() { diff --git a/tests/Tests/SKColorSpaceTest.cs b/tests/Tests/SKColorSpaceTest.cs index 175a9f0925..a0e0e7ba49 100644 --- a/tests/Tests/SKColorSpaceTest.cs +++ b/tests/Tests/SKColorSpaceTest.cs @@ -52,31 +52,31 @@ public void ImageInfoColorSpaceIsReferencedCorrectly() CollectGarbage(); - Assert.Equal(1, colorspaceHandle.GetReferenceCount(false)); + Assert.Equal(2, colorspaceHandle.GetReferenceCount(false)); Check(); CollectGarbage(); - Assert.Equal(1, colorspaceHandle.GetReferenceCount(false)); + Assert.Equal(2, colorspaceHandle.GetReferenceCount(false)); GC.KeepAlive(img); void Check() { var peek = img.PeekPixels(); - Assert.Equal(2, colorspaceHandle.GetReferenceCount(false)); + Assert.Equal(3, colorspaceHandle.GetReferenceCount(false)); // get the info and color space var info1 = peek.Info; var cs1 = info1.ColorSpace; - Assert.Equal(3, colorspaceHandle.GetReferenceCount(false)); + Assert.Equal(4, colorspaceHandle.GetReferenceCount(false)); Assert.NotNull(cs1); // get the info and color space again and make sure we are all using the same things var info2 = peek.Info; var cs2 = info2.ColorSpace; - Assert.Equal(3, colorspaceHandle.GetReferenceCount(false)); + Assert.Equal(4, colorspaceHandle.GetReferenceCount(false)); Assert.NotNull(cs2); Assert.Same(cs1, cs2); @@ -97,12 +97,37 @@ SKImage DoWork(out IntPtr handle) Assert.Equal(1, handle.GetReferenceCount(false)); var image = SKImage.Create(info); - Assert.Equal(2, handle.GetReferenceCount(false)); + Assert.Equal(3, handle.GetReferenceCount(false)); return image; } } + [SkippableFact] + public unsafe void ReferencesCountedCorrectly() + { + var colorspace = SKColorSpace.CreateRgb( + new SKColorSpaceTransferFn { A = 0.1f, B = 0.2f, C = 0.3f, D = 0.4f, E = 0.5f, F = 0.6f }, + SKMatrix44.CreateIdentity()); + var handle = colorspace.Handle; + Assert.Equal(1, handle.GetReferenceCount(false)); + + var info = new SKImageInfo(1, 1, SKImageInfo.PlatformColorType, SKAlphaType.Premul, colorspace); + Assert.Equal(1, handle.GetReferenceCount(false)); + + var pixels = new byte[info.BytesSize]; + fixed (byte* p = pixels) + { + var pixmap = new SKPixmap(info, (IntPtr)p); + Assert.Equal(2, handle.GetReferenceCount(false)); + + pixmap.Dispose(); + Assert.Equal(1, handle.GetReferenceCount(false)); + } + + GC.KeepAlive(colorspace); + } + [SkippableFact] public void ColorSpaceIsNotDisposedPrematurely() { @@ -112,30 +137,30 @@ public void ColorSpaceIsNotDisposedPrematurely() CheckBeforeCollection(colorSpaceHandle); - CheckExistingImage(3, img, colorSpaceHandle); + CheckExistingImage(4, img, colorSpaceHandle); CollectGarbage(); Assert.Null(weakColorspace.Target); - Assert.Equal(1, colorSpaceHandle.GetReferenceCount(false)); + Assert.Equal(2, colorSpaceHandle.GetReferenceCount(false)); - CheckExistingImage(2, img, colorSpaceHandle); + CheckExistingImage(3, img, colorSpaceHandle); CollectGarbage(); Assert.Null(weakColorspace.Target); - Assert.Equal(1, colorSpaceHandle.GetReferenceCount(false)); + Assert.Equal(2, colorSpaceHandle.GetReferenceCount(false)); CollectGarbage(); - Assert.Equal(1, colorSpaceHandle.GetReferenceCount(false)); + Assert.Equal(2, colorSpaceHandle.GetReferenceCount(false)); GC.KeepAlive(img); void CheckBeforeCollection(IntPtr csh) { Assert.NotNull(weakColorspace.Target); - Assert.Equal(2, csh.GetReferenceCount(false)); + Assert.Equal(3, csh.GetReferenceCount(false)); } void CheckExistingImage(int expected, SKImage image, IntPtr csh) @@ -144,10 +169,10 @@ void CheckExistingImage(int expected, SKImage image, IntPtr csh) Assert.Equal(expected, csh.GetReferenceCount(false)); var info = peek.Info; - Assert.Equal(3, csh.GetReferenceCount(false)); + Assert.Equal(4, csh.GetReferenceCount(false)); var cs = info.ColorSpace; - Assert.Equal(3, csh.GetReferenceCount(false)); + Assert.Equal(4, csh.GetReferenceCount(false)); Assert.NotNull(cs); } @@ -170,7 +195,7 @@ SKImage DoWork(out IntPtr handle, out WeakReference weak) var image = SKImage.Create(info); - Assert.Equal(2, handle.GetReferenceCount(false)); + Assert.Equal(3, handle.GetReferenceCount(false)); return image; }