108template <
class T, DeviceFunctions functions>
class DeviceBase
116 static_assert(std::is_standard_layout_v<DeviceBase>,
117 "glue base must be standard layout for pointer recovery");
118 static_assert(is_non_virtual_base_v<DeviceBase, T>,
119 "glue base must be a non-virtual base of T for pointer recovery");
129 if constexpr (functions.hmd) {
130 xdev.get_view_poses = getViewPosesWrap;
131 xdev.is_form_factor_available = isFormFactorAvailableWrap;
134 if constexpr (functions.distortion) {
135 xdev.compute_distortion = computeDistortionWrap;
138 if constexpr (functions.visibility_mask) {
139 xdev.get_visibility_mask = getVisibilityMaskWrap;
142 if constexpr (functions.update_inputs) {
143 xdev.update_inputs = updateInputsWrap;
146 if constexpr (functions.output) {
147 xdev.set_output = setOutputWrap;
150 if constexpr (functions.output_limits) {
151 xdev.get_output_limits = getOutputLimitsWrap;
154 if constexpr (functions.hand_tracking) {
155 xdev.get_hand_tracking = getHandTrackingWrap;
158 if constexpr (functions.face_tracking) {
159 xdev.get_face_tracking = getFaceTrackingWrap;
162 if constexpr (functions.face_calibration_android) {
163 xdev.get_face_calibration_state_android = getFaceCalibrationStateAndroidWrap;
166 if constexpr (functions.body_tracking) {
167 xdev.get_body_skeleton = getBodySkeletonWrap;
168 xdev.get_body_joints = getBodyJointsWrap;
169 xdev.reset_body_tracking_calibration_meta = resetBodyTrackingCalibrationMetaWrap;
170 xdev.set_body_tracking_calibration_override_meta = setBodyTrackingCalibrationOverrideMetaWrap;
173 if constexpr (functions.plane_detection) {
174 xdev.begin_plane_detection_ext = beginPlaneDetectionExtWrap;
175 xdev.destroy_plane_detection_ext = destroyPlaneDetectionExtWrap;
176 xdev.get_plane_detection_state_ext = getPlaneDetectionStateExtWrap;
177 xdev.get_plane_detections_ext = getPlaneDetectionsExtWrap;
180 if constexpr (functions.reference_space) {
181 xdev.ref_space_usage = refSpaceUsageWrap;
184 if constexpr (functions.battery) {
185 xdev.get_battery_status = getBatteryStatusWrap;
188 if constexpr (functions.brightness) {
189 xdev.get_brightness = getBrightnessWrap;
190 xdev.set_brightness = setBrightnessWrap;
193 if constexpr (functions.compositor_info) {
194 xdev.get_compositor_info = getCompositorInfoWrap;
197 if constexpr (functions.features) {
198 xdev.begin_feature = beginFeatureWrap;
199 xdev.end_feature = endFeatureWrap;
209 derived() const noexcept
211 return static_cast<const T &
>(*this);
217 return static_cast<T &
>(*this);
224 return &(
reinterpret_cast<const DeviceBase *
>(xdev)->derived());
231 return &(
reinterpret_cast<DeviceBase *
>(xdev)->derived());
260#define GET(xdev) (fromXDev(xdev)->derived())
263 updateInputsWrap(
struct xrt_device *xdev)
noexcept
265 return GET(xdev).updateInputs();
272 int64_t at_timestamp_ns,
275 return GET(xdev).getTrackedPose(name, at_timestamp_ns, out_relation);
282 int64_t desired_timestamp_ns,
284 int64_t *out_timestamp_ns)
noexcept
286 return GET(xdev).getHandTracking(name, desired_timestamp_ns, out_value, out_timestamp_ns);
293 int64_t at_timestamp_ns,
296 return GET(xdev).getFaceTracking(facial_expression_type, at_timestamp_ns, out_value);
301 getFaceCalibrationStateAndroidWrap(
struct xrt_device *xdev,
bool *out_face_is_calibrated)
noexcept
303 return GET(xdev).getFaceCalibrationStateAndroid(out_face_is_calibrated);
312 return GET(xdev).getBodySkeleton(body_tracking_type, out_value);
319 int64_t desired_timestamp_ns,
322 return GET(xdev).getBodyJoints(body_tracking_type, desired_timestamp_ns, out_value);
327 resetBodyTrackingCalibrationMetaWrap(
struct xrt_device *xdev)
noexcept
329 return GET(xdev).resetBodyTrackingCalibrationMeta();
334 setBodyTrackingCalibrationOverrideMetaWrap(
struct xrt_device *xdev,
float new_body_height)
noexcept
336 return GET(xdev).setBodyTrackingCalibrationOverrideMeta(new_body_height);
343 return GET(xdev).setOutput(name, value);
350 return GET(xdev).getOutputLimits(limits);
355 beginPlaneDetectionExtWrap(
struct xrt_device *xdev,
357 uint64_t plane_detection_id,
358 uint64_t *out_plane_detection_id)
noexcept
360 return GET(xdev).beginPlaneDetectionExt(begin_info, plane_detection_id, out_plane_detection_id);
365 destroyPlaneDetectionExtWrap(
struct xrt_device *xdev, uint64_t plane_detection_id)
noexcept
367 return GET(xdev).destroyPlaneDetectionExt(plane_detection_id);
372 getPlaneDetectionStateExtWrap(
struct xrt_device *xdev,
373 uint64_t plane_detection_id,
376 return GET(xdev).getPlaneDetectionStateExt(plane_detection_id, out_state);
381 getPlaneDetectionsExtWrap(
struct xrt_device *xdev,
382 uint64_t plane_detection_id,
385 return GET(xdev).getPlaneDetectionsExt(plane_detection_id, out_detections);
391 const struct xrt_vec3 *default_eye_relation,
392 int64_t at_timestamp_ns,
397 struct xrt_pose *out_poses)
noexcept
399 return GET(xdev).getViewPoses(default_eye_relation, at_timestamp_ns, view_type, view_count,
400 out_head_relation, out_fovs, out_poses);
405 computeDistortionWrap(
408 return GET(xdev).computeDistortion(view, u, v, out_result);
413 getVisibilityMaskWrap(
struct xrt_device *xdev,
418 return GET(xdev).getVisibilityMask(type, view_index, out_mask);
428 return GET(xdev).refSpaceUsage(type, name, used);
433 isFormFactorAvailableWrap(
struct xrt_device *xdev,
435 bool *out_available)
noexcept
437 return GET(xdev).isFormFactorAvailable(form_factor, out_available);
442 getBatteryStatusWrap(
struct xrt_device *xdev,
bool *out_present,
bool *out_charging,
float *out_charge)
noexcept
444 return GET(xdev).getBatteryStatus(out_present, out_charging, out_charge);
449 getBrightnessWrap(
struct xrt_device *xdev,
float *out_brightness)
noexcept
451 return GET(xdev).getBrightness(out_brightness);
456 setBrightnessWrap(
struct xrt_device *xdev,
float brightness,
bool relative)
noexcept
458 return GET(xdev).setBrightness(brightness, relative);
463 getCompositorInfoWrap(
struct xrt_device *xdev,
467 return GET(xdev).getCompositorInfo(mode, out_info);
474 return GET(xdev).beginFeature(type);
481 return GET(xdev).endFeature(type);
486 destroyDeviceWrap(
struct xrt_device *xdev)
noexcept
488 T::destroyDevice(xdev);
CRTP glue wrapper for xrt_device.
Definition g_device.hpp:109
DeviceBase() noexcept
Fully resets and sets function pointers on xrt_device.
Definition g_device.hpp:114
xrt_device * getXDev() noexcept
Gets the underlying xrt_device pointer.
Definition g_device.hpp:243
static T * fromXDev(xrt_device *xdev) noexcept
Gets the pointer to the derived class from a xrt_device.
Definition g_device.hpp:229
static const T * fromXDev(const xrt_device *xdev) noexcept
Gets the pointer to the derived class from a xrt_device.
Definition g_device.hpp:222
~DeviceBase() noexcept=default
Destructor.
const xrt_device * getXDev() const noexcept
Gets the underlying xrt_device pointer.
Definition g_device.hpp:236
Catch guards for glue classes.
Shared type traits for glue classes.
void u_device_populate_function_pointers(struct xrt_device *xdev, u_device_get_tracked_pose_function_t get_tracked_pose_fn, u_device_destroy_function_t destroy_fn)
Populate the device's function pointers with default implementations.
Definition u_device.c:599
void u_device_id_assign(struct xrt_device *xdev)
Assign a newly generated ID to the given device.
Definition u_device_id.c:31
xrt_visibility_mask_type
Visibility mask, mirror of XrVisibilityMaskKHR.
Definition xrt_defines.h:2468
xrt_form_factor
What form factor is this device, mostly maps onto OpenXR's XrFormFactor.
Definition xrt_defines.h:2408
xrt_input_name
Every internal input source known to monado with a baked in type.
Definition xrt_defines.h:930
enum xrt_result xrt_result_t
Result type used across Monado.
xrt_reference_space_type
Type of a OpenXR mapped reference space, maps to the semantic spaces on the xrt_space_overseer struct...
Definition xrt_defines.h:625
xrt_output_name
Name of a output with a baked in type.
Definition xrt_defines.h:1612
xrt_plane_detector_state_ext
State of a plane detector, see xrt_device.
Definition xrt_plane_detector.h:83
Selects which functions that the DeviceBase wrapper should set.
Definition g_device.hpp:28
bool body_tracking
xrt_device::get_body_skeleton xrt_device::get_body_joints xrt_device::reset_body_tracking_calibration...
Definition g_device.hpp:65
bool reference_space
xrt_device::ref_space_usage
Definition g_device.hpp:76
bool plane_detection
xrt_device::begin_plane_detection_ext xrt_device::destroy_plane_detection_ext xrt_device::get_plane_d...
Definition g_device.hpp:73
bool output_limits
xrt_device::get_output_limits
Definition g_device.hpp:48
bool visibility_mask
xrt_device::get_visibility_mask
Definition g_device.hpp:39
bool update_inputs
xrt_device::update_inputs
Definition g_device.hpp:42
bool compositor_info
xrt_device::get_compositor_info
Definition g_device.hpp:88
bool hmd
xrt_device::get_view_poses xrt_device::is_form_factor_available
Definition g_device.hpp:33
bool output
xrt_device::set_output
Definition g_device.hpp:45
bool battery
xrt_device::get_battery_status
Definition g_device.hpp:79
bool brightness
xrt_device::get_brightness xrt_device::set_brightness
Definition g_device.hpp:85
bool hand_tracking
xrt_device::get_hand_tracking
Definition g_device.hpp:51
bool face_tracking
xrt_device::get_face_tracking
Definition g_device.hpp:54
bool distortion
xrt_device::compute_distortion
Definition g_device.hpp:36
bool features
xrt_device::begin_feature xrt_device::end_feature
Definition g_device.hpp:94
bool face_calibration_android
xrt_device::get_face_calibration_state_android
Definition g_device.hpp:57
Definition xrt_defines.h:2301
Definition xrt_defines.h:2198
Compositor information for a device.
Definition xrt_device.h:110
Compositor mode information for a device.
Definition xrt_device.h:126
A single HMD or input device.
Definition xrt_device.h:340
Definition xrt_defines.h:1967
Describes a projection matrix fov.
Definition xrt_defines.h:512
Joint set type used for hand tracking.
Definition xrt_defines.h:1521
Output limits of a particular device.
Definition xrt_device.h:288
A union of all output types.
Definition xrt_defines.h:2386
Each plane has n polygons; ultimately plane metadata from xrt_plane_detections_ext::locations and xrt...
Definition xrt_plane_detector.h:172
A query for a plane.
Definition xrt_plane_detector.h:97
A pose composed of a position and orientation.
Definition xrt_defines.h:492
A relation with two spaces, includes velocity and acceleration.
Definition xrt_defines.h:683
Represents a uv triplet for distortion, basically just three xrt_vec2.
Definition xrt_defines.h:279
A 3 element vector with single floats.
Definition xrt_defines.h:289
Visibility mask helper, the indices and vertices are tightly packed after this struct.
Definition xrt_visibility_mask.h:26
Misc helpers for device drivers.
Generator for per-process unique xrt_device_id values.
xrt_view_type
View type to be rendered to by the compositor.
Definition xrt_defines.h:2417
Header defining an xrt display or controller device.
xrt_device_feature_type
Higher level features for devices.
Definition xrt_device.h:276