diff --git a/src/xrt/compositor/main/comp_target.h b/src/xrt/compositor/main/comp_target.h index 9eb791a70..96eefa5e7 100644 --- a/src/xrt/compositor/main/comp_target.h +++ b/src/xrt/compositor/main/comp_target.h @@ -105,9 +105,18 @@ struct comp_target */ bool (*init_post_vulkan)(struct comp_target *ct, uint32_t preferred_width, uint32_t preferred_height); + /*! + * Is this target ready for image creation? + * + * Call before calling @ref create_images + */ + bool (*check_ready)(struct comp_target *ct); + /*! * Create or recreate the image(s) of the target, for swapchain based * targets this will (re)create the swapchain. + * + * @pre @ref check_ready returns true */ void (*create_images)(struct comp_target *ct, uint32_t preferred_width, @@ -218,6 +227,20 @@ comp_target_init_post_vulkan(struct comp_target *ct, uint32_t preferred_width, u return ct->init_post_vulkan(ct, preferred_width, preferred_height); } +/*! + * @copydoc comp_target::check_ready + * + * @public @memberof comp_target + * @ingroup comp_main + */ +static inline bool +comp_target_check_ready(struct comp_target *ct) +{ + COMP_TRACE_MARKER(); + + return ct->check_ready(ct); +} + /*! * @copydoc comp_target::create_images * diff --git a/src/xrt/compositor/main/comp_target_swapchain.c b/src/xrt/compositor/main/comp_target_swapchain.c index 253c00cb0..9e1dca5c0 100644 --- a/src/xrt/compositor/main/comp_target_swapchain.c +++ b/src/xrt/compositor/main/comp_target_swapchain.c @@ -299,6 +299,13 @@ comp_target_swapchain_present(struct comp_target *ct, return vk->vkQueuePresentKHR(queue, &presentInfo); } +static bool +comp_target_swapchain_check_ready(struct comp_target *ct) +{ + struct comp_target_swapchain *cts = (struct comp_target_swapchain *)ct; + return cts->surface.handle != VK_NULL_HANDLE; +} + static bool _find_surface_format(struct comp_target_swapchain *cts, VkSurfaceKHR surface, VkSurfaceFormatKHR *format) { @@ -646,6 +653,7 @@ comp_target_swapchain_init_and_set_fnptrs(struct comp_target_swapchain *cts, enum comp_target_display_timing_usage timing_usage) { cts->timing_usage = timing_usage; + cts->base.check_ready = comp_target_swapchain_check_ready; cts->base.create_images = comp_target_swapchain_create_images; cts->base.acquire = comp_target_swapchain_acquire_next_image; cts->base.present = comp_target_swapchain_present; diff --git a/src/xrt/compositor/main/comp_target_swapchain.h b/src/xrt/compositor/main/comp_target_swapchain.h index 8e07b7fc4..a30cf24e4 100644 --- a/src/xrt/compositor/main/comp_target_swapchain.h +++ b/src/xrt/compositor/main/comp_target_swapchain.h @@ -83,6 +83,7 @@ struct comp_target_swapchain * Initializes these function pointers, all other methods of @ref comp_target are the responsibility of the caller (the * "subclass"): * + * - comp_target::check_ready * - comp_target::create_images * - comp_target::acquire * - comp_target::present