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>
This commit is contained in:
Moshi Turner 2023-03-06 16:28:50 -06:00
parent e338d57945
commit 7485afbeaa
13 changed files with 145 additions and 120 deletions

View file

@ -269,16 +269,17 @@ option_with_deps(XRT_FEATURE_SLAM "Enable SLAM tracking support" DEPENDS XRT_HAV
option_with_deps(XRT_FEATURE_STEAMVR_PLUGIN "Build SteamVR plugin" DEPENDS "NOT ANDROID")
option_with_deps(XRT_FEATURE_TRACING "Enable debug tracing on supported platforms" DEFAULT OFF DEPENDS "XRT_HAVE_PERCETTO OR XRT_HAVE_TRACY")
option_with_deps(XRT_FEATURE_WINDOW_PEEK "Enable a window that displays the content of the HMD on screen" DEPENDS XRT_HAVE_SDL2)
option_with_deps(XRT_FEATURE_DEBUG_GUI "Enable debug window to be used" DEPENDS XRT_HAVE_SDL2)
option(XRT_FEATURE_SSE2 "Build using SSE2 instructions, if building for 32-bit x86" ON)
if (XRT_FEATURE_SERVICE)
# Disable the client debug gui by default for out-of-proc -
# too many clients have problems with depending on SDL/GStreamer/etc and we rarely use it in this configuration
option(XRT_FEATURE_CLIENT_DEBUG_GUI "Allow clients to have their own instances of the debug gui" OFF)
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)
else()
# Enable the client debug gui by default for in-proc -
# In in-proc, the client debug gui is the same as the server debug gui, and we use it a lot in this configuration
option(XRT_FEATURE_CLIENT_DEBUG_GUI "Allow clients to have their own instances of the debug gui" ON)
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)
endif()
# systemd detailed config
@ -526,6 +527,7 @@ message(STATUS "# MODULE_MONADO_CLI ${XRT_MODULE_MONADO_CLI}")
message(STATUS "#")
message(STATUS "# FEATURE_CLIENT_DEBUG_GUI: ${XRT_FEATURE_CLIENT_DEBUG_GUI}")
message(STATUS "# FEATURE_COLOR_LOG: ${XRT_FEATURE_COLOR_LOG}")
message(STATUS "# FEATURE_DEBUG_GUI: ${XRT_FEATURE_DEBUG_GUI}")
message(STATUS "# FEATURE_MERCURY_HANDTRACKING: ${XRT_MODULE_MERCURY_HANDTRACKING}")
message(STATUS "# FEATURE_OPENXR: ${XRT_FEATURE_OPENXR}")
message(STATUS "# FEATURE_OPENXR_LAYER_CUBE: ${XRT_FEATURE_OPENXR_LAYER_CUBE}")

View file

@ -141,6 +141,37 @@ endif()
# Internal dependency and doesn't bring in any DSO.
target_include_directories(aux_util PRIVATE ${EIGEN3_INCLUDE_DIR})
####
# Debug UI library
#
add_library(aux_util_debug_gui STATIC u_debug_gui.c u_debug_gui.h) # Always built, for stubs.
target_link_libraries(
aux_util_debug_gui
INTERFACE xrt-interfaces
PRIVATE aux-includes
)
if(XRT_FEATURE_DEBUG_GUI)
target_link_libraries(aux_util_debug_gui PRIVATE aux_util)
if(XRT_HAVE_OPENGL)
target_link_libraries(aux_util_debug_gui PUBLIC aux_ogl)
endif()
if(XRT_HAVE_SDL2)
target_link_libraries(
aux_util_debug_gui PRIVATE st_gui xrt-external-imgui-sdl2 ${SDL2_LIBRARIES}
)
if(XRT_BUILD_DRIVER_QWERTY)
target_link_libraries(
aux_util_debug_gui PRIVATE drv_qwerty drv_qwerty_includes
)
endif()
endif()
endif()
####
# Sink library
#

View file

@ -1,44 +1,51 @@
// Copyright 2019, Collabora, Ltd.
// Copyright 2019-2023, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0
/*!
* @file
* @brief Hacky SDL integration
* @brief SDL2 Debug UI implementation
* @author Jakob Bornecrantz <jakob@collabora.com>
* @author Moses Turner <moses@collabora.com>
*/
#include "util/u_file.h"
#include "xrt/xrt_compiler.h"
#include "xrt/xrt_instance.h"
#include "xrt/xrt_config_have.h"
#include "xrt/xrt_config_drivers.h"
#include "xrt/xrt_config_build.h"
#include "util/u_var.h"
#include "util/u_misc.h"
#include "util/u_debug.h"
#ifndef XRT_FEATURE_DEBUG_GUI
#include "os/os_threading.h"
struct xrt_instance;
#ifndef XRT_HAVE_SDL2
#include "util/u_debug_gui.h"
int
oxr_sdl2_hack_create(void **out_hack)
u_debug_gui_create(struct u_debug_gui **out_debug_ui)
{
return 0;
}
void
oxr_sdl2_hack_start(void *hack, struct xrt_instance *xinst, struct xrt_system_devices *xsysd)
{}
u_debug_gui_start(struct u_debug_gui *debug_ui, struct xrt_instance *xinst, struct xrt_system_devices *xsysd)
{
// No-op
}
void
oxr_sdl2_hack_stop(void **hack)
{}
u_debug_gui_stop(struct u_debug_gui **debug_ui)
{
// No-op
}
#else /* XRT_FEATURE_DEBUG_GUI */
#else
#include "xrt/xrt_system.h"
#include "xrt/xrt_instance.h"
#include "xrt/xrt_config_have.h"
#include "xrt/xrt_config_drivers.h"
#include "os/os_threading.h"
#include "util/u_var.h"
#include "util/u_misc.h"
#include "util/u_file.h"
#include "util/u_debug.h"
#include "util/u_debug_gui.h"
#include "ogl/ogl_api.h"
#include "gui/gui_common.h"
@ -50,7 +57,7 @@ oxr_sdl2_hack_stop(void **hack)
#include <SDL2/SDL.h>
DEBUG_GET_ONCE_BOOL_OPTION(gui, "OXR_DEBUG_GUI", false)
DEBUG_GET_ONCE_BOOL_OPTION(gui, "XRT_DEBUG_GUI", false)
#ifdef XRT_BUILD_DRIVER_QWERTY
DEBUG_GET_ONCE_BOOL_OPTION(qwerty_enable, "QWERTY_ENABLE", false)
#endif
@ -60,7 +67,7 @@ DEBUG_GET_ONCE_BOOL_OPTION(qwerty_enable, "QWERTY_ENABLE", false)
* Common struct holding state for the GUI interface.
* @extends gui_program
*/
struct sdl2_program
struct u_debug_gui
{
struct gui_program base;
@ -81,7 +88,7 @@ struct gui_imgui
};
static void
sdl2_window_init(struct sdl2_program *p)
sdl2_window_init(struct u_debug_gui *p)
{
const char *title = "Monado! ✨⚡🔥";
int x = SDL_WINDOWPOS_UNDEFINED;
@ -137,7 +144,7 @@ sdl2_window_init(struct sdl2_program *p)
}
static void
sdl2_loop(struct sdl2_program *p)
sdl2_loop(struct u_debug_gui *p)
{
// Need to call this before any other Imgui call.
igCreateContext(NULL);
@ -251,7 +258,7 @@ sdl2_loop(struct sdl2_program *p)
}
static void
sdl2_close(struct sdl2_program *p)
sdl2_close(struct u_debug_gui *p)
{
// All scenes should be destroyed by now.
gui_scene_manager_destroy(&p->base);
@ -276,21 +283,20 @@ sdl2_close(struct sdl2_program *p)
}
static void *
oxr_sdl2_hack_run_thread(void *ptr)
u_debug_gui_run_thread(void *ptr)
{
struct sdl2_program *p = (struct sdl2_program *)ptr;
struct u_debug_gui *debug_gui = (struct u_debug_gui *)ptr;
sdl2_window_init(debug_gui);
sdl2_window_init(p);
sdl2_loop(debug_gui);
sdl2_loop(p);
sdl2_close(p);
sdl2_close(debug_gui);
return NULL;
}
int
oxr_sdl2_hack_create(void **out_hack)
u_debug_gui_create(struct u_debug_gui **out_debug_gui)
{
// Enabled?
if (!debug_get_bool_option_gui()) {
@ -300,53 +306,52 @@ oxr_sdl2_hack_create(void **out_hack)
// Need to do this as early as possible.
u_var_force_on();
struct sdl2_program *p = U_TYPED_CALLOC(struct sdl2_program);
struct u_debug_gui *p = U_TYPED_CALLOC(struct u_debug_gui);
if (p == NULL) {
return -1;
}
os_thread_helper_init(&p->oth);
*out_hack = p;
*out_debug_gui = p;
return 0;
}
void
oxr_sdl2_hack_start(void *hack, struct xrt_instance *xinst, struct xrt_system_devices *xsysd)
u_debug_gui_start(struct u_debug_gui *debug_gui, struct xrt_instance *xinst, struct xrt_system_devices *xsysd)
{
struct sdl2_program *p = (struct sdl2_program *)hack;
if (p == NULL) {
if (debug_gui == NULL) {
return;
}
// Share the system devices.
p->base.xsysd = xsysd;
debug_gui->base.xsysd = xsysd;
if (SDL_Init(SDL_INIT_EVERYTHING) < 0) {
U_LOG_E("Failed to init SDL2!");
return;
}
p->sdl_initialized = true;
debug_gui->sdl_initialized = true;
(void)os_thread_helper_start(&p->oth, oxr_sdl2_hack_run_thread, p);
(void)os_thread_helper_start(&debug_gui->oth, u_debug_gui_run_thread, (void *)debug_gui);
}
void
oxr_sdl2_hack_stop(void **hack_ptr)
u_debug_gui_stop(struct u_debug_gui **debug_gui)
{
struct sdl2_program *p = *(struct sdl2_program **)hack_ptr;
struct u_debug_gui *p = *(struct u_debug_gui **)debug_gui;
if (p == NULL) {
return;
}
// HACK!
p->base.stopped = true;
// Destroy the thread object.
os_thread_helper_destroy(&p->oth);
free(p);
*hack_ptr = NULL;
*debug_gui = NULL;
}
#endif
#endif /* XRT_FEATURE_DEBUG_GUI */

View file

@ -0,0 +1,36 @@
// Copyright 2019-2023, Collabora, Ltd.
// SPDX-License-Identifier: BSL-1.0
/*!
* @file
* @brief SDL2 Debug UI implementation
* @author Jakob Bornecrantz <jakob@collabora.com>
* @author Moses Turner <moses@collabora.com>
*/
#pragma once
#include "xrt/xrt_compiler.h"
#ifdef __cplusplus
extern "C" {
#endif
struct xrt_instance;
struct xrt_system_devices;
struct u_debug_gui;
int
u_debug_gui_create(struct u_debug_gui **out_debug_gui);
void
u_debug_gui_start(struct u_debug_gui *debug_gui, struct xrt_instance *xinst, struct xrt_system_devices *xsysd);
void
u_debug_gui_stop(struct u_debug_gui **debug_gui);
#ifdef __cplusplus
}
#endif

View file

@ -21,6 +21,7 @@
/* keep sorted */
#cmakedefine XRT_FEATURE_COLOR_LOG
#cmakedefine XRT_FEATURE_DEBUG_GUI
#cmakedefine XRT_FEATURE_OPENXR
#cmakedefine XRT_FEATURE_OPENXR_DEBUG_UTILS
#cmakedefine XRT_FEATURE_OPENXR_LAYER_CUBE

View file

@ -92,7 +92,7 @@ target_include_directories(
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}
)
target_link_libraries(ipc_server PRIVATE aux_util aux_util_process ipc_shared)
target_link_libraries(ipc_server PRIVATE aux_util aux_util_process aux_util_debug_gui ipc_shared)
if(XRT_HAVE_SYSTEMD)
target_include_directories(ipc_server PRIVATE ${SYSTEMD_INCLUDE_DIRS})

View file

@ -295,9 +295,7 @@ struct ipc_server
//! Handle for the current process, e.g. pidfile on linux
struct u_process *process;
/* ---- HACK ---- */
void *hack;
/* ---- HACK ---- */
struct u_debug_gui *debug_gui;
//! System devices.
struct xrt_system_devices *xsysd;

View file

@ -23,6 +23,7 @@
#include "util/u_trace_marker.h"
#include "util/u_verify.h"
#include "util/u_process.h"
#include "util/u_debug_gui.h"
#include "util/u_git_tag.h"
@ -40,18 +41,6 @@
#include <string.h>
#include <assert.h>
/* ---- HACK ---- */
extern int
oxr_sdl2_hack_create(void **out_hack);
extern void
oxr_sdl2_hack_start(void *hack, struct xrt_instance *xinst, struct xrt_system_devices *xsysd);
extern void
oxr_sdl2_hack_stop(void **hack_ptr);
/* ---- HACK ---- */
/*
*
* Defines and helpers.
@ -789,29 +778,23 @@ ipc_server_main(int argc, char **argv)
U_LOG_I("Monado Service %s starting up...", u_git_tag);
/* ---- HACK ---- */
// need to create early before any vars are added
oxr_sdl2_hack_create(&s->hack);
/* ---- HACK ---- */
u_debug_gui_create(&s->debug_gui);
int ret = init_all(s);
if (ret < 0) {
free(s->hack);
free(s->debug_gui);
free(s);
return ret;
}
init_server_state(s);
/* ---- HACK ---- */
oxr_sdl2_hack_start(s->hack, s->xinst, s->xsysd);
/* ---- HACK ---- */
u_debug_gui_start(s->debug_gui, s->xinst, s->xsysd);
ret = main_loop(s);
/* ---- HACK ---- */
oxr_sdl2_hack_stop(&s->hack);
/* ---- HACK ---- */
u_debug_gui_stop(&s->debug_gui);
teardown_all(s);
free(s);

View file

@ -19,6 +19,10 @@
#include "util/u_git_tag.h"
#include "util/u_builders.h"
#ifdef XRT_FEATURE_CLIENT_DEBUG_GUI
#include "util/u_debug_gui.h"
#endif
#ifdef XRT_OS_ANDROID
#include "android/android_globals.h"
#include "android/android_looper.h"
@ -49,19 +53,6 @@ DEBUG_GET_ONCE_FLOAT_OPTION(tracking_origin_offset_x, "OXR_TRACKING_ORIGIN_OFFSE
DEBUG_GET_ONCE_FLOAT_OPTION(tracking_origin_offset_y, "OXR_TRACKING_ORIGIN_OFFSET_Y", 0.0f)
DEBUG_GET_ONCE_FLOAT_OPTION(tracking_origin_offset_z, "OXR_TRACKING_ORIGIN_OFFSET_Z", 0.0f)
#ifdef XRT_FEATURE_CLIENT_DEBUG_GUI
/* ---- HACK ---- */
extern int
oxr_sdl2_hack_create(void **out_hack);
extern void
oxr_sdl2_hack_start(void *hack, struct xrt_instance *xinst, struct xrt_system_devices *xsysd);
extern void
oxr_sdl2_hack_stop(void **hack_ptr);
/* ---- HACK ---- */
#endif
static XrResult
oxr_instance_destroy(struct oxr_logger *log, struct oxr_handle_base *hb)
{
@ -82,9 +73,7 @@ oxr_instance_destroy(struct oxr_logger *log, struct oxr_handle_base *hb)
xrt_system_devices_destroy(&inst->system.xsysd);
#ifdef XRT_FEATURE_CLIENT_DEBUG_GUI
/* ---- HACK ---- */
oxr_sdl2_hack_stop(&inst->hack);
/* ---- HACK ---- */
u_debug_gui_stop(&inst->debug_ui);
#endif
xrt_instance_destroy(&inst->xinst);
@ -204,9 +193,7 @@ oxr_instance_create(struct oxr_logger *log,
}
#ifdef XRT_FEATURE_CLIENT_DEBUG_GUI
/* ---- HACK ---- */
oxr_sdl2_hack_create(&inst->hack);
/* ---- HACK ---- */
u_debug_gui_create(&inst->debug_ui);
#endif
ret = oxr_path_init(log, inst);
@ -343,9 +330,7 @@ oxr_instance_create(struct oxr_logger *log,
u_var_add_root((void *)inst, "XrInstance", true);
#ifdef XRT_FEATURE_CLIENT_DEBUG_GUI
/* ---- HACK ---- */
oxr_sdl2_hack_start(inst->hack, inst->xinst, sys->xsysd);
/* ---- HACK ---- */
u_debug_gui_start(inst->debug_ui, inst->xinst, sys->xsysd);
#endif
oxr_log(log,

View file

@ -1360,9 +1360,7 @@ struct oxr_instance
//! Common structure for things referred to by OpenXR handles.
struct oxr_handle_base handle;
/* ---- HACK ---- */
void *hack;
/* ---- HACK ---- */
struct u_debug_gui *debug_ui;
struct xrt_instance *xinst;

View file

@ -130,21 +130,7 @@ elseif(NOT ANDROID)
)
endif()
###
# Inelegant but effective SDL2-based debug GUI
add_library(oxr_sdl2 STATIC oxr_sdl2_hack.c)
target_link_libraries(oxr_sdl2 PRIVATE aux_util)
if(XRT_HAVE_OPENGL)
target_link_libraries(oxr_sdl2 PUBLIC aux_ogl)
endif()
if(XRT_HAVE_SDL2)
target_link_libraries(oxr_sdl2 PRIVATE st_gui xrt-external-imgui-sdl2 ${SDL2_LIBRARIES})
if(XRT_BUILD_DRIVER_QWERTY)
target_link_libraries(oxr_sdl2 PRIVATE drv_qwerty drv_qwerty_includes)
endif()
endif()
# Optional debug ui
if(XRT_FEATURE_CLIENT_DEBUG_GUI)
target_link_libraries(${RUNTIME_TARGET} PRIVATE oxr_sdl2)
target_link_libraries(${RUNTIME_TARGET} PRIVATE aux_util_debug_gui)
endif()

View file

@ -13,19 +13,19 @@ struct xrt_system_devices;
int
oxr_sdl2_hack_create(void **out_hack)
u_debug_gui_create(void **out_hack)
{
return 0;
}
void
oxr_sdl2_hack_start(void *hack, struct xrt_instance *xinst, struct xrt_system_devices *xsysd)
u_debug_gui_start(void *hack, struct xrt_instance *xinst, struct xrt_system_devices *xsysd)
{
// Noop
}
void
oxr_sdl2_hack_stop(void **hack)
u_debug_gui_stop(void **hack)
{
// Noop
}

View file

@ -8,11 +8,11 @@ target_link_libraries(
monado-service
PRIVATE
aux_util
aux_util_debug_gui
st_prober
ipc_server
target_lists
target_instance
oxr_sdl2
)
install(TARGETS monado-service RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})