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 1 commit
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
11 changes: 6 additions & 5 deletions src/CoreVideo/CVBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
//
using System;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using CoreFoundation;
using ObjCRuntime;
using Foundation;
Expand Down Expand Up @@ -150,9 +151,9 @@ public NSObject GetAttachment (NSString key, out CVAttachmentMode attachmentMode
if (key == null)
throw new ArgumentNullException ("key");
if (PlatformHelper.CheckSystemVersion (12, 0))
return Runtime.GetNSObject (CVBufferCopyAttachment (handle, key.Handle, out attachmentMode));
return Runtime.GetINativeObject<NSObject> (CVBufferCopyAttachment (handle, key.Handle, out attachmentMode), true);
Copy link
Contributor

Choose a reason for hiding this comment

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

Runtime.GetNSObject<NSObject> (ptr, true)

since GetINativeObject logic is more complex and you already know the return type.

mandel-macaque marked this conversation as resolved.
Show resolved Hide resolved
else
return Runtime.GetNSObject (CVBufferGetAttachment (handle, key.Handle, out attachmentMode));
return Runtime.GetINativeObject<NSObject> (CVBufferGetAttachment (handle, key.Handle, out attachmentMode), false);
Copy link
Contributor

Choose a reason for hiding this comment

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

same

mandel-macaque marked this conversation as resolved.
Show resolved Hide resolved
}
#endif

Expand All @@ -177,8 +178,8 @@ public NSDictionary GetAttachments (CVAttachmentMode attachmentMode)
#elif MONOMAC
if (PlatformHelper.CheckSystemVersion (12, 0))
#endif
return (NSDictionary) Runtime.GetNSObject (CVBufferCopyAttachments (handle, attachmentMode));
return (NSDictionary) Runtime.GetNSObject (CVBufferGetAttachments (handle, attachmentMode));
return Runtime.GetINativeObject<NSDictionary> (CVBufferCopyAttachments (handle, attachmentMode), true);
return Runtime.GetINativeObject<NSDictionary> (CVBufferGetAttachments (handle, attachmentMode), false);
Copy link
Contributor

Choose a reason for hiding this comment

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

Runtime.GetNSObject<NSDictionary> would be better since you know the return type (and GetINativeObject is more complex)

mandel-macaque marked this conversation as resolved.
Show resolved Hide resolved
}

// There is some API that needs a more strongly typed version of a NSDictionary
Expand Down Expand Up @@ -232,7 +233,7 @@ public void SetAttachments (NSDictionary theAttachments, CVAttachmentMode attach
[SupportedOSPlatform ("macos12.0")]
#endif
[DllImport (Constants.CoreVideoLibrary)]
[return: MarshalAs(UnmanagedType.U1)]
[return: MarshalAs (UnmanagedType.U1)]
static extern bool CVBufferHasAttachment (/* CVBufferRef */ IntPtr buffer, /* CFStringRef */ IntPtr key);

#if !NET
Expand Down
111 changes: 111 additions & 0 deletions tests/monotouch-test/CoreVideo/CVDisplayLinkTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#if __MACOS__
using System;
using CoreGraphics;
using Foundation;
using NUnit.Framework;
using Foundation;
using ObjCRuntime;
using CoreVideo;

namespace MonoTouchFixtures.CoreVideo {

[TestFixture]
[Preserve (AllMembers = true)]
public class CVDisplayLinkTest {
int? mainDisplayId = null;

[SetUp]
public void SetUp ()
{
// we need to have access to the media display to be able to perform
// the displaylink tests
mainDisplayId = CGDisplay.MainDisplayID;
Copy link
Contributor

Choose a reason for hiding this comment

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

mainDisplayId does not seem to be used (except in TearDown)
are you missing an Ignore in case no valid is was returned ?

Copy link
Member Author

Choose a reason for hiding this comment

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

I can remove SetUp and TearDown.

}

[TearDown]
public void TearDown ()
{
mainDisplayId = null;
}

[Test]
public void CreateFromDisplayIdValidIdTest ()
{
TestRuntime.AssertSystemVersion (PlatformName.MacOSX, 12, 0);
Assert.DoesNotThrow (() => {
using var displayLink = CVDisplayLink.CreateFromDisplayId ((uint) CGDisplay.MainDisplayID);
Assert.NotNull (displayLink, "Not null");
Assert.AreEqual (CGDisplay.MainDisplayID, displayLink.GetCurrentDisplay (), "DisplayId");
}, "Throws");
}

[Test]
public void CreateFromDisplayWrongIdTest ()
{
TestRuntime.AssertSystemVersion (PlatformName.MacOSX, 12, 0);
Assert.DoesNotThrow (() => {
using var displayLink = CVDisplayLink.CreateFromDisplayId (UInt32.MaxValue);
Assert.Null (displayLink, "null");
}, "Throws");
}

[Test]
public void CreateFromDisplayIdsTest ()
{
TestRuntime.AssertSystemVersion (PlatformName.MacOSX, 12, 0);
// we might not have more than one display, therefore we will use an array
// with a single one, there is nothing in the docs that say that we cannot do that
Assert.DoesNotThrow (() => {
using var displayLink = CVDisplayLink.CreateFromDisplayIds (new []{ (uint) CGDisplay.MainDisplayID});
Assert.Null (displayLink, "null");
}, "Throws");
}

[Test]
public void CreateFromOpenGLMaskTest ()
{
TestRuntime.AssertSystemVersion (PlatformName.MacOSX, 12, 0);
var openGLMask = CGDisplay.GetOpenGLDisplayMask (CGDisplay.MainDisplayID);
Assert.DoesNotThrow (() => {
using var displayLink = CVDisplayLink.CreateFromOpenGLMask ((uint) openGLMask);
Assert.NotNull (displayLink, "Not null");
}, "Throws");
}

[Test]
public void DefaultconstructorTest () => Assert.DoesNotThrow (() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: DefaultconstructorTest -> DefaultConstructorTest

using var displayLink = new CVDisplayLink ();
});

[Test]
public void SetCurrentDisplayOpenGLTest () => Assert.DoesNotThrow (() => {
using var displayLink = new CVDisplayLink ();
displayLink.SetCurrentDisplay (CGDisplay.MainDisplayID);
});

[Test]
public void GetCurrentDisplayTest () => Assert.DoesNotThrow (() => {
using var displayLink = new CVDisplayLink ();
Assert.AreEqual (CGDisplay.MainDisplayID, displayLink.GetCurrentDisplay ());
});

[Test]
public void GetTypeIdTest ()
{
TestRuntime.AssertSystemVersion (PlatformName.MacOSX, 12, 0);
Assert.DoesNotThrow (() => {
CVDisplayLink.GetTypeId ();
}, "Throws");
}

[Test]
public void TryTranslateTimeValidTest ()
{
TestRuntime.AssertSystemVersion (PlatformName.MacOSX, 12, 0);
using var displayLink = new CVDisplayLink ();
displayLink.GetCurrentTime (out var timeStamp);
Assert.True (displayLink.TryTranslateTime (timeStamp, out var _));
}
}
}
#endif