7 #include "flutter/fml/trace_event.h"
14 : context_(
std::move(context)), desc_(desc), max_entries_(max_entries) {
19 for (
auto i = 0u; i < max_entries_; i++) {
20 auto texture = CreateTexture();
21 if (!texture->IsValid()) {
24 pool_.emplace_back(std::move(texture));
33 Lock lock(pool_mutex_);
37 auto entry = pool_.front();
46 fml::UniqueFD render_ready_fence) {
50 Lock lock(pool_mutex_);
51 pool_.push_back(
PoolEntry{std::move(texture), std::move(render_ready_fence)});
55 std::shared_ptr<AHBTextureSourceVK> AHBTexturePoolVK::CreateTexture()
const {
56 TRACE_EVENT0(
"impeller",
"CreateSwapchainTexture");
57 auto context = context_.lock();
63 auto ahb = std::make_unique<android::HardwareBuffer>(desc_);
64 if (!ahb->IsValid()) {
70 auto ahb_texture_source =
71 std::make_shared<AHBTextureSourceVK>(context, std::move(ahb),
true);
72 if (!ahb_texture_source->IsValid()) {
73 VALIDATION_LOG <<
"Could not create hardware buffer texture source for "
74 "swapchain image of size: "
79 return ahb_texture_source;
83 Lock lock(pool_mutex_);
87 void AHBTexturePoolVK::PerformGCLocked() {
88 while (!pool_.empty() && (pool_.size() > max_entries_)) {
PoolEntry Pop()
Pops an texture source from the pool. If the pool is empty, a new texture source is created and retur...
AHBTexturePoolVK(std::weak_ptr< Context > context, android::HardwareBufferDescriptor desc, size_t max_entries=3u)
Create a new (empty) texture pool.
void PerformGC()
Perform an explicit GC of the pool items. This happens implicitly when a texture source us pushed int...
bool IsValid() const
If the pool can create and pool hardware buffer backed texture sources. The only reason valid texture...
void Push(std::shared_ptr< AHBTextureSourceVK > texture, fml::UniqueFD render_ready_fence)
Push a popped texture back into the pool. This also performs a GC.
A descriptor use to specify hardware buffer allocations.
bool IsAllocatable() const
If hardware buffers can be created using this descriptor. Allocatable descriptors may still cause fai...