Flutter Impeller
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
 
AHBSwapchainImplVKoperator= (const AHBSwapchainImplVK &)=delete
 
const ISizeGetSize () const
 
bool IsValid () const
 
const android::HardwareBufferDescriptorGetDescriptor () const
 Get the descriptor used to create the hardware buffers that will be displayed on the surface control. More...
 
std::unique_ptr< SurfaceAcquireNextDrawable ()
 Acquire the next surface that can be used to present to the swapchain. More...
 

Static Public Member Functions

static std::shared_ptr< AHBSwapchainImplVKCreate (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. 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 29 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 89 of file ahb_swapchain_impl_vk.cc.

89  {
90  {
91  TRACE_EVENT0("impeller", "CompositorPendingWait");
92  if (!pending_presents_->Wait()) {
93  return nullptr;
94  }
95  }
96 
97  AutoSemaSignaler auto_sema_signaler =
98  std::make_shared<fml::ScopedCleanupClosure>(
99  [sema = pending_presents_]() { sema->Signal(); });
100 
101  if (!is_valid_) {
102  return nullptr;
103  }
104 
105  auto pool_entry = pool_->Pop();
106 
107  if (!pool_entry.IsValid()) {
108  VALIDATION_LOG << "Could not create AHB texture source.";
109  return nullptr;
110  }
111 
112  auto context = transients_->GetContext().lock();
113  if (context) {
114  ContextVK::Cast(*context).GetGPUTracer()->MarkFrameStart();
115  }
116 
117  // Ask the GPU to wait for the render ready semaphore to be signaled before
118  // performing rendering operations.
119  if (!SubmitWaitForRenderReady(pool_entry.render_ready_fence,
120  pool_entry.texture)) {
121  VALIDATION_LOG << "Could not submit a command to the GPU to wait on render "
122  "readiness.";
123  return nullptr;
124  }
125 
126  auto surface = SurfaceVK::WrapSwapchainImage(
127  transients_, pool_entry.texture,
128  [signaler = auto_sema_signaler, weak = weak_from_this(),
129  texture = pool_entry.texture]() {
130  auto thiz = weak.lock();
131  if (!thiz) {
132  VALIDATION_LOG << "Swapchain died before image could be presented.";
133  return false;
134  }
135  return thiz->Present(signaler, texture);
136  });
137 
138  if (!surface) {
139  return nullptr;
140  }
141 
142  return surface;
143 }

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

◆ Create()

std::shared_ptr< AHBSwapchainImplVK > impeller::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 
)
static

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

Parameters
[in]contextThe context whose allocators will be used to create swapchain image resources.
[in]surface_controlThe surface control to which the swapchain images will be presented.
[in]sizeThe size of the swapchain images. This is constant for the lifecycle of the swapchain impl.
[in]enable_msaaIf 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 43 of file ahb_swapchain_impl_vk.cc.

48  {
49  auto impl = std::shared_ptr<AHBSwapchainImplVK>(
50  new AHBSwapchainImplVK(context, std::move(surface_control), size,
51  enable_msaa, swapchain_image_count));
52  return impl->IsValid() ? impl : nullptr;
53 }

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 84 of file ahb_swapchain_impl_vk.cc.

85  {
86  return desc_;
87 }

◆ 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 76 of file ahb_swapchain_impl_vk.cc.

76  {
77  return desc_.size;
78 }

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 80 of file ahb_swapchain_impl_vk.cc.

80  {
81  return is_valid_;
82 }

◆ operator=()

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

The documentation for this class was generated from the following files:
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::AHBSwapchainImplVK::AHBSwapchainImplVK
AHBSwapchainImplVK(const AHBSwapchainImplVK &)=delete
impeller::ContextVK::GetGPUTracer
std::shared_ptr< GPUTracerVK > GetGPUTracer() const
Definition: context_vk.cc:568
impeller::android::HardwareBufferDescriptor::size
ISize size
Definition: hardware_buffer.h:49
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:73
impeller::BackendCast< ContextVK, Context >::Cast
static ContextVK & Cast(Context &base)
Definition: backend_cast.h:13