MayaFlux 0.2.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
DisplayService.hpp
Go to the documentation of this file.
1#pragma once
2
4
5/**
6 * @brief Backend display and presentation service interface
7 *
8 * Manages window surfaces, swapchains, and frame presentation.
9 * Handles window resize events and ensures proper surface recreation.
10 */
11struct MAYAFLUX_API DisplayService {
12
13 /**
14 * @brief Submit a primary command buffer and present the frame
15 * @param window_handle Window handle
16 * @param primary_command_buffer The primary command buffer (uint64_t bits of vk::CommandBuffer)
17 *
18 * Handles semaphore choreography: waits on image_available, signals render_finished,
19 * then presents. Must be called after acquire_next_swapchain_image().
20 */
21 std::function<void(const std::shared_ptr<void>&, uint64_t)> submit_and_present;
22
23 /**
24 * @brief Wait for all GPU operations to complete
25 *
26 * Blocks until all submitted command buffers have finished execution.
27 * Used for synchronization before shutdown or major state changes.
28 * Can significantly impact performance - use sparingly.
29 */
30 std::function<void()> wait_idle;
31
32 /**
33 * @brief Resize rendering surface for a window
34 * @param window_handle Window to resize
35 * @param width New width in pixels
36 * @param height New height in pixels
37 *
38 * Recreates swapchain and associated framebuffers for new dimensions.
39 * Must be called when window size changes to avoid rendering artifacts.
40 * Automatically waits for idle before reconstruction.
41 */
42 std::function<void(const std::shared_ptr<void>&, uint32_t, uint32_t)> resize_surface;
43
44 /**
45 * @brief Get current swapchain image count
46 * @param window_handle Window handle
47 * @return Number of images in the swapchain
48 *
49 * Useful for allocating per-frame resources. Typically 2-3 images
50 * for double/triple buffering.
51 */
52 std::function<uint32_t(const std::shared_ptr<void>&)> get_swapchain_image_count;
53
54 /**
55 * @brief Acquire the next swapchain image for a window
56 * @param window_handle Window handle
57 * @return Index of the acquired swapchain image
58 *
59 * Must be called before get_current_image_view() for dynamic rendering.
60 * Stores the acquired image index internally for subsequent calls.
61 */
62 std::function<uint64_t(const std::shared_ptr<void>&)> acquire_next_swapchain_image;
63
64 /**
65 * @brief Get actual swapchain format for a window
66 * @param window_handle Window handle
67 * @return Vulkan format (vk::Format cast to uint32_t)
68 *
69 * Returns the actual format used by the window's swapchain.
70 * Used to ensure multiple dynamic render calls are compatible
71 */
72 std::function<int(const std::shared_ptr<void>&)> get_swapchain_format;
73
74 /**
75 * @brief Get swapchain extent for a window
76 * @param window_handle Window handle
77 * @param out_width Output parameter for width
78 * @param out_height Output parameter for height
79 *
80 * Retrieves current swapchain dimensions. Sets out_width and out_height
81 * to 0 if window not registered or swapchain unavailable.
82 */
83 std::function<void(const std::shared_ptr<void>&, uint32_t&, uint32_t&)> get_swapchain_extent;
84
85 /**
86 * @brief Get current swapchain image view for rendering
87 * @param window_handle Window handle
88 * @return vk::ImageView cast to void*
89 *
90 * Returns the image view for the currently acquired swapchain image.
91 * Used with dynamic rendering.
92 */
93 std::function<void*(const std::shared_ptr<void>&)> get_current_image_view;
94};
95
96} // namespace MayaFlux::Registry::Services
std::function< void(const std::shared_ptr< void > &, uint32_t, uint32_t)> resize_surface
Resize rendering surface for a window.
std::function< int(const std::shared_ptr< void > &)> get_swapchain_format
Get actual swapchain format for a window.
std::function< uint64_t(const std::shared_ptr< void > &)> acquire_next_swapchain_image
Acquire the next swapchain image for a window.
std::function< void()> wait_idle
Wait for all GPU operations to complete.
std::function< void(const std::shared_ptr< void > &, uint32_t &, uint32_t &)> get_swapchain_extent
Get swapchain extent for a window.
std::function< uint32_t(const std::shared_ptr< void > &)> get_swapchain_image_count
Get current swapchain image count.
std::function< void(const std::shared_ptr< void > &, uint64_t)> submit_and_present
Submit a primary command buffer and present the frame.
Backend display and presentation service interface.