mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-01-01 12:46:12 +00:00
u/handles: Add graphics sync handle helpers.
This commit is contained in:
parent
c876087ee7
commit
61c1044089
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2020, Collabora, Ltd.
|
||||
// Copyright 2020-2021, Collabora, Ltd.
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
/*!
|
||||
* @file
|
||||
|
@ -11,6 +11,12 @@
|
|||
|
||||
#include "u_handles.h"
|
||||
|
||||
/*
|
||||
*
|
||||
* Graphics Buffer Handles
|
||||
*
|
||||
*/
|
||||
|
||||
#if defined(XRT_GRAPHICS_BUFFER_HANDLE_IS_AHARDWAREBUFFER)
|
||||
#include <android/hardware_buffer.h>
|
||||
|
||||
|
@ -89,3 +95,71 @@ u_graphics_buffer_unref(xrt_graphics_buffer_handle_t *handle_ptr)
|
|||
release_graphics_handle(handle);
|
||||
*handle_ptr = XRT_GRAPHICS_BUFFER_HANDLE_INVALID;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* Graphics Sync Handles
|
||||
*
|
||||
*/
|
||||
|
||||
#if defined(XRT_GRAPHICS_SYNC_HANDLE_IS_FD)
|
||||
#include <unistd.h>
|
||||
|
||||
static inline void
|
||||
release_sync_handle(xrt_graphics_sync_handle_t handle)
|
||||
{
|
||||
close(handle);
|
||||
}
|
||||
|
||||
static inline xrt_graphics_sync_handle_t
|
||||
ref_sync_handle(xrt_graphics_sync_handle_t handle)
|
||||
{
|
||||
return dup(handle);
|
||||
}
|
||||
|
||||
#elif defined(XRT_GRAPHICS_SYNC_HANDLE_IS_WIN32_HANDLE)
|
||||
|
||||
static inline void
|
||||
release_sync_handle(xrt_graphics_sync_handle_t handle)
|
||||
{
|
||||
CloseHandle(handle);
|
||||
}
|
||||
|
||||
static inline xrt_graphics_sync_handle_t
|
||||
ref_sync_handle(xrt_graphics_sync_handle_t handle)
|
||||
{
|
||||
HANDLE self = GetCurrentProcess();
|
||||
HANDLE result = NULL;
|
||||
if (DuplicateHandle(self, handle, self, &result, 0, FALSE, DUPLICATE_SAME_ACCESS) != 0) {
|
||||
return result;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#else
|
||||
#error "need port"
|
||||
#endif
|
||||
|
||||
xrt_graphics_sync_handle_t
|
||||
u_graphics_sync_ref(xrt_graphics_sync_handle_t handle)
|
||||
{
|
||||
if (xrt_graphics_sync_handle_is_valid(handle)) {
|
||||
return ref_sync_handle(handle);
|
||||
}
|
||||
|
||||
return XRT_GRAPHICS_SYNC_HANDLE_INVALID;
|
||||
}
|
||||
|
||||
void
|
||||
u_graphics_sync_unref(xrt_graphics_sync_handle_t *handle_ptr)
|
||||
{
|
||||
if (handle_ptr == NULL) {
|
||||
return;
|
||||
}
|
||||
xrt_graphics_sync_handle_t handle = *handle_ptr;
|
||||
if (!xrt_graphics_sync_handle_is_valid(handle)) {
|
||||
return;
|
||||
}
|
||||
release_sync_handle(handle);
|
||||
*handle_ptr = XRT_GRAPHICS_SYNC_HANDLE_INVALID;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2020, Collabora, Ltd.
|
||||
// Copyright 2020-20211, Collabora, Ltd.
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
/*!
|
||||
* @file
|
||||
|
@ -17,13 +17,15 @@
|
|||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* Increase the reference count on the buffer handle, returning the new
|
||||
* reference.
|
||||
*
|
||||
* Depending on the underlying type, the value may be the same or different than
|
||||
* what was passed in. It should be retained for use at release time,
|
||||
* regardless.
|
||||
*
|
||||
* Depending on the underlying type, the value may be the same or different than what was passed in. It should be
|
||||
* retained for use at release time, regardless. (For example, if the underlying native handle does not expose reference
|
||||
* counting, it may be duplicated and the duplicate returned.)
|
||||
*
|
||||
* @public @memberof xrt_graphics_buffer_handle_t
|
||||
*/
|
||||
|
@ -42,6 +44,31 @@ u_graphics_buffer_ref(xrt_graphics_buffer_handle_t handle);
|
|||
void
|
||||
u_graphics_buffer_unref(xrt_graphics_buffer_handle_t *handle);
|
||||
|
||||
/*!
|
||||
* Increase the reference count on the sync handle, returning the new
|
||||
* reference.
|
||||
*
|
||||
* Depending on the underlying type, the value may be the same or different than what was passed in. It should be
|
||||
* retained for use at release time, regardless. (For example, if the underlying native handle does not expose reference
|
||||
* counting, it may be duplicated and the duplicate returned.)
|
||||
*
|
||||
* @public @memberof xrt_graphics_sync_handle_t
|
||||
*/
|
||||
xrt_graphics_sync_handle_t
|
||||
u_graphics_sync_ref(xrt_graphics_sync_handle_t handle);
|
||||
|
||||
/*!
|
||||
* Decrease the reference count/release the handle reference passed in.
|
||||
*
|
||||
* Be sure to only call this once per handle.
|
||||
*
|
||||
* Performs null-check and clears the value after unreferencing.
|
||||
*
|
||||
* @public @memberof xrt_graphics_sync_handle_t
|
||||
*/
|
||||
void
|
||||
u_graphics_sync_unref(xrt_graphics_sync_handle_t *handle);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue