The open source OpenXR runtime
1// Copyright 2020-2024, Collabora, Ltd.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Shared default implementation of the instance, but with no compositor
6 * usage
7 * @author Jakob Bornecrantz <jakob@collabora.com>
8 * @author Rylie Pavlik <rylie.pavlik@collabora.com>
9 */
10
11#include "xrt/xrt_system.h"
12#include "xrt/xrt_config_os.h"
13
14#include "util/u_system.h"
15#include "util/u_trace_marker.h"
16#include "util/u_system_helpers.h"
17
18#include "target_instance_parts.h"
19
20#include <assert.h>
21
22#ifdef XRT_OS_ANDROID
23#include "android/android_instance_base.h"
24#endif
25
26static xrt_result_t
27t_instance_create_system(struct xrt_instance *xinst,
28 struct xrt_system **out_xsys,
29 struct xrt_system_devices **out_xsysd,
30 struct xrt_space_overseer **out_xso,
31 struct xrt_system_compositor **out_xsysc)
32{
33 XRT_TRACE_MARKER();
34
35 struct u_system *usys = NULL;
36 struct xrt_system_devices *xsysd = NULL;
37 struct xrt_space_overseer *xso = NULL;
38 xrt_result_t xret = XRT_SUCCESS;
39
40 assert(out_xsysd != NULL);
41 assert(*out_xsysd == NULL);
42 assert(out_xso != NULL);
43 assert(*out_xso == NULL);
44 assert(out_xsysc == NULL || *out_xsysc == NULL);
45
46 // Can't create a system compositor.
47 if (out_xsysc != NULL) {
48 return XRT_ERROR_ALLOCATION;
49 }
50
51 usys = u_system_create();
52 assert(usys != NULL); // Should never fail.
53
54 xret = u_system_devices_create_from_prober( //
55 xinst, //
56 &usys->broadcast, //
57 &xsysd, //
58 &xso); //
59 if (xret != XRT_SUCCESS) {
60 u_system_destroy(&usys);
61 return xret;
62 }
63
64 u_system_fill_properties(usys, xsysd->static_roles.head->str);
65 *out_xsys = &usys->base;
66 *out_xsysd = xsysd;
67 *out_xso = xso;
68
69 return xret;
70}
71
72
73/*
74 *
75 * Exported function(s).
76 *
77 */
78
79xrt_result_t
80xrt_instance_create(struct xrt_instance_info *ii, struct xrt_instance **out_xinst)
81{
82 XRT_TRACE_MARKER();
83
84 struct xrt_prober *xp = NULL;
85
86 int ret = xrt_prober_create_with_lists(&xp, &target_lists);
87 if (ret < 0) {
88 return XRT_ERROR_PROBER_CREATION_FAILED;
89 }
90
91 struct t_instance *tinst = U_TYPED_CALLOC(struct t_instance);
92 tinst->base.create_system = t_instance_create_system;
93 tinst->base.get_prober = t_instance_get_prober;
94 tinst->base.destroy = t_instance_destroy;
95 tinst->xp = xp;
96
97#ifdef XRT_OS_ANDROID
98 ret = android_instance_base_init(&tinst->android, &tinst->base, ii);
99 if (ret < 0) {
100 xrt_prober_destroy(&xp);
101 free(tinst);
102 return ret;
103 }
104#endif // XRT_OS_ANDROID
105
106 *out_xinst = &tinst->base;
107
108 return XRT_SUCCESS;
109}