Flutter Engine
 
Loading...
Searching...
No Matches
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.sysmem2.Allocator",
39 sysmem_allocator_.NewRequest().TakeChannel().release());
40 sysmem_allocator_->SetDebugClientInfo(
41 std::move(fuchsia::sysmem2::AllocatorSetDebugClientInfoRequest{}
42 .set_name(GetCurrentProcessName())
43 .set_id(GetCurrentProcessId())));
44 FML_DCHECK(status == ZX_OK);
45
46 status = fdio_service_connect(
47 "/svc/fuchsia.ui.composition.Allocator",
48 flatland_allocator_.NewRequest().TakeChannel().release());
49 FML_DCHECK(status == ZX_OK);
50}
#define FML_CHECK(condition)
Definition logging.h:104
#define FML_DCHECK(condition)
Definition logging.h:122
static zx_koid_t GetCurrentProcessId()
static std::string GetCurrentProcessName()

References FML_CHECK, FML_DCHECK, flutter_runner::GetCurrentProcessId(), and flutter_runner::GetCurrentProcessName().

◆ ~VulkanSurfacePool()

flutter_runner::VulkanSurfacePool::~VulkanSurfacePool ( )

Definition at line 52 of file vulkan_surface_pool.cc.

52{}

Member Function Documentation

◆ AcquireSurface()

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

Definition at line 54 of file vulkan_surface_pool.cc.

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

References FML_LOG, and surface.

◆ AgeAndCollectOldBuffers()

void flutter_runner::VulkanSurfacePool::AgeAndCollectOldBuffers ( )

Definition at line 167 of file vulkan_surface_pool.cc.

167 {
168 TRACE_EVENT0("flutter", "VulkanSurfacePool::AgeAndCollectOldBuffers");
169
170 // Remove all surfaces that are no longer valid or are too old.
171 size_t size_before = available_surfaces_.size();
172 available_surfaces_.erase(
173 std::remove_if(available_surfaces_.begin(), available_surfaces_.end(),
174 [&](auto& surface) {
175 return !surface->IsValid() ||
176 surface->AdvanceAndGetAge() >= kMaxSurfaceAge;
177 }),
178 available_surfaces_.end());
179 TRACE_EVENT1("flutter", "AgeAndCollect", "aged surfaces",
180 (size_before - available_surfaces_.size()));
181
182 // Look for a surface that has both a larger |VkDeviceMemory| allocation
183 // than is necessary for its |VkImage|, and has a stable size history.
184 auto surface_to_remove_it = std::find_if(
185 available_surfaces_.begin(), available_surfaces_.end(),
186 [](const auto& surface) {
187 return surface->IsOversized() && surface->HasStableSizeHistory();
188 });
189 // If we found such a surface, then destroy it and cache a new one that only
190 // uses a necessary amount of memory.
191 if (surface_to_remove_it != available_surfaces_.end()) {
192 TRACE_EVENT_INSTANT0("flutter", "replacing surface with smaller one");
193 auto size = (*surface_to_remove_it)->GetSize();
194 available_surfaces_.erase(surface_to_remove_it);
195 auto new_surface = CreateSurface(size);
196 if (new_surface != nullptr) {
197 available_surfaces_.push_back(std::move(new_surface));
198 } else {
199 FML_LOG(ERROR)
200 << "VulkanSurfaceProducer: Failed to create a new shrunk surface";
201 }
202 }
203
204 TraceStats();
205}
std::unique_ptr< VulkanSurface > CreateSurface(const SkISize &size)
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all 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
#define TRACE_EVENT0(category_group, name)
#define TRACE_EVENT_INSTANT0(category_group, name)
#define TRACE_EVENT1(category_group, name, arg1_name, arg1_val)

References CreateSurface(), FML_LOG, surface, TRACE_EVENT0, TRACE_EVENT1, and TRACE_EVENT_INSTANT0.

◆ CreateSurface()

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

Definition at line 119 of file vulkan_surface_pool.cc.

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

References FML_LOG, surface, and TRACE_EVENT2.

Referenced by AgeAndCollectOldBuffers(), and ShrinkToFit().

◆ ShrinkToFit()

void flutter_runner::VulkanSurfacePool::ShrinkToFit ( )

Definition at line 207 of file vulkan_surface_pool.cc.

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

References CreateSurface(), FML_LOG, surface, and TRACE_EVENT0.

◆ SubmitSurface()

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

Definition at line 94 of file vulkan_surface_pool.cc.

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

References TRACE_EVENT0.

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: