Skip to content

Commit

Permalink
[AppKit] Make P/Invokes have blittable signatures. (#19987)
Browse files Browse the repository at this point in the history
  • Loading branch information
rolfbjarne committed Feb 2, 2024
1 parent ca43bc8 commit 631e363
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
5 changes: 2 additions & 3 deletions src/AppKit/NSAccessibility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,11 @@ public static void PostNotification (NSObject element, NSString notification)
}

[DllImport (Constants.AppKitLibrary)]
[return: MarshalAs (UnmanagedType.I1)]
static extern bool NSAccessibilitySetMayContainProtectedContent ([MarshalAs (UnmanagedType.I1)] bool flag);
static extern byte NSAccessibilitySetMayContainProtectedContent (byte flag);

public static bool SetMayContainProtectedContent (bool flag)
{
return NSAccessibilitySetMayContainProtectedContent (flag);
return NSAccessibilitySetMayContainProtectedContent (flag ? (byte) 1 : (byte) 0) != 0;
}
#endif
}
Expand Down
11 changes: 7 additions & 4 deletions src/AppKit/NSCell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public partial class NSCell {
[DllImport (Constants.AppKitLibrary)]
extern static void NSDrawThreePartImage (CGRect rect,
IntPtr /* NSImage* */ startCap, IntPtr /* NSImage* */ centerFill, IntPtr /* NSImage* */ endCap,
[MarshalAs (UnmanagedType.I1)] bool vertial, nint op, nfloat alphaFraction, [MarshalAs (UnmanagedType.I1)] bool flipped);
byte vertial, nint op, nfloat alphaFraction, byte flipped);

public void DrawThreePartImage (CGRect frame,
NSImage startCap, NSImage centerFill, NSImage endCap,
Expand All @@ -51,15 +51,18 @@ public void DrawThreePartImage (CGRect frame,
frame, startCap.GetHandle (),
centerFill.GetHandle (),
endCap.GetHandle (),
vertical, (nint) (long) op, alphaFraction, flipped);
vertical ? (byte) 1 : (byte) 0,
(nint) (long) op,
alphaFraction,
flipped ? (byte) 1 : (byte) 0);
}

[DllImport (Constants.AppKitLibrary)]
extern static void NSDrawNinePartImage (CGRect frame,
IntPtr /* NSImage* */ topLeftCorner, IntPtr /* NSImage* */ topEdgeFill, IntPtr /* NSImage* */ topRightCorner,
IntPtr /* NSImage* */ leftEdgeFill, IntPtr /* NSImage* */ centerFill, IntPtr /* NSImage* */ rightEdgeFill,
IntPtr /* NSImage* */ bottomLeftCorner, IntPtr /* NSImage* */ bottomEdgeFill, IntPtr /* NSImage* */ bottomRightCnint,
nint op, nfloat alphaFraction, [MarshalAs (UnmanagedType.I1)] bool flipped);
nint op, nfloat alphaFraction, byte flipped);

public void DrawNinePartImage (CGRect frame,
NSImage topLeftCorner, NSImage topEdgeFill, NSImage topRightCorner,
Expand All @@ -77,7 +80,7 @@ public void DrawNinePartImage (CGRect frame,
bottomLeftCorner.GetHandle (),
bottomEdgeFill.GetHandle (),
bottomRightCorner.GetHandle (),
(nint) (long) op, alphaFraction, flipped);
(nint) (long) op, alphaFraction, flipped ? (byte) 1 : (byte) 0);
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/AppKit/NSGraphics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,11 @@ public static NSWindowDepth GetBestDepth (NSString colorspace, nint bitsPerSampl
}

[DllImport (Constants.AppKitLibrary)]
[return: MarshalAs (UnmanagedType.I1)]
extern static bool NSPlanarFromDepth (NSWindowDepth depth);
extern static byte NSPlanarFromDepth (NSWindowDepth depth);

public static bool PlanarFromDepth (NSWindowDepth depth)
{
return NSPlanarFromDepth (depth);
return NSPlanarFromDepth (depth) != 0;
}

[DllImport (Constants.AppKitLibrary)]
Expand Down
4 changes: 0 additions & 4 deletions tests/cecil-tests/BlittablePInvokes.KnownFailures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,6 @@ public partial class BlittablePInvokes {
"System.Boolean AddressBook.ABPerson::ABPersonSetImageData(System.IntPtr,System.IntPtr,System.IntPtr&)",
"System.Boolean AddressBook.ABRecord::ABRecordRemoveValue(System.IntPtr,System.Int32,System.IntPtr&)",
"System.Boolean AddressBook.ABRecord::ABRecordSetValue(System.IntPtr,System.Int32,System.IntPtr,System.IntPtr&)",
"System.Boolean AppKit.NSAccessibility::NSAccessibilitySetMayContainProtectedContent(System.Boolean)",
"System.Boolean AppKit.NSGraphics::NSPlanarFromDepth(AppKit.NSWindowDepth)",
"System.Boolean CFNetwork.CFHTTPAuthentication::CFHTTPAuthenticationAppliesToRequest(System.IntPtr,System.IntPtr)",
"System.Boolean CFNetwork.CFHTTPAuthentication::CFHTTPAuthenticationIsValid(System.IntPtr,System.IntPtr)",
"System.Boolean CFNetwork.CFHTTPAuthentication::CFHTTPAuthenticationRequiresAccountDomain(System.IntPtr)",
Expand Down Expand Up @@ -618,8 +616,6 @@ public partial class BlittablePInvokes {
"System.Runtime.InteropServices.NFloat MediaAccessibility.MACaptionAppearance::MACaptionAppearanceGetRelativeCharacterSize(System.IntPtr,System.IntPtr&)",
"System.Runtime.InteropServices.NFloat MediaAccessibility.MACaptionAppearance::MACaptionAppearanceGetWindowOpacity(System.IntPtr,System.IntPtr&)",
"System.Runtime.InteropServices.NFloat MediaAccessibility.MACaptionAppearance::MACaptionAppearanceGetWindowRoundedCornerRadius(System.IntPtr,System.IntPtr&)",
"System.Void AppKit.NSCell::NSDrawNinePartImage(CoreGraphics.CGRect,System.IntPtr,System.IntPtr,System.IntPtr,System.IntPtr,System.IntPtr,System.IntPtr,System.IntPtr,System.IntPtr,System.IntPtr,System.IntPtr,System.Runtime.InteropServices.NFloat,System.Boolean)",
"System.Void AppKit.NSCell::NSDrawThreePartImage(CoreGraphics.CGRect,System.IntPtr,System.IntPtr,System.IntPtr,System.Boolean,System.IntPtr,System.Runtime.InteropServices.NFloat,System.Boolean)",
"System.Void CoreFoundation.CFBundle::CFBundleGetPackageInfo(System.IntPtr,System.UInt32&,System.UInt32&)",
"System.Void CoreFoundation.CFMessagePort::CFMessagePortGetContext(System.IntPtr,CoreFoundation.CFMessagePort/ContextProxy&)",
"System.Void CoreFoundation.CFStream::CFStreamCreateBoundPair(System.IntPtr,System.IntPtr&,System.IntPtr&,System.IntPtr)",
Expand Down

6 comments on commit 631e363

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

Please sign in to comment.