From 937f5d582a74fb08f37a8da6bde9917bd609b0c0 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Tue, 22 Oct 2019 11:47:25 +0100 Subject: [PATCH] st/oxr: Refactor logging options to instance --- src/xrt/state_trackers/oxr/oxr_handle_base.c | 4 +--- src/xrt/state_trackers/oxr/oxr_input.c | 6 +++++- src/xrt/state_trackers/oxr/oxr_instance.c | 11 ++++++++++ src/xrt/state_trackers/oxr/oxr_objects.h | 5 +++++ src/xrt/state_trackers/oxr/oxr_session.c | 21 +++++++++++--------- src/xrt/state_trackers/oxr/oxr_space.c | 15 +++++++------- 6 files changed, 41 insertions(+), 21 deletions(-) diff --git a/src/xrt/state_trackers/oxr/oxr_handle_base.c b/src/xrt/state_trackers/oxr/oxr_handle_base.c index 279043d21..f7a216de8 100644 --- a/src/xrt/state_trackers/oxr/oxr_handle_base.c +++ b/src/xrt/state_trackers/oxr/oxr_handle_base.c @@ -17,10 +17,8 @@ #include -DEBUG_GET_ONCE_BOOL_OPTION(lifecycle_verbose, "OXR_LIFECYCLE_VERBOSE", false) - #define HANDLE_LIFECYCLE_LOG(log, ...) \ - if (debug_get_bool_option_lifecycle_verbose()) { \ + if (log->inst != NULL && log->inst->lifecycle_verbose) { \ oxr_log(log, " Handle Lifecycle: " __VA_ARGS__); \ } diff --git a/src/xrt/state_trackers/oxr/oxr_input.c b/src/xrt/state_trackers/oxr/oxr_input.c index c4169f48a..9c2b85b98 100644 --- a/src/xrt/state_trackers/oxr/oxr_input.c +++ b/src/xrt/state_trackers/oxr/oxr_input.c @@ -535,7 +535,11 @@ oxr_source_create(struct oxr_logger *log, oxr_slog(&slog, "\tDone"); // Also frees all data. - oxr_log_slog(log, &slog); + if (sess->sys->inst->debug_bindings) { + oxr_log_slog(log, &slog); + } else { + oxr_slog_abort(&slog); + } return XR_SUCCESS; } diff --git a/src/xrt/state_trackers/oxr/oxr_instance.c b/src/xrt/state_trackers/oxr/oxr_instance.c index deae6a157..77b551ad9 100644 --- a/src/xrt/state_trackers/oxr/oxr_instance.c +++ b/src/xrt/state_trackers/oxr/oxr_instance.c @@ -25,6 +25,12 @@ #include "oxr_handle.h" #include "oxr_extension_support.h" + +DEBUG_GET_ONCE_BOOL_OPTION(debug_views, "OXR_DEBUG_VIEWS", false) +DEBUG_GET_ONCE_BOOL_OPTION(debug_spaces, "OXR_DEBUG_SPACES", false) +DEBUG_GET_ONCE_BOOL_OPTION(debug_bindings, "OXR_DEBUG_BINDINGS", false) +DEBUG_GET_ONCE_BOOL_OPTION(lifecycle_verbose, "OXR_LIFECYCLE_VERBOSE", false) + DEBUG_GET_ONCE_FLOAT_OPTION(lfov_left, "OXR_OVERRIDE_LFOV_LEFT", 0.0f) DEBUG_GET_ONCE_FLOAT_OPTION(lfov_right, "OXR_OVERRIDE_LFOV_RIGHT", 0.0f) DEBUG_GET_ONCE_FLOAT_OPTION(lfov_up, "OXR_OVERRIDE_LFOV_UP", 0.0f) @@ -102,6 +108,11 @@ oxr_instance_create(struct oxr_logger *log, OXR_ALLOCATE_HANDLE_OR_RETURN(log, inst, OXR_XR_DEBUG_INSTANCE, oxr_instance_destroy, NULL); + inst->lifecycle_verbose = debug_get_bool_option_lifecycle_verbose(); + inst->debug_spaces = debug_get_bool_option_debug_spaces(); + inst->debug_views = debug_get_bool_option_debug_views(); + inst->debug_bindings = debug_get_bool_option_debug_bindings(); + /* ---- HACK ---- */ oxr_sdl2_hack_create(&inst->hack); /* ---- HACK ---- */ diff --git a/src/xrt/state_trackers/oxr/oxr_objects.h b/src/xrt/state_trackers/oxr/oxr_objects.h index 301b55fb4..1f3412311 100644 --- a/src/xrt/state_trackers/oxr/oxr_objects.h +++ b/src/xrt/state_trackers/oxr/oxr_objects.h @@ -907,6 +907,11 @@ struct oxr_instance //! Debug messengers struct oxr_debug_messenger *messengers[XRT_MAX_HANDLE_CHILDREN]; + + bool lifecycle_verbose; + bool debug_views; + bool debug_spaces; + bool debug_bindings; }; /*! diff --git a/src/xrt/state_trackers/oxr/oxr_session.c b/src/xrt/state_trackers/oxr/oxr_session.c index 40465f774..18d6ca56b 100644 --- a/src/xrt/state_trackers/oxr/oxr_session.c +++ b/src/xrt/state_trackers/oxr/oxr_session.c @@ -28,7 +28,6 @@ #include "oxr_chain.h" -DEBUG_GET_ONCE_BOOL_OPTION(views, "OXR_DEBUG_VIEWS", false) DEBUG_GET_ONCE_BOOL_OPTION(dynamic_prediction, "OXR_DYNAMIC_PREDICTION", true) DEBUG_GET_ONCE_NUM_OPTION(ipd, "OXR_DEBUG_IPD_MM", 63) DEBUG_GET_ONCE_NUM_OPTION(prediction_ms, "OXR_DEBUG_PREDICTION_MS", 11) @@ -220,7 +219,7 @@ oxr_session_get_view_pose_at(struct oxr_logger *log, &relation.angular_velocity, interval, &predicted); - if (debug_get_bool_option_views()) { + if (sess->sys->inst->debug_views) { fprintf(stderr, "\toriginal quat = {%f, %f, %f, %f} " "(time requested: %li, Interval %li nsec, with " @@ -237,9 +236,11 @@ oxr_session_get_view_pose_at(struct oxr_logger *log, } void -print_view_fov(uint32_t index, const struct xrt_fov *fov) +print_view_fov(struct oxr_session *sess, + uint32_t index, + const struct xrt_fov *fov) { - if (!debug_get_bool_option_views()) { + if (!sess->sys->inst->debug_views) { return; } @@ -249,9 +250,11 @@ print_view_fov(uint32_t index, const struct xrt_fov *fov) } void -print_view_pose(uint32_t index, const struct xrt_pose *pose) +print_view_pose(struct oxr_session *sess, + uint32_t index, + const struct xrt_pose *pose) { - if (!debug_get_bool_option_views()) { + if (!sess->sys->inst->debug_views) { return; } @@ -295,7 +298,7 @@ oxr_session_views(struct oxr_logger *log, } // End two call handling. - if (debug_get_bool_option_views()) { + if (sess->sys->inst->debug_views) { fprintf(stderr, "%s\n", __func__); fprintf(stderr, "\tviewLocateInfo->displayTime %lu\n", viewLocateInfo->displayTime); @@ -337,8 +340,8 @@ oxr_session_views(struct oxr_logger *log, safe_copy.xrt = xdev->hmd->views[i].fov; views[i].fov = safe_copy.oxr; - print_view_fov(i, (struct xrt_fov *)&views[i].fov); - print_view_pose(i, (struct xrt_pose *)&views[i].pose); + print_view_fov(sess, i, (struct xrt_fov *)&views[i].fov); + print_view_pose(sess, i, (struct xrt_pose *)&views[i].pose); } // @todo Add tracking bit once we have them. diff --git a/src/xrt/state_trackers/oxr/oxr_space.c b/src/xrt/state_trackers/oxr/oxr_space.c index ab7b25f32..2cc0f2f01 100644 --- a/src/xrt/state_trackers/oxr/oxr_space.c +++ b/src/xrt/state_trackers/oxr/oxr_space.c @@ -21,8 +21,6 @@ #include "oxr_handle.h" -DEBUG_GET_ONCE_BOOL_OPTION(space, "OXR_DEBUG_SPACE", false) - const struct xrt_pose origin = {{0.0f, 0.0f, 0.0f, 1.0f}, {0.0f, 0.0f, 0.0f}}; static XrResult @@ -303,9 +301,9 @@ get_pure_space_relation(struct oxr_logger *log, } static void -print_pose(const char *prefix, struct xrt_pose *pose) +print_pose(struct oxr_session *sess, const char *prefix, struct xrt_pose *pose) { - if (!debug_get_bool_option_space()) { + if (!sess->sys->inst->debug_spaces) { return; } @@ -319,13 +317,13 @@ print_pose(const char *prefix, struct xrt_pose *pose) static void print_space(const char *name, struct oxr_space *spc) { - if (!debug_get_bool_option_space()) { + if (!spc->sess->sys->inst->debug_spaces) { return; } const char *type_str = get_ref_space_type_short_str(spc); fprintf(stderr, "\t%s->type %s\n\t%s->pose", name, type_str, name); - print_pose("", &spc->pose); + print_pose(spc->sess, "", &spc->pose); } XrResult @@ -335,7 +333,7 @@ oxr_space_locate(struct oxr_logger *log, XrTime time, XrSpaceLocation *location) { - if (debug_get_bool_option_space()) { + if (spc->sess->sys->inst->debug_spaces) { fprintf(stderr, "%s\n", __func__); } print_space("space", spc); @@ -374,7 +372,8 @@ oxr_space_locate(struct oxr_logger *log, *(XrVector3f *)&result.angular_acceleration; #endif - print_pose("\trelation->pose", (struct xrt_pose *)&location->pose); + print_pose(spc->sess, "\trelation->pose", + (struct xrt_pose *)&location->pose); return oxr_session_success_result(spc->sess); }