diff --git a/src/xrt/state_trackers/oxr/CMakeLists.txt b/src/xrt/state_trackers/oxr/CMakeLists.txt index 115f6bc4f..e83994a48 100644 --- a/src/xrt/state_trackers/oxr/CMakeLists.txt +++ b/src/xrt/state_trackers/oxr/CMakeLists.txt @@ -18,6 +18,7 @@ add_library( oxr_api_verify.h oxr_binding.c oxr_chain.h + oxr_dpad.c oxr_event.c oxr_extension_support.h oxr_handle_base.c diff --git a/src/xrt/state_trackers/oxr/oxr_dpad.c b/src/xrt/state_trackers/oxr/oxr_dpad.c new file mode 100644 index 000000000..cdc0b7361 --- /dev/null +++ b/src/xrt/state_trackers/oxr/oxr_dpad.c @@ -0,0 +1,70 @@ +// Copyright 2022, Collabora, Ltd. +// SPDX-License-Identifier: BSL-1.0 +/*! + * @file + * @brief Holds binding related functions. + * @author Jakob Bornecrantz + * @ingroup oxr_main + */ + +#include "oxr_objects.h" + + +/* + * + * Helper functions. + * + */ + +static void +destroy_callback(void *item, void *priv) +{ + free(item); +} + + +/* + * + * 'Exported' functions. + * + */ + +bool +oxr_dpad_state_init(struct oxr_dpad_state *state) +{ + if (u_hashmap_int_create(&state->uhi) < 0) { + return false; + } + + return true; +} + +struct oxr_dpad_entry * +oxr_dpad_state_get(struct oxr_dpad_state *state, uint64_t key) +{ + void *ptr = NULL; + u_hashmap_int_find(state->uhi, key, &ptr); + return (struct oxr_dpad_entry *)ptr; +} + +struct oxr_dpad_entry * +oxr_dpad_state_get_or_add(struct oxr_dpad_state *state, uint64_t key) +{ + struct oxr_dpad_entry *e = oxr_dpad_state_get(state, key); + if (e == NULL) { + e = U_TYPED_CALLOC(struct oxr_dpad_entry); + int ret = u_hashmap_int_insert(state->uhi, key, (void *)e); + assert(ret >= 0); + } + + return e; +} + +void +oxr_dpad_state_deinit(struct oxr_dpad_state *state) +{ + if (state->uhi != NULL) { + u_hashmap_int_clear_and_call_for_each(state->uhi, destroy_callback, NULL); + u_hashmap_int_destroy(&state->uhi); + } +} diff --git a/src/xrt/state_trackers/oxr/oxr_objects.h b/src/xrt/state_trackers/oxr/oxr_objects.h index 7a86571ff..3471b010f 100644 --- a/src/xrt/state_trackers/oxr/oxr_objects.h +++ b/src/xrt/state_trackers/oxr/oxr_objects.h @@ -125,6 +125,7 @@ struct oxr_action_attachment; struct oxr_action_set_attachment; struct oxr_action_input; struct oxr_action_output; +struct oxr_dpad_state; struct oxr_binding; struct oxr_interaction_profile; struct oxr_action_set_ref; @@ -636,6 +637,54 @@ oxr_action_get_input_source_localized_name(struct oxr_logger *log, * @} */ + +/*! + * + * @name oxr_dpad.c + * @{ + * + */ + +/*! + * Initialises a dpad state, has to be zero init before a call to this function. + * + * @public @memberof oxr_dpad_state_get + */ +bool +oxr_dpad_state_init(struct oxr_dpad_state *state); + +/*! + * Look for a entry in the state for the given action set key, + * returns NULL if no entry has been made for that action set. + * + * @public @memberof oxr_dpad_state_get + */ +struct oxr_dpad_entry * +oxr_dpad_state_get(struct oxr_dpad_state *state, uint64_t key); + +/*! + * Look for a entry in the state for the given action set key, + * allocates a new entry if none was found. + * + * @public @memberof oxr_dpad_state_get + */ +struct oxr_dpad_entry * +oxr_dpad_state_get_or_add(struct oxr_dpad_state *state, uint64_t key); + +/*! + * Frees all state and entries attached to this dpad state. + * + * @public @memberof oxr_dpad_state_get + */ +void +oxr_dpad_state_deinit(struct oxr_dpad_state *state); + + +/*! + * @} + */ + + /*! * * @name oxr_session.c @@ -1802,6 +1851,31 @@ struct oxr_action_attachment #undef OXR_CACHE_MEMBER }; +/*! + * A entry in the dpad state for one action set. + * + * @ingroup oxr_input + */ +struct oxr_dpad_entry +{ +#ifdef XR_EXT_dpad_binding + XrInteractionProfileDpadBindingEXT dpads[4]; + uint32_t dpad_count; +#endif + + uint64_t key; +}; + +/*! + * Holds dpad binding state for a single interaction profile. + * + * @ingroup oxr_input + */ +struct oxr_dpad_state +{ + struct u_hashmap_int *uhi; +}; + /*! * @} */