| Flutter Impeller |

Public Member Functions | Static Public Member Functions | List of all members
impeller::AHBSwapchainImplVK Class Referencefinal

The implementation of a swapchain at a specific size. Resizes to the surface will cause the instance of the swapchain impl at that size to be discarded along with all its caches and transients. More...

`#include <ahb_swapchain_impl_vk.h>`

Inheritance diagram for impeller::AHBSwapchainImplVK:

## Public Member Functions
| ~AHBSwapchainImplVK ()
| AHBSwapchainImplVK (const AHBSwapchainImplVK &)=delete
AHBSwapchainImplVK & | operator= (const AHBSwapchainImplVK &)=delete
const ISize & | GetSize () const
bool | IsValid () const
const android::HardwareBufferDescriptor & | GetDescriptor () const
| Get the descriptor used to create the hardware buffers that will be displayed on the surface control. More...
std::unique_ptr< Surface > | AcquireNextDrawable ()
| Acquire the next surface that can be used to present to the swapchain. More...
void | AddFinalCommandBuffer (std::shared_ptr< CommandBuffer > cmd_buffer)

## Static Public Member Functions
static std::shared_ptr< AHBSwapchainImplVK > | Create (const std::weak_ptr< Context > &context, std::weak_ptr< android::SurfaceControl > surface_control, const CreateTransactionCB &cb, const ISize &size, bool enable_msaa)
| Create a swapchain of a specific size whose images will be presented to the provided surface control. More...

## Detailed Description

The implementation of a swapchain at a specific size. Resizes to the surface will cause the instance of the swapchain impl at that size to be discarded along with all its caches and transients.

Definition at line 50 of file ahb_swapchain_impl_vk.h.

## Constructor & Destructor Documentation

## ◆ ~AHBSwapchainImplVK()

impeller::AHBSwapchainImplVK::~AHBSwapchainImplVK | ( |  | ) |
| default

## ◆ AHBSwapchainImplVK()

impeller::AHBSwapchainImplVK::AHBSwapchainImplVK | ( | const AHBSwapchainImplVK & |  | ) |
| delete

Referenced by Create().

## Member Function Documentation

## ◆ AcquireNextDrawable()

std::unique_ptr< Surface > impeller::AHBSwapchainImplVK::AcquireNextDrawable | ( |  | ) |

Acquire the next surface that can be used to present to the swapchain.

Returns
  A surface if one can be created. If one cannot be created, it is likely due to resource exhaustion.

Definition at line 120 of file ahb_swapchain_impl_vk.cc.

120 {
121 auto context = transients_->GetContext().lock();
122 if (!context) {
123 return nullptr;
124 }
125
126 frame_index_ = (frame_index_ + 1) % kMaxPendingPresents;
127
128 if (!frame_data_[frame_index_]->WaitForFence(
129 ContextVK::Cast(*context).GetDevice())) {
130 return nullptr;
131 }
132
133 if (!is_valid_) {
134 return nullptr;
135 }
136
137 auto pool_entry = pool_->Pop();
138
139 if (!pool_entry.IsValid()) {
140 VALIDATION_LOG << "Could not create AHB texture source.";
141 return nullptr;
142 }
143
144 // Import the render ready semaphore that will block onscreen rendering until
145 // it is ready.
146 if (!ImportRenderReady(pool_entry.render_ready_fence, pool_entry.texture)) {
147 VALIDATION_LOG << "Could wait on render ready fence.";
148 return nullptr;
149 }
150
151 #if IMPELLER_DEBUG
152 if (context) {
153 ContextVK::Cast(*context).GetGPUTracer()->MarkFrameStart();
154 }
155 #endif // IMPELLER_DEBUG
156
157 auto surface = SurfaceVK::WrapSwapchainImage(
158 transients_, pool_entry.texture,
159 [weak = weak_from_this(), texture = pool_entry.texture]() {
160 auto thiz = weak.lock();
161 if (!thiz) {
162 VALIDATION_LOG << "Swapchain died before image could be presented.";
163 return false;
164 }
165 return thiz->Present(texture);
166 });
167
168 if (!surface) {
169 return nullptr;
170 }
171
172 return surface;
173 }
impeller::BackendCast< ContextVK, Context >::Cast
static ContextVK & Cast(Context &base)
Definition: backend_cast.h:13
impeller::ContextVK::GetDevice
const vk::Device & GetDevice() const
Definition: context_vk.cc:589
impeller::ContextVK::GetGPUTracer
std::shared_ptr< GPUTracerVK > GetGPUTracer() const
Definition: context_vk.cc:639
impeller::SurfaceVK::WrapSwapchainImage
static std::unique_ptr< SurfaceVK > WrapSwapchainImage(const std::shared_ptr< SwapchainTransientsVK > &transients, const std::shared_ptr< TextureSourceVK > &swapchain_image, SwapCallback swap_callback)
Wrap the swapchain image in a Surface, which provides the additional configuration required for usage...
Definition: surface_vk.cc:13
impeller::kMaxPendingPresents
static constexpr const size_t kMaxPendingPresents
Definition: ahb_swapchain_impl_vk.h:26
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:91

References impeller::BackendCast< ContextVK, Context >::Cast(), impeller::ContextVK::GetDevice(), impeller::ContextVK::GetGPUTracer(), impeller::kMaxPendingPresents, VALIDATION_LOG, and impeller::SurfaceVK::WrapSwapchainImage().

## ◆ AddFinalCommandBuffer()

void impeller::AHBSwapchainImplVK::AddFinalCommandBuffer | ( | std::shared_ptr< CommandBuffer > | cmd_buffer | ) |

Definition at line 222 of file ahb_swapchain_impl_vk.cc.

223 {
224 frame_data_[frame_index_]->final_cmd_buffer = std::move(cmd_buffer);
225 }

## ◆ Create()

std::shared_ptr< AHBSwapchainImplVK > impeller::AHBSwapchainImplVK::Create | ( | const std::weak_ptr< Context > & | context,
|  | std::weak_ptr< android::SurfaceControl > | surface_control,
|  | const CreateTransactionCB & | cb,
|  | const ISize & | size,
|  | bool | enable_msaa
| ) |  |
| static

Create a swapchain of a specific size whose images will be presented to the provided surface control.

Parameters

  [in] | context | The context whose allocators will be used to create swapchain image resources.
  [in] | surface_control | The surface control to which the swapchain images will be presented.
  [in] | size | The size of the swapchain images. This is constant for the lifecycle of the swapchain impl.
  [in] | enable_msaa | If the swapchain images will be presented using a render target that enables MSAA. This allows for additional caching of transients.

Returns
  A valid swapchain impl if one can be created. `nullptr` otherwise.

Definition at line 66 of file ahb_swapchain_impl_vk.cc.

71 {
72 auto impl = std::shared_ptr<AHBSwapchainImplVK>(new AHBSwapchainImplVK(
73 context, std::move(surface_control), cb, size, enable_msaa));
74 return impl->IsValid() ? impl : nullptr;
75 }
impeller::AHBSwapchainImplVK::AHBSwapchainImplVK
AHBSwapchainImplVK(const AHBSwapchainImplVK &)=delete

References AHBSwapchainImplVK().

Referenced by impeller::AHBSwapchainVK::UpdateSurfaceSize().

## ◆ GetDescriptor()

const android::HardwareBufferDescriptor & impeller::AHBSwapchainImplVK::GetDescriptor | ( |  | ) | const

Get the descriptor used to create the hardware buffers that will be displayed on the surface control.

Returns
  The descriptor.

Definition at line 115 of file ahb_swapchain_impl_vk.cc.

116 {
117 return desc_;
118 }

## ◆ GetSize()

const ISize & impeller::AHBSwapchainImplVK::GetSize | ( |  | ) | const

Returns
  The size of the swapchain images that will be displayed on the surface control.

Definition at line 107 of file ahb_swapchain_impl_vk.cc.

107 {
108 return desc_.size;
109 }
impeller::android::HardwareBufferDescriptor::size
ISize size
Definition: hardware_buffer.h:49

References impeller::android::HardwareBufferDescriptor::size.

## ◆ IsValid()

bool impeller::AHBSwapchainImplVK::IsValid | ( |  | ) | const

Returns
  If the swapchain impl is valid. If it is not, the instance must be discarded. There is no error recovery.

Definition at line 111 of file ahb_swapchain_impl_vk.cc.

111 {
112 return is_valid_;
113 }

## ◆ operator=()

AHBSwapchainImplVK& impeller::AHBSwapchainImplVK::operator= | ( | const AHBSwapchainImplVK & |  | ) |
| delete

The documentation for this class was generated from the following files:

- impeller/renderer/backend/vulkan/swapchain/ahb/ahb_swapchain_impl_vk.h
- impeller/renderer/backend/vulkan/swapchain/ahb/ahb_swapchain_impl_vk.cc