Skip to content

Commit

Permalink
[CoreGraphics] Make P/Invokes in CGRect/CGPoint/CGSize have blittable…
Browse files Browse the repository at this point in the history
… signatures. (#20246)

Contributes towards #15684.
  • Loading branch information
rolfbjarne committed Mar 6, 2024
1 parent 8cfbe6f commit a65d539
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
20 changes: 12 additions & 8 deletions src/NativeTypes/Drawing.tt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ using System;
using System.Drawing;
#endif
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

using Foundation;
Expand Down Expand Up @@ -173,7 +174,10 @@ namespace CoreGraphics
<#= type.ArgName #> = Empty;
return false;
}
return NativeDrawingMethods.<#= type.Name #>MakeWithDictionaryRepresentation (dictionaryRepresentation.Handle, out <#=type.ArgName#>);
unsafe {
<#=type.ArgName#> = default;
return NativeDrawingMethods.<#= type.Name #>MakeWithDictionaryRepresentation (dictionaryRepresentation.Handle, (<#= type.Name #> *) Unsafe.AsPointer<<#= type.Name #>> (ref <#=type.ArgName#>)) != 0;
}
}

public NSDictionary ToDictionary ()
Expand Down Expand Up @@ -604,7 +608,10 @@ namespace CoreGraphics
rect = Empty;
return false;
}
return NativeDrawingMethods.CGRectMakeWithDictionaryRepresentation (dictionaryRepresentation.Handle, out rect);
rect = default;
unsafe {
return NativeDrawingMethods.CGRectMakeWithDictionaryRepresentation (dictionaryRepresentation.Handle, (CGRect *) Unsafe.AsPointer<CGRect> (ref rect)) != 0;
}
}

public NSDictionary ToDictionary ()
Expand All @@ -622,14 +629,11 @@ namespace CoreGraphics
internal const string CG = Constants.CoreGraphicsLibrary;
#endif
[DllImport (CG)]
[return: MarshalAs (UnmanagedType.I1)]
internal extern static bool CGRectMakeWithDictionaryRepresentation (IntPtr dict, out CGRect rect);
internal unsafe extern static byte CGRectMakeWithDictionaryRepresentation (IntPtr dict, CGRect* rect);
[DllImport (CG)]
[return: MarshalAs (UnmanagedType.I1)]
internal extern static bool CGPointMakeWithDictionaryRepresentation (IntPtr dict, out CGPoint point);
internal unsafe extern static byte CGPointMakeWithDictionaryRepresentation (IntPtr dict, CGPoint* point);
[DllImport (CG)]
[return: MarshalAs (UnmanagedType.I1)]
internal extern static bool CGSizeMakeWithDictionaryRepresentation (IntPtr dict, out CGSize point);
internal unsafe extern static byte CGSizeMakeWithDictionaryRepresentation (IntPtr dict, CGSize* point);

[DllImport (CG)]
internal extern static IntPtr CGRectCreateDictionaryRepresentation (CGRect rect);
Expand Down
3 changes: 0 additions & 3 deletions tests/cecil-tests/BlittablePInvokes.KnownFailures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,6 @@ public partial class BlittablePInvokes {
"System.Boolean CoreGraphics.CGPDFScanner::CGPDFScannerScan(System.IntPtr)",
"System.Boolean CoreGraphics.CGRectExtensions::CGRectIsInfinite(CoreGraphics.CGRect)",
"System.Boolean CoreGraphics.CGRectExtensions::CGRectIsNull(CoreGraphics.CGRect)",
"System.Boolean CoreGraphics.NativeDrawingMethods::CGPointMakeWithDictionaryRepresentation(System.IntPtr,CoreGraphics.CGPoint&)",
"System.Boolean CoreGraphics.NativeDrawingMethods::CGRectMakeWithDictionaryRepresentation(System.IntPtr,CoreGraphics.CGRect&)",
"System.Boolean CoreGraphics.NativeDrawingMethods::CGSizeMakeWithDictionaryRepresentation(System.IntPtr,CoreGraphics.CGSize&)",
"System.Boolean CoreMedia.CMBlockBuffer::CMBlockBufferIsEmpty(System.IntPtr)",
"System.Boolean CoreMedia.CMBlockBuffer::CMBlockBufferIsRangeContiguous(System.IntPtr,System.UIntPtr,System.UIntPtr)",
"System.Boolean CoreMedia.CMClock::CMClockMightDrift(System.IntPtr,System.IntPtr)",
Expand Down

8 comments on commit a65d539

@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.

@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.