| Flutter Impeller |

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_IMPL_VK_H_
6 #define FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_SWAPCHAIN_IMPL_VK_H_
7
8 #include <cstdint>
9 #include <memory>
10 #include <variant>
11
12 #include "flutter/fml/macros.h"
13 #include "impeller/renderer/backend/vulkan/vk.h"
14 #include "vulkan/vulkan_enums.hpp"
15
16 namespace impeller {
17
18 class Context;
19 class SwapchainImageVK;
20 class Surface;
21 struct FrameSynchronizer;
22
23 //------------------------------------------------------------------------------
24 /// @brief An instance of a swapchain that does NOT adapt to going out of
25 /// date with the underlying surface. Errors will be indicated when
26 /// the next drawable is acquired from this implementation of the
27 /// swapchain. If the error is due the swapchain going out of date,
28 /// the caller must recreate another instance by optionally
29 /// stealing this implementations guts.
30 ///
31 class SwapchainImplVK final
32 : public std::enable_shared_from_this<SwapchainImplVK> {
33 public:
34 static std::shared_ptr<SwapchainImplVK> Create(
35 const std::shared_ptr<Context>& context,
36 vk::UniqueSurfaceKHR surface,
37 vk::SwapchainKHR old_swapchain = VK_NULL_HANDLE,
38 vk::SurfaceTransformFlagBitsKHR last_transform =
39 vk::SurfaceTransformFlagBitsKHR::eIdentity);
40
41 ~SwapchainImplVK();
42
43 bool IsValid() const;
44
45 struct AcquireResult {
46 std::unique_ptr<Surface> surface;
47 bool out_of_date = false;
48
49 explicit AcquireResult(bool p_out_of_date = false)
50 : out_of_date(p_out_of_date) {}
51
52 explicit AcquireResult(std::unique_ptr<Surface> p_surface)
53 : surface(std::move(p_surface)) {}
54 };
55
56 AcquireResult AcquireNextDrawable();
57
58 vk::Format GetSurfaceFormat() const;
59
60 vk::SurfaceTransformFlagBitsKHR GetLastTransform() const;
61
62 std::shared_ptr<Context> GetContext() const;
63
64 std::pair<vk::UniqueSurfaceKHR, vk::UniqueSwapchainKHR> DestroySwapchain();
65
66 private:
67 std::weak_ptr<Context> context_;
68 vk::UniqueSurfaceKHR surface_;
69 vk::Queue present_queue_ = {};
70 vk::Format surface_format_ = vk::Format::eUndefined;
71 vk::UniqueSwapchainKHR swapchain_;
72 std::vector<std::shared_ptr<SwapchainImageVK>> images_;
73 std::vector<std::unique_ptr<FrameSynchronizer>> synchronizers_;
74 size_t current_frame_ = 0u;
75 bool is_valid_ = false;
76 size_t current_transform_poll_count_ = 0u;
77 vk::SurfaceTransformFlagBitsKHR transform_if_changed_discard_swapchain_;
78
79 SwapchainImplVK(const std::shared_ptr<Context>& context,
80 vk::UniqueSurfaceKHR surface,
81 vk::SwapchainKHR old_swapchain,
82 vk::SurfaceTransformFlagBitsKHR last_transform);
83
84 bool Present(const std::shared_ptr<SwapchainImageVK>& image, uint32_t index);
85
86 void WaitIdle() const;
87
88 SwapchainImplVK(const SwapchainImplVK&) = delete;
89
90 SwapchainImplVK& operator=(const SwapchainImplVK&) = delete;
91 };
92
93 } // namespace impeller
94
95 #endif // FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_SWAPCHAIN_IMPL_VK_H_
impeller::SwapchainImplVK::~SwapchainImplVK
~SwapchainImplVK()
Definition: swapchain_impl_vk.cc:302
impeller::SwapchainImplVK::AcquireResult::surface
std::unique_ptr< Surface > surface
Definition: swapchain_impl_vk.h:46
impeller::SwapchainImplVK
An instance of a swapchain that does NOT adapt to going out of date with the underlying surface....
Definition: swapchain_impl_vk.h:31
impeller::SwapchainImplVK::IsValid
bool IsValid() const
Definition: swapchain_impl_vk.cc:306
vk.h
impeller::SwapchainImplVK::GetContext
std::shared_ptr< Context > GetContext() const
Definition: swapchain_impl_vk.cc:335
impeller::SwapchainImplVK::AcquireResult::AcquireResult
AcquireResult(std::unique_ptr< Surface > p_surface)
Definition: swapchain_impl_vk.h:52
impeller::SwapchainImplVK::GetSurfaceFormat
vk::Format GetSurfaceFormat() const
Definition: swapchain_impl_vk.cc:327
impeller::SwapchainImplVK::Create
static std::shared_ptr< SwapchainImplVK > Create(const std::shared_ptr< Context > &context, vk::UniqueSurfaceKHR surface, vk::SwapchainKHR old_swapchain=VK_NULL_HANDLE, vk::SurfaceTransformFlagBitsKHR last_transform=vk::SurfaceTransformFlagBitsKHR::eIdentity)
Definition: swapchain_impl_vk.cc:140
impeller::SwapchainImplVK::AcquireResult::out_of_date
bool out_of_date
Definition: swapchain_impl_vk.h:47
impeller::SwapchainImplVK::AcquireResult::AcquireResult
AcquireResult(bool p_out_of_date=false)
Definition: swapchain_impl_vk.h:49
impeller::SwapchainImplVK::AcquireResult
Definition: swapchain_impl_vk.h:45
std
Definition: comparable.h:95
impeller::SwapchainImplVK::AcquireNextDrawable
AcquireResult AcquireNextDrawable()
Definition: swapchain_impl_vk.cc:339
impeller::SwapchainImplVK::DestroySwapchain
std::pair< vk::UniqueSurfaceKHR, vk::UniqueSwapchainKHR > DestroySwapchain()
Definition: swapchain_impl_vk.cc:318
impeller
Definition: aiks_context.cc:10
impeller::SwapchainImplVK::GetLastTransform
vk::SurfaceTransformFlagBitsKHR GetLastTransform() const
Definition: swapchain_impl_vk.cc:331