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

[CoreVideo] Add support for Xcode13 beta 1. #11997

Merged
merged 6 commits into from
Jun 23, 2021
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
2 changes: 2 additions & 0 deletions src/CoreVideo/CVBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
using ObjCRuntime;
using Foundation;

#nullable enable

namespace CoreVideo {

// CVBuffer.h
Expand Down
2 changes: 2 additions & 0 deletions src/CoreVideo/CVDisplayLink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
using Foundation;
using OpenGL;

#nullable enable

namespace CoreVideo {
public class CVDisplayLink : INativeObject, IDisposable {
IntPtr handle;
Expand Down
2 changes: 2 additions & 0 deletions src/CoreVideo/CVEnums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
using Foundation;
using ObjCRuntime;

#nullable enable

namespace CoreVideo {

// uint32_t -> CVBuffer.h
Expand Down
14 changes: 8 additions & 6 deletions src/CoreVideo/CVImageBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
using Foundation;
using CoreGraphics;

#nullable enable

namespace CoreVideo {

// CVImageBuffer.h
Expand Down Expand Up @@ -93,7 +95,7 @@ public bool IsFlipped {

[Deprecated (PlatformName.MacOSX, 10, 4)]
[Unavailable (PlatformName.iOS)]
public CGColorSpace ColorSpace {
public CGColorSpace? ColorSpace {
get {
var h = CVImageBufferGetColorSpace (handle);
return h == IntPtr.Zero ? null : new CGColorSpace (h);
Expand All @@ -105,7 +107,7 @@ public CGColorSpace ColorSpace {
#if IOS
[Obsolete ("This API is not available on this platform.")]
#endif
public CGColorSpace ColorSpace {
public CGColorSpace? ColorSpace {
get {
return null;
}
Expand All @@ -116,7 +118,7 @@ public CGColorSpace ColorSpace {
[DllImport (Constants.CoreVideoLibrary)]
extern static /* CGColorSpaceRef */ IntPtr CVImageBufferCreateColorSpaceFromAttachments (/* CFDictionaryRef */ IntPtr attachments);

public static CGColorSpace CreateFrom (NSDictionary attachments)
public static CGColorSpace? CreateFrom (NSDictionary attachments)
{
if (attachments == null)
throw new ArgumentNullException ("attachments");
Expand All @@ -132,7 +134,7 @@ public static CGColorSpace CreateFrom (NSDictionary attachments)
[iOS (11, 0), Mac (10, 13), TV (11, 0)]
public static int GetCodePoint (CVImageBufferYCbCrMatrix yCbCrMatrix)
{
return CVYCbCrMatrixGetIntegerCodePointForString (yCbCrMatrix.GetConstant ().Handle);
return CVYCbCrMatrixGetIntegerCodePointForString (yCbCrMatrix.GetConstant ()!.Handle);
}

[DllImport (Constants.CoreVideoLibrary)]
Expand All @@ -142,7 +144,7 @@ public static int GetCodePoint (CVImageBufferYCbCrMatrix yCbCrMatrix)
[iOS (11, 0), Mac (10, 13), TV (11, 0)]
public static int GetCodePoint (CVImageBufferColorPrimaries color)
{
return CVColorPrimariesGetIntegerCodePointForString (color.GetConstant ().Handle);
return CVColorPrimariesGetIntegerCodePointForString (color.GetConstant ()!.Handle);
}

[DllImport (Constants.CoreVideoLibrary)]
Expand All @@ -152,7 +154,7 @@ public static int GetCodePoint (CVImageBufferColorPrimaries color)
[iOS (11, 0), Mac (10, 13), TV (11, 0)]
public static int GetCodePoint (CVImageBufferTransferFunction function)
{
return CVTransferFunctionGetIntegerCodePointForString (function.GetConstant ().Handle);
return CVTransferFunctionGetIntegerCodePointForString (function.GetConstant ()!.Handle);
}

[DllImport (Constants.CoreVideoLibrary)]
Expand Down
2 changes: 2 additions & 0 deletions src/CoreVideo/CVMetalTexture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
using Foundation;
using Metal;

#nullable enable

namespace CoreVideo {

[iOS (8,0)]
Expand Down
2 changes: 2 additions & 0 deletions src/CoreVideo/CVMetalTextureAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
using Foundation;
using Metal;

#nullable enable

namespace CoreVideo {
public partial class CVMetalTextureAttributes : DictionaryContainer {

Expand Down
10 changes: 6 additions & 4 deletions src/CoreVideo/CVMetalTextureCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
using Foundation;
using Metal;

#nullable enable

namespace CoreVideo {

[iOS (8,0)]
Expand Down Expand Up @@ -74,7 +76,7 @@ public CVMetalTextureCache (IMTLDevice metalDevice)
throw new Exception ("Could not create the texture cache");
}

public static CVMetalTextureCache FromDevice (IMTLDevice metalDevice)
public static CVMetalTextureCache? FromDevice (IMTLDevice metalDevice)
{
if (metalDevice == null)
throw new ArgumentNullException ("metalDevice");
Expand Down Expand Up @@ -104,7 +106,7 @@ public CVMetalTextureCache (IMTLDevice metalDevice, CVMetalTextureAttributes tex
throw new Exception ($"Could not create the texture cache, Reason: {err}.");
}

public static CVMetalTextureCache FromDevice (IMTLDevice metalDevice, CVMetalTextureAttributes textureAttributes, out CVReturn creationErr)
public static CVMetalTextureCache? FromDevice (IMTLDevice metalDevice, CVMetalTextureAttributes textureAttributes, out CVReturn creationErr)
{
if (metalDevice == null)
throw new ArgumentNullException (nameof (metalDevice));
Expand All @@ -119,13 +121,13 @@ public static CVMetalTextureCache FromDevice (IMTLDevice metalDevice, CVMetalTex
return null;
}

public static CVMetalTextureCache FromDevice (IMTLDevice metalDevice, CVMetalTextureAttributes textureAttributes)
public static CVMetalTextureCache? FromDevice (IMTLDevice metalDevice, CVMetalTextureAttributes textureAttributes)
{
CVReturn creationErr;
return FromDevice (metalDevice, textureAttributes, out creationErr);
}

public CVMetalTexture TextureFromImage (CVImageBuffer imageBuffer, MTLPixelFormat format, nint width, nint height, nint planeIndex, out CVReturn errorCode)
public CVMetalTexture? TextureFromImage (CVImageBuffer imageBuffer, MTLPixelFormat format, nint width, nint height, nint planeIndex, out CVReturn errorCode)
{
if (imageBuffer == null)
throw new ArgumentNullException ("imageBuffer");
Expand Down
2 changes: 2 additions & 0 deletions src/CoreVideo/CVOpenGLESTexture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
using Foundation;
using OpenGLES;

#nullable enable

namespace CoreVideo {

// CVOpenGLESTexture.h
Expand Down
2 changes: 2 additions & 0 deletions src/CoreVideo/CVOpenGLESTextureCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
using Foundation;
using OpenGLES;

#nullable enable

namespace CoreVideo {

// CVOpenGLESTextureCache.h
Expand Down
50 changes: 41 additions & 9 deletions src/CoreVideo/CVPixelBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
using CoreFoundation;
using ObjCRuntime;
using Foundation;
#if NET
using System.Runtime.Versioning;
#endif

using CFDictionaryRef=System.IntPtr;
using CVPixelBufferRef=System.IntPtr;

#nullable enable

namespace CoreVideo {

Expand Down Expand Up @@ -38,17 +46,17 @@ extern static CVReturn CVPixelBufferCreate (
/* CVPixelBufferRef __nullable * __nonnull */ out IntPtr pixelBufferOut);

public CVPixelBuffer (nint width, nint height, CVPixelFormatType pixelFormat)
: this (width, height, pixelFormat, (NSDictionary) null)
: this (width, height, pixelFormat, (NSDictionary?) null)
{
}

public CVPixelBuffer (nint width, nint height, CVPixelFormatType pixelFormatType, CVPixelBufferAttributes attributes)
public CVPixelBuffer (nint width, nint height, CVPixelFormatType pixelFormatType, CVPixelBufferAttributes? attributes)
: this (width, height, pixelFormatType, attributes == null ? null : attributes.Dictionary)
{
}

[Advice ("Use constructor with CVPixelBufferAttributes")]
CVPixelBuffer (nint width, nint height, CVPixelFormatType pixelFormatType, NSDictionary pixelBufferAttributes)
CVPixelBuffer (nint width, nint height, CVPixelFormatType pixelFormatType, NSDictionary? pixelBufferAttributes)
{
if (width <= 0)
throw new ArgumentOutOfRangeException ("width");
Expand Down Expand Up @@ -84,6 +92,30 @@ public NSDictionary GetAttributes (NSDictionary [] attributes)
throw new ArgumentException (ret.ToString ());
return Runtime.GetNSObject<NSDictionary> (resolvedDictionaryOut);
}

#if NET
[SupportedOSPlatform ("ios15.0")]
[SupportedOSPlatform ("tvos15.0")]
[SupportedOSPlatform ("macos12.0")]
[UnsupportedOSPlatform ("maccatalyst")]
#else
[Watch (8,0), TV (15,0), Mac (12,0), iOS (15,0), NoMacCatalyst]
#endif
[DllImport (Constants.CoreVideoLibrary)]
static extern CFDictionaryRef CVPixelBufferCopyCreationAttributes (CVPixelBufferRef pixelBuffer);

#if NET
[SupportedOSPlatform ("ios15.0")]
[SupportedOSPlatform ("tvos15.0")]
[SupportedOSPlatform ("macos12.0")]
[UnsupportedOSPlatform ("maccatalyst")]
#else
[Watch (8,0), TV (15,0), Mac (12,0), iOS (15,0), NoMacCatalyst]
#endif
public CVPixelBufferAttributes? GetPixelBufferCreationAttributes () {
var attrs = CVPixelBufferCopyCreationAttributes (handle);
return (attrs == IntPtr.Zero) ? null : new CVPixelBufferAttributes (new NSDictionary (attrs));
}
#endif

/* CVPixelBufferCreateWithBytes */
Expand Down Expand Up @@ -114,13 +146,13 @@ static extern CVReturn CVPixelBufferCreateWithBytes (
/* CFDictionaryRef CV_NULLABLE */ IntPtr pixelBufferAttributes,
/* CV_RETURNS_RETAINED_PARAMETER CVPixelBufferRef CV_NULLABLE * CV_NONNULL */ out IntPtr pixelBufferOut);// __OSX_AVAILABLE_STARTING(__MAC_10_4,__IPHONE_4_0);

public static CVPixelBuffer Create (nint width, nint height, CVPixelFormatType pixelFormatType, byte[] data, nint bytesPerRow, CVPixelBufferAttributes pixelBufferAttributes)
public static CVPixelBuffer? Create (nint width, nint height, CVPixelFormatType pixelFormatType, byte[] data, nint bytesPerRow, CVPixelBufferAttributes pixelBufferAttributes)
{
CVReturn status;
return Create (width, height, pixelFormatType, data, bytesPerRow, pixelBufferAttributes, out status);
}

public static CVPixelBuffer Create (nint width, nint height, CVPixelFormatType pixelFormatType, byte[] data, nint bytesPerRow, CVPixelBufferAttributes pixelBufferAttributes, out CVReturn status)
public static CVPixelBuffer? Create (nint width, nint height, CVPixelFormatType pixelFormatType, byte[] data, nint bytesPerRow, CVPixelBufferAttributes pixelBufferAttributes, out CVReturn status)
{
IntPtr handle;
GCHandle gchandle;
Expand All @@ -147,7 +179,7 @@ public static CVPixelBuffer Create (nint width, nint height, CVPixelFormatType p

class PlaneData
{
public GCHandle[] dataHandles;
public GCHandle[] dataHandles = Array.Empty<GCHandle> ();
}

delegate void CVPixelBufferReleasePlanarBytesCallback (
Expand All @@ -163,7 +195,7 @@ delegate void CVPixelBufferReleasePlanarBytesCallback (
static void ReleasePlanarBytesCallback (IntPtr releaseRefCon, IntPtr dataPtr, nint dataSize, nint numberOfPlanes, IntPtr planeAddresses)
{
GCHandle handle = GCHandle.FromIntPtr (releaseRefCon);
PlaneData data = (PlaneData) handle.Target;
PlaneData data = (PlaneData) handle.Target!;
for (int i = 0; i < data.dataHandles.Length; i++)
data.dataHandles[i].Free ();
handle.Free ();
Expand All @@ -187,13 +219,13 @@ static extern CVReturn CVPixelBufferCreateWithPlanarBytes (
/* CFDictionaryRef CV_NULLABLE */ IntPtr pixelBufferAttributes,
/* CV_RETURNS_RETAINED_PARAMETER CVPixelBufferRef CV_NULLABLE * CV_NONNULL */ out IntPtr pixelBufferOut); // __OSX_AVAILABLE_STARTING(__MAC_10_4,__IPHONE_4_0);

public static CVPixelBuffer Create (nint width, nint height, CVPixelFormatType pixelFormatType, byte[][] planes, nint[] planeWidths, nint[] planeHeights, nint[] planeBytesPerRow, CVPixelBufferAttributes pixelBufferAttributes)
public static CVPixelBuffer? Create (nint width, nint height, CVPixelFormatType pixelFormatType, byte[][] planes, nint[] planeWidths, nint[] planeHeights, nint[] planeBytesPerRow, CVPixelBufferAttributes pixelBufferAttributes)
{
CVReturn status;
return Create (width, height, pixelFormatType, planes, planeWidths, planeHeights, planeBytesPerRow, pixelBufferAttributes, out status);
}

public static CVPixelBuffer Create (nint width, nint height, CVPixelFormatType pixelFormatType, byte[][] planes, nint[] planeWidths, nint[] planeHeights, nint[] planeBytesPerRow, CVPixelBufferAttributes pixelBufferAttributes, out CVReturn status)
public static CVPixelBuffer? Create (nint width, nint height, CVPixelFormatType pixelFormatType, byte[][] planes, nint[] planeWidths, nint[] planeHeights, nint[] planeBytesPerRow, CVPixelBufferAttributes pixelBufferAttributes, out CVReturn status)
{
IntPtr handle;
IntPtr[] addresses;
Expand Down
4 changes: 3 additions & 1 deletion src/CoreVideo/CVPixelBufferAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
using CoreFoundation;
using ObjCRuntime;

#nullable enable

namespace CoreVideo {

[Watch (4,0)]
Expand Down Expand Up @@ -63,7 +65,7 @@ public CVPixelFormatType? PixelFormatType {
}
}

public CFAllocator MemoryAllocator {
public CFAllocator? MemoryAllocator {
get {
return GetNativeValue<CFAllocator> (CVPixelBuffer.MemoryAllocatorKey);
}
Expand Down
8 changes: 5 additions & 3 deletions src/CoreVideo/CVPixelBufferIOSurface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
using Foundation;
using ObjCRuntime;

#nullable enable

namespace CoreVideo {
public partial class CVPixelBuffer : CVImageBuffer {

Expand All @@ -23,7 +25,7 @@ public partial class CVPixelBuffer : CVImageBuffer {
);

[iOS (11,0), Mac (10,13), TV (11,0), NoWatch]
public IOSurface.IOSurface GetIOSurface ()
public IOSurface.IOSurface? GetIOSurface ()
{
if (Handle == IntPtr.Zero)
throw new ObjectDisposedException ("CVPixelBuffer");
Expand All @@ -45,7 +47,7 @@ public IOSurface.IOSurface GetIOSurface ()
);

[iOS (11,0), Mac (10,13), TV (11,0), NoWatch]
public static CVPixelBuffer Create (IOSurface.IOSurface surface, out CVReturn result, CVPixelBufferAttributes pixelBufferAttributes = null)
public static CVPixelBuffer? Create (IOSurface.IOSurface surface, out CVReturn result, CVPixelBufferAttributes? pixelBufferAttributes = null)
{
if (surface == null)
throw new ArgumentNullException (nameof (surface));
Expand All @@ -65,7 +67,7 @@ public static CVPixelBuffer Create (IOSurface.IOSurface surface, out CVReturn re
}

[iOS (11,0), Mac (10,13), TV (11,0), NoWatch]
public static CVPixelBuffer Create (IOSurface.IOSurface surface, CVPixelBufferAttributes pixelBufferAttributes = null)
public static CVPixelBuffer? Create (IOSurface.IOSurface surface, CVPixelBufferAttributes? pixelBufferAttributes = null)
{
CVReturn result;
return Create (surface, out result, pixelBufferAttributes);
Expand Down
8 changes: 5 additions & 3 deletions src/CoreVideo/CVPixelBufferPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
using ObjCRuntime;
using Foundation;

#nullable enable

namespace CoreVideo {

// CVPixelBufferPool.h
Expand Down Expand Up @@ -101,7 +103,7 @@ public NSDictionary Attributes {
}
}

public CVPixelBufferPoolSettings Settings {
public CVPixelBufferPoolSettings? Settings {
get {
var attr = Attributes;
return attr == null ? null : new CVPixelBufferPoolSettings (attr);
Expand Down Expand Up @@ -132,7 +134,7 @@ extern static CVReturn CVPixelBufferPoolCreatePixelBufferWithAuxAttributes (
/* CFDictionaryRef __nullable */ IntPtr auxAttributes,
/* CVPixelBufferRef __nullable * __nonnull */ out IntPtr pixelBufferOut);

public CVPixelBuffer CreatePixelBuffer (CVPixelBufferPoolAllocationSettings allocationSettings, out CVReturn error)
public CVPixelBuffer? CreatePixelBuffer (CVPixelBufferPoolAllocationSettings allocationSettings, out CVReturn error)
{
IntPtr pb;
error = CVPixelBufferPoolCreatePixelBufferWithAuxAttributes (IntPtr.Zero, handle, allocationSettings.GetHandle (), out pb);
Expand All @@ -159,7 +161,7 @@ public CVPixelBufferPool (NSDictionary poolAttributes, NSDictionary pixelBufferA
}

public CVPixelBufferPool (CVPixelBufferPoolSettings settings, CVPixelBufferAttributes pixelBufferAttributes)
: this (settings.GetDictionary (), pixelBufferAttributes.GetDictionary ())
: this (settings.GetDictionary ()!, pixelBufferAttributes.GetDictionary ()!)
{
}

Expand Down
2 changes: 2 additions & 0 deletions src/CoreVideo/CVPixelBufferPoolSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
using CoreFoundation;
using ObjCRuntime;

#nullable enable

namespace CoreVideo {

[Watch (4,0)]
Expand Down
2 changes: 2 additions & 0 deletions src/CoreVideo/CVPixelFormatDescription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
using ObjCRuntime;
using Foundation;

#nullable enable

namespace CoreVideo {

[Watch (4,0)]
Expand Down
Loading