| 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, std::optional< Rect > coverage_limit=std::nullopt, const std::optional< SamplerDescriptor > &sampler_descriptor=std::nullopt, bool msaa_enabled=true, int32_t mip_count=1, std::string_view label="Snapshot") 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 40 of file atlas_contents.h.

## Constructor & Destructor Documentation

## ◆ AtlasContents()

impeller::AtlasContents::AtlasContents | ( |  | ) |
| explicit default

## ◆ ~AtlasContents()

impeller::AtlasContents::~AtlasContents | ( |  | ) |
| override default

## Member Function Documentation

## ◆ GetCoverage()

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

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 23 of file atlas_contents.cc.

23 {
24 if (!geometry_) {
25 return std::nullopt;
26 }
27 return geometry_->ComputeBoundingBox().TransformBounds(entity.GetTransform());
28 }

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
| override virtual

Implements impeller::Contents.

Definition at line 38 of file atlas_contents.cc.

40 {
41 if (geometry_->ShouldSkip() || alpha_ <= 0.0) {
42 return true;
43 }
44
45 auto dst_sampler_descriptor = geometry_->GetSamplerDescriptor();
46 if (renderer.GetDeviceCapabilities().SupportsDecalSamplerAddressMode()) {
47 dst_sampler_descriptor.width_address_mode = SamplerAddressMode::kDecal;
48 dst_sampler_descriptor.height_address_mode = SamplerAddressMode::kDecal;
49 }
50 raw_ptr<const Sampler> dst_sampler =
51 renderer.GetContext()->GetSamplerLibrary()->GetSampler(
52 dst_sampler_descriptor);
53
54 auto& host_buffer = renderer.GetTransientsBuffer();
55 if (!geometry_->ShouldUseBlend()) {
56 using VS = TextureFillVertexShader;
57 using FS = TextureFillFragmentShader;
58
59 auto dst_sampler_descriptor = geometry_->GetSamplerDescriptor();
60
61 raw_ptr<const Sampler> dst_sampler =
62 renderer.GetContext()->GetSamplerLibrary()->GetSampler(
63 dst_sampler_descriptor);
64
65 auto pipeline_options = OptionsFromPassAndEntity(pass, entity);
66 pipeline_options.primitive_type = PrimitiveType::kTriangle;
67 pipeline_options.depth_write_enabled =
68 pipeline_options.blend_mode == BlendMode::kSource;
69
70 pass.SetPipeline(renderer.GetTexturePipeline(pipeline_options));
71 pass.SetVertexBuffer(geometry_->CreateSimpleVertexBuffer(host_buffer));
72 #ifdef IMPELLER_DEBUG
73 pass.SetCommandLabel("DrawAtlas");
74 #endif // IMPELLER_DEBUG
75
76 VS::FrameInfo frame_info;
77 frame_info.mvp = entity.GetShaderTransform(pass);
78 frame_info.texture_sampler_y_coord_scale =
79 geometry_->GetAtlas()->GetYCoordScale();
80
81 VS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));
82
83 FS::FragInfo frag_info;
84 frag_info.alpha = alpha_;
85 FS::BindFragInfo(pass, host_buffer.EmplaceUniform((frag_info)));
86 FS::BindTextureSampler(pass, geometry_->GetAtlas(), dst_sampler);
87 return pass.Draw().ok();
88 }
89
90 BlendMode blend_mode = geometry_->GetBlendMode();
91
92 if (blend_mode <= BlendMode::kModulate) {
93 using VS = PorterDuffBlendPipeline::VertexShader;
94 using FS = PorterDuffBlendPipeline::FragmentShader;
95
96 #ifdef IMPELLER_DEBUG
97 pass.SetCommandLabel("DrawAtlas Blend");
98 #endif // IMPELLER_DEBUG
99 pass.SetVertexBuffer(geometry_->CreateBlendVertexBuffer(host_buffer));
100 auto inverted_blend_mode =
101 InvertPorterDuffBlend(blend_mode).value_or(BlendMode::kSource);
102 pass.SetPipeline(renderer.GetPorterDuffPipeline(inverted_blend_mode,
103 OptionsFromPass(pass)));
104
105 FS::FragInfo frag_info;
106 VS::FrameInfo frame_info;
107
108 FS::BindTextureSamplerDst(pass, geometry_->GetAtlas(), dst_sampler);
109 frame_info.texture_sampler_y_coord_scale =
110 geometry_->GetAtlas()->GetYCoordScale();
111
112 frag_info.output_alpha = alpha_;
113 frag_info.input_alpha = 1.0;
114
115 // These values are ignored on platforms that natively support decal.
116 frag_info.tmx = static_cast<int>(Entity::TileMode::kDecal);
117 frag_info.tmy = static_cast<int>(Entity::TileMode::kDecal);
118
119 FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
120
121 frame_info.mvp = entity.GetShaderTransform(pass);
122
123 auto uniform_view = host_buffer.EmplaceUniform(frame_info);
124 VS::BindFrameInfo(pass, uniform_view);
125
126 return pass.Draw().ok();
127 }
128
129 using VUS = VerticesUberShader::VertexShader;
130 using FS = VerticesUberShader::FragmentShader;
131
132 #ifdef IMPELLER_DEBUG
133 pass.SetCommandLabel("DrawAtlas Advanced Blend");
134 #endif // IMPELLER_DEBUG
135 pass.SetVertexBuffer(geometry_->CreateBlendVertexBuffer(host_buffer));
136
137 pass.SetPipeline(renderer.GetDrawVerticesUberShader(OptionsFromPass(pass)));
138 FS::BindTextureSampler(pass, geometry_->GetAtlas(), dst_sampler);
139
140 VUS::FrameInfo frame_info;
141 FS::FragInfo frag_info;
142
143 frame_info.texture_sampler_y_coord_scale =
144 geometry_->GetAtlas()->GetYCoordScale();
145 frame_info.mvp = entity.GetShaderTransform(pass);
146
147 frag_info.alpha = alpha_;
148 frag_info.blend_mode = static_cast<int>(blend_mode);
149
150 // These values are ignored on platforms that natively support decal.
151 frag_info.tmx = static_cast<int>(Entity::TileMode::kDecal);
152 frag_info.tmy = static_cast<int>(Entity::TileMode::kDecal);
153
154 FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
155 VUS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));
156
157 return pass.Draw().ok();
158 }

References impeller::AtlasGeometry::CreateBlendVertexBuffer(), impeller::AtlasGeometry::CreateSimpleVertexBuffer(), impeller::RenderPass::Draw(), impeller::AtlasGeometry::GetAtlas(), impeller::AtlasGeometry::GetBlendMode(), impeller::ContentContext::GetContext(), impeller::ContentContext::GetDeviceCapabilities(), impeller::ContentContext::GetDrawVerticesUberShader(), impeller::ContentContext::GetPorterDuffPipeline(), impeller::AtlasGeometry::GetSamplerDescriptor(), impeller::Entity::GetShaderTransform(), impeller::ContentContext::GetTexturePipeline(), impeller::ContentContext::GetTransientsBuffer(), impeller::InvertPorterDuffBlend(), impeller::Entity::kDecal, impeller::kDecal, impeller::kModulate, impeller::kSource, impeller::kTriangle, impeller::OptionsFromPass(), impeller::OptionsFromPassAndEntity(), impeller::RenderPass::SetCommandLabel(), impeller::RenderPass::SetPipeline(), impeller::RenderPass::SetVertexBuffer(), impeller::AtlasGeometry::ShouldSkip(), impeller::AtlasGeometry::ShouldUseBlend(), impeller::Capabilities::SupportsDecalSamplerAddressMode(), and impeller::SamplerDescriptor::width_address_mode.

## ◆ SetAlpha()

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

Definition at line 34 of file atlas_contents.cc.

34 {
35 alpha_ = alpha;
36 }

## ◆ SetGeometry()

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

Definition at line 30 of file atlas_contents.cc.

30 {
31 geometry_ = geometry;
32 }

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

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

impeller::RenderPipelineHandle::FragmentShader
FragmentShader_ FragmentShader
Definition: pipeline.h:114
impeller::OptionsFromPass
ContentContextOptions OptionsFromPass(const RenderPass &pass)
Definition: contents.cc:19
impeller::AtlasGeometry::ShouldUseBlend
virtual bool ShouldUseBlend() const =0
impeller::SamplerAddressMode::kDecal
@ kDecal
decal sampling mode is only supported on devices that pass the Capabilities.SupportsDecalSamplerAddre...
impeller::BlendMode
BlendMode
Definition: color.h:58
impeller::AtlasGeometry::GetBlendMode
virtual BlendMode GetBlendMode() const =0
impeller::Entity::TileMode::kDecal
@ kDecal
impeller::BlendMode::kSource
@ kSource
impeller::VS
GlyphAtlasPipeline::VertexShader VS
Definition: text_contents.cc:25
impeller::TRect::TransformBounds
constexpr TRect TransformBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle.
Definition: rect.h:476
impeller::InvertPorterDuffBlend
std::optional< BlendMode > InvertPorterDuffBlend(BlendMode blend_mode)
Definition: blend_filter_contents.cc:51
impeller::AtlasGeometry::GetSamplerDescriptor
virtual const SamplerDescriptor & GetSamplerDescriptor() const =0
impeller::AtlasGeometry::ShouldSkip
virtual bool ShouldSkip() const =0
impeller::BlendMode::kModulate
@ kModulate
impeller::PrimitiveType::kTriangle
@ kTriangle
impeller::OptionsFromPassAndEntity
ContentContextOptions OptionsFromPassAndEntity(const RenderPass &pass, const Entity &entity)
Definition: contents.cc:34
impeller::AtlasGeometry::GetAtlas
virtual std::shared_ptr< Texture > GetAtlas() const =0
impeller::AtlasGeometry::CreateSimpleVertexBuffer
virtual VertexBuffer CreateSimpleVertexBuffer(HostBuffer &host_buffer) const =0
impeller::RenderPipelineHandle::VertexShader
VertexShader_ VertexShader
Definition: pipeline.h:113
impeller::SamplerDescriptor::width_address_mode
SamplerAddressMode width_address_mode
Definition: sampler_descriptor.h:19
impeller::AtlasGeometry::ComputeBoundingBox
virtual Rect ComputeBoundingBox() const =0
impeller::AtlasGeometry::CreateBlendVertexBuffer
virtual VertexBuffer CreateBlendVertexBuffer(HostBuffer &host_buffer) const =0
impeller::FS
GlyphAtlasPipeline::FragmentShader FS
Definition: text_contents.cc:26