inc/xrt: Add helpers for the handle types - null value, validity checker

This commit is contained in:
Ryan Pavlik 2020-07-16 11:20:43 -05:00
parent 1b50c43ce6
commit 25627e55ca

View file

@ -10,6 +10,8 @@
#pragma once
#include "xrt_config_os.h"
#include <stdbool.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
@ -22,10 +24,58 @@ extern "C" {
*/
typedef int xrt_shmem_handle_t;
/*!
* An invalid value for a shared memory block.
*
* Note that there may be more than one value that's invalid - use
* @ref xrt_shmem_is_valid instead of comparing against this!
*
* @relates xrt_shmem_handle_t
*/
#define XRT_SHMEM_HANDLE_INVALID (-1)
/*!
* Check whether a shared memory handle is valid.
*
* @public @memberof xrt_shmem_handle_t
*/
static inline bool
xrt_shmem_is_valid(xrt_shmem_handle_t handle)
{
return handle >= 0;
}
#if defined(XRT_OS_ANDROID)
typedef struct AHardwareBuffer AHardwareBuffer;
/*!
* The type underlying buffers shared between compositor clients and the main
* compositor.
*
* On Android, this is an @p AHardwareBuffer pointer.
*/
typedef AHardwareBuffer *xrt_graphics_buffer_handle_t;
/*!
* An invalid value for a graphics buffer.
*
* Note that there may be more than one value that's invalid - use
* @ref xrt_graphics_buffer_is_valid instead of comparing against this!
*
* @relates xrt_graphics_buffer_handle_t
*/
#define XRT_GRAPHICS_BUFFER_HANDLE_INVALID NULL
/*!
* Check whether a graphics buffer handle is valid.
*
* @public @memberof xrt_graphics_buffer_handle_t
*/
static inline bool
xrt_graphics_buffer_is_valid(xrt_graphics_buffer_handle_t handle)
{
return handle != NULL;
}
#else
/*!
@ -35,6 +85,27 @@ typedef AHardwareBuffer *xrt_graphics_buffer_handle_t;
* On Linux, this is a file descriptor.
*/
typedef int xrt_graphics_buffer_handle_t;
/*!
* An invalid value for a graphics buffer.
*
* Note that there may be more than one value that's invalid - use
* @ref xrt_graphics_buffer_is_valid instead of comparing against this!
*
* @relates xrt_graphics_buffer_handle_t
*/
#define XRT_GRAPHICS_BUFFER_HANDLE_INVALID (-1)
/*!
* Check whether a graphics buffer handle is valid.
*
* @public @memberof xrt_graphics_buffer_handle_t
*/
static inline bool
xrt_graphics_buffer_is_valid(xrt_graphics_buffer_handle_t handle)
{
return handle >= 0;
}
#endif
#ifdef __cplusplus