Wes xx mediapipe integration

This commit is contained in:
Jelle De Geest
2023-03-12 20:34:16 +00:00
parent 8349b5f149
commit b11eeb465c
975 changed files with 192230 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
#if UNITY_STANDALONE_LINUX || UNITY_ANDROID
namespace Mediapipe
{
public class Egl
{
public static IntPtr GetCurrentContext()
{
return SafeNativeMethods.eglGetCurrentContext();
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 451f377fbd9cb54bcb56031e72e6603b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,25 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
namespace Mediapipe
{
public class Gl
{
public static uint GL_TEXTURE_2D = 0x0DE1;
public static void Flush()
{
UnsafeNativeMethods.glFlush();
}
public static void ReadPixels(int x, int y, int width, int height, uint glFormat, uint glType, IntPtr pixels)
{
UnsafeNativeMethods.glReadPixels(x, y, width, height, glFormat, glType, pixels);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2fced906166b27dff82e2af4aa2e38c6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,132 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
namespace Mediapipe
{
public class GlCalculatorHelper : MpResourceHandle
{
public delegate Status.StatusArgs NativeGlStatusFunction();
public delegate void GlFunction();
public GlCalculatorHelper() : base()
{
UnsafeNativeMethods.mp_GlCalculatorHelper__(out var ptr).Assert();
this.ptr = ptr;
}
protected override void DeleteMpPtr()
{
UnsafeNativeMethods.mp_GlCalculatorHelper__delete(ptr);
}
public void InitializeForTest(GpuResources gpuResources)
{
UnsafeNativeMethods.mp_GlCalculatorHelper__InitializeForTest__Pgr(mpPtr, gpuResources.mpPtr).Assert();
GC.KeepAlive(gpuResources);
GC.KeepAlive(this);
}
/// <param name="nativeGlStatusFunction">
/// Function that is run in Gl Context.
/// Make sure that this function doesn't throw exceptions and won't be GCed.
/// </param>
public Status RunInGlContext(NativeGlStatusFunction nativeGlStatusFunction)
{
UnsafeNativeMethods.mp_GlCalculatorHelper__RunInGlContext__PF(mpPtr, nativeGlStatusFunction, out var statusPtr).Assert();
GC.KeepAlive(this);
return new Status(statusPtr);
}
public Status RunInGlContext(GlFunction glFunction)
{
return RunInGlContext(() =>
{
try
{
glFunction();
return Status.StatusArgs.Ok();
}
catch (Exception e)
{
return Status.StatusArgs.Internal(e.ToString());
}
});
}
public GlTexture CreateSourceTexture(ImageFrame imageFrame)
{
UnsafeNativeMethods.mp_GlCalculatorHelper__CreateSourceTexture__Rif(mpPtr, imageFrame.mpPtr, out var texturePtr).Assert();
GC.KeepAlive(this);
GC.KeepAlive(imageFrame);
return new GlTexture(texturePtr);
}
public GlTexture CreateSourceTexture(GpuBuffer gpuBuffer)
{
UnsafeNativeMethods.mp_GlCalculatorHelper__CreateSourceTexture__Rgb(mpPtr, gpuBuffer.mpPtr, out var texturePtr).Assert();
GC.KeepAlive(this);
GC.KeepAlive(gpuBuffer);
return new GlTexture(texturePtr);
}
#if UNITY_IOS
public GlTexture CreateSourceTexture(GpuBuffer gpuBuffer, int plane) {
UnsafeNativeMethods.mp_GlCalculatorHelper__CreateSourceTexture__Rgb_i(mpPtr, gpuBuffer.mpPtr, plane, out var texturePtr).Assert();
GC.KeepAlive(this);
GC.KeepAlive(gpuBuffer);
return new GlTexture(texturePtr);
}
#endif
public GlTexture CreateDestinationTexture(int width, int height, GpuBufferFormat format)
{
UnsafeNativeMethods.mp_GlCalculatorHelper__CreateDestinationTexture__i_i_ui(mpPtr, width, height, format, out var texturePtr).Assert();
GC.KeepAlive(this);
return new GlTexture(texturePtr);
}
public GlTexture CreateDestinationTexture(GpuBuffer gpuBuffer)
{
UnsafeNativeMethods.mp_GlCalculatorHelper__CreateDestinationTexture__Rgb(mpPtr, gpuBuffer.mpPtr, out var texturePtr).Assert();
GC.KeepAlive(this);
GC.KeepAlive(gpuBuffer);
return new GlTexture(texturePtr);
}
public uint framebuffer => SafeNativeMethods.mp_GlCalculatorHelper__framebuffer(mpPtr);
public void BindFramebuffer(GlTexture glTexture)
{
UnsafeNativeMethods.mp_GlCalculatorHelper__BindFrameBuffer__Rtexture(mpPtr, glTexture.mpPtr).Assert();
GC.KeepAlive(glTexture);
GC.KeepAlive(this);
}
public GlContext GetGlContext()
{
var glContextPtr = SafeNativeMethods.mp_GlCalculatorHelper__GetGlContext(mpPtr);
GC.KeepAlive(this);
return new GlContext(glContextPtr, false);
}
public bool Initialized()
{
return SafeNativeMethods.mp_GlCalculatorHelper__Initialized(mpPtr);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d373b6292efa02f09bb64650c4ceab57
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,91 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
namespace Mediapipe
{
public class GlContext : MpResourceHandle
{
private SharedPtrHandle _sharedPtrHandle;
public static GlContext GetCurrent()
{
UnsafeNativeMethods.mp_GlContext_GetCurrent(out var glContextPtr).Assert();
return glContextPtr == IntPtr.Zero ? null : new GlContext(glContextPtr);
}
public GlContext(IntPtr ptr, bool isOwner = true) : base(isOwner)
{
_sharedPtrHandle = new SharedPtr(ptr, isOwner);
this.ptr = _sharedPtrHandle.Get();
}
protected override void DisposeManaged()
{
if (_sharedPtrHandle != null)
{
_sharedPtrHandle.Dispose();
_sharedPtrHandle = null;
}
base.DisposeManaged();
}
protected override void DeleteMpPtr()
{
// Do nothing
}
public IntPtr sharedPtr => _sharedPtrHandle == null ? IntPtr.Zero : _sharedPtrHandle.mpPtr;
#if UNITY_EDITOR_LINUX || UNITY_STANDALONE_LINUX || UNITY_ANDROID
public IntPtr eglDisplay => SafeNativeMethods.mp_GlContext__egl_display(mpPtr);
public IntPtr eglConfig => SafeNativeMethods.mp_GlContext__egl_config(mpPtr);
public IntPtr eglContext => SafeNativeMethods.mp_GlContext__egl_context(mpPtr);
#endif
#if UNITY_STANDALONE_OSX
// NOTE: On macOS, native libs cannot be built with GPU enabled, so it cannot be used actually.
public IntPtr nsglContext => SafeNativeMethods.mp_GlContext__nsgl_context(mpPtr);
#elif UNITY_IOS
public IntPtr eaglContext => SafeNativeMethods.mp_GlContext__eagl_context(mpPtr);
#endif
public bool IsCurrent()
{
return SafeNativeMethods.mp_GlContext__IsCurrent(mpPtr);
}
public int glMajorVersion => SafeNativeMethods.mp_GlContext__gl_major_version(mpPtr);
public int glMinorVersion => SafeNativeMethods.mp_GlContext__gl_minor_version(mpPtr);
public long glFinishCount => SafeNativeMethods.mp_GlContext__gl_finish_count(mpPtr);
private class SharedPtr : SharedPtrHandle
{
public SharedPtr(IntPtr ptr, bool isOwner = true) : base(ptr, isOwner) { }
protected override void DeleteMpPtr()
{
UnsafeNativeMethods.mp_SharedGlContext__delete(ptr);
}
public override IntPtr Get()
{
return SafeNativeMethods.mp_SharedGlContext__get(mpPtr);
}
public override void Reset()
{
UnsafeNativeMethods.mp_SharedGlContext__reset(mpPtr);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9326248fed7e3b84f91321864c9e94a2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,84 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
namespace Mediapipe
{
public class GlSyncPoint : MpResourceHandle
{
private SharedPtrHandle _sharedPtrHandle;
public GlSyncPoint(IntPtr ptr) : base()
{
_sharedPtrHandle = new SharedPtr(ptr);
this.ptr = _sharedPtrHandle.Get();
}
protected override void DisposeManaged()
{
if (_sharedPtrHandle != null)
{
_sharedPtrHandle.Dispose();
_sharedPtrHandle = null;
}
base.DisposeManaged();
}
protected override void DeleteMpPtr()
{
// Do nothing
}
public IntPtr sharedPtr => _sharedPtrHandle == null ? IntPtr.Zero : _sharedPtrHandle.mpPtr;
public void Wait()
{
UnsafeNativeMethods.mp_GlSyncPoint__Wait(mpPtr).Assert();
}
public void WaitOnGpu()
{
UnsafeNativeMethods.mp_GlSyncPoint__WaitOnGpu(mpPtr).Assert();
}
public bool IsReady()
{
UnsafeNativeMethods.mp_GlSyncPoint__IsReady(mpPtr, out var value).Assert();
GC.KeepAlive(this);
return value;
}
public GlContext GetContext()
{
UnsafeNativeMethods.mp_GlSyncPoint__GetContext(mpPtr, out var sharedGlContextPtr).Assert();
GC.KeepAlive(this);
return new GlContext(sharedGlContextPtr);
}
private class SharedPtr : SharedPtrHandle
{
public SharedPtr(IntPtr ptr) : base(ptr) { }
protected override void DeleteMpPtr()
{
UnsafeNativeMethods.mp_GlSyncToken__delete(ptr);
}
public override IntPtr Get()
{
return SafeNativeMethods.mp_GlSyncToken__get(mpPtr);
}
public override void Reset()
{
UnsafeNativeMethods.mp_GlSyncToken__reset(mpPtr);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e6711aa0798875aad858e15d3900032b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,48 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
namespace Mediapipe
{
public class GlTexture : MpResourceHandle
{
public GlTexture() : base()
{
UnsafeNativeMethods.mp_GlTexture__(out var ptr).Assert();
this.ptr = ptr;
}
public GlTexture(IntPtr ptr, bool isOwner = true) : base(ptr, isOwner) { }
protected override void DeleteMpPtr()
{
UnsafeNativeMethods.mp_GlTexture__delete(ptr);
}
public int width => SafeNativeMethods.mp_GlTexture__width(mpPtr);
public int height => SafeNativeMethods.mp_GlTexture__height(mpPtr);
public uint target => SafeNativeMethods.mp_GlTexture__target(mpPtr);
public uint name => SafeNativeMethods.mp_GlTexture__name(mpPtr);
public void Release()
{
UnsafeNativeMethods.mp_GlTexture__Release(mpPtr).Assert();
GC.KeepAlive(this);
}
public GpuBuffer GetGpuBufferFrame()
{
UnsafeNativeMethods.mp_GlTexture__GetGpuBufferFrame(mpPtr, out var gpuBufferPtr).Assert();
GC.KeepAlive(this);
return new GpuBuffer(gpuBufferPtr);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 91fe3aeb09816f4b4909de29906d7903
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,149 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
namespace Mediapipe
{
public class GlTextureBuffer : MpResourceHandle
{
private SharedPtrHandle _sharedPtrHandle;
/// <remarks>
/// In the original MediaPipe repo, DeletionCallback only receives GlSyncToken.
/// However, IL2CPP does not support marshaling delegates that point to instance methods to native code,
/// so it receives also the texture name to specify the target instance.
/// </remarks>
public delegate void DeletionCallback(uint name, IntPtr glSyncToken);
public GlTextureBuffer(IntPtr ptr, bool isOwner = true) : base(isOwner)
{
_sharedPtrHandle = new SharedPtr(ptr, isOwner);
this.ptr = _sharedPtrHandle.Get();
}
/// <param name="callback">
/// A function called when the texture buffer is deleted.
/// Make sure that this function doesn't throw exceptions and won't be GCed.
/// </param>
public GlTextureBuffer(uint target, uint name, int width, int height,
GpuBufferFormat format, DeletionCallback callback, GlContext glContext) : base()
{
var sharedContextPtr = glContext == null ? IntPtr.Zero : glContext.sharedPtr;
UnsafeNativeMethods.mp_SharedGlTextureBuffer__ui_ui_i_i_ui_PF_PSgc(
target, name, width, height, format, callback, sharedContextPtr, out var ptr).Assert();
_sharedPtrHandle = new SharedPtr(ptr);
this.ptr = _sharedPtrHandle.Get();
}
public GlTextureBuffer(uint name, int width, int height, GpuBufferFormat format, DeletionCallback callback, GlContext glContext = null) :
this(Gl.GL_TEXTURE_2D, name, width, height, format, callback, glContext)
{ }
protected override void DisposeManaged()
{
if (_sharedPtrHandle != null)
{
_sharedPtrHandle.Dispose();
_sharedPtrHandle = null;
}
base.DisposeManaged();
}
protected override void DeleteMpPtr()
{
// Do nothing
}
public IntPtr sharedPtr => _sharedPtrHandle == null ? IntPtr.Zero : _sharedPtrHandle.mpPtr;
public uint Name()
{
return SafeNativeMethods.mp_GlTextureBuffer__name(mpPtr);
}
public uint Target()
{
return SafeNativeMethods.mp_GlTextureBuffer__target(mpPtr);
}
public int Width()
{
return SafeNativeMethods.mp_GlTextureBuffer__width(mpPtr);
}
public int Height()
{
return SafeNativeMethods.mp_GlTextureBuffer__height(mpPtr);
}
public GpuBufferFormat Format()
{
return SafeNativeMethods.mp_GlTextureBuffer__format(mpPtr);
}
public void WaitUntilComplete()
{
UnsafeNativeMethods.mp_GlTextureBuffer__WaitUntilComplete(mpPtr).Assert();
}
public void WaitOnGpu()
{
UnsafeNativeMethods.mp_GlTextureBuffer__WaitOnGpu(mpPtr).Assert();
}
public void Reuse()
{
UnsafeNativeMethods.mp_GlTextureBuffer__Reuse(mpPtr).Assert();
}
public void Updated(GlSyncPoint prodToken)
{
UnsafeNativeMethods.mp_GlTextureBuffer__Updated__Pgst(mpPtr, prodToken.sharedPtr).Assert();
}
public void DidRead(GlSyncPoint consToken)
{
UnsafeNativeMethods.mp_GlTextureBuffer__DidRead__Pgst(mpPtr, consToken.sharedPtr).Assert();
}
public void WaitForConsumers()
{
UnsafeNativeMethods.mp_GlTextureBuffer__WaitForConsumers(mpPtr).Assert();
}
public void WaitForConsumersOnGpu()
{
UnsafeNativeMethods.mp_GlTextureBuffer__WaitForConsumersOnGpu(mpPtr).Assert();
}
public GlContext GetProducerContext()
{
return new GlContext(SafeNativeMethods.mp_GlTextureBuffer__GetProducerContext(mpPtr), false);
}
private class SharedPtr : SharedPtrHandle
{
public SharedPtr(IntPtr ptr, bool isOwner = true) : base(ptr, isOwner) { }
protected override void DeleteMpPtr()
{
UnsafeNativeMethods.mp_SharedGlTextureBuffer__delete(ptr);
}
public override IntPtr Get()
{
return SafeNativeMethods.mp_SharedGlTextureBuffer__get(mpPtr);
}
public override void Reset()
{
UnsafeNativeMethods.mp_SharedGlTextureBuffer__reset(mpPtr);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fdc0e340c6497d69482b411dd1da98d1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,19 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System.Runtime.InteropServices;
namespace Mediapipe
{
[StructLayout(LayoutKind.Sequential)]
public struct GlTextureInfo
{
public int glInternalFormat;
public uint glFormat;
public uint glType;
public int downscale;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 52c2de190149bd59f8fdc4b61fb65e5e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,15 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
namespace Mediapipe
{
public enum GlVersion : uint
{
kGL = 1,
kGLES2 = 2,
kGLES3 = 3,
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c8ed2bce7c4dadfed96ab02757192254
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,44 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
namespace Mediapipe
{
public class GpuBuffer : MpResourceHandle
{
public GpuBuffer(IntPtr ptr, bool isOwner = true) : base(ptr, isOwner) { }
#if UNITY_EDITOR_LINUX || UNITY_STANDALONE_LINUX || UNITY_ANDROID
public GpuBuffer(GlTextureBuffer glTextureBuffer) : base()
{
UnsafeNativeMethods.mp_GpuBuffer__PSgtb(glTextureBuffer.sharedPtr, out var ptr).Assert();
glTextureBuffer.Dispose(); // respect move semantics
this.ptr = ptr;
}
#endif
protected override void DeleteMpPtr()
{
UnsafeNativeMethods.mp_GpuBuffer__delete(ptr);
}
public GpuBufferFormat Format()
{
return SafeNativeMethods.mp_GpuBuffer__format(mpPtr);
}
public int Width()
{
return SafeNativeMethods.mp_GpuBuffer__width(mpPtr);
}
public int Height()
{
return SafeNativeMethods.mp_GpuBuffer__height(mpPtr);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c6ff19d1ad393a456aa8a1957d8de679
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,38 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
namespace Mediapipe
{
public enum GpuBufferFormat : uint
{
kUnknown = 0,
kBGRA32 = ('B' << 24) + ('G' << 16) + ('R' << 8) + 'A',
kGrayFloat32 = ('L' << 24) + ('0' << 16) + ('0' << 8) + 'f',
kGrayHalf16 = ('L' << 24) + ('0' << 16) + ('0' << 8) + 'h',
kOneComponent8 = ('L' << 24) + ('0' << 16) + ('0' << 8) + '8',
kTwoComponentHalf16 = ('2' << 24) + ('C' << 16) + ('0' << 8) + 'h',
kTwoComponentFloat32 = ('2' << 24) + ('C' << 16) + ('0' << 8) + 'f',
kBiPlanar420YpCbCr8VideoRange = ('4' << 24) + ('2' << 16) + ('0' << 8) + 'v',
kBiPlanar420YpCbCr8FullRange = ('4' << 24) + ('2' << 16) + ('0' << 8) + 'f',
kRGB24 = 0x00000018, // Note: prefer BGRA32 whenever possible.
kRGBAHalf64 = ('R' << 24) + ('G' << 16) + ('h' << 8) + 'A',
kRGBAFloat128 = ('R' << 24) + ('G' << 16) + ('f' << 8) + 'A',
}
public static class GpuBufferFormatExtension
{
public static ImageFormat.Types.Format ImageFormatFor(this GpuBufferFormat gpuBufferFormat)
{
return SafeNativeMethods.mp__ImageFormatForGpuBufferFormat__ui(gpuBufferFormat);
}
public static GlTextureInfo GlTextureInfoFor(this GpuBufferFormat gpuBufferFormat, int plane, GlVersion glVersion = GlVersion.kGLES3)
{
UnsafeNativeMethods.mp__GlTextureInfoForGpuBufferFormat__ui_i_ui(gpuBufferFormat, plane, glVersion, out var glTextureInfo).Assert();
return glTextureInfo;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9cf369502e143ed428fb320c1bf6a612
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,73 @@
// Copyright (c) 2021 homuler
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
using System;
namespace Mediapipe
{
public class GpuResources : MpResourceHandle
{
private SharedPtrHandle _sharedPtrHandle;
/// <param name="ptr">Shared pointer of mediapipe::GpuResources</param>
public GpuResources(IntPtr ptr) : base()
{
_sharedPtrHandle = new SharedPtr(ptr);
this.ptr = _sharedPtrHandle.Get();
}
protected override void DisposeManaged()
{
if (_sharedPtrHandle != null)
{
_sharedPtrHandle.Dispose();
_sharedPtrHandle = null;
}
base.DisposeManaged();
}
protected override void DeleteMpPtr()
{
// Do nothing
}
public IntPtr sharedPtr => _sharedPtrHandle == null ? IntPtr.Zero : _sharedPtrHandle.mpPtr;
public static StatusOrGpuResources Create()
{
UnsafeNativeMethods.mp_GpuResources_Create(out var statusOrGpuResourcesPtr).Assert();
return new StatusOrGpuResources(statusOrGpuResourcesPtr);
}
public static StatusOrGpuResources Create(IntPtr externalContext)
{
UnsafeNativeMethods.mp_GpuResources_Create__Pv(externalContext, out var statusOrGpuResourcesPtr).Assert();
return new StatusOrGpuResources(statusOrGpuResourcesPtr);
}
private class SharedPtr : SharedPtrHandle
{
public SharedPtr(IntPtr ptr) : base(ptr) { }
protected override void DeleteMpPtr()
{
UnsafeNativeMethods.mp_SharedGpuResources__delete(ptr);
}
public override IntPtr Get()
{
return SafeNativeMethods.mp_SharedGpuResources__get(mpPtr);
}
public override void Reset()
{
UnsafeNativeMethods.mp_SharedGpuResources__reset(mpPtr);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 79a3f5b48340727e8b240d5aa9fb28ab
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: