From 962de77ca0c831061d1f4fc2a8411200c15f3ff7 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Wed, 24 Jul 2019 17:15:15 +0100 Subject: [PATCH] st/oxr: Carry around extra xrt_devices Pretty much only used for enabling 3 PS Move Controllers right now. --- src/xrt/state_trackers/oxr/oxr_input.c | 8 ++++--- src/xrt/state_trackers/oxr/oxr_instance.c | 28 +++++++---------------- src/xrt/state_trackers/oxr/oxr_objects.h | 21 ++++++++++++----- src/xrt/state_trackers/oxr/oxr_system.c | 20 +++++++++++----- src/xrt/state_trackers/oxr/oxr_xdev.c | 13 +++++++++++ 5 files changed, 55 insertions(+), 35 deletions(-) diff --git a/src/xrt/state_trackers/oxr/oxr_input.c b/src/xrt/state_trackers/oxr/oxr_input.c index 75728a380..38645450b 100644 --- a/src/xrt/state_trackers/oxr/oxr_input.c +++ b/src/xrt/state_trackers/oxr/oxr_input.c @@ -664,9 +664,11 @@ oxr_action_sync_data(struct oxr_logger* log, // Synchronize outputs to this time. int64_t now = time_state_get_now(sess->sys->inst->timekeeping); - oxr_xdev_update(sess->sys->head, sess->sys->inst->timekeeping); - oxr_xdev_update(sess->sys->left, sess->sys->inst->timekeeping); - oxr_xdev_update(sess->sys->right, sess->sys->inst->timekeeping); + // Loop over all xdev devices. + for (size_t i = 0; i < sess->sys->num_xdevs; i++) { + oxr_xdev_update(sess->sys->xdevs[i], + sess->sys->inst->timekeeping); + } //! @todo These semantics below are all wrong! diff --git a/src/xrt/state_trackers/oxr/oxr_instance.c b/src/xrt/state_trackers/oxr/oxr_instance.c index 096d3c532..e316df2dc 100644 --- a/src/xrt/state_trackers/oxr/oxr_instance.c +++ b/src/xrt/state_trackers/oxr/oxr_instance.c @@ -36,19 +36,6 @@ radtodeg_for_display(float radians) 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 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); } - xdev_destroy(&inst->system.head); - xdev_destroy(&inst->system.left); - xdev_destroy(&inst->system.right); + for (size_t i = 0; i < inst->system.num_xdevs; i++) { + oxr_xdev_destroy(&inst->system.xdevs[i]); + } 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); } +#define NUM_XDEVS 16 + XrResult oxr_instance_create(struct oxr_logger *log, const XrInstanceCreateInfo *createInfo, struct oxr_instance **out_instance) { struct oxr_instance *inst = NULL; - struct xrt_device *xdevs[3] = {0}; + struct xrt_device *xdevs[NUM_XDEVS] = {0}; int h_ret, p_ret; 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)"); } - p_ret = xrt_prober_select(inst->prober, xdevs, 3); + p_ret = xrt_prober_select(inst->prober, xdevs, NUM_XDEVS); if (p_ret != 0) { xrt_prober_destroy(&inst->prober); 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; } - oxr_system_fill_in(log, inst, 1, &inst->system, xdevs[0], xdevs[1], - xdevs[2]); + oxr_system_fill_in(log, inst, 1, &inst->system, xdevs, NUM_XDEVS); inst->timekeeping = time_state_create(); diff --git a/src/xrt/state_trackers/oxr/oxr_objects.h b/src/xrt/state_trackers/oxr/oxr_objects.h index 7539fcf85..ffe2d8fbc 100644 --- a/src/xrt/state_trackers/oxr/oxr_objects.h +++ b/src/xrt/state_trackers/oxr/oxr_objects.h @@ -535,9 +535,8 @@ oxr_system_fill_in(struct oxr_logger *log, struct oxr_instance *inst, XrSystemId systemId, struct oxr_system *sys, - struct xrt_device *head, - struct xrt_device *left, - struct xrt_device *right); + struct xrt_device **xdevs, + size_t num_xdevs); XrResult 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 oxr_xdev_update(struct xrt_device *xdev, struct time_state *timekeeping); @@ -765,9 +767,16 @@ struct oxr_system { struct oxr_instance *inst; - struct xrt_device *head; - struct xrt_device *left; - struct xrt_device *right; + union { + struct + { + struct xrt_device *head; + struct xrt_device *left; + struct xrt_device *right; + }; + struct xrt_device *xdevs[16]; + }; + size_t num_xdevs; XrSystemId systemId; diff --git a/src/xrt/state_trackers/oxr/oxr_system.c b/src/xrt/state_trackers/oxr/oxr_system.c index 4c5aaebba..dd3e81878 100644 --- a/src/xrt/state_trackers/oxr/oxr_system.c +++ b/src/xrt/state_trackers/oxr/oxr_system.c @@ -93,10 +93,21 @@ oxr_system_fill_in(struct oxr_logger *log, struct oxr_instance *inst, XrSystemId systemId, struct oxr_system *sys, - struct xrt_device *head, - struct xrt_device *left, - struct xrt_device *right) + struct xrt_device **xdevs, + size_t num_xdevs) { + + 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) { return oxr_error(log, XR_ERROR_INITIALIZATION_FAILED, " failed to probe device"); @@ -122,9 +133,6 @@ oxr_system_fill_in(struct oxr_logger *log, } // clang-format off - sys->head = head; - sys->left = left; - sys->right = right; sys->inst = inst; sys->systemId = systemId; sys->form_factor = XR_FORM_FACTOR_HEAD_MOUNTED_DISPLAY; diff --git a/src/xrt/state_trackers/oxr/oxr_xdev.c b/src/xrt/state_trackers/oxr/oxr_xdev.c index 89f902505..b8e1a1d45 100644 --- a/src/xrt/state_trackers/oxr/oxr_xdev.c +++ b/src/xrt/state_trackers/oxr/oxr_xdev.c @@ -13,6 +13,19 @@ #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 oxr_xdev_update(struct xrt_device *xdev, struct time_state *timekeeping) {