MayaFlux 0.1.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 * @brief Present a rendered frame to window
14 * @param window_handle Opaque window/surface handle
15 * @param command_buffer_handle Opaque command buffer handle with rendering commands
16 *
17 * Submits the current frame for presentation to the display.
18 * Blocks until presentation completes or returns immediately
19 * depending on vsync settings. Thread-safe.
20 */
21 std::function<void(const std::shared_ptr<void>&, uint64_t)> present_frame;
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 Get actual swapchain format for a window
56 * @param window_handle Window handle
57 * @return Vulkan format (vk::Format cast to uint32_t)
58 *
59 * Returns the actual format used by the window's swapchain.
60 * Used to ensure render passes are compatible with framebuffers.
61 */
62 std::function<int(const std::shared_ptr<void>&)> get_swapchain_format;
63
64 /**
65 * @brief Get current framebuffer for a window
66 * @param window_handle Window handle
67 * @return Vulkan framebuffer handle (vk::Framebuffer cast to void*)
68 *
69 * Returns the framebuffer corresponding to the current swapchain image.
70 * Updated internally during frame acquisition. Returns nullptr if window
71 * not registered or no framebuffer available.
72 */
73 std::function<void*(const std::shared_ptr<void>&)> get_current_framebuffer;
74
75 /**
76 * @brief Get swapchain extent for a window
77 * @param window_handle Window handle
78 * @param out_width Output parameter for width
79 * @param out_height Output parameter for height
80 *
81 * Retrieves current swapchain dimensions. Sets out_width and out_height
82 * to 0 if window not registered or swapchain unavailable.
83 */
84 std::function<void(const std::shared_ptr<void>&, uint32_t&, uint32_t&)> get_swapchain_extent;
85
86 /**
87 * @brief Get backend render pass for a window
88 * @param window_handle Window handle
89 * @return Vulkan render pass handle (vk::RenderPass cast to void*)
90 *
91 * Returns the render pass created by the backend for this window's swapchain.
92 * Managed by backend, compatible with window's framebuffers.
93 * Returns nullptr if window not registered.
94 */
95 std::function<void*(const std::shared_ptr<void>&)> get_window_render_pass;
96
97 /**
98 * @brief Attach a custom render pass to a window
99 * @param window_handle Window handle
100 * @param render_pass_handle Opaque render pass handle (Core::VKRenderPass cast to shared void*)
101 * @return bool True on success, false on failure
102 * Replaces the backend-managed render pass with a user-provided one.
103 * Recreates framebuffers to be compatible with the new render pass.
104 * Used for advanced rendering techniques requiring custom render passes.
105 * Waits for idle before making changes.
106 */
107 std::function<bool(const std::shared_ptr<void>&, const std::shared_ptr<void>&)> attach_render_pass;
108};
109
110} // namespace MayaFlux::Registry::Services
std::function< void(const std::shared_ptr< void > &, uint64_t)> present_frame
Present a rendered frame to window.
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< 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< bool(const std::shared_ptr< void > &, const std::shared_ptr< void > &)> attach_render_pass
Attach a custom render pass to a window.
std::function< uint32_t(const std::shared_ptr< void > &)> get_swapchain_image_count
Get current swapchain image count.
Backend display and presentation service interface.