mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-01-01 12:46:12 +00:00
ipc: Add support for reference space usage
This commit is contained in:
parent
5a789ff623
commit
a0a0f7cfa6
|
@ -7,6 +7,7 @@
|
|||
* @ingroup ipc_client
|
||||
*/
|
||||
|
||||
#include "xrt/xrt_defines.h"
|
||||
#include "xrt/xrt_space.h"
|
||||
|
||||
#include "ipc_client_generated.h"
|
||||
|
@ -26,6 +27,8 @@ struct ipc_client_space_overseer
|
|||
struct xrt_space_overseer base;
|
||||
|
||||
struct ipc_connection *ipc_c;
|
||||
|
||||
struct xrt_reference ref_space_use[XRT_SPACE_REFERENCE_TYPE_COUNT];
|
||||
};
|
||||
|
||||
|
||||
|
@ -171,6 +174,42 @@ locate_device(struct xrt_space_overseer *xso,
|
|||
IPC_CHK_ALWAYS_RET(icspo->ipc_c, xret, "ipc_call_space_locate_device");
|
||||
}
|
||||
|
||||
static xrt_result_t
|
||||
ref_space_inc(struct xrt_space_overseer *xso, enum xrt_reference_space_type type)
|
||||
{
|
||||
struct ipc_client_space_overseer *icspo = ipc_client_space_overseer(xso);
|
||||
xrt_result_t xret;
|
||||
|
||||
// No more checking then this.
|
||||
assert(type < XRT_SPACE_REFERENCE_TYPE_COUNT);
|
||||
|
||||
// If it wasn't zero nothing to do.
|
||||
if (!xrt_reference_inc_and_was_zero(&icspo->ref_space_use[type])) {
|
||||
return XRT_SUCCESS;
|
||||
}
|
||||
|
||||
xret = ipc_call_space_mark_ref_space_in_use(icspo->ipc_c, type);
|
||||
IPC_CHK_ALWAYS_RET(icspo->ipc_c, xret, "ipc_call_space_mark_ref_space_in_use");
|
||||
}
|
||||
|
||||
static xrt_result_t
|
||||
ref_space_dec(struct xrt_space_overseer *xso, enum xrt_reference_space_type type)
|
||||
{
|
||||
struct ipc_client_space_overseer *icspo = ipc_client_space_overseer(xso);
|
||||
xrt_result_t xret;
|
||||
|
||||
// No more checking then this.
|
||||
assert(type < XRT_SPACE_REFERENCE_TYPE_COUNT);
|
||||
|
||||
// If it is not zero we are done.
|
||||
if (!xrt_reference_dec_and_is_zero(&icspo->ref_space_use[type])) {
|
||||
return XRT_SUCCESS;
|
||||
}
|
||||
|
||||
xret = ipc_call_space_unmark_ref_space_in_use(icspo->ipc_c, type);
|
||||
IPC_CHK_ALWAYS_RET(icspo->ipc_c, xret, "ipc_call_space_unmark_ref_space_in_use");
|
||||
}
|
||||
|
||||
static void
|
||||
destroy(struct xrt_space_overseer *xso)
|
||||
{
|
||||
|
@ -219,6 +258,8 @@ ipc_client_space_overseer_create(struct ipc_connection *ipc_c)
|
|||
icspo->base.create_pose_space = create_pose_space;
|
||||
icspo->base.locate_space = locate_space;
|
||||
icspo->base.locate_device = locate_device;
|
||||
icspo->base.ref_space_inc = ref_space_inc;
|
||||
icspo->base.ref_space_dec = ref_space_dec;
|
||||
icspo->base.destroy = destroy;
|
||||
icspo->ipc_c = ipc_c;
|
||||
|
||||
|
|
|
@ -117,6 +117,9 @@ struct ipc_client_state
|
|||
//! Ptrs to the spaces.
|
||||
struct xtr_space *xspcs[IPC_MAX_CLIENT_SPACES];
|
||||
|
||||
//! Which of the references spaces is the client using.
|
||||
bool ref_space_used[XRT_SPACE_REFERENCE_TYPE_COUNT];
|
||||
|
||||
//! Socket fd used for client comms
|
||||
struct ipc_message_channel imc;
|
||||
|
||||
|
|
|
@ -82,6 +82,17 @@ set_swapchain_info(volatile struct ipc_client_state *ics,
|
|||
ics->swapchain_data[index].image_count = xsc->image_count;
|
||||
}
|
||||
|
||||
static xrt_result_t
|
||||
validate_reference_space_type(volatile struct ipc_client_state *ics, enum xrt_reference_space_type type)
|
||||
{
|
||||
if ((uint32_t)type >= XRT_SPACE_REFERENCE_TYPE_COUNT) {
|
||||
IPC_ERROR(ics->server, "Invalid reference space type %u", type);
|
||||
return XRT_ERROR_IPC_FAILURE;
|
||||
}
|
||||
|
||||
return XRT_SUCCESS;
|
||||
}
|
||||
|
||||
static xrt_result_t
|
||||
validate_space_id(volatile struct ipc_client_state *ics, int64_t space_id, struct xrt_space **out_xspc)
|
||||
{
|
||||
|
@ -477,6 +488,63 @@ ipc_handle_space_destroy(volatile struct ipc_client_state *ics, uint32_t space_i
|
|||
return XRT_SUCCESS;
|
||||
}
|
||||
|
||||
xrt_result_t
|
||||
ipc_handle_space_mark_ref_space_in_use(volatile struct ipc_client_state *ics, enum xrt_reference_space_type type)
|
||||
{
|
||||
struct xrt_space_overseer *xso = ics->server->xso;
|
||||
xrt_result_t xret;
|
||||
|
||||
xret = validate_reference_space_type(ics, type);
|
||||
if (xret != XRT_SUCCESS) {
|
||||
return XRT_ERROR_IPC_FAILURE;
|
||||
}
|
||||
|
||||
// Is this space already used?
|
||||
if (ics->ref_space_used[type]) {
|
||||
IPC_ERROR(ics->server, "Space '%u' already used!", type);
|
||||
return XRT_ERROR_IPC_FAILURE;
|
||||
}
|
||||
|
||||
xret = xrt_space_overseer_ref_space_inc(xso, type);
|
||||
if (xret != XRT_SUCCESS) {
|
||||
IPC_ERROR(ics->server, "xrt_space_overseer_ref_space_inc failed");
|
||||
return xret;
|
||||
}
|
||||
|
||||
// Can now mark it as used.
|
||||
ics->ref_space_used[type] = true;
|
||||
|
||||
return XRT_SUCCESS;
|
||||
}
|
||||
|
||||
xrt_result_t
|
||||
ipc_handle_space_unmark_ref_space_in_use(volatile struct ipc_client_state *ics, enum xrt_reference_space_type type)
|
||||
{
|
||||
struct xrt_space_overseer *xso = ics->server->xso;
|
||||
xrt_result_t xret;
|
||||
|
||||
xret = validate_reference_space_type(ics, type);
|
||||
if (xret != XRT_SUCCESS) {
|
||||
return XRT_ERROR_IPC_FAILURE;
|
||||
}
|
||||
|
||||
if (!ics->ref_space_used[type]) {
|
||||
IPC_ERROR(ics->server, "Space '%u' not used!", type);
|
||||
return XRT_ERROR_IPC_FAILURE;
|
||||
}
|
||||
|
||||
xret = xrt_space_overseer_ref_space_dec(xso, type);
|
||||
if (xret != XRT_SUCCESS) {
|
||||
IPC_ERROR(ics->server, "xrt_space_overseer_ref_space_dec failed");
|
||||
return xret;
|
||||
}
|
||||
|
||||
// Now we can mark it as not used.
|
||||
ics->ref_space_used[type] = false;
|
||||
|
||||
return XRT_SUCCESS;
|
||||
}
|
||||
|
||||
xrt_result_t
|
||||
ipc_handle_compositor_get_info(volatile struct ipc_client_state *ics, struct xrt_compositor_info *out_info)
|
||||
{
|
||||
|
|
|
@ -67,6 +67,17 @@ common_shutdown(volatile struct ipc_client_state *ics)
|
|||
xrt_space_reference((struct xrt_space **)&ics->xspcs[i], NULL);
|
||||
}
|
||||
|
||||
// Mark an still in use reference spaces as no longer used.
|
||||
for (uint32_t i = 0; i < ARRAY_SIZE(ics->ref_space_used); i++) {
|
||||
bool used = ics->ref_space_used[i];
|
||||
if (!used) {
|
||||
continue;
|
||||
}
|
||||
|
||||
xrt_space_overseer_ref_space_dec(ics->server->xso, i);
|
||||
ics->ref_space_used[i] = false;
|
||||
}
|
||||
|
||||
// Should we stop the server when a client disconnects?
|
||||
if (ics->server->exit_on_disconnect) {
|
||||
ics->server->running = false;
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "xrt/xrt_instance.h"
|
||||
#include "xrt/xrt_compositor.h"
|
||||
#include "xrt/xrt_device.h"
|
||||
#include "xrt/xrt_space.h"
|
||||
#include "xrt/xrt_tracking.h"
|
||||
#include "xrt/xrt_config_build.h"
|
||||
|
||||
|
|
|
@ -136,6 +136,18 @@
|
|||
]
|
||||
},
|
||||
|
||||
"space_mark_ref_space_in_use": {
|
||||
"in": [
|
||||
{"name": "type", "type": "enum xrt_reference_space_type"}
|
||||
]
|
||||
},
|
||||
|
||||
"space_unmark_ref_space_in_use": {
|
||||
"in": [
|
||||
{"name": "type", "type": "enum xrt_reference_space_type"}
|
||||
]
|
||||
},
|
||||
|
||||
"compositor_get_info": {
|
||||
"out": [
|
||||
{"name": "info", "type": "struct xrt_compositor_info"}
|
||||
|
|
Loading…
Reference in a new issue