| Flutter Impeller |

Classes | Public Member Functions | List of all members
impeller::RenderTargetCache Class Reference

An implementation of the [RenderTargetAllocator] that caches all allocated texture data for one frame. More...

`#include <render_target_cache.h>`

Inheritance diagram for impeller::RenderTargetCache:

## Public Member Functions
| RenderTargetCache (std::shared_ptr< Allocator > allocator)
| ~RenderTargetCache ()=default
void | Start () override
| Mark the beginning of a frame workload. More...
void | End () override
| Mark the end of a frame workload. More...
std::shared_ptr< Texture > | CreateTexture (const TextureDescriptor &desc) override
| Create a new render target texture, or recycle a previously allocated render target texture. More...
size_t | CachedTextureCount () const
Public Member Functions inherited from impeller::RenderTargetAllocator
| RenderTargetAllocator (std::shared_ptr< Allocator > allocator)
virtual | ~RenderTargetAllocator ()=default

## Detailed Description

An implementation of the [RenderTargetAllocator] that caches all allocated texture data for one frame.

Any textures unused after a frame are immediately discarded.

Definition at line 16 of file render_target_cache.h.

## Constructor & Destructor Documentation

## ◆ RenderTargetCache()

impeller::RenderTargetCache::RenderTargetCache | ( | std::shared_ptr< Allocator > | allocator | ) |
| explicit

Definition at line 10 of file render_target_cache.cc.

11 : RenderTargetAllocator(std::move(allocator)) {}

## ◆ ~RenderTargetCache()

impeller::RenderTargetCache::~RenderTargetCache | ( |  | ) |
| default

## Member Function Documentation

## ◆ CachedTextureCount()

size_t impeller::RenderTargetCache::CachedTextureCount | ( |  | ) | const

Definition at line 30 of file render_target_cache.cc.

30 {
31 return texture_data_.size();
32 }

## ◆ CreateTexture()

std::shared_ptr< Texture > impeller::RenderTargetCache::CreateTexture | ( | const TextureDescriptor & | desc | ) |
| override virtual

Create a new render target texture, or recycle a previously allocated render target texture.

Reimplemented from impeller::RenderTargetAllocator.

Definition at line 34 of file render_target_cache.cc.

35 {
36 FML_DCHECK(desc.storage_mode != StorageMode::kHostVisible);
37 FML_DCHECK(desc.usage &
38 static_cast<TextureUsageMask>(TextureUsage::kRenderTarget));
39
40 for (auto& td : texture_data_) {
41 const auto other_desc = td.texture->GetTextureDescriptor();
42 FML_DCHECK(td.texture != nullptr);
43 if (!td.used_this_frame && desc == other_desc) {
44 td.used_this_frame = true;
45 return td.texture;
46 }
47 }
48 auto result = RenderTargetAllocator::CreateTexture(desc);
49 if (result == nullptr) {
50 return result;
51 }
52 texture_data_.push_back(
53 TextureData{.used_this_frame = true, .texture = result});
54 return result;
55 }

References impeller::RenderTargetAllocator::CreateTexture(), impeller::kHostVisible, impeller::kRenderTarget, impeller::TextureDescriptor::storage_mode, and impeller::TextureDescriptor::usage.

## ◆ End()

void impeller::RenderTargetCache::End | ( |  | ) |
| override virtual

Mark the end of a frame workload.

       This may be used to deallocate any unused textures.

Reimplemented from impeller::RenderTargetAllocator.

Definition at line 19 of file render_target_cache.cc.

19 {
20 std::vector<TextureData> retain;
21
22 for (const auto& td : texture_data_) {
23 if (td.used_this_frame) {
24 retain.push_back(td);
25 }
26 }
27 texture_data_.swap(retain);
28 }

## ◆ Start()

void impeller::RenderTargetCache::Start | ( |  | ) |
| override virtual

Mark the beginning of a frame workload.

      This may be used to reset any tracking state on whether or not a
      particular texture instance is still in use.

Reimplemented from impeller::RenderTargetAllocator.

Definition at line 13 of file render_target_cache.cc.

13 {
14 for (auto& td : texture_data_) {
15 td.used_this_frame = false;
16 }
17 }

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

- impeller/entity/render_target_cache.h
- impeller/entity/render_target_cache.cc

impeller::TextureUsageMask
uint64_t TextureUsageMask
Definition: formats.h:295
impeller::TextureUsage::kRenderTarget
@ kRenderTarget
impeller::RenderTargetAllocator::RenderTargetAllocator
RenderTargetAllocator(std::shared_ptr< Allocator > allocator)
Definition: render_target.cc:17
impeller::StorageMode::kHostVisible
@ kHostVisible
impeller::RenderTargetAllocator::CreateTexture
virtual std::shared_ptr< Texture > CreateTexture(const TextureDescriptor &desc)
Create a new render target texture, or recycle a previously allocated render target texture.
Definition: render_target.cc:25