| Flutter Impeller |

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

`#include <atlas_contents.h>`

Inheritance diagram for impeller::ColorFilterAtlasContents:

## Public Member Functions
| ColorFilterAtlasContents ()
| ~ColorFilterAtlasContents () override
void | SetGeometry (AtlasGeometry *geometry)
void | SetAlpha (Scalar alpha)
void | SetMatrix (ColorMatrix matrix)
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

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

Definition at line 122 of file atlas_contents.h.

## Constructor & Destructor Documentation

## ◆ ColorFilterAtlasContents()

impeller::ColorFilterAtlasContents::ColorFilterAtlasContents | ( |  | ) |
| explicit default

## ◆ ~ColorFilterAtlasContents()

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

## Member Function Documentation

## ◆ GetCoverage()

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

292 {
293 if (!geometry_) {
294 return std::nullopt;
295 }
296 return geometry_->ComputeBoundingBox().TransformBounds(entity.GetTransform());
297 }
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::ColorFilterAtlasContents::Render | ( | const ContentContext & | renderer,
|  | const Entity & | entity,
|  | RenderPass & | pass
| ) |  | const
| override virtual

Implements impeller::Contents.

Definition at line 311 of file atlas_contents.cc.

313 {
314 if (geometry_->ShouldSkip() || alpha_ <= 0.0) {
315 return true;
316 }
317
318 const SamplerDescriptor& dst_sampler_descriptor =
319 geometry_->GetSamplerDescriptor();
320
321 raw_ptr<const Sampler> dst_sampler =
322 renderer.GetContext()->GetSamplerLibrary()->GetSampler(
323 dst_sampler_descriptor);
324
325 auto& data_host_buffer = renderer.GetTransientsDataBuffer();
326
327 using VS = ColorMatrixColorFilterPipeline::VertexShader;
328 using FS = ColorMatrixColorFilterPipeline::FragmentShader;
329
330 #ifdef IMPELLER_DEBUG
331 pass.SetCommandLabel("Atlas ColorFilter");
332 #endif // IMPELLER_DEBUG
333 pass.SetVertexBuffer(geometry_->CreateSimpleVertexBuffer(data_host_buffer));
334 pass.SetPipeline(
335 renderer.GetColorMatrixColorFilterPipeline(OptionsFromPass(pass)));
336
337 FS::FragInfo frag_info;
338 VS::FrameInfo frame_info;
339
340 FS::BindInputTexture(pass, geometry_->GetAtlas(), dst_sampler);
341 frame_info.texture_sampler_y_coord_scale =
342 geometry_->GetAtlas()->GetYCoordScale();
343
344 frag_info.input_alpha = 1;
345 frag_info.output_alpha = alpha_;
346 const float* matrix = matrix_.array;
347 frag_info.color_v = Vector4(matrix[4], matrix[9], matrix[14], matrix[19]);
348 frag_info.color_m = Matrix(matrix[0], matrix[5], matrix[10], matrix[15], //
349 matrix[1], matrix[6], matrix[11], matrix[16], //
350 matrix[2], matrix[7], matrix[12], matrix[17], //
351 matrix[3], matrix[8], matrix[13], matrix[18] //
352 );
353
354 FS::BindFragInfo(pass, data_host_buffer.EmplaceUniform(frag_info));
355
356 frame_info.mvp = entity.GetShaderTransform(pass);
357
358 auto uniform_view = data_host_buffer.EmplaceUniform(frame_info);
359 VS::BindFrameInfo(pass, uniform_view);
360
361 return pass.Draw().ok();
362 }
impeller::AtlasGeometry::CreateSimpleVertexBuffer
virtual VertexBuffer CreateSimpleVertexBuffer(HostBuffer &host_buffer) const =0
impeller::AtlasGeometry::GetSamplerDescriptor
virtual const SamplerDescriptor & GetSamplerDescriptor() const =0
impeller::AtlasGeometry::ShouldSkip
virtual bool ShouldSkip() const =0
impeller::AtlasGeometry::GetAtlas
virtual const std::shared_ptr< Texture > & GetAtlas() const =0
impeller::RenderPipelineHandle::VertexShader
VertexShader_ VertexShader
Definition: pipeline.h:168
impeller::RenderPipelineHandle::FragmentShader
FragmentShader_ FragmentShader
Definition: pipeline.h:169
impeller::FS
LinePipeline::FragmentShader FS
Definition: line_contents.cc:14
impeller::VS
LinePipeline::VertexShader VS
Definition: line_contents.cc:13
impeller::OptionsFromPass
ContentContextOptions OptionsFromPass(const RenderPass &pass)
Definition: contents.cc:19
impeller::ColorMatrix::array
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::GetTransientsDataBuffer(), 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 303 of file atlas_contents.cc.

303 {
304 alpha_ = alpha;
305 }

## ◆ SetGeometry()

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

Definition at line 299 of file atlas_contents.cc.

299 {
300 geometry_ = geometry;
301 }

## ◆ SetMatrix()

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

Definition at line 307 of file atlas_contents.cc.

307 {
308 matrix_ = matrix;
309 }

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

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