The open source OpenXR runtime

u/builders: Add xrt_builder_helpers

+163 -1
+2
src/xrt/auxiliary/CMakeLists.txt
··· 153 153 aux_util STATIC 154 154 util/u_bitwise.c 155 155 util/u_bitwise.h 156 + util/u_builders.c 157 + util/u_builders.h 156 158 util/u_debug.c 157 159 util/u_debug.h 158 160 util/u_device.c
+74
src/xrt/auxiliary/util/u_builders.c
··· 1 + // Copyright 2022, Collabora, Ltd. 2 + // SPDX-License-Identifier: BSL-1.0 3 + /*! 4 + * @file 5 + * @brief Helpers for @ref xrt_builder implementations. 6 + * @author Jakob Bornecrantz <jakob@collabora.com> 7 + * @ingroup aux_util 8 + */ 9 + 10 + #include "xrt/xrt_prober.h" 11 + #include "u_builders.h" 12 + 13 + 14 + /* 15 + * 16 + * 'Exported' function. 17 + * 18 + */ 19 + 20 + struct xrt_prober_device * 21 + u_builder_find_prober_device(struct xrt_prober_device *const *xpdevs, 22 + size_t xpdev_count, 23 + uint16_t product_id, 24 + uint16_t vendor_id) 25 + { 26 + for (size_t i = 0; i < xpdev_count; i++) { 27 + struct xrt_prober_device *xpdev = xpdevs[i]; 28 + if (xpdev->product_id != product_id || xpdev->vendor_id != vendor_id) { 29 + continue; 30 + } 31 + 32 + return xpdev; 33 + } 34 + 35 + return NULL; 36 + } 37 + 38 + void 39 + u_builder_search(struct xrt_prober *xp, 40 + struct xrt_prober_device *const *xpdevs, 41 + size_t xpdev_count, 42 + const struct u_builder_search_filter *filters, 43 + size_t filter_count, 44 + struct u_builder_search_results *results) 45 + { 46 + for (size_t i = 0; i < xpdev_count; i++) { 47 + struct xrt_prober_device *xpdev = xpdevs[i]; 48 + bool match = false; 49 + 50 + for (size_t k = 0; k < filter_count; k++) { 51 + struct u_builder_search_filter f = filters[k]; 52 + 53 + if (xpdev->product_id != f.product_id || // 54 + xpdev->vendor_id != f.vendor_id || // 55 + xpdev->bus != f.bus_type) { // 56 + continue; 57 + } 58 + 59 + match = true; 60 + break; 61 + } 62 + 63 + if (!match) { 64 + continue; 65 + } 66 + 67 + results->xpdevs[results->xpdev_count++] = xpdev; 68 + 69 + // Abort if full. 70 + if (results->xpdev_count >= ARRAY_SIZE(results->xpdevs)) { 71 + return; 72 + } 73 + } 74 + }
+82
src/xrt/auxiliary/util/u_builders.h
··· 1 + // Copyright 2022, Collabora, Ltd. 2 + // SPDX-License-Identifier: BSL-1.0 3 + /*! 4 + * @file 5 + * @brief Helpers for @ref xrt_builder implementations. 6 + * @author Jakob Bornecrantz <jakob@collabora.com> 7 + * @ingroup aux_util 8 + */ 9 + 10 + #pragma once 11 + 12 + #include "xrt/xrt_prober.h" 13 + 14 + 15 + #ifdef __cplusplus 16 + extern "C" { 17 + #endif 18 + 19 + struct xrt_prober_device; 20 + 21 + /*! 22 + * Max return of the number @ref xrt_prober_device. 23 + * 24 + * @ingroup aux_util 25 + */ 26 + #define U_BUILDER_SEARCH_MAX (16) // 16 Vive trackers 27 + 28 + /*! 29 + * A filter to match the against. 30 + * 31 + * @ingroup aux_util 32 + */ 33 + struct u_builder_search_filter 34 + { 35 + uint16_t vendor_id; 36 + uint16_t product_id; 37 + enum xrt_bus_type bus_type; 38 + }; 39 + 40 + /*! 41 + * Results of a search of devices. 42 + * 43 + * @ingroup aux_util 44 + */ 45 + struct u_builder_search_results 46 + { 47 + //! Out field of found @ref xrt_prober_device. 48 + struct xrt_prober_device *xpdevs[U_BUILDER_SEARCH_MAX]; 49 + 50 + //! Number of found devices. 51 + size_t xpdev_count; 52 + }; 53 + 54 + /*! 55 + * Find the first @ref xrt_prober_device in the prober list. 56 + * 57 + * @ingroup aux_util 58 + */ 59 + struct xrt_prober_device * 60 + u_builder_find_prober_device(struct xrt_prober_device *const *xpdevs, 61 + size_t xpdev_count, 62 + uint16_t product_id, 63 + uint16_t vendor_id); 64 + 65 + /*! 66 + * Find all of the @ref xrt_prober_device that matches any in the given list of 67 + * @ref u_builder_search_filter filters. 68 + * 69 + * @ingroup aux_util 70 + */ 71 + void 72 + u_builder_search(struct xrt_prober *xp, 73 + struct xrt_prober_device *const *xpdevs, 74 + size_t xpdev_count, 75 + const struct u_builder_search_filter *filters, 76 + size_t filter_count, 77 + struct u_builder_search_results *results); 78 + 79 + 80 + #ifdef __cplusplus 81 + } 82 + #endif
+5 -1
src/xrt/auxiliary/util/u_system_helpers.h
··· 13 13 #include "xrt/xrt_frame.h" 14 14 #include "xrt/xrt_system.h" 15 15 #include "xrt/xrt_instance.h" 16 + #include "xrt/xrt_tracking.h" 16 17 17 18 18 19 #ifdef __cplusplus ··· 33 34 { 34 35 struct xrt_system_devices base; 35 36 36 - //! Frame context for visual tracking. 37 + //! Optional frame context for visual tracking. 37 38 struct xrt_frame_context xfctx; 39 + 40 + //! Optional shared tracking origin. 41 + struct xrt_tracking_origin origin; 38 42 }; 39 43 40 44 /*!