| 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 30 of file clip_contents.cc.

31 : coverage_rect_(coverage_rect),
32 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 44 of file clip_contents.cc.

45 {
46 if (!current_clip_coverage.has_value()) {
47 return {.coverage = std::nullopt};
48 }
49 switch (clip_op_) {
50 case Entity::ClipOperation::kDifference:
51 // This can be optimized further by considering cases when the bounds of
52 // the current stencil will shrink.
53 return {
54 .is_difference_or_non_square = true, //
55 .coverage = current_clip_coverage //
56 };
57 case Entity::ClipOperation::kIntersect:
58 if (coverage_rect_.IsEmpty() || !current_clip_coverage.has_value()) {
59 return {.coverage = std::nullopt};
60 }
61 return {
62 .is_difference_or_non_square = !is_axis_aligned_rect_, //
63 .coverage = current_clip_coverage->Intersection(coverage_rect_), //
64 };
65 }
66 FML_UNREACHABLE();
67 }

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 69 of file clip_contents.cc.

71 {
72 if (!clip_geometry_.vertex_buffer) {
73 return true;
74 }
75
76 using VS = ClipPipeline::VertexShader;
77
78 VS::FrameInfo info;
79 info.depth = GetShaderClipDepth(clip_depth);
80
81 auto options = OptionsFromPass(pass);
82 options.blend_mode = BlendMode::kDestination;
83
84 pass.SetStencilReference(0);
85
86 /// Stencil preparation draw.
87
88 options.depth_write_enabled = false;
89 options.primitive_type = clip_geometry_.type;
90 pass.SetVertexBuffer(clip_geometry_.vertex_buffer);
91 switch (clip_geometry_.mode) {
92 case GeometryResult::Mode::kNonZero:
93 pass.SetCommandLabel("Clip stencil preparation (NonZero)");
94 options.stencil_mode =
95 ContentContextOptions::StencilMode::kStencilNonZeroFill;
96 break;
97 case GeometryResult::Mode::kEvenOdd:
98 pass.SetCommandLabel("Clip stencil preparation (EvenOdd)");
99 options.stencil_mode =
100 ContentContextOptions::StencilMode::kStencilEvenOddFill;
101 break;
102 case GeometryResult::Mode::kNormal:
103 case GeometryResult::Mode::kPreventOverdraw:
104 pass.SetCommandLabel("Clip stencil preparation (Increment)");
105 options.stencil_mode =
106 ContentContextOptions::StencilMode::kOverdrawPreventionIncrement;
107 break;
108 }
109 pass.SetPipeline(renderer.GetClipPipeline(options));
110
111 info.mvp = clip_geometry_.transform;
112 VS::BindFrameInfo(pass, renderer.GetTransientsBuffer().EmplaceUniform(info));
113
114 if (!pass.Draw().ok()) {
115 return false;
116 }
117
118 /// Write depth.
119
120 options.depth_write_enabled = true;
121 options.primitive_type = PrimitiveType::kTriangleStrip;
122 Rect cover_area;
123 switch (clip_op_) {
124 case Entity::ClipOperation::kIntersect:
125 pass.SetCommandLabel("Intersect Clip");
126 options.stencil_mode =
127 ContentContextOptions::StencilMode::kCoverCompareInverted;
128 cover_area = Rect::MakeSize(pass.GetRenderTargetSize());
129 break;
130 case Entity::ClipOperation::kDifference:
131 pass.SetCommandLabel("Difference Clip");
132 options.stencil_mode = ContentContextOptions::StencilMode::kCoverCompare;
133 cover_area = coverage_rect_;
134 break;
135 }
136 auto points = cover_area.GetPoints();
137 pass.SetVertexBuffer(
138 CreateVertexBuffer(points, renderer.GetTransientsBuffer()));
139
140 pass.SetPipeline(renderer.GetClipPipeline(options));
141
142 info.mvp = pass.GetOrthographicTransform();
143 VS::BindFrameInfo(pass, renderer.GetTransientsBuffer().EmplaceUniform(info));
144
145 return pass.Draw().ok();
146 }

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::GetTransientsBuffer(), impeller::ContentContextOptions::kCoverCompare, impeller::ContentContextOptions::kCoverCompareInverted, impeller::kDestination, impeller::Entity::kDifference, impeller::GeometryResult::kEvenOdd, impeller::Entity::kIntersect, impeller::GeometryResult::kNonZero, impeller::GeometryResult::kNormal, impeller::ContentContextOptions::kOverdrawPreventionIncrement, impeller::GeometryResult::kPreventOverdraw, impeller::ContentContextOptions::kStencilEvenOddFill, impeller::ContentContextOptions::kStencilNonZeroFill, impeller::kTriangleStrip, impeller::TRect< Scalar >::MakeSize(), impeller::GeometryResult::mode, impeller::OptionsFromPass(), 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 40 of file clip_contents.cc.

40 {
41 clip_op_ = clip_op;
42 }

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

## ◆ SetGeometry()

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

Set the pre-tessellated clip geometry.

Definition at line 36 of file clip_contents.cc.

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

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

impeller::GeometryResult::Mode::kNormal
@ kNormal
The geometry has no overlapping triangles.
impeller::Entity::ClipOperation::kIntersect
@ kIntersect
impeller::OptionsFromPass
ContentContextOptions OptionsFromPass(const RenderPass &pass)
Definition: contents.cc:19
impeller::Entity::ClipOperation::kDifference
@ kDifference
impeller::ContentContextOptions::StencilMode::kOverdrawPreventionIncrement
@ kOverdrawPreventionIncrement
impeller::GetShaderClipDepth
static Scalar GetShaderClipDepth(uint32_t clip_depth)
Definition: clip_contents.cc:19
impeller::VS
GlyphAtlasPipeline::VertexShader VS
Definition: text_contents.cc:25
impeller::BlendMode::kDestination
@ kDestination
impeller::ContentContextOptions::StencilMode::kStencilEvenOddFill
@ kStencilEvenOddFill
impeller::GeometryResult::Mode::kEvenOdd
@ kEvenOdd
impeller::TRect::GetPoints
constexpr std::array< TPoint< T >, 4 > GetPoints() const
Get the points that represent the 4 corners of this rectangle in a Z order that is compatible with tr...
Definition: rect.h:418
impeller::TRect::IsEmpty
constexpr bool IsEmpty() const
Returns true if either of the width or height are 0, negative, or NaN.
Definition: rect.h:301
impeller::PrimitiveType::kTriangleStrip
@ kTriangleStrip
impeller::GeometryResult::type
PrimitiveType type
Definition: geometry.h:37
impeller::CreateVertexBuffer
VertexBuffer CreateVertexBuffer(std::array< VertexType, size > input, HostBuffer &host_buffer)
Create an index-less vertex buffer from a fixed size array.
Definition: vertex_buffer_builder.h:24
impeller::ContentContextOptions::StencilMode::kStencilNonZeroFill
@ kStencilNonZeroFill
impeller::RenderPipelineHandle::VertexShader
VertexShader_ VertexShader
Definition: pipeline.h:113
impeller::Rect
TRect< Scalar > Rect
Definition: rect.h:792
impeller::GeometryResult::transform
Matrix transform
Definition: geometry.h:39
impeller::TRect< Scalar >::MakeSize
constexpr static TRect MakeSize(const TSize< U > &size)
Definition: rect.h:150
impeller::GeometryResult::Mode::kPreventOverdraw
@ kPreventOverdraw
impeller::ContentContextOptions::StencilMode::kCoverCompareInverted
@ kCoverCompareInverted
impeller::ContentContextOptions::StencilMode::kCoverCompare
@ kCoverCompare
impeller::GeometryResult::vertex_buffer
VertexBuffer vertex_buffer
Definition: geometry.h:38
impeller::GeometryResult::mode
Mode mode
Definition: geometry.h:40
impeller::GeometryResult::Mode::kNonZero
@ kNonZero