| 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, 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

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 | ( |  | ) |
| 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 288 of file atlas_contents.cc.

289 {
290 if (!geometry_) {
291 return std::nullopt;
292 }
293 return geometry_->ComputeBoundingBox().TransformBounds(entity.GetTransform());
294 }
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: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 308 of file atlas_contents.cc.

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

300 {
301 alpha_ = alpha;
302 }

## ◆ SetGeometry()

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

Definition at line 296 of file atlas_contents.cc.

296 {
297 geometry_ = geometry;
298 }

## ◆ SetMatrix()

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

Definition at line 304 of file atlas_contents.cc.

304 {
305 matrix_ = matrix;
306 }

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

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