| Flutter Impeller |

Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
impeller::Contents Class Referenceabstract

`#include <contents.h>`

Inheritance diagram for impeller::Contents:

## Classes
struct | SnapshotOptions

## Public Types
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)>

## Public Member Functions
| Contents ()
virtual | ~Contents ()
virtual bool | Render (const ContentContext &renderer, const Entity &entity, RenderPass &pass) const =0
virtual std::optional< Rect > | GetCoverage (const Entity &entity) const =0
| Get the area of the render pass that will be affected when this contents is rendered. More...
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...

## Static Public Member Functions
static std::shared_ptr< Contents > | MakeAnonymous (RenderProc render_proc, CoverageProc coverage_proc)

## Detailed Description

Definition at line 31 of file contents.h.

## Member Typedef Documentation

## ◆ ColorFilterProc

using impeller::Contents::ColorFilterProc = std::function<Color(Color)>

A procedure that filters a given unpremultiplied color to produce a new unpremultiplied color.

Definition at line 35 of file contents.h.

## ◆ CoverageProc

using impeller::Contents::CoverageProc = std::function<std::optional<Rect>(const Entity& entity)>

Definition at line 40 of file contents.h.

## ◆ RenderProc

using impeller::Contents::RenderProc = std::function<bool(const ContentContext& renderer, const Entity& entity, RenderPass& pass)>

Definition at line 37 of file contents.h.

## Constructor & Destructor Documentation

## ◆ Contents()

impeller::Contents::Contents | ( |  | ) |
| default

## ◆ ~Contents()

impeller::Contents::~Contents | ( |  | ) |
| virtual default

## Member Function Documentation

## ◆ ApplyColorFilter()

bool impeller::Contents::ApplyColorFilter | ( | const ColorFilterProc & | color_filter_proc | ) |
| virtual

If possible, applies a color filter to this contents inputs on the CPU.

This method will either fully apply the color filter or perform no action. Partial/incorrect application of the color filter will never occur.

Parameters

  [in] | color_filter_proc | A function that filters a given unpremultiplied color to produce a new unpremultiplied color.

Returns
  True if the color filter was able to be fully applied to all all relevant inputs. Otherwise, this operation is a no-op and false is returned.

Reimplemented in impeller::SweepGradientContents, impeller::SolidRRectLikeBlurContents, impeller::SolidColorContents, impeller::RadialGradientContents, impeller::LinearGradientContents, and impeller::ConicalGradientContents.

Definition at line 128 of file contents.cc.

129 {
130 return false;
131 }

## ◆ AsBackgroundColor()

std::optional< Color > impeller::Contents::AsBackgroundColor | ( | const Entity & | entity,
|  | ISize | target_size
| ) |  | const
| virtual

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.

This is useful for absorbing full screen solid color draws into subpass clear colors.

Reimplemented in impeller::SolidColorContents.

Definition at line 123 of file contents.cc.

124 {
125 return {};
126 }

## ◆ GetColorSourceSize()

std::optional< Size > impeller::Contents::GetColorSourceSize | ( |  | ) | const

Return the color source's intrinsic size, if available.

        For example, a gradient has a size based on its end and beginning
        points, ignoring any tiling. Solid colors and runtime effects have
        no size.

Definition at line 141 of file contents.cc.

141 {
142 return color_source_size_;
143 };

## ◆ GetCoverage()

virtual std::optional<Rect> impeller::Contents::GetCoverage | ( | const Entity & | entity | ) | const
| pure 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.

Implemented in impeller::VerticesSimpleBlendContents, impeller::TextureContents, impeller::TextContents, impeller::SolidRRectLikeBlurContents, impeller::SolidColorContents, impeller::LineContents, impeller::FilterContents, impeller::ColorSourceContents, impeller::CircleContents, impeller::ColorFilterAtlasContents, impeller::AtlasContents, and impeller::AnonymousContents.

Referenced by impeller::ColorSourceContents::DrawGeometry(), and RenderToSnapshot().

## ◆ GetCoverageHint()

const std::optional< Rect > & impeller::Contents::GetCoverageHint | ( |  | ) | const

Definition at line 137 of file contents.cc.

137 {
138 return coverage_hint_;
139 }

Referenced by impeller::FilterContents::Render().

## ◆ IsOpaque()

bool impeller::Contents::IsOpaque | ( | const Matrix & | transform | ) | const
| virtual

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.

Parameters

  transform | The current transform matrix of the entity that will render this contents.

Reimplemented in impeller::TiledTextureContents, impeller::SweepGradientContents, impeller::SolidColorContents, impeller::RadialGradientContents, and impeller::LinearGradientContents.

Definition at line 52 of file contents.cc.

52 {
53 return false;
54 }

Referenced by impeller::testing::TEST_P().

## ◆ MakeAnonymous()

std::shared_ptr< Contents > impeller::Contents::MakeAnonymous | ( | Contents::RenderProc | render_proc,
|  | Contents::CoverageProc | coverage_proc
| ) |  |
| static

Definition at line 41 of file contents.cc.

43 {
44 return AnonymousContents::Make(std::move(render_proc),
45 std::move(coverage_proc));
46 }
impeller::AnonymousContents::Make
static std::shared_ptr< Contents > Make(RenderProc render_proc, CoverageProc coverage_proc)
Definition: anonymous_contents.cc:11

References impeller::AnonymousContents::Make().

## ◆ Render()

virtual bool impeller::Contents::Render | ( | const ContentContext & | renderer,
|  | const Entity & | entity,
|  | RenderPass & | pass
| ) |  | const
| pure virtual

Implemented in impeller::VerticesSimpleBlendContents, impeller::TiledTextureContents, impeller::TextureContents, impeller::TextContents, impeller::SweepGradientContents, impeller::SolidRRectLikeBlurContents, impeller::SolidColorContents, impeller::RuntimeEffectContents, impeller::RadialGradientContents, impeller::LinearGradientContents, impeller::LineContents, impeller::FilterContents, impeller::ConicalGradientContents, impeller::CircleContents, impeller::ColorFilterAtlasContents, impeller::AtlasContents, and impeller::AnonymousContents.

## ◆ RenderToSnapshot()

std::optional< Snapshot > impeller::Contents::RenderToSnapshot | ( | const ContentContext & | renderer,
|  | const Entity & | entity,
|  | const SnapshotOptions & | options
| ) |  | const
| virtual

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)`.

Reimplemented in impeller::TiledTextureContents, impeller::TextureContents, and impeller::FilterContents.

Definition at line 56 of file contents.cc.

59 {
60 auto coverage = GetCoverage(entity);
61 if (!coverage.has_value()) {
62 return std::nullopt;
63 }
64
65 std::shared_ptr<CommandBuffer> command_buffer =
66 renderer.GetContext()->CreateCommandBuffer();
67 if (!command_buffer) {
68 return std::nullopt;
69 }
70
71 // Pad Contents snapshots with 1 pixel borders to ensure correct sampling
72 // behavior. Not doing so results in a coverage leak for filters that support
73 // customizing the input sampling mode. Snapshots of contents should be
74 // theoretically treated as infinite size just like layers.
75 coverage = coverage->Expand(options.coverage_expansion);
76
77 if (options.coverage_limit.has_value()) {
78 coverage = coverage->Intersection(*options.coverage_limit);
79 if (!coverage.has_value()) {
80 return std::nullopt;
81 }
82 }
83
84 ISize subpass_size = ISize::Ceil(coverage->GetSize());
85 fml::StatusOr<RenderTarget> render_target = renderer.MakeSubpass(
86 options.label, subpass_size, command_buffer,
87 [&contents = *this, &entity, &coverage](const ContentContext& renderer,
88 RenderPass& pass) -> bool {
89 Entity sub_entity;
90 sub_entity.SetBlendMode(BlendMode::kSrcOver);
91 sub_entity.SetTransform(
92 Matrix::MakeTranslation(Vector3(-coverage->GetOrigin())) *
93 entity.GetTransform());
94 return contents.Render(renderer, sub_entity, pass);
95 },
96 options.msaa_enabled, /*depth_stencil_enabled=*/true,
97 std::min(options.mip_count,
98 static_cast<int32_t>(subpass_size.MipCount())));
99
100 if (!render_target.ok()) {
101 return std::nullopt;
102 }
103 if (!renderer.GetContext()->EnqueueCommandBuffer(std::move(command_buffer))) {
104 return std::nullopt;
105 }
106
107 auto snapshot = Snapshot{
108 .texture = render_target.value().GetRenderTargetTexture(),
109 .transform = Matrix::MakeTranslation(coverage->GetOrigin()),
110 };
111 if (options.sampler_descriptor.has_value()) {
112 snapshot.sampler_descriptor = options.sampler_descriptor.value();
113 }
114
115 return snapshot;
116 }
impeller::Contents::GetCoverage
virtual std::optional< Rect > GetCoverage(const Entity &entity) const =0
Get the area of the render pass that will be affected when this contents is rendered.
subpass_size
ISize subpass_size
The output size of the down-sampling pass.
Definition: gaussian_blur_filter_contents.cc:202
impeller::ISize
ISize64 ISize
Definition: size.h:162
impeller::Matrix::MakeTranslation
static constexpr Matrix MakeTranslation(const Vector3 &t)
Definition: matrix.h:95
impeller::TSize::Ceil
constexpr TSize Ceil() const
Definition: size.h:114

References impeller::TSize< T >::Ceil(), impeller::Contents::SnapshotOptions::coverage_expansion, impeller::Contents::SnapshotOptions::coverage_limit, impeller::ContentContext::GetContext(), GetCoverage(), impeller::Contents::SnapshotOptions::label, impeller::ContentContext::MakeSubpass(), impeller::Matrix::MakeTranslation(), impeller::Contents::SnapshotOptions::mip_count, impeller::Contents::SnapshotOptions::msaa_enabled, impeller::Contents::SnapshotOptions::sampler_descriptor, subpass_size, and impeller::Snapshot::texture.

Referenced by impeller::TextureContents::RenderToSnapshot(), and impeller::TiledTextureContents::RenderToSnapshot().

## ◆ SetColorSourceSize()

void impeller::Contents::SetColorSourceSize | ( | Size | size | ) |

Definition at line 145 of file contents.cc.

145 {
146 color_source_size_ = size;
147 }

## ◆ SetCoverageHint()

void impeller::Contents::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()`.

Definition at line 133 of file contents.cc.

133 {
134 coverage_hint_ = coverage_hint;
135 }

## ◆ SetInheritedOpacity()

void impeller::Contents::SetInheritedOpacity | ( | Scalar | opacity | ) |
| virtual

Inherit the provided opacity.

       Use of this method is invalid if CanAcceptOpacity returns false.

Reimplemented in impeller::TextureContents, impeller::TextContents, impeller::ColorFilterContents, and impeller::ColorSourceContents.

Definition at line 118 of file contents.cc.

118 {
119 VALIDATION_LOG << "Contents::SetInheritedOpacity should never be called when "
120 "Contents::CanAcceptOpacity returns false.";
121 }
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:91

References VALIDATION_LOG.

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

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