The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

t/gui: Add st/prober code

authored by

Jakob Bornecrantz and committed by
Jakob Bornecrantz
968952aa 44d58037

+157
+1
src/xrt/targets/gui/CMakeLists.txt
··· 16 16 set(SOURCE_FILES 17 17 gui_common.h 18 18 gui_main.c 19 + gui_prober.c 19 20 gui_sdl2.c 20 21 ../../../external/glad/gl.h 21 22 ../../../external/glad/gl.c
+33
src/xrt/targets/gui/gui_common.h
··· 24 24 extern "C" { 25 25 #endif 26 26 27 + #define NUM_XDEVS 8 28 + struct xrt_device; 29 + struct xrt_prober; 30 + struct time_state; 31 + 27 32 /*! 28 33 * Common struct holding state for the GUI interface. 29 34 * ··· 46 51 uint32_t height; 47 52 bool own_buffer; 48 53 } blit; 54 + 55 + struct time_state *timekeeping; 56 + struct xrt_device *xdevs[NUM_XDEVS]; 57 + struct xrt_prober *xp; 49 58 }; 50 59 51 60 /*! ··· 84 93 */ 85 94 void 86 95 gui_sdl2_quit(struct program *p); 96 + 97 + /*! 98 + * Initialize the prober and open all devices found. 99 + * 100 + * @ingroup gui 101 + */ 102 + int 103 + gui_prober_init(struct program *p); 104 + 105 + /*! 106 + * Update all devices. 107 + * 108 + * @ingroup gui 109 + */ 110 + void 111 + gui_prober_update(struct program *p); 112 + 113 + /*! 114 + * Destroy all opened devices and destroy the prober. 115 + * 116 + * @ingroup gui 117 + */ 118 + void 119 + gui_prober_teardown(struct program *p); 87 120 88 121 89 122 #ifdef __cplusplus
+123
src/xrt/targets/gui/gui_prober.c
··· 1 + // Copyright 2019, 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 "util/u_time.h" 10 + #include "target_lists.h" 11 + #include "gui_common.h" 12 + 13 + 14 + /* 15 + * 16 + * Helper functions. 17 + * 18 + */ 19 + 20 + static int 21 + do_exit(struct program *p, int ret) 22 + { 23 + gui_prober_teardown(p); 24 + return ret; 25 + } 26 + 27 + 28 + /* 29 + * 30 + * 'Exported' functions. 31 + * 32 + */ 33 + 34 + int 35 + gui_prober_init(struct program *p) 36 + { 37 + int ret = 0; 38 + 39 + p->timekeeping = time_state_create(); 40 + 41 + // Initialize the prober. 42 + printf(" :: Creating prober!\n"); 43 + 44 + ret = xrt_prober_create(&p->xp); 45 + if (ret != 0) { 46 + return do_exit(p, ret); 47 + } 48 + 49 + // Need to prime the prober with devices before dumping and listing. 50 + printf(" :: Probing!\n"); 51 + 52 + ret = xrt_prober_probe(p->xp); 53 + if (ret != 0) { 54 + return do_exit(p, ret); 55 + } 56 + 57 + // Multiple devices can be found. 58 + printf(" :: Selecting devices!\n"); 59 + 60 + ret = xrt_prober_select(p->xp, p->xdevs, NUM_XDEVS); 61 + if (ret != 0) { 62 + do_exit(p, ret); 63 + } 64 + if (p->xdevs[0] == NULL) { 65 + printf("\tNo HMD found! :(\n"); 66 + return do_exit(p, -1); 67 + } 68 + 69 + for (size_t i = 0; i < NUM_XDEVS; i++) { 70 + if (p->xdevs[i] == NULL) { 71 + continue; 72 + } 73 + 74 + printf("\tFound '%s'\n", p->xdevs[i]->str); 75 + } 76 + 77 + return 0; 78 + } 79 + 80 + void 81 + gui_prober_update(struct program *p) 82 + { 83 + // We haven't been initialized 84 + if (p->timekeeping == NULL) { 85 + return; 86 + } 87 + 88 + time_state_get_now_and_update(p->timekeeping); 89 + 90 + for (size_t i = 0; i < NUM_XDEVS; i++) { 91 + if (p->xdevs[i] == NULL) { 92 + continue; 93 + } 94 + 95 + p->xdevs[i]->update_inputs(p->xdevs[i], p->timekeeping); 96 + } 97 + } 98 + 99 + void 100 + gui_prober_teardown(struct program *p) 101 + { 102 + for (size_t i = 0; i < NUM_XDEVS; i++) { 103 + if (p->xdevs[i] == NULL) { 104 + continue; 105 + } 106 + 107 + p->xdevs[i]->destroy(p->xdevs[i]); 108 + p->xdevs[i] = NULL; 109 + } 110 + 111 + if (p->timekeeping != NULL) { 112 + time_state_destroy(p->timekeeping); 113 + p->timekeeping = NULL; 114 + } 115 + 116 + xrt_prober_destroy(&p->xp); 117 + } 118 + 119 + int 120 + xrt_prober_create(struct xrt_prober **out_xp) 121 + { 122 + return xrt_prober_create_with_lists(out_xp, &target_lists); 123 + }