-
Notifications
You must be signed in to change notification settings - Fork 514
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
Changes from 2 commits
da24cab
7d79213
7b35179
915f8e6
2b32222
03026b5
dcbbdf3
ecb3a76
b1e0ec9
c33bb04
21b7238
43657fc
127806e
ba74e6f
76d8cc2
2aba632
3da2cc7
1b6f927
02ec533
a94f580
733cc93
35503c8
f091491
7cd7f9e
23e6096
43a87fc
be1614e
1da2f02
94d8143
b141a30
050f6f0
5c17e7d
e522eb4
ac7a987
d44a025
3949601
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)] | ||
[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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing argument for ownership There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The API without the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yup, the generic version is newer/better There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same, you're not specifying the ownership (using the default) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same :) |
||
return (NSDictionary) Runtime.GetNSObject (CVBufferGetAttachments (handle, attachmentMode)); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder why |
||
} | ||
} | ||
|
||
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); | ||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
{ | ||
outTime = null; | ||
if (CVDisplayLinkTranslateTime (this.Handle, inTime, out var translated) == 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The documentation says this:
You're passing in null, which is not what the API calls for. It looks from the documentation that this should be a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice catch, I'll update it, thx! |
||
outTime = translated; | ||
} | ||
return outTime != null; | ||
} | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
// | ||
// | ||
|
||
#if IOS || TVOS | ||
#if !__WATCHOS__ | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
|
@@ -22,7 +22,7 @@ | |
|
||
namespace CoreVideo { | ||
|
||
[iOS (8,0)] | ||
[iOS (8,0), Mac (12,0)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mac Catalyst? |
||
public class CVMetalTexture : INativeObject, IDisposable { | ||
|
||
internal IntPtr handle; | ||
|
@@ -97,5 +97,5 @@ public void GetCleanTexCoords (out float [] lowerLeft, out float [] lowerRight, | |
} | ||
} | ||
|
||
#endif // IOS || TVOS | ||
#endif // ! __WATCHOS__ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
// | ||
// | ||
|
||
#if IOS || TVOS | ||
#if !__WATCHOS__ | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
|
@@ -21,7 +21,7 @@ | |
|
||
namespace CoreVideo { | ||
|
||
[iOS (8,0)] | ||
[iOS (8,0), Mac (12,0)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mac Catalyst? |
||
public partial class CVMetalTextureCache : INativeObject, IDisposable { | ||
internal IntPtr handle; | ||
|
||
|
@@ -171,4 +171,4 @@ extern static CVReturn CVMetalTextureCacheCreateTextureFromImage ( | |
} | ||
} | ||
|
||
#endif // IOS || TVOS | ||
#endif // __WATCHOS__ |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mac Catalyst?