2020-06-01 20:32:43 +00:00
|
|
|
// Copyright 2018-2020, Collabora, Ltd.
|
2019-03-18 05:52:32 +00:00
|
|
|
// SPDX-License-Identifier: BSL-1.0
|
|
|
|
/*!
|
|
|
|
* @file
|
2020-03-31 16:24:58 +00:00
|
|
|
* @brief File for verifying app input into api functions.
|
2019-03-18 05:52:32 +00:00
|
|
|
* @author Jakob Bornecrantz <jakob@collabora.com>
|
|
|
|
* @ingroup oxr_api
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#define _OXR_VERIFY_AND_SET_AND_INIT(log, thing, new_thing, THING, name, \
|
|
|
|
lookup) \
|
|
|
|
do { \
|
|
|
|
oxr_log_init(log, name); \
|
2020-04-28 22:47:12 +00:00
|
|
|
if (thing == XR_NULL_HANDLE) { \
|
2019-03-18 05:52:32 +00:00
|
|
|
return oxr_error(log, XR_ERROR_HANDLE_INVALID, \
|
|
|
|
"(" #thing " == NULL)"); \
|
|
|
|
} \
|
2020-04-28 22:51:39 +00:00
|
|
|
new_thing = (__typeof__(new_thing))(uintptr_t)thing; \
|
2019-04-05 19:18:03 +00:00
|
|
|
if (new_thing->handle.debug != OXR_XR_DEBUG_##THING) { \
|
2019-03-18 05:52:32 +00:00
|
|
|
return oxr_error(log, XR_ERROR_HANDLE_INVALID, \
|
|
|
|
"(" #thing " == %p)", \
|
2019-09-29 10:43:45 +00:00
|
|
|
(void *)new_thing); \
|
2019-03-18 05:52:32 +00:00
|
|
|
} \
|
2019-04-05 22:21:35 +00:00
|
|
|
if (new_thing->handle.state != OXR_HANDLE_STATE_LIVE) { \
|
|
|
|
return oxr_error(log, XR_ERROR_HANDLE_INVALID, \
|
2020-05-31 15:49:25 +00:00
|
|
|
"(" #thing " == %p) state == %s", \
|
|
|
|
(void *)new_thing, \
|
2019-04-05 22:21:35 +00:00
|
|
|
oxr_handle_state_to_string( \
|
2020-05-31 15:49:25 +00:00
|
|
|
new_thing->handle.state)); \
|
2019-04-05 22:21:35 +00:00
|
|
|
} \
|
2019-03-18 05:52:32 +00:00
|
|
|
oxr_log_set_instance(log, lookup); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define _OXR_VERIFY_SET(log, arg, new_arg, THING) \
|
|
|
|
do { \
|
2020-04-28 22:47:12 +00:00
|
|
|
if (arg == XR_NULL_HANDLE) { \
|
2019-03-18 05:52:32 +00:00
|
|
|
return oxr_error(log, XR_ERROR_HANDLE_INVALID, \
|
|
|
|
"(" #arg " == NULL)"); \
|
|
|
|
} \
|
2020-04-28 22:51:39 +00:00
|
|
|
new_arg = (__typeof__(new_arg))(uintptr_t)arg; \
|
2019-04-05 19:18:03 +00:00
|
|
|
if (new_arg->handle.debug != OXR_XR_DEBUG_##THING) { \
|
2019-03-18 05:52:32 +00:00
|
|
|
return oxr_error(log, XR_ERROR_HANDLE_INVALID, \
|
2019-09-29 10:43:45 +00:00
|
|
|
"(" #arg " == %p)", (void *)new_arg); \
|
2019-03-18 05:52:32 +00:00
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* @ingroup oxr_api
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
// clang-format off
|
|
|
|
#define OXR_VERIFY_INSTANCE_AND_INIT_LOG(log, thing, new_thing, name) \
|
|
|
|
_OXR_VERIFY_AND_SET_AND_INIT(log, thing, new_thing, INSTANCE, name, new_thing)
|
|
|
|
#define OXR_VERIFY_MESSENGER_AND_INIT_LOG(log, thing, new_thing, name) \
|
|
|
|
_OXR_VERIFY_AND_SET_AND_INIT(log, thing, new_thing, MESSENGER, name, new_thing->inst)
|
|
|
|
#define OXR_VERIFY_SESSION_AND_INIT_LOG(log, thing, new_thing, name) \
|
|
|
|
_OXR_VERIFY_AND_SET_AND_INIT(log, thing, new_thing, SESSION, name, new_thing->sys->inst)
|
|
|
|
#define OXR_VERIFY_SPACE_AND_INIT_LOG(log, thing, new_thing, name) \
|
|
|
|
_OXR_VERIFY_AND_SET_AND_INIT(log, thing, new_thing, SPACE, name, new_thing->sess->sys->inst)
|
|
|
|
#define OXR_VERIFY_ACTION_AND_INIT_LOG(log, thing, new_thing, name) \
|
2019-07-13 16:17:57 +00:00
|
|
|
_OXR_VERIFY_AND_SET_AND_INIT(log, thing, new_thing, ACTION, name, new_thing->act_set->inst)
|
2019-03-18 05:52:32 +00:00
|
|
|
#define OXR_VERIFY_SWAPCHAIN_AND_INIT_LOG(log, thing, new_thing, name) \
|
|
|
|
_OXR_VERIFY_AND_SET_AND_INIT(log, thing, new_thing, SWAPCHAIN, name, new_thing->sess->sys->inst)
|
|
|
|
#define OXR_VERIFY_ACTIONSET_AND_INIT_LOG(log, thing, new_thing, name) \
|
2019-07-13 16:17:57 +00:00
|
|
|
_OXR_VERIFY_AND_SET_AND_INIT(log, thing, new_thing, ACTIONSET, name, new_thing->inst)
|
2019-03-18 05:52:32 +00:00
|
|
|
|
|
|
|
#define OXR_VERIFY_INSTANCE_NOT_NULL(log, arg, new_arg) _OXR_VERIFY_SET(log, arg, new_arg, INSTANCE);
|
|
|
|
#define OXR_VERIFY_MESSENGER_NOT_NULL(log, arg, new_arg) _OXR_VERIFY_SET(log, arg, new_arg, MESSENGER);
|
|
|
|
#define OXR_VERIFY_SESSION_NOT_NULL(log, arg, new_arg) _OXR_VERIFY_SET(log, arg, new_arg, SESSION);
|
|
|
|
#define OXR_VERIFY_SPACE_NOT_NULL(log, arg, new_arg) _OXR_VERIFY_SET(log, arg, new_arg, SPACE);
|
|
|
|
#define OXR_VERIFY_ACTION_NOT_NULL(log, arg, new_arg) _OXR_VERIFY_SET(log, arg, new_arg, ACTION);
|
|
|
|
#define OXR_VERIFY_SWAPCHAIN_NOT_NULL(log, arg, new_arg) _OXR_VERIFY_SET(log, arg, new_arg, SWAPCHAIN);
|
|
|
|
#define OXR_VERIFY_ACTIONSET_NOT_NULL(log, arg, new_arg) _OXR_VERIFY_SET(log, arg, new_arg, ACTIONSET);
|
|
|
|
// clang-format on
|
|
|
|
|
2019-08-19 17:37:50 +00:00
|
|
|
/*!
|
|
|
|
* Checks if a required extension is enabled.
|
|
|
|
*
|
|
|
|
* mixed_case_name should be the extension name without the XR_ prefix.
|
|
|
|
*/
|
|
|
|
#define OXR_VERIFY_EXTENSION(log, inst, mixed_case_name) \
|
|
|
|
do { \
|
|
|
|
if (!(inst)->extensions.mixed_case_name) { \
|
|
|
|
return oxr_error((log), XR_ERROR_FUNCTION_UNSUPPORTED, \
|
2020-05-31 15:49:25 +00:00
|
|
|
"Requires XR_" #mixed_case_name \
|
2019-08-19 17:37:50 +00:00
|
|
|
" extension enabled"); \
|
|
|
|
} \
|
|
|
|
} while (false)
|
2019-03-18 05:52:32 +00:00
|
|
|
|
|
|
|
#define OXR_VERIFY_ARG_NOT_NULL(log, arg) \
|
|
|
|
do { \
|
|
|
|
if (arg == NULL) { \
|
|
|
|
return oxr_error(log, XR_ERROR_VALIDATION_FAILURE, \
|
|
|
|
"(" #arg " == NULL)"); \
|
|
|
|
} \
|
|
|
|
} while (false)
|
|
|
|
|
2019-08-01 06:39:50 +00:00
|
|
|
#define OXR_VERIFY_ARG_NOT_ZERO(log, arg) \
|
|
|
|
do { \
|
|
|
|
if (arg == 0) { \
|
|
|
|
return oxr_error(log, XR_ERROR_VALIDATION_FAILURE, \
|
|
|
|
"(" #arg " == 0) must be non-zero"); \
|
|
|
|
} \
|
|
|
|
} while (false)
|
|
|
|
|
2019-10-31 15:57:02 +00:00
|
|
|
#define OXR_VERIFY_ARG_TYPE_CAN_BE_NULL(log, arg, type_enum) \
|
2019-03-18 05:52:32 +00:00
|
|
|
do { \
|
2019-10-31 15:57:02 +00:00
|
|
|
if (arg != NULL && arg->type != type_enum) { \
|
2019-03-18 05:52:32 +00:00
|
|
|
return oxr_error(log, XR_ERROR_VALIDATION_FAILURE, \
|
2019-10-31 15:57:02 +00:00
|
|
|
"(" #arg "->type == %u)", arg->type); \
|
2019-03-18 05:52:32 +00:00
|
|
|
} \
|
2019-10-31 15:57:02 +00:00
|
|
|
} while (false)
|
|
|
|
|
|
|
|
#define OXR_VERIFY_ARG_TYPE_AND_NOT_NULL(log, arg, type_enum) \
|
|
|
|
do { \
|
|
|
|
if (arg == NULL) { \
|
2019-03-18 05:52:32 +00:00
|
|
|
return oxr_error(log, XR_ERROR_VALIDATION_FAILURE, \
|
2019-10-31 15:57:02 +00:00
|
|
|
"(" #arg " == NULL)"); \
|
2019-03-18 05:52:32 +00:00
|
|
|
} \
|
2019-10-31 15:57:02 +00:00
|
|
|
OXR_VERIFY_ARG_TYPE_CAN_BE_NULL(log, arg, type_enum); \
|
2019-03-18 05:52:32 +00:00
|
|
|
} while (false)
|
|
|
|
|
|
|
|
#define OXR_VERIFY_SUBACTION_PATHS(log, count, paths) \
|
|
|
|
do { \
|
|
|
|
if (count > 0 && paths == NULL) { \
|
|
|
|
return oxr_error(log, XR_ERROR_VALIDATION_FAILURE, \
|
2020-05-31 15:49:25 +00:00
|
|
|
"(" #count \
|
|
|
|
") is not zero but " #paths \
|
2019-03-18 05:52:32 +00:00
|
|
|
" is NULL"); \
|
|
|
|
} \
|
|
|
|
} while (false)
|
|
|
|
|
|
|
|
#define OXR_VERIFY_ARG_SINGLE_LEVEL_FIXED_LENGTH_PATH(log, path) \
|
|
|
|
do { \
|
|
|
|
XrResult verify_ret = oxr_verify_fixed_size_single_level_path( \
|
|
|
|
log, path, ARRAY_SIZE(path), #path); \
|
|
|
|
if (verify_ret != XR_SUCCESS) { \
|
|
|
|
return verify_ret; \
|
|
|
|
} \
|
|
|
|
} while (false)
|
|
|
|
|
2019-04-13 15:11:47 +00:00
|
|
|
#define OXR_VERIFY_ARG_LOCALIZED_NAME(log, string) \
|
|
|
|
do { \
|
|
|
|
XrResult verify_ret = oxr_verify_localized_name( \
|
|
|
|
log, string, ARRAY_SIZE(string), #string); \
|
|
|
|
if (verify_ret != XR_SUCCESS) { \
|
|
|
|
return verify_ret; \
|
|
|
|
} \
|
|
|
|
} while (false)
|
2019-04-05 11:54:37 +00:00
|
|
|
|
2019-07-21 12:40:27 +00:00
|
|
|
#define OXR_VERIFY_POSE(log, p) \
|
|
|
|
do { \
|
2019-09-29 10:43:45 +00:00
|
|
|
if (!math_quat_validate((struct xrt_quat *)&p.orientation)) { \
|
2019-07-21 12:40:27 +00:00
|
|
|
return oxr_error(log, XR_ERROR_POSE_INVALID, \
|
|
|
|
"(" #p \
|
|
|
|
".orientation) is not a valid quat"); \
|
|
|
|
} \
|
|
|
|
\
|
2019-09-29 10:43:45 +00:00
|
|
|
if (!math_vec3_validate((struct xrt_vec3 *)&p.position)) { \
|
2019-07-21 12:40:27 +00:00
|
|
|
return oxr_error(log, XR_ERROR_POSE_INVALID, \
|
|
|
|
"(" #p ".position) is not valid"); \
|
|
|
|
} \
|
|
|
|
} while (false)
|
|
|
|
|
2019-03-18 05:52:32 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Implementation in oxr_verify.cpp
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-04-05 11:54:37 +00:00
|
|
|
XrResult
|
2019-09-29 10:43:45 +00:00
|
|
|
oxr_verify_full_path_c(struct oxr_logger *log,
|
|
|
|
const char *path,
|
|
|
|
const char *name);
|
2019-04-05 11:54:37 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* Verify a full path.
|
|
|
|
*
|
|
|
|
* Length not including zero terminator character but must be there.
|
|
|
|
*/
|
|
|
|
XrResult
|
2019-09-29 10:43:45 +00:00
|
|
|
oxr_verify_full_path(struct oxr_logger *log,
|
|
|
|
const char *path,
|
2019-04-05 11:54:37 +00:00
|
|
|
size_t length,
|
2019-09-29 10:43:45 +00:00
|
|
|
const char *name);
|
2019-04-05 11:54:37 +00:00
|
|
|
|
2019-04-05 09:37:57 +00:00
|
|
|
/*!
|
|
|
|
* Verify a single path level that sits inside of a fixed sized array.
|
|
|
|
*/
|
2019-03-18 05:52:32 +00:00
|
|
|
XrResult
|
2019-09-29 10:43:45 +00:00
|
|
|
oxr_verify_fixed_size_single_level_path(struct oxr_logger *,
|
|
|
|
const char *path,
|
2019-04-05 09:37:57 +00:00
|
|
|
uint32_t array_size,
|
2019-09-29 10:43:45 +00:00
|
|
|
const char *name);
|
2019-03-18 05:52:32 +00:00
|
|
|
|
2019-04-13 15:11:47 +00:00
|
|
|
/*!
|
|
|
|
* Verify an arbitrary UTF-8 string that sits inside of a fixed sized array.
|
|
|
|
*/
|
|
|
|
XrResult
|
2019-09-29 10:43:45 +00:00
|
|
|
oxr_verify_localized_name(struct oxr_logger *,
|
|
|
|
const char *string,
|
2019-04-13 15:11:47 +00:00
|
|
|
uint32_t array_size,
|
2019-09-29 10:43:45 +00:00
|
|
|
const char *name);
|
2019-04-13 15:11:47 +00:00
|
|
|
|
2019-05-07 12:47:18 +00:00
|
|
|
/*!
|
|
|
|
* Verify a set of subaction paths for action creation.
|
|
|
|
*/
|
|
|
|
XrResult
|
2019-09-29 10:43:45 +00:00
|
|
|
oxr_verify_subaction_paths_create(struct oxr_logger *log,
|
|
|
|
struct oxr_instance *inst,
|
2019-05-07 12:47:18 +00:00
|
|
|
uint32_t countSubactionPaths,
|
2019-09-29 10:43:45 +00:00
|
|
|
const XrPath *subactionPaths,
|
|
|
|
const char *variable);
|
2019-05-07 12:47:18 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* Verify a set of subaction paths for action sync.
|
|
|
|
*/
|
|
|
|
XrResult
|
2019-09-29 10:43:45 +00:00
|
|
|
oxr_verify_subaction_path_sync(struct oxr_logger *log,
|
|
|
|
struct oxr_instance *inst,
|
2019-05-07 12:47:18 +00:00
|
|
|
XrPath path,
|
|
|
|
uint32_t index);
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Verify a set of subaction paths for action state get.
|
|
|
|
*/
|
|
|
|
XrResult
|
2019-09-29 10:43:45 +00:00
|
|
|
oxr_verify_subaction_path_get(struct oxr_logger *log,
|
|
|
|
struct oxr_instance *inst,
|
2019-05-07 12:47:18 +00:00
|
|
|
XrPath path,
|
2019-09-29 10:43:45 +00:00
|
|
|
const struct oxr_sub_paths *act_sub_paths,
|
|
|
|
struct oxr_sub_paths *out_sub_paths,
|
|
|
|
const char *variable);
|
2019-05-07 12:47:18 +00:00
|
|
|
|
2019-03-18 05:52:32 +00:00
|
|
|
XrResult
|
2019-09-29 10:43:45 +00:00
|
|
|
oxr_verify_XrSessionCreateInfo(struct oxr_logger *,
|
|
|
|
const struct oxr_instance *,
|
|
|
|
const XrSessionCreateInfo *);
|
2019-03-18 05:52:32 +00:00
|
|
|
|
2019-12-03 19:08:10 +00:00
|
|
|
#if defined(XR_USE_PLATFORM_XLIB) && defined(XR_USE_GRAPHICS_API_OPENGL)
|
2019-03-18 05:52:32 +00:00
|
|
|
XrResult
|
|
|
|
oxr_verify_XrGraphicsBindingOpenGLXlibKHR(
|
2019-09-29 10:43:45 +00:00
|
|
|
struct oxr_logger *, const XrGraphicsBindingOpenGLXlibKHR *);
|
2019-12-03 19:08:10 +00:00
|
|
|
#endif // defined(XR_USE_PLATFORM_XLIB) && defined(XR_USE_GRAPHICS_API_OPENGL)
|
2019-03-18 05:52:32 +00:00
|
|
|
|
2019-12-03 19:08:10 +00:00
|
|
|
#if defined(XR_USE_GRAPHICS_API_VULKAN)
|
2019-03-18 05:52:32 +00:00
|
|
|
XrResult
|
2019-09-29 10:43:45 +00:00
|
|
|
oxr_verify_XrGraphicsBindingVulkanKHR(struct oxr_logger *,
|
|
|
|
const XrGraphicsBindingVulkanKHR *);
|
2019-12-03 19:08:10 +00:00
|
|
|
#endif // defined(XR_USE_GRAPHICS_API_VULKAN)
|
2019-03-18 05:52:32 +00:00
|
|
|
|
2019-12-03 19:08:10 +00:00
|
|
|
#if defined(XR_USE_PLATFORM_EGL) && defined(XR_USE_GRAPHICS_API_OPENGL)
|
2019-10-29 16:11:48 +00:00
|
|
|
XrResult
|
2020-05-20 15:55:07 +00:00
|
|
|
oxr_verify_XrGraphicsBindingEGLMNDX(struct oxr_logger *log,
|
|
|
|
const XrGraphicsBindingEGLMNDX *next);
|
2019-12-03 19:08:10 +00:00
|
|
|
#endif // defined(XR_USE_PLATFORM_EGL) && defined(XR_USE_GRAPHICS_API_OPENGL)
|
2019-10-29 16:11:48 +00:00
|
|
|
|
2019-03-18 05:52:32 +00:00
|
|
|
/*!
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|