st/oxr: Carry around extra xrt_devices

Pretty much only used for enabling 3 PS Move Controllers right now.
This commit is contained in:
Jakob Bornecrantz 2019-07-24 17:15:15 +01:00
parent 2abc98dbec
commit 962de77ca0
5 changed files with 55 additions and 35 deletions

View file

@ -664,9 +664,11 @@ oxr_action_sync_data(struct oxr_logger* log,
// Synchronize outputs to this time. // Synchronize outputs to this time.
int64_t now = time_state_get_now(sess->sys->inst->timekeeping); int64_t now = time_state_get_now(sess->sys->inst->timekeeping);
oxr_xdev_update(sess->sys->head, sess->sys->inst->timekeeping); // Loop over all xdev devices.
oxr_xdev_update(sess->sys->left, sess->sys->inst->timekeeping); for (size_t i = 0; i < sess->sys->num_xdevs; i++) {
oxr_xdev_update(sess->sys->right, sess->sys->inst->timekeeping); oxr_xdev_update(sess->sys->xdevs[i],
sess->sys->inst->timekeeping);
}
//! @todo These semantics below are all wrong! //! @todo These semantics below are all wrong!

View file

@ -36,19 +36,6 @@ radtodeg_for_display(float radians)
return (int32_t)(radians * 180 * M_1_PI); return (int32_t)(radians * 180 * M_1_PI);
} }
static inline void
xdev_destroy(struct xrt_device **xdev_ptr)
{
struct xrt_device *xdev = *xdev_ptr;
if (xdev == NULL) {
return;
}
xdev->destroy(xdev);
*xdev_ptr = NULL;
}
static XrResult static XrResult
oxr_instance_destroy(struct oxr_logger *log, struct oxr_handle_base *hb) oxr_instance_destroy(struct oxr_logger *log, struct oxr_handle_base *hb)
{ {
@ -62,9 +49,9 @@ oxr_instance_destroy(struct oxr_logger *log, struct oxr_handle_base *hb)
u_hashset_destroy(&inst->path_store); u_hashset_destroy(&inst->path_store);
} }
xdev_destroy(&inst->system.head); for (size_t i = 0; i < inst->system.num_xdevs; i++) {
xdev_destroy(&inst->system.left); oxr_xdev_destroy(&inst->system.xdevs[i]);
xdev_destroy(&inst->system.right); }
xrt_prober_destroy(&inst->prober); xrt_prober_destroy(&inst->prober);
@ -85,13 +72,15 @@ cache_path(struct oxr_logger *log,
oxr_path_get_or_create(log, inst, str, strlen(str), out_path); oxr_path_get_or_create(log, inst, str, strlen(str), out_path);
} }
#define NUM_XDEVS 16
XrResult XrResult
oxr_instance_create(struct oxr_logger *log, oxr_instance_create(struct oxr_logger *log,
const XrInstanceCreateInfo *createInfo, const XrInstanceCreateInfo *createInfo,
struct oxr_instance **out_instance) struct oxr_instance **out_instance)
{ {
struct oxr_instance *inst = NULL; struct oxr_instance *inst = NULL;
struct xrt_device *xdevs[3] = {0}; struct xrt_device *xdevs[NUM_XDEVS] = {0};
int h_ret, p_ret; int h_ret, p_ret;
OXR_ALLOCATE_HANDLE_OR_RETURN(log, inst, OXR_XR_DEBUG_INSTANCE, OXR_ALLOCATE_HANDLE_OR_RETURN(log, inst, OXR_XR_DEBUG_INSTANCE,
@ -125,7 +114,7 @@ oxr_instance_create(struct oxr_logger *log,
"Failed to probe device(s)"); "Failed to probe device(s)");
} }
p_ret = xrt_prober_select(inst->prober, xdevs, 3); p_ret = xrt_prober_select(inst->prober, xdevs, NUM_XDEVS);
if (p_ret != 0) { if (p_ret != 0) {
xrt_prober_destroy(&inst->prober); xrt_prober_destroy(&inst->prober);
return oxr_error(log, XR_ERROR_RUNTIME_FAILURE, return oxr_error(log, XR_ERROR_RUNTIME_FAILURE,
@ -173,8 +162,7 @@ oxr_instance_create(struct oxr_logger *log,
dev->hmd->views[1].fov.angle_down = down_override; dev->hmd->views[1].fov.angle_down = down_override;
} }
oxr_system_fill_in(log, inst, 1, &inst->system, xdevs[0], xdevs[1], oxr_system_fill_in(log, inst, 1, &inst->system, xdevs, NUM_XDEVS);
xdevs[2]);
inst->timekeeping = time_state_create(); inst->timekeeping = time_state_create();

View file

@ -535,9 +535,8 @@ oxr_system_fill_in(struct oxr_logger *log,
struct oxr_instance *inst, struct oxr_instance *inst,
XrSystemId systemId, XrSystemId systemId,
struct oxr_system *sys, struct oxr_system *sys,
struct xrt_device *head, struct xrt_device **xdevs,
struct xrt_device *left, size_t num_xdevs);
struct xrt_device *right);
XrResult XrResult
oxr_system_verify_id(struct oxr_logger *log, oxr_system_verify_id(struct oxr_logger *log,
@ -612,6 +611,9 @@ oxr_event_push_XrEventDataSessionStateChanged(struct oxr_logger *log,
* *
*/ */
void
oxr_xdev_destroy(struct xrt_device **xdev_ptr);
void void
oxr_xdev_update(struct xrt_device *xdev, struct time_state *timekeeping); oxr_xdev_update(struct xrt_device *xdev, struct time_state *timekeeping);
@ -765,9 +767,16 @@ struct oxr_system
{ {
struct oxr_instance *inst; struct oxr_instance *inst;
struct xrt_device *head; union {
struct xrt_device *left; struct
struct xrt_device *right; {
struct xrt_device *head;
struct xrt_device *left;
struct xrt_device *right;
};
struct xrt_device *xdevs[16];
};
size_t num_xdevs;
XrSystemId systemId; XrSystemId systemId;

View file

@ -93,10 +93,21 @@ oxr_system_fill_in(struct oxr_logger *log,
struct oxr_instance *inst, struct oxr_instance *inst,
XrSystemId systemId, XrSystemId systemId,
struct oxr_system *sys, struct oxr_system *sys,
struct xrt_device *head, struct xrt_device **xdevs,
struct xrt_device *left, size_t num_xdevs)
struct xrt_device *right)
{ {
for (uint32_t i = 4; i < ARRAY_SIZE(sys->xdevs); i++) {
sys->xdevs[i] = xdevs[i];
}
for (size_t i = ARRAY_SIZE(sys->xdevs); i < num_xdevs; i++) {
oxr_xdev_destroy(&xdevs[i]);
}
struct xrt_device *head = sys->head;
struct xrt_device *left = sys->left;
struct xrt_device *right = sys->right;
if (head == NULL) { if (head == NULL) {
return oxr_error(log, XR_ERROR_INITIALIZATION_FAILED, return oxr_error(log, XR_ERROR_INITIALIZATION_FAILED,
" failed to probe device"); " failed to probe device");
@ -122,9 +133,6 @@ oxr_system_fill_in(struct oxr_logger *log,
} }
// clang-format off // clang-format off
sys->head = head;
sys->left = left;
sys->right = right;
sys->inst = inst; sys->inst = inst;
sys->systemId = systemId; sys->systemId = systemId;
sys->form_factor = XR_FORM_FACTOR_HEAD_MOUNTED_DISPLAY; sys->form_factor = XR_FORM_FACTOR_HEAD_MOUNTED_DISPLAY;

View file

@ -13,6 +13,19 @@
#include "oxr_objects.h" #include "oxr_objects.h"
void
oxr_xdev_destroy(struct xrt_device **xdev_ptr)
{
struct xrt_device *xdev = *xdev_ptr;
if (xdev == NULL) {
return;
}
xdev->destroy(xdev);
*xdev_ptr = NULL;
}
void void
oxr_xdev_update(struct xrt_device *xdev, struct time_state *timekeeping) oxr_xdev_update(struct xrt_device *xdev, struct time_state *timekeeping)
{ {