The open source OpenXR runtime
at main 110 lines 1.9 kB view raw
1// Copyright 2019-2023, Collabora, Ltd. 2// SPDX-License-Identifier: BSL-1.0 3/*! 4 * @file 5 * @brief Enable the use of the prober in the gui application. 6 * @author Jakob Bornecrantz <jakob@collabora.com> 7 */ 8 9#include "xrt/xrt_space.h" 10#include "xrt/xrt_prober.h" 11#include "xrt/xrt_system.h" 12#include "xrt/xrt_instance.h" 13 14#include "util/u_time.h" 15#include "util/u_trace_marker.h" 16 17#include "gui_common.h" 18 19 20/* 21 * 22 * Helper functions. 23 * 24 */ 25 26static int 27do_exit(struct gui_program *p, int ret) 28{ 29 gui_prober_teardown(p); 30 return ret; 31} 32 33 34/* 35 * 36 * 'Exported' functions. 37 * 38 */ 39 40int 41gui_prober_init(struct gui_program *p) 42{ 43 XRT_TRACE_MARKER(); 44 45 xrt_result_t xret; 46 47 // Initialize the prober. 48 xret = xrt_instance_create(NULL, &p->instance); 49 if (xret != 0) { 50 return do_exit(p, -1); 51 } 52 53 // Still need the prober to get video devices. 54 xret = xrt_instance_get_prober(p->instance, &p->xp); 55 if (xret != XRT_SUCCESS) { 56 return do_exit(p, -1); 57 } 58 59 if (p->xp != NULL) { 60 // Need to prime the prober with devices before dumping and listing. 61 xret = xrt_prober_probe(p->xp); 62 if (xret != XRT_SUCCESS) { 63 return do_exit(p, -1); 64 } 65 } 66 67 return 0; 68} 69 70int 71gui_prober_select(struct gui_program *p) 72{ 73 XRT_TRACE_MARKER(); 74 75 xrt_result_t xret = xrt_instance_create_system(p->instance, &p->xsys, &p->xsysd, &p->xso, NULL); 76 if (xret != XRT_SUCCESS) { 77 return -1; 78 } 79 80 return 0; 81} 82 83void 84gui_prober_update(struct gui_program *p) 85{ 86 XRT_TRACE_MARKER(); 87 88 if (!p->xsysd) { 89 return; 90 } 91 92 for (size_t i = 0; i < p->xsysd->xdev_count; i++) { 93 if (p->xsysd->xdevs[i] == NULL) { 94 continue; 95 } 96 xrt_device_update_inputs(p->xsysd->xdevs[i]); 97 } 98} 99 100void 101gui_prober_teardown(struct gui_program *p) 102{ 103 XRT_TRACE_MARKER(); 104 105 xrt_space_overseer_destroy(&p->xso); 106 xrt_system_devices_destroy(&p->xsysd); 107 xrt_system_destroy(&p->xsys); 108 109 xrt_instance_destroy(&p->instance); 110}