| Flutter Impeller |

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
11 #include "impeller/geometry/size.h"
12 #include "impeller/renderer/backend/vulkan/swapchain/swapchain_transients_vk.h"
13 #include "impeller/renderer/backend/vulkan/vk.h"
14
15 namespace impeller {
16
17 class Context;
18 class KHRSwapchainImageVK;
19 class Surface;
20 struct 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 ///
30 class KHRSwapchainImplVK final
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
40 ~KHRSwapchainImplVK();
41
42 bool IsValid() const;
43
44 struct AcquireResult {
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 size_t current_frame_ = 0u;
78 ISize size_;
79 bool enable_msaa_ = true;
80 bool is_valid_ = false;
81
82 KHRSwapchainImplVK(const std::shared_ptr<Context>& context,
83 vk::UniqueSurfaceKHR surface,
84 const ISize& size,
85 bool enable_msaa,
86 vk::SwapchainKHR old_swapchain);
87
88 bool Present(const std::shared_ptr<KHRSwapchainImageVK>& image,
89 uint32_t index);
90
91 void WaitIdle() const;
92
93 KHRSwapchainImplVK(const KHRSwapchainImplVK&) = delete;
94
95 KHRSwapchainImplVK& operator=(const KHRSwapchainImplVK&) = delete;
96 };
97
98 } // namespace impeller
99
100 #endif // FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_SWAPCHAIN_KHR_KHR_SWAPCHAIN_IMPL_VK_H_
impeller::KHRSwapchainImplVK
An instance of a swapchain that does NOT adapt to going out of date with the underlying surface....
Definition: khr_swapchain_impl_vk.h:31
impeller::KHRSwapchainImplVK::GetContext
std::shared_ptr< Context > GetContext() const
Definition: khr_swapchain_impl_vk.cc:338
impeller::KHRSwapchainImplVK::AddFinalCommandBuffer
void AddFinalCommandBuffer(std::shared_ptr< CommandBuffer > cmd_buffer)
Definition: khr_swapchain_impl_vk.cc:415
impeller::KHRSwapchainImplVK::Create
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)
Definition: khr_swapchain_impl_vk.cc:115
impeller::KHRSwapchainImplVK::AcquireNextDrawable
AcquireResult AcquireNextDrawable()
Definition: khr_swapchain_impl_vk.cc:342
impeller::KHRSwapchainImplVK::GetSurfaceFormat
vk::Format GetSurfaceFormat() const
Definition: khr_swapchain_impl_vk.cc:334
impeller::KHRSwapchainImplVK::IsValid
bool IsValid() const
Definition: khr_swapchain_impl_vk.cc:313
impeller::KHRSwapchainImplVK::GetCurrentUnderlyingSurfaceSize
std::optional< ISize > GetCurrentUnderlyingSurfaceSize() const
Definition: khr_swapchain_impl_vk.cc:281
impeller::KHRSwapchainImplVK::DestroySwapchain
std::pair< vk::UniqueSurfaceKHR, vk::UniqueSwapchainKHR > DestroySwapchain()
Definition: khr_swapchain_impl_vk.cc:325
impeller::KHRSwapchainImplVK::GetSize
const ISize & GetSize() const
Definition: khr_swapchain_impl_vk.cc:277
impeller::KHRSwapchainImplVK::~KHRSwapchainImplVK
~KHRSwapchainImplVK()
Definition: khr_swapchain_impl_vk.cc:273
impeller
Definition: allocation.cc:12
std
Definition: comparable.h:95
size.h
impeller::KHRSwapchainImplVK::AcquireResult
Definition: khr_swapchain_impl_vk.h:44
impeller::KHRSwapchainImplVK::AcquireResult::AcquireResult
AcquireResult(std::unique_ptr< Surface > p_surface)
Definition: khr_swapchain_impl_vk.h:51
impeller::KHRSwapchainImplVK::AcquireResult::surface
std::unique_ptr< Surface > surface
Definition: khr_swapchain_impl_vk.h:45
impeller::KHRSwapchainImplVK::AcquireResult::AcquireResult
AcquireResult(bool p_out_of_date=false)
Definition: khr_swapchain_impl_vk.h:48
impeller::KHRSwapchainImplVK::AcquireResult::out_of_date
bool out_of_date
Definition: khr_swapchain_impl_vk.h:46
impeller::TSize
Definition: size.h:25
swapchain_transients_vk.h
vk.h