st/oxr: oxr_space type is now an enum

v2: Get rid of ref_space_type
This commit is contained in:
Christoph Haag 2022-03-23 19:20:15 +01:00 committed by Jakob Bornecrantz
parent 543fbc38e2
commit 18376007f9
3 changed files with 103 additions and 46 deletions

View file

@ -1738,6 +1738,64 @@ struct oxr_action_attachment
* @} * @}
*/ */
enum oxr_space_type
{
OXR_SPACE_TYPE_REFERENCE_VIEW = 1,
OXR_SPACE_TYPE_REFERENCE_LOCAL = 2,
OXR_SPACE_TYPE_REFERENCE_STAGE = 3,
OXR_SPACE_TYPE_REFERENCE_UNBOUNDED_MSFT,
OXR_SPACE_TYPE_REFERENCE_COMBINED_EYE_VARJO,
OXR_SPACE_TYPE_ACTION,
};
static inline bool
oxr_space_type_is_reference(enum oxr_space_type space_type)
{
switch (space_type) {
case OXR_SPACE_TYPE_REFERENCE_VIEW:
case OXR_SPACE_TYPE_REFERENCE_LOCAL:
case OXR_SPACE_TYPE_REFERENCE_STAGE:
case OXR_SPACE_TYPE_REFERENCE_UNBOUNDED_MSFT:
case OXR_SPACE_TYPE_REFERENCE_COMBINED_EYE_VARJO: return true;
case OXR_SPACE_TYPE_ACTION: return false;
}
return false;
}
static inline XrReferenceSpaceType
oxr_ref_space_to_xr(enum oxr_space_type space_type)
{
switch (space_type) {
case OXR_SPACE_TYPE_REFERENCE_VIEW: return XR_REFERENCE_SPACE_TYPE_VIEW;
case OXR_SPACE_TYPE_REFERENCE_LOCAL: return XR_REFERENCE_SPACE_TYPE_LOCAL;
case OXR_SPACE_TYPE_REFERENCE_STAGE: return XR_REFERENCE_SPACE_TYPE_STAGE;
case OXR_SPACE_TYPE_REFERENCE_UNBOUNDED_MSFT: return XR_REFERENCE_SPACE_TYPE_UNBOUNDED_MSFT;
case OXR_SPACE_TYPE_REFERENCE_COMBINED_EYE_VARJO: return XR_REFERENCE_SPACE_TYPE_COMBINED_EYE_VARJO;
case OXR_SPACE_TYPE_ACTION: return XR_REFERENCE_SPACE_TYPE_MAX_ENUM;
}
return XR_REFERENCE_SPACE_TYPE_MAX_ENUM;
}
static inline enum oxr_space_type
xr_ref_space_to_oxr(XrReferenceSpaceType space_type)
{
switch (space_type) {
case XR_REFERENCE_SPACE_TYPE_VIEW: return OXR_SPACE_TYPE_REFERENCE_VIEW;
case XR_REFERENCE_SPACE_TYPE_LOCAL: return OXR_SPACE_TYPE_REFERENCE_LOCAL;
case XR_REFERENCE_SPACE_TYPE_STAGE: return OXR_SPACE_TYPE_REFERENCE_STAGE;
case XR_REFERENCE_SPACE_TYPE_UNBOUNDED_MSFT: return OXR_SPACE_TYPE_REFERENCE_UNBOUNDED_MSFT;
case XR_REFERENCE_SPACE_TYPE_COMBINED_EYE_VARJO: return OXR_SPACE_TYPE_REFERENCE_COMBINED_EYE_VARJO;
case XR_REFERENCE_SPACE_TYPE_MAX_ENUM: return (enum oxr_space_type) - 1;
}
// wrap around or negative depending on enum data type, invalid value either way.
return (enum oxr_space_type) - 1;
}
/*! /*!
* Can be one of several reference space types, or a space that is bound to an * Can be one of several reference space types, or a space that is bound to an
* action. * action.
@ -1758,14 +1816,11 @@ struct oxr_space
//! Pose that was given during creation. //! Pose that was given during creation.
struct xrt_pose pose; struct xrt_pose pose;
//! What kind of reference space is this, if any.
XrReferenceSpaceType type;
//! Action key from which action this space was created from. //! Action key from which action this space was created from.
uint32_t act_key; uint32_t act_key;
//! Is this a reference space? //! What kind of space is this?
bool is_reference; enum oxr_space_type space_type;
//! Which sub action path is this? //! Which sub action path is this?
struct oxr_subaction_paths subaction_paths; struct oxr_subaction_paths subaction_paths;

View file

@ -807,7 +807,7 @@ handle_space(struct oxr_logger *log,
/* /*
* poses in view space are already in the space the compositor expects * poses in view space are already in the space the compositor expects
*/ */
if (spc->is_reference && spc->type == XR_REFERENCE_SPACE_TYPE_VIEW) { if (spc->space_type == OXR_SPACE_TYPE_REFERENCE_VIEW) {
struct xrt_space_relation rel; struct xrt_space_relation rel;
struct xrt_relation_chain xrc = {0}; struct xrt_relation_chain xrc = {0};
m_relation_chain_push_pose(&xrc, &pose); m_relation_chain_push_pose(&xrc, &pose);
@ -857,7 +857,7 @@ submit_quad_layer(struct oxr_session *sess,
return XR_SUCCESS; return XR_SUCCESS;
} }
if (spc->is_reference && spc->type == XR_REFERENCE_SPACE_TYPE_VIEW) { if (spc->space_type == OXR_SPACE_TYPE_REFERENCE_VIEW) {
flags |= XRT_LAYER_COMPOSITION_VIEW_SPACE_BIT; flags |= XRT_LAYER_COMPOSITION_VIEW_SPACE_BIT;
} }
@ -908,7 +908,7 @@ submit_projection_layer(struct oxr_session *sess,
} }
} }
if (spc->is_reference && spc->type == XR_REFERENCE_SPACE_TYPE_VIEW) { if (spc->space_type == OXR_SPACE_TYPE_REFERENCE_VIEW) {
flags |= XRT_LAYER_COMPOSITION_VIEW_SPACE_BIT; flags |= XRT_LAYER_COMPOSITION_VIEW_SPACE_BIT;
} }
@ -1021,7 +1021,7 @@ submit_cylinder_layer(struct oxr_session *sess,
return XR_SUCCESS; return XR_SUCCESS;
} }
if (spc->is_reference && spc->type == XR_REFERENCE_SPACE_TYPE_VIEW) { if (spc->space_type == OXR_SPACE_TYPE_REFERENCE_VIEW) {
flags |= XRT_LAYER_COMPOSITION_VIEW_SPACE_BIT; flags |= XRT_LAYER_COMPOSITION_VIEW_SPACE_BIT;
} }
@ -1066,7 +1066,7 @@ submit_equirect1_layer(struct oxr_session *sess,
return XR_SUCCESS; return XR_SUCCESS;
} }
if (spc->is_reference && spc->type == XR_REFERENCE_SPACE_TYPE_VIEW) { if (spc->space_type == OXR_SPACE_TYPE_REFERENCE_VIEW) {
flags |= XRT_LAYER_COMPOSITION_VIEW_SPACE_BIT; flags |= XRT_LAYER_COMPOSITION_VIEW_SPACE_BIT;
} }
@ -1124,7 +1124,7 @@ submit_equirect2_layer(struct oxr_session *sess,
return XR_SUCCESS; return XR_SUCCESS;
} }
if (spc->is_reference && spc->type == XR_REFERENCE_SPACE_TYPE_VIEW) { if (spc->space_type == OXR_SPACE_TYPE_REFERENCE_VIEW) {
flags |= XRT_LAYER_COMPOSITION_VIEW_SPACE_BIT; flags |= XRT_LAYER_COMPOSITION_VIEW_SPACE_BIT;
} }

View file

@ -69,7 +69,7 @@ oxr_space_action_create(struct oxr_logger *log,
oxr_classify_sub_action_paths(log, inst, 1, &createInfo->subactionPath, &subaction_paths); oxr_classify_sub_action_paths(log, inst, 1, &createInfo->subactionPath, &subaction_paths);
spc->sess = sess; spc->sess = sess;
spc->is_reference = false; spc->space_type = OXR_SPACE_TYPE_ACTION;
spc->subaction_paths = subaction_paths; spc->subaction_paths = subaction_paths;
spc->act_key = key; spc->act_key = key;
memcpy(&spc->pose, &createInfo->poseInActionSpace, sizeof(spc->pose)); memcpy(&spc->pose, &createInfo->poseInActionSpace, sizeof(spc->pose));
@ -99,8 +99,7 @@ oxr_space_reference_create(struct oxr_logger *log,
struct oxr_space *spc = NULL; struct oxr_space *spc = NULL;
OXR_ALLOCATE_HANDLE_OR_RETURN(log, spc, OXR_XR_DEBUG_SPACE, oxr_space_destroy, &sess->handle); OXR_ALLOCATE_HANDLE_OR_RETURN(log, spc, OXR_XR_DEBUG_SPACE, oxr_space_destroy, &sess->handle);
spc->sess = sess; spc->sess = sess;
spc->is_reference = true; spc->space_type = xr_ref_space_to_oxr(createInfo->referenceSpaceType);
spc->type = createInfo->referenceSpaceType;
memcpy(&spc->pose, &createInfo->poseInReferenceSpace, sizeof(spc->pose)); memcpy(&spc->pose, &createInfo->poseInReferenceSpace, sizeof(spc->pose));
*out_space = spc; *out_space = spc;
@ -112,15 +111,15 @@ oxr_space_reference_create(struct oxr_logger *log,
static const char * static const char *
get_ref_space_type_short_str(struct oxr_space *spc) get_ref_space_type_short_str(struct oxr_space *spc)
{ {
if (!spc->is_reference) { switch (spc->space_type) {
return "action"; case OXR_SPACE_TYPE_ACTION: return "action";
}
switch (spc->type) { case OXR_SPACE_TYPE_REFERENCE_VIEW: return "view";
case XR_REFERENCE_SPACE_TYPE_VIEW: return "view"; case OXR_SPACE_TYPE_REFERENCE_LOCAL: return "local";
case XR_REFERENCE_SPACE_TYPE_LOCAL: return "local"; case OXR_SPACE_TYPE_REFERENCE_STAGE: return "stage";
case XR_REFERENCE_SPACE_TYPE_STAGE: return "stage"; case OXR_SPACE_TYPE_REFERENCE_UNBOUNDED_MSFT: return "unbounded";
default: return "unknown"; case OXR_SPACE_TYPE_REFERENCE_COMBINED_EYE_VARJO: return "combined_eye";
default: return "unknown_space";
} }
} }
@ -170,13 +169,13 @@ is_local_space_set_up(struct oxr_session *sess)
XRT_CHECK_RESULT static bool XRT_CHECK_RESULT static bool
oxr_space_ref_get_pure_relation(struct oxr_logger *log, oxr_space_ref_get_pure_relation(struct oxr_logger *log,
struct oxr_session *sess, struct oxr_session *sess,
XrReferenceSpaceType ref_type, enum oxr_space_type space_type,
struct xrt_device *ref_xdev, struct xrt_device *ref_xdev,
XrTime time, XrTime time,
struct xrt_space_relation *out_relation) struct xrt_space_relation *out_relation)
{ {
switch (ref_type) { switch (space_type) {
case XR_REFERENCE_SPACE_TYPE_LOCAL: { case OXR_SPACE_TYPE_REFERENCE_LOCAL: {
if (!is_local_space_set_up(sess)) { if (!is_local_space_set_up(sess)) {
if (!set_up_local_space(log, sess, time)) { if (!set_up_local_space(log, sess, time)) {
return false; return false;
@ -186,22 +185,22 @@ oxr_space_ref_get_pure_relation(struct oxr_logger *log,
*out_relation = sess->local_space_pure_relation; *out_relation = sess->local_space_pure_relation;
return true; return true;
} }
case XR_REFERENCE_SPACE_TYPE_STAGE: { case OXR_SPACE_TYPE_REFERENCE_STAGE: {
//! @todo: stage space origin assumed to be the same as HMD xdev space origin for now. //! @todo: stage space origin assumed to be the same as HMD xdev space origin for now.
m_space_relation_ident(out_relation); m_space_relation_ident(out_relation);
return true; return true;
} }
case XR_REFERENCE_SPACE_TYPE_VIEW: { case OXR_SPACE_TYPE_REFERENCE_VIEW: {
oxr_xdev_get_space_relation(log, sess->sys->inst, ref_xdev, XRT_INPUT_GENERIC_HEAD_POSE, time, oxr_xdev_get_space_relation(log, sess->sys->inst, ref_xdev, XRT_INPUT_GENERIC_HEAD_POSE, time,
out_relation); out_relation);
return true; return true;
} }
case XR_REFERENCE_SPACE_TYPE_UNBOUNDED_MSFT: case OXR_SPACE_TYPE_REFERENCE_UNBOUNDED_MSFT:
case XR_REFERENCE_SPACE_TYPE_COMBINED_EYE_VARJO: case OXR_SPACE_TYPE_REFERENCE_COMBINED_EYE_VARJO:
// not implemented // not implemented
return false; return oxr_error(log, false, "Reference Space type %d not implemented!", space_type);
case XR_REFERENCE_SPACE_TYPE_MAX_ENUM: return false; ; case OXR_SPACE_TYPE_ACTION: return oxr_error(log, false, "Space is not a reference space!");
} }
return true; return true;
} }
@ -286,25 +285,28 @@ oxr_space_get_pure_relation(struct oxr_logger *log,
struct xrt_space_relation *out_relation, struct xrt_space_relation *out_relation,
struct xrt_device **out_xdev) struct xrt_device **out_xdev)
{ {
if (spc->is_reference) { if (oxr_space_type_is_reference(spc->space_type)) {
struct xrt_device *head_xdev = GET_XDEV_BY_ROLE(spc->sess->sys, head); struct xrt_device *head_xdev = GET_XDEV_BY_ROLE(spc->sess->sys, head);
*out_xdev = head_xdev; *out_xdev = head_xdev;
return oxr_space_ref_get_pure_relation(log, spc->sess, spc->type, head_xdev, time, out_relation); return oxr_space_ref_get_pure_relation(log, spc->sess, spc->space_type, head_xdev, time, out_relation);
} else if (spc->space_type == OXR_SPACE_TYPE_ACTION) {
struct oxr_action_input *input = NULL;
oxr_action_get_pose_input(log, spc->sess, spc->act_key, &spc->subaction_paths, &input);
// If the input isn't active.
if (input == NULL) {
out_relation->relation_flags = XRT_SPACE_RELATION_BITMASK_NONE;
return false;
}
*out_xdev = input->xdev;
oxr_xdev_get_space_relation(log, spc->sess->sys->inst, input->xdev, input->input->name, time,
out_relation);
return true;
} }
struct oxr_action_input *input = NULL; return oxr_error(log, false, "Unknown space type");
oxr_action_get_pose_input(log, spc->sess, spc->act_key, &spc->subaction_paths, &input);
// If the input isn't active.
if (input == NULL) {
out_relation->relation_flags = XRT_SPACE_RELATION_BITMASK_NONE;
return false;
}
*out_xdev = input->xdev;
oxr_xdev_get_space_relation(log, spc->sess->sys->inst, input->xdev, input->input->name, time, out_relation);
return true;
} }
bool bool