The open source OpenXR runtime

drivers: Use the new helper to set functions

This adds the helper to some of the drivers,
but not all that can be done as a follow up.

Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2634>

authored by Jakob Bornecrantz and committed by Marge Bot 8fbc3907 95598839

+1 -5
src/xrt/drivers/android/android_sensors.c
··· 16 16 17 17 #include "util/u_debug.h" 18 18 #include "util/u_device.h" 19 - #include "util/u_device_ni.h" 20 19 #include "util/u_distortion_mesh.h" 21 20 #include "util/u_var.h" 22 21 #include "util/u_visibility_mask.h" ··· 355 354 struct android_device *d = U_DEVICE_ALLOCATE(struct android_device, flags, 1, 0); 356 355 357 356 d->base.name = XRT_DEVICE_GENERIC_HMD; 358 - d->base.destroy = android_device_destroy; 359 - d->base.update_inputs = u_device_noop_update_inputs; 360 - d->base.set_output = u_device_ni_set_output; 361 - d->base.get_tracked_pose = android_device_get_tracked_pose; 357 + u_device_populate_function_pointers(&d->base, android_device_get_tracked_pose, android_device_destroy); 362 358 d->base.get_view_poses = u_device_get_view_poses; 363 359 d->base.get_visibility_mask = u_device_get_visibility_mask; 364 360 d->base.compute_distortion = android_device_compute_distortion;
+1 -6
src/xrt/drivers/euroc/euroc_device.c
··· 10 10 #include "util/u_misc.h" 11 11 #include "util/u_debug.h" 12 12 #include "util/u_device.h" 13 - #include "util/u_device_ni.h" 14 13 #include "util/u_distortion_mesh.h" 15 14 #include "util/u_var.h" 16 15 #include "math/m_space.h" ··· 207 206 xd->inputs[0].name = XRT_INPUT_SIMPLE_GRIP_POSE; 208 207 } 209 208 210 - xd->update_inputs = u_device_noop_update_inputs; 211 - xd->get_tracked_pose = euroc_device_get_tracked_pose; 212 - xd->destroy = euroc_device_destroy; 209 + u_device_populate_function_pointers(xd, euroc_device_get_tracked_pose, euroc_device_destroy); 213 210 if (is_hmd) { 214 211 xd->get_view_poses = u_device_get_view_poses; 215 - } else { 216 - xd->get_view_poses = u_device_ni_get_view_poses; 217 212 } 218 213 219 214 u_var_add_root(ed, dev_name, false);
+1 -4
src/xrt/drivers/ht_ctrl_emu/ht_ctrl_emu.cpp
··· 24 24 #include "util/u_misc.h" 25 25 #include "util/u_debug.h" 26 26 #include "util/u_device.h" 27 - #include "util/u_device_ni.h" 28 27 #include "util/u_distortion_mesh.h" 29 28 #include "util/u_config_json.h" 30 29 ··· 514 513 cemud[i]->base.inputs[CEMU_INDEX_GRIP].name = XRT_INPUT_HAND_CTRL_EMU_GRIP_POSE; 515 514 cemud[i]->base.inputs[CEMU_INDEX_AIM].name = XRT_INPUT_HAND_CTRL_EMU_AIM_POSE; 516 515 516 + u_device_populate_function_pointers(&cemud[i]->base, cemu_device_get_tracked_pose, cemu_device_destroy); 517 517 cemud[i]->base.update_inputs = cemu_device_update_inputs; 518 - cemud[i]->base.get_tracked_pose = cemu_device_get_tracked_pose; 519 - cemud[i]->base.set_output = u_device_ni_set_output; 520 518 cemud[i]->base.get_hand_tracking = cemu_device_get_hand_tracking; 521 - cemud[i]->base.destroy = cemu_device_destroy; 522 519 523 520 cemud[i]->base.device_type = 524 521 i ? XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER : XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER;
+1 -4
src/xrt/drivers/hydra/hydra_driver.c
··· 31 31 32 32 #include "util/u_debug.h" 33 33 #include "util/u_device.h" 34 - #include "util/u_device_ni.h" 35 34 #include "util/u_misc.h" 36 35 #include "util/u_time.h" 37 36 #include "util/u_logging.h" ··· 798 797 for (size_t i = 0; i < 2; ++i) { 799 798 struct hydra_device *hd = hs->devs[i]; 800 799 801 - hd->base.destroy = hydra_device_destroy; 800 + u_device_populate_function_pointers(&hd->base, hydra_device_get_tracked_pose, hydra_device_destroy); 802 801 hd->base.update_inputs = hydra_device_update_inputs; 803 - hd->base.get_tracked_pose = hydra_device_get_tracked_pose; 804 - hd->base.set_output = u_device_ni_set_output; 805 802 hd->base.name = XRT_DEVICE_HYDRA; 806 803 snprintf(hd->base.str, XRT_DEVICE_NAME_LEN, "%s %i", "Razer Hydra Controller", (int)(i + 1)); 807 804 snprintf(hd->base.serial, XRT_DEVICE_NAME_LEN, "%s%i", "RZRHDRC", (int)(i + 1));
+2 -6
src/xrt/drivers/ohmd/oh_device.c
··· 21 21 #include "util/u_misc.h" 22 22 #include "util/u_debug.h" 23 23 #include "util/u_device.h" 24 - #include "util/u_device_ni.h" 25 24 #include "util/u_time.h" 26 25 #include "util/u_distortion_mesh.h" 27 26 #include "util/u_logging.h" ··· 758 757 759 758 enum u_device_alloc_flags flags = U_DEVICE_ALLOC_HMD; 760 759 struct oh_device *ohd = U_DEVICE_ALLOCATE(struct oh_device, flags, 1, 0); 760 + u_device_populate_function_pointers(&ohd->base, oh_device_get_tracked_pose, oh_device_destroy); 761 761 ohd->base.update_inputs = oh_device_update_inputs; 762 - ohd->base.get_tracked_pose = oh_device_get_tracked_pose; 763 762 ohd->base.get_view_poses = u_device_get_view_poses; 764 - ohd->base.destroy = oh_device_destroy; 765 763 ohd->base.inputs[0].name = XRT_INPUT_GENERIC_HEAD_POSE; 766 764 ohd->base.name = XRT_DEVICE_GENERIC_HMD; 767 765 ohd->ctx = ctx; ··· 1075 1073 1076 1074 enum u_device_alloc_flags flags = 0; 1077 1075 struct oh_device *ohd = U_DEVICE_ALLOCATE(struct oh_device, flags, input_count, output_count); 1076 + u_device_populate_function_pointers(&ohd->base, oh_device_get_tracked_pose, oh_device_destroy); 1078 1077 ohd->base.update_inputs = oh_device_update_inputs; 1079 1078 ohd->base.set_output = oh_device_set_output; 1080 - ohd->base.get_tracked_pose = oh_device_get_tracked_pose; 1081 - ohd->base.get_view_poses = u_device_ni_get_view_poses; 1082 - ohd->base.destroy = oh_device_destroy; 1083 1079 if (oculus_touch) { 1084 1080 ohd->ohmd_device_type = OPENHMD_OCULUS_RIFT_CONTROLLER; 1085 1081 ohd->base.name = XRT_DEVICE_TOUCH_CONTROLLER;
+1 -5
src/xrt/drivers/realsense/rs_ddev.c
··· 22 22 23 23 #include "util/u_time.h" 24 24 #include "util/u_device.h" 25 - #include "util/u_device_ni.h" 26 25 #include "util/u_logging.h" 27 26 28 27 #include "util/u_json.h" ··· 449 448 450 449 U_LOG_D("Realsense opts are %i %i %i %i %i\n", rs->enable_mapping, rs->enable_pose_jumping, 451 450 rs->enable_relocalization, rs->enable_pose_prediction, rs->enable_pose_filtering); 452 - rs->base.update_inputs = u_device_noop_update_inputs; 453 - rs->base.get_tracked_pose = rs_ddev_get_tracked_pose; 454 - rs->base.get_view_poses = u_device_ni_get_view_poses; 455 - rs->base.destroy = rs_ddev_destroy; 451 + u_device_populate_function_pointers(&rs->base, rs_ddev_get_tracked_pose, rs_ddev_destroy); 456 452 rs->base.name = XRT_DEVICE_REALSENSE; 457 453 rs->base.tracking_origin->type = XRT_TRACKING_TYPE_EXTERNAL_SLAM; 458 454
+1 -5
src/xrt/drivers/remote/r_device.c
··· 15 15 #include "util/u_misc.h" 16 16 #include "util/u_debug.h" 17 17 #include "util/u_device.h" 18 - #include "util/u_device_ni.h" 19 18 #include "util/u_hand_tracking.h" 20 19 21 20 #include "vive/vive_bindings.h" ··· 194 193 struct r_device, flags, input_count, output_count); 195 194 196 195 // Setup the basics. 196 + u_device_populate_function_pointers(&rd->base, r_device_get_tracked_pose, r_device_destroy); 197 197 rd->base.update_inputs = r_device_update_inputs; 198 - rd->base.get_tracked_pose = r_device_get_tracked_pose; 199 198 rd->base.get_hand_tracking = r_device_get_hand_tracking; 200 - rd->base.get_view_poses = u_device_ni_get_view_poses; 201 - rd->base.set_output = u_device_ni_set_output; 202 - rd->base.destroy = r_device_destroy; 203 199 rd->base.tracking_origin = &r->origin; 204 200 rd->base.supported.orientation_tracking = true; 205 201 rd->base.supported.position_tracking = true;
+1 -6
src/xrt/drivers/remote/r_hmd.c
··· 15 15 #include "util/u_misc.h" 16 16 #include "util/u_debug.h" 17 17 #include "util/u_device.h" 18 - #include "util/u_device_ni.h" 19 18 #include "util/u_distortion_mesh.h" 20 19 21 20 #include "math/m_api.h" ··· 125 124 struct r_hmd, flags, input_count, output_count); 126 125 127 126 // Setup the basics. 128 - rh->base.update_inputs = u_device_noop_update_inputs; 129 - rh->base.get_tracked_pose = r_hmd_get_tracked_pose; 130 - rh->base.get_hand_tracking = u_device_ni_get_hand_tracking; 127 + u_device_populate_function_pointers(&rh->base, r_hmd_get_tracked_pose, r_hmd_destroy); 131 128 rh->base.get_view_poses = r_hmd_get_view_poses; 132 - rh->base.set_output = u_device_ni_set_output; 133 - rh->base.destroy = r_hmd_destroy; 134 129 rh->base.tracking_origin = &r->origin; 135 130 rh->base.supported.orientation_tracking = true; 136 131 rh->base.supported.position_tracking = true;
+1 -4
src/xrt/drivers/rift_s/rift_s_controller.c
··· 28 28 #include "os/os_hid.h" 29 29 30 30 #include "util/u_device.h" 31 - #include "util/u_device_ni.h" 32 31 #include "util/u_trace_marker.h" 33 32 #include "util/u_var.h" 34 33 ··· 607 606 608 607 os_mutex_init(&ctrl->mutex); 609 608 609 + u_device_populate_function_pointers(&ctrl->base, rift_s_controller_get_tracked_pose, rift_s_controller_destroy); 610 610 ctrl->base.update_inputs = rift_s_controller_update_inputs; 611 - ctrl->base.set_output = u_device_ni_set_output; 612 - ctrl->base.get_tracked_pose = rift_s_controller_get_tracked_pose; 613 611 ctrl->base.get_view_poses = u_device_get_view_poses; 614 - ctrl->base.destroy = rift_s_controller_destroy; 615 612 ctrl->base.name = XRT_DEVICE_TOUCH_CONTROLLER; 616 613 ctrl->base.device_type = device_type; 617 614
+1 -6
src/xrt/drivers/simulated/simulated_controller.c
··· 19 19 #include "util/u_time.h" 20 20 #include "util/u_debug.h" 21 21 #include "util/u_device.h" 22 - #include "util/u_device_ni.h" 23 22 #include "util/u_logging.h" 24 23 #include "util/u_distortion_mesh.h" 25 24 ··· 348 347 349 348 // Allocate. 350 349 struct simulated_device *sd = U_DEVICE_ALLOCATE(struct simulated_device, flags, input_count, output_count); 350 + u_device_populate_function_pointers(&sd->base, simulated_device_get_tracked_pose, simulated_device_destroy); 351 351 sd->base.update_inputs = simulated_device_update_inputs; 352 - sd->base.get_tracked_pose = simulated_device_get_tracked_pose; 353 - sd->base.get_hand_tracking = u_device_ni_get_hand_tracking; 354 - sd->base.get_view_poses = u_device_ni_get_view_poses; 355 - sd->base.set_output = u_device_ni_set_output; 356 - sd->base.destroy = simulated_device_destroy; 357 352 sd->base.tracking_origin = origin; 358 353 sd->base.supported.orientation_tracking = true; 359 354 sd->base.supported.position_tracking = true;
+1 -5
src/xrt/drivers/twrap/twrap_slam.c
··· 29 29 #include <assert.h> 30 30 31 31 #include "util/u_device.h" 32 - #include "util/u_device_ni.h" 33 32 #include "math/m_space.h" 34 33 #include "util/u_tracked_imu_3dof.h" 35 34 ··· 160 159 161 160 162 161 163 - dx->base.update_inputs = u_device_noop_update_inputs; 164 - dx->base.get_tracked_pose = twrap_slam_get_tracked_pose; 165 - dx->base.get_view_poses = u_device_ni_get_view_poses; 166 - dx->base.destroy = twrap_slam_destroy; 162 + u_device_populate_function_pointers(&dx->base, twrap_slam_get_tracked_pose, twrap_slam_destroy); 167 163 dx->base.name = name; 168 164 dx->base.tracking_origin->type = XRT_TRACKING_TYPE_OTHER; 169 165 dx->base.inputs[0].name = XRT_INPUT_GENERIC_TRACKER_POSE;
+4 -2
src/xrt/drivers/wmr/wmr_controller_base.c
··· 526 526 wmr_controller_base_init(struct wmr_controller_base *wcb, 527 527 struct wmr_controller_connection *conn, 528 528 enum xrt_device_type controller_type, 529 - enum u_logging_level log_level) 529 + enum u_logging_level log_level, 530 + u_device_destroy_function_t destroy_fn) 530 531 { 531 532 DRV_TRACE_MARKER(); 532 533 ··· 544 545 snprintf(wcb->base.serial, XRT_DEVICE_NAME_LEN, "Right Controller"); 545 546 } 546 547 547 - wcb->base.get_tracked_pose = wmr_controller_base_get_tracked_pose; 548 + // Set all functions. 549 + u_device_populate_function_pointers(&wcb->base, wmr_controller_base_get_tracked_pose, destroy_fn); 548 550 549 551 wcb->base.name = XRT_DEVICE_WMR_CONTROLLER; 550 552 wcb->base.device_type = controller_type;
+3 -1
src/xrt/drivers/wmr/wmr_controller_base.h
··· 16 16 17 17 #include "os/os_threading.h" 18 18 #include "math/m_imu_3dof.h" 19 + #include "util/u_device.h" 19 20 #include "util/u_logging.h" 20 21 #include "xrt/xrt_device.h" 21 22 ··· 129 130 wmr_controller_base_init(struct wmr_controller_base *wcb, 130 131 struct wmr_controller_connection *conn, 131 132 enum xrt_device_type controller_type, 132 - enum u_logging_level log_level); 133 + enum u_logging_level log_level, 134 + u_device_destroy_function_t destroy_fn); 133 135 134 136 void 135 137 wmr_controller_base_deinit(struct wmr_controller_base *wcb);
+3 -6
src/xrt/drivers/wmr/wmr_controller_hp.c
··· 11 11 #include "math/m_api.h" 12 12 13 13 #include "util/u_device.h" 14 - #include "util/u_device_ni.h" 15 14 #include "util/u_trace_marker.h" 16 15 #include "util/u_var.h" 17 16 ··· 361 360 U_DEVICE_ALLOCATE(struct wmr_controller_hp, flags, WMR_CONTROLLER_INDEX_COUNT, 1); 362 361 struct wmr_controller_base *wcb = (struct wmr_controller_base *)(ctrl); 363 362 364 - if (!wmr_controller_base_init(wcb, conn, controller_type, log_level)) { 363 + if (!wmr_controller_base_init(wcb, conn, controller_type, log_level, wmr_controller_hp_destroy)) { 365 364 wmr_controller_hp_destroy(&wcb->base); 366 365 return NULL; 367 366 } 368 367 369 368 wcb->handle_input_packet = handle_input_packet; 370 369 370 + // Only set those we want to overwrite. 371 + wcb->base.update_inputs = wmr_controller_hp_update_inputs; 371 372 wcb->base.name = XRT_DEVICE_HP_REVERB_G2_CONTROLLER; 372 373 373 374 if (controller_type == XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER) { ··· 375 376 } else { 376 377 snprintf(wcb->base.str, ARRAY_SIZE(wcb->base.str), "HP Reverb G2 Right Controller"); 377 378 } 378 - 379 - wcb->base.destroy = wmr_controller_hp_destroy; 380 - wcb->base.update_inputs = wmr_controller_hp_update_inputs; 381 - wcb->base.set_output = u_device_ni_set_output; 382 379 383 380 SET_INPUT(wcb, MENU_CLICK, MENU_CLICK); 384 381 SET_INPUT(wcb, HOME_CLICK, HOME_CLICK);
+4 -5
src/xrt/drivers/wmr/wmr_controller_og.c
··· 11 11 #include "math/m_api.h" 12 12 13 13 #include "util/u_device.h" 14 - #include "util/u_device_ni.h" 15 14 #include "util/u_trace_marker.h" 16 15 #include "util/u_var.h" 17 16 ··· 414 413 struct wmr_controller_og *ctrl = U_DEVICE_ALLOCATE(struct wmr_controller_og, flags, 11, 1); 415 414 struct wmr_controller_base *wcb = (struct wmr_controller_base *)(ctrl); 416 415 417 - if (!wmr_controller_base_init(wcb, conn, controller_type, log_level)) { 416 + if (!wmr_controller_base_init(wcb, conn, controller_type, log_level, wmr_controller_og_destroy)) { 418 417 wmr_controller_og_destroy(&wcb->base); 419 418 return NULL; 420 419 } 421 420 422 421 wcb->handle_input_packet = handle_input_packet; 423 422 423 + // Only set those we want to overwrite. 424 + wcb->base.update_inputs = wmr_controller_og_update_inputs; 425 + 424 426 if (pid == ODYSSEY_CONTROLLER_PID) { 425 427 wcb->base.name = XRT_DEVICE_SAMSUNG_ODYSSEY_CONTROLLER; 426 428 } else { 427 429 wcb->base.name = XRT_DEVICE_WMR_CONTROLLER; 428 430 } 429 - wcb->base.destroy = wmr_controller_og_destroy; 430 - wcb->base.update_inputs = wmr_controller_og_update_inputs; 431 - wcb->base.set_output = u_device_ni_set_output; 432 431 433 432 if (pid == ODYSSEY_CONTROLLER_PID) { 434 433 SET_ODYSSEY_INPUT(wcb, MENU_CLICK);