The open source OpenXR runtime

ipc: Refactor native compositor creation

+65 -30
+23 -1
src/xrt/ipc/client/ipc_client.h
··· 202 202 /*! 203 203 * Create an IPC client system compositor. 204 204 * 205 + * It owns a special implementation of the @ref xrt_system_compositor interface. 206 + * 207 + * This actually creates an IPC client "native" compositor with deferred 208 + * initialization. The @ref ipc_client_create_native_compositor function 209 + * actually completes the deferred initialization of the compositor, effectively 210 + * finishing creation of a compositor IPC proxy. 211 + * 205 212 * @param ipc_c IPC connection 206 213 * @param xina Optional native image allocator for client-side allocation. Takes 207 214 * ownership if one is supplied. 208 215 * @param xdev Taken in but not used currently @todo remove this param? 209 216 * @param[out] out_xcs Pointer to receive the created xrt_system_compositor. 210 217 */ 211 - int 218 + xrt_result_t 212 219 ipc_client_create_system_compositor(struct ipc_connection *ipc_c, 213 220 struct xrt_image_native_allocator *xina, 214 221 struct xrt_device *xdev, 215 222 struct xrt_system_compositor **out_xcs); 223 + 224 + /*! 225 + * Create a native compositor from a system compositor, this is used instead 226 + * of the normal xrt_system_compositor::create_native_compositor function 227 + * because it doesn't support events being generated on the app side. This will 228 + * also create the session on the service side. 229 + * 230 + * @param xsysc IPC created system compositor. 231 + * @param xsi Session information struct. 232 + * @param[out] out_xcn Pointer to receive the created xrt_compositor_native. 233 + */ 234 + xrt_result_t 235 + ipc_client_create_native_compositor(struct xrt_system_compositor *xsysc, 236 + const struct xrt_session_info *xsi, 237 + struct xrt_compositor_native **out_xcn); 216 238 217 239 struct xrt_device * 218 240 ipc_client_hmd_create(struct ipc_connection *ipc_c, struct xrt_tracking_origin *xtrack, uint32_t device_id);
+28 -24
src/xrt/ipc/client/ipc_client_compositor.c
··· 993 993 struct ipc_client_compositor *icc = container_of(xsc, struct ipc_client_compositor, system); 994 994 xrt_result_t xret; 995 995 996 - if (icc->compositor_created) { 997 - return XRT_ERROR_MULTI_SESSION_NOT_IMPLEMENTED; 998 - } 999 - 1000 - // Needs to be done before init. 1001 - xret = ipc_call_session_create(icc->ipc_c, xsi); 1002 - IPC_CHK_AND_RET(icc->ipc_c, xret, "ipc_call_session_create"); 1003 - 1004 - // Needs to be done after session create call. 1005 - ipc_compositor_init(icc, out_xcn); 1006 - 1007 - icc->compositor_created = true; 1008 - 1009 - return XRT_SUCCESS; 996 + xret = ipc_client_create_native_compositor(xsc, xsi, out_xcn); 997 + IPC_CHK_ALWAYS_RET(icc->ipc_c, xret, "ipc_client_create_native_compositor"); 1010 998 } 1011 999 1012 1000 void ··· 1030 1018 * 1031 1019 */ 1032 1020 1033 - /*! 1034 - * 1035 - * 1036 - * This actually creates an IPC client "native" compositor with deferred initialization. 1037 - * It owns a special implementation of the @ref xrt_system_compositor interface 1038 - * whose "create_native_compositor" method actually completes the deferred initialization 1039 - * of the compositor, effectively finishing creation of a compositor IPC proxy. 1040 - */ 1041 - int 1021 + xrt_result_t 1022 + ipc_client_create_native_compositor(struct xrt_system_compositor *xsysc, 1023 + const struct xrt_session_info *xsi, 1024 + struct xrt_compositor_native **out_xcn) 1025 + { 1026 + struct ipc_client_compositor *icc = container_of(xsysc, struct ipc_client_compositor, system); 1027 + xrt_result_t xret; 1028 + 1029 + if (icc->compositor_created) { 1030 + return XRT_ERROR_MULTI_SESSION_NOT_IMPLEMENTED; 1031 + } 1032 + 1033 + // Needs to be done before init. 1034 + xret = ipc_call_session_create(icc->ipc_c, xsi); 1035 + IPC_CHK_AND_RET(icc->ipc_c, xret, "ipc_call_session_create"); 1036 + 1037 + // Needs to be done after session create call. 1038 + ipc_compositor_init(icc, out_xcn); 1039 + 1040 + icc->compositor_created = true; 1041 + 1042 + return XRT_SUCCESS; 1043 + } 1044 + 1045 + xrt_result_t 1042 1046 ipc_client_create_system_compositor(struct ipc_connection *ipc_c, 1043 1047 struct xrt_image_native_allocator *xina, 1044 1048 struct xrt_device *xdev, ··· 1067 1071 1068 1072 *out_xcs = &c->system; 1069 1073 1070 - return 0; 1074 + return XRT_SUCCESS; 1071 1075 }
+14 -5
src/xrt/ipc/client/ipc_client_instance.c
··· 95 95 { 96 96 struct xrt_system_compositor *xsysc = NULL; 97 97 struct xrt_image_native_allocator *xina = NULL; 98 + xrt_result_t xret; 98 99 99 100 #ifdef XRT_GRAPHICS_BUFFER_HANDLE_IS_AHARDWAREBUFFER 100 101 // On Android, we allocate images natively on the client side. 101 102 xina = android_ahardwarebuffer_allocator_create(); 102 103 #endif // XRT_GRAPHICS_BUFFER_HANDLE_IS_AHARDWAREBUFFER 103 104 104 - int ret = ipc_client_create_system_compositor(&ii->ipc_c, xina, xdev, &xsysc); 105 - if (ret < 0 || xsysc == NULL) { 106 - xrt_images_destroy(&xina); 107 - return XRT_ERROR_IPC_FAILURE; 105 + xret = ipc_client_create_system_compositor(&ii->ipc_c, xina, xdev, &xsysc); 106 + IPC_CHK_WITH_GOTO(&ii->ipc_c, xret, "ipc_client_create_system_compositor", err_xina); 107 + 108 + // Paranoia. 109 + if (xsysc == NULL) { 110 + xret = XRT_ERROR_IPC_FAILURE; 111 + IPC_ERROR(&ii->ipc_c, "Variable xsysc NULL!"); 112 + goto err_xina; 108 113 } 109 114 110 115 *out_xsysc = xsysc; 111 116 112 - return 0; 117 + return XRT_SUCCESS; 118 + 119 + err_xina: 120 + xrt_images_destroy(&xina); 121 + return xret; 113 122 } 114 123 115 124