Flutter Impeller
impeller::KHRSwapchainVK 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 <khr_swapchain_vk.h>

Public Member Functions

 ~KHRSwapchainVK ()
 
bool IsValid () const
 
std::unique_ptr< SurfaceAcquireNextDrawable ()
 
vk::Format GetSurfaceFormat () const
 
void UpdateSurfaceSize (const ISize &size)
 Mark the current swapchain configuration as dirty, forcing it to be recreated on the next frame. More...
 

Static Public Member Functions

static std::shared_ptr< KHRSwapchainVKCreate (const std::shared_ptr< Context > &context, vk::UniqueSurfaceKHR surface, const ISize &size, bool enable_msaa=true)
 

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 khr_swapchain_vk.h.

Constructor & Destructor Documentation

◆ ~KHRSwapchainVK()

impeller::KHRSwapchainVK::~KHRSwapchainVK ( )
default

Member Function Documentation

◆ AcquireNextDrawable()

std::unique_ptr< Surface > impeller::KHRSwapchainVK::AcquireNextDrawable ( )

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

Definition at line 45 of file khr_swapchain_vk.cc.

45  {
46  if (!IsValid()) {
47  return nullptr;
48  }
49 
50  TRACE_EVENT0("impeller", __FUNCTION__);
51 
52  auto result = impl_->AcquireNextDrawable();
53  if (!result.out_of_date && size_ == impl_->GetSize()) {
54  return std::move(result.surface);
55  }
56 
57  TRACE_EVENT0("impeller", "RecreateSwapchain");
58 
59  // This swapchain implementation indicates that it is out of date. Tear it
60  // down and make a new one.
61  auto context = impl_->GetContext();
62  auto [surface, old_swapchain] = impl_->DestroySwapchain();
63 
64  auto new_impl = KHRSwapchainImplVK::Create(context, //
65  std::move(surface), //
66  size_, //
67  enable_msaa_, //
68  *old_swapchain //
69  );
70  if (!new_impl || !new_impl->IsValid()) {
71  VALIDATION_LOG << "Could not update swapchain.";
72  // The old swapchain is dead because we took its surface. This is
73  // unrecoverable.
74  impl_.reset();
75  return nullptr;
76  }
77  impl_ = std::move(new_impl);
78 
79  //----------------------------------------------------------------------------
80  /// We managed to recreate the swapchain in the new configuration. Try again.
81  ///
82  return AcquireNextDrawable();
83 }

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

◆ Create()

std::shared_ptr< KHRSwapchainVK > impeller::KHRSwapchainVK::Create ( const std::shared_ptr< Context > &  context,
vk::UniqueSurfaceKHR  surface,
const ISize size,
bool  enable_msaa = true 
)
static

Definition at line 13 of file khr_swapchain_vk.cc.

17  {
18  auto impl = KHRSwapchainImplVK::Create(context, std::move(surface), size,
19  enable_msaa);
20  if (!impl || !impl->IsValid()) {
21  VALIDATION_LOG << "Failed to create SwapchainVK implementation.";
22  return nullptr;
23  }
24  return std::shared_ptr<KHRSwapchainVK>(
25  new KHRSwapchainVK(std::move(impl), size, enable_msaa));
26 }

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

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

◆ GetSurfaceFormat()

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

Definition at line 85 of file khr_swapchain_vk.cc.

85  {
86  return IsValid() ? impl_->GetSurfaceFormat() : vk::Format::eUndefined;
87 }

References IsValid().

◆ IsValid()

bool impeller::KHRSwapchainVK::IsValid ( ) const

Definition at line 35 of file khr_swapchain_vk.cc.

35  {
36  return impl_ ? impl_->IsValid() : false;
37 }

Referenced by AcquireNextDrawable(), and GetSurfaceFormat().

◆ UpdateSurfaceSize()

void impeller::KHRSwapchainVK::UpdateSurfaceSize ( const ISize size)

Mark the current swapchain configuration as dirty, forcing it to be recreated on the next frame.

Definition at line 39 of file khr_swapchain_vk.cc.

39  {
40  // Update the size of the swapchain. On the next acquired drawable,
41  // the sizes may no longer match, forcing the swapchain to be recreated.
42  size_ = size;
43 }

The documentation for this class was generated from the following files:
impeller::KHRSwapchainVK::AcquireNextDrawable
std::unique_ptr< Surface > AcquireNextDrawable()
Definition: khr_swapchain_vk.cc:45
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:73
impeller::KHRSwapchainImplVK::Create
static std::shared_ptr< KHRSwapchainImplVK > Create(const std::shared_ptr< Context > &context, vk::UniqueSurfaceKHR surface, const ISize &size, bool enable_msaa=true, vk::SwapchainKHR old_swapchain=VK_NULL_HANDLE)
Definition: khr_swapchain_impl_vk.cc:119
impeller::KHRSwapchainVK::IsValid
bool IsValid() const
Definition: khr_swapchain_vk.cc:35