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 CGFunction have blittable signatures. #20220

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
18 changes: 11 additions & 7 deletions src/CoreGraphics/CGFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ unsafe static CGFunction ()
cbacks.evaluate = &EvaluateCallback;
cbacks.release = &ReleaseCallback;
#else
cbacks.evaluate = new CGFunctionEvaluateCallback (EvaluateCallback);
cbacks.release = new CGFunctionReleaseCallback (ReleaseCallback);
cbacks.evaluate = Marshal.GetFunctionPointerForDelegate (evaluateCallbackDelegate);
cbacks.release = Marshal.GetFunctionPointerForDelegate (releaseCallbackDelegate);
#endif
}

Expand Down Expand Up @@ -116,13 +116,13 @@ struct CGFunctionCallbacks {
public unsafe delegate* unmanaged<IntPtr, nfloat*, nfloat*, void> evaluate;
public unsafe delegate* unmanaged<IntPtr, void> release;
#else
public CGFunctionEvaluateCallback? evaluate;
public CGFunctionReleaseCallback? release;
public IntPtr evaluate;
public IntPtr release;
#endif
}

[DllImport (Constants.CoreGraphicsLibrary)]
extern static unsafe IntPtr CGFunctionCreate (/* void* */ IntPtr data, /* size_t */ nint domainDimension, /* CGFloat* */ nfloat* domain, nint rangeDimension, /* CGFloat* */ nfloat* range, ref CGFunctionCallbacks callbacks);
extern static unsafe IntPtr CGFunctionCreate (/* void* */ IntPtr data, /* size_t */ nint domainDimension, /* CGFloat* */ nfloat* domain, nint rangeDimension, /* CGFloat* */ nfloat* range, CGFunctionCallbacks* callbacks);

unsafe public delegate void CGFunctionEvaluate (nfloat* data, nfloat* outData);

Expand All @@ -145,14 +145,17 @@ public unsafe CGFunction (nfloat []? domain, nfloat []? range, CGFunctionEvaluat
var gch = GCHandle.Alloc (this);
unsafe {
fixed (nfloat* domainPtr = domain, rangePtr = range) {
var handle = CGFunctionCreate (GCHandle.ToIntPtr (gch), domain is not null ? domain.Length / 2 : 0, domainPtr, range is not null ? range.Length / 2 : 0, rangePtr, ref cbacks);
InitializeHandle (handle);
fixed (CGFunctionCallbacks* cbacksptr = &cbacks) {
var handle = CGFunctionCreate (GCHandle.ToIntPtr (gch), domain is not null ? domain.Length / 2 : 0, domainPtr, range is not null ? range.Length / 2 : 0, rangePtr, cbacksptr);
InitializeHandle (handle);
}
}
}
}
#if NET
[UnmanagedCallersOnly]
#else
static CGFunctionReleaseCallback releaseCallbackDelegate = ReleaseCallback;
#if !MONOMAC
[MonoPInvokeCallback (typeof (CGFunctionReleaseCallback))]
#endif
Expand All @@ -165,6 +168,7 @@ static void ReleaseCallback (IntPtr info)
#if NET
[UnmanagedCallersOnly]
#else
unsafe static CGFunctionEvaluateCallback evaluateCallbackDelegate = EvaluateCallback;
#if !MONOMAC
[MonoPInvokeCallback (typeof (CGFunctionEvaluateCallback))]
#endif
Expand Down
1 change: 0 additions & 1 deletion tests/cecil-tests/BlittablePInvokes.KnownFailures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,6 @@ public partial class BlittablePInvokes {
"System.Int32 Security.SslContext::SSLCopyALPNProtocols(System.IntPtr,System.IntPtr&)",
"System.Int32 Security.SslContext::SSLSetSessionTicketsEnabled(System.IntPtr,System.Boolean)",
"System.Int32 SystemConfiguration.NetworkReachability::SCNetworkReachabilityGetFlags(System.IntPtr,SystemConfiguration.NetworkReachabilityFlags&)",
"System.IntPtr CoreGraphics.CGFunction::CGFunctionCreate(System.IntPtr,System.IntPtr,System.Runtime.InteropServices.NFloat*,System.IntPtr,System.Runtime.InteropServices.NFloat*,CoreGraphics.CGFunction/CGFunctionCallbacks&)",
"System.IntPtr CoreGraphics.CGImage::CGImageCreate(System.IntPtr,System.IntPtr,System.IntPtr,System.IntPtr,System.IntPtr,System.IntPtr,CoreGraphics.CGBitmapFlags,System.IntPtr,System.Runtime.InteropServices.NFloat*,System.Boolean,CoreGraphics.CGColorRenderingIntent)",
"System.IntPtr CoreGraphics.CGImage::CGImageCreateWithJPEGDataProvider(System.IntPtr,System.Runtime.InteropServices.NFloat*,System.Boolean,CoreGraphics.CGColorRenderingIntent)",
"System.IntPtr CoreGraphics.CGImage::CGImageCreateWithPNGDataProvider(System.IntPtr,System.Runtime.InteropServices.NFloat*,System.Boolean,CoreGraphics.CGColorRenderingIntent)",
Expand Down
Loading