From f94d65ee440037fbcffea87ecfc71eb37057c0d7 Mon Sep 17 00:00:00 2001 From: Santiago Fernandez Madero Date: Fri, 15 Oct 2021 09:48:15 -0700 Subject: [PATCH] [release/6.0] Move 2 Drawing APIs that are not implemented in netfx to netcoreapp3.1 or later (#60371) --- .../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..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,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 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 NETCOREAPP3_1_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..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,6 +583,7 @@ public object GetContextInfo() throw new NotImplementedException(); } +#if NETCOREAPP3_1_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..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,9 @@ public unsafe void EnumerateMetafile( /// WARNING: This method is for internal FX support only. /// [EditorBrowsable(EditorBrowsableState.Never)] +#if NETCOREAPP3_1_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 NETCOREAPP3_1_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..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,6 +61,7 @@ public static WindowsGraphics FromGraphics(Graphics g, ApplyGraphicsProperties p { Region? clip = null; +#if NETCOREAPP3_1_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) {