| 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 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
94 KHRSwapchainImplVK(const KHRSwapchainImplVK&) = delete;
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_
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:343
impeller::KHRSwapchainImplVK::AddFinalCommandBuffer
void AddFinalCommandBuffer(std::shared_ptr< CommandBuffer > cmd_buffer)
Definition: khr_swapchain_impl_vk.cc:420
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:111
impeller::KHRSwapchainImplVK::AcquireNextDrawable
AcquireResult AcquireNextDrawable()
Definition: khr_swapchain_impl_vk.cc:347
impeller::KHRSwapchainImplVK::GetSurfaceFormat
vk::Format GetSurfaceFormat() const
Definition: khr_swapchain_impl_vk.cc:339
impeller::KHRSwapchainImplVK::IsValid
bool IsValid() const
Definition: khr_swapchain_impl_vk.cc:318
impeller::KHRSwapchainImplVK::GetCurrentUnderlyingSurfaceSize
std::optional< ISize > GetCurrentUnderlyingSurfaceSize() const
Definition: khr_swapchain_impl_vk.cc:286
impeller::KHRSwapchainImplVK::DestroySwapchain
std::pair< vk::UniqueSurfaceKHR, vk::UniqueSwapchainKHR > DestroySwapchain()
Definition: khr_swapchain_impl_vk.cc:330
impeller::KHRSwapchainImplVK::GetSize
const ISize & GetSize() const
Definition: khr_swapchain_impl_vk.cc:282
impeller::KHRSwapchainImplVK::~KHRSwapchainImplVK
~KHRSwapchainImplVK()
Definition: khr_swapchain_impl_vk.cc:278
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