| Flutter Impeller |

Classes | Public Member Functions | List of all members
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, size_t max_entries=3u)
| Create a new (empty) texture pool. More...
| ~AHBTexturePoolVK ()
| AHBTexturePoolVK (const AHBTexturePoolVK &)=delete
AHBTexturePoolVK & | operator= (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. More...
PoolEntry | Pop ()
| Pops an texture source from the pool. If the pool is empty, a new texture source is created and returned. More...
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. More...
void | PerformGC ()
| Perform an explicit GC of the pool items. This happens implicitly when a texture source us pushed into the pool but one may be necessary explicitly if there is no push back into the pool for a long time. More...

## 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,
|  | size_t | max_entries = `3u`
| ) |  |
| explicit

Create a new (empty) texture pool.

Parameters

  [in] | context | The context whose allocators will be used to create the resources for the texture sources.
  [in] | desc | The descriptor of the hardware buffers that will be used to create the backing stores of the texture sources.
  [in] | max_entries | The maximum entries that will remain cached in the pool.

Definition at line 11 of file ahb_texture_pool_vk.cc.

14 : context_(std::move(context)), desc_(desc), max_entries_(max_entries) {
15 if (!desc_.IsAllocatable()) {
16 VALIDATION_LOG << "Swapchain image is not allocatable.";
17 return;
18 }
19 for (auto i = 0u; i < max_entries_; i++) {
20 pool_.emplace_back(CreateTexture());
21 }
22 is_valid_ = true;
23 }

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 93 of file ahb_texture_pool_vk.cc.

93 {
94 return is_valid_;
95 }

## ◆ operator=()

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

## ◆ PerformGC()

void impeller::AHBTexturePoolVK::PerformGC | ( |  | ) |

Perform an explicit GC of the pool items. This happens implicitly when a texture source us pushed into the pool but one may be necessary explicitly if there is no push back into the pool for a long time.

Definition at line 78 of file ahb_texture_pool_vk.cc.

78 {
79 Lock lock(pool_mutex_);
80 PerformGCLocked();
81 }

## ◆ 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 27 of file ahb_texture_pool_vk.cc.

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

## ◆ 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] | texture | The texture to be returned to the pool.

Definition at line 41 of file ahb_texture_pool_vk.cc.

42 {
43 if (!texture) {
44 return;
45 }
46 Lock lock(pool_mutex_);
47 pool_.push_back(PoolEntry{std::move(texture), std::move(render_ready_fence)});
48 PerformGCLocked();
49 }

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

- impeller/renderer/backend/vulkan/swapchain/ahb/ahb_texture_pool_vk.h
- impeller/renderer/backend/vulkan/swapchain/ahb/ahb_texture_pool_vk.cc

VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:91
impeller::android::HardwareBufferDescriptor::IsAllocatable
bool IsAllocatable() const
If hardware buffers can be created using this descriptor. Allocatable descriptors may still cause fai...
Definition: hardware_buffer.cc:52