| Flutter Impeller |

Public Member Functions | List of all members
impeller::ClipContents Class Reference

`#include <clip_contents.h>`

## Public Member Functions
| ClipContents (Rect coverage_rect, bool is_axis_aligned_rect)
| ~ClipContents ()
void | SetGeometry (GeometryResult geometry)
| Set the pre-tessellated clip geometry. More...
void | SetClipOperation (Entity::ClipOperation clip_op)
ClipCoverage | GetClipCoverage (const std::optional< Rect > &current_clip_coverage) const
| 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. More...
bool | Render (const ContentContext &renderer, RenderPass &pass, uint32_t clip_depth) const

## Detailed Description

Definition at line 29 of file clip_contents.h.

## Constructor & Destructor Documentation

## ◆ ClipContents()

impeller::ClipContents::ClipContents | ( | Rect | coverage_rect,
|  | bool | is_axis_aligned_rect
| ) |  |

Definition at line 31 of file clip_contents.cc.

32 : coverage_rect_(coverage_rect),
33 is_axis_aligned_rect_(is_axis_aligned_rect) {}

## ◆ ~ClipContents()

impeller::ClipContents::~ClipContents | ( |  | ) |
| default

## Member Function Documentation

## ◆ GetClipCoverage()

ClipCoverage impeller::ClipContents::GetClipCoverage | ( | const std::optional< Rect > & | current_clip_coverage | ) | const

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.

Definition at line 45 of file clip_contents.cc.

46 {
47 if (!current_clip_coverage.has_value()) {
48 return ClipCoverage{.coverage = std::nullopt};
49 }
50 switch (clip_op_) {
51 case Entity::ClipOperation::kDifference:
52 // This can be optimized further by considering cases when the bounds of
53 // the current stencil will shrink.
54 return {
55 .is_difference_or_non_square = true, //
56 .coverage = current_clip_coverage //
57 };
58 case Entity::ClipOperation::kIntersect:
59 if (coverage_rect_.IsEmpty() || !current_clip_coverage.has_value()) {
60 return ClipCoverage{.coverage = std::nullopt};
61 }
62 return {
63 .is_difference_or_non_square = !is_axis_aligned_rect_, //
64 .coverage = current_clip_coverage->Intersection(coverage_rect_), //
65 };
66 }
67 FML_UNREACHABLE();
68 }
impeller::Entity::ClipOperation::kIntersect
@ kIntersect
impeller::Entity::ClipOperation::kDifference
@ kDifference
impeller::TRect::IsEmpty
constexpr bool IsEmpty() const
Returns true if either of the width or height are 0, negative, or NaN.
Definition: rect.h:297

References impeller::ClipCoverage::coverage, impeller::TRect< T >::IsEmpty(), impeller::Entity::kDifference, and impeller::Entity::kIntersect.

Referenced by impeller::EntityPassClipStack::RecordClip().

## ◆ Render()

bool impeller::ClipContents::Render | ( | const ContentContext & | renderer,
|  | RenderPass & | pass,
|  | uint32_t | clip_depth
| ) |  | const

Stencil preparation draw.

Write depth.

Definition at line 70 of file clip_contents.cc.

72 {
73 if (!clip_geometry_.vertex_buffer) {
74 return true;
75 }
76
77 using VS = ClipPipeline::VertexShader;
78
79 VS::FrameInfo info;
80 info.depth = GetShaderClipDepth(clip_depth);
81 info.mvp = clip_geometry_.transform;
82
83 auto options = OptionsFromPass(pass);
84 options.blend_mode = BlendMode::kDst;
85 options.primitive_type = clip_geometry_.type;
86
87 pass.SetVertexBuffer(clip_geometry_.vertex_buffer);
88
89 // kNormal and kPreventOverdraw geometries can do a difference clip by writing
90 // depth directly without stencil-and-cover.
91 if ((clip_geometry_.mode == GeometryResult::Mode::kNormal ||
92 clip_geometry_.mode == GeometryResult::Mode::kPreventOverdraw) &&
93 clip_op_ == Entity::ClipOperation::kDifference) {
94 options.depth_write_enabled = true;
95 pass.SetPipeline(renderer.GetClipPipeline(options));
96
97 VS::BindFrameInfo(pass,
98 renderer.GetTransientsDataBuffer().EmplaceUniform(info));
99
100 return pass.Draw().ok();
101 }
102
103 /// Stencil preparation draw.
104
105 pass.SetStencilReference(0);
106
107 options.depth_write_enabled = false;
108 switch (clip_geometry_.mode) {
109 case GeometryResult::Mode::kNonZero:
110 pass.SetCommandLabel("Clip stencil preparation (NonZero)");
111 options.stencil_mode =
112 ContentContextOptions::StencilMode::kStencilNonZeroFill;
113 break;
114 case GeometryResult::Mode::kEvenOdd:
115 pass.SetCommandLabel("Clip stencil preparation (EvenOdd)");
116 options.stencil_mode =
117 ContentContextOptions::StencilMode::kStencilEvenOddFill;
118 break;
119 case GeometryResult::Mode::kNormal:
120 case GeometryResult::Mode::kPreventOverdraw:
121 pass.SetCommandLabel("Clip stencil preparation (Increment)");
122 options.stencil_mode =
123 ContentContextOptions::StencilMode::kStencilIncrementAll;
124 break;
125 }
126 pass.SetPipeline(renderer.GetClipPipeline(options));
127
128 VS::BindFrameInfo(pass,
129 renderer.GetTransientsDataBuffer().EmplaceUniform(info));
130
131 if (!pass.Draw().ok()) {
132 return false;
133 }
134
135 /// Write depth.
136
137 options.depth_write_enabled = true;
138 options.primitive_type = PrimitiveType::kTriangleStrip;
139 Rect cover_area;
140 switch (clip_op_) {
141 case Entity::ClipOperation::kIntersect:
142 pass.SetCommandLabel("Intersect Clip");
143 options.stencil_mode =
144 ContentContextOptions::StencilMode::kCoverCompareInverted;
145 cover_area = Rect::MakeSize(pass.GetRenderTargetSize());
146 break;
147 case Entity::ClipOperation::kDifference:
148 pass.SetCommandLabel("Difference Clip");
149 options.stencil_mode = ContentContextOptions::StencilMode::kCoverCompare;
150 cover_area = coverage_rect_;
151 break;
152 }
153 auto points = cover_area.GetPoints();
154 pass.SetVertexBuffer(
155 CreateVertexBuffer(points, renderer.GetTransientsDataBuffer()));
156
157 pass.SetPipeline(renderer.GetClipPipeline(options));
158
159 info.mvp = pass.GetOrthographicTransform();
160 VS::BindFrameInfo(pass,
161 renderer.GetTransientsDataBuffer().EmplaceUniform(info));
162
163 return pass.Draw().ok();
164 }
impeller::RenderPipelineHandle::VertexShader
VertexShader_ VertexShader
Definition: pipeline.h:163
impeller::PrimitiveType::kTriangleStrip
@ kTriangleStrip
impeller::GetShaderClipDepth
static Scalar GetShaderClipDepth(uint32_t clip_depth)
Definition: clip_contents.cc:20
impeller::Rect
TRect< Scalar > Rect
Definition: rect.h:788
impeller::CreateVertexBuffer
VertexBuffer CreateVertexBuffer(std::array< VertexType, size > input, HostBuffer &data_host_buffer)
Create an index-less vertex buffer from a fixed size array.
Definition: vertex_buffer_builder.h:24
impeller::BlendMode::kDst
@ kDst
impeller::VS
LinePipeline::VertexShader VS
Definition: line_contents.cc:13
impeller::OptionsFromPass
ContentContextOptions OptionsFromPass(const RenderPass &pass)
Definition: contents.cc:19
impeller::ContentContextOptions::StencilMode::kStencilEvenOddFill
@ kStencilEvenOddFill
impeller::ContentContextOptions::StencilMode::kStencilIncrementAll
@ kStencilIncrementAll
impeller::ContentContextOptions::StencilMode::kCoverCompareInverted
@ kCoverCompareInverted
impeller::ContentContextOptions::StencilMode::kStencilNonZeroFill
@ kStencilNonZeroFill
impeller::ContentContextOptions::StencilMode::kCoverCompare
@ kCoverCompare
impeller::GeometryResult::type
PrimitiveType type
Definition: geometry.h:37
impeller::GeometryResult::Mode::kNormal
@ kNormal
The geometry has no overlapping triangles.
impeller::GeometryResult::Mode::kEvenOdd
@ kEvenOdd
impeller::GeometryResult::Mode::kPreventOverdraw
@ kPreventOverdraw
impeller::GeometryResult::Mode::kNonZero
@ kNonZero
impeller::GeometryResult::transform
Matrix transform
Definition: geometry.h:39
impeller::GeometryResult::vertex_buffer
VertexBuffer vertex_buffer
Definition: geometry.h:38
impeller::GeometryResult::mode
Mode mode
Definition: geometry.h:40
impeller::TRect< Scalar >::MakeSize
constexpr static TRect MakeSize(const TSize< U > &size)
Definition: rect.h:150
points
std::vector< Point > points
Definition: tessellator_libtess.cc:76

References impeller::CreateVertexBuffer(), impeller::RenderPass::Draw(), impeller::HostBuffer::EmplaceUniform(), impeller::ContentContext::GetClipPipeline(), impeller::RenderPass::GetOrthographicTransform(), impeller::TRect< T >::GetPoints(), impeller::RenderPass::GetRenderTargetSize(), impeller::GetShaderClipDepth(), impeller::ContentContext::GetTransientsDataBuffer(), impeller::ContentContextOptions::kCoverCompare, impeller::ContentContextOptions::kCoverCompareInverted, impeller::Entity::kDifference, impeller::kDst, impeller::GeometryResult::kEvenOdd, impeller::Entity::kIntersect, impeller::GeometryResult::kNonZero, impeller::GeometryResult::kNormal, impeller::GeometryResult::kPreventOverdraw, impeller::ContentContextOptions::kStencilEvenOddFill, impeller::ContentContextOptions::kStencilIncrementAll, impeller::ContentContextOptions::kStencilNonZeroFill, impeller::kTriangleStrip, impeller::TRect< Scalar >::MakeSize(), impeller::GeometryResult::mode, impeller::OptionsFromPass(), points, impeller::RenderPass::SetCommandLabel(), impeller::RenderPass::SetPipeline(), impeller::RenderPass::SetStencilReference(), impeller::RenderPass::SetVertexBuffer(), impeller::GeometryResult::transform, impeller::GeometryResult::type, and impeller::GeometryResult::vertex_buffer.

Referenced by impeller::Canvas::ClipGeometry().

## ◆ SetClipOperation()

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

Definition at line 41 of file clip_contents.cc.

41 {
42 clip_op_ = clip_op;
43 }

Referenced by impeller::Canvas::ClipGeometry().

## ◆ SetGeometry()

void impeller::ClipContents::SetGeometry | ( | GeometryResult | geometry | ) |

Set the pre-tessellated clip geometry.

Definition at line 37 of file clip_contents.cc.

37 {
38 clip_geometry_ = std::move(clip_geometry);
39 }

Referenced by impeller::Canvas::ClipGeometry().

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

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