Flutter Engine
 
Loading...
Searching...
No Matches
khr_swapchain_impl_vk.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_SWAPCHAIN_KHR_KHR_SWAPCHAIN_IMPL_VK_H_
6#define FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_SWAPCHAIN_KHR_KHR_SWAPCHAIN_IMPL_VK_H_
7
8#include <cstdint>
9#include <memory>
10
14
15namespace impeller {
16
17class Context;
18class KHRSwapchainImageVK;
19class Surface;
20struct KHRFrameSynchronizerVK;
21
22//------------------------------------------------------------------------------
23/// @brief An instance of a swapchain that does NOT adapt to going out of
24/// date with the underlying surface. Errors will be indicated when
25/// the next drawable is acquired from this implementation of the
26/// swapchain. If the error is due the swapchain going out of date,
27/// the caller must recreate another instance by optionally
28/// stealing this implementations guts.
29///
31 : public std::enable_shared_from_this<KHRSwapchainImplVK> {
32 public:
33 static std::shared_ptr<KHRSwapchainImplVK> Create(
34 const std::shared_ptr<Context>& context,
35 vk::UniqueSurfaceKHR surface,
36 const ISize& size,
37 bool enable_msaa = true,
38 vk::SwapchainKHR old_swapchain = VK_NULL_HANDLE);
39
41
42 bool IsValid() const;
43
45 std::unique_ptr<Surface> surface;
46 bool out_of_date = false;
47
48 explicit AcquireResult(bool p_out_of_date = false)
49 : out_of_date(p_out_of_date) {}
50
51 explicit AcquireResult(std::unique_ptr<Surface> p_surface)
52 : surface(std::move(p_surface)) {}
53 };
54
55 AcquireResult AcquireNextDrawable();
56
57 vk::Format GetSurfaceFormat() const;
58
59 std::shared_ptr<Context> GetContext() const;
60
61 std::pair<vk::UniqueSurfaceKHR, vk::UniqueSwapchainKHR> DestroySwapchain();
62
63 const ISize& GetSize() const;
64
65 void AddFinalCommandBuffer(std::shared_ptr<CommandBuffer> cmd_buffer);
66
67 std::optional<ISize> GetCurrentUnderlyingSurfaceSize() const;
68
69 private:
70 std::weak_ptr<Context> context_;
71 vk::UniqueSurfaceKHR surface_;
72 vk::Format surface_format_ = vk::Format::eUndefined;
73 vk::UniqueSwapchainKHR swapchain_;
74 std::shared_ptr<SwapchainTransientsVK> transients_;
75 std::vector<std::shared_ptr<KHRSwapchainImageVK>> images_;
76 std::vector<std::unique_ptr<KHRFrameSynchronizerVK>> synchronizers_;
77 std::vector<vk::UniqueSemaphore> present_semaphores_;
78 size_t current_frame_ = 0u;
79 ISize size_;
80 bool enable_msaa_ = true;
81 bool is_valid_ = false;
82
83 KHRSwapchainImplVK(const std::shared_ptr<Context>& context,
84 vk::UniqueSurfaceKHR surface,
85 const ISize& size,
86 bool enable_msaa,
87 vk::SwapchainKHR old_swapchain);
88
89 bool Present(const std::shared_ptr<KHRSwapchainImageVK>& image,
90 uint32_t index);
91
92 void WaitIdle() const;
93
95
96 KHRSwapchainImplVK& operator=(const KHRSwapchainImplVK&) = delete;
97};
98
99} // namespace impeller
100
101#endif // FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_SWAPCHAIN_KHR_KHR_SWAPCHAIN_IMPL_VK_H_
An instance of a swapchain that does NOT adapt to going out of date with the underlying surface....
std::shared_ptr< Context > GetContext() const
void AddFinalCommandBuffer(std::shared_ptr< CommandBuffer > cmd_buffer)
static std::shared_ptr< KHRSwapchainImplVK > Create(const std::shared_ptr< Context > &context, vk::UniqueSurfaceKHR surface, const ISize &size, bool enable_msaa=true, vk::SwapchainKHR old_swapchain=VK_NULL_HANDLE)
std::optional< ISize > GetCurrentUnderlyingSurfaceSize() const
std::pair< vk::UniqueSurfaceKHR, vk::UniqueSwapchainKHR > DestroySwapchain()
FlutterVulkanImage * image
VkSurfaceKHR surface
Definition main.cc:65
Definition ref_ptr.h:261
AcquireResult(std::unique_ptr< Surface > p_surface)