mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-01-24 07:31:48 +00:00
71 lines
1.4 KiB
C
71 lines
1.4 KiB
C
// Copyright 2020, Collabora, Ltd.
|
|
// SPDX-License-Identifier: BSL-1.0
|
|
/*!
|
|
* @file
|
|
* @brief Implementations of handle functions
|
|
*
|
|
* @author Ryan Pavlik <ryan.pavlik@collabora.com>
|
|
* @ingroup aux_util
|
|
*
|
|
*/
|
|
|
|
#include "u_handles.h"
|
|
|
|
#if defined(XRT_GRAPHICS_BUFFER_HANDLE_IS_AHARDWAREBUFFER)
|
|
#include <android/hardware_buffer.h>
|
|
|
|
static inline void
|
|
release_graphics_handle(xrt_graphics_buffer_handle_t handle)
|
|
{
|
|
AHardwareBuffer_release(handle);
|
|
}
|
|
|
|
static inline xrt_graphics_buffer_handle_t
|
|
ref_graphics_handle(xrt_graphics_buffer_handle_t handle)
|
|
{
|
|
AHardwareBuffer_acquire(handle);
|
|
|
|
return handle;
|
|
}
|
|
|
|
#elif defined(XRT_GRAPHICS_BUFFER_HANDLE_IS_FD)
|
|
#include <unistd.h>
|
|
|
|
static inline void
|
|
release_graphics_handle(xrt_graphics_buffer_handle_t handle)
|
|
{
|
|
close(handle);
|
|
}
|
|
|
|
static inline xrt_graphics_buffer_handle_t
|
|
ref_graphics_handle(xrt_graphics_buffer_handle_t handle)
|
|
{
|
|
return dup(handle);
|
|
}
|
|
|
|
#endif
|
|
|
|
xrt_graphics_buffer_handle_t
|
|
u_graphics_buffer_ref(xrt_graphics_buffer_handle_t handle)
|
|
{
|
|
if (xrt_graphics_buffer_is_valid(handle)) {
|
|
return ref_graphics_handle(handle);
|
|
}
|
|
|
|
return XRT_GRAPHICS_BUFFER_HANDLE_INVALID;
|
|
}
|
|
|
|
void
|
|
u_graphics_buffer_unref(xrt_graphics_buffer_handle_t *handle_ptr)
|
|
{
|
|
if (handle_ptr == NULL) {
|
|
return;
|
|
}
|
|
xrt_graphics_buffer_handle_t handle = *handle_ptr;
|
|
if (!xrt_graphics_buffer_is_valid(handle)) {
|
|
return;
|
|
}
|
|
release_graphics_handle(handle);
|
|
*handle_ptr = XRT_GRAPHICS_BUFFER_HANDLE_INVALID;
|
|
}
|