7 #include "flutter/fml/build_config.h"
8 #include "flutter/fml/trace_event.h"
14 KHRSwapchainVK::KHRSwapchainVK(
const std::shared_ptr<Context>& context,
15 vk::UniqueSurfaceKHR surface,
18 : size_(size), enable_msaa_(enable_msaa) {
24 if (!impl || !impl->IsValid()) {
28 impl_ = std::move(impl);
31 KHRSwapchainVK::~KHRSwapchainVK() =
default;
33 bool KHRSwapchainVK::IsValid()
const {
34 return impl_ ? impl_->IsValid() :
false;
37 void KHRSwapchainVK::UpdateSurfaceSize(
const ISize& size) {
43 void KHRSwapchainVK::AddFinalCommandBuffer(
44 std::shared_ptr<CommandBuffer> cmd_buffer)
const {
45 impl_->AddFinalCommandBuffer(std::move(cmd_buffer));
48 std::unique_ptr<Surface> KHRSwapchainVK::AcquireNextDrawable() {
49 return AcquireNextDrawable(0u);
52 std::unique_ptr<Surface> KHRSwapchainVK::AcquireNextDrawable(
53 size_t resize_retry_count) {
58 TRACE_EVENT0(
"impeller", __FUNCTION__);
60 auto result = impl_->AcquireNextDrawable();
61 if (!result.out_of_date && size_ == impl_->GetSize()) {
62 return std::move(result.surface);
74 constexpr
const size_t kMaxResizeAttempts = 3u;
75 if (resize_retry_count == kMaxResizeAttempts) {
76 VALIDATION_LOG <<
"Attempted to resize the swapchain" << kMaxResizeAttempts
77 <<
" time unsuccessfully. This platform likely doesn't "
78 "support returning the current swapchain extents and "
79 "must recreate the swapchain using the actual size.";
83 size_ = impl_->GetCurrentUnderlyingSurfaceSize().value_or(size_);
86 TRACE_EVENT0(
"impeller",
"RecreateSwapchain");
90 auto context = impl_->GetContext();
91 auto [surface, old_swapchain] = impl_->DestroySwapchain();
99 if (!new_impl || !new_impl->IsValid()) {
106 impl_ = std::move(new_impl);
111 return AcquireNextDrawable(resize_retry_count + 1);
114 vk::Format KHRSwapchainVK::GetSurfaceFormat()
const {
115 return IsValid() ? impl_->GetSurfaceFormat() : vk::Format::eUndefined;
ScopedObject< Object > Create(CtorArgs &&... args)