| 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 ClipCoverage | GetClipCoverage (const Entity &entity, const std::optional< Rect > &current_clip_coverage) const
| Given the current pass space bounding rectangle of the clip buffer, return the expected clip coverage after this draw call. This should only be implemented for contents that may write to the clip buffer. 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, const std::string &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 const FilterContents * | AsFilter () const
| Cast to a filter. Returns `nullptr` if this Contents is not a filter. 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 | ( |  | ) |
| 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 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
| overridevirtual

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 const std::unique_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 const std::unique_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(
98 SPrintF("DrawAtlas Blend (%s)", BlendModeToString(blend_mode)));
99 #endif // IMPELLER_DEBUG
100 pass.SetVertexBuffer(geometry_->CreateBlendVertexBuffer(host_buffer));
101 pass.SetPipeline(
102 renderer.GetPorterDuffBlendPipeline(OptionsFromPass(pass)));
103
104 FS::FragInfo frag_info;
105 VS::FrameInfo frame_info;
106
107 FS::BindTextureSamplerDst(pass, geometry_->GetAtlas(), dst_sampler);
108 frame_info.texture_sampler_y_coord_scale =
109 geometry_->GetAtlas()->GetYCoordScale();
110
111 frag_info.output_alpha = alpha_;
112 frag_info.input_alpha = 1.0;
113
114 auto inverted_blend_mode =
115 InvertPorterDuffBlend(blend_mode).value_or(BlendMode::kSource);
116 auto blend_coefficients =
117 kPorterDuffCoefficients[static_cast<int>(inverted_blend_mode)];
118 frag_info.src_coeff = blend_coefficients[0];
119 frag_info.src_coeff_dst_alpha = blend_coefficients[1];
120 frag_info.dst_coeff = blend_coefficients[2];
121 frag_info.dst_coeff_src_alpha = blend_coefficients[3];
122 frag_info.dst_coeff_src_color = blend_coefficients[4];
123 // These values are ignored on platforms that natively support decal.
124 frag_info.tmx = static_cast<int>(Entity::TileMode::kDecal);
125 frag_info.tmy = static_cast<int>(Entity::TileMode::kDecal);
126
127 FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
128
129 frame_info.mvp = entity.GetShaderTransform(pass);
130
131 auto uniform_view = host_buffer.EmplaceUniform(frame_info);
132 VS::BindFrameInfo(pass, uniform_view);
133
134 return pass.Draw().ok();
135 }
136
137 using VUS = VerticesUberShader::VertexShader;
138 using FS = VerticesUberShader::FragmentShader;
139
140 #ifdef IMPELLER_DEBUG
141 pass.SetCommandLabel(
142 SPrintF("DrawAtlas Advanced Blend (%s)", BlendModeToString(blend_mode)));
143 #endif // IMPELLER_DEBUG
144 pass.SetVertexBuffer(geometry_->CreateBlendVertexBuffer(host_buffer));
145
146 pass.SetPipeline(renderer.GetDrawVerticesUberShader(OptionsFromPass(pass)));
147 FS::BindTextureSampler(pass, geometry_->GetAtlas(), dst_sampler);
148
149 VUS::FrameInfo frame_info;
150 FS::FragInfo frag_info;
151
152 frame_info.texture_sampler_y_coord_scale =
153 geometry_->GetAtlas()->GetYCoordScale();
154 frame_info.mvp = entity.GetShaderTransform(pass);
155
156 frag_info.alpha = alpha_;
157 frag_info.blend_mode = static_cast<int>(blend_mode);
158
159 // These values are ignored on platforms that natively support decal.
160 frag_info.tmx = static_cast<int>(Entity::TileMode::kDecal);
161 frag_info.tmy = static_cast<int>(Entity::TileMode::kDecal);
162
163 FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
164 VUS::BindFrameInfo(pass, host_buffer.EmplaceUniform(frame_info));
165
166 return pass.Draw().ok();
167 }

References impeller::BlendModeToString(), 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::GetPorterDuffBlendPipeline(), impeller::AtlasGeometry::GetSamplerDescriptor(), impeller::Entity::GetShaderTransform(), impeller::ContentContext::GetTexturePipeline(), impeller::ContentContext::GetTransientsBuffer(), impeller::InvertPorterDuffBlend(), impeller::Entity::kDecal, impeller::kDecal, impeller::kModulate, impeller::kPorterDuffCoefficients, impeller::kSource, impeller::kTriangle, impeller::OptionsFromPass(), impeller::OptionsFromPassAndEntity(), impeller::RenderPass::SetCommandLabel(), impeller::RenderPass::SetPipeline(), impeller::RenderPass::SetVertexBuffer(), impeller::AtlasGeometry::ShouldSkip(), impeller::AtlasGeometry::ShouldUseBlend(), impeller::SPrintF(), 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:107
impeller::OptionsFromPass
ContentContextOptions OptionsFromPass(const RenderPass &pass)
Definition: contents.cc:19
impeller::AtlasGeometry::ShouldUseBlend
virtual bool ShouldUseBlend() const =0
impeller::BlendModeToString
const char * BlendModeToString(BlendMode blend_mode)
Definition: color.cc:47
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::TRect::TransformBounds
constexpr TRect TransformBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle.
Definition: rect.h:466
impeller::InvertPorterDuffBlend
std::optional< BlendMode > InvertPorterDuffBlend(BlendMode blend_mode)
Definition: blend_filter_contents.cc:33
impeller::AtlasGeometry::GetSamplerDescriptor
virtual const SamplerDescriptor & GetSamplerDescriptor() const =0
impeller::AtlasGeometry::ShouldSkip
virtual bool ShouldSkip() const =0
impeller::BlendMode::kModulate
@ kModulate
impeller::VS
SolidFillVertexShader VS
Definition: stroke_path_geometry.cc:16
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::SPrintF
std::string SPrintF(const char *format,...)
Definition: strings.cc:12
impeller::AtlasGeometry::CreateSimpleVertexBuffer
virtual VertexBuffer CreateSimpleVertexBuffer(HostBuffer &host_buffer) const =0
impeller::RenderPipelineHandle::VertexShader
VertexShader_ VertexShader
Definition: pipeline.h:106
impeller::SamplerDescriptor::width_address_mode
SamplerAddressMode width_address_mode
Definition: sampler_descriptor.h:20
impeller::kPorterDuffCoefficients
constexpr std::array< std::array< Scalar, 5 >, 15 > kPorterDuffCoefficients
Definition: blend_filter_contents.h:15
impeller::AtlasGeometry::ComputeBoundingBox
virtual Rect ComputeBoundingBox() const =0
impeller::AtlasGeometry::CreateBlendVertexBuffer
virtual VertexBuffer CreateBlendVertexBuffer(HostBuffer &host_buffer) const =0
impeller::SamplerAddressMode::kDecal
@ kDecal
decal sampling mode is only supported on devices that pass the Capabilities.SupportsDecalSamplerAddre...