Flutter Engine
The Flutter Engine
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
12#if FML_OS_ANDROID
14#endif // FML_OS_ANDROID
15
16namespace impeller {
17
18std::shared_ptr<SwapchainVK> SwapchainVK::Create(
19 const std::shared_ptr<Context>& context,
20 vk::UniqueSurfaceKHR surface,
21 const ISize& size,
22 bool enable_msaa) {
23 auto swapchain = std::shared_ptr<KHRSwapchainVK>(
24 new KHRSwapchainVK(context, std::move(surface), size, enable_msaa));
25 if (!swapchain->IsValid()) {
26 VALIDATION_LOG << "Could not create valid swapchain.";
27 return nullptr;
28 }
29 return swapchain;
30}
31
32#if FML_OS_ANDROID
33std::shared_ptr<SwapchainVK> SwapchainVK::Create(
34 const std::shared_ptr<Context>& context,
35 ANativeWindow* p_window,
36 bool enable_msaa) {
37 TRACE_EVENT0("impeller", "CreateAndroidSwapchain");
38 if (!context) {
39 return nullptr;
40 }
41
42 android::NativeWindow window(p_window);
43 if (!window.IsValid()) {
44 return nullptr;
45 }
46
47 vk::AndroidSurfaceCreateInfoKHR surface_info;
48 surface_info.setWindow(window.GetHandle());
49 auto [result, surface] =
50 ContextVK::Cast(*context).GetInstance().createAndroidSurfaceKHRUnique(
51 surface_info);
52 if (result != vk::Result::eSuccess) {
53 VALIDATION_LOG << "Could not create KHR Android Surface: "
55 return nullptr;
56 }
57
58 // TODO(148139): https://github.com/flutter/flutter/issues/148139 sync issues
59 // on present.
60 if constexpr (false) {
61 // TODO(147533): AHB swapchains on emulators are not functional.
62 const auto emulator =
63 ContextVK::Cast(*context).GetDriverInfo()->IsEmulator();
64
65 // Try AHB swapchains first.
66 if (!emulator && AHBSwapchainVK::IsAvailableOnPlatform()) {
67 auto ahb_swapchain = std::shared_ptr<AHBSwapchainVK>(new AHBSwapchainVK(
68 context, //
69 window.GetHandle(), //
70 surface, //
71 window.GetSize(), //
72 enable_msaa //
73 ));
74
75 if (ahb_swapchain->IsValid()) {
76 return ahb_swapchain;
77 } else {
79 << "Could not create AHB swapchain. Falling back to KHR variant.";
80 }
81 }
82 }
83
84 // Fallback to KHR swapchains if AHB swapchains aren't available.
85 return Create(context, std::move(surface), window.GetSize(), enable_msaa);
86}
87#endif // FML_OS_ANDROID
88
89SwapchainVK::SwapchainVK() = default;
90
92
93} // namespace impeller
static bool IsAvailableOnPlatform()
static ContextVK & Cast(Context &base)
Definition: backend_cast.h:13
const std::unique_ptr< DriverInfoVK > & GetDriverInfo() const
Definition: context_vk.cc:625
vk::Instance GetInstance() const
Definition: context_vk.cc:509
A swapchain implemented backed by VK_KHR_swapchain and VK_KHR_surface.
static std::shared_ptr< SwapchainVK > Create(const std::shared_ptr< Context > &context, vk::UniqueSurfaceKHR surface, const ISize &size, bool enable_msaa=true)
Definition: swapchain_vk.cc:18
VkSwapchainKHR swapchain
Definition: main.cc:64
GLFWwindow * window
Definition: main.cc:45
VkSurfaceKHR surface
Definition: main.cc:49
GAsyncResult * result
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
static SkString to_string(int n)
Definition: nanobench.cpp:119
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:131
#define VALIDATION_LOG
Definition: validation.h:73
struct ANativeWindow ANativeWindow