Flutter Engine
 
Loading...
Searching...
No Matches
impeller::Contents Class Referenceabstract

#include <contents.h>

Inheritance diagram for impeller::Contents:
impeller::AnonymousContents impeller::AtlasContents impeller::ColorFilterAtlasContents impeller::ColorSourceContents impeller::FilterContents impeller::LineContents impeller::SolidRRectLikeBlurContents impeller::TextContents impeller::TextureContents impeller::VerticesSimpleBlendContents

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< RectGetCoverage (const Entity &entity) const =0
 Get the area of the render pass that will be affected when this contents is rendered.
 
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().
 
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.
 
virtual std::optional< SnapshotRenderToSnapshot (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).
 
std::optional< SizeGetColorSourceSize () const
 Return the color source's intrinsic size, if available.
 
void SetColorSourceSize (Size size)
 
virtual void SetInheritedOpacity (Scalar opacity)
 Inherit the provided opacity.
 
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.
 
virtual bool ApplyColorFilter (const ColorFilterProc &color_filter_proc)
 If possible, applies a color filter to this contents inputs on the CPU.
 

Static Public Member Functions

static std::shared_ptr< ContentsMakeAnonymous (RenderProc render_proc, CoverageProc coverage_proc)
 

Detailed Description

Definition at line 31 of file contents.h.

Member Typedef Documentation

◆ ColorFilterProc

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 ( )
virtualdefault

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_procA 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::ConicalGradientContents, impeller::LinearGradientContents, impeller::RadialGradientContents, impeller::SolidColorContents, impeller::SolidRRectLikeBlurContents, and impeller::SweepGradientContents.

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::AnonymousContents, impeller::AtlasContents, impeller::ColorFilterAtlasContents, impeller::CircleContents, impeller::ColorSourceContents, impeller::FilterContents, impeller::LineContents, impeller::SolidColorContents, impeller::SolidRRectLikeBlurContents, impeller::TextContents, impeller::TextureContents, and impeller::VerticesSimpleBlendContents.

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
transformThe current transform matrix of the entity that will render this contents.

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

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}
static std::shared_ptr< Contents > Make(RenderProc render_proc, CoverageProc coverage_proc)

References impeller::AnonymousContents::Make().

◆ Render()

◆ 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::FilterContents, impeller::TextureContents, and impeller::TiledTextureContents.

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}
const T & value() const
Definition status_or.h:77
bool ok() const
Definition status_or.h:75
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.
ISize subpass_size
The output size of the down-sampling pass.
ISize64 ISize
Definition size.h:162
static constexpr Matrix MakeTranslation(const Vector3 &t)
Definition matrix.h:95
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, fml::StatusOr< T >::ok(), impeller::Contents::SnapshotOptions::sampler_descriptor, subpass_size, impeller::Snapshot::texture, and fml::StatusOr< T >::value().

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}
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size

◆ 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::ColorSourceContents, impeller::ColorFilterContents, impeller::TextContents, and impeller::TextureContents.

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}
#define VALIDATION_LOG
Definition validation.h:91

References VALIDATION_LOG.


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