Flutter Engine
 
Loading...
Searching...
No Matches
impeller::AHBTexturePoolVK Class Reference

Maintains a bounded pool of hardware buffer backed texture sources that can be used as swapchain images. More...

#include <ahb_texture_pool_vk.h>

Classes

struct  PoolEntry
 

Public Member Functions

 AHBTexturePoolVK (std::weak_ptr< Context > context, android::HardwareBufferDescriptor desc)
 Create a new (empty) texture pool.
 
 ~AHBTexturePoolVK ()
 
 AHBTexturePoolVK (const AHBTexturePoolVK &)=delete
 
AHBTexturePoolVKoperator= (const AHBTexturePoolVK &)=delete
 
bool IsValid () const
 If the pool can create and pool hardware buffer backed texture sources. The only reason valid textures cannot be obtained from a valid pool is because of resource exhaustion.
 
PoolEntry Pop ()
 Pops an texture source from the pool. If the pool is empty, a new texture source is created and returned.
 
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.
 

Detailed Description

Maintains a bounded pool of hardware buffer backed texture sources that can be used as swapchain images.

The number of cached entries in the texture pool is capped to a caller specified value.

If a previously cached entry cannot be obtained from the pool, a new entry is created. The only case where a valid texture source cannot be obtained is due to resource exhaustion.

Pools are thread-safe.

Definition at line 29 of file ahb_texture_pool_vk.h.

Constructor & Destructor Documentation

◆ AHBTexturePoolVK() [1/2]

impeller::AHBTexturePoolVK::AHBTexturePoolVK ( std::weak_ptr< Context context,
android::HardwareBufferDescriptor  desc 
)
explicit

Create a new (empty) texture pool.

Parameters
[in]contextThe context whose allocators will be used to create the resources for the texture sources.
[in]descThe descriptor of the hardware buffers that will be used to create the backing stores of the texture sources.
[in]max_entriesThe maximum entries that will remain cached in the pool.

Definition at line 11 of file ahb_texture_pool_vk.cc.

13 : context_(std::move(context)), desc_(desc) {
14 if (!desc_.IsAllocatable()) {
15 VALIDATION_LOG << "Swapchain image is not allocatable.";
16 return;
17 }
18 is_valid_ = true;
19}
bool IsAllocatable() const
If hardware buffers can be created using this descriptor. Allocatable descriptors may still cause fai...
#define VALIDATION_LOG
Definition validation.h:91

References impeller::android::HardwareBufferDescriptor::IsAllocatable(), and VALIDATION_LOG.

◆ ~AHBTexturePoolVK()

impeller::AHBTexturePoolVK::~AHBTexturePoolVK ( )
default

◆ AHBTexturePoolVK() [2/2]

impeller::AHBTexturePoolVK::AHBTexturePoolVK ( const AHBTexturePoolVK )
delete

Member Function Documentation

◆ IsValid()

bool impeller::AHBTexturePoolVK::IsValid ( ) const

If the pool can create and pool hardware buffer backed texture sources. The only reason valid textures cannot be obtained from a valid pool is because of resource exhaustion.

Returns
true if valid, false otherwise.

Definition at line 73 of file ahb_texture_pool_vk.cc.

73 {
74 return is_valid_;
75}

◆ operator=()

AHBTexturePoolVK & impeller::AHBTexturePoolVK::operator= ( const AHBTexturePoolVK )
delete

◆ Pop()

AHBTexturePoolVK::PoolEntry impeller::AHBTexturePoolVK::Pop ( )

Pops an texture source from the pool. If the pool is empty, a new texture source is created and returned.

This operation is thread-safe.

Returns
A texture source that can be used as a swapchain image. This can be nullptr in case of resource exhaustion.

Definition at line 23 of file ahb_texture_pool_vk.cc.

23 {
24 {
25 Lock lock(pool_mutex_);
26 if (!pool_.empty()) {
27 // Buffers are pushed to the back of the queue. To give the ready fences
28 // the most time to signal, pick a buffer from the front of the queue.
29 auto entry = pool_.front();
30 pool_.pop_front();
31 return entry;
32 }
33 }
34 return PoolEntry{CreateTexture()};
35}

◆ Push()

void impeller::AHBTexturePoolVK::Push ( std::shared_ptr< AHBTextureSourceVK texture,
fml::UniqueFD  render_ready_fence 
)

Push a popped texture back into the pool. This also performs a GC.

This operation is thread-safe.

Warning
Only a texture source obtained from the same pool can be returned to it. It is user error to mix and match texture sources from different pools.
Parameters
[in]textureThe texture to be returned to the pool.

Definition at line 37 of file ahb_texture_pool_vk.cc.

38 {
39 if (!texture) {
40 return;
41 }
42 Lock lock(pool_mutex_);
43 pool_.push_back(PoolEntry{std::move(texture), std::move(render_ready_fence)});
44}
FlTexture * texture

References texture.


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