Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove System.Drawing code that doesn't work #54245

Merged
merged 1 commit into from
Jun 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
{
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down