| Flutter Impeller |

ahb_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_AHB_AHB_SWAPCHAIN_IMPL_VK_H_
6 #define FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_SWAPCHAIN_AHB_AHB_SWAPCHAIN_IMPL_VK_H_
7
8 #include <memory>
9
10 #include "flutter/fml/closure.h"
11 #include "flutter/fml/synchronization/semaphore.h"
12 #include "impeller/base/thread.h"
13 #include "impeller/renderer/backend/vulkan/android/ahb_texture_source_vk.h"
14 #include "impeller/renderer/backend/vulkan/swapchain/ahb/ahb_texture_pool_vk.h"
15 #include "impeller/renderer/backend/vulkan/swapchain/ahb/external_fence_vk.h"
16 #include "impeller/renderer/backend/vulkan/swapchain/swapchain_transients_vk.h"
17 #include "impeller/renderer/surface.h"
18 #include "impeller/toolkit/android/hardware_buffer.h"
19 #include "impeller/toolkit/android/surface_control.h"
20
21 namespace impeller {
22
23 //------------------------------------------------------------------------------
24 /// @brief The implementation of a swapchain at a specific size. Resizes to
25 /// the surface will cause the instance of the swapchain impl at
26 /// that size to be discarded along with all its caches and
27 /// transients.
28 ///
29 class AHBSwapchainImplVK final
30 : public std::enable_shared_from_this<AHBSwapchainImplVK> {
31 public:
32 //----------------------------------------------------------------------------
33 /// @brief Create a swapchain of a specific size whose images will be
34 /// presented to the provided surface control.
35 ///
36 /// @param[in] context The context whose allocators will be used to
37 /// create swapchain image resources.
38 /// @param[in] surface_control The surface control to which the swapchain
39 /// images will be presented.
40 /// @param[in] size The size of the swapchain images. This is
41 /// constant for the lifecycle of the swapchain
42 /// impl.
43 /// @param[in] enable_msaa If the swapchain images will be presented
44 /// using a render target that enables MSAA. This
45 /// allows for additional caching of transients.
46 ///
47 /// @return A valid swapchain impl if one can be created. `nullptr`
48 /// otherwise.
49 ///
50 static std::shared_ptr<AHBSwapchainImplVK> Create(
51 const std::weak_ptr<Context>& context,
52 std::weak_ptr<android::SurfaceControl> surface_control,
53 const ISize& size,
54 bool enable_msaa,
55 size_t swapchain_image_count);
56
57 ~AHBSwapchainImplVK();
58
59 AHBSwapchainImplVK(const AHBSwapchainImplVK&) = delete;
60
61 AHBSwapchainImplVK& operator=(const AHBSwapchainImplVK&) = delete;
62
63 //----------------------------------------------------------------------------
64 /// @return The size of the swapchain images that will be displayed on the
65 /// surface control.
66 ///
67 const ISize& GetSize() const;
68
69 //----------------------------------------------------------------------------
70 /// @return If the swapchain impl is valid. If it is not, the instance
71 /// must be discarded. There is no error recovery.
72 ///
73 bool IsValid() const;
74
75 //----------------------------------------------------------------------------
76 /// @brief Get the descriptor used to create the hardware buffers that
77 /// will be displayed on the surface control.
78 ///
79 /// @return The descriptor.
80 ///
81 const android::HardwareBufferDescriptor& GetDescriptor() const;
82
83 //----------------------------------------------------------------------------
84 /// @brief Acquire the next surface that can be used to present to the
85 /// swapchain.
86 ///
87 /// @return A surface if one can be created. If one cannot be created, it
88 /// is likely due to resource exhaustion.
89 ///
90 std::unique_ptr<Surface> AcquireNextDrawable();
91
92 private:
93 using AutoSemaSignaler = std::shared_ptr<fml::ScopedCleanupClosure>;
94
95 std::weak_ptr<android::SurfaceControl> surface_control_;
96 android::HardwareBufferDescriptor desc_;
97 std::shared_ptr<AHBTexturePoolVK> pool_;
98 std::shared_ptr<SwapchainTransientsVK> transients_;
99 // In C++20, this mutex can be replaced by the shared pointer specialization
100 // of std::atomic.
101 Mutex currently_displayed_texture_mutex_;
102 std::shared_ptr<AHBTextureSourceVK> currently_displayed_texture_
103 IPLR_GUARDED_BY(currently_displayed_texture_mutex_);
104 std::shared_ptr<fml::Semaphore> pending_presents_;
105 bool is_valid_ = false;
106
107 explicit AHBSwapchainImplVK(
108 const std::weak_ptr<Context>& context,
109 std::weak_ptr<android::SurfaceControl> surface_control,
110 const ISize& size,
111 bool enable_msaa,
112 size_t swapchain_image_count);
113
114 bool Present(const AutoSemaSignaler& signaler,
115 const std::shared_ptr<AHBTextureSourceVK>& texture);
116
117 vk::UniqueSemaphore CreateRenderReadySemaphore(
118 const std::shared_ptr<fml::UniqueFD>& fd) const;
119
120 bool SubmitWaitForRenderReady(
121 const std::shared_ptr<fml::UniqueFD>& render_ready_fence,
122 const std::shared_ptr<AHBTextureSourceVK>& texture) const;
123
124 std::shared_ptr<ExternalFenceVK> SubmitSignalForPresentReady(
125 const std::shared_ptr<AHBTextureSourceVK>& texture) const;
126
127 void OnTextureUpdatedOnSurfaceControl(
128 const AutoSemaSignaler& signaler,
129 std::shared_ptr<AHBTextureSourceVK> texture,
130 ASurfaceTransactionStats* stats);
131 };
132
133 } // namespace impeller
134
135 #endif // FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_SWAPCHAIN_AHB_AHB_SWAPCHAIN_IMPL_VK_H_
hardware_buffer.h
impeller::AHBSwapchainImplVK::GetDescriptor
const android::HardwareBufferDescriptor & GetDescriptor() const
Get the descriptor used to create the hardware buffers that will be displayed on the surface control.
Definition: ahb_swapchain_impl_vk.cc:84
impeller::AHBSwapchainImplVK::operator=
AHBSwapchainImplVK & operator=(const AHBSwapchainImplVK &)=delete
impeller::AHBSwapchainImplVK::AcquireNextDrawable
std::unique_ptr< Surface > AcquireNextDrawable()
Acquire the next surface that can be used to present to the swapchain.
Definition: ahb_swapchain_impl_vk.cc:89
surface_control.h
swapchain_transients_vk.h
impeller::AHBSwapchainImplVK
The implementation of a swapchain at a specific size. Resizes to the surface will cause the instance ...
Definition: ahb_swapchain_impl_vk.h:29
impeller::AHBSwapchainImplVK::Create
static std::shared_ptr< AHBSwapchainImplVK > Create(const std::weak_ptr< Context > &context, std::weak_ptr< android::SurfaceControl > surface_control, const ISize &size, bool enable_msaa, size_t swapchain_image_count)
Create a swapchain of a specific size whose images will be presented to the provided surface control.
Definition: ahb_swapchain_impl_vk.cc:43
external_fence_vk.h
surface.h
impeller::AHBSwapchainImplVK::AHBSwapchainImplVK
AHBSwapchainImplVK(const AHBSwapchainImplVK &)=delete
impeller::TSize
Definition: size.h:19
impeller::android::HardwareBufferDescriptor
A descriptor use to specify hardware buffer allocations.
Definition: hardware_buffer.h:47
ahb_texture_source_vk.h
impeller::AHBSwapchainImplVK::~AHBSwapchainImplVK
~AHBSwapchainImplVK()
impeller::AHBSwapchainImplVK::GetSize
const ISize & GetSize() const
Definition: ahb_swapchain_impl_vk.cc:76
ahb_texture_pool_vk.h
impeller::AHBSwapchainImplVK::IsValid
bool IsValid() const
Definition: ahb_swapchain_impl_vk.cc:80
thread.h
impeller
Definition: aiks_blend_unittests.cc:18