| 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 auto texture = CreateTexture();
21 if (!texture->IsValid()) {
22 return;
23 }
24 pool_.emplace_back(std::move(texture));
25 }
26 is_valid_ = true;
27 }
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
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:91

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

97 {
98 return is_valid_;
99 }

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

82 {
83 Lock lock(pool_mutex_);
84 PerformGCLocked();
85 }

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

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

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

46 {
47 if (!texture) {
48 return;
49 }
50 Lock lock(pool_mutex_);
51 pool_.push_back(PoolEntry{std::move(texture), std::move(render_ready_fence)});
52 PerformGCLocked();
53 }

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