Flutter Engine
The Flutter Engine
Classes | Public Member Functions | Static Public Attributes | List of all members
impeller::RenderTarget Class Referencefinal

#include <render_target.h>

Classes

struct  AttachmentConfig
 
struct  AttachmentConfigMSAA
 

Public Member Functions

 RenderTarget ()
 
 ~RenderTarget ()
 
bool IsValid () const
 
void SetupDepthStencilAttachments (const Context &context, Allocator &allocator, ISize size, bool msaa, const std::string &label="Offscreen", RenderTarget::AttachmentConfig stencil_attachment_config=RenderTarget::kDefaultStencilAttachmentConfig, const std::shared_ptr< Texture > &depth_stencil_texture=nullptr)
 
SampleCount GetSampleCount () const
 
bool HasColorAttachment (size_t index) const
 
ISize GetRenderTargetSize () const
 
std::shared_ptr< TextureGetRenderTargetTexture () const
 
PixelFormat GetRenderTargetPixelFormat () const
 
std::optional< ISizeGetColorAttachmentSize (size_t index) const
 
RenderTargetSetColorAttachment (const ColorAttachment &attachment, size_t index)
 
RenderTargetSetDepthAttachment (std::optional< DepthAttachment > attachment)
 
RenderTargetSetStencilAttachment (std::optional< StencilAttachment > attachment)
 
size_t GetMaxColorAttacmentBindIndex () const
 
const std::map< size_t, ColorAttachment > & GetColorAttachments () const
 
const std::optional< DepthAttachment > & GetDepthAttachment () const
 
const std::optional< StencilAttachment > & GetStencilAttachment () const
 
size_t GetTotalAttachmentCount () const
 
void IterateAllAttachments (const std::function< bool(const Attachment &attachment)> &iterator) const
 
std::string ToString () const
 
RenderTargetConfig ToConfig () const
 

Static Public Attributes

static constexpr AttachmentConfig kDefaultColorAttachmentConfig
 
static constexpr AttachmentConfigMSAA kDefaultColorAttachmentConfigMSAA
 
static constexpr AttachmentConfig kDefaultStencilAttachmentConfig
 

Detailed Description

Definition at line 38 of file render_target.h.

Constructor & Destructor Documentation

◆ RenderTarget()

impeller::RenderTarget::RenderTarget ( )
default

◆ ~RenderTarget()

impeller::RenderTarget::~RenderTarget ( )
default

Member Function Documentation

◆ GetColorAttachments()

const std::map< size_t, ColorAttachment > & impeller::RenderTarget::GetColorAttachments ( ) const

Definition at line 198 of file render_target.cc.

199 {
200 return colors_;
201}

◆ GetColorAttachmentSize()

std::optional< ISize > impeller::RenderTarget::GetColorAttachmentSize ( size_t  index) const

Definition at line 129 of file render_target.cc.

129 {
130 auto found = colors_.find(index);
131
132 if (found == colors_.end()) {
133 return std::nullopt;
134 }
135
136 return found->second.texture->GetSize();
137}

◆ GetDepthAttachment()

const std::optional< DepthAttachment > & impeller::RenderTarget::GetDepthAttachment ( ) const

Definition at line 203 of file render_target.cc.

203 {
204 return depth_;
205}

◆ GetMaxColorAttacmentBindIndex()

size_t impeller::RenderTarget::GetMaxColorAttacmentBindIndex ( ) const

Definition at line 161 of file render_target.cc.

161 {
162 size_t max = 0;
163 for (const auto& color : colors_) {
164 max = std::max(color.first, max);
165 }
166 return max;
167}
DlColor color
static float max(float r, float g, float b)
Definition: hsl.cpp:49

◆ GetRenderTargetPixelFormat()

PixelFormat impeller::RenderTarget::GetRenderTargetPixelFormat ( ) const

Definition at line 153 of file render_target.cc.

153 {
154 if (auto texture = GetRenderTargetTexture(); texture != nullptr) {
155 return texture->GetTextureDescriptor().format;
156 }
157
159}
std::shared_ptr< Texture > GetRenderTargetTexture() const
FlTexture * texture

◆ GetRenderTargetSize()

ISize impeller::RenderTarget::GetRenderTargetSize ( ) const

Definition at line 139 of file render_target.cc.

139 {
140 auto size = GetColorAttachmentSize(0u);
141 return size.has_value() ? size.value() : ISize{};
142}
std::optional< ISize > GetColorAttachmentSize(size_t index) const
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
ISize64 ISize
Definition: size.h:140

◆ GetRenderTargetTexture()

std::shared_ptr< Texture > impeller::RenderTarget::GetRenderTargetTexture ( ) const

Definition at line 144 of file render_target.cc.

144 {
145 auto found = colors_.find(0u);
146 if (found == colors_.end()) {
147 return nullptr;
148 }
149 return found->second.resolve_texture ? found->second.resolve_texture
150 : found->second.texture;
151}

◆ GetSampleCount()

SampleCount impeller::RenderTarget::GetSampleCount ( ) const

Definition at line 115 of file render_target.cc.

115 {
116 if (auto found = colors_.find(0u); found != colors_.end()) {
117 return found->second.texture->GetTextureDescriptor().sample_count;
118 }
120}

◆ GetStencilAttachment()

const std::optional< StencilAttachment > & impeller::RenderTarget::GetStencilAttachment ( ) const

Definition at line 207 of file render_target.cc.

208 {
209 return stencil_;
210}

◆ GetTotalAttachmentCount()

size_t impeller::RenderTarget::GetTotalAttachmentCount ( ) const

Definition at line 212 of file render_target.cc.

212 {
213 size_t count = 0u;
214 for (const auto& [_, color] : colors_) {
215 if (color.texture) {
216 count++;
217 }
218 if (color.resolve_texture) {
219 count++;
220 }
221 }
222 if (depth_.has_value()) {
223 count++;
224 }
225 if (stencil_.has_value()) {
226 count++;
227 }
228 return count;
229}
int count
Definition: FontMgrTest.cpp:50

◆ HasColorAttachment()

bool impeller::RenderTarget::HasColorAttachment ( size_t  index) const

Definition at line 122 of file render_target.cc.

122 {
123 if (auto found = colors_.find(index); found != colors_.end()) {
124 return true;
125 }
126 return false;
127}

◆ IsValid()

bool impeller::RenderTarget::IsValid ( ) const

Definition at line 23 of file render_target.cc.

23 {
24 // Validate that there is a color attachment at zero index.
25 if (!HasColorAttachment(0u)) {
27 << "Render target does not have color attachment at index 0.";
28 return false;
29 }
30
31 // Validate that all attachments are of the same size.
32 {
33 std::optional<ISize> size;
34 bool sizes_are_same = true;
35 auto iterator = [&](const Attachment& attachment) -> bool {
36 if (!size.has_value()) {
37 size = attachment.texture->GetSize();
38 }
39 if (size != attachment.texture->GetSize()) {
40 sizes_are_same = false;
41 return false;
42 }
43 return true;
44 };
45 IterateAllAttachments(iterator);
46 if (!sizes_are_same) {
48 << "Sizes of all render target attachments are not the same.";
49 return false;
50 }
51 }
52
53 // Validate that all attachments are of the same type and sample counts.
54 {
55 std::optional<TextureType> texture_type;
56 std::optional<SampleCount> sample_count;
57 bool passes_type_validation = true;
58 auto iterator = [&](const Attachment& attachment) -> bool {
59 if (!texture_type.has_value() || !sample_count.has_value()) {
60 texture_type = attachment.texture->GetTextureDescriptor().type;
61 sample_count = attachment.texture->GetTextureDescriptor().sample_count;
62 }
63
64 if (texture_type != attachment.texture->GetTextureDescriptor().type) {
65 passes_type_validation = false;
66 VALIDATION_LOG << "Render target has incompatible texture types: "
67 << TextureTypeToString(texture_type.value()) << " != "
69 attachment.texture->GetTextureDescriptor().type)
70 << " on target " << ToString();
71 return false;
72 }
73
74 if (sample_count !=
75 attachment.texture->GetTextureDescriptor().sample_count) {
76 passes_type_validation = false;
77 VALIDATION_LOG << "Render target (" << ToString()
78 << ") has incompatible sample counts.";
79
80 return false;
81 }
82
83 return true;
84 };
85 IterateAllAttachments(iterator);
86 if (!passes_type_validation) {
87 return false;
88 }
89 }
90
91 return true;
92}
void IterateAllAttachments(const std::function< bool(const Attachment &attachment)> &iterator) const
bool HasColorAttachment(size_t index) const
std::string ToString() const
constexpr const char * TextureTypeToString(TextureType type)
Definition: formats.h:269
#define VALIDATION_LOG
Definition: validation.h:73

◆ IterateAllAttachments()

void impeller::RenderTarget::IterateAllAttachments ( const std::function< bool(const Attachment &attachment)> &  iterator) const

Definition at line 94 of file render_target.cc.

95 {
96 for (const auto& color : colors_) {
97 if (!iterator(color.second)) {
98 return;
99 }
100 }
101
102 if (depth_.has_value()) {
103 if (!iterator(depth_.value())) {
104 return;
105 }
106 }
107
108 if (stencil_.has_value()) {
109 if (!iterator(stencil_.value())) {
110 return;
111 }
112 }
113}

◆ SetColorAttachment()

RenderTarget & impeller::RenderTarget::SetColorAttachment ( const ColorAttachment attachment,
size_t  index 
)

Definition at line 169 of file render_target.cc.

171 {
172 if (attachment.IsValid()) {
173 colors_[index] = attachment;
174 }
175 return *this;
176}

◆ SetDepthAttachment()

RenderTarget & impeller::RenderTarget::SetDepthAttachment ( std::optional< DepthAttachment attachment)

Definition at line 178 of file render_target.cc.

179 {
180 if (!attachment.has_value()) {
181 depth_ = std::nullopt;
182 } else if (attachment->IsValid()) {
183 depth_ = std::move(attachment);
184 }
185 return *this;
186}

◆ SetStencilAttachment()

RenderTarget & impeller::RenderTarget::SetStencilAttachment ( std::optional< StencilAttachment attachment)

Definition at line 188 of file render_target.cc.

189 {
190 if (!attachment.has_value()) {
191 stencil_ = std::nullopt;
192 } else if (attachment->IsValid()) {
193 stencil_ = std::move(attachment);
194 }
195 return *this;
196}

◆ SetupDepthStencilAttachments()

void impeller::RenderTarget::SetupDepthStencilAttachments ( const Context context,
Allocator allocator,
ISize  size,
bool  msaa,
const std::string &  label = "Offscreen",
RenderTarget::AttachmentConfig  stencil_attachment_config = RenderTarget::kDefaultStencilAttachmentConfig,
const std::shared_ptr< Texture > &  depth_stencil_texture = nullptr 
)

Definition at line 413 of file render_target.cc.

420 {
421 std::shared_ptr<Texture> depth_stencil_texture;
422 if (existing_depth_stencil_texture) {
423 depth_stencil_texture = existing_depth_stencil_texture;
424 } else {
425 TextureDescriptor depth_stencil_texture_desc;
426 depth_stencil_texture_desc.storage_mode =
427 stencil_attachment_config.storage_mode;
428 if (msaa) {
429 depth_stencil_texture_desc.type = TextureType::kTexture2DMultisample;
430 depth_stencil_texture_desc.sample_count = SampleCount::kCount4;
431 }
432 depth_stencil_texture_desc.format =
433 context.GetCapabilities()->GetDefaultDepthStencilFormat();
434 depth_stencil_texture_desc.size = size;
435 depth_stencil_texture_desc.usage = TextureUsage::kRenderTarget;
436 depth_stencil_texture = allocator.CreateTexture(depth_stencil_texture_desc);
437 if (!depth_stencil_texture) {
438 return; // Error messages are handled by `Allocator::CreateTexture`.
439 }
440 }
441
442 DepthAttachment depth0;
443 depth0.load_action = stencil_attachment_config.load_action;
444 depth0.store_action = stencil_attachment_config.store_action;
445 depth0.clear_depth = 0u;
446 depth0.texture = depth_stencil_texture;
447
448 StencilAttachment stencil0;
449 stencil0.load_action = stencil_attachment_config.load_action;
450 stencil0.store_action = stencil_attachment_config.store_action;
451 stencil0.clear_stencil = 0u;
452 stencil0.texture = std::move(depth_stencil_texture);
453
454 stencil0.texture->SetLabel(
455 SPrintF("%s Depth+Stencil Texture", label.c_str()));
456 SetDepthAttachment(std::move(depth0));
457 SetStencilAttachment(std::move(stencil0));
458}
RenderTarget & SetDepthAttachment(std::optional< DepthAttachment > attachment)
RenderTarget & SetStencilAttachment(std::optional< StencilAttachment > attachment)
std::string SPrintF(const char *format,...)
Definition: strings.cc:12

◆ ToConfig()

RenderTargetConfig impeller::RenderTarget::ToConfig ( ) const
inline

Definition at line 125 of file render_target.h.

125 {
126 auto& color_attachment = GetColorAttachments().find(0)->second;
127 return RenderTargetConfig{
128 .size = color_attachment.texture->GetSize(),
129 .mip_count = color_attachment.texture->GetMipCount(),
130 .has_msaa = color_attachment.resolve_texture != nullptr,
131 .has_depth_stencil = depth_.has_value() && stencil_.has_value()};
132 }
const std::map< size_t, ColorAttachment > & GetColorAttachments() const

◆ ToString()

std::string impeller::RenderTarget::ToString ( ) const

Definition at line 231 of file render_target.cc.

231 {
232 std::stringstream stream;
233
234 for (const auto& [index, color] : colors_) {
235 stream << SPrintF("Color[%zu]=(%s)", index,
237 }
238 if (depth_) {
239 stream << ",";
240 stream << SPrintF("Depth=(%s)",
241 DepthAttachmentToString(depth_.value()).c_str());
242 }
243 if (stencil_) {
244 stream << ",";
245 stream << SPrintF("Stencil=(%s)",
246 StencilAttachmentToString(stencil_.value()).c_str());
247 }
248 return stream.str();
249}
std::string DepthAttachmentToString(const DepthAttachment &depth)
Definition: formats.cc:130
std::string ColorAttachmentToString(const ColorAttachment &color)
Definition: formats.cc:123
std::string StencilAttachmentToString(const StencilAttachment &stencil)
Definition: formats.cc:137

Member Data Documentation

◆ kDefaultColorAttachmentConfig

constexpr AttachmentConfig impeller::RenderTarget::kDefaultColorAttachmentConfig
staticconstexpr
Initial value:
= {
.storage_mode = StorageMode::kDevicePrivate,
.load_action = LoadAction::kClear,
.store_action = StoreAction::kStore,
.clear_color = Color::BlackTransparent()}
static constexpr Color BlackTransparent()
Definition: color.h:272

Definition at line 55 of file render_target.h.

◆ kDefaultColorAttachmentConfigMSAA

constexpr AttachmentConfigMSAA impeller::RenderTarget::kDefaultColorAttachmentConfigMSAA
staticconstexpr
Initial value:
= {
.resolve_storage_mode = StorageMode::kDevicePrivate,
.load_action = LoadAction::kClear,
.clear_color = Color::BlackTransparent()}

Definition at line 61 of file render_target.h.

◆ kDefaultStencilAttachmentConfig

constexpr AttachmentConfig impeller::RenderTarget::kDefaultStencilAttachmentConfig
staticconstexpr
Initial value:
= {
.load_action = LoadAction::kClear,
.store_action = StoreAction::kDontCare,
.clear_color = Color::BlackTransparent()}

Definition at line 68 of file render_target.h.


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