mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2024-12-29 11:06:18 +00:00
st/oxr: Add dpad state and functions
This commit is contained in:
parent
9b27fb1a2e
commit
fb0f94c900
|
@ -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
|
||||
|
|
70
src/xrt/state_trackers/oxr/oxr_dpad.c
Normal file
70
src/xrt/state_trackers/oxr/oxr_dpad.c
Normal file
|
@ -0,0 +1,70 @@
|
|||
// Copyright 2022, Collabora, Ltd.
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
/*!
|
||||
* @file
|
||||
* @brief Holds binding related functions.
|
||||
* @author Jakob Bornecrantz <jakob@collabora.com>
|
||||
* @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);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
};
|
||||
|
||||
/*!
|
||||
* @}
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue