2021-04-26 20:28:12 +00:00
|
|
|
// Copyright 2019-2021, Collabora, Ltd.
|
2019-03-18 05:52:32 +00:00
|
|
|
// SPDX-License-Identifier: BSL-1.0
|
|
|
|
/*!
|
|
|
|
* @file
|
|
|
|
* @brief Misc helpers for device drivers.
|
|
|
|
* @author Jakob Bornecrantz <jakob@collabora.com>
|
2021-04-26 20:28:12 +00:00
|
|
|
* @author Ryan Pavlik <ryan.pavlik@collabora.com>
|
2021-06-16 09:28:16 +00:00
|
|
|
* @author Moses Turner <moses@collabora.com>
|
2019-04-06 11:28:56 +00:00
|
|
|
* @ingroup aux_util
|
2019-03-18 05:52:32 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "xrt/xrt_compiler.h"
|
|
|
|
#include "xrt/xrt_device.h"
|
2019-05-09 10:54:48 +00:00
|
|
|
#include "xrt/xrt_tracking.h"
|
2019-03-18 05:52:32 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
extern const struct xrt_matrix_2x2 u_device_rotation_right;
|
|
|
|
extern const struct xrt_matrix_2x2 u_device_rotation_left;
|
|
|
|
extern const struct xrt_matrix_2x2 u_device_rotation_ident;
|
|
|
|
extern const struct xrt_matrix_2x2 u_device_rotation_180;
|
|
|
|
|
2019-05-09 10:54:48 +00:00
|
|
|
enum u_device_alloc_flags
|
|
|
|
{
|
|
|
|
// clang-format off
|
2020-12-27 22:49:32 +00:00
|
|
|
U_DEVICE_ALLOC_NO_FLAGS = 0,
|
2023-03-02 22:50:39 +00:00
|
|
|
U_DEVICE_ALLOC_HMD = 1u << 0u,
|
|
|
|
U_DEVICE_ALLOC_TRACKING_NONE = 1u << 1u,
|
2019-05-09 10:54:48 +00:00
|
|
|
// clang-format on
|
|
|
|
};
|
|
|
|
|
2021-06-16 09:28:16 +00:00
|
|
|
/*!
|
|
|
|
*
|
|
|
|
* Info to describe 2D extents of a device's screen
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
struct u_extents_2d
|
|
|
|
{
|
|
|
|
uint32_t w_pixels; // Width of entire screen in pixels
|
|
|
|
uint32_t h_pixels; // Height of entire screen
|
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
*
|
|
|
|
* Info to describe a very simple headset with diffractive lens optics.
|
|
|
|
*
|
|
|
|
*/
|
2019-04-19 23:11:16 +00:00
|
|
|
struct u_device_simple_info
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
uint32_t w_pixels;
|
|
|
|
uint32_t h_pixels;
|
|
|
|
float w_meters;
|
|
|
|
float h_meters;
|
|
|
|
} display;
|
|
|
|
|
|
|
|
float lens_horizontal_separation_meters;
|
|
|
|
float lens_vertical_position_meters;
|
|
|
|
|
2022-02-19 01:02:36 +00:00
|
|
|
float fov[2];
|
2019-04-19 23:11:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Setup the device information given a very simple info struct.
|
|
|
|
*
|
|
|
|
* @return true on success.
|
|
|
|
* @ingroup aux_util
|
|
|
|
*/
|
|
|
|
bool
|
2021-01-14 14:13:48 +00:00
|
|
|
u_device_setup_split_side_by_side(struct xrt_device *xdev, const struct u_device_simple_info *info);
|
2019-04-19 23:11:16 +00:00
|
|
|
|
2021-06-16 09:28:16 +00:00
|
|
|
/*!
|
2022-05-17 20:28:47 +00:00
|
|
|
* Setup the device's display's 2D extents.
|
2021-06-16 09:28:16 +00:00
|
|
|
* Good for headsets without traditional VR optics.
|
|
|
|
*
|
|
|
|
* @return true on success.
|
|
|
|
* @ingroup aux_util
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
u_extents_2d_split_side_by_side(struct xrt_device *xdev, const struct u_extents_2d *extents);
|
|
|
|
|
|
|
|
|
2019-03-18 05:52:32 +00:00
|
|
|
/*!
|
|
|
|
* Dump the device config to stderr.
|
2019-04-06 11:28:56 +00:00
|
|
|
*
|
|
|
|
* @ingroup aux_util
|
2019-03-18 05:52:32 +00:00
|
|
|
*/
|
|
|
|
void
|
2021-01-14 14:13:48 +00:00
|
|
|
u_device_dump_config(struct xrt_device *xdev, const char *prefix, const char *prod);
|
2019-03-18 05:52:32 +00:00
|
|
|
|
2021-11-08 21:02:03 +00:00
|
|
|
#define U_DEVICE_ALLOCATE(type, flags, input_count, output_count) \
|
|
|
|
((type *)u_device_allocate(flags, sizeof(type), input_count, output_count))
|
2019-05-09 10:54:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Helper function to allocate a device plus inputs in the same allocation
|
|
|
|
* placed after the device in memory.
|
|
|
|
*
|
|
|
|
* Will setup any pointers and num values.
|
2019-10-24 10:43:01 +00:00
|
|
|
*
|
|
|
|
* @ingroup aux_util
|
2019-05-09 10:54:48 +00:00
|
|
|
*/
|
2019-09-29 10:43:23 +00:00
|
|
|
void *
|
2021-11-08 21:02:03 +00:00
|
|
|
u_device_allocate(enum u_device_alloc_flags flags, size_t size, size_t input_count, size_t output_count);
|
2019-05-09 10:54:48 +00:00
|
|
|
|
2019-10-24 10:43:01 +00:00
|
|
|
/*!
|
|
|
|
* Helper function to free a device and any data hanging of it.
|
|
|
|
*
|
|
|
|
* @ingroup aux_util
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
u_device_free(struct xrt_device *xdev);
|
|
|
|
|
2019-03-18 05:52:32 +00:00
|
|
|
|
2020-11-06 15:34:29 +00:00
|
|
|
#define XRT_DEVICE_ROLE_UNASSIGNED (-1)
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Helper function to assign head, left hand and right hand roles.
|
|
|
|
*
|
|
|
|
* @ingroup aux_util
|
|
|
|
*/
|
|
|
|
void
|
2021-11-08 21:29:21 +00:00
|
|
|
u_device_assign_xdev_roles(struct xrt_device **xdevs, size_t xdev_count, int *head, int *left, int *right);
|
2020-11-06 15:34:29 +00:00
|
|
|
|
2021-04-26 20:28:12 +00:00
|
|
|
/*!
|
|
|
|
* Helper function for `get_view_pose` in an HMD driver.
|
|
|
|
*
|
|
|
|
* Takes in a translation from the left to right eye, and returns a center to left or right eye transform that assumes
|
|
|
|
* the eye relation is symmetrical around the tracked point ("center eye"). Knowing IPD is a subset of this: If you know
|
|
|
|
* IPD better than the overall Monado system, copy @p eye_relation and put your known IPD in @p real_eye_relation->x
|
|
|
|
*
|
|
|
|
* If you have rotation, apply it after calling this function.
|
|
|
|
*
|
|
|
|
* @param eye_relation 3D translation from left eye to right eye.
|
|
|
|
* @param view_index 0 for left, 1 for right.
|
|
|
|
* @param out_pose The output pose to populate. Will receive translation, with an identity rotation.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
u_device_get_view_pose(const struct xrt_vec3 *eye_relation, uint32_t view_index, struct xrt_pose *out_pose);
|
|
|
|
|
2022-02-07 23:35:09 +00:00
|
|
|
/*!
|
|
|
|
* Helper function for `get_view_poses` in a HMD driver.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
u_device_get_view_poses(struct xrt_device *xdev,
|
|
|
|
const struct xrt_vec3 *default_eye_relation,
|
|
|
|
uint64_t at_timestamp_ns,
|
|
|
|
uint32_t view_count,
|
|
|
|
struct xrt_space_relation *out_head_relation,
|
|
|
|
struct xrt_fov *out_fovs,
|
|
|
|
struct xrt_pose *out_poses);
|
|
|
|
|
|
|
|
|
2019-03-18 05:52:32 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|