Flutter Engine
The Flutter Engine
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
6
7#include "flutter/fml/trace_event.h"
11#include "third_party/vulkan-deps/vulkan-headers/src/include/vulkan/vulkan_enums.hpp"
12
13namespace impeller {
14
18}
19
20AHBSwapchainVK::AHBSwapchainVK(const std::shared_ptr<Context>& context,
22 const vk::UniqueSurfaceKHR& surface,
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 const auto [caps_result, surface_caps] =
30 ContextVK::Cast(*context).GetPhysicalDevice().getSurfaceCapabilitiesKHR(
31 *surface);
32 if (caps_result == vk::Result::eSuccess) {
33 swapchain_image_count_ =
34 std::clamp(surface_caps.minImageCount + 1u, // preferred image count
35 surface_caps.minImageCount, // min count cannot be zero
36 surface_caps.maxImageCount == 0u
37 ? surface_caps.minImageCount + 1u
38 : surface_caps.maxImageCount // max zero means no limit
39 );
40 }
41
43}
44
46
47// |SwapchainVK|
49 return impl_ ? impl_->IsValid() : false;
50}
51
52// |SwapchainVK|
53std::unique_ptr<Surface> AHBSwapchainVK::AcquireNextDrawable() {
54 if (!IsValid()) {
55 return nullptr;
56 }
57
58 TRACE_EVENT0("impeller", __FUNCTION__);
59 return impl_->AcquireNextDrawable();
60}
61
62// |SwapchainVK|
64 return IsValid()
65 ? ToVKImageFormat(ToPixelFormat(impl_->GetDescriptor().format))
66 : vk::Format::eUndefined;
67}
68
69// |SwapchainVK|
71 if (impl_ && impl_->GetSize() == size) {
72 return;
73 }
74 TRACE_EVENT0("impeller", __FUNCTION__);
75 auto impl = AHBSwapchainImplVK::Create(context_, //
76 surface_control_, //
77 size, //
78 enable_msaa_, //
79 swapchain_image_count_ //
80 );
81 if (!impl || !impl->IsValid()) {
82 VALIDATION_LOG << "Could not resize swapchain to size: " << size;
83 return;
84 }
85 impl_ = std::move(impl);
86}
87
88} // namespace impeller
static unsigned clamp(SkFixed fx, int max)
static std::shared_ptr< 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)
Create a swapchain of a specific size whose images will be presented to the provided surface control.
static bool IsAvailableOnPlatform()
void UpdateSurfaceSize(const ISize &size) override
Mark the current swapchain configuration as dirty, forcing it to be recreated on the next frame.
bool IsValid() const override
vk::Format GetSurfaceFormat() const override
std::unique_ptr< Surface > AcquireNextDrawable() override
AHBSwapchainVK(const AHBSwapchainVK &)=delete
static ContextVK & Cast(Context &base)
Definition: backend_cast.h:13
vk::PhysicalDevice GetPhysicalDevice() const
Definition: context_vk.cc:546
GLFWwindow * window
Definition: main.cc:45
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
constexpr vk::Format ToVKImageFormat(PixelFormat format)
Definition: formats_vk.h:133
static PixelFormat ToPixelFormat(AHardwareBuffer_Format format)
def Format(template, **parameters)
Definition: emitter.py:13
Definition: ref_ptr.h:256
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:131
#define VALIDATION_LOG
Definition: validation.h:73
struct ANativeWindow ANativeWindow