Flutter Impeller
impeller::AtlasContents Class Referencefinal

#include <atlas_contents.h>

Inheritance diagram for impeller::AtlasContents:
impeller::Contents

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 }
virtual Rect ComputeBoundingBox() const =0
constexpr TRect TransformBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle.
Definition: rect.h:506

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 
195  VS::BindFrameInfo(pass, data_host_buffer.EmplaceUniform(frame_info));
196 
197  FS::FragInfo frag_info;
198  frag_info.alpha = alpha_;
199  FS::BindFragInfo(pass, data_host_buffer.EmplaceUniform((frag_info)));
200  FS::BindTextureSampler(pass, geometry_->GetAtlas(), dst_sampler);
201  return pass.Draw().ok();
202  }
203 
204  BlendMode blend_mode = geometry_->GetBlendMode();
205 
206  if (blend_mode <= BlendMode::kModulate) {
209 
210 #ifdef IMPELLER_DEBUG
211  pass.SetCommandLabel("DrawAtlas Blend");
212 #endif // IMPELLER_DEBUG
213  pass.SetVertexBuffer(geometry_->CreateBlendVertexBuffer(data_host_buffer));
214  BlendMode inverted_blend_mode =
215  geometry_->ShouldInvertBlendMode()
216  ? (InvertPorterDuffBlend(blend_mode).value_or(BlendMode::kSrc))
217  : blend_mode;
218  pass.SetPipeline(renderer.GetPorterDuffPipeline(
219  inverted_blend_mode, OptionsFromPassAndEntity(pass, entity)));
220 
221  FS::FragInfo frag_info;
222  VS::FrameInfo frame_info;
223 
224  FS::BindTextureSamplerDst(pass, geometry_->GetAtlas(), dst_sampler);
225 
226  frag_info.input_alpha_output_alpha_tmx_tmy =
227  Vector4(1.0, alpha_, static_cast<int>(Entity::TileMode::kDecal),
228  static_cast<int>(Entity::TileMode::kDecal));
229  if (auto rect = geometry_->GetStrictSrcRect(); rect.has_value()) {
230  Rect src_rect = rect.value();
231  frag_info.source_rect =
232  Vector4(src_rect.GetX(), src_rect.GetY(), src_rect.GetRight(),
233  src_rect.GetBottom());
234  frag_info.use_strict_source_rect = 1.0;
235  } else {
236  frag_info.use_strict_source_rect = 0.0;
237  }
238 
239  FS::BindFragInfo(pass, data_host_buffer.EmplaceUniform(frag_info));
240 
241  frame_info.mvp = entity.GetShaderTransform(pass);
242 
243  auto uniform_view = data_host_buffer.EmplaceUniform(frame_info);
244  VS::BindFrameInfo(pass, uniform_view);
245 
246  return pass.Draw().ok();
247  }
248 
251 
252 #ifdef IMPELLER_DEBUG
253  pass.SetCommandLabel("DrawAtlas Advanced Blend");
254 #endif // IMPELLER_DEBUG
255  pass.SetVertexBuffer(geometry_->CreateBlendVertexBuffer(data_host_buffer));
256 
257  pass.SetPipeline(renderer.GetDrawVerticesUberPipeline(
258  blend_mode, OptionsFromPassAndEntity(pass, entity)));
259  FS::BindTextureSampler(pass, geometry_->GetAtlas(), dst_sampler);
260 
261  VUS::FrameInfo frame_info;
262  FS::FragInfo frag_info;
263 
264  frame_info.mvp = entity.GetShaderTransform(pass);
265 
266  frag_info.alpha = alpha_;
267  frag_info.blend_mode = static_cast<int>(blend_mode);
268 
269  // These values are ignored on platforms that natively support decal.
270  frag_info.tmx = static_cast<int>(Entity::TileMode::kDecal);
271  frag_info.tmy = static_cast<int>(Entity::TileMode::kDecal);
272 
273  FS::BindFragInfo(pass, data_host_buffer.EmplaceUniform(frag_info));
274  VUS::BindFrameInfo(pass, data_host_buffer.EmplaceUniform(frame_info));
275 
276  return pass.Draw().ok();
277 }
virtual std::optional< Rect > GetStrictSrcRect() const
The source rect of the draw in texture coordinates if a strict source rect should be applied,...
virtual VertexBuffer CreateSimpleVertexBuffer(HostBuffer &host_buffer) const =0
virtual bool ShouldInvertBlendMode() const
virtual bool ShouldUseBlend() const =0
virtual const SamplerDescriptor & GetSamplerDescriptor() const =0
virtual bool ShouldSkip() const =0
virtual VertexBuffer CreateBlendVertexBuffer(HostBuffer &host_buffer) const =0
virtual BlendMode GetBlendMode() const =0
virtual const std::shared_ptr< Texture > & GetAtlas() const =0
FragmentShader_ FragmentShader
Definition: pipeline.h:169
TRect< Scalar > Rect
Definition: rect.h:857
LinePipeline::FragmentShader FS
std::optional< BlendMode > InvertPorterDuffBlend(BlendMode blend_mode)
BlendMode
Definition: color.h:58
LinePipeline::VertexShader VS
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: