From 7a0d87db25dcede9b781e26c1b0487c59ac659f2 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Fri, 9 Dec 2022 19:24:32 +0100 Subject: [PATCH] c/main: Allow providing comp_target_factory in constructor --- src/xrt/compositor/main/comp_compositor.c | 10 +++++----- src/xrt/compositor/main/comp_main_interface.h | 11 ++++++++++- src/xrt/targets/common/target_instance.c | 2 +- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/xrt/compositor/main/comp_compositor.c b/src/xrt/compositor/main/comp_compositor.c index 23eaf536a..1509e188c 100644 --- a/src/xrt/compositor/main/comp_compositor.c +++ b/src/xrt/compositor/main/comp_compositor.c @@ -858,12 +858,10 @@ select_target_factory_by_detecting(struct comp_compositor *c, struct comp_target } static bool -compositor_init_window_pre_vulkan(struct comp_compositor *c) +compositor_init_window_pre_vulkan(struct comp_compositor *c, struct comp_target_factory *selected_ctf) { COMP_TRACE_MARKER(); - struct comp_target_factory *selected_ctf = NULL; - if (selected_ctf == NULL && !select_target_factory_from_settings(c, &selected_ctf)) { return false; // Error! } @@ -985,7 +983,9 @@ compositor_init_renderer(struct comp_compositor *c) } xrt_result_t -comp_main_create_system_compositor(struct xrt_device *xdev, struct xrt_system_compositor **out_xsysc) +comp_main_create_system_compositor(struct xrt_device *xdev, + struct comp_target_factory *ctf, + struct xrt_system_compositor **out_xsysc) { COMP_TRACE_MARKER(); @@ -1041,7 +1041,7 @@ comp_main_create_system_compositor(struct xrt_device *xdev, struct xrt_system_co // clang-format off if (!compositor_check_and_prepare_xdev(c, xdev) || - !compositor_init_window_pre_vulkan(c) || + !compositor_init_window_pre_vulkan(c, ctf) || !compositor_init_vulkan(c) || !compositor_init_render_resources(c)) { COMP_ERROR(c, "Failed to init compositor %p", (void *)c); diff --git a/src/xrt/compositor/main/comp_main_interface.h b/src/xrt/compositor/main/comp_main_interface.h index e6d67fd7c..986125402 100644 --- a/src/xrt/compositor/main/comp_main_interface.h +++ b/src/xrt/compositor/main/comp_main_interface.h @@ -14,6 +14,8 @@ #include "xrt/xrt_device.h" #include "xrt/xrt_compositor.h" +struct comp_target_factory; + #ifdef __cplusplus extern "C" { #endif @@ -25,9 +27,16 @@ extern "C" { * * @ingroup comp_main * @relates xrt_system_compositor + * + * @param xdev The head device + * @param ctf A compositor target factory to force the output device, must remain valid for the lifetime of the + * compositor. If NULL, factory is automatically selected + * @param out_xsysc The output compositor */ xrt_result_t -comp_main_create_system_compositor(struct xrt_device *xdev, struct xrt_system_compositor **out_xsysc); +comp_main_create_system_compositor(struct xrt_device *xdev, + struct comp_target_factory *ctf, + struct xrt_system_compositor **out_xsysc); #ifdef __cplusplus diff --git a/src/xrt/targets/common/target_instance.c b/src/xrt/targets/common/target_instance.c index 35648e9dd..73f430316 100644 --- a/src/xrt/targets/common/target_instance.c +++ b/src/xrt/targets/common/target_instance.c @@ -86,7 +86,7 @@ t_instance_create_system(struct xrt_instance *xinst, #ifdef XRT_FEATURE_COMPOSITOR_MAIN if (xret == XRT_SUCCESS && xsysc == NULL) { - xret = comp_main_create_system_compositor(head, &xsysc); + xret = comp_main_create_system_compositor(head, NULL, &xsysc); } #else if (!use_null) {