| Flutter Impeller |

Public Member Functions | List of all members
impeller::AtlasContents Class Referencefinal

`#include <atlas_contents.h>`

Inheritance diagram for impeller::AtlasContents:

## Public Member Functions
| AtlasContents ()
| ~AtlasContents () override
void | SetGeometry (AtlasGeometry *geometry)
void | SetAlpha (Scalar alpha)
std::optional< Rect > | GetCoverage (const Entity &entity) const override
| Get the area of the render pass that will be affected when this contents is rendered. More...
bool | Render (const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
Public Member Functions inherited from impeller::Contents
| Contents ()
virtual | ~Contents ()
void | SetCoverageHint (std::optional< Rect > coverage_hint)
| Hint that specifies the coverage area of this Contents that will actually be used during rendering. This is for optimization purposes only and can not be relied on as a clip. May optionally affect the result of `GetCoverage()`. More...
const std::optional< Rect > & | GetCoverageHint () const
virtual bool | IsOpaque (const Matrix &transform) const
| Whether this Contents only emits opaque source colors from the fragment stage. This value does not account for any entity properties (e.g. the blend mode), clips/visibility culling, or inherited opacity. More...
virtual std::optional< Snapshot > | RenderToSnapshot (const ContentContext &renderer, const Entity &entity, const SnapshotOptions &options) const
| Render this contents to a snapshot, respecting the entity's transform, path, clip depth, and blend mode. The result texture size is always the size of `GetCoverage(entity)`. More...
std::optional< Size > | GetColorSourceSize () const
| Return the color source's intrinsic size, if available. More...
void | SetColorSourceSize (Size size)
virtual void | SetInheritedOpacity (Scalar opacity)
| Inherit the provided opacity. More...
virtual std::optional< Color > | AsBackgroundColor (const Entity &entity, ISize target_size) const
| Returns a color if this Contents will flood the given `target_size` with a color. This output color is the "Source" color that will be used for the Entity's blend operation. More...
virtual bool | ApplyColorFilter (const ColorFilterProc &color_filter_proc)
| If possible, applies a color filter to this contents inputs on the CPU. More...

## Additional Inherited Members
Public Types inherited from impeller::Contents
using | ColorFilterProc = std::function< Color(Color)>
using | RenderProc = std::function< bool(const ContentContext &renderer, const Entity &entity, RenderPass &pass)>
using | CoverageProc = std::function< std::optional< Rect >(const Entity &entity)>
Static Public Member Functions inherited from impeller::Contents
static std::shared_ptr< Contents > | MakeAnonymous (RenderProc render_proc, CoverageProc coverage_proc)

## Detailed Description

Definition at line 93 of file atlas_contents.h.

## Constructor & Destructor Documentation

## ◆ AtlasContents()

impeller::AtlasContents::AtlasContents | ( |  | ) |
| explicitdefault

## ◆ ~AtlasContents()

impeller::AtlasContents::~AtlasContents | ( |  | ) |
| overridedefault

## Member Function Documentation

## ◆ GetCoverage()

std::optional< Rect > impeller::AtlasContents::GetCoverage | ( | const Entity & | entity | ) | const
| overridevirtual

Get the area of the render pass that will be affected when this contents is rendered.

During rendering, coverage coordinates count pixels from the top left corner of the framebuffer.

Returns
  The coverage rectangle. An `std::nullopt` result means that rendering this contents has no effect on the output color.

Implements impeller::Contents.

Definition at line 144 of file atlas_contents.cc.

144 {
145 if (!geometry_) {
146 return std::nullopt;
147 }
148 return geometry_->ComputeBoundingBox().TransformBounds(entity.GetTransform());
149 }
impeller::AtlasGeometry::ComputeBoundingBox
virtual Rect ComputeBoundingBox() const =0
impeller::TRect::TransformBounds
constexpr TRect TransformBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle.
Definition: rect.h:472

References impeller::AtlasGeometry::ComputeBoundingBox(), impeller::Entity::GetTransform(), and impeller::TRect< T >::TransformBounds().

## ◆ Render()

bool impeller::AtlasContents::Render | ( | const ContentContext & | renderer,
|  | const Entity & | entity,
|  | RenderPass & | pass
| ) |  | const
| overridevirtual

Implements impeller::Contents.

Definition at line 159 of file atlas_contents.cc.

161 {
162 if (geometry_->ShouldSkip() || alpha_ <= 0.0) {
163 return true;
164 }
165
166 const SamplerDescriptor& dst_sampler_descriptor =
167 geometry_->GetSamplerDescriptor();
168 raw_ptr<const Sampler> dst_sampler =
169 renderer.GetContext()->GetSamplerLibrary()->GetSampler(
170 dst_sampler_descriptor);
171
172 auto& data_host_buffer = renderer.GetTransientsDataBuffer();
173 if (!geometry_->ShouldUseBlend()) {
174 using VS = TextureFillVertexShader;
175 using FS = TextureFillFragmentShader;
176
177 raw_ptr<const Sampler> dst_sampler =
178 renderer.GetContext()->GetSamplerLibrary()->GetSampler(
179 dst_sampler_descriptor);
180
181 auto pipeline_options = OptionsFromPassAndEntity(pass, entity);
182 pipeline_options.primitive_type = PrimitiveType::kTriangle;
183 pipeline_options.depth_write_enabled =
184 pipeline_options.blend_mode == BlendMode::kSrc;
185
186 pass.SetPipeline(renderer.GetTexturePipeline(pipeline_options));
187 pass.SetVertexBuffer(geometry_->CreateSimpleVertexBuffer(data_host_buffer));
188 #ifdef IMPELLER_DEBUG
189 pass.SetCommandLabel("DrawAtlas");
190 #endif // IMPELLER_DEBUG
191
192 VS::FrameInfo frame_info;
193 frame_info.mvp = entity.GetShaderTransform(pass);
194 frame_info.texture_sampler_y_coord_scale =
195 geometry_->GetAtlas()->GetYCoordScale();
196
197 VS::BindFrameInfo(pass, data_host_buffer.EmplaceUniform(frame_info));
198
199 FS::FragInfo frag_info;
200 frag_info.alpha = alpha_;
201 FS::BindFragInfo(pass, data_host_buffer.EmplaceUniform((frag_info)));
202 FS::BindTextureSampler(pass, geometry_->GetAtlas(), dst_sampler);
203 return pass.Draw().ok();
204 }
205
206 BlendMode blend_mode = geometry_->GetBlendMode();
207
208 if (blend_mode <= BlendMode::kModulate) {
209 using VS = PorterDuffBlendPipeline::VertexShader;
210 using FS = PorterDuffBlendPipeline::FragmentShader;
211
212 #ifdef IMPELLER_DEBUG
213 pass.SetCommandLabel("DrawAtlas Blend");
214 #endif // IMPELLER_DEBUG
215 pass.SetVertexBuffer(geometry_->CreateBlendVertexBuffer(data_host_buffer));
216 BlendMode inverted_blend_mode =
217 geometry_->ShouldInvertBlendMode()
218 ? (InvertPorterDuffBlend(blend_mode).value_or(BlendMode::kSrc))
219 : blend_mode;
220 pass.SetPipeline(renderer.GetPorterDuffPipeline(
221 inverted_blend_mode, OptionsFromPassAndEntity(pass, entity)));
222
223 FS::FragInfo frag_info;
224 VS::FrameInfo frame_info;
225
226 FS::BindTextureSamplerDst(pass, geometry_->GetAtlas(), dst_sampler);
227 frame_info.texture_sampler_y_coord_scale =
228 geometry_->GetAtlas()->GetYCoordScale();
229
230 frag_info.input_alpha_output_alpha_tmx_tmy =
231 Vector4(1.0, alpha_, static_cast<int>(Entity::TileMode::kDecal),
232 static_cast<int>(Entity::TileMode::kDecal));
233 if (auto rect = geometry_->GetStrictSrcRect(); rect.has_value()) {
234 Rect src_rect = rect.value();
235 frag_info.source_rect =
236 Vector4(src_rect.GetX(), src_rect.GetY(), src_rect.GetRight(),
237 src_rect.GetBottom());
238 frag_info.use_strict_source_rect = 1.0;
239 } else {
240 frag_info.use_strict_source_rect = 0.0;
241 }
242
243 FS::BindFragInfo(pass, data_host_buffer.EmplaceUniform(frag_info));
244
245 frame_info.mvp = entity.GetShaderTransform(pass);
246
247 auto uniform_view = data_host_buffer.EmplaceUniform(frame_info);
248 VS::BindFrameInfo(pass, uniform_view);
249
250 return pass.Draw().ok();
251 }
252
253 using VUS = VerticesUber1Shader::VertexShader;
254 using FS = VerticesUber1Shader::FragmentShader;
255
256 #ifdef IMPELLER_DEBUG
257 pass.SetCommandLabel("DrawAtlas Advanced Blend");
258 #endif // IMPELLER_DEBUG
259 pass.SetVertexBuffer(geometry_->CreateBlendVertexBuffer(data_host_buffer));
260
261 pass.SetPipeline(renderer.GetDrawVerticesUberPipeline(
262 blend_mode, OptionsFromPassAndEntity(pass, entity)));
263 FS::BindTextureSampler(pass, geometry_->GetAtlas(), dst_sampler);
264
265 VUS::FrameInfo frame_info;
266 FS::FragInfo frag_info;
267
268 frame_info.texture_sampler_y_coord_scale =
269 geometry_->GetAtlas()->GetYCoordScale();
270 frame_info.mvp = entity.GetShaderTransform(pass);
271
272 frag_info.alpha = alpha_;
273 frag_info.blend_mode = static_cast<int>(blend_mode);
274
275 // These values are ignored on platforms that natively support decal.
276 frag_info.tmx = static_cast<int>(Entity::TileMode::kDecal);
277 frag_info.tmy = static_cast<int>(Entity::TileMode::kDecal);
278
279 FS::BindFragInfo(pass, data_host_buffer.EmplaceUniform(frag_info));
280 VUS::BindFrameInfo(pass, data_host_buffer.EmplaceUniform(frame_info));
281
282 return pass.Draw().ok();
283 }
impeller::AtlasGeometry::GetStrictSrcRect
virtual std::optional< Rect > GetStrictSrcRect() const
The source rect of the draw in texture coordinates if a strict source rect should be applied,...
Definition: atlas_contents.h:47
impeller::AtlasGeometry::CreateSimpleVertexBuffer
virtual VertexBuffer CreateSimpleVertexBuffer(HostBuffer &host_buffer) const =0
impeller::AtlasGeometry::ShouldInvertBlendMode
virtual bool ShouldInvertBlendMode() const
Definition: atlas_contents.h:41
impeller::AtlasGeometry::ShouldUseBlend
virtual bool ShouldUseBlend() const =0
impeller::AtlasGeometry::GetSamplerDescriptor
virtual const SamplerDescriptor & GetSamplerDescriptor() const =0
impeller::AtlasGeometry::ShouldSkip
virtual bool ShouldSkip() const =0
impeller::AtlasGeometry::CreateBlendVertexBuffer
virtual VertexBuffer CreateBlendVertexBuffer(HostBuffer &host_buffer) const =0
impeller::AtlasGeometry::GetBlendMode
virtual BlendMode GetBlendMode() const =0
impeller::AtlasGeometry::GetAtlas
virtual const std::shared_ptr< Texture > & GetAtlas() const =0
impeller::Entity::TileMode::kDecal
@ kDecal
impeller::RenderPipelineHandle::VertexShader
VertexShader_ VertexShader
Definition: pipeline.h:163
impeller::RenderPipelineHandle::FragmentShader
FragmentShader_ FragmentShader
Definition: pipeline.h:164
impeller::PrimitiveType::kTriangle
@ kTriangle
impeller::Rect
TRect< Scalar > Rect
Definition: rect.h:788
impeller::FS
LinePipeline::FragmentShader FS
Definition: line_contents.cc:14
impeller::InvertPorterDuffBlend
std::optional< BlendMode > InvertPorterDuffBlend(BlendMode blend_mode)
Definition: blend_filter_contents.cc:51
impeller::BlendMode
BlendMode
Definition: color.h:58
impeller::BlendMode::kModulate
@ kModulate
impeller::BlendMode::kSrc
@ kSrc
impeller::VS
LinePipeline::VertexShader VS
Definition: line_contents.cc:13
impeller::OptionsFromPassAndEntity
ContentContextOptions OptionsFromPassAndEntity(const RenderPass &pass, const Entity &entity)
Definition: contents.cc:34

References impeller::AtlasGeometry::CreateBlendVertexBuffer(), impeller::AtlasGeometry::CreateSimpleVertexBuffer(), impeller::RenderPass::Draw(), impeller::AtlasGeometry::GetAtlas(), impeller::AtlasGeometry::GetBlendMode(), impeller::TRect< T >::GetBottom(), impeller::ContentContext::GetContext(), impeller::ContentContext::GetDrawVerticesUberPipeline(), impeller::ContentContext::GetPorterDuffPipeline(), impeller::TRect< T >::GetRight(), impeller::AtlasGeometry::GetSamplerDescriptor(), impeller::Entity::GetShaderTransform(), impeller::AtlasGeometry::GetStrictSrcRect(), impeller::ContentContext::GetTexturePipeline(), impeller::ContentContext::GetTransientsDataBuffer(), impeller::TRect< T >::GetX(), impeller::TRect< T >::GetY(), impeller::InvertPorterDuffBlend(), impeller::Entity::kDecal, impeller::kModulate, impeller::kSrc, impeller::kTriangle, impeller::OptionsFromPassAndEntity(), impeller::RenderPass::SetCommandLabel(), impeller::RenderPass::SetPipeline(), impeller::RenderPass::SetVertexBuffer(), impeller::AtlasGeometry::ShouldInvertBlendMode(), impeller::AtlasGeometry::ShouldSkip(), and impeller::AtlasGeometry::ShouldUseBlend().

## ◆ SetAlpha()

void impeller::AtlasContents::SetAlpha | ( | Scalar | alpha | ) |

Definition at line 155 of file atlas_contents.cc.

155 {
156 alpha_ = alpha;
157 }

## ◆ SetGeometry()

void impeller::AtlasContents::SetGeometry | ( | AtlasGeometry * | geometry | ) |

Definition at line 151 of file atlas_contents.cc.

151 {
152 geometry_ = geometry;
153 }

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

- impeller/entity/contents/atlas_contents.h
- impeller/entity/contents/atlas_contents.cc