The open source OpenXR runtime
at main 209 lines 5.7 kB view raw
1// Copyright 2019-2024, Collabora, Ltd. 2// SPDX-License-Identifier: BSL-1.0 3/*! 4 * @file 5 * @brief Re-assemble a collection of composition layers submitted for a frame. 6 * 7 * @author Rylie Pavlik <rylie.pavlik@collabora.com> 8 * @author Jakob Bornecrantz <jakob@collabora.com> 9 * @author Lubosz Sarnecki <lubosz.sarnecki@collabora.com> 10 * @ingroup comp_util 11 */ 12 13#pragma once 14 15#include "xrt/xrt_compositor.h" 16#include "xrt/xrt_limits.h" 17#include "xrt/xrt_results.h" 18#include <assert.h> 19#include <stdint.h> 20 21#ifdef __cplusplus 22extern "C" { 23#endif 24 25struct xrt_swapchain; 26 27/*! 28 * A single layer in a @ref comp_layer_accum. 29 * 30 * Independent of graphics API, swapchain implementation, etc. 31 * 32 * @ingroup comp_util 33 * @see comp_layer_accum 34 */ 35struct comp_layer 36{ 37 /*! 38 * Up to two compositor swapchains referenced per view (color and depth) for a layer. 39 * 40 * Unused elements should be set to null. 41 */ 42 struct xrt_swapchain *sc_array[XRT_MAX_VIEWS * 2]; 43 44 /*! 45 * All basic (trivially-serializable) data associated with a layer. 46 */ 47 struct xrt_layer_data data; 48}; 49 50 51/*! 52 * Get a (color) swapchain associated with a layer. 53 * 54 * @param cl self 55 * @param swapchain_index index of swapchain - typically this is 0 for most layers, the view index for projection. 56 57 * @public @memberof comp_layer 58 */ 59struct xrt_swapchain * 60comp_layer_get_swapchain(const struct comp_layer *cl, uint32_t swapchain_index); 61 62 63/*! 64 * Get a depth swapchain associated with a (projection with depth) layer 65 * 66 * @param cl self 67 * @param swapchain_index index of **color** swapchain - typically this is the view index. 68 * 69 * @public @memberof comp_layer 70 */ 71struct xrt_swapchain * 72comp_layer_get_depth_swapchain(const struct comp_layer *cl, uint32_t swapchain_index); 73 74 75 76/*! 77 * Collect a stack of layers - one frame's worth. 78 * 79 * Independent of graphics API, swapchain implementation, etc. 80 * 81 * Used to turn the step by step "one call per layer" compositor API back 82 * into a single structure per frame. 83 * 84 * @ingroup comp_util 85 * @see comp_layer 86 */ 87struct comp_layer_accum 88{ 89 //! The per frame data, supplied by `begin`. 90 struct xrt_layer_frame_data data; 91 92 //! All of the layers. 93 struct comp_layer layers[XRT_MAX_LAYERS]; 94 95 //! Number of submitted layers. 96 uint32_t layer_count; 97}; 98 99/*! 100 * Reset all layer data and reset count to 0. 101 * 102 * Call at the beginning of a frame. 103 * 104 * @public @memberof comp_layer_accum 105 */ 106xrt_result_t 107comp_layer_accum_begin(struct comp_layer_accum *cla, const struct xrt_layer_frame_data *data); 108 109/*! 110 * Accumulate swapchains and data for a projection layer for a frame. 111 * 112 * @public @memberof comp_layer_accum 113 */ 114xrt_result_t 115comp_layer_accum_projection(struct comp_layer_accum *cla, 116 struct xrt_swapchain *xsc[XRT_MAX_VIEWS], 117 const struct xrt_layer_data *data); 118 119/*! 120 * Accumulate swapchains and data for a projection layer (with depth image) for a frame. 121 * 122 * @public @memberof comp_layer_accum 123 */ 124xrt_result_t 125comp_layer_accum_projection_depth(struct comp_layer_accum *cla, 126 struct xrt_swapchain *xsc[XRT_MAX_VIEWS], 127 struct xrt_swapchain *d_xsc[XRT_MAX_VIEWS], 128 const struct xrt_layer_data *data); 129/*! 130 * Accumulate swapchain and data for a quad layer for a frame. 131 * 132 * @public @memberof comp_layer_accum 133 */ 134xrt_result_t 135comp_layer_accum_quad(struct comp_layer_accum *cla, struct xrt_swapchain *xsc, const struct xrt_layer_data *data); 136 137 138/*! 139 * Accumulate swapchain and data for a cube layer for a frame. 140 * 141 * @public @memberof comp_layer_accum 142 */ 143xrt_result_t 144comp_layer_accum_cube(struct comp_layer_accum *cla, struct xrt_swapchain *xsc, const struct xrt_layer_data *data); 145 146 147/*! 148 * Accumulate swapchain and data for a cylinder layer for a frame. 149 * 150 * @public @memberof comp_layer_accum 151 */ 152xrt_result_t 153comp_layer_accum_cylinder(struct comp_layer_accum *cla, struct xrt_swapchain *xsc, const struct xrt_layer_data *data); 154 155 156/*! 157 * Accumulate swapchain and data for an equirect(1) layer for a frame. 158 * 159 * @public @memberof comp_layer_accum 160 */ 161xrt_result_t 162comp_layer_accum_equirect1(struct comp_layer_accum *cla, struct xrt_swapchain *xsc, const struct xrt_layer_data *data); 163 164 165/*! 166 * Accumulate swapchain and data for an equirect2 layer for a frame. 167 * 168 * @public @memberof comp_layer_accum 169 */ 170xrt_result_t 171comp_layer_accum_equirect2(struct comp_layer_accum *cla, struct xrt_swapchain *xsc, const struct xrt_layer_data *data); 172 173 174/*! 175 * Get a (color) swapchain associated with a layer. 176 * 177 * @param cla self 178 * @param layer_index index of layer 179 * @param swapchain_index index of swapchain - typically this is 0 for most layers, the view index for projection. 180 181 * @public @memberof comp_layer_accum 182 */ 183inline struct xrt_swapchain * 184comp_layer_accum_get_swapchain(const struct comp_layer_accum *cla, uint32_t layer_index, uint32_t swapchain_index) 185{ 186 assert(layer_index < cla->layer_count); 187 return cla->layers[layer_index].sc_array[swapchain_index]; 188} 189 190/*! 191 * Get a depth swapchain associated with a (projection with depth) layer 192 * 193 * @param cla self 194 * @param layer_index index of layer 195 * @param swapchain_index index of **color** swapchain - typically this is the view index. 196 * 197 * @public @memberof comp_layer_accum 198 */ 199inline struct xrt_swapchain * 200comp_layer_accum_get_depth_swapchain(const struct comp_layer_accum *cla, uint32_t layer_index, uint32_t swapchain_index) 201{ 202 assert(layer_index < cla->layer_count); 203 assert(cla->layers[layer_index].data.type == XRT_LAYER_PROJECTION_DEPTH); 204 return cla->layers[layer_index].sc_array[XRT_MAX_VIEWS + swapchain_index]; 205} 206 207#ifdef __cplusplus 208} 209#endif