The open source OpenXR runtime

t/common: Use new u_builder helper

+268 -442
+26 -44
src/xrt/targets/common/target_builder_legacy.c
··· 111 111 } 112 112 113 113 static xrt_result_t 114 - legacy_open_system(struct xrt_builder *xb, 115 - cJSON *config, 116 - struct xrt_prober *xp, 117 - struct xrt_system_devices **out_xsysd, 118 - struct xrt_space_overseer **out_xso) 114 + legacy_open_system_impl(struct xrt_builder *xb, 115 + cJSON *config, 116 + struct xrt_prober *xp, 117 + struct xrt_tracking_origin *origin, 118 + struct xrt_system_devices *xsysd, 119 + struct xrt_frame_context *xfctx, 120 + struct u_builder_roles_helper *ubrh) 119 121 { 120 122 xrt_result_t xret; 121 123 int ret; 122 - 123 - assert(out_xsysd != NULL); 124 - assert(*out_xsysd == NULL); 125 124 126 125 127 126 /* ··· 133 132 return xret; 134 133 } 135 134 136 - // Use the static system devices helper, no dynamic roles. 137 - struct u_system_devices_static *usysds = u_system_devices_static_allocate(); 138 - struct xrt_system_devices *xsysd = &usysds->base.base; 139 - 140 135 ret = xrt_prober_select(xp, xsysd->xdevs, ARRAY_SIZE(xsysd->xdevs)); 141 136 if (ret < 0) { 142 - xrt_system_devices_destroy(&xsysd); 143 137 return XRT_ERROR_DEVICE_CREATION_FAILED; 144 138 } 145 139 ··· 179 173 right_ht = u_system_devices_get_ht_device_right(xsysd); 180 174 181 175 // Assign to role(s). 182 - xsysd->static_roles.head = head; 183 - xsysd->static_roles.hand_tracking.left = left_ht; 184 - xsysd->static_roles.hand_tracking.right = right_ht; 185 - 186 - u_system_devices_static_finalize( // 187 - usysds, // usysds 188 - left, // left 189 - right); // right 190 - 191 - 192 - /* 193 - * Done. 194 - */ 195 - 196 - *out_xsysd = xsysd; 197 - u_builder_create_space_overseer_legacy( // 198 - head, // head 199 - left, // left 200 - right, // right 201 - xsysd->xdevs, // xdevs 202 - xsysd->xdev_count, // xdev_count 203 - out_xso); // out_xso 176 + ubrh->head = head; 177 + ubrh->left = left; 178 + ubrh->right = right; 179 + ubrh->hand_tracking.left = left_ht; 180 + ubrh->hand_tracking.right = right_ht; 204 181 205 182 return XRT_SUCCESS; 206 183 } ··· 221 198 struct xrt_builder * 222 199 t_builder_legacy_create(void) 223 200 { 224 - struct xrt_builder *xb = U_TYPED_CALLOC(struct xrt_builder); 225 - xb->estimate_system = legacy_estimate_system; 226 - xb->open_system = legacy_open_system; 227 - xb->destroy = legacy_destroy; 228 - xb->identifier = "legacy"; 229 - xb->name = "Legacy probing system"; 230 - xb->driver_identifiers = driver_list; 231 - xb->driver_identifier_count = ARRAY_SIZE(driver_list) - 1; 201 + struct u_builder *ub = U_TYPED_CALLOC(struct u_builder); 202 + 203 + // xrt_builder fields. 204 + ub->base.estimate_system = legacy_estimate_system; 205 + ub->base.open_system = u_builder_open_system_static_roles; 206 + ub->base.destroy = legacy_destroy; 207 + ub->base.identifier = "legacy"; 208 + ub->base.name = "Legacy probing system"; 209 + ub->base.driver_identifiers = driver_list; 210 + ub->base.driver_identifier_count = ARRAY_SIZE(driver_list) - 1; 211 + 212 + // u_builder fields. 213 + ub->open_system_static_roles = legacy_open_system_impl; 232 214 233 - return xb; 215 + return &ub->base; 234 216 }
+36 -46
src/xrt/targets/common/target_builder_lighthouse.c
··· 118 118 119 119 struct lighthouse_system 120 120 { 121 - struct xrt_builder base; 122 - struct u_system_devices_static *devices; 121 + struct u_builder base; 122 + 123 + struct xrt_frame_context *xfctx; 123 124 enum lighthouse_driver driver; //!< Which lighthouse implementation we are using 124 125 bool is_valve_index; //!< Is our HMD a Valve Index? If so, try to set up hand-tracking and SLAM as needed 125 126 struct vive_tracking_status vive_tstatus; //!< Visual tracking status for Index under Vive driver ··· 165 166 void *ptr) 166 167 { 167 168 struct lighthouse_system *lhs = (struct lighthouse_system *)ptr; 168 - struct u_system_devices *usysd = &lhs->devices->base; 169 169 170 170 // Hardcoded for the Index. 171 171 if (product != NULL && manufacturer != NULL) { 172 172 if ((strcmp(product, "3D Camera") == 0) && (strcmp(manufacturer, "Etron Technology, Inc.") == 0)) { 173 - xrt_prober_open_video_device(xp, pdev, &usysd->xfctx, &lhs->xfs); 173 + xrt_prober_open_video_device(xp, pdev, lhs->xfctx, &lhs->xfs); 174 174 return; 175 175 } 176 176 } ··· 518 518 } 519 519 520 520 static xrt_result_t 521 - lighthouse_open_system(struct xrt_builder *xb, 522 - cJSON *config, 523 - struct xrt_prober *xp, 524 - struct xrt_system_devices **out_xsysd, 525 - struct xrt_space_overseer **out_xso) 521 + lighthouse_open_system_impl(struct xrt_builder *xb, 522 + cJSON *config, 523 + struct xrt_prober *xp, 524 + struct xrt_tracking_origin *origin, 525 + struct xrt_system_devices *xsysd, 526 + struct xrt_frame_context *xfctx, 527 + struct u_builder_roles_helper *ubrh) 526 528 { 527 529 struct lighthouse_system *lhs = (struct lighthouse_system *)xb; 528 - 529 - // Use the static system devices helper, no dynamic roles. 530 - lhs->devices = u_system_devices_static_allocate(); 531 - struct xrt_system_devices *xsysd = &lhs->devices->base.base; 532 - struct xrt_frame_context *xfctx = &lhs->devices->base.xfctx; 533 - 534 - 535 530 xrt_result_t result = XRT_SUCCESS; 536 531 537 - if (out_xsysd == NULL || *out_xsysd != NULL) { 538 - LH_ERROR("Invalid output system pointer"); 539 - result = XRT_ERROR_DEVICE_CREATION_FAILED; 540 - goto end_err; 541 - } 532 + // Needed when we probe for video devices. 533 + lhs->xfctx = xfctx; 542 534 543 535 // Decide whether to initialize the SLAM tracker 544 536 bool slam_wanted = debug_get_bool_option_vive_slam(); ··· 755 747 } 756 748 757 749 // Assign to role(s). 758 - xsysd->static_roles.head = head; 759 - xsysd->static_roles.hand_tracking.left = left_ht; 760 - xsysd->static_roles.hand_tracking.right = right_ht; 761 - 762 - u_system_devices_static_finalize( // 763 - lhs->devices, // usysds 764 - left, // left 765 - right); // right 750 + ubrh->head = head; 751 + ubrh->left = left; 752 + ubrh->right = right; 753 + ubrh->hand_tracking.left = left_ht; 754 + ubrh->hand_tracking.right = right_ht; 766 755 767 - *out_xsysd = xsysd; 768 - u_builder_create_space_overseer_legacy( // 769 - head, // head 770 - left, // left 771 - right, // right 772 - xsysd->xdevs, // xdevs 773 - xsysd->xdev_count, // xdev_count 774 - out_xso); // out_xso 756 + // Clean up after us. 757 + lhs->xfctx = NULL; 775 758 776 759 return XRT_SUCCESS; 760 + 777 761 778 762 end_err: 779 - xrt_system_devices_destroy(&xsysd); 763 + // Clean up after us. 764 + lhs->xfctx = NULL; 780 765 781 766 return result; 782 767 } ··· 799 784 t_builder_lighthouse_create(void) 800 785 { 801 786 struct lighthouse_system *lhs = U_TYPED_CALLOC(struct lighthouse_system); 802 - lhs->base.estimate_system = lighthouse_estimate_system; 803 - lhs->base.open_system = lighthouse_open_system; 804 - lhs->base.destroy = lighthouse_destroy; 805 - lhs->base.identifier = "lighthouse"; 806 - lhs->base.name = "Lighthouse-tracked (Vive, Index, Tundra trackers, etc.) devices builder"; 807 - lhs->base.driver_identifiers = driver_list; 808 - lhs->base.driver_identifier_count = ARRAY_SIZE(driver_list); 787 + 788 + // xrt_builder fields. 789 + lhs->base.base.estimate_system = lighthouse_estimate_system; 790 + lhs->base.base.open_system = u_builder_open_system_static_roles; 791 + lhs->base.base.destroy = lighthouse_destroy; 792 + lhs->base.base.identifier = "lighthouse"; 793 + lhs->base.base.name = "Lighthouse-tracked (Vive, Index, Tundra trackers, etc.) devices builder"; 794 + lhs->base.base.driver_identifiers = driver_list; 795 + lhs->base.base.driver_identifier_count = ARRAY_SIZE(driver_list); 796 + 797 + // u_builder fields. 798 + lhs->base.open_system_static_roles = lighthouse_open_system_impl; 809 799 810 - return &lhs->base; 800 + return &lhs->base.base; 811 801 }
+28 -49
src/xrt/targets/common/target_builder_north_star.c
··· 102 102 103 103 struct ns_builder 104 104 { 105 - struct xrt_builder base; 105 + struct u_builder base; 106 106 107 107 const char *config_path; 108 108 cJSON *config_json; ··· 442 442 return XRT_SUCCESS; 443 443 } 444 444 445 - 446 - 447 445 static xrt_result_t 448 - ns_open_system(struct xrt_builder *xb, 449 - cJSON *config, 450 - struct xrt_prober *xp, 451 - struct xrt_system_devices **out_xsysd, 452 - struct xrt_space_overseer **out_xso) 446 + ns_open_system_impl(struct xrt_builder *xb, 447 + cJSON *config, 448 + struct xrt_prober *xp, 449 + struct xrt_tracking_origin *origin, 450 + struct xrt_system_devices *xsysd, 451 + struct xrt_frame_context *xfctx, 452 + struct u_builder_roles_helper *ubrh) 453 453 { 454 454 struct ns_builder *nsb = (struct ns_builder *)xb; 455 455 xrt_result_t result = XRT_SUCCESS; 456 - 457 - // Use the static system devices helper, no dynamic roles. 458 - struct u_system_devices_static *usysds = u_system_devices_static_allocate(); 459 - struct xrt_system_devices *xsysd = &usysds->base.base; 460 - struct xrt_frame_context *xfctx = &usysds->base.xfctx; 461 - 462 - if (out_xsysd == NULL || *out_xsysd != NULL) { 463 - NS_ERROR("Invalid output system pointer"); 464 - result = XRT_ERROR_DEVICE_CREATION_FAILED; 465 - goto end; 466 - } 467 - 468 456 469 457 bool load_success = ns_config_load(nsb); 470 458 if (!load_success) { ··· 591 579 } 592 580 593 581 // Assign to role(s). 594 - xsysd->static_roles.head = head_wrap; 595 - xsysd->static_roles.hand_tracking.left = left_ht; 596 - xsysd->static_roles.hand_tracking.right = right_ht; 597 - 598 - u_system_devices_static_finalize( // 599 - usysds, // usysds 600 - left, // left 601 - right); // right 602 - 582 + ubrh->head = head_wrap; 583 + ubrh->left = left; 584 + ubrh->right = right; 585 + ubrh->hand_tracking.left = left_ht; 586 + ubrh->hand_tracking.right = right_ht; 603 587 604 588 end: 605 - if (result == XRT_SUCCESS) { 606 - *out_xsysd = xsysd; 607 - u_builder_create_space_overseer_legacy( // 608 - head_wrap, // head 609 - left, // left 610 - right, // right 611 - xsysd->xdevs, // xdevs 612 - xsysd->xdev_count, // xdev_count 613 - out_xso); // out_xso 614 - } else { 615 - xrt_system_devices_destroy(&xsysd); 616 - } 617 589 if (nsb->config_json != NULL) { 618 590 cJSON_Delete(nsb->config_json); 591 + nsb->config_path = NULL; 619 592 } 620 593 621 594 return result; ··· 626 599 { 627 600 free(xb); 628 601 } 602 + 629 603 630 604 /* 631 605 * ··· 637 611 t_builder_north_star_create(void) 638 612 { 639 613 struct ns_builder *sb = U_TYPED_CALLOC(struct ns_builder); 640 - sb->base.estimate_system = ns_estimate_system; 641 - sb->base.open_system = ns_open_system; 642 - sb->base.destroy = ns_destroy; 643 - sb->base.identifier = "north_star"; 644 - sb->base.name = "North Star headset"; 645 - sb->base.driver_identifiers = driver_list; 646 - sb->base.driver_identifier_count = ARRAY_SIZE(driver_list); 647 614 648 - return &sb->base; 615 + // xrt_builder fields. 616 + sb->base.base.estimate_system = ns_estimate_system; 617 + sb->base.base.open_system = u_builder_open_system_static_roles; 618 + sb->base.base.destroy = ns_destroy; 619 + sb->base.base.identifier = "north_star"; 620 + sb->base.base.name = "North Star headset"; 621 + sb->base.base.driver_identifiers = driver_list; 622 + sb->base.base.driver_identifier_count = ARRAY_SIZE(driver_list); 623 + 624 + // u_builder fields. 625 + sb->base.open_system_static_roles = ns_open_system_impl; 626 + 627 + return &sb->base.base; 649 628 }
+21 -43
src/xrt/targets/common/target_builder_nreal_air.c
··· 82 82 } 83 83 84 84 static xrt_result_t 85 - nreal_air_open_system(struct xrt_builder *xb, 86 - cJSON *config, 87 - struct xrt_prober *xp, 88 - struct xrt_system_devices **out_xsysd, 89 - struct xrt_space_overseer **out_xso) 85 + nreal_air_open_system_impl(struct xrt_builder *xb, 86 + cJSON *config, 87 + struct xrt_prober *xp, 88 + struct xrt_tracking_origin *origin, 89 + struct xrt_system_devices *xsysd, 90 + struct xrt_frame_context *xfctx, 91 + struct u_builder_roles_helper *ubrh) 90 92 { 91 93 struct xrt_prober_device **xpdevs = NULL; 92 94 size_t xpdev_count = 0; 93 95 xrt_result_t xret = XRT_SUCCESS; 94 - 95 - assert(out_xsysd != NULL); 96 - assert(*out_xsysd == NULL); 97 96 98 97 DRV_TRACE_MARKER(); 99 98 100 99 nreal_air_log_level = debug_get_log_option_nreal_air_log(); 101 - 102 - // Use the static system devices helper, no dynamic roles. 103 - struct u_system_devices_static *usysds = u_system_devices_static_allocate(); 104 - struct xrt_system_devices *xsysd = &usysds->base.base; 105 100 106 101 xret = xrt_prober_lock_list(xp, &xpdevs, &xpdev_count); 107 102 if (xret != XRT_SUCCESS) { ··· 152 147 xsysd->xdevs[xsysd->xdev_count++] = na_device; 153 148 154 149 // Assign to role(s). 155 - xsysd->static_roles.head = na_device; 156 - 157 - u_system_devices_static_finalize( // 158 - usysds, // usysds 159 - NULL, // left 160 - NULL); // right 161 - 162 - 163 - /* 164 - * Done. 165 - */ 166 - 167 - *out_xsysd = xsysd; 168 - u_builder_create_space_overseer_legacy( // 169 - na_device, // head 170 - NULL, // left 171 - NULL, // right 172 - xsysd->xdevs, // xdevs 173 - xsysd->xdev_count, // xdev_count 174 - out_xso); // out_xso 150 + ubrh->head = na_device; 175 151 176 152 return XRT_SUCCESS; 177 153 ··· 188 164 189 165 /* Fallthrough */ 190 166 fail: 191 - xrt_system_devices_destroy(&xsysd); 192 - 193 167 return XRT_ERROR_DEVICE_CREATION_FAILED; 194 168 } 195 169 ··· 209 183 struct xrt_builder * 210 184 nreal_air_builder_create(void) 211 185 { 186 + struct u_builder *ub = U_TYPED_CALLOC(struct u_builder); 212 187 213 - struct xrt_builder *xb = U_TYPED_CALLOC(struct xrt_builder); 214 - xb->estimate_system = nreal_air_estimate_system; 215 - xb->open_system = nreal_air_open_system; 216 - xb->destroy = nreal_air_destroy; 217 - xb->identifier = "nreal_air"; 218 - xb->name = "Nreal Air"; 219 - xb->driver_identifiers = driver_list; 220 - xb->driver_identifier_count = ARRAY_SIZE(driver_list); 188 + // xrt_builder fields. 189 + ub->base.estimate_system = nreal_air_estimate_system; 190 + ub->base.open_system = u_builder_open_system_static_roles; 191 + ub->base.destroy = nreal_air_destroy; 192 + ub->base.identifier = "nreal_air"; 193 + ub->base.name = "Nreal Air"; 194 + ub->base.driver_identifiers = driver_list; 195 + ub->base.driver_identifier_count = ARRAY_SIZE(driver_list); 221 196 222 - return xb; 197 + // u_builder fields. 198 + ub->open_system_static_roles = nreal_air_open_system_impl; 199 + 200 + return &ub->base; 223 201 }
+25 -42
src/xrt/targets/common/target_builder_qwerty.c
··· 68 68 } 69 69 70 70 static xrt_result_t 71 - qwerty_open_system(struct xrt_builder *xb, 72 - cJSON *config, 73 - struct xrt_prober *xp, 74 - struct xrt_system_devices **out_xsysd, 75 - struct xrt_space_overseer **out_xso) 71 + qwerty_open_system_impl(struct xrt_builder *xb, 72 + cJSON *config, 73 + struct xrt_prober *xp, 74 + struct xrt_tracking_origin *origin, 75 + struct xrt_system_devices *xsysd, 76 + struct xrt_frame_context *xfctx, 77 + struct u_builder_roles_helper *ubrh) 76 78 { 77 - assert(out_xsysd != NULL); 78 - assert(*out_xsysd == NULL); 79 - 80 79 struct xrt_device *head = NULL; 81 80 struct xrt_device *left = NULL; 82 81 struct xrt_device *right = NULL; ··· 87 86 return xret; 88 87 } 89 88 90 - // Use the static system devices helper, no dynamic roles. 91 - struct u_system_devices_static *usysds = u_system_devices_static_allocate(); 92 - struct xrt_system_devices *xsysd = &usysds->base.base; 93 - 94 89 // Add to device list. 95 90 xsysd->xdevs[xsysd->xdev_count++] = head; 96 91 if (left != NULL) { ··· 101 96 } 102 97 103 98 // Assign to role(s). 104 - xsysd->static_roles.head = head; 105 - 106 - u_system_devices_static_finalize( // 107 - usysds, // usysds 108 - left, // left 109 - right); // right 110 - 111 - 112 - /* 113 - * Done. 114 - */ 115 - 116 - *out_xsysd = xsysd; 117 - u_builder_create_space_overseer_legacy( // 118 - head, // head 119 - left, // left 120 - right, // right 121 - xsysd->xdevs, // xdevs 122 - xsysd->xdev_count, // xdev_count 123 - out_xso); // out_xso 99 + ubrh->head = head; 100 + ubrh->left = left; 101 + ubrh->right = right; 124 102 125 103 return XRT_SUCCESS; 126 104 } ··· 141 119 struct xrt_builder * 142 120 t_builder_qwerty_create(void) 143 121 { 144 - struct xrt_builder *xb = U_TYPED_CALLOC(struct xrt_builder); 145 - xb->estimate_system = qwerty_estimate_system; 146 - xb->open_system = qwerty_open_system; 147 - xb->destroy = qwerty_destroy; 148 - xb->identifier = "qwerty"; 149 - xb->name = "Qwerty devices builder"; 150 - xb->driver_identifiers = driver_list; 151 - xb->driver_identifier_count = ARRAY_SIZE(driver_list); 152 - xb->exclude_from_automatic_discovery = !debug_get_bool_option_enable_qwerty(); 122 + struct u_builder *ub = U_TYPED_CALLOC(struct u_builder); 123 + 124 + // xrt_builder fields. 125 + ub->base.estimate_system = qwerty_estimate_system; 126 + ub->base.open_system = u_builder_open_system_static_roles; 127 + ub->base.destroy = qwerty_destroy; 128 + ub->base.identifier = "qwerty"; 129 + ub->base.name = "Qwerty devices builder"; 130 + ub->base.driver_identifiers = driver_list; 131 + ub->base.driver_identifier_count = ARRAY_SIZE(driver_list); 132 + ub->base.exclude_from_automatic_discovery = !debug_get_bool_option_enable_qwerty(); 133 + 134 + // u_builder fields. 135 + ub->open_system_static_roles = qwerty_open_system_impl; 153 136 154 - return xb; 137 + return &ub->base; 155 138 }
+24 -46
src/xrt/targets/common/target_builder_rgb_tracking.c
··· 276 276 } 277 277 278 278 static xrt_result_t 279 - rgb_open_system(struct xrt_builder *xb, 280 - cJSON *config, 281 - struct xrt_prober *xp, 282 - struct xrt_system_devices **out_xsysd, 283 - struct xrt_space_overseer **out_xso) 279 + rgb_open_system_impl(struct xrt_builder *xb, 280 + cJSON *config, 281 + struct xrt_prober *xp, 282 + struct xrt_tracking_origin *origin, 283 + struct xrt_system_devices *xsysd, 284 + struct xrt_frame_context *xfctx, 285 + struct u_builder_roles_helper *ubrh) 284 286 { 285 287 struct u_builder_search_results results = {0}; 286 288 struct xrt_prober_device **xpdevs = NULL; 287 289 size_t xpdev_count = 0; 288 290 xrt_result_t xret = XRT_SUCCESS; 289 291 290 - assert(out_xsysd != NULL); 291 - assert(*out_xsysd == NULL); 292 - 293 - // Use the static system devices helper, no dynamic roles. 294 - struct u_system_devices_static *usysds = u_system_devices_static_allocate(); 295 - struct xrt_tracking_origin *origin = &usysds->base.origin; 296 - struct xrt_system_devices *xsysd = &usysds->base.base; 297 - struct xrt_frame_context *xfctx = &usysds->base.xfctx; 298 - 299 292 300 293 /* 301 294 * Tracking. ··· 327 320 // Lock the device list 328 321 xret = xrt_prober_lock_list(xp, &xpdevs, &xpdev_count); 329 322 if (xret != XRT_SUCCESS) { 330 - xrt_system_devices_destroy(&xsysd); 331 323 return xret; 332 324 } 333 325 ··· 387 379 // Unlock the device list 388 380 xret = xrt_prober_unlock_list(xp, &xpdevs); 389 381 if (xret != XRT_SUCCESS) { 390 - xrt_system_devices_destroy(&xsysd); 391 382 return xret; 392 383 } 393 384 ··· 406 397 } 407 398 408 399 // Assign to role(s). 409 - xsysd->static_roles.head = head; 410 - 411 - u_system_devices_static_finalize( // 412 - usysds, // usysds 413 - left, // left 414 - right); // right 415 - 416 - 417 - /* 418 - * Done. 419 - */ 420 - 421 - *out_xsysd = xsysd; 422 - u_builder_create_space_overseer_legacy( // 423 - head, // head 424 - left, // left 425 - right, // right 426 - xsysd->xdevs, // xdevs 427 - xsysd->xdev_count, // xdev_count 428 - out_xso); // out_xso 429 - 400 + ubrh->head = head; 401 + ubrh->left = left; 402 + ubrh->right = right; 430 403 431 404 return XRT_SUCCESS; 432 405 } ··· 447 420 struct xrt_builder * 448 421 t_builder_rgb_tracking_create(void) 449 422 { 450 - struct xrt_builder *xb = U_TYPED_CALLOC(struct xrt_builder); 451 - xb->estimate_system = rgb_estimate_system; 452 - xb->open_system = rgb_open_system; 453 - xb->destroy = rgb_destroy; 454 - xb->identifier = "rgb_tracking"; 455 - xb->name = "RGB tracking based devices (PSVR, PSMV, ...)"; 456 - xb->driver_identifiers = driver_list; 457 - xb->driver_identifier_count = ARRAY_SIZE(driver_list); 423 + struct u_builder *ub = U_TYPED_CALLOC(struct u_builder); 424 + 425 + // xrt_builder fields. 426 + ub->base.estimate_system = rgb_estimate_system; 427 + ub->base.open_system = u_builder_open_system_static_roles; 428 + ub->base.destroy = rgb_destroy; 429 + ub->base.identifier = "rgb_tracking"; 430 + ub->base.name = "RGB tracking based devices (PSVR, PSMV, ...)"; 431 + ub->base.driver_identifiers = driver_list; 432 + ub->base.driver_identifier_count = ARRAY_SIZE(driver_list); 433 + 434 + // u_builder fields. 435 + ub->open_system_static_roles = rgb_open_system_impl; 458 436 459 - return xb; 437 + return &ub->base; 460 438 }
+30 -44
src/xrt/targets/common/target_builder_rift_s.c
··· 93 93 } 94 94 95 95 static xrt_result_t 96 - rift_s_open_system(struct xrt_builder *xb, 97 - cJSON *config, 98 - struct xrt_prober *xp, 99 - struct xrt_system_devices **out_xsysd, 100 - struct xrt_space_overseer **out_xso) 96 + rift_s_open_system_impl(struct xrt_builder *xb, 97 + cJSON *config, 98 + struct xrt_prober *xp, 99 + struct xrt_tracking_origin *origin, 100 + struct xrt_system_devices *xsysd, 101 + struct xrt_frame_context *xfctx, 102 + struct u_builder_roles_helper *ubrh) 101 103 { 102 104 struct xrt_prober_device **xpdevs = NULL; 103 105 size_t xpdev_count = 0; 104 106 xrt_result_t xret = XRT_SUCCESS; 105 - 106 - assert(out_xsysd != NULL); 107 - assert(*out_xsysd == NULL); 108 107 109 108 DRV_TRACE_MARKER(); 110 109 111 110 rift_s_log_level = debug_get_log_option_rift_s_log(); 112 - 113 - // Use the static system devices helper, no dynamic roles. 114 - struct u_system_devices_static *usysds = u_system_devices_static_allocate(); 115 - struct xrt_system_devices *xsysd = &usysds->base.base; 116 111 117 112 xret = xrt_prober_lock_list(xp, &xpdevs, &xpdev_count); 118 113 if (xret != XRT_SUCCESS) { ··· 180 175 xsysd->xdevs[xsysd->xdev_count++] = right_xdev; 181 176 182 177 178 + struct xrt_device *left_ht = NULL; 179 + struct xrt_device *right_ht = NULL; 180 + 183 181 #ifdef XRT_BUILD_DRIVER_HANDTRACKING 184 182 struct xrt_device *ht_xdev = rift_s_system_get_hand_tracking_device(sys); 185 183 if (ht_xdev != NULL) { ··· 189 187 struct xrt_device *two_hands[2]; 190 188 cemu_devices_create(hmd_xdev, ht_xdev, two_hands); 191 189 192 - xsysd->static_roles.hand_tracking.left = two_hands[0]; 193 - xsysd->static_roles.hand_tracking.right = two_hands[1]; 190 + left_ht = two_hands[0]; 191 + right_ht = two_hands[1]; 194 192 195 193 xsysd->xdevs[xsysd->xdev_count++] = two_hands[0]; 196 194 xsysd->xdevs[xsysd->xdev_count++] = two_hands[1]; ··· 203 201 #endif 204 202 205 203 // Assign to role(s). 206 - xsysd->static_roles.head = hmd_xdev; 207 - 208 - u_system_devices_static_finalize( // 209 - usysds, // usysds 210 - left_xdev, // left 211 - right_xdev); // right 212 - 213 - 214 - /* 215 - * Done. 216 - */ 217 - 218 - *out_xsysd = xsysd; 219 - u_builder_create_space_overseer_legacy( // 220 - hmd_xdev, // head 221 - left_xdev, // left 222 - right_xdev, // right 223 - xsysd->xdevs, // xdevs 224 - xsysd->xdev_count, // xdev_count 225 - out_xso); // out_xso 204 + ubrh->head = hmd_xdev; 205 + ubrh->left = left_xdev; 206 + ubrh->right = right_xdev; 207 + ubrh->hand_tracking.left = left_ht; 208 + ubrh->hand_tracking.right = right_ht; 226 209 227 210 return XRT_SUCCESS; 228 211 ··· 235 218 236 219 /* Fallthrough */ 237 220 fail: 238 - xrt_system_devices_destroy(&xsysd); 239 221 return XRT_ERROR_DEVICE_CREATION_FAILED; 240 222 } 241 223 ··· 255 237 struct xrt_builder * 256 238 rift_s_builder_create(void) 257 239 { 240 + struct u_builder *ub = U_TYPED_CALLOC(struct u_builder); 258 241 259 - struct xrt_builder *xb = U_TYPED_CALLOC(struct xrt_builder); 260 - xb->estimate_system = rift_s_estimate_system; 261 - xb->open_system = rift_s_open_system; 262 - xb->destroy = rift_s_destroy; 263 - xb->identifier = "rift_s"; 264 - xb->name = "Oculus Rift S"; 265 - xb->driver_identifiers = driver_list; 266 - xb->driver_identifier_count = ARRAY_SIZE(driver_list); 242 + // xrt_builder fields. 243 + ub->base.estimate_system = rift_s_estimate_system; 244 + ub->base.open_system = u_builder_open_system_static_roles; 245 + ub->base.destroy = rift_s_destroy; 246 + ub->base.identifier = "rift_s"; 247 + ub->base.name = "Oculus Rift S"; 248 + ub->base.driver_identifiers = driver_list; 249 + ub->base.driver_identifier_count = ARRAY_SIZE(driver_list); 267 250 268 - return xb; 251 + // u_builder fields. 252 + ub->open_system_static_roles = rift_s_open_system_impl; 253 + 254 + return &ub->base; 269 255 }
+25 -42
src/xrt/targets/common/target_builder_simulated.c
··· 90 90 } 91 91 92 92 static xrt_result_t 93 - simulated_open_system(struct xrt_builder *xb, 94 - cJSON *config, 95 - struct xrt_prober *xp, 96 - struct xrt_system_devices **out_xsysd, 97 - struct xrt_space_overseer **out_xso) 93 + simulated_open_system_impl(struct xrt_builder *xb, 94 + cJSON *config, 95 + struct xrt_prober *xp, 96 + struct xrt_tracking_origin *origin, 97 + struct xrt_system_devices *xsysd, 98 + struct xrt_frame_context *xfctx, 99 + struct u_builder_roles_helper *ubrh) 98 100 { 99 - assert(out_xsysd != NULL); 100 - assert(*out_xsysd == NULL); 101 - 102 101 const struct xrt_pose head_center = {XRT_QUAT_IDENTITY, {0.0f, 1.6f, 0.0f}}; // "nominal height" 1.6m 103 102 const struct xrt_pose left_center = {XRT_QUAT_IDENTITY, {-0.2f, 1.3f, -0.5f}}; 104 103 const struct xrt_pose right_center = {XRT_QUAT_IDENTITY, {0.2f, 1.3f, -0.5f}}; ··· 119 118 //! @todo Create a shared tracking origin on the system devices struct instead. 120 119 head->tracking_origin->type = XRT_TRACKING_TYPE_OTHER; // Just anything other then none. 121 120 122 - // Use the static system devices helper, no dynamic roles. 123 - struct u_system_devices_static *usysds = u_system_devices_static_allocate(); 124 - struct xrt_system_devices *xsysd = &usysds->base.base; 125 - 126 121 // Add to device list. 127 122 xsysd->xdevs[xsysd->xdev_count++] = head; 128 123 if (left != NULL) { ··· 133 128 } 134 129 135 130 // Assign to role(s). 136 - xsysd->static_roles.head = head; 137 - 138 - u_system_devices_static_finalize( // 139 - usysds, // usysds 140 - left, // left 141 - right); // right 142 - 143 - 144 - /* 145 - * Done. 146 - */ 147 - 148 - *out_xsysd = xsysd; 149 - u_builder_create_space_overseer_legacy( // 150 - head, // head 151 - left, // left 152 - right, // right 153 - xsysd->xdevs, // xdevs 154 - xsysd->xdev_count, // xdev_count 155 - out_xso); // out_xso 131 + ubrh->head = head; 132 + ubrh->left = left; 133 + ubrh->right = right; 156 134 157 135 return XRT_SUCCESS; 158 136 } ··· 173 151 struct xrt_builder * 174 152 t_builder_simulated_create(void) 175 153 { 176 - struct xrt_builder *xb = U_TYPED_CALLOC(struct xrt_builder); 177 - xb->estimate_system = simulated_estimate_system; 178 - xb->open_system = simulated_open_system; 179 - xb->destroy = simulated_destroy; 180 - xb->identifier = "simulated"; 181 - xb->name = "Simulated devices builder"; 182 - xb->driver_identifiers = driver_list; 183 - xb->driver_identifier_count = ARRAY_SIZE(driver_list); 184 - xb->exclude_from_automatic_discovery = !debug_get_bool_option_simulated_enabled(); 154 + struct u_builder *ub = U_TYPED_CALLOC(struct u_builder); 155 + 156 + // xrt_builder fields. 157 + ub->base.estimate_system = simulated_estimate_system; 158 + ub->base.open_system = u_builder_open_system_static_roles; 159 + ub->base.destroy = simulated_destroy; 160 + ub->base.identifier = "simulated"; 161 + ub->base.name = "Simulated devices builder"; 162 + ub->base.driver_identifiers = driver_list; 163 + ub->base.driver_identifier_count = ARRAY_SIZE(driver_list); 164 + ub->base.exclude_from_automatic_discovery = !debug_get_bool_option_simulated_enabled(); 165 + 166 + // u_builder fields. 167 + ub->open_system_static_roles = simulated_open_system_impl; 185 168 186 - return xb; 169 + return &ub->base; 187 170 }
+27 -42
src/xrt/targets/common/target_builder_simulavr.c
··· 51 51 52 52 struct simula_builder 53 53 { 54 - struct xrt_builder base; 54 + struct u_builder base; 55 + 55 56 struct svr_two_displays_distortion display_distortion; 56 57 }; 57 58 ··· 192 193 } 193 194 194 195 static xrt_result_t 195 - svr_open_system(struct xrt_builder *xb, 196 - cJSON *config, 197 - struct xrt_prober *xp, 198 - struct xrt_system_devices **out_xsysd, 199 - struct xrt_space_overseer **out_xso) 196 + svr_open_system_impl(struct xrt_builder *xb, 197 + cJSON *config, 198 + struct xrt_prober *xp, 199 + struct xrt_tracking_origin *origin, 200 + struct xrt_system_devices *xsysd, 201 + struct xrt_frame_context *xfctx, 202 + struct u_builder_roles_helper *ubrh) 200 203 { 201 204 struct simula_builder *sb = (struct simula_builder *)xb; 202 205 xrt_result_t result = XRT_SUCCESS; 203 206 204 - if (out_xsysd == NULL || *out_xsysd != NULL) { 205 - SVR_ERROR("Invalid output system pointer"); 207 + struct xrt_device *t265_dev = rs_create_tracked_device_internal_slam(); 208 + if (t265_dev == NULL) { 209 + SVR_ERROR("Failed to open T265 device!"); 206 210 result = XRT_ERROR_DEVICE_CREATION_FAILED; 207 211 goto end; 208 212 } 209 213 210 - struct xrt_device *t265_dev = rs_create_tracked_device_internal_slam(); 211 - 212 214 struct xrt_device *svr_dev = svr_hmd_create(&sb->display_distortion); 213 215 214 216 struct xrt_pose ident = XRT_POSE_IDENTITY; ··· 217 219 struct xrt_device *head_device = multi_create_tracking_override( 218 220 XRT_TRACKING_OVERRIDE_ATTACHED, svr_dev, t265_dev, XRT_INPUT_GENERIC_TRACKER_POSE, &ident); 219 221 220 - // Use the static system devices helper, no dynamic roles. 221 - struct u_system_devices_static *usysds = u_system_devices_static_allocate(); 222 - struct xrt_system_devices *xsysd = &usysds->base.base; 223 - 224 222 // Add to device list. 225 223 xsysd->xdevs[xsysd->xdev_count++] = head_device; 226 224 227 225 // Assign to role(s). 228 - xsysd->static_roles.head = head_device; 229 - 226 + ubrh->head = head_device; 230 227 231 228 end: 232 - if (result == XRT_SUCCESS) { 233 - u_system_devices_static_finalize( // 234 - usysds, // usysds 235 - NULL, // left 236 - NULL); // right 237 - 238 - *out_xsysd = xsysd; 239 - u_builder_create_space_overseer_legacy( // 240 - head_device, // head 241 - NULL, // left 242 - NULL, // right 243 - xsysd->xdevs, // xdevs 244 - xsysd->xdev_count, // xdev_count 245 - out_xso); // out_xso 246 - } else { 247 - xrt_system_devices_destroy(&xsysd); 248 - } 249 - 250 229 return result; 251 230 } 252 231 ··· 255 234 { 256 235 free(xb); 257 236 } 237 + 258 238 259 239 /* 260 240 * ··· 266 246 t_builder_simula_create(void) 267 247 { 268 248 struct simula_builder *sb = U_TYPED_CALLOC(struct simula_builder); 269 - sb->base.estimate_system = svr_estimate_system; 270 - sb->base.open_system = svr_open_system; 271 - sb->base.destroy = svr_destroy; 272 - sb->base.identifier = "simula"; 273 - sb->base.name = "SimulaVR headset"; 274 - sb->base.driver_identifiers = driver_list; 275 - sb->base.driver_identifier_count = ARRAY_SIZE(driver_list); 249 + 250 + // xrt_builder fields. 251 + sb->base.base.estimate_system = svr_estimate_system; 252 + sb->base.base.open_system = u_builder_open_system_static_roles; 253 + sb->base.base.destroy = svr_destroy; 254 + sb->base.base.identifier = "simula"; 255 + sb->base.base.name = "SimulaVR headset"; 256 + sb->base.base.driver_identifiers = driver_list; 257 + sb->base.base.driver_identifier_count = ARRAY_SIZE(driver_list); 276 258 277 - return &sb->base; 259 + // u_builder fields. 260 + sb->base.open_system_static_roles = svr_open_system_impl; 261 + 262 + return &sb->base.base; 278 263 }
+26 -44
src/xrt/targets/common/target_builder_wmr.c
··· 176 176 } 177 177 178 178 static xrt_result_t 179 - wmr_open_system(struct xrt_builder *xb, 180 - cJSON *config, 181 - struct xrt_prober *xp, 182 - struct xrt_system_devices **out_xsysd, 183 - struct xrt_space_overseer **out_xso) 179 + wmr_open_system_impl(struct xrt_builder *xb, 180 + cJSON *config, 181 + struct xrt_prober *xp, 182 + struct xrt_tracking_origin *origin, 183 + struct xrt_system_devices *xsysd, 184 + struct xrt_frame_context *xfctx, 185 + struct u_builder_roles_helper *ubrh) 184 186 { 185 187 enum u_logging_level log_level = debug_get_log_option_wmr_log(); 186 188 struct wmr_bt_controllers_search_results ctrls = {0}; ··· 271 273 assert(xret_unlock == XRT_SUCCESS); 272 274 (void)xret_unlock; 273 275 274 - struct u_system_devices_static *usysds = u_system_devices_static_allocate(); 275 - struct xrt_system_devices *xsysd = &usysds->base.base; 276 - 277 276 xsysd->xdevs[xsysd->xdev_count++] = head; 278 277 if (left != NULL) { 279 278 xsysd->xdevs[xsysd->xdev_count++] = left; ··· 298 297 299 298 300 299 // Assign to role(s). 301 - xsysd->static_roles.head = head; 302 - xsysd->static_roles.hand_tracking.left = ht_left; 303 - xsysd->static_roles.hand_tracking.right = ht_right; 304 - 305 - u_system_devices_static_finalize( // 306 - usysds, // usysds 307 - left, // left 308 - right); // right 309 - 310 - // Create space overseer last once all devices set. 311 - struct xrt_space_overseer *xso = NULL; 312 - u_builder_create_space_overseer_legacy( // 313 - head, // head 314 - left, // left 315 - right, // right 316 - xsysd->xdevs, // xdevs 317 - xsysd->xdev_count, // xdev_count 318 - &xso); // out_xso 319 - assert(xso != NULL); 320 - 321 - 322 - /* 323 - * Output. 324 - */ 325 - 326 - *out_xsysd = xsysd; 327 - *out_xso = xso; 300 + ubrh->head = head; 301 + ubrh->left = left; 302 + ubrh->right = right; 303 + ubrh->hand_tracking.left = ht_left; 304 + ubrh->hand_tracking.right = ht_right; 328 305 329 306 return XRT_SUCCESS; 330 307 ··· 355 332 struct xrt_builder * 356 333 t_builder_wmr_create(void) 357 334 { 358 - struct xrt_builder *xb = U_TYPED_CALLOC(struct xrt_builder); 359 - xb->estimate_system = wmr_estimate_system; 360 - xb->open_system = wmr_open_system; 361 - xb->destroy = wmr_destroy; 362 - xb->identifier = "wmr"; 363 - xb->name = "Windows Mixed Reality"; 364 - xb->driver_identifiers = driver_list; 365 - xb->driver_identifier_count = ARRAY_SIZE(driver_list); 335 + struct u_builder *ub = U_TYPED_CALLOC(struct u_builder); 336 + 337 + // xrt_builder fields. 338 + ub->base.estimate_system = wmr_estimate_system; 339 + ub->base.open_system = u_builder_open_system_static_roles; 340 + ub->base.destroy = wmr_destroy; 341 + ub->base.identifier = "wmr"; 342 + ub->base.name = "Windows Mixed Reality"; 343 + ub->base.driver_identifiers = driver_list; 344 + ub->base.driver_identifier_count = ARRAY_SIZE(driver_list); 345 + 346 + // u_builder fields. 347 + ub->open_system_static_roles = wmr_open_system_impl; 366 348 367 - return xb; 349 + return &ub->base; 368 350 }