From 2cabe9c8db160c00f11b83a686c9d022ab31eb8a Mon Sep 17 00:00:00 2001 From: Santiago Fernandez Madero Date: Wed, 13 Oct 2021 14:16:39 -0700 Subject: [PATCH 1/2] Move 2 Drawing APIs that are not implemented in netfx to net6.0 or later --- .../ref/System.Drawing.Common.cs | 4 ++++ .../src/CompatibilitySuppressions.xml | 12 ------------ .../src/System/Drawing/Graphics.Unix.cs | 2 ++ .../src/System/Drawing/Graphics.Windows.cs | 4 ++++ .../src/misc/GDI/WindowsGraphics.cs | 16 ++++++++++++++++ 5 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.cs b/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.cs index 2a6e2a49ef363..685a5342edd12 100644 --- a/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.cs +++ b/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.cs @@ -596,12 +596,16 @@ public void Flush(System.Drawing.Drawing2D.FlushIntention intention) { } public static System.Drawing.Graphics FromImage(System.Drawing.Image image) { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] +#if NET6_0_OR_GREATER [System.ObsoleteAttribute("Use the Graphics.GetContextInfo overloads that accept arguments for better performance and fewer allocations.", DiagnosticId = "SYSLIB0016", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")] +#endif public object GetContextInfo() { throw null; } +#if NET6_0_OR_GREATER [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] public void GetContextInfo(out PointF offset) { throw null; } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] public void GetContextInfo(out PointF offset, out Region? clip) { throw null; } +#endif public static System.IntPtr GetHalftonePalette() { throw null; } public System.IntPtr GetHdc() { throw null; } public System.Drawing.Color GetNearestColor(System.Drawing.Color color) { throw null; } diff --git a/src/libraries/System.Drawing.Common/src/CompatibilitySuppressions.xml b/src/libraries/System.Drawing.Common/src/CompatibilitySuppressions.xml index 22af7d449fc47..a623413023f20 100644 --- a/src/libraries/System.Drawing.Common/src/CompatibilitySuppressions.xml +++ b/src/libraries/System.Drawing.Common/src/CompatibilitySuppressions.xml @@ -1,17 +1,5 @@  - - CP0002 - M:System.Drawing.Graphics.GetContextInfo(System.Drawing.PointF@) - lib/netstandard2.0/System.Drawing.Common.dll - lib/net461/System.Drawing.Common.dll - - - CP0002 - M:System.Drawing.Graphics.GetContextInfo(System.Drawing.PointF@,System.Drawing.Region@) - lib/netstandard2.0/System.Drawing.Common.dll - lib/net461/System.Drawing.Common.dll - CP0001 T:System.Drawing.FontConverter diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.Unix.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.Unix.cs index cba7e4aab0a55..67a8c327fe75b 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.Unix.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.Unix.cs @@ -583,6 +583,7 @@ public object GetContextInfo() throw new NotImplementedException(); } +#if NET6_0_OR_GREATER [EditorBrowsable(EditorBrowsableState.Never)] [SupportedOSPlatform("windows")] public void GetContextInfo(out PointF offset) @@ -596,6 +597,7 @@ public void GetContextInfo(out PointF offset, out Region? clip) { throw new PlatformNotSupportedException(); } +#endif private void CheckErrorStatus(int status) { diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.Windows.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.Windows.cs index 8dd2ad15b22d5..7d8b1fe2cda94 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.Windows.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.Windows.cs @@ -684,7 +684,9 @@ public unsafe void EnumerateMetafile( /// WARNING: This method is for internal FX support only. /// [EditorBrowsable(EditorBrowsableState.Never)] +#if NET6_0_OR_GREATER [Obsolete(Obsoletions.GetContextInfoMessage, DiagnosticId = Obsoletions.GetContextInfoDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] +#endif [SupportedOSPlatform("windows")] public object GetContextInfo() { @@ -763,6 +765,7 @@ private void GetContextInfo(out Matrix3x2 cumulativeTransform, bool calculateCli } } +#if NET6_0_OR_GREATER /// /// Gets the cumulative offset. /// @@ -789,6 +792,7 @@ public void GetContextInfo(out PointF offset, out Region? clip) Vector2 translation = cumulativeTransform.Translation; offset = new PointF(translation.X, translation.Y); } +#endif public RectangleF VisibleClipBounds { diff --git a/src/libraries/System.Drawing.Common/src/misc/GDI/WindowsGraphics.cs b/src/libraries/System.Drawing.Common/src/misc/GDI/WindowsGraphics.cs index 6257a8219199b..ab7c318fd860b 100644 --- a/src/libraries/System.Drawing.Common/src/misc/GDI/WindowsGraphics.cs +++ b/src/libraries/System.Drawing.Common/src/misc/GDI/WindowsGraphics.cs @@ -61,6 +61,7 @@ public static WindowsGraphics FromGraphics(Graphics g, ApplyGraphicsProperties p { Region? clip = null; +#if NET6_0_OR_GREATER if (properties.HasFlag(ApplyGraphicsProperties.Clipping)) { g.GetContextInfo(out offset, out clip); @@ -69,6 +70,21 @@ public static WindowsGraphics FromGraphics(Graphics g, ApplyGraphicsProperties p { g.GetContextInfo(out offset); } +#else + Matrix? worldTransf = null; + if (g.GetContextInfo() is object[] data && data.Length == 2) + { + if (properties.HasFlag(ApplyGraphicsProperties.Clipping)) + { + clip = data[0] as Region; + } + worldTransf = data[1] as Matrix; + if (worldTransf != null) + { + offset = worldTransf.Offset; + } + } +#endif if (clip is not null) { From 8f071a196753bd342fa408099d7ba59ecc413366 Mon Sep 17 00:00:00 2001 From: Santiago Fernandez Madero Date: Thu, 14 Oct 2021 17:46:27 -0700 Subject: [PATCH 2/2] Include the APIs on netcoreapp3.1 or later --- .../System.Drawing.Common/ref/System.Drawing.Common.cs | 4 ++-- .../System.Drawing.Common/src/System/Drawing/Graphics.Unix.cs | 2 +- .../src/System/Drawing/Graphics.Windows.cs | 4 ++-- .../System.Drawing.Common/src/misc/GDI/WindowsGraphics.cs | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.cs b/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.cs index 685a5342edd12..ba1d25352fc23 100644 --- a/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.cs +++ b/src/libraries/System.Drawing.Common/ref/System.Drawing.Common.cs @@ -596,11 +596,11 @@ public void Flush(System.Drawing.Drawing2D.FlushIntention intention) { } public static System.Drawing.Graphics FromImage(System.Drawing.Image image) { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] -#if NET6_0_OR_GREATER +#if NETCOREAPP3_1_OR_GREATER [System.ObsoleteAttribute("Use the Graphics.GetContextInfo overloads that accept arguments for better performance and fewer allocations.", DiagnosticId = "SYSLIB0016", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")] #endif public object GetContextInfo() { throw null; } -#if NET6_0_OR_GREATER +#if NETCOREAPP3_1_OR_GREATER [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] public void GetContextInfo(out PointF offset) { throw null; } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.Unix.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.Unix.cs index 67a8c327fe75b..4baa41dad2449 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.Unix.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.Unix.cs @@ -583,7 +583,7 @@ public object GetContextInfo() throw new NotImplementedException(); } -#if NET6_0_OR_GREATER +#if NETCOREAPP3_1_OR_GREATER [EditorBrowsable(EditorBrowsableState.Never)] [SupportedOSPlatform("windows")] public void GetContextInfo(out PointF offset) diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.Windows.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.Windows.cs index 7d8b1fe2cda94..475e35a176cea 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.Windows.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.Windows.cs @@ -684,7 +684,7 @@ public unsafe void EnumerateMetafile( /// WARNING: This method is for internal FX support only. /// [EditorBrowsable(EditorBrowsableState.Never)] -#if NET6_0_OR_GREATER +#if NETCOREAPP3_1_OR_GREATER [Obsolete(Obsoletions.GetContextInfoMessage, DiagnosticId = Obsoletions.GetContextInfoDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] #endif [SupportedOSPlatform("windows")] @@ -765,7 +765,7 @@ private void GetContextInfo(out Matrix3x2 cumulativeTransform, bool calculateCli } } -#if NET6_0_OR_GREATER +#if NETCOREAPP3_1_OR_GREATER /// /// Gets the cumulative offset. /// diff --git a/src/libraries/System.Drawing.Common/src/misc/GDI/WindowsGraphics.cs b/src/libraries/System.Drawing.Common/src/misc/GDI/WindowsGraphics.cs index ab7c318fd860b..1322bd6e81d08 100644 --- a/src/libraries/System.Drawing.Common/src/misc/GDI/WindowsGraphics.cs +++ b/src/libraries/System.Drawing.Common/src/misc/GDI/WindowsGraphics.cs @@ -61,7 +61,7 @@ public static WindowsGraphics FromGraphics(Graphics g, ApplyGraphicsProperties p { Region? clip = null; -#if NET6_0_OR_GREATER +#if NETCOREAPP3_1_OR_GREATER if (properties.HasFlag(ApplyGraphicsProperties.Clipping)) { g.GetContextInfo(out offset, out clip);