mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2024-12-29 11:06:18 +00:00
st/oxr: Add oxr_chain.h header
This should replace all manual poking of the next chain. Prefer the macros over the functions since they'll do your casting for you.
This commit is contained in:
parent
e944bcb96f
commit
fa8047fed3
|
@ -18,6 +18,7 @@ set(OXR_SOURCE_FILES
|
|||
oxr_api_swapchain.c
|
||||
oxr_api_system.c
|
||||
oxr_api_verify.h
|
||||
oxr_chain.h
|
||||
oxr_event.cpp
|
||||
oxr_handle_base.c
|
||||
oxr_instance.c
|
||||
|
|
94
src/xrt/state_trackers/oxr/oxr_chain.h
Normal file
94
src/xrt/state_trackers/oxr/oxr_chain.h
Normal file
|
@ -0,0 +1,94 @@
|
|||
// Copyright 2019, Collabora, Ltd.
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
/*!
|
||||
* @file
|
||||
* @brief Utilities for accessing members in an OpenXR structure chain.
|
||||
* @author Ryan Pavlik <ryan.pavlik@collabora.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <xrt/xrt_openxr_includes.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @ingroup oxr_api
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*!
|
||||
* Finds an input struct of the given type in a next-chain.
|
||||
*
|
||||
* Returns NULL if nothing matching is found.
|
||||
*
|
||||
* Prefer using OXR_GET_INPUT_FROM_CHAIN() instead, since it includes the
|
||||
* casting.
|
||||
*/
|
||||
static inline XrBaseInStructure const*
|
||||
oxr_find_input_in_chain(const void* ptr, XrStructureType desired)
|
||||
{
|
||||
while (ptr != NULL) {
|
||||
XrBaseInStructure const* base = (XrBaseInStructure const*)ptr;
|
||||
if (base->type == desired) {
|
||||
return base;
|
||||
}
|
||||
ptr = base->next;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Finds an input struct of the given type in a next-chain and casts it as
|
||||
* desired.
|
||||
*
|
||||
* Returns NULL if nothing matching is found.
|
||||
*
|
||||
* Note: There is no protection here to ensure that STRUCTURE_TYPE_ENUM (an
|
||||
* XrStructureType value) and TYPE (a type name) actually match!
|
||||
*/
|
||||
#define OXR_GET_INPUT_FROM_CHAIN(PTR, STRUCTURE_TYPE_ENUM, TYPE) \
|
||||
((TYPE const*)oxr_find_input_in_chain(PTR, STRUCTURE_TYPE_ENUM))
|
||||
|
||||
/*!
|
||||
* Finds an output struct of the given type in a next-chain.
|
||||
*
|
||||
* Returns NULL if nothing matching is found.
|
||||
*
|
||||
* Prefer using OXR_GET_OUTPUT_FROM_CHAIN() instead, since it includes the
|
||||
* casting.
|
||||
*/
|
||||
static inline XrBaseOutStructure*
|
||||
oxr_find_output_in_chain(void* ptr, XrStructureType desired)
|
||||
{
|
||||
while (ptr != NULL) {
|
||||
XrBaseOutStructure* base = (XrBaseOutStructure*)ptr;
|
||||
if (base->type == desired) {
|
||||
return base;
|
||||
}
|
||||
ptr = base->next;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Finds an output struct of the given type in a next-chain and casts it as
|
||||
* desired.
|
||||
*
|
||||
* Returns NULL if nothing matching is found.
|
||||
*
|
||||
* Note: There is no protection here to ensure that STRUCTURE_TYPE_ENUM (an
|
||||
* XrStructureType value) and TYPE (a type name) actually match!
|
||||
*/
|
||||
#define OXR_GET_OUTPUT_FROM_CHAIN(PTR, STRUCTURE_TYPE_ENUM, TYPE) \
|
||||
((TYPE*)oxr_find_output_in_chain(PTR, STRUCTURE_TYPE_ENUM))
|
||||
|
||||
/*!
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
Loading…
Reference in a new issue