Flutter Impeller
impeller::ColorFilterAtlasContents Class Referencefinal

#include <atlas_contents.h>

Inheritance diagram for impeller::ColorFilterAtlasContents:
impeller::Contents

Public Member Functions

 ColorFilterAtlasContents ()
 
 ~ColorFilterAtlasContents () override
 
void SetGeometry (AtlasGeometry *geometry)
 
void SetAlpha (Scalar alpha)
 
void SetMatrix (ColorMatrix matrix)
 
std::optional< RectGetCoverage (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< SnapshotRenderToSnapshot (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< SizeGetColorSourceSize () 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< ColorAsBackgroundColor (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< ContentsMakeAnonymous (RenderProc render_proc, CoverageProc coverage_proc)
 

Detailed Description

A specialized atlas class for applying a color matrix filter to a drawImageRect call.

Definition at line 110 of file atlas_contents.h.

Constructor & Destructor Documentation

◆ ColorFilterAtlasContents()

impeller::ColorFilterAtlasContents::ColorFilterAtlasContents ( )
explicitdefault

◆ ~ColorFilterAtlasContents()

impeller::ColorFilterAtlasContents::~ColorFilterAtlasContents ( )
overridedefault

Member Function Documentation

◆ GetCoverage()

std::optional< Rect > impeller::ColorFilterAtlasContents::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 273 of file atlas_contents.cc.

274  {
275  if (!geometry_) {
276  return std::nullopt;
277  }
278  return geometry_->ComputeBoundingBox().TransformBounds(entity.GetTransform());
279 }
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:476

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

◆ Render()

bool impeller::ColorFilterAtlasContents::Render ( const ContentContext renderer,
const Entity entity,
RenderPass pass 
) const
overridevirtual

Implements impeller::Contents.

Definition at line 293 of file atlas_contents.cc.

295  {
296  if (geometry_->ShouldSkip() || alpha_ <= 0.0) {
297  return true;
298  }
299 
300  const SamplerDescriptor& dst_sampler_descriptor =
301  geometry_->GetSamplerDescriptor();
302 
303  raw_ptr<const Sampler> dst_sampler =
304  renderer.GetContext()->GetSamplerLibrary()->GetSampler(
305  dst_sampler_descriptor);
306 
307  auto& host_buffer = renderer.GetTransientsBuffer();
308 
311 
312 #ifdef IMPELLER_DEBUG
313  pass.SetCommandLabel("Atlas ColorFilter");
314 #endif // IMPELLER_DEBUG
315  pass.SetVertexBuffer(geometry_->CreateSimpleVertexBuffer(host_buffer));
316  pass.SetPipeline(
317  renderer.GetColorMatrixColorFilterPipeline(OptionsFromPass(pass)));
318 
319  FS::FragInfo frag_info;
320  VS::FrameInfo frame_info;
321 
322  FS::BindInputTexture(pass, geometry_->GetAtlas(), dst_sampler);
323  frame_info.texture_sampler_y_coord_scale =
324  geometry_->GetAtlas()->GetYCoordScale();
325 
326  frag_info.input_alpha = 1;
327  frag_info.output_alpha = alpha_;
328  const float* matrix = matrix_.array;
329  frag_info.color_v = Vector4(matrix[4], matrix[9], matrix[14], matrix[19]);
330  frag_info.color_m = Matrix(matrix[0], matrix[5], matrix[10], matrix[15], //
331  matrix[1], matrix[6], matrix[11], matrix[16], //
332  matrix[2], matrix[7], matrix[12], matrix[17], //
333  matrix[3], matrix[8], matrix[13], matrix[18] //
334  );
335 
336  FS::BindFragInfo(pass, host_buffer.EmplaceUniform(frag_info));
337 
338  frame_info.mvp = entity.GetShaderTransform(pass);
339 
340  auto uniform_view = host_buffer.EmplaceUniform(frame_info);
341  VS::BindFrameInfo(pass, uniform_view);
342 
343  return pass.Draw().ok();
344 }
virtual VertexBuffer CreateSimpleVertexBuffer(HostBuffer &host_buffer) const =0
virtual const SamplerDescriptor & GetSamplerDescriptor() const =0
virtual bool ShouldSkip() const =0
virtual const std::shared_ptr< Texture > & GetAtlas() const =0
FragmentShader_ FragmentShader
Definition: pipeline.h:120
LinePipeline::FragmentShader FS
LinePipeline::VertexShader VS
ContentContextOptions OptionsFromPass(const RenderPass &pass)
Definition: contents.cc:19
Scalar array[20]
Definition: color.h:118

References impeller::ColorMatrix::array, impeller::AtlasGeometry::CreateSimpleVertexBuffer(), impeller::RenderPass::Draw(), impeller::AtlasGeometry::GetAtlas(), impeller::ContentContext::GetColorMatrixColorFilterPipeline(), impeller::ContentContext::GetContext(), impeller::AtlasGeometry::GetSamplerDescriptor(), impeller::Entity::GetShaderTransform(), impeller::ContentContext::GetTransientsBuffer(), impeller::OptionsFromPass(), impeller::RenderPass::SetCommandLabel(), impeller::RenderPass::SetPipeline(), impeller::RenderPass::SetVertexBuffer(), and impeller::AtlasGeometry::ShouldSkip().

◆ SetAlpha()

void impeller::ColorFilterAtlasContents::SetAlpha ( Scalar  alpha)

Definition at line 285 of file atlas_contents.cc.

285  {
286  alpha_ = alpha;
287 }

◆ SetGeometry()

void impeller::ColorFilterAtlasContents::SetGeometry ( AtlasGeometry geometry)

Definition at line 281 of file atlas_contents.cc.

281  {
282  geometry_ = geometry;
283 }

◆ SetMatrix()

void impeller::ColorFilterAtlasContents::SetMatrix ( ColorMatrix  matrix)

Definition at line 289 of file atlas_contents.cc.

289  {
290  matrix_ = matrix;
291 }

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