| 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, uint32_t keep_alive_frame_count=4)
| ~RenderTargetCache ()=default
void | Start () override
| Mark the beginning of a frame workload. More...
void | End () override
| Mark the end of a frame workload. More...
RenderTarget | CreateOffscreen (const Context &context, ISize size, int mip_count, std::string_view label="Offscreen", RenderTarget::AttachmentConfig color_attachment_config=RenderTarget::kDefaultColorAttachmentConfig, std::optional< RenderTarget::AttachmentConfig > stencil_attachment_config=RenderTarget::kDefaultStencilAttachmentConfig, const std::shared_ptr< Texture > &existing_color_texture=nullptr, const std::shared_ptr< Texture > &existing_depth_stencil_texture=nullptr) override
RenderTarget | CreateOffscreenMSAA (const Context &context, ISize size, int mip_count, std::string_view label="Offscreen MSAA", RenderTarget::AttachmentConfigMSAA color_attachment_config=RenderTarget::kDefaultColorAttachmentConfigMSAA, std::optional< RenderTarget::AttachmentConfig > stencil_attachment_config=RenderTarget::kDefaultStencilAttachmentConfig, const std::shared_ptr< Texture > &existing_color_msaa_texture=nullptr, const std::shared_ptr< Texture > &existing_color_resolve_texture=nullptr, const std::shared_ptr< Texture > &existing_depth_stencil_texture=nullptr) override
size_t | CachedTextureCount () const
std::vector< RenderTargetData >::const_iterator | GetRenderTargetDataBegin () const
| Visible for testing. More...
std::vector< RenderTargetData >::const_iterator | GetRenderTargetDataEnd () const
| Visible for testing. More...
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 17 of file render_target_cache.h.

## Constructor & Destructor Documentation

## ◆ RenderTargetCache()

impeller::RenderTargetCache::RenderTargetCache | ( | std::shared_ptr< Allocator > | allocator,
|  | uint32_t | keep_alive_frame_count = `4`
| ) |  |
| explicit

Definition at line 11 of file render_target_cache.cc.

13 : RenderTargetAllocator(std::move(allocator)),
14 keep_alive_frame_count_(keep_alive_frame_count) {}
impeller::RenderTargetAllocator::RenderTargetAllocator
RenderTargetAllocator(std::shared_ptr< Allocator > allocator)
Definition: render_target.cc:314

## ◆ ~RenderTargetCache()

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

## Member Function Documentation

## ◆ CachedTextureCount()

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

Definition at line 141 of file render_target_cache.cc.

141 {
142 return render_target_data_.size();
143 }

## ◆ CreateOffscreen()

RenderTarget impeller::RenderTargetCache::CreateOffscreen | ( | const Context & | context,
|  | ISize | size,
|  | int | mip_count,
|  | std::string_view | label = `"Offscreen"`,
|  | RenderTarget::AttachmentConfig | color_attachment_config = `RenderTarget::kDefaultColorAttachmentConfig`,
|  | std::optional< RenderTarget::AttachmentConfig > | stencil_attachment_config = `RenderTarget::kDefaultStencilAttachmentConfig`,
|  | const std::shared_ptr< Texture > & | existing_color_texture = `nullptr`,
|  | const std::shared_ptr< Texture > & | existing_depth_stencil_texture = `nullptr`
| ) |  |
| override virtual

Reimplemented from impeller::RenderTargetAllocator.

Definition at line 36 of file render_target_cache.cc.

44 {
45 if (size.IsEmpty()) {
46 return {};
47 }
48
49 FML_DCHECK(existing_color_texture == nullptr &&
50 existing_depth_stencil_texture == nullptr);
51 auto config = RenderTargetConfig{
52 .size = size,
53 .mip_count = static_cast<size_t>(mip_count),
54 .has_msaa = false,
55 .has_depth_stencil = stencil_attachment_config.has_value(),
56 };
57 for (RenderTargetData& render_target_data : render_target_data_) {
58 const RenderTargetConfig other_config = render_target_data.config;
59 if (!render_target_data.used_this_frame && other_config == config) {
60 render_target_data.used_this_frame = true;
61 render_target_data.keep_alive_frame_count = keep_alive_frame_count_;
62 ColorAttachment color0 =
63 render_target_data.render_target.GetColorAttachment(0);
64 std::optional<DepthAttachment> depth =
65 render_target_data.render_target.GetDepthAttachment();
66 std::shared_ptr<Texture> depth_tex = depth ? depth->texture : nullptr;
67 return RenderTargetAllocator::CreateOffscreen(
68 context, size, mip_count, label, color_attachment_config,
69 stencil_attachment_config, color0.texture, depth_tex);
70 }
71 }
72 RenderTarget created_target = RenderTargetAllocator::CreateOffscreen(
73 context, size, mip_count, label, color_attachment_config,
74 stencil_attachment_config);
75 if (!created_target.IsValid()) {
76 return created_target;
77 }
78 render_target_data_.push_back(RenderTargetData{
79 .used_this_frame = true, //
80 .keep_alive_frame_count = keep_alive_frame_count_, //
81 .config = config, //
82 .render_target = created_target //
83 });
84 return created_target;
85 }
impeller::RenderTargetAllocator::CreateOffscreen
virtual RenderTarget CreateOffscreen(const Context &context, ISize size, int mip_count, std::string_view label="Offscreen", RenderTarget::AttachmentConfig color_attachment_config=RenderTarget::kDefaultColorAttachmentConfig, std::optional< RenderTarget::AttachmentConfig > stencil_attachment_config=RenderTarget::kDefaultStencilAttachmentConfig, const std::shared_ptr< Texture > &existing_color_texture=nullptr, const std::shared_ptr< Texture > &existing_depth_stencil_texture=nullptr)
Definition: render_target.cc:322

References impeller::RenderTargetAllocator::CreateOffscreen(), impeller::TSize< T >::IsEmpty(), impeller::RenderTarget::IsValid(), impeller::RenderTargetConfig::size, and impeller::Attachment::texture.

## ◆ CreateOffscreenMSAA()

RenderTarget impeller::RenderTargetCache::CreateOffscreenMSAA | ( | const Context & | context,
|  | ISize | size,
|  | int | mip_count,
|  | std::string_view | label = `"Offscreen MSAA"`,
|  | RenderTarget::AttachmentConfigMSAA | color_attachment_config = `RenderTarget::kDefaultColorAttachmentConfigMSAA`,
|  | std::optional< RenderTarget::AttachmentConfig > | stencil_attachment_config = `RenderTarget::kDefaultStencilAttachmentConfig`,
|  | const std::shared_ptr< Texture > & | existing_color_msaa_texture = `nullptr`,
|  | const std::shared_ptr< Texture > & | existing_color_resolve_texture = `nullptr`,
|  | const std::shared_ptr< Texture > & | existing_depth_stencil_texture = `nullptr`
| ) |  |
| override virtual

Reimplemented from impeller::RenderTargetAllocator.

Definition at line 87 of file render_target_cache.cc.

96 {
97 if (size.IsEmpty()) {
98 return {};
99 }
100
101 FML_DCHECK(existing_color_msaa_texture == nullptr &&
102 existing_color_resolve_texture == nullptr &&
103 existing_depth_stencil_texture == nullptr);
104 auto config = RenderTargetConfig{
105 .size = size,
106 .mip_count = static_cast<size_t>(mip_count),
107 .has_msaa = true,
108 .has_depth_stencil = stencil_attachment_config.has_value(),
109 };
110 for (RenderTargetData& render_target_data : render_target_data_) {
111 const RenderTargetConfig other_config = render_target_data.config;
112 if (!render_target_data.used_this_frame && other_config == config) {
113 render_target_data.used_this_frame = true;
114 render_target_data.keep_alive_frame_count = keep_alive_frame_count_;
115 ColorAttachment color0 =
116 render_target_data.render_target.GetColorAttachment(0);
117 std::optional<DepthAttachment> depth =
118 render_target_data.render_target.GetDepthAttachment();
119 std::shared_ptr<Texture> depth_tex = depth ? depth->texture : nullptr;
120 return RenderTargetAllocator::CreateOffscreenMSAA(
121 context, size, mip_count, label, color_attachment_config,
122 stencil_attachment_config, color0.texture, color0.resolve_texture,
123 depth_tex);
124 }
125 }
126 RenderTarget created_target = RenderTargetAllocator::CreateOffscreenMSAA(
127 context, size, mip_count, label, color_attachment_config,
128 stencil_attachment_config);
129 if (!created_target.IsValid()) {
130 return created_target;
131 }
132 render_target_data_.push_back(RenderTargetData{
133 .used_this_frame = true, //
134 .keep_alive_frame_count = keep_alive_frame_count_, //
135 .config = config, //
136 .render_target = created_target //
137 });
138 return created_target;
139 }
impeller::RenderTargetAllocator::CreateOffscreenMSAA
virtual RenderTarget CreateOffscreenMSAA(const Context &context, ISize size, int mip_count, std::string_view label="Offscreen MSAA", RenderTarget::AttachmentConfigMSAA color_attachment_config=RenderTarget::kDefaultColorAttachmentConfigMSAA, std::optional< RenderTarget::AttachmentConfig > stencil_attachment_config=RenderTarget::kDefaultStencilAttachmentConfig, const std::shared_ptr< Texture > &existing_color_msaa_texture=nullptr, const std::shared_ptr< Texture > &existing_color_resolve_texture=nullptr, const std::shared_ptr< Texture > &existing_depth_stencil_texture=nullptr)
Definition: render_target.cc:376

References impeller::RenderTargetAllocator::CreateOffscreenMSAA(), impeller::TSize< T >::IsEmpty(), impeller::RenderTarget::IsValid(), impeller::Attachment::resolve_texture, impeller::RenderTargetConfig::size, and impeller::Attachment::texture.

## ◆ 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 22 of file render_target_cache.cc.

22 {
23 std::vector<RenderTargetData> retain;
24
25 for (RenderTargetData& td : render_target_data_) {
26 if (td.used_this_frame) {
27 retain.push_back(td);
28 } else if (td.keep_alive_frame_count > 0) {
29 td.keep_alive_frame_count--;
30 retain.push_back(td);
31 }
32 }
33 render_target_data_.swap(retain);
34 }

## ◆ GetRenderTargetDataBegin()

std::vector<RenderTargetData>::const_iterator impeller::RenderTargetCache::GetRenderTargetDataBegin | ( |  | ) | const
| inline

Visible for testing.

Definition at line 77 of file render_target_cache.h.

78 {
79 return render_target_data_.begin();
80 }

## ◆ GetRenderTargetDataEnd()

std::vector<RenderTargetData>::const_iterator impeller::RenderTargetCache::GetRenderTargetDataEnd | ( |  | ) | const
| inline

Visible for testing.

Definition at line 83 of file render_target_cache.h.

83 {
84 return render_target_data_.end();
85 }

## ◆ 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 16 of file render_target_cache.cc.

16 {
17 for (auto& td : render_target_data_) {
18 td.used_this_frame = false;
19 }
20 }

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

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