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

[CoreGraphics] Make P/Invokes in CGContext have blittable signatures. #20207

Merged
Merged
Show file tree
Hide file tree
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
42 changes: 20 additions & 22 deletions src/CoreGraphics/CGContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,12 +340,11 @@ public void ReplacePathWithStrokedPath ()


[DllImport (Constants.CoreGraphicsLibrary)]
[return: MarshalAs (UnmanagedType.I1)]
extern static bool CGContextIsPathEmpty (/* CGContextRef */ IntPtr context);
extern static byte CGContextIsPathEmpty (/* CGContextRef */ IntPtr context);

public bool IsPathEmpty ()
{
return CGContextIsPathEmpty (Handle);
return CGContextIsPathEmpty (Handle) != 0;
}

[DllImport (Constants.CoreGraphicsLibrary)]
Expand All @@ -365,12 +364,11 @@ public CGRect GetPathBoundingBox ()
}

[DllImport (Constants.CoreGraphicsLibrary)]
[return: MarshalAs (UnmanagedType.I1)]
extern static bool CGContextPathContainsPoint (/* CGContextRef */ IntPtr context, CGPoint point, CGPathDrawingMode mode);
extern static byte CGContextPathContainsPoint (/* CGContextRef */ IntPtr context, CGPoint point, CGPathDrawingMode mode);

public bool PathContainsPoint (CGPoint point, CGPathDrawingMode mode)
{
return CGContextPathContainsPoint (Handle, point, mode);
return CGContextPathContainsPoint (Handle, point, mode) != 0;
}

[DllImport (Constants.CoreGraphicsLibrary)]
Expand Down Expand Up @@ -1244,26 +1242,26 @@ public void Synchronize ()
}

[DllImport (Constants.CoreGraphicsLibrary)]
extern static void CGContextSetShouldAntialias (/* CGContextRef */ IntPtr context, [MarshalAs (UnmanagedType.I1)] bool shouldAntialias);
extern static void CGContextSetShouldAntialias (/* CGContextRef */ IntPtr context, byte shouldAntialias);

public void SetShouldAntialias (bool shouldAntialias)
{
CGContextSetShouldAntialias (Handle, shouldAntialias);
CGContextSetShouldAntialias (Handle, shouldAntialias.AsByte ());
}

[DllImport (Constants.CoreGraphicsLibrary)]
extern static void CGContextSetAllowsAntialiasing (/* CGContextRef */ IntPtr context, [MarshalAs (UnmanagedType.I1)] bool allowsAntialiasing);
extern static void CGContextSetAllowsAntialiasing (/* CGContextRef */ IntPtr context, byte allowsAntialiasing);
public void SetAllowsAntialiasing (bool allowsAntialiasing)
{
CGContextSetAllowsAntialiasing (Handle, allowsAntialiasing);
CGContextSetAllowsAntialiasing (Handle, allowsAntialiasing.AsByte ());
}

[DllImport (Constants.CoreGraphicsLibrary)]
extern static void CGContextSetShouldSmoothFonts (/* CGContextRef */ IntPtr context, [MarshalAs (UnmanagedType.I1)] bool shouldSmoothFonts);
extern static void CGContextSetShouldSmoothFonts (/* CGContextRef */ IntPtr context, byte shouldSmoothFonts);

public void SetShouldSmoothFonts (bool shouldSmoothFonts)
{
CGContextSetShouldSmoothFonts (Handle, shouldSmoothFonts);
CGContextSetShouldSmoothFonts (Handle, shouldSmoothFonts.AsByte ());
}

[DllImport (Constants.CoreGraphicsLibrary)]
Expand Down Expand Up @@ -1353,43 +1351,43 @@ public CGPath CopyPath ()
}

[DllImport (Constants.CoreGraphicsLibrary)]
extern static void CGContextSetAllowsFontSmoothing (/* CGContextRef */ IntPtr context, [MarshalAs (UnmanagedType.I1)] bool shouldSubpixelPositionFonts);
extern static void CGContextSetAllowsFontSmoothing (/* CGContextRef */ IntPtr context, byte shouldSubpixelPositionFonts);

public void SetAllowsFontSmoothing (bool allows)
{
CGContextSetAllowsFontSmoothing (Handle, allows);
CGContextSetAllowsFontSmoothing (Handle, allows.AsByte ());
}

[DllImport (Constants.CoreGraphicsLibrary)]
extern static void CGContextSetAllowsFontSubpixelPositioning (/* CGContextRef */ IntPtr context, [MarshalAs (UnmanagedType.I1)] bool allowsFontSubpixelPositioning);
extern static void CGContextSetAllowsFontSubpixelPositioning (/* CGContextRef */ IntPtr context, byte allowsFontSubpixelPositioning);

public void SetAllowsSubpixelPositioning (bool allows)
{
CGContextSetAllowsFontSubpixelPositioning (Handle, allows);
CGContextSetAllowsFontSubpixelPositioning (Handle, allows.AsByte ());
}

[DllImport (Constants.CoreGraphicsLibrary)]
extern static void CGContextSetAllowsFontSubpixelQuantization (/* CGContextRef */ IntPtr context, [MarshalAs (UnmanagedType.I1)] bool shouldSubpixelQuantizeFonts);
extern static void CGContextSetAllowsFontSubpixelQuantization (/* CGContextRef */ IntPtr context, byte shouldSubpixelQuantizeFonts);

public void SetAllowsFontSubpixelQuantization (bool allows)
{
CGContextSetAllowsFontSubpixelQuantization (Handle, allows);
CGContextSetAllowsFontSubpixelQuantization (Handle, allows.AsByte ());
}

[DllImport (Constants.CoreGraphicsLibrary)]
extern static void CGContextSetShouldSubpixelPositionFonts (/* CGContextRef */ IntPtr context, [MarshalAs (UnmanagedType.I1)] bool shouldSubpixelPositionFonts);
extern static void CGContextSetShouldSubpixelPositionFonts (/* CGContextRef */ IntPtr context, byte shouldSubpixelPositionFonts);

public void SetShouldSubpixelPositionFonts (bool shouldSubpixelPositionFonts)
{
CGContextSetShouldSubpixelPositionFonts (Handle, shouldSubpixelPositionFonts);
CGContextSetShouldSubpixelPositionFonts (Handle, shouldSubpixelPositionFonts.AsByte ());
}

[DllImport (Constants.CoreGraphicsLibrary)]
extern static void CGContextSetShouldSubpixelQuantizeFonts (/* CGContextRef */ IntPtr context, [MarshalAs (UnmanagedType.I1)] bool shouldSubpixelQuantizeFonts);
extern static void CGContextSetShouldSubpixelQuantizeFonts (/* CGContextRef */ IntPtr context, byte shouldSubpixelQuantizeFonts);

public void ShouldSubpixelQuantizeFonts (bool shouldSubpixelQuantizeFonts)
{
CGContextSetShouldSubpixelQuantizeFonts (Handle, shouldSubpixelQuantizeFonts);
CGContextSetShouldSubpixelQuantizeFonts (Handle, shouldSubpixelQuantizeFonts.AsByte ());
}

[DllImport (Constants.CoreGraphicsLibrary)]
Expand Down
8 changes: 8 additions & 0 deletions src/ObjCRuntime/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace ObjCRuntime {
static class Extensions {
public static byte AsByte (this bool value)
{
return value ? (byte) 1 : (byte) 0;
}
}
}
1 change: 1 addition & 0 deletions src/frameworks.sources
Original file line number Diff line number Diff line change
Expand Up @@ -1932,6 +1932,7 @@ SHARED_CORE_SOURCES = \
ObjCRuntime/Constants.cs \
ObjCRuntime/DisposableObject.cs \
ObjCRuntime/ErrorConstants.cs \
ObjCRuntime/Extensions.cs \
ObjCRuntime/INativeObject.cs \
ObjCRuntime/LinkWithAttribute.cs \
ObjCRuntime/Messaging.cs \
Expand Down
10 changes: 0 additions & 10 deletions tests/cecil-tests/BlittablePInvokes.KnownFailures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,6 @@ public partial class BlittablePInvokes {
"Security.SslStatus Security.SslContext::SSLSetSessionOption(System.IntPtr,Security.SslSessionOption,System.Boolean)",
"Security.SslStatus Security.SslContext::SSLWrite(System.IntPtr,System.Byte*,System.IntPtr,System.IntPtr&)",
"System.Boolean CoreGraphics.CGColor::CGColorEqualToColor(System.IntPtr,System.IntPtr)",
"System.Boolean CoreGraphics.CGContext::CGContextIsPathEmpty(System.IntPtr)",
"System.Boolean CoreGraphics.CGContext::CGContextPathContainsPoint(System.IntPtr,CoreGraphics.CGPoint,CoreGraphics.CGPathDrawingMode)",
"System.Boolean CoreGraphics.CGDisplay::CGDisplayIsCaptured(System.UInt32)",
"System.Boolean CoreGraphics.CGEvent::CGEventTapIsEnabled(System.IntPtr)",
"System.Boolean CoreGraphics.CGEvent::PreflightListenEventAccess()",
Expand Down Expand Up @@ -449,14 +447,6 @@ public partial class BlittablePInvokes {
"System.IntPtr SystemConfiguration.NetworkReachability::SCNetworkReachabilityCreateWithAddressPair(System.IntPtr,System.IntPtr,SystemConfiguration.NetworkReachability/sockaddr_in&)",
"System.IntPtr SystemConfiguration.NetworkReachability::SCNetworkReachabilityCreateWithAddressPair(System.IntPtr,SystemConfiguration.NetworkReachability/sockaddr_in&,System.IntPtr)",
"System.IntPtr SystemConfiguration.NetworkReachability::SCNetworkReachabilityCreateWithAddressPair(System.IntPtr,SystemConfiguration.NetworkReachability/sockaddr_in&,SystemConfiguration.NetworkReachability/sockaddr_in&)",
"System.Void CoreGraphics.CGContext::CGContextSetAllowsAntialiasing(System.IntPtr,System.Boolean)",
"System.Void CoreGraphics.CGContext::CGContextSetAllowsFontSmoothing(System.IntPtr,System.Boolean)",
"System.Void CoreGraphics.CGContext::CGContextSetAllowsFontSubpixelPositioning(System.IntPtr,System.Boolean)",
"System.Void CoreGraphics.CGContext::CGContextSetAllowsFontSubpixelQuantization(System.IntPtr,System.Boolean)",
"System.Void CoreGraphics.CGContext::CGContextSetShouldAntialias(System.IntPtr,System.Boolean)",
"System.Void CoreGraphics.CGContext::CGContextSetShouldSmoothFonts(System.IntPtr,System.Boolean)",
"System.Void CoreGraphics.CGContext::CGContextSetShouldSubpixelPositionFonts(System.IntPtr,System.Boolean)",
"System.Void CoreGraphics.CGContext::CGContextSetShouldSubpixelQuantizeFonts(System.IntPtr,System.Boolean)",
"System.Void CoreGraphics.CGEvent::CGEventKeyboardGetUnicodeString(System.IntPtr,System.UIntPtr,System.UIntPtr&,System.Char*)",
"System.Void CoreGraphics.CGEvent::CGEventTapEnable(System.IntPtr,System.Boolean)",
"System.Void CoreGraphics.CGPath::CGPathAddArc(System.IntPtr,CoreGraphics.CGAffineTransform*,System.Runtime.InteropServices.NFloat,System.Runtime.InteropServices.NFloat,System.Runtime.InteropServices.NFloat,System.Runtime.InteropServices.NFloat,System.Runtime.InteropServices.NFloat,System.Boolean)",
Expand Down
Loading