Monado OpenXR Runtime
xrt_instance.h
Go to the documentation of this file.
1 // Copyright 2020, Collabora, Ltd.
2 // SPDX-License-Identifier: BSL-1.0
3 /*!
4  * @file
5  * @brief Header for @ref xrt_instance object.
6  * @author Jakob Bornecrantz <jakob@collabora.com>
7  * @ingroup xrt_iface
8  */
9 
10 #pragma once
11 
12 #include "xrt/xrt_compiler.h"
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 
19 struct xrt_prober;
20 struct xrt_device;
21 struct xrt_compositor_fd;
22 
23 /*!
24  * @ingroup xrt_iface
25  * @{
26  */
27 
28 /*!
29  * This object acts as a root object for Monado, it either wraps a
30  * @ref xrt_prober or forms a connection to a out of process XR service. As
31  * close to a singleton object there is in Monado, you should not create more
32  * then one of these.
33  */
35 {
36  /*!
37  * Returns the devices of the system represented as @ref xrt_device,
38  * see @ref xrt_prober::select, should only be called once.
39  */
40  int (*select)(struct xrt_instance *xinst,
41  struct xrt_device **xdevs,
42  size_t num_xdevs);
43 
44  /*!
45  * Creates a @ref xrt_compositor_fd, should only be called once.
46  */
47  int (*create_fd_compositor)(struct xrt_instance *xinst,
48  struct xrt_device *xdev,
49  bool flip_y,
50  struct xrt_compositor_fd **out_xcfd);
51 
52  /*!
53  * Get the instance @ref xrt_prober, the instance might not be using a
54  * @ref xrt_prober and may return null, the instance still owns the
55  * prober and will destroy it. Can be called multiple times.
56  */
57  int (*get_prober)(struct xrt_instance *xinst,
58  struct xrt_prober **out_xp);
59 
60  /*!
61  * Use helper @p xrt_instance_destroy.
62  */
63  void (*destroy)(struct xrt_instance *xinst);
64 };
65 
66 /*!
67  * Helper function for @ref xrt_instance::select, see @ref xrt_prober::select.
68  */
69 static inline int
70 xrt_instance_select(struct xrt_instance *xinst,
71  struct xrt_device **xdevs,
72  size_t num_xdevs)
73 {
74  return xinst->select(xinst, xdevs, num_xdevs);
75 }
76 
77 /*!
78  * Helper function for @ref xrt_instance::create_fd_compositor.
79  */
80 static inline int
81 xrt_instance_create_fd_compositor(struct xrt_instance *xinst,
82  struct xrt_device *xdev,
83  bool flip_y,
84  struct xrt_compositor_fd **out_xcfd)
85 {
86  return xinst->create_fd_compositor(xinst, xdev, flip_y, out_xcfd);
87 }
88 
89 /*!
90  * Helper function for @ref xrt_instance::get_prober.
91  */
92 static inline int
93 xrt_instance_get_prober(struct xrt_instance *xinst, struct xrt_prober **out_xp)
94 {
95  return xinst->get_prober(xinst, out_xp);
96 }
97 
98 /*!
99  * Helper function for @ref xrt_instance::destroy.
100  */
101 static inline void
102 xrt_instance_destroy(struct xrt_instance **xinst_ptr)
103 {
104  struct xrt_instance *xinst = *xinst_ptr;
105  if (xinst == NULL) {
106  return;
107  }
108 
109  xinst->destroy(xinst);
110  *xinst_ptr = NULL;
111 }
112 
113 /*!
114  * Creating more then one @ref xrt_instance is probably never the right thing
115  * to do, so avoid it.
116  */
117 int
118 xrt_instance_create(struct xrt_instance **out_xinst);
119 
120 /*!
121  * @}
122  */
123 
124 
125 #ifdef __cplusplus
126 }
127 #endif
Main compositor.
Definition: xrt_compositor.h:527
int(* create_fd_compositor)(struct xrt_instance *xinst, struct xrt_device *xdev, bool flip_y, struct xrt_compositor_fd **out_xcfd)
Creates a xrt_compositor_fd, should only be called once.
Definition: xrt_instance.h:47
The main prober that probes and manages found but not opened HMD devices that are connected to the sy...
Definition: xrt_prober.h:153
int(* select)(struct xrt_instance *xinst, struct xrt_device **xdevs, size_t num_xdevs)
Returns the devices of the system represented as xrt_device, see xrt_prober::select, should only be called once.
Definition: xrt_instance.h:40
int xrt_instance_create(struct xrt_instance **out_xinst)
Creating more then one xrt_instance is probably never the right thing to do, so avoid it...
Definition: target_instance.c:101
void(* destroy)(struct xrt_instance *xinst)
Use helper xrt_instance_destroy.
Definition: xrt_instance.h:63
Header holding common defines.
This object acts as a root object for Monado, it either wraps a xrt_prober or forms a connection to a...
Definition: xrt_instance.h:34
A single HMD or input device.
Definition: xrt_device.h:202
int(* get_prober)(struct xrt_instance *xinst, struct xrt_prober **out_xp)
Get the instance xrt_prober, the instance might not be using a xrt_prober and may return null...
Definition: xrt_instance.h:57