Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
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, std::string_view 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)
 
ColorAttachment GetColorAttachment (size_t index) const
 Get the color attachment at [index].
 
RenderTargetSetDepthAttachment (std::optional< DepthAttachment > attachment)
 
RenderTargetSetStencilAttachment (std::optional< StencilAttachment > attachment)
 
size_t GetMaxColorAttachmentBindIndex () const
 
const std::optional< DepthAttachment > & GetDepthAttachment () const
 
const std::optional< StencilAttachment > & GetStencilAttachment () const
 
size_t GetTotalAttachmentCount () const
 
bool IterateAllColorAttachments (const std::function< bool(size_t index, const ColorAttachment &attachment)> &iterator) 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

◆ GetColorAttachment()

ColorAttachment impeller::RenderTarget::GetColorAttachment ( size_t  index) const

Get the color attachment at [index].

This function does not validate whether or not the attachment was previously defined and will return a default constructed attachment if none is set.

Definition at line 248 of file render_target.cc.

248 {
249 if (index == 0) {
250 if (color0_.has_value()) {
251 return color0_.value();
252 }
253 return ColorAttachment{};
254 }
255 std::map<size_t, ColorAttachment>::const_iterator it = colors_.find(index);
256 if (it != colors_.end()) {
257 return it->second;
258 }
259 return ColorAttachment{};
260}

Referenced by impeller::EntityPassTarget::Flip(), impeller::InlinePassContext::GetRenderPass(), impeller::Playground::OpenPlaygroundHere(), impeller::testing::TEST(), impeller::testing::TEST_P(), impeller::testing::TEST_P(), impeller::testing::TEST_P(), and impeller::testing::TEST_P().

◆ GetColorAttachmentSize()

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

Definition at line 169 of file render_target.cc.

169 {
170 if (index == 0u) {
171 if (color0_.has_value()) {
172 return SizeForMipLevel(color0_.value().texture,
173 color0_.value().mip_level);
174 }
175 return std::nullopt;
176 }
177 auto found = colors_.find(index);
178
179 if (found == colors_.end()) {
180 return std::nullopt;
181 }
182
183 return SizeForMipLevel(found->second.texture, found->second.mip_level);
184}
static ISize SizeForMipLevel(const std::shared_ptr< Texture > &texture, uint32_t mip_level)

References impeller::SizeForMipLevel().

Referenced by GetRenderTargetSize(), and impeller::Surface::Surface().

◆ GetDepthAttachment()

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

◆ GetMaxColorAttachmentBindIndex()

size_t impeller::RenderTarget::GetMaxColorAttachmentBindIndex ( ) const

Definition at line 206 of file render_target.cc.

206 {
207 size_t max = 0;
208 for (const auto& color : colors_) {
209 max = std::max(color.first, max);
210 }
211 return max;
212}

◆ GetRenderTargetPixelFormat()

PixelFormat impeller::RenderTarget::GetRenderTargetPixelFormat ( ) const

Definition at line 198 of file render_target.cc.

198 {
199 if (auto texture = GetRenderTargetTexture(); texture != nullptr) {
200 return texture->GetTextureDescriptor().format;
201 }
202
204}
std::shared_ptr< Texture > GetRenderTargetTexture() const
FlTexture * texture

References GetRenderTargetTexture(), impeller::kUnknown, and texture.

◆ GetRenderTargetSize()

ISize impeller::RenderTarget::GetRenderTargetSize ( ) const

Definition at line 186 of file render_target.cc.

186 {
187 auto size = GetColorAttachmentSize(0u);
188 return size.has_value() ? size.value() : ISize{};
189}
std::optional< ISize > GetColorAttachmentSize(size_t index) const
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all 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
ISize64 ISize
Definition size.h:162

References GetColorAttachmentSize().

Referenced by impeller::Canvas::GetLocalCoverageLimit(), flutter::testing::DlSurfaceInstanceImpeller::height(), impeller::AiksPlayground::OpenPlaygroundHere(), impeller::DlPlayground::OpenPlaygroundHere(), and flutter::testing::DlSurfaceInstanceImpeller::width().

◆ GetRenderTargetTexture()

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

Definition at line 191 of file render_target.cc.

191 {
192 if (!color0_.has_value()) {
193 return nullptr;
194 }
195 return color0_->resolve_texture ? color0_->resolve_texture : color0_->texture;
196}

Referenced by impeller::InlinePassContext::EndPass(), GetRenderTargetPixelFormat(), impeller::InlinePassContext::GetTexture(), impeller::ContentContext::MakeSubpass(), impeller::GoldenPlaygroundTest::OpenPlaygroundHere(), flutter::testing::DlSurfaceInstanceImpeller::SnapshotToImage(), and impeller::testing::TEST().

◆ GetSampleCount()

SampleCount impeller::RenderTarget::GetSampleCount ( ) const

Definition at line 152 of file render_target.cc.

152 {
153 if (color0_.has_value()) {
154 return color0_.value().texture->GetTextureDescriptor().sample_count;
155 }
157}

References impeller::kCount1.

◆ GetStencilAttachment()

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

◆ GetTotalAttachmentCount()

size_t impeller::RenderTarget::GetTotalAttachmentCount ( ) const

Definition at line 271 of file render_target.cc.

271 {
272 size_t count = 0u;
273 for (const auto& [_, color] : colors_) {
274 if (color.texture) {
275 count++;
276 }
277 if (color.resolve_texture) {
278 count++;
279 }
280 }
281 if (color0_.has_value()) {
282 count++;
283 }
284 if (depth_.has_value()) {
285 count++;
286 }
287 if (stencil_.has_value()) {
288 count++;
289 }
290 return count;
291}

◆ HasColorAttachment()

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

Definition at line 159 of file render_target.cc.

159 {
160 if (index == 0u) {
161 return color0_.has_value();
162 }
163 if (auto found = colors_.find(index); found != colors_.end()) {
164 return true;
165 }
166 return false;
167}

Referenced by IsValid().

◆ IsValid()

bool impeller::RenderTarget::IsValid ( ) const

Definition at line 35 of file render_target.cc.

35 {
36 // Validate that there is a color attachment at zero index.
37 if (!HasColorAttachment(0u)) {
39 << "Render target does not have color attachment at index 0.";
40 return false;
41 }
42
43#ifndef NDEBUG
44 // Validate that all attachments are of the same size.
45 {
46 std::optional<ISize> size;
47 bool sizes_are_same = true;
48 auto iterator = [&](const Attachment& attachment) -> bool {
49 ISize attachment_size =
50 SizeForMipLevel(attachment.texture, attachment.mip_level);
51 if (!size.has_value()) {
52 size = attachment_size;
53 }
54 if (size != attachment_size) {
55 sizes_are_same = false;
56 return false;
57 }
58 return true;
59 };
60 IterateAllAttachments(iterator);
61 if (!sizes_are_same) {
63 << "Sizes of all render target attachments are not the same.";
64 return false;
65 }
66 }
67
68 // Validate that all attachments are of the same type and sample counts.
69 {
70 std::optional<TextureType> texture_type;
71 std::optional<SampleCount> sample_count;
72 bool passes_type_validation = true;
73 auto iterator = [&](const Attachment& attachment) -> bool {
74 if (!texture_type.has_value() || !sample_count.has_value()) {
75 texture_type = attachment.texture->GetTextureDescriptor().type;
76 sample_count = attachment.texture->GetTextureDescriptor().sample_count;
77 }
78
79 if (texture_type != attachment.texture->GetTextureDescriptor().type) {
80 passes_type_validation = false;
81 VALIDATION_LOG << "Render target has incompatible texture types: "
82 << TextureTypeToString(texture_type.value()) << " != "
84 attachment.texture->GetTextureDescriptor().type)
85 << " on target " << ToString();
86 return false;
87 }
88
89 if (sample_count !=
90 attachment.texture->GetTextureDescriptor().sample_count) {
91 passes_type_validation = false;
92 VALIDATION_LOG << "Render target (" << ToString()
93 << ") has incompatible sample counts.";
94
95 return false;
96 }
97
98 return true;
99 };
100 IterateAllAttachments(iterator);
101 if (!passes_type_validation) {
102 return false;
103 }
104 }
105#endif // NDEBUG
106
107 return true;
108}
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:457
#define VALIDATION_LOG
Definition validation.h:91

References HasColorAttachment(), IterateAllAttachments(), impeller::SizeForMipLevel(), impeller::TextureTypeToString(), ToString(), and VALIDATION_LOG.

Referenced by impeller::RenderTargetCache::CreateOffscreen(), impeller::RenderTargetCache::CreateOffscreenMSAA(), impeller::EntityPassTarget::IsValid(), impeller::GoldenPlaygroundTest::OpenPlaygroundHere(), and impeller::testing::TEST_P().

◆ IterateAllAttachments()

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

Definition at line 126 of file render_target.cc.

127 {
128 if (color0_.has_value()) {
129 if (!iterator(color0_.value())) {
130 return;
131 }
132 }
133 for (const auto& color : colors_) {
134 if (!iterator(color.second)) {
135 return;
136 }
137 }
138
139 if (depth_.has_value()) {
140 if (!iterator(depth_.value())) {
141 return;
142 }
143 }
144
145 if (stencil_.has_value()) {
146 if (!iterator(stencil_.value())) {
147 return;
148 }
149 }
150}

Referenced by IsValid().

◆ IterateAllColorAttachments()

bool impeller::RenderTarget::IterateAllColorAttachments ( const std::function< bool(size_t index, const ColorAttachment &attachment)> &  iterator) const

Definition at line 110 of file render_target.cc.

112 {
113 if (color0_.has_value()) {
114 if (!iterator(0, color0_.value())) {
115 return false;
116 }
117 }
118 for (const auto& [index, attachment] : colors_) {
119 if (!iterator(index, attachment)) {
120 return false;
121 }
122 }
123 return true;
124}

Referenced by impeller::ContextVK::InitializeCommonlyUsedShadersIfNeeded(), and impeller::ToMTLRenderPassDescriptor().

◆ SetColorAttachment()

◆ SetDepthAttachment()

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

Definition at line 228 of file render_target.cc.

229 {
230 if (!attachment.has_value()) {
231 depth_ = std::nullopt;
232 } else if (attachment->IsValid()) {
233 depth_ = std::move(attachment);
234 }
235 return *this;
236}

Referenced by impeller::InlinePassContext::GetRenderPass(), InternalFlutterGpu_RenderPass_SetDepthStencilAttachment(), MakeRenderTargetFromBackingStoreImpeller(), impeller::Playground::OpenPlaygroundHere(), SetupDepthStencilAttachments(), impeller::testing::TEST_P(), impeller::SurfaceGLES::WrapFBO(), and impeller::WrapTextureWithRenderTarget().

◆ SetStencilAttachment()

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

◆ SetupDepthStencilAttachments()

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

Definition at line 496 of file render_target.cc.

503 {
504 std::shared_ptr<Texture> depth_stencil_texture;
505 if (existing_depth_stencil_texture) {
506 depth_stencil_texture = existing_depth_stencil_texture;
507 } else {
508 TextureDescriptor depth_stencil_texture_desc;
509 depth_stencil_texture_desc.storage_mode =
510 stencil_attachment_config.storage_mode;
511 if (msaa) {
512 depth_stencil_texture_desc.type = TextureType::kTexture2DMultisample;
513 depth_stencil_texture_desc.sample_count = SampleCount::kCount4;
514 }
515 depth_stencil_texture_desc.format =
516 context.GetCapabilities()->GetDefaultDepthStencilFormat();
517 depth_stencil_texture_desc.size = size;
518 depth_stencil_texture_desc.usage = TextureUsage::kRenderTarget;
519 depth_stencil_texture = allocator.CreateTexture(depth_stencil_texture_desc);
520 if (!depth_stencil_texture) {
521 return; // Error messages are handled by `Allocator::CreateTexture`.
522 }
523 }
524
525 DepthAttachment depth0;
526 depth0.load_action = stencil_attachment_config.load_action;
527 depth0.store_action = stencil_attachment_config.store_action;
528 depth0.clear_depth = 0u;
529 depth0.texture = depth_stencil_texture;
530
531 StencilAttachment stencil0;
532 stencil0.load_action = stencil_attachment_config.load_action;
533 stencil0.store_action = stencil_attachment_config.store_action;
534 stencil0.clear_stencil = 0u;
535 stencil0.texture = std::move(depth_stencil_texture);
536 stencil0.texture->SetLabel(label, "Depth+Stencil Texture");
537
538 SetDepthAttachment(std::move(depth0));
539 SetStencilAttachment(std::move(stencil0));
540}
RenderTarget & SetDepthAttachment(std::optional< DepthAttachment > attachment)
RenderTarget & SetStencilAttachment(std::optional< StencilAttachment > attachment)
std::shared_ptr< ImpellerAllocator > allocator
std::shared_ptr< ContextGLES > context

References allocator, impeller::DepthAttachment::clear_depth, impeller::StencilAttachment::clear_stencil, context, impeller::TextureDescriptor::format, impeller::kCount4, impeller::kRenderTarget, impeller::kTexture2DMultisample, impeller::Attachment::load_action, impeller::RenderTarget::AttachmentConfig::load_action, impeller::TextureDescriptor::sample_count, SetDepthAttachment(), SetStencilAttachment(), impeller::TextureDescriptor::size, impeller::TextureDescriptor::storage_mode, impeller::RenderTarget::AttachmentConfig::storage_mode, impeller::Attachment::store_action, impeller::RenderTarget::AttachmentConfig::store_action, impeller::Attachment::texture, impeller::TextureDescriptor::type, and impeller::TextureDescriptor::usage.

Referenced by impeller::SurfaceVK::WrapSwapchainImage().

◆ ToConfig()

RenderTargetConfig impeller::RenderTarget::ToConfig ( ) const

Definition at line 317 of file render_target.cc.

317 {
318 if (!color0_.has_value()) {
319 return RenderTargetConfig{};
320 }
321 const auto& color_attachment = color0_.value();
322 return RenderTargetConfig{
323 .size = color_attachment.texture->GetSize(),
324 .mip_count = color_attachment.texture->GetMipCount(),
325 .has_msaa = color_attachment.resolve_texture != nullptr,
326 .has_depth_stencil = depth_.has_value() && stencil_.has_value()};
327}

References impeller::RenderTargetConfig::size.

◆ ToString()

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

Definition at line 293 of file render_target.cc.

293 {
294 std::stringstream stream;
295
296 if (color0_.has_value()) {
297 stream << std::format("Color[{}]=({})", 0,
298 ColorAttachmentToString(color0_.value()));
299 }
300 for (const auto& [index, color] : colors_) {
301 stream << std::format("Color[{}]=({})", index,
303 }
304 if (depth_) {
305 stream << ",";
306 stream << std::format("Depth=({})",
307 DepthAttachmentToString(depth_.value()));
308 }
309 if (stencil_) {
310 stream << ",";
311 stream << std::format("Stencil=({})",
312 StencilAttachmentToString(stencil_.value()));
313 }
314 return stream.str();
315}
std::string DepthAttachmentToString(const DepthAttachment &depth)
Definition formats.cc:144
std::string ColorAttachmentToString(const ColorAttachment &color)
Definition formats.cc:137
std::string StencilAttachmentToString(const StencilAttachment &stencil)
Definition formats.cc:151

References impeller::ColorAttachmentToString(), impeller::DepthAttachmentToString(), and impeller::StencilAttachmentToString().

Referenced by IsValid().

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:275

Definition at line 55 of file render_target.h.

55 {
56 .storage_mode = StorageMode::kDevicePrivate,
57 .load_action = LoadAction::kClear,
58 .store_action = StoreAction::kStore,
59 .clear_color = Color::BlackTransparent()};

Referenced by impeller::DisplayListToTexture(), impeller::ContentContext::MakeSubpass(), impeller::GoldenPlaygroundTest::OpenPlaygroundHere(), and impeller::testing::TEST_P().

◆ 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.

61 {
62 .storage_mode = StorageMode::kDeviceTransient,
63 .resolve_storage_mode = StorageMode::kDevicePrivate,
64 .load_action = LoadAction::kClear,
66 .clear_color = Color::BlackTransparent()};

Referenced by impeller::ContentContext::MakeSubpass().

◆ 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.

68 {
69 .storage_mode = StorageMode::kDeviceTransient,
70 .load_action = LoadAction::kClear,
71 .store_action = StoreAction::kDontCare,
72 .clear_color = Color::BlackTransparent()};

Referenced by impeller::ContentContext::MakeSubpass(), impeller::SurfaceVK::WrapSwapchainImage(), and impeller::WrapTextureWithRenderTarget().


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