mirror of
https://github.com/lbgos/rift-s-linux.git
synced 2026-10-27 08:01:10 +01:00
xrt: Refactor native compositor creation
This commit is contained in:
1 parent
7806993e1f
commit
113278c68d
10 files changed
+70
-25
No files matched your search
@@ -70,6 +70,7 @@ create_session(struct xrt_system *xsys,
|
||||
xret = xrt_syscomp_create_native_compositor( //
|
||||
usys->xsysc, //
|
||||
xsi, //
|
||||
&us->sink, //
|
||||
out_xcn); //
|
||||
if (xret != XRT_SUCCESS) {
|
||||
goto err;
|
||||
|
||||
@@ -1001,6 +1001,7 @@ multi_compositor_retire_delivered_locked(struct multi_compositor *mc, uint64_t w
|
||||
xrt_result_t
|
||||
multi_compositor_create(struct multi_system_compositor *msc,
|
||||
const struct xrt_session_info *xsi,
|
||||
struct xrt_session_event_sink *xses,
|
||||
struct xrt_compositor_native **out_xcn)
|
||||
{
|
||||
COMP_TRACE_MARKER();
|
||||
@@ -1035,6 +1036,7 @@ multi_compositor_create(struct multi_system_compositor *msc,
|
||||
mc->base.base.get_display_refresh_rate = multi_compositor_get_display_refresh_rate;
|
||||
mc->base.base.request_display_refresh_rate = multi_compositor_request_display_refresh_rate;
|
||||
mc->msc = msc;
|
||||
mc->xses = xses;
|
||||
mc->xsi = *xsi;
|
||||
|
||||
os_mutex_init(&mc->event.mutex);
|
||||
|
||||
@@ -116,6 +116,9 @@ struct multi_compositor
|
||||
// Client info.
|
||||
struct xrt_session_info xsi;
|
||||
|
||||
//! Where events for this compositor should go.
|
||||
struct xrt_session_event_sink *xses;
|
||||
|
||||
//! Owning system compositor.
|
||||
struct multi_system_compositor *msc;
|
||||
|
||||
@@ -218,6 +221,7 @@ multi_compositor(struct xrt_compositor *xc)
|
||||
xrt_result_t
|
||||
multi_compositor_create(struct multi_system_compositor *msc,
|
||||
const struct xrt_session_info *xsi,
|
||||
struct xrt_session_event_sink *xses,
|
||||
struct xrt_compositor_native **out_xcn);
|
||||
|
||||
/*!
|
||||
|
||||
@@ -661,11 +661,12 @@ system_compositor_notify_display_refresh_changed(struct xrt_system_compositor *x
|
||||
static xrt_result_t
|
||||
system_compositor_create_native_compositor(struct xrt_system_compositor *xsc,
|
||||
const struct xrt_session_info *xsi,
|
||||
struct xrt_session_event_sink *xses,
|
||||
struct xrt_compositor_native **out_xcn)
|
||||
{
|
||||
struct multi_system_compositor *msc = multi_system_compositor(xsc);
|
||||
|
||||
return multi_compositor_create(msc, xsi, out_xcn);
|
||||
return multi_compositor_create(msc, xsi, xses, out_xcn);
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
@@ -46,6 +46,7 @@ extern "C" {
|
||||
struct xrt_device;
|
||||
struct xrt_image_native;
|
||||
struct xrt_compositor;
|
||||
struct xrt_session_event_sink;
|
||||
|
||||
typedef struct VkCommandBuffer_T *VkCommandBuffer;
|
||||
#ifdef XRT_64_BIT
|
||||
@@ -2262,6 +2263,7 @@ struct xrt_system_compositor
|
||||
*/
|
||||
xrt_result_t (*create_native_compositor)(struct xrt_system_compositor *xsc,
|
||||
const struct xrt_session_info *xsi,
|
||||
struct xrt_session_event_sink *xses,
|
||||
struct xrt_compositor_native **out_xcn);
|
||||
|
||||
/*!
|
||||
@@ -2407,9 +2409,10 @@ xrt_syscomp_notify_display_refresh_changed(struct xrt_system_compositor *xsc,
|
||||
static inline xrt_result_t
|
||||
xrt_syscomp_create_native_compositor(struct xrt_system_compositor *xsc,
|
||||
const struct xrt_session_info *xsi,
|
||||
struct xrt_session_event_sink *xses,
|
||||
struct xrt_compositor_native **out_xcn)
|
||||
{
|
||||
return xsc->create_native_compositor(xsc, xsi, out_xcn);
|
||||
return xsc->create_native_compositor(xsc, xsi, xses, out_xcn);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
||||
@@ -988,13 +988,14 @@ ipc_compositor_images_destroy(struct xrt_image_native_allocator *xina)
|
||||
xrt_result_t
|
||||
ipc_syscomp_create_native_compositor(struct xrt_system_compositor *xsc,
|
||||
const struct xrt_session_info *xsi,
|
||||
struct xrt_session_event_sink *xses,
|
||||
struct xrt_compositor_native **out_xcn)
|
||||
{
|
||||
struct ipc_client_compositor *icc = container_of(xsc, struct ipc_client_compositor, system);
|
||||
xrt_result_t xret;
|
||||
|
||||
xret = ipc_client_create_native_compositor(xsc, xsi, out_xcn);
|
||||
IPC_CHK_ALWAYS_RET(icc->ipc_c, xret, "ipc_client_create_native_compositor");
|
||||
IPC_ERROR(icc->ipc_c, "This function shouldn't be called!");
|
||||
|
||||
return XRT_ERROR_IPC_FAILURE;
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -70,10 +70,10 @@ ipc_client_system_create_session(struct xrt_system *xsys,
|
||||
goto out_session;
|
||||
}
|
||||
|
||||
xret = xrt_syscomp_create_native_compositor( //
|
||||
icsys->xsysc, //
|
||||
xsi, //
|
||||
out_xcn); //
|
||||
xret = ipc_client_create_native_compositor( //
|
||||
icsys->xsysc, //
|
||||
xsi, //
|
||||
out_xcn); //
|
||||
if (xret != XRT_SUCCESS) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
@@ -208,13 +208,14 @@ ipc_handle_session_create(volatile struct ipc_client_state *ics, const struct xr
|
||||
{
|
||||
IPC_TRACE_MARKER();
|
||||
|
||||
struct xrt_session *xs = NULL;
|
||||
struct xrt_compositor_native *xcn = NULL;
|
||||
|
||||
if (ics->xc != NULL) {
|
||||
if (ics->xs != NULL) {
|
||||
return XRT_ERROR_IPC_SESSION_ALREADY_CREATED;
|
||||
}
|
||||
|
||||
xrt_result_t xret = xrt_syscomp_create_native_compositor(ics->server->xsysc, xsi, &xcn);
|
||||
xrt_result_t xret = xrt_system_create_session(ics->server->xsys, xsi, &xs, &xcn);
|
||||
if (xret != XRT_SUCCESS) {
|
||||
return xret;
|
||||
}
|
||||
@@ -222,6 +223,7 @@ ipc_handle_session_create(volatile struct ipc_client_state *ics, const struct xr
|
||||
ics->client_state.session_overlay = xsi->is_overlay;
|
||||
ics->client_state.z_order = xsi->z_order;
|
||||
|
||||
ics->xs = xs;
|
||||
ics->xc = &xcn->base;
|
||||
|
||||
xrt_syscomp_set_state(ics->server->xsysc, ics->xc, ics->client_state.session_visible,
|
||||
@@ -247,10 +249,16 @@ ipc_handle_session_begin(volatile struct ipc_client_state *ics)
|
||||
{
|
||||
IPC_TRACE_MARKER();
|
||||
|
||||
if (ics->xc == NULL) {
|
||||
// Have we created the session?
|
||||
if (ics->xs == NULL) {
|
||||
return XRT_ERROR_IPC_SESSION_NOT_CREATED;
|
||||
}
|
||||
|
||||
// Need to check both because begin session is handled by compositor.
|
||||
if (ics->xc == NULL) {
|
||||
return XRT_ERROR_IPC_COMPOSITOR_NOT_CREATED;
|
||||
}
|
||||
|
||||
//! @todo Pass the view type down.
|
||||
const struct xrt_begin_session_info begin_session_info = {
|
||||
.view_type = XRT_VIEW_TYPE_STEREO,
|
||||
@@ -267,10 +275,16 @@ ipc_handle_session_end(volatile struct ipc_client_state *ics)
|
||||
{
|
||||
IPC_TRACE_MARKER();
|
||||
|
||||
if (ics->xc == NULL) {
|
||||
// Have we created the session?
|
||||
if (ics->xs == NULL) {
|
||||
return XRT_ERROR_IPC_SESSION_NOT_CREATED;
|
||||
}
|
||||
|
||||
// Need to check both because end session is handled by compositor.
|
||||
if (ics->xc == NULL) {
|
||||
return XRT_ERROR_IPC_COMPOSITOR_NOT_CREATED;
|
||||
}
|
||||
|
||||
return xrt_comp_end_session(ics->xc);
|
||||
}
|
||||
|
||||
@@ -279,7 +293,8 @@ ipc_handle_session_destroy(volatile struct ipc_client_state *ics)
|
||||
{
|
||||
IPC_TRACE_MARKER();
|
||||
|
||||
if (ics->xc == NULL) {
|
||||
// Have we created the session?
|
||||
if (ics->xs == NULL) {
|
||||
return XRT_ERROR_IPC_SESSION_NOT_CREATED;
|
||||
}
|
||||
|
||||
|
||||
@@ -1519,6 +1519,9 @@ struct oxr_session
|
||||
//! What graphics type was this session created with.
|
||||
enum oxr_session_graphics_ext gfx_ext;
|
||||
|
||||
//! The @ref xrt_session backing this session.
|
||||
struct xrt_session *xs;
|
||||
|
||||
//! Native compositor that is wrapped by client compositors.
|
||||
struct xrt_compositor_native *xcn;
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
*/
|
||||
|
||||
#include "xrt/xrt_device.h"
|
||||
#include "xrt/xrt_session.h"
|
||||
#include "xrt/xrt_config_build.h" // IWYU pragma: keep
|
||||
#include "xrt/xrt_config_have.h" // IWYU pragma: keep
|
||||
|
||||
@@ -682,6 +683,7 @@ oxr_session_destroy(struct oxr_logger *log, struct oxr_handle_base *hb)
|
||||
|
||||
xrt_comp_destroy(&sess->compositor);
|
||||
xrt_comp_native_destroy(&sess->xcn);
|
||||
xrt_session_destroy(&sess->xs);
|
||||
|
||||
os_precise_sleeper_deinit(&sess->sleeper);
|
||||
os_semaphore_destroy(&sess->sem);
|
||||
@@ -739,15 +741,19 @@ oxr_session_allocate_and_init(struct oxr_logger *log,
|
||||
} \
|
||||
} while (false)
|
||||
|
||||
#define OXR_ALLOCATE_NATIVE_COMPOSITOR(LOG, XSI, SESS) \
|
||||
#define OXR_CREATE_XRT_SESSION_AND_NATIVE_COMPOSITOR(LOG, XSI, SESS) \
|
||||
do { \
|
||||
xrt_result_t xret = xrt_syscomp_create_native_compositor((SESS)->sys->xsysc, (XSI), &(SESS)->xcn); \
|
||||
if ((SESS)->sys->xsysc == NULL) { \
|
||||
return oxr_error((LOG), XR_ERROR_RUNTIME_FAILURE, \
|
||||
"The system compositor wasn't created, can't create native compositor!"); \
|
||||
} \
|
||||
xrt_result_t xret = xrt_system_create_session((SESS)->sys->xsys, (XSI), &(SESS)->xs, &(SESS)->xcn); \
|
||||
if (xret == XRT_ERROR_MULTI_SESSION_NOT_IMPLEMENTED) { \
|
||||
return oxr_error((LOG), XR_ERROR_LIMIT_REACHED, "Per instance multi-session not supported."); \
|
||||
} \
|
||||
if (xret != XRT_SUCCESS) { \
|
||||
return oxr_error((LOG), XR_ERROR_RUNTIME_FAILURE, "Failed to create native compositor! '%i'", \
|
||||
xret); \
|
||||
return oxr_error((LOG), XR_ERROR_RUNTIME_FAILURE, \
|
||||
"Failed to create xrt_session and xrt_compositor_native! '%i'", xret); \
|
||||
} \
|
||||
if ((SESS)->sys->xsysc->xmcc != NULL) { \
|
||||
xrt_syscomp_set_state((SESS)->sys->xsysc, &(SESS)->xcn->base, true, true); \
|
||||
@@ -788,7 +794,7 @@ oxr_session_create_impl(struct oxr_logger *log,
|
||||
}
|
||||
|
||||
OXR_SESSION_ALLOCATE_AND_INIT(log, sys, OXR_SESSION_GRAPHICS_EXT_XLIB_GL, *out_session);
|
||||
OXR_ALLOCATE_NATIVE_COMPOSITOR(log, xsi, *out_session);
|
||||
OXR_CREATE_XRT_SESSION_AND_NATIVE_COMPOSITOR(log, xsi, *out_session);
|
||||
return oxr_session_populate_gl_xlib(log, sys, opengl_xlib, *out_session);
|
||||
}
|
||||
#endif
|
||||
@@ -807,7 +813,7 @@ oxr_session_create_impl(struct oxr_logger *log,
|
||||
}
|
||||
|
||||
OXR_SESSION_ALLOCATE_AND_INIT(log, sys, OXR_SESSION_GRAPHICS_EXT_ANDROID_GLES, *out_session);
|
||||
OXR_ALLOCATE_NATIVE_COMPOSITOR(log, xsi, *out_session);
|
||||
OXR_CREATE_XRT_SESSION_AND_NATIVE_COMPOSITOR(log, xsi, *out_session);
|
||||
return oxr_session_populate_gles_android(log, sys, opengles_android, *out_session);
|
||||
}
|
||||
#endif
|
||||
@@ -824,7 +830,7 @@ oxr_session_create_impl(struct oxr_logger *log,
|
||||
}
|
||||
|
||||
OXR_SESSION_ALLOCATE_AND_INIT(log, sys, OXR_SESSION_GRAPHICS_EXT_WIN32_GL, *out_session);
|
||||
OXR_ALLOCATE_NATIVE_COMPOSITOR(log, xsi, *out_session);
|
||||
OXR_CREATE_XRT_SESSION_AND_NATIVE_COMPOSITOR(log, xsi, *out_session);
|
||||
return oxr_session_populate_gl_win32(log, sys, opengl_win32, *out_session);
|
||||
}
|
||||
#endif
|
||||
@@ -863,7 +869,7 @@ oxr_session_create_impl(struct oxr_logger *log,
|
||||
}
|
||||
|
||||
OXR_SESSION_ALLOCATE_AND_INIT(log, sys, OXR_SESSION_GRAPHICS_EXT_VULKAN, *out_session);
|
||||
OXR_ALLOCATE_NATIVE_COMPOSITOR(log, xsi, *out_session);
|
||||
OXR_CREATE_XRT_SESSION_AND_NATIVE_COMPOSITOR(log, xsi, *out_session);
|
||||
return oxr_session_populate_vk(log, sys, vulkan, *out_session);
|
||||
}
|
||||
#endif
|
||||
@@ -881,7 +887,7 @@ oxr_session_create_impl(struct oxr_logger *log,
|
||||
}
|
||||
|
||||
OXR_SESSION_ALLOCATE_AND_INIT(log, sys, OXR_SESSION_GRAPHICS_EXT_EGL, *out_session);
|
||||
OXR_ALLOCATE_NATIVE_COMPOSITOR(log, xsi, *out_session);
|
||||
OXR_CREATE_XRT_SESSION_AND_NATIVE_COMPOSITOR(log, xsi, *out_session);
|
||||
return oxr_session_populate_egl(log, sys, egl, *out_session);
|
||||
}
|
||||
#endif
|
||||
@@ -906,7 +912,7 @@ oxr_session_create_impl(struct oxr_logger *log,
|
||||
|
||||
|
||||
OXR_SESSION_ALLOCATE_AND_INIT(log, sys, OXR_SESSION_GRAPHICS_EXT_D3D11, *out_session);
|
||||
OXR_ALLOCATE_NATIVE_COMPOSITOR(log, xsi, *out_session);
|
||||
OXR_CREATE_XRT_SESSION_AND_NATIVE_COMPOSITOR(log, xsi, *out_session);
|
||||
return oxr_session_populate_d3d11(log, sys, d3d11, *out_session);
|
||||
}
|
||||
#endif
|
||||
@@ -931,7 +937,7 @@ oxr_session_create_impl(struct oxr_logger *log,
|
||||
|
||||
|
||||
OXR_SESSION_ALLOCATE_AND_INIT(log, sys, OXR_SESSION_GRAPHICS_EXT_D3D12, *out_session);
|
||||
OXR_ALLOCATE_NATIVE_COMPOSITOR(log, xsi, *out_session);
|
||||
OXR_CREATE_XRT_SESSION_AND_NATIVE_COMPOSITOR(log, xsi, *out_session);
|
||||
return oxr_session_populate_d3d12(log, sys, d3d12, *out_session);
|
||||
}
|
||||
#endif
|
||||
@@ -948,6 +954,15 @@ oxr_session_create_impl(struct oxr_logger *log,
|
||||
OXR_SESSION_ALLOCATE_AND_INIT(log, sys, OXR_SESSION_GRAPHICS_EXT_HEADLESS, *out_session);
|
||||
(*out_session)->compositor = NULL;
|
||||
(*out_session)->create_swapchain = NULL;
|
||||
|
||||
xrt_result_t xret = xrt_system_create_session(sys->xsys, xsi, &(*out_session)->xs, NULL);
|
||||
if (xret == XRT_ERROR_MULTI_SESSION_NOT_IMPLEMENTED) {
|
||||
return oxr_error(log, XR_ERROR_LIMIT_REACHED, "Per instance multi-session not supported.");
|
||||
}
|
||||
if (xret != XRT_SUCCESS) {
|
||||
return oxr_error(log, XR_ERROR_RUNTIME_FAILURE, "Failed to create xrt_session! '%i'", xret);
|
||||
}
|
||||
|
||||
return XR_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in new issue
Block a user