diff --git a/doc/changes/auxiliary/mr.2400.md b/doc/changes/auxiliary/mr.2400.md new file mode 100644 index 000000000..f601067af --- /dev/null +++ b/doc/changes/auxiliary/mr.2400.md @@ -0,0 +1,2 @@ +u/debug_gui: Add an interface to control the window title and if the window +opens or not. diff --git a/src/xrt/auxiliary/util/u_debug_gui.c b/src/xrt/auxiliary/util/u_debug_gui.c index 156679d4d..0418a8e7b 100644 --- a/src/xrt/auxiliary/util/u_debug_gui.c +++ b/src/xrt/auxiliary/util/u_debug_gui.c @@ -1,4 +1,5 @@ // Copyright 2019-2024, Collabora, Ltd. +// Copyright 2024-2025, NVIDIA CORPORATION. // SPDX-License-Identifier: BSL-1.0 /*! * @file @@ -16,7 +17,7 @@ struct u_debug_gui; int -u_debug_gui_create(struct u_debug_gui **out_debug_ui) +u_debug_gui_create(const struct u_debug_gui_create_info *udgci, struct u_debug_gui **out_debug_ui) { return 0; } @@ -72,6 +73,9 @@ struct u_debug_gui { struct gui_program base; + //! Information passed in at create. + struct u_debug_gui_create_info udgci; + SDL_GLContext ctx; SDL_Window *win; @@ -97,7 +101,6 @@ sdl2_window_init(struct u_debug_gui *p) { XRT_TRACE_MARKER(); - const char *title = "Monado! ✨⚡🔥"; int x = SDL_WINDOWPOS_UNDEFINED; int y = SDL_WINDOWPOS_UNDEFINED; int w = 1920; @@ -121,7 +124,7 @@ sdl2_window_init(struct u_debug_gui *p) window_flags |= SDL_WINDOW_MAXIMIZED; #endif - p->win = SDL_CreateWindow(title, x, y, w, h, window_flags); + p->win = SDL_CreateWindow(p->udgci.window_title, x, y, w, h, window_flags); if (p->win == NULL) { U_LOG_E("Failed to create window!"); return; @@ -340,13 +343,18 @@ u_debug_gui_run_thread(void *ptr) } int -u_debug_gui_create(struct u_debug_gui **out_debug_gui) +u_debug_gui_create(const struct u_debug_gui_create_info *udgci, struct u_debug_gui **out_debug_gui) { XRT_TRACE_MARKER(); - // Enabled? - if (!debug_get_bool_option_gui()) { - return 0; + switch (udgci->open) { + case U_DEBUG_GUI_OPEN_AUTO: + if (!debug_get_bool_option_gui()) { + return 0; + } + break; + case U_DEBUG_GUI_OPEN_ALWAYS: break; + case U_DEBUG_GUI_OPEN_NEVER: return 0; // No-op } // Need to do this as early as possible. @@ -357,6 +365,9 @@ u_debug_gui_create(struct u_debug_gui **out_debug_gui) return -1; } + // Copy the data. + p->udgci = *udgci; + os_thread_helper_init(&p->oth); *out_debug_gui = p; diff --git a/src/xrt/auxiliary/util/u_debug_gui.h b/src/xrt/auxiliary/util/u_debug_gui.h index cc3e24f17..041855001 100644 --- a/src/xrt/auxiliary/util/u_debug_gui.h +++ b/src/xrt/auxiliary/util/u_debug_gui.h @@ -1,4 +1,5 @@ // Copyright 2019-2023, Collabora, Ltd. +// Copyright 2024-2025, NVIDIA CORPORATION. // SPDX-License-Identifier: BSL-1.0 /*! * @file @@ -16,17 +17,71 @@ extern "C" { #endif +#define U_DEBUG_GUI_WINDOW_TITLE_MAX (256) + struct xrt_instance; struct xrt_system_devices; struct u_debug_gui; +/*! + * Controls if the debug gui window is opened, allowing code to always call + * create and progmatically or external control if the window is opened. + * + * @ingroup aux_util + */ +enum u_debug_gui_open +{ + //! Opens the window if the environmental variable XRT_DEBUG_GUI is true. + U_DEBUG_GUI_OPEN_AUTO, + //! Always (if supported) opens the window. + U_DEBUG_GUI_OPEN_ALWAYS, + //! Never opens the window. + U_DEBUG_GUI_OPEN_NEVER, +}; + +/*! + * Argument to the function @ref u_debug_gui_create. + * + * @ingroup aux_util + */ +struct u_debug_gui_create_info +{ + char window_title[U_DEBUG_GUI_WINDOW_TITLE_MAX]; + + enum u_debug_gui_open open; +}; + +/*! + * Creates the debug gui, may not create it. + * + * If the debug gui is disabled through the means listed below this function + * will return 0, but not create any struct and set @p out_debug_gui to NULL. + * It is safe to call the other functions with a NULL @p debug_gui argument. + * + * The window will be disabled and 0 returned if: + * * Monado was compiled without the needed dependencies, like SDL. + * * The @p open field on the info struct set to NEVER. + * * The XRT_DEBUG_GUI env variable is false (or unset). + * + * @ingroup aux_util + */ int -u_debug_gui_create(struct u_debug_gui **out_debug_gui); +u_debug_gui_create(const struct u_debug_gui_create_info *info, struct u_debug_gui **out_debug_gui); +/*! + * Starts the debug gui, also passes in some structs that might be needed. + * + * @ingroup aux_util + */ void u_debug_gui_start(struct u_debug_gui *debug_gui, struct xrt_instance *xinst, struct xrt_system_devices *xsysd); +/*! + * Stops the debug gui, closing the window and freeing resources. + * + * @ingroup aux_util + */ void u_debug_gui_stop(struct u_debug_gui **debug_gui); diff --git a/src/xrt/ipc/server/ipc_server_process.c b/src/xrt/ipc/server/ipc_server_process.c index fe84b0c46..2bf73ff03 100644 --- a/src/xrt/ipc/server/ipc_server_process.c +++ b/src/xrt/ipc/server/ipc_server_process.c @@ -1,4 +1,5 @@ // Copyright 2020-2024, Collabora, Ltd. +// Copyright 2024-2025, NVIDIA CORPORATION. // SPDX-License-Identifier: BSL-1.0 /*! * @file @@ -1018,12 +1019,18 @@ ipc_server_main(int argc, char **argv) timeBeginPeriod(1); #endif + struct u_debug_gui_info udgci = { + .window_title = "Monado! ✨⚡🔥", + .open = U_DEBUG_GUI_OPEN_AUTO, + }; + /* * Need to create early before any vars are added. Not created in * init_all since that function is shared with Android and the debug * GUI isn't supported on Android. */ - u_debug_gui_create(&s->debug_gui); + u_debug_gui_create(&udgci, &s->debug_gui); + int ret = init_all(s, log_level); if (ret < 0) { diff --git a/src/xrt/state_trackers/oxr/oxr_instance.c b/src/xrt/state_trackers/oxr/oxr_instance.c index 771be73ae..b36c65708 100644 --- a/src/xrt/state_trackers/oxr/oxr_instance.c +++ b/src/xrt/state_trackers/oxr/oxr_instance.c @@ -1,4 +1,5 @@ // Copyright 2018-2024, Collabora, Ltd. +// Copyright 2024-2025, NVIDIA CORPORATION. // SPDX-License-Identifier: BSL-1.0 /*! * @file @@ -250,7 +251,12 @@ oxr_instance_create(struct oxr_logger *log, } #ifdef XRT_FEATURE_CLIENT_DEBUG_GUI - u_debug_gui_create(&inst->debug_ui); + struct u_debug_gui_create_info udgci = { + .window_title = "Monado! ✨⚡🔥", + .open = U_DEBUG_GUI_OPEN_AUTO, + }; + + u_debug_gui_create(&udgci, &inst->debug_ui); #endif ret = oxr_path_init(log, inst); diff --git a/src/xrt/targets/sdl_test/sdl_hack_stubs.c b/src/xrt/targets/sdl_test/sdl_hack_stubs.c index ad103d309..f66443831 100644 --- a/src/xrt/targets/sdl_test/sdl_hack_stubs.c +++ b/src/xrt/targets/sdl_test/sdl_hack_stubs.c @@ -13,7 +13,7 @@ struct xrt_system_devices; int -u_debug_gui_create(void **out_hack) +u_debug_gui_create(void *hack, void **out_hack) { return 0; }