using System;
namespace UnityEngine.XR.ARSubsystems
{
public partial struct XRCpuImage
{
///
/// An API for interacting with s.
///
///
/// This interface is intended to be implemented by AR platform providers (for example, ARCore, ARKit, Magic Leap,
/// and HoloLens). The uses it to make platform-specific API calls. Unity developers
/// don't need to interact directly with this class; use the instead.
///
public abstract class Api
{
///
/// Callback from native code for when the asynchronous conversion is complete.
///
/// The status of the conversion operation.
/// The parameters for the conversion.
/// The native pointer to the converted data.
/// The memory size of the converted data.
/// The native context for the conversion operation.
public delegate void OnImageRequestCompleteDelegate(
AsyncConversionStatus status,
ConversionParams conversionParams,
IntPtr dataPtr,
int dataLength,
IntPtr context);
///
/// Method to be implemented by the provider to get information about an image plane from a native image
/// handle by index.
///
/// A unique identifier for this camera image.
/// The index of the plane to get.
/// The returned camera plane information if successful.
///
/// true if the image plane was acquired. Otherwise, false.
///
/// Thrown if the implementation does not support camera
/// image.
public virtual bool TryGetPlane(
int nativeHandle,
int planeIndex,
out Plane.Cinfo planeCinfo)
{
throw new NotSupportedException("Camera image conversion is not supported by this implementation");
}
///
/// Method to be implemented by the provider to get the number of bytes required to store an image with the
/// given dimensions and TextureFormat.
///
/// A unique identifier for the camera image to convert.
/// The dimensions of the output image.
/// The TextureFormat for the image.
/// The number of bytes required to store the converted image.
/// true if the output was set.
/// Thrown if the implementation does not support camera image conversion.
public virtual bool TryGetConvertedDataSize(int nativeHandle, Vector2Int dimensions, TextureFormat format, out int size)
{
throw new NotSupportedException("Camera image conversion is not supported by this implementation");
}
///
/// Method to be implemented by the provider to convert the image with handle
/// using the provided .
///
/// A unique identifier for the camera image to convert.
/// The parameters to use during the conversion.
/// A buffer to write the converted image to.
/// The number of bytes available in the buffer.
///
/// true if the image was converted and stored in .
///
/// Thrown if the implementation does not support camera
/// image.
public virtual bool TryConvert(
int nativeHandle,
ConversionParams conversionParams,
IntPtr destinationBuffer,
int bufferLength)
{
throw new NotSupportedException("Camera image conversion is not supported by this implementation");
}
///
/// Method to be implemented by the provider to create an asynchronous request to convert a camera image,
/// similar to except the conversion should happen on a thread other than the
/// calling (main) thread.
///
/// A unique identifier for the camera image to convert.
/// The parameters to use during the conversion.
/// A unique identifier for this request.
/// Thrown if the implementation does not support camera
/// image.
public virtual int ConvertAsync(
int nativeHandle,
ConversionParams conversionParams)
{
throw new NotSupportedException("Camera image conversion is not supported by this implementation");
}
///
/// Method to be implemented by the provider to determine whether a native image handle is currently valid.
/// An image can become invalid if it has been disposed.
///
///
/// If a handle is valid, and should not fail.
///
/// A unique identifier for the camera image in question.
/// true, if it is a valid handle. Otherwise, false.
/// Thrown if the implementation does not support camera
/// image.
///
public virtual bool NativeHandleValid(
int nativeHandle)
{
throw new NotSupportedException("Camera image conversion is not supported by this implementation");
}
///
/// Method to be implemented by the provider to get a pointer to the image data from a completed
/// asynchronous request. This method should only succeed if returns
/// .
///
/// The unique identifier associated with a request.
/// A pointer to the native buffer containing the data.
/// The number of bytes in .
/// true if and were set and point
/// to the image data.
/// Thrown if the implementation does not support camera
/// image.
public virtual bool TryGetAsyncRequestData(int requestId, out IntPtr dataPtr, out int dataLength)
{
throw new NotSupportedException("Camera image conversion is not supported by this implementation");
}
///
/// Method to be implemented by the provider. It is similar to
/// but takes a delegate to invoke when the
/// request is complete, rather than returning a request id.
///
///
/// If the first parameter to is
/// , the dataPtr parameter must be valid
/// for the duration of the invocation. The data can be destroyed immediately upon return. The
/// parameter must be passed back to the .
///
/// A unique identifier for the camera image to convert.
/// The parameters to use during the conversion.
/// A delegate which must be invoked when the request is complete, whether the
/// conversion was successfully or not.
/// A native pointer which must be passed back unaltered to
/// .
/// Thrown if the implementation does not support camera
/// image.
public virtual void ConvertAsync(
int nativeHandle,
ConversionParams conversionParams,
OnImageRequestCompleteDelegate callback,
IntPtr context)
{
throw new NotSupportedException("Camera image conversion is not supported by this implementation");
}
///
/// Method to be implemented by the provider to dispose an existing native image identified by
/// .
///
/// A unique identifier for this camera image.
/// Thrown if the implementation does not support camera
/// image.
public virtual void DisposeImage(int nativeHandle)
{
throw new NotSupportedException("Camera image conversion is not supported by this implementation");
}
///
/// Method to be implemented by the provider to dispose an existing async conversion request.
///
/// A unique identifier for the request.
/// Thrown if the implementation does not support camera
/// image.
///
public virtual void DisposeAsyncRequest(int requestId)
{
throw new NotSupportedException("Camera image conversion is not supported by this implementation");
}
///
/// Method to be implemented by the provider to get the status of an existing asynchronous conversion
/// request.
///
/// The unique identifier associated with a request.
/// The state of the request.
/// Thrown if the implementation does not support camera
/// image.
///
public virtual AsyncConversionStatus GetAsyncRequestStatus(int requestId)
{
throw new NotSupportedException("Camera image conversion is not supported by this implementation");
}
///
/// Determines whether a given
/// [TextureFormat](https://docs.unity3d.com/ScriptReference/TextureFormat.html) is supported for image
/// conversion.
///
/// The to convert.
/// The [`TextureFormat`](https://docs.unity3d.com/ScriptReference/TextureFormat.html)
/// to test.
/// Returns `true` if can be converted to .
/// Returns `false` otherwise.
public virtual bool FormatSupported(XRCpuImage image, TextureFormat format) => false;
}
}
}