Monado OpenXR Runtime
Loading...
Searching...
No Matches
u_var.h
Go to the documentation of this file.
1// Copyright 2019-2024, Collabora, Ltd.
2// Copyright 2024-2025, NVIDIA CORPORATION.
3// SPDX-License-Identifier: BSL-1.0
4/*!
5 * @file
6 * @brief Variable tracking code.
7 * @author Jakob Bornecrantz <jakob@collabora.com>
8 * @ingroup aux_util
9 */
10
11#pragma once
12
13#include "xrt/xrt_defines.h" // IWYU pragma: keep
14
15#include "util/u_logging.h"
16
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
22
23struct xrt_frame_sink;
24struct u_sink_debug;
26struct m_ff_f64;
27struct m_ff_vec3_f32;
28
29/*!
30 * Used to plot an array for values.
31 *
32 * @ingroup aux_util
33 */
35{
36 void *data;
37 int *index_ptr;
38 int length;
39};
40
42{
43 void *data;
44 int length;
45};
46
47/*!
48 * Used to plot a graph of timing information.
49 *
50 * @ingroup aux_util
51 */
53{
54 //! Values to be plotted.
56
57 //! A reference line drawn on the plot.
59
60 //! If false, reference_timing will be the bottom of the graph.
62
63 //! How many units the graph expands by default.
64 float range;
65
66 //! Rescale graph's value range when value exceeds range.
68
69 //! A string describing the unit used, not freed.
70 const char *unit;
71};
72
73/*!
74 * Callback for a button action
75 *
76 * @ingroup aux_util
77 */
78typedef void (*u_var_button_cb)(void *);
79
80/*!
81 * Simple pushable button.
82 *
83 * @ingroup aux_util
84 */
86{
87 //! Callback function to execute on button press
89
90 //! Pointer that will be passed to the function as its only argument
91 void *ptr;
92
93 /*!
94 * Is the pointer pressing down on the button curruently, this is not
95 * edge triggered like the callback. For a mouse this means that the
96 * pointer is hovering the button and the left is held down.
97 */
98 xrt_atomic_s32_t downed;
99
100 //! Button text, use var `name` if zeroed
101 char label[64];
102
103 //! Button dimensions, zero for auto size
104 float width;
105 float height;
106
107 //! Whether this button is disabled
109};
110
111/*!
112 * Combo box information.
113 *
114 * @ingroup aux_util
115 */
117{
118 //! Number of options.
119 int count;
120
121 //! List of `count` option names separated by \0.
122 const char *options;
123
124 //! Pointer to the option value.
125 int *value;
126};
127
128/*!
129 * Draggable single precision float information.
130 *
131 * @ingroup aux_util
132 */
134{
135 float val;
136 float step;
137 float min;
138 float max;
139};
140
141/*!
142 * Draggable usingned 16-bit integer information.
143 *
144 * @ingroup aux_util
145 */
147{
148 //! @note Using a float instead of storing the value like @ref
149 //! u_var_draggable_f32. It seemed better to decouple the UI from the value
150 //! itself.
151 //! @todo Unify "draggable" widgets interface.
152 uint16_t *val;
153 uint16_t step;
154 uint16_t min;
155 uint16_t max;
156};
157
158/*!
159 * Histogram based on single precision bars.
160 *
161 * @ingroup aux_util
162 */
164{
165 float *values; //!< Bin heights
166 int count; //!< Number of bins
167 float width; //!< Widget width or 0 for auto
168 float height; //!< Widget height or 0 for auto
169};
170
171/*!
172 * A point on the curve, uses doubles like ImPlotPoint.
173 *
174 * @ingroup aux_util
175 */
177{
178 double x;
179 double y;
180};
181
182/*!
183 * Callback for getting points on a curve.
184 *
185 * @ingroup aux_util
186 */
187typedef struct u_var_curve_point (*u_var_curve_getter)(void *data, int i);
188
189/*!
190 * A single curve on a plot.
191 *
192 * @ingroup aux_util
193 */
195{
196 u_var_curve_getter getter; //!< Getter of 2D points for the curve
197 void *data; //!< User data for `getter`
198 int count; //!< Number of points to draw; param i < count
199 const char *label; //!< Curve name
200 const char *xlabel; //!< Label of the X axis
201 const char *ylabel; //!< Label of the Y axis
202};
203
204/*!
205 * A collection of curves to be plotted.
206 *
207 * @ingroup aux_util
208 */
210{
211 struct u_var_curve curves[16];
212 int curve_count;
213
214 // These override individual curve axis labels
215 const char *xlabel; //!< Label of the X axis
216 const char *ylabel; //!< Label of the Y axis
217};
218
219/*!
220 * What kind of variable is this tracking.
221 *
222 * @ingroup aux_util
223 */
225{
226 U_VAR_KIND_BOOL,
227 U_VAR_KIND_RGB_U8,
228 U_VAR_KIND_RGB_F32,
229 U_VAR_KIND_U8,
230 U_VAR_KIND_U16,
231 U_VAR_KIND_U16_ARR,
232 U_VAR_KIND_U64,
233 U_VAR_KIND_I32,
234 U_VAR_KIND_I64,
235 U_VAR_KIND_F32,
236 U_VAR_KIND_DRAGGABLE_F32,
237 U_VAR_KIND_F64,
238 U_VAR_KIND_F32_ARR,
239 U_VAR_KIND_TIMING,
240 U_VAR_KIND_VEC3_I32,
241 U_VAR_KIND_VEC3_F32,
242 U_VAR_KIND_POSE,
243 U_VAR_KIND_SINK_DEBUG,
244 U_VAR_KIND_NATIVE_IMAGES_DEBUG,
245 U_VAR_KIND_LOG_LEVEL,
246 U_VAR_KIND_RO_TEXT,
247 U_VAR_KIND_RO_RAW_TEXT,
248 U_VAR_KIND_RO_I16,
249 U_VAR_KIND_RO_I32,
250 U_VAR_KIND_RO_U16,
251 U_VAR_KIND_RO_U32,
252 U_VAR_KIND_RO_F32,
253 U_VAR_KIND_RO_I64,
254 U_VAR_KIND_RO_U64,
255 U_VAR_KIND_RO_F64,
256 U_VAR_KIND_RO_I64_NS,
257 U_VAR_KIND_RO_VEC2_F32,
258 U_VAR_KIND_RO_VEC3_I32,
259 U_VAR_KIND_RO_VEC3_F32,
260 U_VAR_KIND_RO_VEC3_F64,
261 U_VAR_KIND_RO_QUAT_F32,
262 U_VAR_KIND_RO_FF_F64,
263 U_VAR_KIND_RO_FF_VEC3_F32,
264 U_VAR_KIND_GUI_HEADER,
265 U_VAR_KIND_GUI_HEADER_BEGIN,
266 U_VAR_KIND_GUI_HEADER_END,
267 U_VAR_KIND_GUI_SAMELINE,
268 U_VAR_KIND_BUTTON,
269 U_VAR_KIND_COMBO,
270 U_VAR_KIND_HISTOGRAM_F32,
271 U_VAR_KIND_DRAGGABLE_U16,
272 U_VAR_KIND_CURVE,
273 U_VAR_KIND_CURVES,
274};
275
276/*!
277 * Maximum string length for a tracked variable.
278 *
279 * @ingroup aux_util
280 */
281#define U_VAR_NAME_STRING_SIZE 256
282
283/*!
284 * Struct that keeps all of the information about the variable, some of the UI
285 * state is kept on it.
286 *
287 * @ingroup aux_util
288 */
290{
291 char name[U_VAR_NAME_STRING_SIZE];
292 void *ptr;
293
294 enum u_var_kind kind;
295
296 struct
297 {
298 bool graphed;
299 } gui;
300};
301
302/*!
303 * Struct containing the information about a root object.
304 *
305 * @ingroup aux_util
306 */
308{
309 //! The displayed name.
310 const char *name;
311
312 //! Raw name without any suffix.
313 const char *raw_name;
314
315 //! The number of the window, or zero (name and raw_name are the same).
316 uint32_t number;
317};
318
319/*!
320 * Callback for entering and leaving root nodes.
321 *
322 * @ingroup aux_util
323 */
324typedef void (*u_var_root_cb)(struct u_var_root_info *info, void *);
325
326/*!
327 * Callback on each variable a root node has.
328 *
329 * @ingroup aux_util
330 */
331typedef void (*u_var_elm_cb)(struct u_var_info *info, void *);
332
333/*!
334 * Add a named root object, the u_var subsystem is completely none-invasive
335 * to the object it's tracking. The root pointer is used as a entry into a
336 * hashmap of hidden objects. When not active all calls are stubs and have no
337 * side-effects.
338 *
339 * This is intended only for debugging and is turned off by default, as this all
340 * very very unsafe. It is only pointers straight into objects, completely
341 * ignores ownership or any safe practices.
342 *
343 * The parameter @p suffix_with_number makes the variable tracking code suffix
344 * the name of the object with with a number. This allows multiple objects of
345 * the same name name.
346 *
347 * ```c
348 * // On create
349 * u_var_add_root((void*)psmv, "PS Move Controller", true);
350 * u_var_add_rgb_u8((void*)psmv, &psmv->led_color, "LED");
351 * u_var_add_log_level(psmv, &psmv->log_level, "Log level");
352 *
353 * // On destroy, only need to destroy the root object.
354 * u_var_remove_root((void*)psmv);
355 * ```
356 *
357 * @param root Object to be tracked.
358 * @param c_name Name of object, null terminated "C" string.
359 * @param suffix_with_number Should name be suffixed with a number.
360 *
361 * @ingroup aux_util
362 */
363void
364u_var_add_root(void *root, const char *c_name, bool suffix_with_number);
365
366/*!
367 * Remove the root node.
368 *
369 * @ingroup aux_util
370 */
371void
373
374/*!
375 * Visit all root nodes and their variables.
376 *
377 * @ingroup aux_util
378 */
379void
380u_var_visit(u_var_root_cb enter_cb, u_var_root_cb exit_cb, u_var_elm_cb elem_cb, void *priv);
381
382/*!
383 * This forces the variable tracking code to on, it is disabled by default.
384 *
385 * @ingroup aux_util
386 */
387void
389
390#define U_VAR_ADD_FUNCS() \
391 ADD_FUNC(bool, bool, BOOL) \
392 ADD_FUNC(rgb_u8, struct xrt_colour_rgb_u8, RGB_U8) \
393 ADD_FUNC(rgb_f32, struct xrt_colour_rgb_f32, RGB_F32) \
394 ADD_FUNC(u8, uint8_t, U8) \
395 ADD_FUNC(u16, uint16_t, U16) \
396 ADD_FUNC(u16_arr, struct u_var_u16_arr, U16_ARR) \
397 ADD_FUNC(u64, uint64_t, U64) \
398 ADD_FUNC(i32, int32_t, I32) \
399 ADD_FUNC(i64, int64_t, I64) \
400 ADD_FUNC(f32, float, F32) \
401 ADD_FUNC(f64, double, F64) \
402 ADD_FUNC(f32_arr, struct u_var_f32_arr, F32_ARR) \
403 ADD_FUNC(f32_timing, struct u_var_timing, TIMING) \
404 ADD_FUNC(vec3_i32, struct xrt_vec3_i32, VEC3_I32) \
405 ADD_FUNC(vec3_f32, struct xrt_vec3, VEC3_F32) \
406 ADD_FUNC(pose, struct xrt_pose, POSE) \
407 ADD_FUNC(sink_debug, struct u_sink_debug, SINK_DEBUG) \
408 ADD_FUNC(native_images_debug, struct u_native_images_debug, NATIVE_IMAGES_DEBUG) \
409 ADD_FUNC(log_level, enum u_logging_level, LOG_LEVEL) \
410 ADD_FUNC(ro_text, const char, RO_TEXT) \
411 ADD_FUNC(ro_raw_text, const char, RO_RAW_TEXT) \
412 ADD_FUNC(ro_i16, int16_t, RO_I16) \
413 ADD_FUNC(ro_i32, int32_t, RO_I32) \
414 ADD_FUNC(ro_u16, uint16_t, RO_U16) \
415 ADD_FUNC(ro_u32, uint32_t, RO_U32) \
416 ADD_FUNC(ro_f32, float, RO_F32) \
417 ADD_FUNC(ro_i64, int64_t, RO_I64) \
418 ADD_FUNC(ro_u64, uint64_t, RO_U64) \
419 ADD_FUNC(ro_f64, double, RO_F64) \
420 ADD_FUNC(ro_i64_ns, int64_t, RO_I64_NS) \
421 ADD_FUNC(ro_vec2_f32, struct xrt_vec2, RO_VEC2_F32) \
422 ADD_FUNC(ro_vec3_i32, struct xrt_vec3_i32, RO_VEC3_I32) \
423 ADD_FUNC(ro_vec3_f32, struct xrt_vec3, RO_VEC3_F32) \
424 ADD_FUNC(ro_vec3_f64, struct xrt_vec3_f64, RO_VEC3_F64) \
425 ADD_FUNC(ro_quat_f32, struct xrt_quat, RO_QUAT_F32) \
426 ADD_FUNC(ro_ff_f64, struct m_ff_f64, RO_FF_F64) \
427 ADD_FUNC(ro_ff_vec3_f32, struct m_ff_vec3_f32, RO_FF_VEC3_F32) \
428 ADD_FUNC(gui_header, bool, GUI_HEADER) \
429 ADD_FUNC(gui_header_begin, bool, GUI_HEADER_BEGIN) \
430 ADD_FUNC(gui_header_end, bool, GUI_HEADER_END) \
431 ADD_FUNC(gui_sameline, void, GUI_SAMELINE) \
432 ADD_FUNC(button, struct u_var_button, BUTTON) \
433 ADD_FUNC(combo, struct u_var_combo, COMBO) \
434 ADD_FUNC(draggable_f32, struct u_var_draggable_f32, DRAGGABLE_F32) \
435 ADD_FUNC(draggable_u16, struct u_var_draggable_u16, DRAGGABLE_U16) \
436 ADD_FUNC(histogram_f32, struct u_var_histogram_f32, HISTOGRAM_F32) \
437 ADD_FUNC(curve, struct u_var_curve, CURVE) \
438 ADD_FUNC(curves, struct u_var_curves, CURVES)
439
440#define ADD_FUNC(SUFFIX, TYPE, ENUM) void u_var_add_##SUFFIX(void *, TYPE *, const char *);
441
442U_VAR_ADD_FUNCS()
443
444#undef ADD_FUNC
445
446
447#ifdef __cplusplus
448}
449#endif
void u_var_add_root(void *root, const char *c_name, bool suffix_with_number)
Add a named root object, the u_var subsystem is completely none-invasive to the object it's tracking.
void(* u_var_button_cb)(void *)
Callback for a button action.
Definition u_var.h:78
void(* u_var_root_cb)(struct u_var_root_info *info, void *)
Callback for entering and leaving root nodes.
Definition u_var.h:324
#define U_VAR_NAME_STRING_SIZE
Maximum string length for a tracked variable.
Definition u_var.h:281
void u_var_visit(u_var_root_cb enter_cb, u_var_root_cb exit_cb, u_var_elm_cb elem_cb, void *priv)
Visit all root nodes and their variables.
void u_var_force_on(void)
This forces the variable tracking code to on, it is disabled by default.
void u_var_remove_root(void *root)
Remove the root node.
struct u_var_curve_point(* u_var_curve_getter)(void *data, int i)
Callback for getting points on a curve.
Definition u_var.h:187
u_var_kind
What kind of variable is this tracking.
Definition u_var.h:225
void(* u_var_elm_cb)(struct u_var_info *info, void *)
Callback on each variable a root node has.
Definition u_var.h:331
Definition m_filter_fifo.c:198
Definition m_filter_fifo.c:23
A struct for debugging one or more native images.
Definition u_native_images_debug.h:27
Allows more safely to debug sink inputs and outputs.
Definition u_sink.h:214
Simple pushable button.
Definition u_var.h:86
bool disabled
Whether this button is disabled.
Definition u_var.h:108
char label[64]
Button text, use var name if zeroed.
Definition u_var.h:101
xrt_atomic_s32_t downed
Is the pointer pressing down on the button curruently, this is not edge triggered like the callback.
Definition u_var.h:98
u_var_button_cb cb
Callback function to execute on button press.
Definition u_var.h:88
void * ptr
Pointer that will be passed to the function as its only argument.
Definition u_var.h:91
float width
Button dimensions, zero for auto size.
Definition u_var.h:104
Combo box information.
Definition u_var.h:117
int count
Number of options.
Definition u_var.h:119
int * value
Pointer to the option value.
Definition u_var.h:125
const char * options
List of count option names separated by \0.
Definition u_var.h:122
A point on the curve, uses doubles like ImPlotPoint.
Definition u_var.h:177
A single curve on a plot.
Definition u_var.h:195
const char * ylabel
Label of the Y axis.
Definition u_var.h:201
int count
Number of points to draw; param i < count.
Definition u_var.h:198
const char * xlabel
Label of the X axis.
Definition u_var.h:200
void * data
User data for getter
Definition u_var.h:197
const char * label
Curve name.
Definition u_var.h:199
u_var_curve_getter getter
Getter of 2D points for the curve.
Definition u_var.h:196
A collection of curves to be plotted.
Definition u_var.h:210
const char * ylabel
Label of the Y axis.
Definition u_var.h:216
const char * xlabel
Label of the X axis.
Definition u_var.h:215
Draggable single precision float information.
Definition u_var.h:134
Draggable usingned 16-bit integer information.
Definition u_var.h:147
uint16_t * val
Definition u_var.h:152
Used to plot an array for values.
Definition u_var.h:35
Histogram based on single precision bars.
Definition u_var.h:164
float height
Widget height or 0 for auto.
Definition u_var.h:168
float width
Widget width or 0 for auto.
Definition u_var.h:167
int count
Number of bins.
Definition u_var.h:166
float * values
Bin heights.
Definition u_var.h:165
Struct that keeps all of the information about the variable, some of the UI state is kept on it.
Definition u_var.h:290
Struct containing the information about a root object.
Definition u_var.h:308
uint32_t number
The number of the window, or zero (name and raw_name are the same).
Definition u_var.h:316
const char * name
The displayed name.
Definition u_var.h:310
const char * raw_name
Raw name without any suffix.
Definition u_var.h:313
Used to plot a graph of timing information.
Definition u_var.h:53
float range
How many units the graph expands by default.
Definition u_var.h:64
bool center_reference_timing
If false, reference_timing will be the bottom of the graph.
Definition u_var.h:61
bool dynamic_rescale
Rescale graph's value range when value exceeds range.
Definition u_var.h:67
float reference_timing
A reference line drawn on the plot.
Definition u_var.h:58
struct u_var_f32_arr values
Values to be plotted.
Definition u_var.h:55
const char * unit
A string describing the unit used, not freed.
Definition u_var.h:70
Definition u_var.h:42
A object that is sent frames.
Definition xrt_frame.h:58
Basic logging functionality.
Common defines and enums for XRT.