Skip to content

Commit

Permalink
[CoreVideo/WebKit] Refactor code a bit to unify indentation. (#22179)
Browse files Browse the repository at this point in the history
* Remove redundant OS version checks (if the OS checked for is earlier than
  the earliest we support).
* Bring CVBuffer.GetAttachment<T> to macOS to unify API across all platforms.
* Rearrange code so that the indentation is the same on all conditional code
  paths (that way code formatters don't fight depending on which conditional
  compilation symbols are defined).
  • Loading branch information
rolfbjarne authored Feb 13, 2025
1 parent 6e37e60 commit a50292c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
23 changes: 10 additions & 13 deletions src/CoreVideo/CVBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#nullable enable

using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using CoreFoundation;
Expand Down Expand Up @@ -119,28 +120,26 @@ unsafe static IntPtr CVBufferCopyAttachment (IntPtr buffer, IntPtr key, out CVAt
return CVBufferCopyAttachment (buffer, key, (CVAttachmentMode*) Unsafe.AsPointer<CVAttachmentMode> (ref 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 is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (key));
#if IOS || __MACCATALYST__ || TVOS
if (SystemVersion.CheckiOS (15, 0))
if (!SystemVersion.CheckiOS (15, 0))
return Runtime.GetINativeObject<T> (CVBufferGetAttachment (Handle, key.Handle, out attachmentMode), false);
#endif
return Runtime.GetINativeObject<T> (CVBufferCopyAttachment (Handle, key.Handle, out attachmentMode), true);
return Runtime.GetINativeObject<T> (CVBufferGetAttachment (Handle, key.Handle, out attachmentMode), false);
}
#else

#if MONOMAC && !XAMCORE_5_0
[Obsolete ("Use the generic 'GetAttachment<T>' method instead.")]
[EditorBrowsable (EditorBrowsableState.Never)]
public NSObject? GetAttachment (NSString key, out CVAttachmentMode attachmentMode)
{
if (key is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (key));
if (SystemVersion.CheckmacOS (12, 0))
return Runtime.GetNSObject<NSObject> (CVBufferCopyAttachment (Handle, key.Handle, out attachmentMode), true);
else
return Runtime.GetNSObject<NSObject> (CVBufferGetAttachment (Handle, key.Handle, out attachmentMode), false);
return Runtime.GetNSObject<NSObject> (CVBufferCopyAttachment (Handle, key.Handle, out attachmentMode), true);
}
#endif

Expand All @@ -165,12 +164,10 @@ unsafe static IntPtr CVBufferCopyAttachment (IntPtr buffer, IntPtr key, out CVAt
public NSDictionary? GetAttachments (CVAttachmentMode attachmentMode)
{
#if IOS || __MACCATALYST__ || TVOS
if (SystemVersion.CheckiOS (15, 0))
#elif MONOMAC
if (SystemVersion.CheckmacOS (12, 0))
if (!SystemVersion.CheckiOS (15, 0))
return Runtime.GetNSObject<NSDictionary> (CVBufferGetAttachments (Handle, attachmentMode), false);
#endif
return Runtime.GetINativeObject<NSDictionary> (CVBufferCopyAttachments (Handle, attachmentMode), true);
return Runtime.GetNSObject<NSDictionary> (CVBufferGetAttachments (Handle, attachmentMode), false);
}

// There is some API that needs a more strongly typed version of a NSDictionary
Expand Down
7 changes: 2 additions & 5 deletions src/WebKit/WKPreferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,10 @@ public partial class WKPreferences {
public bool TextInteractionEnabled {
get {
#if IOS || __MACCATALYST__
if (SystemVersion.CheckiOS (15, 0))
#elif MONOMAC
if (SystemVersion.CheckmacOS (12, 0))
if (!SystemVersion.CheckiOS (15, 0))
return _OldTextInteractionEnabled;
#endif
return _NewGetTextInteractionEnabled ();
else
return _OldTextInteractionEnabled;
}
set => _OldTextInteractionEnabled = value;
}
Expand Down
1 change: 0 additions & 1 deletion tests/cecil-tests/Documentation.KnownFailures.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32466,7 +32466,6 @@ M:CoreText.CTTypesetter.SuggestLineBreak(System.Int32,System.Double)
M:CoreText.CTTypesetterOptions.#ctor
M:CoreText.CTTypesetterOptions.#ctor(Foundation.NSDictionary)
M:CoreText.ICTAdaptiveImageProviding.GetImage(CoreGraphics.CGSize,System.Runtime.InteropServices.NFloat,CoreGraphics.CGPoint@,CoreGraphics.CGSize@)
M:CoreVideo.CVBuffer.GetAttachment(Foundation.NSString,CoreVideo.CVAttachmentMode@)
M:CoreVideo.CVBuffer.GetAttachment``1(Foundation.NSString,CoreVideo.CVAttachmentMode@)
M:CoreVideo.CVBuffer.GetAttachments(CoreVideo.CVAttachmentMode)
M:CoreVideo.CVBuffer.GetAttachments``2(CoreVideo.CVAttachmentMode)
Expand Down

10 comments on commit a50292c

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

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

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

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

Please sign in to comment.