| Flutter Impeller |

ahb_swapchain_vk.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "impeller/renderer/backend/vulkan/swapchain/ahb/ahb_swapchain_vk.h"
6
7 #include "flutter/fml/trace_event.h"
8 #include "impeller/renderer/backend/vulkan/context_vk.h"
9 #include "impeller/renderer/backend/vulkan/formats_vk.h"
10 #include "impeller/renderer/backend/vulkan/swapchain/ahb/ahb_formats.h"
11 #include "third_party/vulkan-deps/vulkan-headers/src/include/vulkan/vulkan_enums.hpp"
12
13 namespace impeller {
14
15 bool AHBSwapchainVK::IsAvailableOnPlatform() {
16 return android::SurfaceControl::IsAvailableOnPlatform() &&
17 android::HardwareBuffer::IsAvailableOnPlatform();
18 }
19
20 AHBSwapchainVK::AHBSwapchainVK(const std::shared_ptr<Context>& context,
21 ANativeWindow* window,
22 const CreateTransactionCB& cb,
23 const ISize& size,
24 bool enable_msaa)
25 : context_(context),
26 surface_control_(
27 std::make_shared<android::SurfaceControl>(window, "ImpellerSurface")),
28 enable_msaa_(enable_msaa),
29 cb_(cb) {
30 UpdateSurfaceSize(size);
31 }
32
33 AHBSwapchainVK::~AHBSwapchainVK() = default;
34
35 // |SwapchainVK|
36 bool AHBSwapchainVK::IsValid() const {
37 return impl_ ? impl_->IsValid() : false;
38 }
39
40 // |SwapchainVK|
41 std::unique_ptr<Surface> AHBSwapchainVK::AcquireNextDrawable() {
42 if (!IsValid()) {
43 return nullptr;
44 }
45
46 TRACE_EVENT0("impeller", __FUNCTION__);
47 return impl_->AcquireNextDrawable();
48 }
49
50 // |SwapchainVK|
51 vk::Format AHBSwapchainVK::GetSurfaceFormat() const {
52 return IsValid()
53 ? ToVKImageFormat(ToPixelFormat(impl_->GetDescriptor().format))
54 : vk::Format::eUndefined;
55 }
56
57 // |SwapchainVK|
58 void AHBSwapchainVK::AddFinalCommandBuffer(
59 std::shared_ptr<CommandBuffer> cmd_buffer) const {
60 return impl_->AddFinalCommandBuffer(cmd_buffer);
61 }
62
63 // |SwapchainVK|
64 void AHBSwapchainVK::UpdateSurfaceSize(const ISize& size) {
65 if (impl_ && impl_->GetSize() == size) {
66 return;
67 }
68 TRACE_EVENT0("impeller", __FUNCTION__);
69 auto impl = AHBSwapchainImplVK::Create(context_, //
70 surface_control_, //
71 cb_, //
72 size, //
73 enable_msaa_ //
74 );
75 if (!impl || !impl->IsValid()) {
76 VALIDATION_LOG << "Could not resize swapchain to size: " << size;
77 return;
78 }
79 impl_ = std::move(impl);
80 }
81
82 } // namespace impeller
ahb_formats.h
ahb_swapchain_vk.h
impeller::AHBSwapchainImplVK::Create
static std::shared_ptr< AHBSwapchainImplVK > Create(const std::weak_ptr< Context > &context, std::weak_ptr< android::SurfaceControl > surface_control, const CreateTransactionCB &cb, const ISize &size, bool enable_msaa)
Create a swapchain of a specific size whose images will be presented to the provided surface control.
Definition: ahb_swapchain_impl_vk.cc:66
impeller::AHBSwapchainVK::IsAvailableOnPlatform
static bool IsAvailableOnPlatform()
Definition: ahb_swapchain_vk.cc:15
impeller::AHBSwapchainVK::UpdateSurfaceSize
void UpdateSurfaceSize(const ISize &size) override
Mark the current swapchain configuration as dirty, forcing it to be recreated on the next frame.
Definition: ahb_swapchain_vk.cc:64
impeller::AHBSwapchainVK::IsValid
bool IsValid() const override
Definition: ahb_swapchain_vk.cc:36
impeller::AHBSwapchainVK::AddFinalCommandBuffer
void AddFinalCommandBuffer(std::shared_ptr< CommandBuffer > cmd_buffer) const override
Definition: ahb_swapchain_vk.cc:58
impeller::AHBSwapchainVK::GetSurfaceFormat
vk::Format GetSurfaceFormat() const override
Definition: ahb_swapchain_vk.cc:51
impeller::AHBSwapchainVK::~AHBSwapchainVK
~AHBSwapchainVK() override
impeller::AHBSwapchainVK::AcquireNextDrawable
std::unique_ptr< Surface > AcquireNextDrawable() override
Definition: ahb_swapchain_vk.cc:41
impeller::AHBSwapchainVK::AHBSwapchainVK
AHBSwapchainVK(const AHBSwapchainVK &)=delete
impeller::android::HardwareBuffer::IsAvailableOnPlatform
static bool IsAvailableOnPlatform()
Definition: hardware_buffer.cc:107
impeller::android::SurfaceControl::IsAvailableOnPlatform
static bool IsAvailableOnPlatform()
Definition: surface_control.cc:50
formats_vk.h
impeller
Definition: allocation.cc:12
impeller::CreateTransactionCB
std::function< android::SurfaceTransaction()> CreateTransactionCB
Definition: ahb_swapchain_impl_vk.h:24
impeller::ToPixelFormat
constexpr PixelFormat ToPixelFormat(vk::Format format)
Definition: formats_vk.h:185
impeller::ToVKImageFormat
constexpr vk::Format ToVKImageFormat(PixelFormat format)
Definition: formats_vk.h:146
std
Definition: comparable.h:95
context_vk.h
impeller::TSize
Definition: size.h:25
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:91