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