The open source OpenXR runtime
at prediction-2 158 lines 4.8 kB view raw
1// Copyright 2020-2023, Collabora, Ltd. 2// Copyright 2025, NVIDIA CORPORATION. 3// SPDX-License-Identifier: BSL-1.0 4/*! 5 * @file 6 * @brief Common client side code. 7 * @author Pete Black <pblack@collabora.com> 8 * @author Jakob Bornecrantz <jakob@collabora.com> 9 * @author Korcan Hussein <korcan.hussein@collabora.com> 10 * @ingroup ipc_client 11 */ 12 13#pragma once 14 15#include "xrt/xrt_compiler.h" 16#include "xrt/xrt_config_os.h" 17 18#include "util/u_threading.h" 19#include "util/u_logging.h" 20#include "util/u_system_helpers.h" 21 22#include "shared/ipc_utils.h" 23#include "shared/ipc_protocol.h" 24#include "shared/ipc_message_channel.h" 25 26#include <stdio.h> 27 28 29/* 30 * 31 * Logging 32 * 33 */ 34 35#define IPC_TRACE(IPC_C, ...) U_LOG_IFL_T((IPC_C)->imc.log_level, __VA_ARGS__) 36#define IPC_DEBUG(IPC_C, ...) U_LOG_IFL_D((IPC_C)->imc.log_level, __VA_ARGS__) 37#define IPC_INFO(IPC_C, ...) U_LOG_IFL_I((IPC_C)->imc.log_level, __VA_ARGS__) 38#define IPC_WARN(IPC_C, ...) U_LOG_IFL_W((IPC_C)->imc.log_level, __VA_ARGS__) 39#define IPC_ERROR(IPC_C, ...) U_LOG_IFL_E((IPC_C)->imc.log_level, __VA_ARGS__) 40 41#define IPC_CHK_AND_RET(IPC_C, ...) U_LOG_CHK_AND_RET((IPC_C)->imc.log_level, __VA_ARGS__) 42#define IPC_CHK_WITH_GOTO(IPC_C, ...) U_LOG_CHK_WITH_GOTO((IPC_C)->imc.log_level, __VA_ARGS__) 43#define IPC_CHK_WITH_RET(IPC_C, ...) U_LOG_CHK_WITH_RET((IPC_C)->imc.log_level, __VA_ARGS__) 44#define IPC_CHK_ONLY_PRINT(IPC_C, ...) U_LOG_CHK_ONLY_PRINT((IPC_C)->imc.log_level, __VA_ARGS__) 45#define IPC_CHK_ALWAYS_RET(IPC_C, ...) U_LOG_CHK_ALWAYS_RET((IPC_C)->imc.log_level, __VA_ARGS__) 46 47 48/* 49 * 50 * Structs 51 * 52 */ 53 54struct xrt_compositor_native; 55 56 57/*! 58 * Connection. 59 */ 60struct ipc_connection 61{ 62 struct ipc_message_channel imc; 63 64 struct ipc_shared_memory *ism; 65 xrt_shmem_handle_t ism_handle; 66 67 struct os_mutex mutex; 68 69#ifdef XRT_OS_ANDROID 70 struct ipc_client_android *ica; 71#endif // XRT_OS_ANDROID 72}; 73 74/*! 75 * Client side implementation of the system devices struct. 76 */ 77struct ipc_client_system_devices 78{ 79 //! @public Base 80 struct u_system_devices base; 81 82 //! Connection to service. 83 struct ipc_connection *ipc_c; 84 85 struct xrt_tracking_origin *xtracks[XRT_SYSTEM_MAX_DEVICES]; 86 87 size_t xtrack_count; 88 89 struct xrt_reference feature_use[XRT_DEVICE_FEATURE_MAX_ENUM]; 90}; 91 92 93/* 94 * 95 * Internal functions. 96 * 97 */ 98 99/*! 100 * Create an IPC client system compositor. 101 * 102 * It owns a special implementation of the @ref xrt_system_compositor interface. 103 * 104 * This actually creates an IPC client "native" compositor with deferred 105 * initialization. The @ref ipc_client_create_native_compositor function 106 * actually completes the deferred initialization of the compositor, effectively 107 * finishing creation of a compositor IPC proxy. 108 * 109 * @param ipc_c IPC connection 110 * @param xina Optional native image allocator for client-side allocation. Takes 111 * ownership if one is supplied. 112 * @param xdev Taken in but not used currently @todo remove this param? 113 * @param[out] out_xcs Pointer to receive the created xrt_system_compositor. 114 */ 115xrt_result_t 116ipc_client_create_system_compositor(struct ipc_connection *ipc_c, 117 struct xrt_image_native_allocator *xina, 118 struct xrt_device *xdev, 119 struct xrt_system_compositor **out_xcs); 120 121/*! 122 * Create a native compositor from a system compositor, this is used instead 123 * of the normal xrt_system_compositor::create_native_compositor function 124 * because it doesn't support events being generated on the app side. This will 125 * also create the session on the service side. 126 * 127 * @param xsysc IPC created system compositor. 128 * @param xsi Session information struct. 129 * @param[out] out_xcn Pointer to receive the created xrt_compositor_native. 130 */ 131xrt_result_t 132ipc_client_create_native_compositor(struct xrt_system_compositor *xsysc, 133 const struct xrt_session_info *xsi, 134 struct xrt_compositor_native **out_xcn); 135 136struct xrt_device * 137ipc_client_hmd_create(struct ipc_connection *ipc_c, struct xrt_tracking_origin *xtrack, uint32_t device_id); 138 139struct xrt_device * 140ipc_client_device_create(struct ipc_connection *ipc_c, struct xrt_tracking_origin *xtrack, uint32_t device_id); 141 142struct xrt_system * 143ipc_client_system_create(struct ipc_connection *ipc_c, struct xrt_system_compositor *xsysc); 144 145struct xrt_space_overseer * 146ipc_client_space_overseer_create(struct ipc_connection *ipc_c); 147 148uint32_t 149ipc_client_space_get_id(struct xrt_space *space); 150 151struct ipc_client_system_devices * 152ipc_client_system_devices_create(struct ipc_connection *ipc_c); 153 154struct xrt_session * 155ipc_client_session_create(struct ipc_connection *ipc_c); 156 157struct xrt_future * 158ipc_client_future_create(struct ipc_connection *ipc_c, uint32_t future_id);