The open source OpenXR runtime

xrt: Return xrt_system when creating system

+105 -23
+5 -1
src/xrt/include/xrt/xrt_instance.h
··· 22 22 struct xrt_prober; 23 23 struct xrt_device; 24 24 struct xrt_space_overseer; 25 + struct xrt_system; 25 26 struct xrt_system_devices; 26 27 struct xrt_system_compositor; 27 28 ··· 81 82 * @note Code consuming this interface should use xrt_instance_create_system() 82 83 * 83 84 * @param xinst Pointer to self 85 + * @param[out] out_xsys Return of system, required. 84 86 * @param[out] out_xsysd Return of devices, required. 85 87 * @param[out] out_xsysc Return of system compositor, optional. 86 88 * 87 89 * @see xrt_prober::probe, xrt_prober::select, xrt_gfx_provider_create_native 88 90 */ 89 91 xrt_result_t (*create_system)(struct xrt_instance *xinst, 92 + struct xrt_system **out_xsys, 90 93 struct xrt_system_devices **out_xsysd, 91 94 struct xrt_space_overseer **out_xso, 92 95 struct xrt_system_compositor **out_xsysc); ··· 139 142 */ 140 143 static inline xrt_result_t 141 144 xrt_instance_create_system(struct xrt_instance *xinst, 145 + struct xrt_system **out_xsys, 142 146 struct xrt_system_devices **out_xsysd, 143 147 struct xrt_space_overseer **out_xso, 144 148 struct xrt_system_compositor **out_xsysc) 145 149 { 146 - return xinst->create_system(xinst, out_xsysd, out_xso, out_xsysc); 150 + return xinst->create_system(xinst, out_xsys, out_xsysd, out_xso, out_xsysc); 147 151 } 148 152 149 153 /*!
+23 -10
src/xrt/ipc/client/ipc_client_instance.c
··· 130 130 131 131 static xrt_result_t 132 132 ipc_client_instance_create_system(struct xrt_instance *xinst, 133 + struct xrt_system **out_xsys, 133 134 struct xrt_system_devices **out_xsysd, 134 135 struct xrt_space_overseer **out_xso, 135 136 struct xrt_system_compositor **out_xsysc) ··· 137 138 struct ipc_client_instance *ii = ipc_client_instance(xinst); 138 139 xrt_result_t xret = XRT_SUCCESS; 139 140 141 + assert(out_xsys != NULL); 142 + assert(*out_xsys == NULL); 140 143 assert(out_xsysd != NULL); 141 144 assert(*out_xsysd == NULL); 142 145 assert(out_xsysc == NULL || *out_xsysc == NULL); 143 146 147 + struct xrt_system_devices *xsysd = NULL; 148 + struct xrt_system_compositor *xsysc = NULL; 149 + 144 150 // Allocate a helper xrt_system_devices struct. 145 - struct xrt_system_devices *xsysd = ipc_client_system_devices_create(&ii->ipc_c); 151 + xsysd = ipc_client_system_devices_create(&ii->ipc_c); 146 152 147 153 // Take the devices from this instance. 148 154 for (uint32_t i = 0; i < ii->xdev_count; i++) { ··· 167 173 168 174 // Done here now. 169 175 if (out_xsysc == NULL) { 170 - *out_xsysd = xsysd; 171 - *out_xso = ipc_client_space_overseer_create(&ii->ipc_c); 172 - return XRT_SUCCESS; 176 + goto out; 173 177 } 174 178 175 179 if (xsysd->static_roles.head == NULL) { 176 180 IPC_ERROR((&ii->ipc_c), "No head device found but asking for system compositor!"); 177 - xrt_system_devices_destroy(&xsysd); 178 - return XRT_ERROR_IPC_FAILURE; 181 + xret = XRT_ERROR_IPC_FAILURE; 182 + goto err_destroy; 179 183 } 180 184 181 - struct xrt_system_compositor *xsysc = NULL; 182 185 xret = create_system_compositor(ii, xsysd->static_roles.head, &xsysc); 183 186 if (xret != XRT_SUCCESS) { 184 - xrt_system_devices_destroy(&xsysd); 185 - return xret; 187 + goto err_destroy; 186 188 } 187 189 190 + out: 191 + *out_xsys = ipc_client_system_create(&ii->ipc_c, xsysc); 188 192 *out_xsysd = xsysd; 189 193 *out_xso = ipc_client_space_overseer_create(&ii->ipc_c); 190 - *out_xsysc = xsysc; 194 + 195 + if (xsysc != NULL) { 196 + assert(out_xsysc != NULL); 197 + *out_xsysc = xsysc; 198 + } 191 199 192 200 return XRT_SUCCESS; 201 + 202 + err_destroy: 203 + xrt_system_devices_destroy(&xsysd); 204 + 205 + return xret; 193 206 } 194 207 195 208 static xrt_result_t
+3
src/xrt/ipc/server/ipc_server.h
··· 320 320 321 321 struct u_debug_gui *debug_gui; 322 322 323 + //! The @ref xrt_iface level system. 324 + struct xrt_system *xsys; 325 + 323 326 //! System devices. 324 327 struct xrt_system_devices *xsysd; 325 328
+2 -1
src/xrt/ipc/server/ipc_server_process.c
··· 135 135 136 136 xrt_space_overseer_destroy(&s->xso); 137 137 xrt_system_devices_destroy(&s->xsysd); 138 + xrt_system_destroy(&s->xsys); 138 139 139 140 xrt_instance_destroy(&s->xinst); 140 141 ··· 484 485 return -1; 485 486 } 486 487 487 - xret = xrt_instance_create_system(s->xinst, &s->xsysd, &s->xso, &s->xsysc); 488 + xret = xrt_instance_create_system(s->xinst, &s->xsys, &s->xsysd, &s->xso, &s->xsysc); 488 489 if (xret != XRT_SUCCESS) { 489 490 IPC_ERROR(s, "Could not create system!"); 490 491 teardown_all(s);
+1
src/xrt/state_trackers/gui/gui_common.h
··· 46 46 47 47 struct gui_scene_manager *gsm; 48 48 49 + struct xrt_system *xsys; 49 50 struct xrt_system_devices *xsysd; 50 51 struct xrt_space_overseer *xso; 51 52 struct xrt_instance *instance;
+2 -1
src/xrt/state_trackers/gui/gui_prober.c
··· 72 72 { 73 73 XRT_TRACE_MARKER(); 74 74 75 - xrt_result_t xret = xrt_instance_create_system(p->instance, &p->xsysd, &p->xso, NULL); 75 + xrt_result_t xret = xrt_instance_create_system(p->instance, &p->xsys, &p->xsysd, &p->xso, NULL); 76 76 if (xret != XRT_SUCCESS) { 77 77 return -1; 78 78 } ··· 104 104 105 105 xrt_space_overseer_destroy(&p->xso); 106 106 xrt_system_devices_destroy(&p->xsysd); 107 + xrt_system_destroy(&p->xsys); 107 108 108 109 xrt_instance_destroy(&p->instance); 109 110 }
+2 -2
src/xrt/state_trackers/oxr/oxr_instance.c
··· 316 316 317 317 // Create the system. 318 318 if (should_create_compositor) { 319 - xret = xrt_instance_create_system(inst->xinst, &sys->xsysd, &sys->xso, &sys->xsysc); 319 + xret = xrt_instance_create_system(inst->xinst, &sys->xsys, &sys->xsysd, &sys->xso, &sys->xsysc); 320 320 } else { 321 - xret = xrt_instance_create_system(inst->xinst, &sys->xsysd, &sys->xso, NULL); 321 + xret = xrt_instance_create_system(inst->xinst, &sys->xsys, &sys->xsysd, &sys->xso, NULL); 322 322 } 323 323 324 324 if (xret != XRT_SUCCESS) {
+3
src/xrt/state_trackers/oxr/oxr_objects.h
··· 1273 1273 { 1274 1274 struct oxr_instance *inst; 1275 1275 1276 + //! The @ref xrt_iface level system. 1277 + struct xrt_system *xsys; 1278 + 1276 1279 //! System devices used in all session types. 1277 1280 struct xrt_system_devices *xsysd; 1278 1281
+4 -1
src/xrt/state_trackers/steamvr_drv/ovrd_driver.cpp
··· 1440 1440 1441 1441 private: 1442 1442 struct xrt_instance *m_xinst = NULL; 1443 + struct xrt_system *m_xsys = NULL; 1443 1444 struct xrt_system_devices *m_xsysd = NULL; 1444 1445 struct xrt_space_overseer *m_xso = NULL; 1445 1446 struct xrt_device *m_xhmd = NULL; ··· 1471 1472 return vr::VRInitError_Init_HmdNotFound; 1472 1473 } 1473 1474 1474 - xret = xrt_instance_create_system(m_xinst, &m_xsysd, &m_xso, NULL); 1475 + xret = xrt_instance_create_system(m_xinst, &m_xsys, &m_xsysd, &m_xso, NULL); 1475 1476 if (xret < 0) { 1476 1477 ovrd_log("Failed to create system devices\n"); 1477 1478 xrt_instance_destroy(&m_xinst); ··· 1481 1482 ovrd_log("Didn't get a HMD device!\n"); 1482 1483 xrt_space_overseer_destroy(&m_xso); 1483 1484 xrt_system_devices_destroy(&m_xsysd); 1485 + xrt_system_destroy(&m_xsys); 1484 1486 xrt_instance_destroy(&m_xinst); 1485 1487 return vr::VRInitError_Init_HmdNotFound; 1486 1488 } ··· 1530 1532 1531 1533 xrt_space_overseer_destroy(&m_xso); 1532 1534 xrt_system_devices_destroy(&m_xsysd); 1535 + xrt_system_destroy(&m_xsys); 1533 1536 m_xhmd = NULL; 1534 1537 m_left->m_xdev = NULL; 1535 1538 m_right->m_xdev = NULL;
+3
src/xrt/targets/cli/cli_cmd_probe.c
··· 48 48 // Need to prime the prober with devices before dumping and listing. 49 49 printf(" :: Creating system devices!\n"); 50 50 51 + struct xrt_system *xsys = NULL; 51 52 struct xrt_system_devices *xsysd = NULL; 52 53 struct xrt_space_overseer *xso = NULL; 53 54 xret = xrt_instance_create_system( // 54 55 xi, // Instance 56 + &xsys, // System 55 57 &xsysd, // System devices. 56 58 &xso, // Space overseer. 57 59 NULL); // System compositor. ··· 119 121 120 122 xrt_space_overseer_destroy(&xso); 121 123 xrt_system_devices_destroy(&xsysd); 124 + xrt_system_destroy(&xsys); 122 125 123 126 // End of program 124 127 printf(" :: All ok, shutting down.\n");
+3
src/xrt/targets/cli/cli_cmd_test.c
··· 75 75 // (multiple) devices. 76 76 printf(" :: Creating system devices!\n"); 77 77 78 + struct xrt_system *xsys = NULL; 78 79 struct xrt_system_devices *xsysd = NULL; 79 80 struct xrt_space_overseer *xso = NULL; 80 81 xret = xrt_instance_create_system( // 81 82 xi, // Instance 83 + &xsys, // System 82 84 &xsysd, // System devices. 83 85 &xso, // Space Overseer. 84 86 NULL); // System compositor. ··· 141 143 142 144 xrt_space_overseer_destroy(&xso); 143 145 xrt_system_devices_destroy(&xsysd); 146 + xrt_system_destroy(&xsys); 144 147 145 148 // Finally done 146 149 return do_exit(&xi, 0);
+28 -6
src/xrt/targets/common/target_instance.c
··· 13 13 #include "os/os_time.h" 14 14 15 15 #include "util/u_debug.h" 16 + #include "util/u_system.h" 16 17 #include "util/u_trace_marker.h" 17 18 #include "util/u_system_helpers.h" 18 19 ··· 46 47 47 48 static xrt_result_t 48 49 t_instance_create_system(struct xrt_instance *xinst, 50 + struct xrt_system **out_xsys, 49 51 struct xrt_system_devices **out_xsysd, 50 52 struct xrt_space_overseer **out_xso, 51 53 struct xrt_system_compositor **out_xsysc) 52 54 { 53 55 XRT_TRACE_MARKER(); 54 56 57 + assert(out_xsys != NULL); 58 + assert(*out_xsys == NULL); 55 59 assert(out_xsysd != NULL); 56 60 assert(*out_xsysd == NULL); 57 61 assert(out_xso != NULL); 58 62 assert(*out_xso == NULL); 59 63 assert(out_xsysc == NULL || *out_xsysc == NULL); 60 64 65 + struct u_system *usys = NULL; 61 66 struct xrt_system_compositor *xsysc = NULL; 62 67 struct xrt_space_overseer *xso = NULL; 63 68 struct xrt_system_devices *xsysd = NULL; 64 69 xrt_result_t xret = XRT_SUCCESS; 65 70 71 + usys = u_system_create(); 72 + assert(usys != NULL); // Should never fail. 73 + 66 74 xret = u_system_devices_create_from_prober(xinst, &xsysd, &xso); 67 75 if (xret != XRT_SUCCESS) { 68 76 return xret; ··· 70 78 71 79 // Early out if we only want devices. 72 80 if (out_xsysc == NULL) { 73 - *out_xsysd = xsysd; 74 - return XRT_SUCCESS; 81 + goto out; 75 82 } 76 83 77 84 struct xrt_device *head = xsysd->static_roles.head; ··· 101 108 #endif 102 109 103 110 if (xret != XRT_SUCCESS) { 104 - xrt_space_overseer_destroy(&xso); 105 - xrt_system_devices_destroy(&xsysd); 106 - return xret; 111 + goto err_destroy; 107 112 } 108 113 114 + out: 115 + *out_xsys = &usys->base; 109 116 *out_xsysd = xsysd; 110 117 *out_xso = xso; 111 - *out_xsysc = xsysc; 118 + 119 + if (xsysc != NULL) { 120 + // Tell the system about the system compositor. 121 + u_system_set_system_compositor(usys, xsysc); 122 + 123 + assert(out_xsysc != NULL); 124 + *out_xsysc = xsysc; 125 + } 126 + 127 + return xret; 128 + 129 + 130 + err_destroy: 131 + xrt_space_overseer_destroy(&xso); 132 + xrt_system_devices_destroy(&xsysd); 133 + u_system_destroy(&usys); 112 134 113 135 return xret; 114 136 }
+10
src/xrt/targets/common/target_instance_no_comp.c
··· 8 8 */ 9 9 10 10 #include "xrt/xrt_system.h" 11 + 12 + #include "util/u_system.h" 11 13 #include "util/u_trace_marker.h" 12 14 #include "util/u_system_helpers.h" 15 + 13 16 #include "target_instance_parts.h" 14 17 15 18 #include <assert.h> ··· 17 20 18 21 static xrt_result_t 19 22 t_instance_create_system(struct xrt_instance *xinst, 23 + struct xrt_system **out_xsys, 20 24 struct xrt_system_devices **out_xsysd, 21 25 struct xrt_space_overseer **out_xso, 22 26 struct xrt_system_compositor **out_xsysc) 23 27 { 24 28 XRT_TRACE_MARKER(); 25 29 30 + struct u_system *usys = NULL; 26 31 struct xrt_system_devices *xsysd = NULL; 27 32 struct xrt_space_overseer *xso = NULL; 28 33 xrt_result_t xret = XRT_SUCCESS; ··· 38 43 return XRT_ERROR_ALLOCATION; 39 44 } 40 45 46 + usys = u_system_create(); 47 + assert(usys != NULL); // Should never fail. 48 + 41 49 xret = u_system_devices_create_from_prober(xinst, &xsysd, &xso); 42 50 if (xret != XRT_SUCCESS) { 51 + u_system_destroy(&usys); 43 52 return xret; 44 53 } 45 54 55 + *out_xsys = &usys->base; 46 56 *out_xsysd = xsysd; 47 57 *out_xso = xso; 48 58
+16 -1
src/xrt/targets/sdl_test/sdl_instance.c
··· 11 11 #include "xrt/xrt_config_drivers.h" 12 12 13 13 #include "util/u_misc.h" 14 + #include "util/u_system.h" 14 15 #include "util/u_builders.h" 15 16 #include "util/u_trace_marker.h" 16 17 ··· 66 67 67 68 static xrt_result_t 68 69 sdl_instance_create_system(struct xrt_instance *xinst, 70 + struct xrt_system **out_xsys, 69 71 struct xrt_system_devices **out_xsysd, 70 72 struct xrt_space_overseer **out_xso, 71 73 struct xrt_system_compositor **out_xsysc) 72 74 { 75 + assert(out_xsys != NULL); 76 + assert(*out_xsys == NULL); 73 77 assert(out_xsysd != NULL); 74 78 assert(*out_xsysd == NULL); 75 79 assert(out_xso != NULL); 76 80 assert(*out_xso == NULL); 77 81 assert(out_xsysc == NULL || *out_xsysc == NULL); 78 82 83 + // Use system helper. 84 + struct u_system *usys = u_system_create(); 85 + assert(usys != NULL); // Should never fail. 86 + 79 87 struct sdl_program *sp = from_xinst(xinst); 80 88 89 + *out_xsys = &usys->base; 81 90 *out_xsysd = &sp->xsysd_base; 82 91 *out_xso = sp->xso; 83 92 ··· 86 95 return XRT_SUCCESS; 87 96 } 88 97 89 - sdl_compositor_create_system(sp, out_xsysc); 98 + struct xrt_system_compositor *xsysc = NULL; 99 + sdl_compositor_create_system(sp, &xsysc); 100 + 101 + // Tell the system about the system compositor. 102 + u_system_set_system_compositor(usys, xsysc); 103 + 104 + *out_xsysc = xsysc; 90 105 91 106 return XRT_SUCCESS; 92 107 }