Monado OpenXR Runtime
null_compositor.h
Go to the documentation of this file.
1// Copyright 2019-2022, Collabora, Ltd.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Header for null compositor.
6 *
7 * Based on src/xrt/compositor/main/comp_compositor.h
8 *
9 * @author Jakob Bornecrantz <jakob@collabora.com>
10 * @author Lubosz Sarnecki <lubosz.sarnecki@collabora.com>
11 * @author Rylie Pavlik <rylie.pavlik@collabora.com>
12 * @ingroup comp_null
13 */
14
15#pragma once
16
17#include "xrt/xrt_gfx_vk.h"
18#include "xrt/xrt_instance.h"
19
20#include "os/os_time.h"
21
22#include "util/u_threading.h"
23#include "util/u_logging.h"
24#include "util/u_pacing.h"
25
26#include "util/comp_base.h"
27
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33/*!
34 * @defgroup comp_null Null compositor
35 * @ingroup xrt
36 * @brief A non-rendering alternate for the main compositor that still can
37 * support applications fully.
38 *
39 * Monado's design is highly modular, including allowing alternate compositors to
40 * be used. If you are looking to write an additional or alternate compositor to
41 * the one in `src/xrt/compositor/main`, this code is your starting point. It is
42 * the basic implementation of @ref xrt_compositor_native extracted from there,
43 * renamed, and with most implementations removed. Compare with similarly-named
44 * files there to see what was removed, and what helper functionality has been
45 * factored out and may be reusable. For example, you may be able to use @ref
46 * comp_renderer, @ref comp_resources, @ref comp_shaders, and @ref comp_target,
47 * among others.
48 */
49
50
51/*
52 *
53 * Structs, enums and defines.
54 *
55 */
56
57/*!
58 * Tracking frame state.
59 *
60 * @ingroup comp_null
61 */
63{
64 int64_t id;
65 uint64_t predicted_display_time_ns;
66 uint64_t desired_present_time_ns;
67 uint64_t present_slop_ns;
68};
69
70/*!
71 * Main compositor struct tying everything in the compositor together.
72 *
73 * This ultimately implements @ref xrt_compositor_native but does so by
74 * extending @ref comp_base, similar to how @ref comp_compositor works.
75 *
76 * @extends comp_base
77 * @ingroup comp_null
78 */
80{
81 struct comp_base base;
82
83 //! The device we are displaying to.
85
86 //! Pacing helper to drive us forward.
88
89 struct
90 {
91 enum u_logging_level log_level;
92
93 //! Frame interval that we are using.
95 } settings;
96
97 // Kept here for convenience.
98 struct xrt_system_compositor_info sys_info;
99
100 //! @todo Insert your own required members here
101
102 struct
103 {
104 struct null_comp_frame waited;
105 struct null_comp_frame rendering;
107};
108
109
110/*
111 *
112 * Functions and helpers.
113 *
114 */
115
116/*!
117 * Convenience function to convert a xrt_compositor to a null_compositor.
118 * (Down-cast helper.)
119 *
120 * @private @memberof null_compositor
121 * @ingroup comp_null
122 */
123static inline struct null_compositor *
125{
126 return (struct null_compositor *)xc;
127}
128
129/*!
130 * Spew level logging.
131 *
132 * @relates null_compositor
133 * @ingroup comp_null
134 */
135#define NULL_TRACE(c, ...) U_LOG_IFL_T(c->settings.log_level, __VA_ARGS__);
136
137/*!
138 * Debug level logging.
139 *
140 * @relates null_compositor
141 */
142#define NULL_DEBUG(c, ...) U_LOG_IFL_D(c->settings.log_level, __VA_ARGS__);
143
144/*!
145 * Info level logging.
146 *
147 * @relates null_compositor
148 * @ingroup comp_null
149 */
150#define NULL_INFO(c, ...) U_LOG_IFL_I(c->settings.log_level, __VA_ARGS__);
151
152/*!
153 * Warn level logging.
154 *
155 * @relates null_compositor
156 * @ingroup comp_null
157 */
158#define NULL_WARN(c, ...) U_LOG_IFL_W(c->settings.log_level, __VA_ARGS__);
159
160/*!
161 * Error level logging.
162 *
163 * @relates null_compositor
164 * @ingroup comp_null
165 */
166#define NULL_ERROR(c, ...) U_LOG_IFL_E(c->settings.log_level, __VA_ARGS__);
167
168
169#ifdef __cplusplus
170}
171#endif
Helper implementation for native compositors.
u_logging_level
Logging level enum.
Definition: u_logging.h:40
Wrapper around OS native time functions.
A simple compositor base that handles a lot of things for you.
Definition: comp_base.h:98
struct xrt_compositor_native base
Base native compositor.
Definition: comp_base.h:100
Tracking frame state.
Definition: null_compositor.h:63
Main compositor struct tying everything in the compositor together.
Definition: null_compositor.h:80
struct null_compositor::@85 frame
struct xrt_device * xdev
The device we are displaying to.
Definition: null_compositor.h:84
uint64_t frame_interval_ns
Frame interval that we are using.
Definition: null_compositor.h:94
struct u_pacing_compositor * upc
Pacing helper to drive us forward.
Definition: null_compositor.h:87
Compositor pacing helper interface.
Definition: u_pacing.h:68
Common compositor client interface/base.
Definition: xrt_compositor.h:986
A single HMD or input device.
Definition: xrt_device.h:230
Capabilities and information about the system compositor (and its wrapped native compositor,...
Definition: xrt_compositor.h:2295
Basic logging functionality.
Shared pacing code.
Slightly higher level thread safe helpers.
Header defining a XRT graphics provider.
Header for xrt_instance object.