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"
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 
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_
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()
Definition: comparable.h:95
AcquireResult(std::unique_ptr< Surface > p_surface)