| Flutter Impeller |

Public Member Functions | Static Public Member Functions | List of all members
impeller::SwapchainVK Class Reference

A swapchain that adapts to the underlying surface going out of date. If the caller cannot acquire the next drawable, it is due to an unrecoverable error and the swapchain must be recreated with a new surface. More...

`#include <swapchain_vk.h>`

## Public Member Functions
| ~SwapchainVK ()
bool | IsValid () const
std::unique_ptr< Surface > | AcquireNextDrawable ()
vk::Format | GetSurfaceFormat () const

## Static Public Member Functions
static std::shared_ptr< SwapchainVK > | Create (const std::shared_ptr< Context > &context, vk::UniqueSurfaceKHR surface)

## Detailed Description

A swapchain that adapts to the underlying surface going out of date. If the caller cannot acquire the next drawable, it is due to an unrecoverable error and the swapchain must be recreated with a new surface.

Definition at line 25 of file swapchain_vk.h.

## Constructor & Destructor Documentation

## ◆ ~SwapchainVK()

impeller::SwapchainVK::~SwapchainVK | ( |  | ) |
| default

## Member Function Documentation

## ◆ AcquireNextDrawable()

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

We managed to recreate the swapchain in the new configuration. Try again.

Definition at line 33 of file swapchain_vk.cc.

33 {
34 if (!IsValid()) {
35 return nullptr;
36 }
37
38 TRACE_EVENT0("impeller", __FUNCTION__);
39
40 auto result = impl_->AcquireNextDrawable();
41 if (!result.out_of_date) {
42 return std::move(result.surface);
43 }
44
45 TRACE_EVENT0("impeller", "RecreateSwapchain");
46
47 // This swapchain implementation indicates that it is out of date. Tear it
48 // down and make a new one.
49 auto context = impl_->GetContext();
50 auto [surface, old_swapchain] = impl_->DestroySwapchain();
51
52 auto new_impl = SwapchainImplVK::Create(context, //
53 std::move(surface), //
54 *old_swapchain, //
55 impl_->GetLastTransform() //
56 );
57 if (!new_impl || !new_impl->IsValid()) {
58 VALIDATION_LOG << "Could not update swapchain.";
59 // The old swapchain is dead because we took its surface. This is
60 // unrecoverable.
61 impl_.reset();
62 return nullptr;
63 }
64 impl_ = std::move(new_impl);
65
66 //----------------------------------------------------------------------------
67 /// We managed to recreate the swapchain in the new configuration. Try again.
68 ///
69 return AcquireNextDrawable();
70 }

References impeller::SwapchainImplVK::Create(), IsValid(), and VALIDATION_LOG.

## ◆ Create()

std::shared_ptr< SwapchainVK > impeller::SwapchainVK::Create | ( | const std::shared_ptr< Context > & | context,
|  | vk::UniqueSurfaceKHR | surface
| ) |  |
| static

Definition at line 13 of file swapchain_vk.cc.

15 {
16 auto impl = SwapchainImplVK::Create(context, std::move(surface));
17 if (!impl || !impl->IsValid()) {
18 VALIDATION_LOG << "Failed to create SwapchainVK implementation.";
19 return nullptr;
20 }
21 return std::shared_ptr<SwapchainVK>(new SwapchainVK(std::move(impl)));
22 }

References impeller::SwapchainImplVK::Create(), and VALIDATION_LOG.

Referenced by impeller::SurfaceContextVK::SetWindowSurface().

## ◆ GetSurfaceFormat()

vk::Format impeller::SwapchainVK::GetSurfaceFormat | ( |  | ) | const

Definition at line 72 of file swapchain_vk.cc.

72 {
73 return IsValid() ? impl_->GetSurfaceFormat() : vk::Format::eUndefined;
74 }

References IsValid().

## ◆ IsValid()

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

Definition at line 29 of file swapchain_vk.cc.

29 {
30 return impl_ ? impl_->IsValid() : false;
31 }

Referenced by AcquireNextDrawable(), and GetSurfaceFormat().

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

- impeller/renderer/backend/vulkan/swapchain_vk.h
- impeller/renderer/backend/vulkan/swapchain_vk.cc

impeller::SwapchainVK::IsValid
bool IsValid() const
Definition: swapchain_vk.cc:29
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
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:67
impeller::SwapchainVK::AcquireNextDrawable
std::unique_ptr< Surface > AcquireNextDrawable()
Definition: swapchain_vk.cc:33