The open source OpenXR runtime

xrt: Refactor oxr_sdl2_hack to u_debug_gui

And OXR_DEBUG_GUI to XRT_DEBUG_GUI

Co-authored-by: Jakob Bornecrantz <jakob@collabora.com>

+145 -120
+4 -2
CMakeLists.txt
··· 269 269 option_with_deps(XRT_FEATURE_STEAMVR_PLUGIN "Build SteamVR plugin" DEPENDS "NOT ANDROID") 270 270 option_with_deps(XRT_FEATURE_TRACING "Enable debug tracing on supported platforms" DEFAULT OFF DEPENDS "XRT_HAVE_PERCETTO OR XRT_HAVE_TRACY") 271 271 option_with_deps(XRT_FEATURE_WINDOW_PEEK "Enable a window that displays the content of the HMD on screen" DEPENDS XRT_HAVE_SDL2) 272 + option_with_deps(XRT_FEATURE_DEBUG_GUI "Enable debug window to be used" DEPENDS XRT_HAVE_SDL2) 272 273 option(XRT_FEATURE_SSE2 "Build using SSE2 instructions, if building for 32-bit x86" ON) 273 274 274 275 if (XRT_FEATURE_SERVICE) 275 276 # Disable the client debug gui by default for out-of-proc - 276 277 # too many clients have problems with depending on SDL/GStreamer/etc and we rarely use it in this configuration 277 - option(XRT_FEATURE_CLIENT_DEBUG_GUI "Allow clients to have their own instances of the debug gui" OFF) 278 + option_with_deps(XRT_FEATURE_CLIENT_DEBUG_GUI "Allow clients to have their own instances of the debug gui" DEFAULT OFF DEPENDS XRT_FEATURE_DEBUG_GUI) 278 279 else() 279 280 # Enable the client debug gui by default for in-proc - 280 281 # In in-proc, the client debug gui is the same as the server debug gui, and we use it a lot in this configuration 281 - option(XRT_FEATURE_CLIENT_DEBUG_GUI "Allow clients to have their own instances of the debug gui" ON) 282 + option_with_deps(XRT_FEATURE_CLIENT_DEBUG_GUI "Allow clients to have their own instances of the debug gui" DEFAULT ON DEPENDS XRT_FEATURE_DEBUG_GUI) 282 283 endif() 283 284 284 285 # systemd detailed config ··· 526 527 message(STATUS "#") 527 528 message(STATUS "# FEATURE_CLIENT_DEBUG_GUI: ${XRT_FEATURE_CLIENT_DEBUG_GUI}") 528 529 message(STATUS "# FEATURE_COLOR_LOG: ${XRT_FEATURE_COLOR_LOG}") 530 + message(STATUS "# FEATURE_DEBUG_GUI: ${XRT_FEATURE_DEBUG_GUI}") 529 531 message(STATUS "# FEATURE_MERCURY_HANDTRACKING: ${XRT_MODULE_MERCURY_HANDTRACKING}") 530 532 message(STATUS "# FEATURE_OPENXR: ${XRT_FEATURE_OPENXR}") 531 533 message(STATUS "# FEATURE_OPENXR_LAYER_CUBE: ${XRT_FEATURE_OPENXR_LAYER_CUBE}")
+31
src/xrt/auxiliary/util/CMakeLists.txt
··· 142 142 target_include_directories(aux_util PRIVATE ${EIGEN3_INCLUDE_DIR}) 143 143 144 144 #### 145 + # Debug UI library 146 + # 147 + 148 + add_library(aux_util_debug_gui STATIC u_debug_gui.c u_debug_gui.h) # Always built, for stubs. 149 + target_link_libraries( 150 + aux_util_debug_gui 151 + INTERFACE xrt-interfaces 152 + PRIVATE aux-includes 153 + ) 154 + 155 + if(XRT_FEATURE_DEBUG_GUI) 156 + target_link_libraries(aux_util_debug_gui PRIVATE aux_util) 157 + 158 + if(XRT_HAVE_OPENGL) 159 + target_link_libraries(aux_util_debug_gui PUBLIC aux_ogl) 160 + endif() 161 + 162 + if(XRT_HAVE_SDL2) 163 + target_link_libraries( 164 + aux_util_debug_gui PRIVATE st_gui xrt-external-imgui-sdl2 ${SDL2_LIBRARIES} 165 + ) 166 + 167 + if(XRT_BUILD_DRIVER_QWERTY) 168 + target_link_libraries( 169 + aux_util_debug_gui PRIVATE drv_qwerty drv_qwerty_includes 170 + ) 171 + endif() 172 + endif() 173 + endif() 174 + 175 + #### 145 176 # Sink library 146 177 # 147 178
+36
src/xrt/auxiliary/util/u_debug_gui.h
··· 1 + // Copyright 2019-2023, Collabora, Ltd. 2 + // SPDX-License-Identifier: BSL-1.0 3 + /*! 4 + * @file 5 + * @brief SDL2 Debug UI implementation 6 + * @author Jakob Bornecrantz <jakob@collabora.com> 7 + * @author Moses Turner <moses@collabora.com> 8 + */ 9 + 10 + #pragma once 11 + 12 + #include "xrt/xrt_compiler.h" 13 + 14 + 15 + #ifdef __cplusplus 16 + extern "C" { 17 + #endif 18 + 19 + struct xrt_instance; 20 + struct xrt_system_devices; 21 + 22 + struct u_debug_gui; 23 + 24 + int 25 + u_debug_gui_create(struct u_debug_gui **out_debug_gui); 26 + 27 + void 28 + u_debug_gui_start(struct u_debug_gui *debug_gui, struct xrt_instance *xinst, struct xrt_system_devices *xsysd); 29 + 30 + void 31 + u_debug_gui_stop(struct u_debug_gui **debug_gui); 32 + 33 + 34 + #ifdef __cplusplus 35 + } 36 + #endif
+1
src/xrt/include/xrt/xrt_config_build.h.cmake_in
··· 21 21 /* keep sorted */ 22 22 23 23 #cmakedefine XRT_FEATURE_COLOR_LOG 24 + #cmakedefine XRT_FEATURE_DEBUG_GUI 24 25 #cmakedefine XRT_FEATURE_OPENXR 25 26 #cmakedefine XRT_FEATURE_OPENXR_DEBUG_UTILS 26 27 #cmakedefine XRT_FEATURE_OPENXR_LAYER_CUBE
+1 -1
src/xrt/ipc/CMakeLists.txt
··· 92 92 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} 93 93 PRIVATE ${CMAKE_CURRENT_BINARY_DIR} 94 94 ) 95 - target_link_libraries(ipc_server PRIVATE aux_util aux_util_process ipc_shared) 95 + target_link_libraries(ipc_server PRIVATE aux_util aux_util_process aux_util_debug_gui ipc_shared) 96 96 97 97 if(XRT_HAVE_SYSTEMD) 98 98 target_include_directories(ipc_server PRIVATE ${SYSTEMD_INCLUDE_DIRS})
+1 -3
src/xrt/ipc/server/ipc_server.h
··· 295 295 //! Handle for the current process, e.g. pidfile on linux 296 296 struct u_process *process; 297 297 298 - /* ---- HACK ---- */ 299 - void *hack; 300 - /* ---- HACK ---- */ 298 + struct u_debug_gui *debug_gui; 301 299 302 300 //! System devices. 303 301 struct xrt_system_devices *xsysd;
+5 -22
src/xrt/ipc/server/ipc_server_process.c
··· 23 23 #include "util/u_trace_marker.h" 24 24 #include "util/u_verify.h" 25 25 #include "util/u_process.h" 26 + #include "util/u_debug_gui.h" 26 27 27 28 #include "util/u_git_tag.h" 28 29 ··· 39 40 #include <stdio.h> 40 41 #include <string.h> 41 42 #include <assert.h> 42 - 43 - /* ---- HACK ---- */ 44 - extern int 45 - oxr_sdl2_hack_create(void **out_hack); 46 - 47 - extern void 48 - oxr_sdl2_hack_start(void *hack, struct xrt_instance *xinst, struct xrt_system_devices *xsysd); 49 - 50 - extern void 51 - oxr_sdl2_hack_stop(void **hack_ptr); 52 - /* ---- HACK ---- */ 53 - 54 43 55 44 /* 56 45 * ··· 789 778 790 779 U_LOG_I("Monado Service %s starting up...", u_git_tag); 791 780 792 - /* ---- HACK ---- */ 793 781 // need to create early before any vars are added 794 - oxr_sdl2_hack_create(&s->hack); 795 - /* ---- HACK ---- */ 782 + u_debug_gui_create(&s->debug_gui); 796 783 797 784 int ret = init_all(s); 798 785 if (ret < 0) { 799 - free(s->hack); 786 + free(s->debug_gui); 800 787 free(s); 801 788 return ret; 802 789 } 803 790 804 791 init_server_state(s); 805 792 806 - /* ---- HACK ---- */ 807 - oxr_sdl2_hack_start(s->hack, s->xinst, s->xsysd); 808 - /* ---- HACK ---- */ 793 + u_debug_gui_start(s->debug_gui, s->xinst, s->xsysd); 809 794 810 795 ret = main_loop(s); 811 796 812 - /* ---- HACK ---- */ 813 - oxr_sdl2_hack_stop(&s->hack); 814 - /* ---- HACK ---- */ 797 + u_debug_gui_stop(&s->debug_gui); 815 798 816 799 teardown_all(s); 817 800 free(s);
+7 -22
src/xrt/state_trackers/oxr/oxr_instance.c
··· 19 19 #include "util/u_git_tag.h" 20 20 #include "util/u_builders.h" 21 21 22 + #ifdef XRT_FEATURE_CLIENT_DEBUG_GUI 23 + #include "util/u_debug_gui.h" 24 + #endif 25 + 22 26 #ifdef XRT_OS_ANDROID 23 27 #include "android/android_globals.h" 24 28 #include "android/android_looper.h" ··· 49 53 DEBUG_GET_ONCE_FLOAT_OPTION(tracking_origin_offset_y, "OXR_TRACKING_ORIGIN_OFFSET_Y", 0.0f) 50 54 DEBUG_GET_ONCE_FLOAT_OPTION(tracking_origin_offset_z, "OXR_TRACKING_ORIGIN_OFFSET_Z", 0.0f) 51 55 52 - #ifdef XRT_FEATURE_CLIENT_DEBUG_GUI 53 - /* ---- HACK ---- */ 54 - extern int 55 - oxr_sdl2_hack_create(void **out_hack); 56 - 57 - extern void 58 - oxr_sdl2_hack_start(void *hack, struct xrt_instance *xinst, struct xrt_system_devices *xsysd); 59 - 60 - extern void 61 - oxr_sdl2_hack_stop(void **hack_ptr); 62 - /* ---- HACK ---- */ 63 - #endif 64 - 65 56 static XrResult 66 57 oxr_instance_destroy(struct oxr_logger *log, struct oxr_handle_base *hb) 67 58 { ··· 82 73 xrt_system_devices_destroy(&inst->system.xsysd); 83 74 84 75 #ifdef XRT_FEATURE_CLIENT_DEBUG_GUI 85 - /* ---- HACK ---- */ 86 - oxr_sdl2_hack_stop(&inst->hack); 87 - /* ---- HACK ---- */ 76 + u_debug_gui_stop(&inst->debug_ui); 88 77 #endif 89 78 90 79 xrt_instance_destroy(&inst->xinst); ··· 204 193 } 205 194 206 195 #ifdef XRT_FEATURE_CLIENT_DEBUG_GUI 207 - /* ---- HACK ---- */ 208 - oxr_sdl2_hack_create(&inst->hack); 209 - /* ---- HACK ---- */ 196 + u_debug_gui_create(&inst->debug_ui); 210 197 #endif 211 198 212 199 ret = oxr_path_init(log, inst); ··· 343 330 u_var_add_root((void *)inst, "XrInstance", true); 344 331 345 332 #ifdef XRT_FEATURE_CLIENT_DEBUG_GUI 346 - /* ---- HACK ---- */ 347 - oxr_sdl2_hack_start(inst->hack, inst->xinst, sys->xsysd); 348 - /* ---- HACK ---- */ 333 + u_debug_gui_start(inst->debug_ui, inst->xinst, sys->xsysd); 349 334 #endif 350 335 351 336 oxr_log(log,
+1 -3
src/xrt/state_trackers/oxr/oxr_objects.h
··· 1360 1360 //! Common structure for things referred to by OpenXR handles. 1361 1361 struct oxr_handle_base handle; 1362 1362 1363 - /* ---- HACK ---- */ 1364 - void *hack; 1365 - /* ---- HACK ---- */ 1363 + struct u_debug_gui *debug_ui; 1366 1364 1367 1365 struct xrt_instance *xinst; 1368 1366
+2 -16
src/xrt/targets/openxr/CMakeLists.txt
··· 130 130 ) 131 131 endif() 132 132 133 - ### 134 - # Inelegant but effective SDL2-based debug GUI 135 - add_library(oxr_sdl2 STATIC oxr_sdl2_hack.c) 136 - target_link_libraries(oxr_sdl2 PRIVATE aux_util) 137 - if(XRT_HAVE_OPENGL) 138 - target_link_libraries(oxr_sdl2 PUBLIC aux_ogl) 139 - endif() 140 - if(XRT_HAVE_SDL2) 141 - target_link_libraries(oxr_sdl2 PRIVATE st_gui xrt-external-imgui-sdl2 ${SDL2_LIBRARIES}) 142 - 143 - if(XRT_BUILD_DRIVER_QWERTY) 144 - target_link_libraries(oxr_sdl2 PRIVATE drv_qwerty drv_qwerty_includes) 145 - endif() 146 - endif() 147 - 133 + # Optional debug ui 148 134 if(XRT_FEATURE_CLIENT_DEBUG_GUI) 149 - target_link_libraries(${RUNTIME_TARGET} PRIVATE oxr_sdl2) 135 + target_link_libraries(${RUNTIME_TARGET} PRIVATE aux_util_debug_gui) 150 136 endif()
+52 -47
src/xrt/targets/openxr/oxr_sdl2_hack.c src/xrt/auxiliary/util/u_debug_gui.c
··· 1 - // Copyright 2019, Collabora, Ltd. 1 + // Copyright 2019-2023, Collabora, Ltd. 2 2 // SPDX-License-Identifier: BSL-1.0 3 3 /*! 4 4 * @file 5 - * @brief Hacky SDL integration 5 + * @brief SDL2 Debug UI implementation 6 6 * @author Jakob Bornecrantz <jakob@collabora.com> 7 + * @author Moses Turner <moses@collabora.com> 7 8 */ 8 9 9 - #include "util/u_file.h" 10 - #include "xrt/xrt_compiler.h" 11 - #include "xrt/xrt_instance.h" 12 - #include "xrt/xrt_config_have.h" 13 - #include "xrt/xrt_config_drivers.h" 10 + #include "xrt/xrt_config_build.h" 14 11 15 - #include "util/u_var.h" 16 - #include "util/u_misc.h" 17 - #include "util/u_debug.h" 12 + #ifndef XRT_FEATURE_DEBUG_GUI 18 13 19 - #include "os/os_threading.h" 20 - 21 - 22 - struct xrt_instance; 23 - 24 - #ifndef XRT_HAVE_SDL2 14 + #include "util/u_debug_gui.h" 25 15 26 16 int 27 - oxr_sdl2_hack_create(void **out_hack) 17 + u_debug_gui_create(struct u_debug_gui **out_debug_ui) 28 18 { 29 19 return 0; 30 20 } 31 21 32 22 void 33 - oxr_sdl2_hack_start(void *hack, struct xrt_instance *xinst, struct xrt_system_devices *xsysd) 34 - {} 23 + u_debug_gui_start(struct u_debug_gui *debug_ui, struct xrt_instance *xinst, struct xrt_system_devices *xsysd) 24 + { 25 + // No-op 26 + } 35 27 36 28 void 37 - oxr_sdl2_hack_stop(void **hack) 38 - {} 29 + u_debug_gui_stop(struct u_debug_gui **debug_ui) 30 + { 31 + // No-op 32 + } 33 + 34 + #else /* XRT_FEATURE_DEBUG_GUI */ 39 35 40 - #else 41 36 #include "xrt/xrt_system.h" 37 + #include "xrt/xrt_instance.h" 38 + #include "xrt/xrt_config_have.h" 39 + #include "xrt/xrt_config_drivers.h" 40 + 41 + #include "os/os_threading.h" 42 + 43 + #include "util/u_var.h" 44 + #include "util/u_misc.h" 45 + #include "util/u_file.h" 46 + #include "util/u_debug.h" 47 + #include "util/u_debug_gui.h" 48 + 42 49 #include "ogl/ogl_api.h" 43 50 44 51 #include "gui/gui_common.h" ··· 50 57 51 58 #include <SDL2/SDL.h> 52 59 53 - DEBUG_GET_ONCE_BOOL_OPTION(gui, "OXR_DEBUG_GUI", false) 60 + DEBUG_GET_ONCE_BOOL_OPTION(gui, "XRT_DEBUG_GUI", false) 54 61 #ifdef XRT_BUILD_DRIVER_QWERTY 55 62 DEBUG_GET_ONCE_BOOL_OPTION(qwerty_enable, "QWERTY_ENABLE", false) 56 63 #endif ··· 60 67 * Common struct holding state for the GUI interface. 61 68 * @extends gui_program 62 69 */ 63 - struct sdl2_program 70 + struct u_debug_gui 64 71 { 65 72 struct gui_program base; 66 73 ··· 81 88 }; 82 89 83 90 static void 84 - sdl2_window_init(struct sdl2_program *p) 91 + sdl2_window_init(struct u_debug_gui *p) 85 92 { 86 93 const char *title = "Monado! ✨⚡🔥"; 87 94 int x = SDL_WINDOWPOS_UNDEFINED; ··· 137 144 } 138 145 139 146 static void 140 - sdl2_loop(struct sdl2_program *p) 147 + sdl2_loop(struct u_debug_gui *p) 141 148 { 142 149 // Need to call this before any other Imgui call. 143 150 igCreateContext(NULL); ··· 251 258 } 252 259 253 260 static void 254 - sdl2_close(struct sdl2_program *p) 261 + sdl2_close(struct u_debug_gui *p) 255 262 { 256 263 // All scenes should be destroyed by now. 257 264 gui_scene_manager_destroy(&p->base); ··· 276 283 } 277 284 278 285 static void * 279 - oxr_sdl2_hack_run_thread(void *ptr) 286 + u_debug_gui_run_thread(void *ptr) 280 287 { 281 - struct sdl2_program *p = (struct sdl2_program *)ptr; 282 - 283 - sdl2_window_init(p); 288 + struct u_debug_gui *debug_gui = (struct u_debug_gui *)ptr; 289 + sdl2_window_init(debug_gui); 284 290 285 - sdl2_loop(p); 291 + sdl2_loop(debug_gui); 286 292 287 - sdl2_close(p); 293 + sdl2_close(debug_gui); 288 294 289 295 return NULL; 290 296 } 291 297 292 298 int 293 - oxr_sdl2_hack_create(void **out_hack) 299 + u_debug_gui_create(struct u_debug_gui **out_debug_gui) 294 300 { 295 301 // Enabled? 296 302 if (!debug_get_bool_option_gui()) { ··· 300 306 // Need to do this as early as possible. 301 307 u_var_force_on(); 302 308 303 - struct sdl2_program *p = U_TYPED_CALLOC(struct sdl2_program); 309 + struct u_debug_gui *p = U_TYPED_CALLOC(struct u_debug_gui); 304 310 if (p == NULL) { 305 311 return -1; 306 312 } 307 313 308 314 os_thread_helper_init(&p->oth); 309 315 310 - *out_hack = p; 316 + *out_debug_gui = p; 311 317 312 318 return 0; 313 319 } 314 320 315 321 void 316 - oxr_sdl2_hack_start(void *hack, struct xrt_instance *xinst, struct xrt_system_devices *xsysd) 322 + u_debug_gui_start(struct u_debug_gui *debug_gui, struct xrt_instance *xinst, struct xrt_system_devices *xsysd) 317 323 { 318 - struct sdl2_program *p = (struct sdl2_program *)hack; 319 - if (p == NULL) { 324 + if (debug_gui == NULL) { 320 325 return; 321 326 } 322 327 323 328 // Share the system devices. 324 - p->base.xsysd = xsysd; 329 + debug_gui->base.xsysd = xsysd; 325 330 326 331 if (SDL_Init(SDL_INIT_EVERYTHING) < 0) { 327 332 U_LOG_E("Failed to init SDL2!"); 328 333 return; 329 334 } 330 - p->sdl_initialized = true; 335 + debug_gui->sdl_initialized = true; 331 336 332 - (void)os_thread_helper_start(&p->oth, oxr_sdl2_hack_run_thread, p); 337 + (void)os_thread_helper_start(&debug_gui->oth, u_debug_gui_run_thread, (void *)debug_gui); 333 338 } 334 339 335 340 void 336 - oxr_sdl2_hack_stop(void **hack_ptr) 341 + u_debug_gui_stop(struct u_debug_gui **debug_gui) 337 342 { 338 - struct sdl2_program *p = *(struct sdl2_program **)hack_ptr; 343 + struct u_debug_gui *p = *(struct u_debug_gui **)debug_gui; 339 344 if (p == NULL) { 340 345 return; 341 346 } 342 347 343 - // HACK! 344 348 p->base.stopped = true; 345 349 346 350 // Destroy the thread object. 347 351 os_thread_helper_destroy(&p->oth); 348 352 349 353 free(p); 350 - *hack_ptr = NULL; 354 + *debug_gui = NULL; 351 355 } 352 - #endif 356 + 357 + #endif /* XRT_FEATURE_DEBUG_GUI */
+3 -3
src/xrt/targets/sdl_test/sdl_hack_stubs.c
··· 13 13 14 14 15 15 int 16 - oxr_sdl2_hack_create(void **out_hack) 16 + u_debug_gui_create(void **out_hack) 17 17 { 18 18 return 0; 19 19 } 20 20 21 21 void 22 - oxr_sdl2_hack_start(void *hack, struct xrt_instance *xinst, struct xrt_system_devices *xsysd) 22 + u_debug_gui_start(void *hack, struct xrt_instance *xinst, struct xrt_system_devices *xsysd) 23 23 { 24 24 // Noop 25 25 } 26 26 27 27 void 28 - oxr_sdl2_hack_stop(void **hack) 28 + u_debug_gui_stop(void **hack) 29 29 { 30 30 // Noop 31 31 }
+1 -1
src/xrt/targets/service/CMakeLists.txt
··· 8 8 monado-service 9 9 PRIVATE 10 10 aux_util 11 + aux_util_debug_gui 11 12 st_prober 12 13 ipc_server 13 14 target_lists 14 15 target_instance 15 - oxr_sdl2 16 16 ) 17 17 18 18 install(TARGETS monado-service RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})