Flutter Impeller
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_) {
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  };
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 }
constexpr bool IsEmpty() const
Returns true if either of the width or height are 0, negative, or NaN.
Definition: rect.h:301

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 
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) {
93  pass.SetCommandLabel("Clip stencil preparation (NonZero)");
94  options.stencil_mode =
96  break;
98  pass.SetCommandLabel("Clip stencil preparation (EvenOdd)");
99  options.stencil_mode =
101  break;
104  pass.SetCommandLabel("Clip stencil preparation (Increment)");
105  options.stencil_mode =
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_) {
125  pass.SetCommandLabel("Intersect Clip");
126  options.stencil_mode =
128  cover_area = Rect::MakeSize(pass.GetRenderTargetSize());
129  break;
131  pass.SetCommandLabel("Difference Clip");
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 }
static Scalar GetShaderClipDepth(uint32_t clip_depth)
TRect< Scalar > Rect
Definition: rect.h:792
GlyphAtlasPipeline::VertexShader VS
VertexBuffer CreateVertexBuffer(std::array< VertexType, size > input, HostBuffer &host_buffer)
Create an index-less vertex buffer from a fixed size array.
ContentContextOptions OptionsFromPass(const RenderPass &pass)
Definition: contents.cc:19
PrimitiveType type
Definition: geometry.h:37
@ kNormal
The geometry has no overlapping triangles.
VertexBuffer vertex_buffer
Definition: geometry.h:38
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
constexpr static TRect MakeSize(const TSize< U > &size)
Definition: rect.h:150

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: