mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-02-16 10:40:06 +00:00
xrt: Add dynamic roles to xrt_system_devices
Doesn't fully remove the old way yet. Co-authored-by: Korcan Hussein <korcan.hussein@collabora.com> Co-authored-by: Jakob Bornecrantz <jakob@collabora.com>
This commit is contained in:
parent
f6239ddd34
commit
2718f0506e
src/xrt
include/xrt
ipc/client
targets/common
|
@ -1,4 +1,5 @@
|
|||
// Copyright 2020-2022, Collabora, Ltd.
|
||||
// Copyright 2023, NVIDIA CORPORATION.
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
/*!
|
||||
* @file
|
||||
|
@ -12,9 +13,47 @@
|
|||
#include "xrt/xrt_compiler.h"
|
||||
#include "xrt/xrt_defines.h"
|
||||
|
||||
struct xrt_system_devices;
|
||||
struct xrt_instance;
|
||||
|
||||
|
||||
#define XRT_SYSTEM_MAX_DEVICES (32)
|
||||
|
||||
/*!
|
||||
* Roles of the devices, negative index means unpopulated. When the devices
|
||||
* change the caller will do the needed actions to handle a device changes, for
|
||||
* the OpenXR state tracker this may include switching bound interaction profile
|
||||
* and generating the events for such a change.
|
||||
*
|
||||
* @see xrt_system_devices
|
||||
* @ingroup xrt_iface
|
||||
*/
|
||||
struct xrt_system_roles
|
||||
{
|
||||
/*!
|
||||
* Monotonically increasing generation counter, is increased when ever
|
||||
* the roles is changed. Will always be greater then zero, this is to
|
||||
* make init easier where any cache can start at zero and be guaranteed
|
||||
* to be replaced with a new @ref xrt_system_roles.
|
||||
*/
|
||||
uint64_t generation_id;
|
||||
|
||||
int32_t left;
|
||||
int32_t right;
|
||||
int32_t gamepad;
|
||||
};
|
||||
|
||||
/*!
|
||||
* Guaranteed invalid content, not using designated initializers due to C++.
|
||||
*
|
||||
* @ingroup xrt_iface
|
||||
*/
|
||||
#define XRT_SYSTEM_ROLES_INIT \
|
||||
{ \
|
||||
0, -1, -1, -1 \
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* A collection of @ref xrt_device, and the roles they have been assigned.
|
||||
*
|
||||
|
@ -25,6 +64,17 @@ struct xrt_system_devices
|
|||
struct xrt_device *xdevs[XRT_SYSTEM_MAX_DEVICES];
|
||||
size_t xdev_count;
|
||||
|
||||
struct
|
||||
{
|
||||
struct xrt_device *head;
|
||||
struct xrt_device *eyes;
|
||||
struct
|
||||
{
|
||||
struct xrt_device *left;
|
||||
struct xrt_device *right;
|
||||
} hand_tracking;
|
||||
} static_roles;
|
||||
|
||||
struct
|
||||
{
|
||||
struct xrt_device *head;
|
||||
|
@ -41,6 +91,15 @@ struct xrt_system_devices
|
|||
} roles;
|
||||
|
||||
|
||||
/*!
|
||||
* Function to get the dynamic input device roles from this system
|
||||
* devices, see @ref xrt_system_roles for more information.
|
||||
*
|
||||
* @param[in] xsysd Pointer to self
|
||||
* @param[out] roles Pointer to xrt_system_roles
|
||||
*/
|
||||
xrt_result_t (*get_roles)(struct xrt_system_devices *xsysd, struct xrt_system_roles *out_roles);
|
||||
|
||||
/*!
|
||||
* Destroy all the devices that are owned by this system devices.
|
||||
*
|
||||
|
@ -49,6 +108,18 @@ struct xrt_system_devices
|
|||
void (*destroy)(struct xrt_system_devices *xsysd);
|
||||
};
|
||||
|
||||
/*!
|
||||
* @copydoc xrt_system_devices::get_roles
|
||||
*
|
||||
* Helper for calling through the function pointer.
|
||||
*
|
||||
* @public @memberof xrt_system_devices
|
||||
*/
|
||||
static inline xrt_result_t
|
||||
xrt_system_devices_get_roles(struct xrt_system_devices *xsysd, struct xrt_system_roles *out_roles)
|
||||
{
|
||||
return xsysd->get_roles(xsysd, out_roles);
|
||||
}
|
||||
|
||||
/*!
|
||||
* Destroy an xrt_system_devices and owned devices - helper function.
|
||||
|
|
|
@ -154,6 +154,15 @@ ipc_client_instance_create_system(struct xrt_instance *xinst,
|
|||
|
||||
#undef SET_ROLE
|
||||
|
||||
/*
|
||||
* Fallback code while transitioning to new dynamic roles,
|
||||
* this allows things to at least start since a lot of code
|
||||
* assumes there always is device in the head role.
|
||||
*/
|
||||
if (xsysd->roles.head == NULL) {
|
||||
xsysd->roles.head = xsysd->static_roles.head;
|
||||
}
|
||||
|
||||
// Done here now.
|
||||
if (out_xsysc == NULL) {
|
||||
*out_xsysd = &usysd->base;
|
||||
|
|
|
@ -68,6 +68,15 @@ t_instance_create_system(struct xrt_instance *xinst,
|
|||
return xret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fallback code while transitioning to new dynamic roles,
|
||||
* this allows things to at least start since a lot of code
|
||||
* assumes there always is device in the head role.
|
||||
*/
|
||||
if (xsysd->roles.head == NULL) {
|
||||
xsysd->roles.head = xsysd->static_roles.head;
|
||||
}
|
||||
|
||||
// Early out if we only want devices.
|
||||
if (out_xsysc == NULL) {
|
||||
*out_xsysd = xsysd;
|
||||
|
|
|
@ -43,6 +43,15 @@ t_instance_create_system(struct xrt_instance *xinst,
|
|||
return xret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fallback code while transitioning to new dynamic roles,
|
||||
* this allows things to at least start since a lot of code
|
||||
* assumes there always is device in the head role.
|
||||
*/
|
||||
if (xsysd->roles.head == NULL) {
|
||||
xsysd->roles.head = xsysd->static_roles.head;
|
||||
}
|
||||
|
||||
*out_xsysd = xsysd;
|
||||
*out_xso = xso;
|
||||
|
||||
|
|
Loading…
Reference in a new issue