From d74cb450f40d44487e4d6c311a4b4d5f2edb5e0c Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Tue, 15 Jun 2021 16:26:58 -0500 Subject: [PATCH] Remove System.Drawing code that doesn't work This code only runs on macOS, and expects mono's System.Windows.Forms assembly is loaded into the process. This is causing trim warnings, and it is easier just to delete this code than try to make ILLink happy. This code is only called from Graphics.FromHwnd, which doesn't work because the Carbon.framework no longer exists on macOS. Issue https://github.com/dotnet/runtime/issues/22221 is tracking the test failures that use FromHwnd. --- .../src/System/Drawing/macFunctions.cs | 71 ++----------------- 1 file changed, 4 insertions(+), 67 deletions(-) diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/macFunctions.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/macFunctions.cs index 13e75725b83fdb..ddc7fef94d976a 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/macFunctions.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/macFunctions.cs @@ -28,10 +28,8 @@ // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // -#undef DEBUG_CLIPPING using System.Collections; -using System.Reflection; using System.Runtime.InteropServices; namespace System.Drawing @@ -40,31 +38,6 @@ internal static class MacSupport { internal static readonly Hashtable contextReference = new Hashtable(); internal static readonly object lockobj = new object(); - internal static readonly Delegate? hwnd_delegate = GetHwndDelegate(); - -#if DEBUG_CLIPPING - internal static float red = 1.0f; - internal static float green = 0.0f; - internal static float blue = 0.0f; - internal static int debug_threshold = 1; -#endif - - private static Delegate? GetHwndDelegate() - { - foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies()) - { - if (string.Equals(asm.GetName().Name, "System.Windows.Forms")) - { - Type? driver_type = asm.GetType("System.Windows.Forms.XplatUICarbon"); - if (driver_type != null) - { - return (Delegate?)driver_type.GetField("HwndDelegate", BindingFlags.NonPublic | BindingFlags.Static)!.GetValue(null); - } - } - } - - return null; - } internal static CocoaContext GetCGContextForNSView(IntPtr handle) { @@ -129,39 +102,10 @@ internal static CarbonContext GetCGContextForView(IntPtr handle) CGContextSaveGState(context); - Rectangle[]? clip_rectangles = (Rectangle[]?)hwnd_delegate!.DynamicInvoke(new object[] { handle }); - if (clip_rectangles != null && clip_rectangles.Length > 0) - { - int length = clip_rectangles.Length; - - CGContextBeginPath(context); - CGContextAddRect(context, rc_clip); - - for (int i = 0; i < length; i++) - { - CGContextAddRect(context, new Rect(clip_rectangles[i].X, view_bounds.size.height - clip_rectangles[i].Y - clip_rectangles[i].Height, clip_rectangles[i].Width, clip_rectangles[i].Height)); - } - CGContextClosePath(context); - CGContextEOClip(context); -#if DEBUG_CLIPPING - if (clip_rectangles.Length >= debug_threshold) { - CGContextSetRGBFillColor (context, red, green, blue, 0.5f); - CGContextFillRect (context, rc_clip); - CGContextFlush (context); - System.Threading.Thread.Sleep (500); - if (red == 1.0f) { red = 0.0f; blue = 1.0f; } - else if (blue == 1.0f) { blue = 0.0f; green = 1.0f; } - else if (green == 1.0f) { green = 0.0f; red = 1.0f; } - } -#endif - } - else - { - CGContextBeginPath(context); - CGContextAddRect(context, rc_clip); - CGContextClosePath(context); - CGContextClip(context); - } + CGContextBeginPath(context); + CGContextAddRect(context, rc_clip); + CGContextClosePath(context); + CGContextClip(context); return new CarbonContext(port, context, (int)view_bounds.size.width, (int)view_bounds.size.height); } @@ -285,13 +229,6 @@ internal static void ReleaseContext(IntPtr port, IntPtr context) internal static extern void CGContextSaveGState(IntPtr context); [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")] internal static extern void CGContextRestoreGState(IntPtr context); - -#if DEBUG_CLIPPING - [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")] - internal static extern void CGContextSetRGBFillColor (IntPtr context, float red, float green, float blue, float alpha); - [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")] - internal static extern void CGContextFillRect (IntPtr context, Rect rect); -#endif } internal struct CGSize