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 Xcode 13 beta3. #12257

Merged
merged 36 commits into from
Sep 13, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
da24cab
[HealthKit] Add support for xcode13 beta3.
mandel-macaque Jul 22, 2021
7d79213
Address reviews.
mandel-macaque Jul 23, 2021
7b35179
Merge branch 'main' into healthkit-xcode13-beta3
mandel-macaque Jul 26, 2021
915f8e6
Add missing selector for WatchOS 8.
mandel-macaque Jul 26, 2021
2b32222
[CoreVideo] Add support for Xcode13 beta 3.
mandel-macaque Jul 27, 2021
03026b5
[CoreVideo] Add support for Xcode13 beta 3
mandel-macaque Jul 27, 2021
dcbbdf3
Remove method from watchos.
mandel-macaque Jul 27, 2021
ecb3a76
Address reviews.
mandel-macaque Jul 27, 2021
b1e0ec9
Address reviews.
mandel-macaque Jul 27, 2021
c33bb04
Add overload to return the error.
mandel-macaque Jul 27, 2021
21b7238
Apply suggestions from code review
mandel-macaque Jul 28, 2021
43657fc
Revert "Remove method from watchos."
mandel-macaque Jul 28, 2021
127806e
Fix intro on sim.
mandel-macaque Jul 28, 2021
ba74e6f
Address reviews and fix compilation.
mandel-macaque Jul 28, 2021
76d8cc2
Merge branch 'main' into corevideo-xcode13-beta3
mandel-macaque Jul 29, 2021
2aba632
Fix comments from review, update for beta 4.
mandel-macaque Jul 29, 2021
3da2cc7
Merge branch 'main' into corevideo-xcode13-beta3
mandel-macaque Jul 29, 2021
1b6f927
Update src/CoreVideo/CVDisplayLink.cs
mandel-macaque Jul 29, 2021
02ec533
Update version else we have issues with the old codee.
mandel-macaque Jul 29, 2021
a94f580
Merge branch 'main' into corevideo-xcode13-beta3
mandel-macaque Aug 10, 2021
733cc93
Merge branch 'corevideo-xcode13-beta3' of github.com:mandel-macaque/x…
mandel-macaque Aug 10, 2021
35503c8
Merge branch 'main' into corevideo-xcode13-beta3
mandel-macaque Aug 18, 2021
f091491
Merge branch 'main' into corevideo-xcode13-beta3
mandel-macaque Aug 18, 2021
7cd7f9e
Update for beta 5.
mandel-macaque Aug 18, 2021
23e6096
Merge branch 'corevideo-xcode13-beta3' of github.com:mandel-macaque/x…
mandel-macaque Aug 18, 2021
43a87fc
Fix mac intro.
mandel-macaque Aug 18, 2021
be1614e
Merge branch 'corevideo-xcode13-beta3' of github.com:mandel-macaque/x…
mandel-macaque Aug 31, 2021
1da2f02
Merge branch 'main' into corevideo-xcode13-beta3
mandel-macaque Aug 31, 2021
94d8143
Address reviews and add tests for manual code.
mandel-macaque Sep 1, 2021
b141a30
Fix api and testt.
mandel-macaque Sep 1, 2021
050f6f0
Merge branch 'main' into corevideo-xcode13-beta3
mandel-macaque Sep 1, 2021
5c17e7d
Merge branch 'main' into corevideo-xcode13-beta3
mandel-macaque Sep 2, 2021
e522eb4
Fix issue with the catalyst intro tests.
mandel-macaque Sep 8, 2021
ac7a987
Apply suggestions from code review
mandel-macaque Sep 8, 2021
d44a025
Merge branch 'main' into corevideo-xcode13-beta3
mandel-macaque Sep 9, 2021
3949601
Merge branch 'main' into corevideo-xcode13-beta3
mandel-macaque Sep 10, 2021
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
37 changes: 36 additions & 1 deletion src/CoreVideo/CVBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,32 +115,67 @@ public void RemoveAttachment (NSString key)
CVBufferRemoveAttachment (handle, key.Handle);
}

[Deprecated (PlatformName.MacOSX, 12, 0)]
[Deprecated (PlatformName.iOS, 15, 0)]
[Deprecated (PlatformName.TvOS, 15, 0)]
[Deprecated (PlatformName.WatchOS, 8, 0)]
[DllImport (Constants.CoreVideoLibrary)]
extern static /* CFTypeRef */ IntPtr CVBufferGetAttachment (/* CVBufferRef */ IntPtr buffer, /* CFStringRef */ IntPtr key, out CVAttachmentMode attachmentMode);

// The new method is the same as the old one but changing the ownership from Get to Copy, so we will use the new version if possible since the
// older method has been deprecatd.
[Watch (8,0), TV (15,0), Mac (12,0), iOS (15,0)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mac Catalyst?

[DllImport (Constants.CoreVideoLibrary)]
extern static /* CFTypeRef */ IntPtr CVBufferCopyAttachment (/* CVBufferRef */ IntPtr buffer, /* CFStringRef */ IntPtr key, out CVAttachmentMode attachmentMode);

// FIXME: we need to bring the new API to xamcore
#if !MONOMAC
// any CF object can be attached
public T GetAttachment<T> (NSString key, out CVAttachmentMode attachmentMode) where T : class, INativeObject
{
if (key == null)
throw new ArgumentNullException ("key");
#if IOS || __MACCATALYST__ || TVOS
if (UIKit.UIDevice.CurrentDevice.CheckSystemVersion (15, 0))
#elif WATCH
if (WatchKit.WKInterfaceDevice.CurrentDevice.CheckSystemVersion (8, 0))
#endif
return Runtime.GetINativeObject<T> (CVBufferCopyAttachment (handle, key.Handle, out attachmentMode), true);
return Runtime.GetINativeObject<T> (CVBufferGetAttachment (handle, key.Handle, out attachmentMode), false);
}
#else
public NSObject GetAttachment (NSString key, out CVAttachmentMode attachmentMode)
{
if (key == null)
throw new ArgumentNullException ("key");
return Runtime.GetNSObject (CVBufferGetAttachment (handle, key.Handle, out attachmentMode));
if (PlatformHelper.CheckSystemVersion (12, 0))
return Runtime.GetNSObject (CVBufferCopyAttachment (handle, key.Handle, out attachmentMode));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing argument for ownership

Copy link
Member Author

@mandel-macaque mandel-macaque Jul 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API without the <T> does not have the argument: https://docs.microsoft.com/en-us/dotnet/api/objcruntime.runtime.getnsobject?view=xamarin-ios-sdk-12#ObjCRuntime_Runtime_GetNSObject_System_IntPtr_ Which is the one being used, should I switch to the version?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, the generic version is newer/better
the alternative would be to explicitly call memory managed methods... which is less desirable

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still needs to be fixed

else
return Runtime.GetNSObject (CVBufferGetAttachment (handle, key.Handle, out attachmentMode));
}
#endif

[Deprecated (PlatformName.MacOSX, 12, 0)]
[Deprecated (PlatformName.iOS, 15, 0)]
[Deprecated (PlatformName.TvOS, 15, 0)]
[Deprecated (PlatformName.WatchOS, 8, 0)]
rolfbjarne marked this conversation as resolved.
Show resolved Hide resolved
[DllImport (Constants.CoreVideoLibrary)]
extern static /* CFDictionaryRef */ IntPtr CVBufferGetAttachments (/* CVBufferRef */ IntPtr buffer, CVAttachmentMode attachmentMode);

[Watch (8,0), TV (15,0), Mac (12,0), iOS (15,0)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mac Catalyst?

[DllImport (Constants.CoreVideoLibrary)]
extern static /* CFDictionaryRef */ IntPtr CVBufferCopyAttachments (/* CVBufferRef */ IntPtr buffer, CVAttachmentMode attachmentMode);

public NSDictionary GetAttachments (CVAttachmentMode attachmentMode)
{
#if IOS || __MACCATALYST__ || TVOS
if (UIKit.UIDevice.CurrentDevice.CheckSystemVersion (15, 0))
#elif WATCH
if (WatchKit.WKInterfaceDevice.CurrentDevice.CheckSystemVersion (8, 0))
#elif MONOMAC
if (PlatformHelper.CheckSystemVersion (12, 0))
#endif
return (NSDictionary) Runtime.GetNSObject (CVBufferCopyAttachments (handle, attachmentMode));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same, you're not specifying the ownership (using the default)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same :)

return (NSDictionary) Runtime.GetNSObject (CVBufferGetAttachments (handle, attachmentMode));
}

Expand Down
73 changes: 72 additions & 1 deletion src/CoreVideo/CVDisplayLink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,54 @@ internal CVDisplayLink (IntPtr handle, bool owns)
this.handle = handle;
}

[Mac (12,0)]
[DllImport (Constants.CoreVideoLibrary)]
static extern int CVDisplayLinkCreateWithCGDisplay (uint displayId, out IntPtr displayLink);

[Mac (12,0)]
public static CVDisplayLink FromDisplayId (uint displayId)
{
var result = CVDisplayLinkCreateWithCGDisplay (displayId, out IntPtr handle);
if (result != 0)
throw new Exception ($"Could not create display link for display {displayId}.");
spouliot marked this conversation as resolved.
Show resolved Hide resolved

return new CVDisplayLink (handle, true);
}

[Mac (12,0)]
[DllImport (Constants.CoreVideoLibrary)]
unsafe static extern int CVDisplayLinkCreateWithCGDisplays (uint* displayArray, nint count, out IntPtr displayLink);

[Mac (12,0)]
public static CVDisplayLink FromDisplayIds (uint[] displayIds)
{
int result = 0;
IntPtr handle = IntPtr.Zero;
unsafe {
fixed (uint *displaysHandle = displayIds) {
result = CVDisplayLinkCreateWithCGDisplays (displaysHandle, displayIds.Length, out handle);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NullReferenceException if displayIds is null - which is not validated

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why #nullable enable did not report an error...

}
}

if (result != 0)
throw new Exception ("Could not create display link for the given displays.");
spouliot marked this conversation as resolved.
Show resolved Hide resolved

return new CVDisplayLink (handle, true);
}

[Mac (12,0)]
[DllImport (Constants.CoreVideoLibrary)]
static extern int CVDisplayLinkCreateWithOpenGLDisplayMask (uint mask, out IntPtr displayLinkOut);

[Mac (12,0)]
public static CVDisplayLink FromOpenGLMask (uint mask)
mandel-macaque marked this conversation as resolved.
Show resolved Hide resolved
{
var result = CVDisplayLinkCreateWithOpenGLDisplayMask (mask, out IntPtr handle);
if (result != 0)
throw new Exception ($"Could not create display link for the given mask '{mask}'.");
spouliot marked this conversation as resolved.
Show resolved Hide resolved
return new CVDisplayLink (handle, true);
}

~CVDisplayLink ()
{
Dispose (false);
Expand Down Expand Up @@ -192,20 +240,43 @@ public CVReturn GetCurrentTime (out CVTimeStamp outTime)
static CVReturn OutputCallback (IntPtr displayLink, ref CVTimeStamp inNow, ref CVTimeStamp inOutputTime, CVOptionFlags flagsIn, ref CVOptionFlags flagsOut, IntPtr displayLinkContext)
{
GCHandle callbackHandle = GCHandle.FromIntPtr (displayLinkContext);
DisplayLinkOutputCallback func = (DisplayLinkOutputCallback) callbackHandle.Target;
DisplayLinkOutputCallback func = (DisplayLinkOutputCallback) callbackHandle.Target!;
CVDisplayLink delegateDisplayLink = new CVDisplayLink(displayLink, false);
return func (delegateDisplayLink, ref inNow, ref inOutputTime, flagsIn, ref flagsOut);
}

[DllImport (Constants.CoreVideoLibrary)]
extern static CVReturn CVDisplayLinkSetOutputCallback (IntPtr displayLink, CVDisplayLinkOutputCallback function, IntPtr userInfo);

mandel-macaque marked this conversation as resolved.
Show resolved Hide resolved
public CVReturn SetOutputCallback (DisplayLinkOutputCallback callback)
{
callbackHandle = GCHandle.Alloc (callback);
CVReturn ret = CVDisplayLinkSetOutputCallback (this.Handle, static_OutputCallback, GCHandle.ToIntPtr (callbackHandle));

return ret;
}

[Mac (12,0), NoiOS, NoTV]
[DllImport (Constants.CoreVideoLibrary)]
static extern nuint CVDisplayLinkGetTypeID ();

[Mac (12,0), NoiOS, NoTV]
public static nuint GetTypeId ()
=> CVDisplayLinkGetTypeID ();

[Mac (12,0), NoiOS, NoTV]
[DllImport (Constants.CoreVideoLibrary)]
static extern int CVDisplayLinkTranslateTime (IntPtr displayLink, CVTimeStamp inTime, out CVTimeStamp outTime);

[Mac (12,0), NoiOS, NoTV]
public bool TryTranslateTime (CVTimeStamp inTime, out CVTimeStamp? outTime)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{
outTime = null;
if (CVDisplayLinkTranslateTime (this.Handle, inTime, out var translated) == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation says this:

outTime
A pointer to a CVTimeStamp structure into which the target time is written. Before calling, you must set the version field (currently 0) to indicate which version of the structure you want. You should also set the flags field to specify which representations to translate to.

You're passing in null, which is not what the API calls for. It looks from the documentation that this should be a ref parameter and not an out parameter, and outTime.Version should be 0.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, I'll update it, thx!

outTime = translated;
}
return outTime != null;
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/CoreVideo/CVMetalTexture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//
//

#if IOS || TVOS
#if !__WATCHOS__

using System;
using System.Runtime.InteropServices;
Expand All @@ -22,7 +22,7 @@

namespace CoreVideo {

[iOS (8,0)]
[iOS (8,0), Mac (12,0)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mac Catalyst?

public class CVMetalTexture : INativeObject, IDisposable {

internal IntPtr handle;
Expand Down Expand Up @@ -97,5 +97,5 @@ public void GetCleanTexCoords (out float [] lowerLeft, out float [] lowerRight,
}
}

#endif // IOS || TVOS
#endif // ! __WATCHOS__

6 changes: 3 additions & 3 deletions src/CoreVideo/CVMetalTextureCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//
//

#if IOS || TVOS
#if !__WATCHOS__

using System;
using System.Runtime.InteropServices;
Expand All @@ -21,7 +21,7 @@

namespace CoreVideo {

[iOS (8,0)]
[iOS (8,0), Mac (12,0)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mac Catalyst?

public partial class CVMetalTextureCache : INativeObject, IDisposable {
internal IntPtr handle;

Expand Down Expand Up @@ -171,4 +171,4 @@ extern static CVReturn CVMetalTextureCacheCreateTextureFromImage (
}
}

#endif // IOS || TVOS
#endif // __WATCHOS__
2 changes: 1 addition & 1 deletion src/corevideo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ interface CVPixelBufferPool : CVImageBuffer {
[NoWatch]
[Partial]
interface CVMetalTextureCache {
[NoMac]
[Mac (12,0)]
[Internal]
[Field ("kCVMetalTextureCacheMaximumTextureAgeKey")]
IntPtr MaxTextureAge { get; }
Expand Down
2 changes: 0 additions & 2 deletions tests/xtro-sharpie/MacCatalyst-CoreVideo.todo

This file was deleted.

4 changes: 0 additions & 4 deletions tests/xtro-sharpie/iOS-CoreVideo.todo

This file was deleted.

29 changes: 8 additions & 21 deletions tests/xtro-sharpie/macOS-CoreVideo.ignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
## deprecated in favor of metal
# opengl was deprecated
!missing-field! kCVOpenGLBufferHeight not bound
!missing-field! kCVOpenGLBufferInternalFormat not bound
!missing-field! kCVOpenGLBufferMaximumMipmapLevel not bound
!missing-field! kCVOpenGLBufferTarget not bound
!missing-field! kCVOpenGLBufferWidth not bound
!missing-field! kCVOpenGLBufferPoolMaximumBufferAgeKey not bound
!missing-field! kCVOpenGLBufferPoolMinimumBufferCountKey not bound
!missing-field! kCVOpenGLBufferTarget not bound
!missing-field! kCVOpenGLBufferWidth not bound
!missing-field! kCVOpenGLTextureCacheChromaSamplingModeAutomatic not bound
!missing-field! kCVOpenGLTextureCacheChromaSamplingModeBestPerformance not bound
!missing-field! kCVOpenGLTextureCacheChromaSamplingModeHighestQuality not bound
!missing-field! kCVOpenGLTextureCacheChromaSamplingModeKey not bound
!missing-field! kCVPixelBufferIOSurfaceOpenGLFBOCompatibilityKey not bound
!missing-field! kCVPixelBufferIOSurfaceOpenGLTextureCompatibilityKey not bound
!missing-pinvoke! CVOpenGLBufferAttach is not bound
!missing-pinvoke! CVOpenGLBufferCreate is not bound
!missing-pinvoke! CVOpenGLBufferGetAttributes is not bound
Expand Down Expand Up @@ -37,24 +39,9 @@
!missing-pinvoke! CVOpenGLTextureRelease is not bound
!missing-pinvoke! CVOpenGLTextureRetain is not bound

## unsorted

# deprecated
!missing-field! kCVImageBufferTransferFunction_EBU_3213 not bound
!missing-field! kCVImageBufferTransferFunction_SMPTE_C not bound
!missing-field! kCVMetalTextureCacheMaximumTextureAgeKey not bound
!missing-field! kCVPixelBufferIOSurfaceOpenGLFBOCompatibilityKey not bound
!missing-field! kCVPixelBufferIOSurfaceOpenGLTextureCompatibilityKey not bound
!missing-pinvoke! CVDisplayLinkCreateWithCGDisplay is not bound
!missing-pinvoke! CVDisplayLinkCreateWithCGDisplays is not bound
!missing-pinvoke! CVDisplayLinkCreateWithOpenGLDisplayMask is not bound
!missing-pinvoke! CVDisplayLinkGetTypeID is not bound

# not clear if it is a relacement for CVDisplayLinkSetOutputCallback or not
!missing-pinvoke! CVDisplayLinkSetOutputHandler is not bound
!missing-pinvoke! CVDisplayLinkTranslateTime is not bound
!missing-pinvoke! CVMetalTextureCacheCreate is not bound
!missing-pinvoke! CVMetalTextureCacheCreateTextureFromImage is not bound
!missing-pinvoke! CVMetalTextureCacheFlush is not bound
!missing-pinvoke! CVMetalTextureGetCleanTexCoords is not bound
!missing-pinvoke! CVMetalTextureGetTexture is not bound
!missing-pinvoke! CVMetalTextureIsFlipped is not bound
!missing-pinvoke! CVBufferCopyAttachment is not bound
!missing-pinvoke! CVBufferCopyAttachments is not bound
4 changes: 0 additions & 4 deletions tests/xtro-sharpie/tvOS-CoreVideo.todo

This file was deleted.

4 changes: 0 additions & 4 deletions tests/xtro-sharpie/watchOS-CoreVideo.todo

This file was deleted.