Flutter Impeller
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< SurfaceAcquireNextDrawable ()
 
vk::Format GetSurfaceFormat () const
 

Static Public Member Functions

static std::shared_ptr< SwapchainVKCreate (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 24 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 31 of file swapchain_vk.cc.

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

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 12 of file swapchain_vk.cc.

14  {
15  auto impl = SwapchainImplVK::Create(context, std::move(surface));
16  if (!impl || !impl->IsValid()) {
17  return nullptr;
18  }
19  return std::shared_ptr<SwapchainVK>(new SwapchainVK(std::move(impl)));
20 }

References impeller::SwapchainImplVK::Create().

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

◆ GetSurfaceFormat()

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

Definition at line 70 of file swapchain_vk.cc.

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

References IsValid().

◆ IsValid()

bool impeller::SwapchainVK::IsValid ( ) const

Definition at line 27 of file swapchain_vk.cc.

27  {
28  return impl_ ? impl_->IsValid() : false;
29 }

Referenced by AcquireNextDrawable(), and GetSurfaceFormat().


The documentation for this class was generated from the following files:
impeller::SwapchainVK::IsValid
bool IsValid() const
Definition: swapchain_vk.cc:27
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:130
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:60
impeller::SwapchainVK::AcquireNextDrawable
std::unique_ptr< Surface > AcquireNextDrawable()
Definition: swapchain_vk.cc:31