Skip to content

Commit

Permalink
[CoreVideo] Implement Xcode 16.0 beta 1-6 changes. (#21163)
Browse files Browse the repository at this point in the history
Note: there were no changes in beta 2, beta 3, beta 5 or beta 6.
  • Loading branch information
rolfbjarne authored Sep 12, 2024
1 parent fd88272 commit ad1a3b7
Show file tree
Hide file tree
Showing 19 changed files with 637 additions and 107 deletions.
204 changes: 204 additions & 0 deletions src/CoreVideo/CVDisplayLink.cs

Large diffs are not rendered by default.

58 changes: 58 additions & 0 deletions src/CoreVideo/CVMetalBuffer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#if !WATCH
using System;
using System.Runtime.InteropServices;

using CoreFoundation;
using CoreGraphics;
using Foundation;
using Metal;
using ObjCRuntime;

#if !NET
using NativeHandle = System.IntPtr;
#endif

#nullable enable

namespace CoreVideo {

/// <summary>A CVPixelBuffer wrapped in a Metal based buffer.</summary>
/// <remarks>This type is used to provide buffers to Metal.</remarks>
#if NET
[SupportedOSPlatform ("ios18.0")]
[SupportedOSPlatform ("maccatalyst18.0")]
[SupportedOSPlatform ("macos15.0")]
[SupportedOSPlatform ("tvos18.0")]
#else
[NoWatch, TV (18, 0), Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0)]
#endif
public class CVMetalBuffer : CVBuffer {
#if !COREBUILD
[Preserve (Conditional = true)]
internal CVMetalBuffer (NativeHandle handle, bool owns)
: base (handle, owns)
{
}

[DllImport (Constants.CoreVideoLibrary)]
extern static /* CFTypeID */ nint CVMetalBufferCacheGetTypeID ();

public static nint GetTypeId ()
{
return CVMetalBufferCacheGetTypeID ();
}

[DllImport (Constants.CoreVideoLibrary)]
extern static /* id<MTLBuffer> CV_NULLABLE */ IntPtr CVMetalBufferGetBuffer (IntPtr /* CVMetalBufferRef CV_NONNULL */ buffer);

/// <summary>Retrieve the Metal MTLBuffer for the CVMetalBuffer.</summary>
public IMTLBuffer? GetMetalBuffer ()
{
return Runtime.GetINativeObject<IMTLBuffer> (CVMetalBufferGetBuffer (GetCheckedHandle ()), owns: false);
}

#endif // !COREBUILD
}
}

#endif // !WATCH
125 changes: 125 additions & 0 deletions src/CoreVideo/CVMetalBufferCache.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#if !WATCH
using System;
using System.Runtime.InteropServices;

using CoreFoundation;
using CoreGraphics;
using Foundation;
using Metal;
using ObjCRuntime;

#if !NET
using NativeHandle = System.IntPtr;
#endif

#nullable enable

namespace CoreVideo {

/// <summary>A cache used to manage <see cref="CVMetalBuffer" /> instances.</summary>
#if NET
[SupportedOSPlatform ("ios18.0")]
[SupportedOSPlatform ("maccatalyst18.0")]
[SupportedOSPlatform ("macos15.0")]
[SupportedOSPlatform ("tvos18.0")]
#else
[NoWatch, TV (18, 0), Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0)]
#endif
public class CVMetalBufferCache : NativeObject {
#if !COREBUILD
[Preserve (Conditional = true)]
internal CVMetalBufferCache (NativeHandle handle, bool owns)
: base (handle, owns)
{
}

[DllImport (Constants.CoreVideoLibrary)]
extern static /* CFTypeID */ nint CVMetalBufferGetTypeID ();

public static nint GetTypeId ()
{
return CVMetalBufferGetTypeID ();
}

[DllImport (Constants.CoreVideoLibrary)]
unsafe extern static /* CVReturn */ CVReturn CVMetalBufferCacheCreate (
IntPtr /* CFAllocatorRef CV_NULLABLE */ allocator,
IntPtr /* CFDictionaryRef CV_NULLABLE */ cacheAttributes,
IntPtr /* id<MTLDevice> CV_NONNULL */ metalDevice,
IntPtr* /* CV_RETURNS_RETAINED_PARAMETER CVMetalBufferCacheRef CV_NULLABLE * CV_NONNULL */ cacheOut
);

static IntPtr Create (IMTLDevice device, NSDictionary? attributes)
{
IntPtr handle;
CVReturn res;
unsafe {
res = CVMetalBufferCacheCreate (IntPtr.Zero, attributes.GetHandle (), device.GetNonNullHandle (nameof (device)), &handle);
}
if (res != CVReturn.Success)
throw new Exception ($"Could not create CVMetalBufferCache, CVMetalBufferCacheCreate returned: {res}");
return handle;
}

/// <summary>Create a new <see cref="CVMetalBufferCache" /> instance.</summary>
/// <param name="device">The Metal device to create the <see cref="CVMetalBufferCache" /> instance for.</param>
/// <param name="attributes">An optional dictionary of attributes to apply to the cache.</param>
public CVMetalBufferCache (IMTLDevice device, NSDictionary? attributes)
: base (Create (device, attributes), owns: true)
{
}

/// <summary>Create a new <see cref="CVMetalBufferCache" /> instance.</summary>
/// <param name="device">The Metal device to create the <see cref="CVMetalBufferCache" /> instance for.</param>
/// <param name="attributes">Optional attributes to apply to the cache.</param>
public CVMetalBufferCache (IMTLDevice device, CVMetalBufferCacheAttributes? attributes)
: this (device, attributes?.Dictionary)
{
}

[DllImport (Constants.CoreVideoLibrary)]
unsafe extern static /* CVReturn */ CVReturn CVMetalBufferCacheCreateBufferFromImage (
IntPtr /* CFAllocatorRef CV_NULLABLE */ allocator,
IntPtr /* CVMetalBufferCacheRef CV_NONNULL */ bufferCache,
IntPtr /* CVImageBufferRef CV_NONNULL */ imageBuffer,
IntPtr* /* CV_RETURNS_RETAINED_PARAMETER CVMetalBufferRef CV_NULLABLE * CV_NONNULL */ bufferOut
);

/// <summary>Create a <see cref="CVMetalBuffer" /> for an existing <see cref="CVImageBuffer" />.</summary>
/// <param name="imageBuffer">The image buffer to create the <see cref="CVMetalBuffer" /> from.</param>
public CVMetalBuffer? CreateBufferFromImage (CVImageBuffer imageBuffer)
{
IntPtr handle;
CVReturn res;
unsafe {
res = CVMetalBufferCacheCreateBufferFromImage (IntPtr.Zero, GetCheckedHandle (), imageBuffer.GetNonNullHandle (nameof (imageBuffer)), &handle);
}
if (res != CVReturn.Success)
throw new Exception ($"Could not create CVMetalBuffer, CVMetalBufferCacheCreateBufferFromImage returned: {res}");
return Runtime.GetINativeObject<CVMetalBuffer> (handle, true);
}

[DllImport (Constants.CoreVideoLibrary)]
unsafe extern static /* CVReturn */ CVReturn CVMetalBufferCacheFlush (
IntPtr /* CVMetalBufferCacheRef CV_NONNULL */ bufferCache,
CVOptionFlags options
);

/// <summary>Perform internal housekeeping/recycling operations.</summary>
/// <remarks>This method must be called periodically.</remarks>
public void Flush ()
{
Flush (CVOptionFlags.None);
}

/// <summary>Perform internal housekeeping/recycling operations.</summary>
/// <param name="options">Any flags for the flush operation. Currently unused, always pass <see cref="CVOptionFlags.None" />.</param>
/// <remarks>This method must be called periodically.</remarks>
public void Flush (CVOptionFlags options)
{
CVMetalBufferCacheFlush (GetCheckedHandle (), options);
}
#endif // !COREBUILD
}
}
#endif // !WATCH
1 change: 1 addition & 0 deletions src/CoreVideo/CVPixelFormatDescription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ public CVFillExtendedPixelsCallBackDataStruct? FillExtendedPixelsCallbackStruct
}
}
#endif

#endif // !COREBUILD
}
}
53 changes: 53 additions & 0 deletions src/CoreVideo/CVPixelFormatType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public enum CVPixelFormatType : uint {
CV48RGB = 0x62343872,
CV32AlphaGray = 0x62333261,
CV16Gray = 0x62313667,
/// <summary>30-bit RGB, 10-bit big endian samples, 2 unused padding bits (at most significant end).</summary>
CV30RGB_r210 = 0x72323130, // 'r210'
CV422YpCbCr8 = 0x32767579,
CV4444YpCbCrA8 = 0x76343038,
CV4444YpCbCrA8R = 0x72343038,
Expand Down Expand Up @@ -122,6 +124,57 @@ public enum CVPixelFormatType : uint {
CV64Rgba_DownscaledProResRaw = 0x62703634, // 'bp64'
// iOS 14.2
CV64RgbaLE = 0x6C363472,

/* Lossless pixel formats */

/// <summary>Lossless-compressed form of <see cref="CV32BGRA" />.</summary>
Lossless_32BGRA = ('&' << 24) + ('B' << 16) + ('G' << 8) + 'A', // '&BGA'

/// <summary>Lossless-compressed form of <see cref="CV64RGBAHalf" />.</summary>
/// <remarks>No CVPlanarPixelBufferInfo struct.</remarks>
Lossless_64RGBAHalf = ('&' << 24) + ('R' << 16) + ('h' << 8) + 'A', // '&RhA'

/// <summary>Lossless-compressed form of <see cref="CV420YpCbCr8BiPlanarVideoRange" />.</summary>
/// <remarks>No CVPlanarPixelBufferInfo struct.</remarks>
Lossless_420YpCbCr8BiPlanarVideoRange = ('&' << 24) + ('8' << 16) + ('v' << 8) + '0', // '&8v0'

/// <summary>Lossless-compressed form of <see cref="CV420YpCbCr8BiPlanarFullRange" />.</summary>
/// <remarks>No CVPlanarPixelBufferInfo struct.</remarks>
Lossless_420YpCbCr8BiPlanarFullRange = ('&' << 24) + ('8' << 16) + ('f' << 8) + '0', // '&8f0'

/// <summary>Lossless-compressed form of <see cref="CV420YpCbCr10BiPlanarVideoRange" />.</summary>
/// <remarks>No CVPlanarPixelBufferInfo struct. Compressed-packed with bo padding bits between pixels.</remarks>
Lossless_420YpCbCr10PackedBiPlanarVideoRange = ('&' << 24) + ('x' << 16) + ('v' << 8) + '0', // '&xv0'

/// <summary>Lossless-compressed form of <see cref="CV422YpCbCr10BiPlanarVideoRange" />.</summary>
/// <remarks>No CVPlanarPixelBufferInfo struct. Compressed-packed with bo padding bits between pixels.</remarks>
Lossless_422YpCbCr10PackedBiPlanarVideoRange = ('&' << 24) + ('x' << 16) + ('v' << 8) + '2', // '&xv2'

/// <summary>Lossless-compressed form of <see cref="CV420YpCbCr10BiPlanarFullRange" />.</summary>
/// <remarks>No CVPlanarPixelBufferInfo struct. Compressed-packed with bo padding bits between pixels.</remarks>
Lossless_420YpCbCr10PackedBiPlanarFullRange = ('&' << 24) + ('x' << 16) + ('f' << 8) + '0', // '&xf0'

/* Lossy pixel formats */

/// <summary>Lossy-compressed form of <see cref="CV32BGRA" />.</summary>
/// <remarks>No CVPlanarPixelBufferInfo struct.</remarks>
Lossy_32BGRA = ('-' << 24) + ('B' << 16) + ('G' << 8) + 'A', // '-BGA'

/// <summary>Lossy-compressed form of <see cref="CV420YpCbCr8BiPlanarVideoRange" />.</summary>
/// <remarks>No CVPlanarPixelBufferInfo struct.</remarks>
Lossy_420YpCbCr8BiPlanarVideoRange = ('-' << 24) + ('8' << 16) + ('v' << 8) + '0', // '-8v0'

/// <summary>Lossy-compressed form of <see cref="CV420YpCbCr8BiPlanarFullRange" />.</summary>
/// <remarks>No CVPlanarPixelBufferInfo struct.</remarks>
Lossy_420YpCbCr8BiPlanarFullRange = ('-' << 24) + ('8' << 16) + ('f' << 8) + '0', // '-8f0'

/// <summary>Lossy-compressed form of <see cref="CV420YpCbCr10BiPlanarVideoRange" />.</summary>
/// <remarks>No CVPlanarPixelBufferInfo struct. Compressed-packed with bo padding bits between pixels.</remarks>
Lossy_420YpCbCr10PackedBiPlanarVideoRange = ('-' << 24) + ('x' << 16) + ('v' << 8) + '0', // '-xv0'

/// <summary>Lossy-compressed form of <see cref="CV422YpCbCr10BiPlanarVideoRange" />.</summary>
/// <remarks>No CVPlanarPixelBufferInfo struct. Compressed-packed with bo padding bits between pixels.</remarks>
Lossy_422YpCbCr10PackedBiPlanarVideoRange = ('-' << 24) + ('x' << 16) + ('v' << 8) + '2', // '-xv2'
}

#if !COREBUILD
Expand Down
32 changes: 32 additions & 0 deletions src/corevideo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,18 @@ interface CVImageBuffer : CVBuffer {
[Watch (10, 2), TV (17, 2), Mac (14, 2), iOS (17, 2), MacCatalyst (17, 2)]
[Field ("kCVImageBufferLogTransferFunction_AppleLog")]
NSString LogTransferFunctionAppleLogKey { get; }

[Watch (11, 0), TV (18, 0), Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0)]
[Field ("kCVImageBufferSceneIlluminationKey")]
NSString SceneIlluminationKey { get; }

[Mac (15, 0), NoiOS, NoTV, NoWatch, NoMacCatalyst]
[Field ("kCVImageBufferPostDecodeProcessingSequenceMetadataKey")]
NSString PostDecodeProcessingSequenceMetadataKey { get; }

[Mac (15, 0), NoiOS, NoTV, NoWatch, NoMacCatalyst]
[Field ("kCVImageBufferPostDecodeProcessingFrameMetadataKey")]
NSString PostDecodeProcessingFrameMetadataKey { get; }
}

[MacCatalyst (13, 1)]
Expand Down Expand Up @@ -571,6 +583,19 @@ public enum CVVersatileBayerPattern : uint {
Bggr = 3,
}

[NoWatch, TV (18, 0), Mac (15, 0), iOS (18, 0), MacCatalyst (18, 0)]
[Static, Internal]
interface CVMetalBufferCacheAttributeKeys {
[Field ("kCVMetalBufferCacheMaximumBufferAgeKey")]
NSString MaximumBufferAgeKey { get; }
}

[NoWatch]
[StrongDictionary ("CVMetalBufferCacheAttributeKeys")]
interface CVMetalBufferCacheAttributes {
double MaximumBufferAge { get; }
}

[Partial]
interface CVPixelFormatKeys {
[Field ("kCVPixelFormatName")]
Expand Down Expand Up @@ -661,6 +686,10 @@ interface CVPixelFormatKeys {

[Field ("kCVPixelFormatFillExtendedPixelsCallback")]
NSString FillExtendedPixelsCallback { get; }

[iOS (18, 0), Mac (15, 0), MacCatalyst (18, 0), TV (18, 0), Watch (11, 0)]
[Field ("kCVPixelFormatBitsPerComponent")]
NSString BitsPerComponent { get; }
}

[Partial]
Expand Down Expand Up @@ -767,5 +796,8 @@ interface CVPixelFormatDescription {
bool OpenGlesCompatibility { get; set; }

NSData FillExtendedPixelsCallback { get; set; }

[iOS (18, 0), Mac (15, 0), MacCatalyst (18, 0), TV (18, 0), Watch (11, 0)]
int BitsPerComponent { get; set; }
}
}
2 changes: 2 additions & 0 deletions src/frameworks.sources
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,8 @@ COREVIDEO_CORE_SOURCES = \

COREVIDEO_SOURCES = \
CoreVideo/CVDisplayLink.cs \
CoreVideo/CVMetalBuffer.cs \
CoreVideo/CVMetalBufferCache.cs \
CoreVideo/CVMetalTexture.cs \
CoreVideo/CVMetalTextureAttributes.cs \
CoreVideo/CVMetalTextureCache.cs \
Expand Down
11 changes: 11 additions & 0 deletions tests/cecil-tests/Documentation.KnownFailures.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34270,6 +34270,10 @@ M:CoreVideo.CVImageBuffer.GetCodePoint(CoreVideo.CVImageBufferYCbCrMatrix)
M:CoreVideo.CVImageBuffer.GetColorPrimariesOption(System.Int32)
M:CoreVideo.CVImageBuffer.GetTransferFunctionOption(System.Int32)
M:CoreVideo.CVImageBuffer.GetYCbCrMatrixOption(System.Int32)
M:CoreVideo.CVMetalBuffer.GetTypeId
M:CoreVideo.CVMetalBufferCache.GetTypeId
M:CoreVideo.CVMetalBufferCacheAttributes.#ctor
M:CoreVideo.CVMetalBufferCacheAttributes.#ctor(Foundation.NSDictionary)
M:CoreVideo.CVMetalTexture.GetCleanTexCoords(System.Single[]@,System.Single[]@,System.Single[]@,System.Single[]@)
M:CoreVideo.CVMetalTextureAttributes.#ctor
M:CoreVideo.CVMetalTextureAttributes.#ctor(Foundation.NSDictionary)
Expand Down Expand Up @@ -65927,9 +65931,12 @@ P:CoreVideo.CVImageBuffer.NonPropagatedAttachmentsKey
P:CoreVideo.CVImageBuffer.PixelAspectRatioHorizontalSpacingKey
P:CoreVideo.CVImageBuffer.PixelAspectRatioKey
P:CoreVideo.CVImageBuffer.PixelAspectRatioVerticalSpacingKey
P:CoreVideo.CVImageBuffer.PostDecodeProcessingFrameMetadataKey
P:CoreVideo.CVImageBuffer.PostDecodeProcessingSequenceMetadataKey
P:CoreVideo.CVImageBuffer.PreferredCleanApertureKey
P:CoreVideo.CVImageBuffer.PropagatedAttachmentsKey
P:CoreVideo.CVImageBuffer.RegionOfInterestKey
P:CoreVideo.CVImageBuffer.SceneIlluminationKey
P:CoreVideo.CVImageBuffer.TimeScaleKey
P:CoreVideo.CVImageBuffer.TimeValueKey
P:CoreVideo.CVImageBuffer.TransferFunction_ITU_R_2020
Expand All @@ -65948,6 +65955,7 @@ P:CoreVideo.CVImageBuffer.YCbCrMatrix_ITU_R_709_2
P:CoreVideo.CVImageBuffer.YCbCrMatrix_P3_D65
P:CoreVideo.CVImageBuffer.YCbCrMatrix_SMPTE_240M_1995
P:CoreVideo.CVImageBuffer.YCbCrMatrixKey
P:CoreVideo.CVMetalBufferCacheAttributes.MaximumBufferAge
P:CoreVideo.CVMetalTexture.IsFlipped
P:CoreVideo.CVMetalTexture.Texture
P:CoreVideo.CVMetalTextureAttributes.Usage
Expand Down Expand Up @@ -66021,6 +66029,7 @@ P:CoreVideo.CVPixelFormatComponentRangeKeys.FullRange
P:CoreVideo.CVPixelFormatComponentRangeKeys.VideoRange
P:CoreVideo.CVPixelFormatComponentRangeKeys.WideRange
P:CoreVideo.CVPixelFormatDescription.BitsPerBlock
P:CoreVideo.CVPixelFormatDescription.BitsPerComponent
P:CoreVideo.CVPixelFormatDescription.BlackBlock
P:CoreVideo.CVPixelFormatDescription.BlockHeight
P:CoreVideo.CVPixelFormatDescription.BlockHorizontalAlignment
Expand Down Expand Up @@ -66051,6 +66060,7 @@ P:CoreVideo.CVPixelFormatDescription.Planes
P:CoreVideo.CVPixelFormatDescription.QDCompatibility
P:CoreVideo.CVPixelFormatDescription.VerticalSubsampling
P:CoreVideo.CVPixelFormatKeys.BitsPerBlock
P:CoreVideo.CVPixelFormatKeys.BitsPerComponent
P:CoreVideo.CVPixelFormatKeys.BlackBlock
P:CoreVideo.CVPixelFormatKeys.BlockHeight
P:CoreVideo.CVPixelFormatKeys.BlockHorizontalAlignment
Expand Down Expand Up @@ -82357,6 +82367,7 @@ T:CoreVideo.CVImageBufferAlphaChannelMode
T:CoreVideo.CVImageBufferColorPrimaries
T:CoreVideo.CVImageBufferTransferFunction
T:CoreVideo.CVImageBufferYCbCrMatrix
T:CoreVideo.CVMetalBufferCacheAttributes
T:CoreVideo.CVMetalTexture
T:CoreVideo.CVMetalTextureAttributes
T:CoreVideo.CVPixelBufferAttributes
Expand Down
2 changes: 2 additions & 0 deletions tests/introspection/ApiCMAttachmentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ protected virtual bool Skip (string nativeName)
case "CVBuffer": // DOES support the API, but it has its own version and is already in the bindings, so no need ATM
case "CVImageBuffer": // same as CVBuffer
case "CVPixelBuffer": // same as CVBuffer
case "CVMetalBuffer": // same as CVBuffer
case "CVMetalBufferCache": // same as CVBuffer
case "MTAudioProcessingTap":
case "Protocol":
case "MidiObject": // causes crash
Expand Down
Loading

3 comments on commit ad1a3b7

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