From b857b2a16c2dee9c2e2733dd72508bdd62b1d129 Mon Sep 17 00:00:00 2001 From: Hugh Bellamy Date: Tue, 19 Sep 2017 22:28:44 +0100 Subject: [PATCH] Fix multiplying TextureBrush with a disposed matrix on Unix (dotnet/corefx#24109) * Fix multiplying TextureBrush with a disposed matrix on Unix * Enable another passing test * Fix accidentally committed file Commit migrated from https://github.com/dotnet/corefx/commit/15f9a31fd45f9a7d667765ef08ecfd1cefddde3a --- .../src/System/Drawing/TextureBrush.cs | 9 ++++++++- .../System.Drawing.Common/tests/TextureBrushTests.cs | 4 ---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/TextureBrush.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/TextureBrush.cs index c39f329afc107..1710dfb4dc43b 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/TextureBrush.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/TextureBrush.cs @@ -168,7 +168,7 @@ public Matrix Transform { if (value == null) { - throw new ArgumentNullException("value"); + throw new ArgumentNullException(nameof(value)); } int status = SafeNativeMethods.Gdip.GdipSetTextureTransform(new HandleRef(this, NativeBrush), new HandleRef(value, value.nativeMatrix)); @@ -225,6 +225,13 @@ public void MultiplyTransform(Matrix matrix, MatrixOrder order) throw new ArgumentNullException(nameof(matrix)); } + // Multiplying the transform by a disposed matrix is a nop in GDI+, but throws + // with the libgdiplus backend. Simulate a nop for compatability with GDI+. + if (matrix.nativeMatrix == IntPtr.Zero) + { + return; + } + int status = SafeNativeMethods.Gdip.GdipMultiplyTextureTransform(new HandleRef(this, NativeBrush), new HandleRef(matrix, matrix.nativeMatrix), order); diff --git a/src/libraries/System.Drawing.Common/tests/TextureBrushTests.cs b/src/libraries/System.Drawing.Common/tests/TextureBrushTests.cs index bb93324f0d0ac..02e3e4cc39160 100644 --- a/src/libraries/System.Drawing.Common/tests/TextureBrushTests.cs +++ b/src/libraries/System.Drawing.Common/tests/TextureBrushTests.cs @@ -294,7 +294,6 @@ public void Ctor_DisposedImage_ThrowsArgumentException() AssertExtensions.Throws(null, () => new TextureBrush(image, WrapMode.Tile, Rectangle.Empty)); } - [ActiveIssue(20884, TestPlatforms.AnyUnix)] [ConditionalTheory(Helpers.GdiplusIsAvailable)] [InlineData(WrapMode.Tile - 1)] [InlineData(WrapMode.Clamp + 1)] @@ -431,7 +430,6 @@ public void MultiplyTransform_NotInvertibleMatrix_ThrowsArgumentException() } } - [ActiveIssue(20884, TestPlatforms.AnyUnix)] [ConditionalFact(Helpers.GdiplusIsAvailable)] public void MultiplyTransform_DisposedMatrix_Nop() { @@ -662,7 +660,6 @@ public void Transform_SetValid_GetReturnsExpected() } } - [ActiveIssue(20884, TestPlatforms.AnyUnix)] [ConditionalFact(Helpers.GdiplusIsAvailable)] public void Transform_SetNull_ThrowsArgumentNullException() { @@ -786,7 +783,6 @@ public void WrapMode_SetValid_GetReturnsExpected(WrapMode wrapMode) } } - [ActiveIssue(20884, TestPlatforms.AnyUnix)] [ConditionalTheory(Helpers.GdiplusIsAvailable)] [InlineData(WrapMode.Tile - 1)] [InlineData(WrapMode.Clamp + 1)]