Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | List of all members
impeller::ClipContents Class Referencefinal

#include <clip_contents.h>

Inheritance diagram for impeller::ClipContents:
impeller::Contents

Public Member Functions

 ClipContents ()
 
 ~ClipContents ()
 
void SetGeometry (const std::shared_ptr< Geometry > &geometry)
 
void SetClipOperation (Entity::ClipOperation clip_op)
 
std::optional< RectGetCoverage (const Entity &entity) const override
 Get the area of the render pass that will be affected when this contents is rendered.
 
ClipCoverage GetClipCoverage (const Entity &entity, const std::optional< Rect > &current_clip_coverage) const override
 Given the current pass space bounding rectangle of the clip buffer, return the expected clip coverage after this draw call. This should only be implemented for contents that may write to the clip buffer.
 
bool ShouldRender (const Entity &entity, const std::optional< Rect > clip_coverage) const override
 
bool Render (const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
 
bool CanInheritOpacity (const Entity &entity) const override
 Whether or not this contents can accept the opacity peephole optimization.
 
void SetInheritedOpacity (Scalar opacity) override
 Inherit the provided opacity.
 
- Public Member Functions inherited from impeller::Contents
 Contents ()
 
virtual ~Contents ()
 
virtual void PopulateGlyphAtlas (const std::shared_ptr< LazyGlyphAtlas > &lazy_glyph_atlas, Scalar scale)
 Add any text data to the specified lazy atlas. The scale parameter must be used again later when drawing the text.
 
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
 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, std::optional< Rect > coverage_limit=std::nullopt, const std::optional< SamplerDescriptor > &sampler_descriptor=std::nullopt, bool msaa_enabled=true, int32_t mip_count=1, const std::string &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).
 
std::optional< SizeGetColorSourceSize () const
 Return the color source's intrinsic size, if available.
 
void SetColorSourceSize (Size size)
 
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 const FilterContentsAsFilter () const
 Cast to a filter. Returns nullptr if this Contents is not a filter.
 
virtual bool ApplyColorFilter (const ColorFilterProc &color_filter_proc)
 If possible, applies a color filter to this contents inputs on the CPU.
 

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

Definition at line 18 of file clip_contents.h.

Constructor & Destructor Documentation

◆ ClipContents()

impeller::ClipContents::ClipContents ( )
default

◆ ~ClipContents()

impeller::ClipContents::~ClipContents ( )
default

Member Function Documentation

◆ CanInheritOpacity()

bool impeller::ClipContents::CanInheritOpacity ( const Entity entity) const
overridevirtual

Whether or not this contents can accept the opacity peephole optimization.

By default all contents return false. Contents are responsible for determining whether or not their own geometries intersect in a way that makes accepting opacity impossible. It is always safe to return false, especially if computing overlap would be computationally expensive.

Reimplemented from impeller::Contents.

Definition at line 79 of file clip_contents.cc.

79 {
80 return true;
81}

◆ GetClipCoverage()

Contents::ClipCoverage impeller::ClipContents::GetClipCoverage ( const Entity entity,
const std::optional< Rect > &  current_clip_coverage 
) const
overridevirtual

Given the current pass space bounding rectangle of the clip buffer, return the expected clip coverage after this draw call. This should only be implemented for contents that may write to the clip buffer.

During rendering, coverage coordinates count pixels from the top left corner of the framebuffer.

Reimplemented from impeller::Contents.

Definition at line 46 of file clip_contents.cc.

48 {
49 if (!current_clip_coverage.has_value()) {
50 return {.type = ClipCoverage::Type::kAppend, .coverage = std::nullopt};
51 }
52 switch (clip_op_) {
54 // This can be optimized further by considering cases when the bounds of
55 // the current stencil will shrink.
56 return {.type = ClipCoverage::Type::kAppend,
57 .coverage = current_clip_coverage};
59 if (!geometry_) {
60 return {.type = ClipCoverage::Type::kAppend, .coverage = std::nullopt};
61 }
62 auto coverage = geometry_->GetCoverage(entity.GetTransform());
63 if (!coverage.has_value() || !current_clip_coverage.has_value()) {
64 return {.type = ClipCoverage::Type::kAppend, .coverage = std::nullopt};
65 }
66 return {
67 .type = ClipCoverage::Type::kAppend,
68 .coverage = current_clip_coverage->Intersection(coverage.value()),
69 };
70 }
72}
#define FML_UNREACHABLE()
Definition logging.h:109

◆ GetCoverage()

std::optional< Rect > impeller::ClipContents::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 42 of file clip_contents.cc.

42 {
43 return std::nullopt;
44};

◆ Render()

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

Stencil preparation draw.

Write depth.

Implements impeller::Contents.

Definition at line 85 of file clip_contents.cc.

87 {
88 if (!geometry_) {
89 return true;
90 }
91
93
94 if (clip_op_ == Entity::ClipOperation::kIntersect &&
95 geometry_->IsAxisAlignedRect() &&
96 entity.GetTransform().IsTranslationScaleOnly()) {
97 std::optional<Rect> coverage =
98 geometry_->GetCoverage(entity.GetTransform());
99 if (coverage.has_value() &&
100 coverage->Contains(Rect::MakeSize(pass.GetRenderTargetSize()))) {
101 // Skip axis-aligned intersect clips that cover the whole render target
102 // since they won't draw anything to the depth buffer.
103 return true;
104 }
105 }
106
107 VS::FrameInfo info;
108 info.depth = GetShaderClipDepth(entity);
109
110 auto geometry_result = geometry_->GetPositionBuffer(renderer, entity, pass);
111 auto options = OptionsFromPass(pass);
112 options.blend_mode = BlendMode::kDestination;
113
114 pass.SetStencilReference(0);
115
116 /// Stencil preparation draw.
117
118 options.depth_write_enabled = false;
119 options.primitive_type = geometry_result.type;
120 pass.SetVertexBuffer(std::move(geometry_result.vertex_buffer));
121 switch (geometry_result.mode) {
123 pass.SetCommandLabel("Clip stencil preparation (NonZero)");
124 options.stencil_mode =
126 break;
128 pass.SetCommandLabel("Clip stencil preparation (EvenOdd)");
129 options.stencil_mode =
131 break;
134 pass.SetCommandLabel("Clip stencil preparation (Increment)");
135 options.stencil_mode =
137 break;
138 }
139 pass.SetPipeline(renderer.GetClipPipeline(options));
140
141 info.mvp = geometry_result.transform;
142 VS::BindFrameInfo(pass, renderer.GetTransientsBuffer().EmplaceUniform(info));
143
144 if (!pass.Draw().ok()) {
145 return false;
146 }
147
148 /// Write depth.
149
150 options.depth_write_enabled = true;
151 options.primitive_type = PrimitiveType::kTriangleStrip;
152 Rect cover_area;
153 switch (clip_op_) {
155 pass.SetCommandLabel("Intersect Clip");
156 options.stencil_mode =
158 cover_area = Rect::MakeSize(pass.GetRenderTargetSize());
159 break;
161 pass.SetCommandLabel("Difference Clip");
163 std::optional<Rect> maybe_cover_area =
164 geometry_->GetCoverage(entity.GetTransform());
165 if (!maybe_cover_area.has_value()) {
166 return true;
167 }
168 cover_area = maybe_cover_area.value();
169 break;
170 }
171 auto points = cover_area.GetPoints();
172 auto vertices =
173 VertexBufferBuilder<VS::PerVertexData>{}
174 .AddVertices({{points[0]}, {points[1]}, {points[2]}, {points[3]}})
175 .CreateVertexBuffer(renderer.GetTransientsBuffer());
176 pass.SetVertexBuffer(std::move(vertices));
177
178 pass.SetPipeline(renderer.GetClipPipeline(options));
179
180 info.mvp = pass.GetOrthographicTransform();
181 VS::BindFrameInfo(pass, renderer.GetTransientsBuffer().EmplaceUniform(info));
182
183 return pass.Draw().ok();
184}
const char * options
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
static const int points[]
static Scalar GetShaderClipDepth(const Entity &entity)
TRect< Scalar > Rect
Definition rect.h:746
SolidFillVertexShader VS
ContentContextOptions OptionsFromPass(const RenderPass &pass)
Definition contents.cc:20
@ kNormal
The geometry has no overlapping triangles.
static constexpr TRect MakeSize(const TSize< U > &size)
Definition rect.h:146

◆ SetClipOperation()

void impeller::ClipContents::SetClipOperation ( Entity::ClipOperation  clip_op)

Definition at line 38 of file clip_contents.cc.

38 {
39 clip_op_ = clip_op;
40}

◆ SetGeometry()

void impeller::ClipContents::SetGeometry ( const std::shared_ptr< Geometry > &  geometry)

Definition at line 34 of file clip_contents.cc.

34 {
35 geometry_ = geometry;
36}

◆ SetInheritedOpacity()

void impeller::ClipContents::SetInheritedOpacity ( Scalar  opacity)
overridevirtual

Inherit the provided opacity.

   Use of this method is invalid if CanAcceptOpacity returns false.

Reimplemented from impeller::Contents.

Definition at line 83 of file clip_contents.cc.

83{}

◆ ShouldRender()

bool impeller::ClipContents::ShouldRender ( const Entity entity,
const std::optional< Rect clip_coverage 
) const
overridevirtual

Reimplemented from impeller::Contents.

Definition at line 74 of file clip_contents.cc.

75 {
76 return true;
77}

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