Flutter Engine
The Flutter Engine
Classes | Public Member Functions | Static Public Member Functions | List of all members
impeller::KHRSwapchainImplVK Class Referencefinal

An instance of a swapchain that does NOT adapt to going out of date with the underlying surface. Errors will be indicated when the next drawable is acquired from this implementation of the swapchain. If the error is due the swapchain going out of date, the caller must recreate another instance by optionally stealing this implementations guts. More...

#include <khr_swapchain_impl_vk.h>

Inheritance diagram for impeller::KHRSwapchainImplVK:

Classes

struct  AcquireResult
 

Public Member Functions

 ~KHRSwapchainImplVK ()
 
bool IsValid () const
 
AcquireResult AcquireNextDrawable ()
 
vk::Format GetSurfaceFormat () const
 
std::shared_ptr< ContextGetContext () const
 
std::pair< vk::UniqueSurfaceKHR, vk::UniqueSwapchainKHR > DestroySwapchain ()
 
const ISizeGetSize () const
 

Static Public Member Functions

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

Detailed Description

An instance of a swapchain that does NOT adapt to going out of date with the underlying surface. Errors will be indicated when the next drawable is acquired from this implementation of the swapchain. If the error is due the swapchain going out of date, the caller must recreate another instance by optionally stealing this implementations guts.

Definition at line 31 of file khr_swapchain_impl_vk.h.

Constructor & Destructor Documentation

◆ ~KHRSwapchainImplVK()

impeller::KHRSwapchainImplVK::~KHRSwapchainImplVK ( )

Definition at line 277 of file khr_swapchain_impl_vk.cc.

277 {
279}
std::pair< vk::UniqueSurfaceKHR, vk::UniqueSwapchainKHR > DestroySwapchain()

Member Function Documentation

◆ AcquireNextDrawable()

KHRSwapchainImplVK::AcquireResult impeller::KHRSwapchainImplVK::AcquireNextDrawable ( )

Wait on the host for the synchronizer fence.

Get the next image index.

Record all subsequent cmd buffers as part of the current frame.

Definition at line 314 of file khr_swapchain_impl_vk.cc.

314 {
315 auto context_strong = context_.lock();
316 if (!context_strong) {
317 return KHRSwapchainImplVK::AcquireResult{};
318 }
319
320 const auto& context = ContextVK::Cast(*context_strong);
321
322 current_frame_ = (current_frame_ + 1u) % synchronizers_.size();
323
324 const auto& sync = synchronizers_[current_frame_];
325
326 //----------------------------------------------------------------------------
327 /// Wait on the host for the synchronizer fence.
328 ///
329 if (!sync->WaitForFence(context.GetDevice())) {
330 VALIDATION_LOG << "Could not wait for fence.";
331 return KHRSwapchainImplVK::AcquireResult{};
332 }
333
334 //----------------------------------------------------------------------------
335 /// Get the next image index.
336 ///
337 auto [acq_result, index] = context.GetDevice().acquireNextImageKHR(
338 *swapchain_, // swapchain
339 1'000'000'000, // timeout (ns) 1000ms
340 *sync->render_ready, // signal semaphore
341 nullptr // fence
342 );
343
344 switch (acq_result) {
345 case vk::Result::eSuccess:
346 // Keep going.
347 break;
348 case vk::Result::eSuboptimalKHR:
349 case vk::Result::eErrorOutOfDateKHR:
350 // A recoverable error. Just say we are out of date.
351 return AcquireResult{true /* out of date */};
352 break;
353 default:
354 // An unrecoverable error.
355 VALIDATION_LOG << "Could not acquire next swapchain image: "
356 << vk::to_string(acq_result);
357 return AcquireResult{false /* out of date */};
358 }
359
360 if (index >= images_.size()) {
361 VALIDATION_LOG << "Swapchain returned an invalid image index.";
362 return KHRSwapchainImplVK::AcquireResult{};
363 }
364
365 /// Record all subsequent cmd buffers as part of the current frame.
366 context.GetGPUTracer()->MarkFrameStart();
367
368 auto image = images_[index % images_.size()];
369 uint32_t image_index = index;
370 return AcquireResult{SurfaceVK::WrapSwapchainImage(
371 transients_, // transients
372 image, // swapchain image
373 [weak_swapchain = weak_from_this(), image, image_index]() -> bool {
374 auto swapchain = weak_swapchain.lock();
375 if (!swapchain) {
376 return false;
377 }
378 return swapchain->Present(image, image_index);
379 } // swap callback
380 )};
381}
static ContextVK & Cast(Context &base)
Definition: backend_cast.h:13
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
VkSwapchainKHR swapchain
Definition: main.cc:64
sk_sp< const SkImage > image
Definition: SkRecords.h:269
static SkString to_string(int n)
Definition: nanobench.cpp:119
#define VALIDATION_LOG
Definition: validation.h:73

◆ Create()

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

Definition at line 118 of file khr_swapchain_impl_vk.cc.

123 {
124 return std::shared_ptr<KHRSwapchainImplVK>(new KHRSwapchainImplVK(
125 context, std::move(surface), size, enable_msaa, old_swapchain));
126}
VkSurfaceKHR surface
Definition: main.cc:49
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259

◆ DestroySwapchain()

std::pair< vk::UniqueSurfaceKHR, vk::UniqueSwapchainKHR > impeller::KHRSwapchainImplVK::DestroySwapchain ( )

Definition at line 297 of file khr_swapchain_impl_vk.cc.

297 {
298 WaitIdle();
299 is_valid_ = false;
300 synchronizers_.clear();
301 images_.clear();
302 context_.reset();
303 return {std::move(surface_), std::move(swapchain_)};
304}

◆ GetContext()

std::shared_ptr< Context > impeller::KHRSwapchainImplVK::GetContext ( ) const

Definition at line 310 of file khr_swapchain_impl_vk.cc.

310 {
311 return context_.lock();
312}

◆ GetSize()

const ISize & impeller::KHRSwapchainImplVK::GetSize ( ) const

Definition at line 281 of file khr_swapchain_impl_vk.cc.

281 {
282 return size_;
283}

◆ GetSurfaceFormat()

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

Definition at line 306 of file khr_swapchain_impl_vk.cc.

306 {
307 return surface_format_;
308}

◆ IsValid()

bool impeller::KHRSwapchainImplVK::IsValid ( ) const

Definition at line 285 of file khr_swapchain_impl_vk.cc.

285 {
286 return is_valid_;
287}

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