Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | List of all members
flutter_runner::VulkanSurfacePool Class Referencefinal

#include <vulkan_surface_pool.h>

Public Member Functions

 VulkanSurfacePool (vulkan::VulkanProvider &vulkan_provider, sk_sp< GrDirectContext > context)
 
 ~VulkanSurfacePool ()
 
std::unique_ptr< VulkanSurfaceCreateSurface (const SkISize &size)
 
std::unique_ptr< VulkanSurfaceAcquireSurface (const SkISize &size)
 
void SubmitSurface (std::unique_ptr< SurfaceProducerSurface > surface)
 
void AgeAndCollectOldBuffers ()
 
void ShrinkToFit ()
 

Static Public Attributes

static constexpr int kMaxSurfaces = 12
 
static constexpr int kMaxSurfaceAge = 3
 

Detailed Description

Definition at line 18 of file vulkan_surface_pool.h.

Constructor & Destructor Documentation

◆ VulkanSurfacePool()

flutter_runner::VulkanSurfacePool::VulkanSurfacePool ( vulkan::VulkanProvider vulkan_provider,
sk_sp< GrDirectContext context 
)

Definition at line 32 of file vulkan_surface_pool.cc.

34 : vulkan_provider_(vulkan_provider), context_(std::move(context)) {
35 FML_CHECK(context_ != nullptr);
36
37 zx_status_t status = fdio_service_connect(
38 "/svc/fuchsia.sysmem.Allocator",
39 sysmem_allocator_.NewRequest().TakeChannel().release());
40 sysmem_allocator_->SetDebugClientInfo(GetCurrentProcessName(),
42 FML_DCHECK(status == ZX_OK);
43
44 status = fdio_service_connect(
45 "/svc/fuchsia.ui.composition.Allocator",
46 flatland_allocator_.NewRequest().TakeChannel().release());
47 FML_DCHECK(status == ZX_OK);
48}
#define FML_CHECK(condition)
Definition logging.h:85
#define FML_DCHECK(condition)
Definition logging.h:103
static zx_koid_t GetCurrentProcessId()
static std::string GetCurrentProcessName()

◆ ~VulkanSurfacePool()

flutter_runner::VulkanSurfacePool::~VulkanSurfacePool ( )

Definition at line 50 of file vulkan_surface_pool.cc.

50{}

Member Function Documentation

◆ AcquireSurface()

std::unique_ptr< VulkanSurface > flutter_runner::VulkanSurfacePool::AcquireSurface ( const SkISize size)

Definition at line 52 of file vulkan_surface_pool.cc.

53 {
54 auto surface = GetCachedOrCreateSurface(size);
55
56 if (surface == nullptr) {
57 FML_LOG(ERROR) << "VulkanSurfaceProducer: Could not acquire surface";
58 return nullptr;
59 }
60
61 if (!surface->FlushSessionAcquireAndReleaseEvents()) {
62 FML_LOG(ERROR) << "VulkanSurfaceProducer: Could not flush acquire/release "
63 "events for buffer.";
64 return nullptr;
65 }
66
67 return surface;
68}
VkSurfaceKHR surface
Definition main.cc:49
#define FML_LOG(severity)
Definition logging.h:82
#define ERROR(message)

◆ AgeAndCollectOldBuffers()

void flutter_runner::VulkanSurfacePool::AgeAndCollectOldBuffers ( )

Definition at line 165 of file vulkan_surface_pool.cc.

165 {
166 TRACE_EVENT0("flutter", "VulkanSurfacePool::AgeAndCollectOldBuffers");
167
168 // Remove all surfaces that are no longer valid or are too old.
169 size_t size_before = available_surfaces_.size();
170 available_surfaces_.erase(
171 std::remove_if(available_surfaces_.begin(), available_surfaces_.end(),
172 [&](auto& surface) {
173 return !surface->IsValid() ||
174 surface->AdvanceAndGetAge() >= kMaxSurfaceAge;
175 }),
176 available_surfaces_.end());
177 TRACE_EVENT1("flutter", "AgeAndCollect", "aged surfaces",
178 (size_before - available_surfaces_.size()));
179
180 // Look for a surface that has both a larger |VkDeviceMemory| allocation
181 // than is necessary for its |VkImage|, and has a stable size history.
182 auto surface_to_remove_it = std::find_if(
183 available_surfaces_.begin(), available_surfaces_.end(),
184 [](const auto& surface) {
185 return surface->IsOversized() && surface->HasStableSizeHistory();
186 });
187 // If we found such a surface, then destroy it and cache a new one that only
188 // uses a necessary amount of memory.
189 if (surface_to_remove_it != available_surfaces_.end()) {
190 TRACE_EVENT_INSTANT0("flutter", "replacing surface with smaller one");
191 auto size = (*surface_to_remove_it)->GetSize();
192 available_surfaces_.erase(surface_to_remove_it);
193 auto new_surface = CreateSurface(size);
194 if (new_surface != nullptr) {
195 available_surfaces_.push_back(std::move(new_surface));
196 } else {
198 << "VulkanSurfaceProducer: Failed to create a new shrunk surface";
199 }
200 }
201
202 TraceStats();
203}
std::unique_ptr< VulkanSurface > CreateSurface(const SkISize &size)
static sk_sp< SkSurface > new_surface(int width, int height)
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
#define TRACE_EVENT0(category_group, name)
#define TRACE_EVENT_INSTANT0(category_group, name)
#define TRACE_EVENT1(category_group, name, arg1_name, arg1_val)

◆ CreateSurface()

std::unique_ptr< VulkanSurface > flutter_runner::VulkanSurfacePool::CreateSurface ( const SkISize size)

Definition at line 117 of file vulkan_surface_pool.cc.

118 {
119 TRACE_EVENT2("flutter", "VulkanSurfacePool::CreateSurface", "width",
120 size.width(), "height", size.height());
121 auto surface = std::make_unique<VulkanSurface>(
122 vulkan_provider_, sysmem_allocator_, flatland_allocator_, context_, size);
123 if (!surface->IsValid()) {
124 FML_LOG(ERROR) << "VulkanSurfaceProducer: Created surface is invalid";
125 return nullptr;
126 }
127 trace_surfaces_created_++;
128 return surface;
129}
#define TRACE_EVENT2(category_group, name, arg1_name, arg1_val, arg2_name, arg2_val)

◆ ShrinkToFit()

void flutter_runner::VulkanSurfacePool::ShrinkToFit ( )

Definition at line 205 of file vulkan_surface_pool.cc.

205 {
206 TRACE_EVENT0("flutter", "VulkanSurfacePool::ShrinkToFit");
207 // Reset all oversized surfaces in |available_surfaces_| so that the old
208 // surfaces and new surfaces don't exist at the same time at any point,
209 // reducing our peak memory footprint.
210 std::vector<SkISize> sizes_to_recreate;
211 for (auto& surface : available_surfaces_) {
212 if (surface->IsOversized()) {
213 sizes_to_recreate.push_back(surface->GetSize());
214 surface.reset();
215 }
216 }
217 available_surfaces_.erase(std::remove(available_surfaces_.begin(),
218 available_surfaces_.end(), nullptr),
219 available_surfaces_.end());
220 for (const auto& size : sizes_to_recreate) {
221 auto surface = CreateSurface(size);
222 if (surface != nullptr) {
223 available_surfaces_.push_back(std::move(surface));
224 } else {
226 << "VulkanSurfaceProducer: Failed to create resized surface";
227 }
228 }
229
230 TraceStats();
231}

◆ SubmitSurface()

void flutter_runner::VulkanSurfacePool::SubmitSurface ( std::unique_ptr< SurfaceProducerSurface surface)

Definition at line 92 of file vulkan_surface_pool.cc.

93 {
94 TRACE_EVENT0("flutter", "VulkanSurfacePool::SubmitSurface");
95
96 // This cast is safe because |VulkanSurface| is the only implementation of
97 // |SurfaceProducerSurface| for Flutter on Fuchsia. Additionally, it is
98 // required, because we need to access |VulkanSurface| specific information
99 // of the surface (such as the amount of VkDeviceMemory it contains).
100 auto vulkan_surface = std::unique_ptr<VulkanSurface>(
101 static_cast<VulkanSurface*>(p_surface.release()));
102 if (!vulkan_surface) {
103 return;
104 }
105
106 uintptr_t surface_key = reinterpret_cast<uintptr_t>(vulkan_surface.get());
107 auto insert_iterator = pending_surfaces_.insert(std::make_pair(
108 surface_key, // key
109 std::move(vulkan_surface) // value
110 ));
111 if (insert_iterator.second) {
112 insert_iterator.first->second->SignalWritesFinished(std::bind(
113 &VulkanSurfacePool::RecyclePendingSurface, this, surface_key));
114 }
115}

Member Data Documentation

◆ kMaxSurfaceAge

constexpr int flutter_runner::VulkanSurfacePool::kMaxSurfaceAge = 3
staticconstexpr

Definition at line 24 of file vulkan_surface_pool.h.

◆ kMaxSurfaces

constexpr int flutter_runner::VulkanSurfacePool::kMaxSurfaces = 12
staticconstexpr

Definition at line 22 of file vulkan_surface_pool.h.


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