Monado OpenXR Runtime
Loading...
Searching...
No Matches
u_native_images_debug.h
Go to the documentation of this file.
1// Copyright 2023-2024, Collabora, Ltd.
2// Copyright 2026, NVIDIA CORPORATION.
3// SPDX-License-Identifier: BSL-1.0
4/*!
5 * @file
6 * @brief Special code for managing a variable tracked swapchain.
7 * @author Jakob Bornecrantz <jakob@collabora.com>
8 * @ingroup aux_util
9 */
10
11#pragma once
12
13#include "os/os_threading.h"
14#include "xrt/xrt_compositor.h"
15
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
21
22/*!
23 * A struct for debugging one or more native images.
24 *
25 * @ingroup aux_util
26 */
28{
29 //! Is initialised/destroyed when added or root is removed.
31
32 /*!
33 * Process unique id for the set of images, protected by @p mutex,
34 * allows caching of imports. Created by @ref u_limited_unique_id_get.
35 */
37
38 //! List to current set of native images, protected by @p mutex.
40
41 //! Count of @p native_images, protected by @p mutex.
43
44 /*!
45 * Information needed to import the native images, information in the
46 * struct is immutable, the pointer is protected by @p mutex.
47 */
49
50 /*!
51 * The native image that was last filled in by the source, only
52 * valid if @p native_images is non-null, protected by @p mutex.
53 */
54 uint32_t active_index;
55
56 //! Should the image be flipped in y direction.
57 bool flip_y;
58};
59
60/*!
61 * Must be called before variable is tracked.
62 *
63 * @ingroup aux_util
64 */
65static inline void
67{
68 os_mutex_init(&unid->mutex);
69}
70
71/*!
72 * Must not be called while variable longer tracked, after @p u_var_remove_root.
73 *
74 * @ingroup aux_util
75 */
76static inline void
78{
79 os_mutex_destroy(&unid->mutex);
80 unid->native_images = NULL;
81 unid->native_image_count = 0;
82 unid->xscci = NULL;
83 unid->active_index = 0;
84 unid->flip_y = false;
85}
86
87/*!
88 * Simple lock helper.
89 *
90 * @ingroup aux_util
91 */
92static inline void
94{
95 os_mutex_lock(&unid->mutex);
96}
97
98/*!
99 * Simple lock helper.
100 *
101 * @ingroup aux_util
102 */
103static inline void
105{
106 os_mutex_unlock(&unid->mutex);
107}
108
109/*!
110 * Helper function to update all variables, must be called with the lock held.
111 *
112 * @ingroup aux_util
113 */
114static inline void
116 xrt_limited_unique_id_t limited_unique_id,
117 struct xrt_image_native *native_images,
118 uint32_t native_image_count,
119 const struct xrt_swapchain_create_info *xscci,
120 uint32_t active_index,
121 bool flip_y)
122{
123 unid->limited_unique_id = limited_unique_id;
124 unid->native_images = native_images;
125 unid->native_image_count = native_image_count;
126 unid->active_index = active_index;
127 unid->xscci = xscci;
128 unid->flip_y = flip_y;
129}
130
131/*!
132 * Updates all variables atomically by holding the lock.
133 *
134 * @ingroup aux_util
135 */
136static inline void
138 xrt_limited_unique_id_t limited_unique_id,
139 struct xrt_image_native *native_images,
140 uint32_t native_image_count,
141 const struct xrt_swapchain_create_info *xscci,
142 uint32_t active_index,
143 bool flip_y)
144{
147 unid, //
148 limited_unique_id, //
149 native_images, //
150 native_image_count, //
151 xscci, //
152 active_index, //
153 flip_y); //
155}
156
157/*!
158 * Clear all variables, must be called with the lock held.
159 *
160 * @ingroup aux_util
161 */
162static inline void
164{
165 unid->limited_unique_id.data = 0;
166 unid->xscci = NULL;
167 unid->active_index = 0;
168 unid->native_images = NULL;
169 unid->native_image_count = 0;
170}
171
172/*!
173 * Clear all variables atomically by holding the lock, still valid to use.
174 *
175 * @ingroup aux_util
176 */
177static inline void
184
185
186#ifdef __cplusplus
187}
188#endif
static void u_native_images_debug_set_locked(struct u_native_images_debug *unid, xrt_limited_unique_id_t limited_unique_id, struct xrt_image_native *native_images, uint32_t native_image_count, const struct xrt_swapchain_create_info *xscci, uint32_t active_index, bool flip_y)
Helper function to update all variables, must be called with the lock held.
Definition u_native_images_debug.h:115
static void u_native_images_debug_clear(struct u_native_images_debug *unid)
Clear all variables atomically by holding the lock, still valid to use.
Definition u_native_images_debug.h:178
static void u_native_images_debug_unlock(struct u_native_images_debug *unid)
Simple lock helper.
Definition u_native_images_debug.h:104
static void u_native_images_debug_lock(struct u_native_images_debug *unid)
Simple lock helper.
Definition u_native_images_debug.h:93
static void u_native_images_debug_clear_locked(struct u_native_images_debug *unid)
Clear all variables, must be called with the lock held.
Definition u_native_images_debug.h:163
static void u_native_images_debug_set(struct u_native_images_debug *unid, xrt_limited_unique_id_t limited_unique_id, struct xrt_image_native *native_images, uint32_t native_image_count, const struct xrt_swapchain_create_info *xscci, uint32_t active_index, bool flip_y)
Updates all variables atomically by holding the lock.
Definition u_native_images_debug.h:137
static void u_native_images_debug_init(struct u_native_images_debug *unid)
Must be called before variable is tracked.
Definition u_native_images_debug.h:66
static void u_native_images_debug_destroy(struct u_native_images_debug *unid)
Must not be called while variable longer tracked, after u_var_remove_root.
Definition u_native_images_debug.h:77
Wrapper around OS threading native functions.
A wrapper around a native mutex.
Definition os_threading.h:69
A struct for debugging one or more native images.
Definition u_native_images_debug.h:28
uint32_t active_index
The native image that was last filled in by the source, only valid if native_images is non-null,...
Definition u_native_images_debug.h:54
struct os_mutex mutex
Is initialised/destroyed when added or root is removed.
Definition u_native_images_debug.h:30
struct xrt_image_native * native_images
List to current set of native images, protected by mutex.
Definition u_native_images_debug.h:39
const struct xrt_swapchain_create_info * xscci
Information needed to import the native images, information in the struct is immutable,...
Definition u_native_images_debug.h:48
bool flip_y
Should the image be flipped in y direction.
Definition u_native_images_debug.h:57
xrt_limited_unique_id_t limited_unique_id
Process unique id for the set of images, protected by mutex, allows caching of imports.
Definition u_native_images_debug.h:36
uint32_t native_image_count
Count of native_images, protected by mutex.
Definition u_native_images_debug.h:42
A single image of a swapchain based on native buffer handles.
Definition xrt_compositor.h:2186
A limited unique id, it is only unique for the process it is in, so must not be used or synchronized ...
Definition xrt_defines.h:82
Swapchain creation info.
Definition xrt_compositor.h:895
Header declaring XRT graphics interfaces.