Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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:
impeller::RenderTargetAllocator

Public Member Functions

 RenderTargetCache (std::shared_ptr< Allocator > allocator)
 
 ~RenderTargetCache ()=default
 
void Start () override
 Mark the beginning of a frame workload.
 
void End () override
 Mark the end of a frame workload.
 
RenderTarget CreateOffscreen (const Context &context, ISize size, int mip_count, const std::string &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, const std::string &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.
 
std::vector< RenderTargetData >::const_iterator GetRenderTargetDataEnd () const
 Visible for testing.
 
- 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)) {}
RenderTargetAllocator(std::shared_ptr< Allocator > allocator)

◆ ~RenderTargetCache()

impeller::RenderTargetCache::~RenderTargetCache ( )
default

Member Function Documentation

◆ CachedTextureCount()

size_t impeller::RenderTargetCache::CachedTextureCount ( ) const

Definition at line 129 of file render_target_cache.cc.

129 {
130 return render_target_data_.size();
131}

◆ CreateOffscreen()

RenderTarget impeller::RenderTargetCache::CreateOffscreen ( const Context context,
ISize  size,
int  mip_count,
const std::string &  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 
)
overridevirtual

Reimplemented from impeller::RenderTargetAllocator.

Definition at line 30 of file render_target_cache.cc.

38 {
39 if (size.IsEmpty()) {
40 return {};
41 }
42
43 FML_DCHECK(existing_color_texture == nullptr &&
44 existing_depth_stencil_texture == nullptr);
45 auto config = RenderTargetConfig{
46 .size = size,
47 .mip_count = static_cast<size_t>(mip_count),
48 .has_msaa = false,
49 .has_depth_stencil = stencil_attachment_config.has_value(),
50 };
51 for (auto& render_target_data : render_target_data_) {
52 const auto other_config = render_target_data.config;
53 if (!render_target_data.used_this_frame && other_config == config) {
54 render_target_data.used_this_frame = true;
55 auto color0 = render_target_data.render_target.GetColorAttachments()
56 .find(0u)
57 ->second;
58 auto depth = render_target_data.render_target.GetDepthAttachment();
59 std::shared_ptr<Texture> depth_tex = depth ? depth->texture : nullptr;
61 context, size, mip_count, label, color_attachment_config,
62 stencil_attachment_config, color0.texture, depth_tex);
63 }
64 }
66 context, size, mip_count, label, color_attachment_config,
67 stencil_attachment_config);
68 if (!created_target.IsValid()) {
69 return created_target;
70 }
71 render_target_data_.push_back(
72 RenderTargetData{.used_this_frame = true,
73 .config = config,
74 .render_target = created_target});
75 return created_target;
76}
virtual RenderTarget CreateOffscreen(const Context &context, ISize size, int mip_count, const std::string &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)
#define FML_DCHECK(condition)
Definition logging.h:103
SK_API sk_sp< SkSurface > RenderTarget(GrRecordingContext *context, skgpu::Budgeted budgeted, const SkImageInfo &imageInfo, int sampleCount, GrSurfaceOrigin surfaceOrigin, const SkSurfaceProps *surfaceProps, bool shouldCreateWithMips=false, bool isProtected=false)
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition switches.h:259

◆ CreateOffscreenMSAA()

RenderTarget impeller::RenderTargetCache::CreateOffscreenMSAA ( const Context context,
ISize  size,
int  mip_count,
const std::string &  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 
)
overridevirtual

Reimplemented from impeller::RenderTargetAllocator.

Definition at line 78 of file render_target_cache.cc.

87 {
88 if (size.IsEmpty()) {
89 return {};
90 }
91
92 FML_DCHECK(existing_color_msaa_texture == nullptr &&
93 existing_color_resolve_texture == nullptr &&
94 existing_depth_stencil_texture == nullptr);
95 auto config = RenderTargetConfig{
96 .size = size,
97 .mip_count = static_cast<size_t>(mip_count),
98 .has_msaa = true,
99 .has_depth_stencil = stencil_attachment_config.has_value(),
100 };
101 for (auto& render_target_data : render_target_data_) {
102 const auto other_config = render_target_data.config;
103 if (!render_target_data.used_this_frame && other_config == config) {
104 render_target_data.used_this_frame = true;
105 auto color0 = render_target_data.render_target.GetColorAttachments()
106 .find(0u)
107 ->second;
108 auto depth = render_target_data.render_target.GetDepthAttachment();
109 std::shared_ptr<Texture> depth_tex = depth ? depth->texture : nullptr;
111 context, size, mip_count, label, color_attachment_config,
112 stencil_attachment_config, color0.texture, color0.resolve_texture,
113 depth_tex);
114 }
115 }
117 context, size, mip_count, label, color_attachment_config,
118 stencil_attachment_config);
119 if (!created_target.IsValid()) {
120 return created_target;
121 }
122 render_target_data_.push_back(
123 RenderTargetData{.used_this_frame = true,
124 .config = config,
125 .render_target = created_target});
126 return created_target;
127}
virtual RenderTarget CreateOffscreenMSAA(const Context &context, ISize size, int mip_count, const std::string &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)

◆ End()

void impeller::RenderTargetCache::End ( )
overridevirtual

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<RenderTargetData> retain;
21
22 for (const auto& td : render_target_data_) {
23 if (td.used_this_frame) {
24 retain.push_back(td);
25 }
26 }
27 render_target_data_.swap(retain);
28}

◆ GetRenderTargetDataBegin()

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

Visible for testing.

Definition at line 73 of file render_target_cache.h.

74 {
75 return render_target_data_.begin();
76 }

◆ GetRenderTargetDataEnd()

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

Visible for testing.

Definition at line 79 of file render_target_cache.h.

79 {
80 return render_target_data_.end();
81 }

◆ Start()

void impeller::RenderTargetCache::Start ( )
overridevirtual

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 : render_target_data_) {
15 td.used_this_frame = false;
16 }
17}

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