diff --git a/src/CoreVideo/CVImageBuffer.cs b/src/CoreVideo/CVImageBuffer.cs index 06bb3a36ab..7f9dad5682 100644 --- a/src/CoreVideo/CVImageBuffer.cs +++ b/src/CoreVideo/CVImageBuffer.cs @@ -83,12 +83,11 @@ namespace CoreVideo { } [DllImport (Constants.CoreVideoLibrary)] - [return: MarshalAs (UnmanagedType.I1)] - extern static /* Boolean */ bool CVImageBufferIsFlipped (/* CVImageBufferRef __nonnull */ IntPtr imageBuffer); + extern static /* Boolean */ byte CVImageBufferIsFlipped (/* CVImageBufferRef __nonnull */ IntPtr imageBuffer); public bool IsFlipped { get { - return CVImageBufferIsFlipped (Handle); + return CVImageBufferIsFlipped (Handle) != 0; } } diff --git a/src/CoreVideo/CVMetalTexture.cs b/src/CoreVideo/CVMetalTexture.cs index 372110cf24..9e1cab0c48 100644 --- a/src/CoreVideo/CVMetalTexture.cs +++ b/src/CoreVideo/CVMetalTexture.cs @@ -47,8 +47,7 @@ namespace CoreVideo { /* CVMetalTextureRef __nonnull */ IntPtr image); [DllImport (Constants.CoreVideoLibrary)] - [return: MarshalAs (UnmanagedType.I1)] - extern static /* Boolean */ bool CVMetalTextureIsFlipped (/* CVMetalTextureRef __nonnull */ IntPtr image); + extern static /* Boolean */ byte CVMetalTextureIsFlipped (/* CVMetalTextureRef __nonnull */ IntPtr image); [DllImport (Constants.CoreVideoLibrary)] extern static void CVMetalTextureGetCleanTexCoords (/* CVMetalTextureRef __nonnull */ IntPtr image, @@ -63,7 +62,7 @@ namespace CoreVideo { public bool IsFlipped { get { - return CVMetalTextureIsFlipped (Handle); + return CVMetalTextureIsFlipped (Handle) != 0; } } diff --git a/src/CoreVideo/CVMetalTextureCache.cs b/src/CoreVideo/CVMetalTextureCache.cs index b50993723d..891ef156ac 100644 --- a/src/CoreVideo/CVMetalTextureCache.cs +++ b/src/CoreVideo/CVMetalTextureCache.cs @@ -27,12 +27,12 @@ namespace CoreVideo { public partial class CVMetalTextureCache : NativeObject { [DllImport (Constants.CoreVideoLibrary)] - extern static int /* CVReturn = int32_t */ CVMetalTextureCacheCreate ( + unsafe extern static CVReturn /* CVReturn = int32_t */ CVMetalTextureCacheCreate ( /* CFAllocatorRef __nullable */ IntPtr allocator, /* CFDictionaryRef __nullable */ IntPtr cacheAttributes, /* id __nonnull */ IntPtr metalDevice, /* CFDictionaryRef __nullable */ IntPtr textureAttributes, - /* CVMetalTextureCacheRef __nullable * __nonnull */ out IntPtr cacheOut); + /* CVMetalTextureCacheRef __nullable * __nonnull */ IntPtr* cacheOut); [Preserve (Conditional = true)] internal CVMetalTextureCache (NativeHandle handle, bool owns) @@ -45,11 +45,15 @@ namespace CoreVideo { if (metalDevice is null) ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (metalDevice)); - CVReturn err = (CVReturn) CVMetalTextureCacheCreate (IntPtr.Zero, + IntPtr handle; + CVReturn err; + unsafe { + err = CVMetalTextureCacheCreate (IntPtr.Zero, IntPtr.Zero, /* change one day to support cache attributes */ metalDevice.Handle, textureAttributes.GetHandle (), - out var handle); + &handle); + } if (err == CVReturn.Success) return handle; @@ -66,11 +70,15 @@ namespace CoreVideo { if (metalDevice is null) ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (metalDevice)); IntPtr handle; - if (CVMetalTextureCacheCreate (IntPtr.Zero, + CVReturn err; + unsafe { + err = CVMetalTextureCacheCreate (IntPtr.Zero, IntPtr.Zero, /* change one day to support cache attributes */ metalDevice.Handle, IntPtr.Zero, /* change one day to support texture attribuets */ - out handle) == 0) + &handle); + } + if (err == 0) return new CVMetalTextureCache (handle, true); return null; } @@ -85,11 +93,13 @@ namespace CoreVideo { if (metalDevice is null) ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (metalDevice)); IntPtr handle; - creationErr = (CVReturn) CVMetalTextureCacheCreate (IntPtr.Zero, + unsafe { + creationErr = CVMetalTextureCacheCreate (IntPtr.Zero, IntPtr.Zero, /* change one day to support cache attributes */ metalDevice.Handle, textureAttributes.GetHandle (), - out handle); + &handle); + } if (creationErr == CVReturn.Success) return new CVMetalTextureCache (handle, true); return null; @@ -107,16 +117,18 @@ namespace CoreVideo { ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (imageBuffer)); IntPtr texture; - errorCode = CVMetalTextureCacheCreateTextureFromImage ( - allocator: IntPtr.Zero, - textureCache: Handle, /* textureCache dict, one day we might add it */ - sourceImage: imageBuffer.Handle, - textureAttr: IntPtr.Zero, - format: (nuint) (ulong) format, - width: width, - height: height, - planeIndex: planeIndex, - textureOut: out texture); + unsafe { + errorCode = CVMetalTextureCacheCreateTextureFromImage ( + allocator: IntPtr.Zero, + textureCache: Handle, /* textureCache dict, one day we might add it */ + sourceImage: imageBuffer.Handle, + textureAttr: IntPtr.Zero, + format: (nuint) (ulong) format, + width: width, + height: height, + planeIndex: planeIndex, + textureOut: &texture); + } if (errorCode != 0) return null; return new CVMetalTexture (texture, true); @@ -132,7 +144,7 @@ namespace CoreVideo { } [DllImport (Constants.CoreVideoLibrary)] - extern static CVReturn CVMetalTextureCacheCreateTextureFromImage ( + unsafe extern static CVReturn CVMetalTextureCacheCreateTextureFromImage ( /* CFAllocatorRef __nullable */ IntPtr allocator, /* CVMetalTextureCacheRef __nonnull */ IntPtr textureCache, /* CVImageBufferRef __nonnull */ IntPtr sourceImage, @@ -141,7 +153,7 @@ namespace CoreVideo { /* size_t */ nint width, /* size_t */ nint height, /* size_t */ nint planeIndex, - /* CVMetalTextureRef __nullable * __nonnull */ out IntPtr textureOut); + /* CVMetalTextureRef __nullable * __nonnull */ IntPtr* textureOut); } } diff --git a/tests/cecil-tests/BlittablePInvokes.KnownFailures.cs b/tests/cecil-tests/BlittablePInvokes.KnownFailures.cs index 774997b649..ce0f57c4d3 100644 --- a/tests/cecil-tests/BlittablePInvokes.KnownFailures.cs +++ b/tests/cecil-tests/BlittablePInvokes.KnownFailures.cs @@ -64,7 +64,6 @@ namespace Cecil.Tests { "AVFoundation.AVSampleCursorSyncInfo ObjCRuntime.Messaging::AVSampleCursorSyncInfo_objc_msgSend(System.IntPtr,System.IntPtr)", "AVFoundation.AVSampleCursorSyncInfo ObjCRuntime.Messaging::AVSampleCursorSyncInfo_objc_msgSendSuper_stret(System.IntPtr,System.IntPtr)", "AVFoundation.AVSampleCursorSyncInfo ObjCRuntime.Messaging::AVSampleCursorSyncInfo_objc_msgSendSuper(System.IntPtr,System.IntPtr)", - "CoreVideo.CVReturn CoreVideo.CVMetalTextureCache::CVMetalTextureCacheCreateTextureFromImage(System.IntPtr,System.IntPtr,System.IntPtr,System.IntPtr,System.UIntPtr,System.IntPtr,System.IntPtr,System.IntPtr,System.IntPtr&)", "CoreVideo.CVReturn CoreVideo.CVPixelBuffer::CVPixelBufferCreate(System.IntPtr,System.IntPtr,System.IntPtr,CoreVideo.CVPixelFormatType,System.IntPtr,System.IntPtr&)", "CoreVideo.CVReturn CoreVideo.CVPixelBuffer::CVPixelBufferCreateResolvedAttributesDictionary(System.IntPtr,System.IntPtr,System.IntPtr&)", "CoreVideo.CVReturn CoreVideo.CVPixelBuffer::CVPixelBufferCreateWithBytes(System.IntPtr,System.IntPtr,System.IntPtr,CoreVideo.CVPixelFormatType,System.IntPtr,System.IntPtr,method System.Void *(System.IntPtr,System.IntPtr),System.IntPtr,System.IntPtr,System.IntPtr&)", @@ -153,8 +152,6 @@ namespace Cecil.Tests { "Security.SslStatus Security.SslContext::SSLRead(System.IntPtr,System.Byte*,System.IntPtr,System.IntPtr&)", "Security.SslStatus Security.SslContext::SSLSetSessionOption(System.IntPtr,Security.SslSessionOption,System.Boolean)", "Security.SslStatus Security.SslContext::SSLWrite(System.IntPtr,System.Byte*,System.IntPtr,System.IntPtr&)", - "System.Boolean CoreVideo.CVImageBuffer::CVImageBufferIsFlipped(System.IntPtr)", - "System.Boolean CoreVideo.CVMetalTexture::CVMetalTextureIsFlipped(System.IntPtr)", "System.Boolean CoreVideo.CVPixelBuffer::CVPixelBufferIsPlanar(System.IntPtr)", "System.Boolean CoreVideo.CVPixelFormatTypeExtensions::CVIsCompressedPixelFormatAvailable(System.UInt32)", "System.Boolean Foundation.NSObject::xamarin_set_gchandle_with_flags_safe(System.IntPtr,System.IntPtr,Foundation.NSObject/XamarinGCHandleFlags)", @@ -233,7 +230,6 @@ namespace Cecil.Tests { "System.Int32 AudioUnit.AudioUnit::AudioUnitGetProperty(System.IntPtr,AudioUnit.AudioUnitPropertyIDType,AudioUnit.AudioUnitScopeType,System.UInt32,System.UInt32&,System.UInt32&)", "System.Int32 AudioUnit.AudioUnit::AudioUnitSetProperty(System.IntPtr,AudioUnit.AudioUnitPropertyIDType,AudioUnit.AudioUnitScopeType,System.UInt32,AudioToolbox.AudioStreamBasicDescription&,System.UInt32)", "System.Int32 AudioUnit.AUGraph::NewAUGraph(System.IntPtr&)", - "System.Int32 CoreVideo.CVMetalTextureCache::CVMetalTextureCacheCreate(System.IntPtr,System.IntPtr,System.IntPtr,System.IntPtr,System.IntPtr&)", "System.Int32 ObjCRuntime.Runtime::_NSGetExecutablePath(System.Byte[],System.Int32&)", "System.Int32 Security.Authorization::AuthorizationCreate(Security.AuthorizationItemSet*,Security.AuthorizationItemSet*,Security.AuthorizationFlags,System.IntPtr&)", "System.Int32 Security.SecCertificate::SecCertificateCopyCommonName(System.IntPtr,System.IntPtr&)",