-
Notifications
You must be signed in to change notification settings - Fork 549
[.NET/CoreGraphics] Use [UnmanagedCallersOnly] instead of [MonoPInvokeCallback] Partial Fix for #10470 #15906
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
Changes from 2 commits
847c1e7
3f8d0ae
1909fa2
26a001b
587e14a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -58,8 +58,13 @@ public class CGFunction : NativeObject { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| unsafe static CGFunction () | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cbacks.version = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #if NET | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cbacks.evaluate = &EvaluateCallback; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cbacks.release = &ReleaseCallback; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cbacks.evaluate = new CGFunctionEvaluateCallback (EvaluateCallback); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cbacks.release = new CGFunctionReleaseCallback (ReleaseCallback); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #if !NET | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -103,13 +108,22 @@ protected internal override void Release () | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Apple's documentation says 'float', the header files say 'CGFloat' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| unsafe delegate void CGFunctionEvaluateCallback (/* void* */ IntPtr info, /* CGFloat* */ nfloat *data, /* CGFloat* */ nfloat *outData); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| delegate void CGFunctionReleaseCallback (IntPtr info); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #if NET | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [StructLayout (LayoutKind.Sequential)] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| unsafe struct CGFunctionCallbacks { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public /* unsigned int */ uint version; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public delegate* unmanaged<IntPtr, nfloat*, nfloat*, void> evaluate; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public delegate* unmanaged<IntPtr, void> release; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [StructLayout (LayoutKind.Sequential)] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| struct CGFunctionCallbacks { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public /* unsigned int */ uint version; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public CGFunctionEvaluateCallback? evaluate; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public CGFunctionReleaseCallback? release; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the struct is the same and we might add more data in it, why not doing:
Suggested change
That way if we need to add more stuff, we won't have to write it twice.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I considered that, but since the struct needs to be marked At this point every element is different except for the attribute and the uint.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't work if you mark just the fields as unsafe? public unsafe delegate* unmanaged<IntPtr, nfloat*, nfloat*, void> evaluate;
public unsafe delegate* unmanaged<IntPtr, void> release; |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [DllImport (Constants.CoreGraphicsLibrary)] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| extern static IntPtr CGFunctionCreate (/* void* */ IntPtr data, /* size_t */ nint domainDimension, /* CGFloat* */ nfloat []? domain, nint rangeDimension, /* CGFloat* */ nfloat []? range, ref CGFunctionCallbacks callbacks); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -136,17 +150,24 @@ public unsafe CGFunction (nfloat []? domain, nfloat []? range, CGFunctionEvaluat | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var handle = CGFunctionCreate (GCHandle.ToIntPtr (gch), domain is not null ? domain.Length / 2 : 0, domain, range is not null ? range.Length / 2 : 0, range, ref cbacks); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| InitializeHandle (handle); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #if NET | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The [MonoPInvokeCallback (typeof (CGFunctionReleaseCallback))] was just being added in those platforms that are not macOS, now with the #If NET the UnmanagedCallersOnly is added in all platforms including macOS, is this intended?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. It's intentional. My understanding is that macOS doesn't need the |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [UnmanagedCallersOnly] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #if !MONOMAC | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [MonoPInvokeCallback (typeof (CGFunctionReleaseCallback))] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| static void ReleaseCallback (IntPtr info) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| GCHandle.FromIntPtr (info).Free (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #if NET | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [UnmanagedCallersOnly] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question as the previous one. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #if !MONOMAC | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [MonoPInvokeCallback (typeof (CGFunctionEvaluateCallback))] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| unsafe static void EvaluateCallback (IntPtr info, nfloat *input, nfloat *output) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -478,9 +478,12 @@ public unsafe bool ContainsPoint (CGPoint point, bool eoFill) | |
| public delegate void ApplierFunction (CGPathElement element); | ||
|
|
||
| delegate void CGPathApplierFunction (/* void* */ IntPtr info, /* const CGPathElement* */ IntPtr element); | ||
|
|
||
| #if NET | ||
| [UnmanagedCallersOnly] | ||
| #else | ||
| #if !MONOMAC | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same. |
||
| [MonoPInvokeCallback (typeof (CGPathApplierFunction))] | ||
| #endif | ||
| #endif | ||
| static void ApplierCallback (IntPtr info, IntPtr element_ptr) | ||
| { | ||
|
|
@@ -520,12 +523,22 @@ static void ApplierCallback (IntPtr info, IntPtr element_ptr) | |
|
|
||
|
|
||
| [DllImport (Constants.CoreGraphicsLibrary)] | ||
| #if NET | ||
| extern unsafe static void CGPathApply (/* CGPathRef */ IntPtr path, /* void* */ IntPtr info, delegate* unmanaged<IntPtr, IntPtr, void> function); | ||
| #else | ||
| extern static void CGPathApply (/* CGPathRef */ IntPtr path, /* void* */ IntPtr info, CGPathApplierFunction function); | ||
| #endif | ||
|
|
||
| public void Apply (ApplierFunction func) | ||
| { | ||
| GCHandle gch = GCHandle.Alloc (func); | ||
| #if NET | ||
| unsafe { | ||
| CGPathApply (Handle, GCHandle.ToIntPtr (gch), &ApplierCallback); | ||
| } | ||
| #else | ||
| CGPathApply (Handle, GCHandle.ToIntPtr (gch), ApplierCallback); | ||
| #endif | ||
| gch.Free (); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -53,12 +53,21 @@ public enum CGPatternTiling { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| delegate void DrawPatternCallback (/* void* */ IntPtr info, /* CGContextRef */ IntPtr c); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| delegate void ReleaseInfoCallback (/* void* */ IntPtr info); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #if NET | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [StructLayout (LayoutKind.Sequential)] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| unsafe struct CGPatternCallbacks { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| internal /* unsigned int */ uint version; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| internal delegate* unmanaged<IntPtr, IntPtr, void> draw; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| internal delegate* unmanaged<IntPtr, void> release; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [StructLayout (LayoutKind.Sequential)] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| struct CGPatternCallbacks { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| internal /* unsigned int */ uint version; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| internal DrawPatternCallback draw; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| internal ReleaseInfoCallback release; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #endif | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #if NET | |
| [StructLayout (LayoutKind.Sequential)] | |
| unsafe struct CGPatternCallbacks { | |
| internal /* unsigned int */ uint version; | |
| internal delegate* unmanaged<IntPtr, IntPtr, void> draw; | |
| internal delegate* unmanaged<IntPtr, void> release; | |
| } | |
| #else | |
| [StructLayout (LayoutKind.Sequential)] | |
| struct CGPatternCallbacks { | |
| internal /* unsigned int */ uint version; | |
| internal DrawPatternCallback draw; | |
| internal ReleaseInfoCallback release; | |
| } | |
| #endif | |
| [StructLayout (LayoutKind.Sequential)] | |
| struct CGPatternCallbacks { | |
| internal /* unsigned int */ uint version; | |
| #if NET | |
| internal delegate* unmanaged<IntPtr, IntPtr, void> draw; | |
| internal delegate* unmanaged<IntPtr, void> release; | |
| #else | |
| internal DrawPatternCallback draw; | |
| internal ReleaseInfoCallback release; | |
| } | |
| #endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same, it adds macOS when it did not in the past.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this delegate still needed in NET?