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

[OpenGL/OpenGLES] Make P/Invokes have blittable signatures. #20512

Merged
merged 1 commit into from
Apr 29, 2024
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
15 changes: 13 additions & 2 deletions src/OpenGL/CGLPixelFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#nullable enable

using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Collections.Generic;

Expand Down Expand Up @@ -77,7 +78,9 @@ internal CGLPixelFormat (NativeHandle handle, bool owns)
extern static void CGLReleasePixelFormat (IntPtr handle);

[DllImport (Constants.OpenGLLibrary)]
extern static CGLErrorCode CGLChoosePixelFormat (CGLPixelFormatAttribute [] attributes, out IntPtr /* CGLPixelFormatObj* */ pix, out int /* GLint* */ npix);
unsafe extern static CGLErrorCode CGLChoosePixelFormat (CGLPixelFormatAttribute* attributes, IntPtr* /* CGLPixelFormatObj* */ pix, int* /* GLint* */ npix);

#if !COREBUILD
public CGLPixelFormat (CGLPixelFormatAttribute [] attributes, out int npix)
: base (Create (attributes, out npix), true)
{
Expand All @@ -92,7 +95,14 @@ static IntPtr Create (CGLPixelFormatAttribute [] attributes, out int npix)

Array.Copy (attributes, marshalAttribs, attributes.Length);

CGLErrorCode ret = CGLChoosePixelFormat (marshalAttribs, out pixelFormatOut, out npix);
npix = default;

CGLErrorCode ret;
unsafe {
fixed (CGLPixelFormatAttribute* marshalAttribsPtr = marshalAttribs) {
ret = CGLChoosePixelFormat (marshalAttribsPtr, &pixelFormatOut, (int*) Unsafe.AsPointer<int> (ref npix));
}
}

if (ret != CGLErrorCode.NoError) {
throw new Exception ("CGLChoosePixelFormat returned: " + ret);
Expand Down Expand Up @@ -178,6 +188,7 @@ static CGLPixelFormatAttribute [] ConvertToAttributes (object [] args)
}
return list.ToArray ();
}
#endif // !COREBUILD

}
}
10 changes: 9 additions & 1 deletion src/OpenGLES/EAGLContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using ObjCRuntime;

Expand All @@ -10,7 +11,14 @@ public enum PresentationMode {
}

[DllImport (Constants.OpenGLESLibrary)]
public extern static void EAGLGetVersion (out nuint major, out nuint minor);
unsafe extern static void EAGLGetVersion (nuint* major, nuint* minor);

public unsafe static void EAGLGetVersion (out nuint major, out nuint minor)
{
major = default;
minor = default;
EAGLGetVersion ((nuint*) Unsafe.AsPointer<nuint> (ref major), (nuint*) Unsafe.AsPointer<nuint> (ref minor));
}

#if !XAMCORE_3_0
[Obsolete ("iOS9 does not allow creating an empty instance")]
Expand Down
2 changes: 0 additions & 2 deletions tests/cecil-tests/BlittablePInvokes.KnownFailures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ public partial class BlittablePInvokes {
"ObjCRuntime.NativeHandle ObjCRuntime.Messaging::NativeHandle_objc_msgSendSuper_AudioComponentDescription_ref_NativeHandle(System.IntPtr,System.IntPtr,AudioUnit.AudioComponentDescription,ObjCRuntime.NativeHandle*)",
"ObjCRuntime.NativeHandle ObjCRuntime.Messaging::NativeHandle_objc_msgSendSuper_AudioComponentDescription_UInt32_ref_NativeHandle(System.IntPtr,System.IntPtr,AudioUnit.AudioComponentDescription,System.UInt32,ObjCRuntime.NativeHandle*)",
"ObjCRuntime.NativeHandle ObjCRuntime.Messaging::NativeHandle_objc_msgSendSuper_AudioComponentDescription(System.IntPtr,System.IntPtr,AudioUnit.AudioComponentDescription)",
"OpenGL.CGLErrorCode OpenGL.CGLPixelFormat::CGLChoosePixelFormat(OpenGL.CGLPixelFormatAttribute[],System.IntPtr&,System.Int32&)",
"PrintCore.PMStatusCode PrintCore.PMPageFormat::PMCreatePageFormat(System.IntPtr&)",
"PrintCore.PMStatusCode PrintCore.PMPageFormat::PMCreatePageFormatWithPMPaper(System.IntPtr&,System.IntPtr)",
"PrintCore.PMStatusCode PrintCore.PMPageFormat::PMGetAdjustedPageRect(System.IntPtr,PrintCore.PMRect&)",
Expand Down Expand Up @@ -300,7 +299,6 @@ public partial class BlittablePInvokes {
"System.Void ObjCRuntime.Protocol::protocol_addMethodDescription(System.IntPtr,System.IntPtr,System.IntPtr,System.Boolean,System.Boolean)",
"System.Void ObjCRuntime.Protocol::protocol_addProperty(System.IntPtr,System.IntPtr,System.IntPtr*,System.Int32,System.Boolean,System.Boolean)",
"System.Void ObjCRuntime.Runtime::xamarin_switch_gchandle(System.IntPtr,System.Boolean)",
"System.Void OpenGLES.EAGLContext::EAGLGetVersion(System.UIntPtr&,System.UIntPtr&)",
};
}
}
Loading