The open source OpenXR runtime
at main 93 lines 1.7 kB view raw
1// Copyright 2020-2024, Collabora, Ltd. 2// SPDX-License-Identifier: BSL-1.0 3/*! 4 * @file 5 * @brief Shared default implementation of the instance: pieces that are used 6 * whether or not there's a compositor. 7 * @author Jakob Bornecrantz <jakob@collabora.com> 8 * @author Rylie Pavlik <rylie.pavlik@collabora.com> 9 */ 10#pragma once 11 12#include "target_lists.h" 13 14#include "xrt/xrt_prober.h" 15#include "xrt/xrt_instance.h" 16#include "xrt/xrt_config_os.h" 17#ifdef XRT_OS_ANDROID 18#include "xrt/xrt_android.h" 19#endif // XRT_OS_ANDROID 20 21#include "util/u_misc.h" 22#include "util/u_trace_marker.h" 23 24#ifdef XRT_OS_ANDROID 25#include "android/android_instance_base.h" 26#endif 27 28/* 29 * 30 * Struct and helpers. 31 * 32 */ 33 34/*! 35 * Main "real" instance implementation. 36 * 37 * Used in instances both with and without compositor usage. 38 * 39 * @implements xrt_instance 40 */ 41struct t_instance 42{ 43 struct xrt_instance base; 44 struct xrt_prober *xp; 45#ifdef XRT_OS_ANDROID 46 struct android_instance_base android; 47#endif 48}; 49 50static inline struct t_instance * 51t_instance(struct xrt_instance *xinst) 52{ 53 return (struct t_instance *)xinst; 54} 55 56 57/* 58 * 59 * Member functions. 60 * 61 */ 62 63static xrt_result_t 64t_instance_get_prober(struct xrt_instance *xinst, struct xrt_prober **out_xp) 65{ 66 XRT_TRACE_MARKER(); 67 68 struct t_instance *tinst = t_instance(xinst); 69 70 if (tinst->xp == NULL) { 71 return XRT_ERROR_PROBER_NOT_SUPPORTED; 72 } 73 74 *out_xp = tinst->xp; 75 76 return XRT_SUCCESS; 77} 78 79static void 80t_instance_destroy(struct xrt_instance *xinst) 81{ 82 XRT_TRACE_MARKER(); 83 84 struct t_instance *tinst = t_instance(xinst); 85 86 xrt_prober_destroy(&tinst->xp); 87 88#ifdef XRT_OS_ANDROID 89 android_instance_base_cleanup(&tinst->android, xinst); 90#endif // XRT_OS_ANDROID 91 92 free(tinst); 93}