Replace preprocs with SupportedOSPlatform attributes

Such a nice feature that we have here :D
This commit is contained in:
Speykious
2022-01-16 07:46:14 +01:00
parent f305fd1495
commit e03ae233a9
8 changed files with 27 additions and 24 deletions

View File

@ -3,6 +3,7 @@
// MediaPipe.NET is licensed under the MIT License. See LICENSE for details.
using System;
using System.Runtime.Versioning;
using Mediapipe.Net.Core;
using Mediapipe.Net.Native;
@ -41,20 +42,21 @@ namespace Mediapipe.Net.Gpu
public IntPtr SharedPtr => sharedPtrHandle == null ? IntPtr.Zero : sharedPtrHandle.MpPtr;
// #if LINUX || ANDROID
[SupportedOSPlatform("Linux"), SupportedOSPlatform("Android")]
public IntPtr EglDisplay => SafeNativeMethods.mp_GlContext__egl_display(MpPtr);
[SupportedOSPlatform("Linux"), SupportedOSPlatform("Android")]
public IntPtr EglConfig => SafeNativeMethods.mp_GlContext__egl_config(MpPtr);
[SupportedOSPlatform("Linux"), SupportedOSPlatform("Android")]
public IntPtr EglContext => SafeNativeMethods.mp_GlContext__egl_context(MpPtr);
// #endif
// #if OSX
// NOTE: (from homuler) On macOS, native libs cannot be built with GPU enabled, so it cannot be used actually.
[SupportedOSPlatform("OSX")]
public IntPtr NsglContext => SafeNativeMethods.mp_GlContext__nsgl_context(MpPtr);
// #elif IOS
[SupportedOSPlatform("IOS")]
public IntPtr EaglContext => SafeNativeMethods.mp_GlContext__eagl_context(MpPtr);
// #endif
public bool IsCurrent() => SafeNativeMethods.mp_GlContext__IsCurrent(MpPtr);

View File

@ -5,14 +5,14 @@
using System;
using System.Diagnostics.Contracts;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
namespace Mediapipe.Net.Native
{
internal partial class SafeNativeMethods : NativeMethods
{
// #if LINUX || ANDROID
[SupportedOSPlatform("Linux"), SupportedOSPlatform("Android")]
[Pure, DllImport(MEDIAPIPE_LIBRARY)]
public static extern IntPtr eglGetCurrentContext();
// #endif
}
}

View File

@ -5,6 +5,7 @@
using System;
using System.Diagnostics.Contracts;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
namespace Mediapipe.Net.Native
{
@ -14,27 +15,29 @@ namespace Mediapipe.Net.Native
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern IntPtr mp_SharedGlContext__get(IntPtr sharedGlContext);
// #if LINUX || ANDROID
[SupportedOSPlatform("Linux"), SupportedOSPlatform("Android")]
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern IntPtr mp_GlContext__egl_display(IntPtr glContext);
[SupportedOSPlatform("Linux"), SupportedOSPlatform("Android")]
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern IntPtr mp_GlContext__egl_config(IntPtr glContext);
[SupportedOSPlatform("Linux"), SupportedOSPlatform("Android")]
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern IntPtr mp_GlContext__egl_context(IntPtr glContext);
// #endif
// #if IOS
[SupportedOSPlatform("IOS")]
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern IntPtr mp_GlContext__eagl_context(IntPtr glContext);
// #elif OSX
[SupportedOSPlatform("OSX")]
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern IntPtr mp_GlContext__nsgl_context(IntPtr glContext);
[SupportedOSPlatform("OSX")]
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern IntPtr mp_GlContext__nsgl_pixel_format(IntPtr glContext);
// #endif
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
[return: MarshalAs(UnmanagedType.I1)]

View File

@ -5,16 +5,16 @@
using System;
using System.Diagnostics.Contracts;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using Mediapipe.Net.Gpu;
namespace Mediapipe.Net.Native
{
internal partial class SafeNativeMethods : NativeMethods
{
// #if LINUX || ANDROID
[SupportedOSPlatform("Linux"), SupportedOSPlatform("Android")]
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern IntPtr mp_GpuBuffer__GetGlTextureBufferSharedPtr(IntPtr gpuBuffer);
// #endif
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern int mp_GpuBuffer__width(IntPtr gpuBuffer);

View File

@ -5,15 +5,15 @@
using System;
using System.Diagnostics.Contracts;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
namespace Mediapipe.Net.Native
{
internal partial class SafeNativeMethods : NativeMethods
{
// #if IOS
[SupportedOSPlatform("IOS")]
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern IntPtr mp_GpuResources__ios_gpu_data(IntPtr gpuResources);
// #endif
[Pure, DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern IntPtr mp_SharedGpuResources__get(IntPtr gpuResources);

View File

@ -4,6 +4,7 @@
using System;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using Mediapipe.Net.Gpu;
namespace Mediapipe.Net.Native
@ -33,11 +34,10 @@ namespace Mediapipe.Net.Native
public static extern MpReturnCode mp_GlCalculatorHelper__CreateSourceTexture__Rgb(
IntPtr glCalculatorHelper, IntPtr gpuBuffer, out IntPtr glTexture);
// #if IOS
[SupportedOSPlatform("IOS")]
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern MpReturnCode mp_GlCalculatorHelper__CreateSourceTexture__Rgb_i(
IntPtr glCalculatorHelper, IntPtr gpuBuffer, int plane, out IntPtr glTexture);
// #endif
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern MpReturnCode mp_GlCalculatorHelper__CreateDestinationTexture__i_i_ui(

View File

@ -4,6 +4,7 @@
using System;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
namespace Mediapipe.Net.Native
{
@ -30,12 +31,10 @@ namespace Mediapipe.Net.Native
public static extern MpReturnCode mp_GlContext_Create__ui_b(
uint shareContext, [MarshalAs(UnmanagedType.I1)] bool createThread, out IntPtr statusOrSharedGlContext);
// #if IOS
// TODO: iOS support?
[SupportedOSPlatform("IOS")]
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern MpReturnCode mp_GlContext_Create__Pes_b(
IntPtr sharegroup, [MarshalAs(UnmanagedType.I1)] bool createThread, out IntPtr statusOrSharedGlContext);
// #endif
#endregion
#region GlSyncToken

View File

@ -4,16 +4,15 @@
using System;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
namespace Mediapipe.Net.Native
{
internal partial class UnsafeNativeMethods : NativeMethods
{
// #if LINUX || ANDROID
// TODO: What preprocessing directive for this?
[SupportedOSPlatform("Linux"), SupportedOSPlatform("Android")]
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern MpReturnCode mp_GpuBuffer__PSgtb(IntPtr glTextureBuffer, out IntPtr gpuBuffer);
// #endif
[DllImport(MEDIAPIPE_LIBRARY, ExactSpelling = true)]
public static extern void mp_GpuBuffer__delete(IntPtr gpuBuffer);