Flutter Impeller
impeller::LineGeometry Class Referencefinal

#include <line_geometry.h>

Inheritance diagram for impeller::LineGeometry:
impeller::Geometry

Public Member Functions

 LineGeometry (Point p0, Point p1, const StrokeParameters &stroke)
 
 ~LineGeometry () override
 
bool CoversArea (const Matrix &transform, const IRect &rect) const override
 Determines if this geometry, transformed by the given transform, will completely cover all of the pixels within the given integer rect. More...
 
bool IsAxisAlignedRect () const override
 
Scalar ComputeAlphaCoverage (const Matrix &transform) const override
 
std::optional< Rect > GetCoverage (const Matrix &transform) const override
 The coverage rectangle of this geometry, transformed by the transform argument. More...
 
Point GetP0 () const
 
Point GetP1 () const
 
Scalar GetWidth () const
 
Cap GetCap () const
 
- Public Member Functions inherited from impeller::Geometry
virtual ~Geometry ()
 
virtual GeometryResult::Mode GetResultMode () const
 
virtual bool CanApplyMaskFilter () const
 

Static Public Member Functions

static Scalar ComputePixelHalfWidth (const Matrix &transform, Scalar width)
 
static Vector2 ComputeAlongVector (const Matrix &transform, bool allow_zero_length, Point p0, Point p1, Scalar width)
 
static bool ComputeCorners (Point corners[4], const Matrix &transform, bool extend_endpoints, Point p0, Point p1, Scalar width)
 
- Static Public Member Functions inherited from impeller::Geometry
static std::unique_ptr< Geometry > MakeFillPath (const flutter::DlPath &path, std::optional< Rect > inner_rect=std::nullopt)
 
static std::unique_ptr< Geometry > MakeStrokePath (const flutter::DlPath &path, const StrokeParameters &stroke={})
 
static std::unique_ptr< Geometry > MakeCover ()
 
static std::unique_ptr< Geometry > MakeRect (const Rect &rect)
 
static std::unique_ptr< Geometry > MakeOval (const Rect &rect)
 
static std::unique_ptr< Geometry > MakeLine (const Point &p0, const Point &p1, const StrokeParameters &stroke)
 
static std::unique_ptr< Geometry > MakeCircle (const Point &center, Scalar radius)
 
static std::unique_ptr< Geometry > MakeStrokedCircle (const Point &center, Scalar radius, Scalar stroke_width)
 
static std::unique_ptr< Geometry > MakeFilledArc (const Rect &oval_bounds, Degrees start, Degrees sweep, bool include_center)
 
static std::unique_ptr< Geometry > MakeStrokedArc (const Rect &oval_bounds, Degrees start, Degrees sweep, const StrokeParameters &stroke)
 
static std::unique_ptr< Geometry > MakeRoundRect (const Rect &rect, const Size &radii)
 
static std::unique_ptr< Geometry > MakeRoundSuperellipse (const Rect &rect, Scalar corner_radius)
 
static Scalar ComputeStrokeAlphaCoverage (const Matrix &entity, Scalar stroke_width)
 Compute an alpha value to simulate lower coverage of fractional pixel strokes. More...
 
static GeometryResult ComputePositionGeometry (const ContentContext &renderer, const Tessellator::VertexGenerator &generator, const Entity &entity, RenderPass &pass)
 

Detailed Description

Definition at line 12 of file line_geometry.h.

Constructor & Destructor Documentation

◆ LineGeometry()

impeller::LineGeometry::LineGeometry ( Point  p0,
Point  p1,
const StrokeParameters &  stroke 
)
explicit

Definition at line 11 of file line_geometry.cc.

12  : p0_(p0), p1_(p1), width_(stroke.width), cap_(stroke.cap) {
13  FML_DCHECK(width_ >= 0);
14 }

◆ ~LineGeometry()

impeller::LineGeometry::~LineGeometry ( )
overridedefault

Member Function Documentation

◆ ComputeAlongVector()

Vector2 impeller::LineGeometry::ComputeAlongVector ( const Matrix &  transform,
bool  allow_zero_length,
Point  p0,
Point  p1,
Scalar  width 
)
static

Definition at line 29 of file line_geometry.cc.

33  {
34  Scalar stroke_half_width = ComputePixelHalfWidth(transform, width);
35  if (stroke_half_width < kEhCloseEnough) {
36  return {};
37  }
38 
39  auto along = p1 - p0;
40  Scalar length = along.GetLength();
41  if (length < kEhCloseEnough) {
42  if (!allow_zero_length) {
43  // We won't enclose any pixels unless the endpoints are extended
44  return {};
45  }
46  return {stroke_half_width, 0};
47  } else {
48  return along * stroke_half_width / length;
49  }
50 }
static Scalar ComputePixelHalfWidth(const Matrix &transform, Scalar width)
float Scalar
Definition: scalar.h:19
constexpr float kEhCloseEnough
Definition: constants.h:57

References ComputePixelHalfWidth(), impeller::TPoint< T >::GetLength(), impeller::kEhCloseEnough, p1, and transform.

Referenced by ComputeCorners().

◆ ComputeAlphaCoverage()

Scalar impeller::LineGeometry::ComputeAlphaCoverage ( const Matrix &  transform) const
overridevirtual

Reimplemented from impeller::Geometry.

Definition at line 77 of file line_geometry.cc.

77  {
78  return Geometry::ComputeStrokeAlphaCoverage(entity, width_);
79 }
static Scalar ComputeStrokeAlphaCoverage(const Matrix &entity, Scalar stroke_width)
Compute an alpha value to simulate lower coverage of fractional pixel strokes.
Definition: geometry.cc:149

References impeller::Geometry::ComputeStrokeAlphaCoverage().

◆ ComputeCorners()

bool impeller::LineGeometry::ComputeCorners ( Point  corners[4],
const Matrix &  transform,
bool  extend_endpoints,
Point  p0,
Point  p1,
Scalar  width 
)
static

Definition at line 52 of file line_geometry.cc.

57  {
58  auto along = ComputeAlongVector(transform, extend_endpoints, p0, p1, width);
59  if (along.IsZero()) {
60  return false;
61  }
62 
63  auto across = Vector2(along.y, -along.x);
64  corners[0] = p0 - across;
65  corners[1] = p1 - across;
66  corners[2] = p0 + across;
67  corners[3] = p1 + across;
68  if (extend_endpoints) {
69  corners[0] -= along;
70  corners[1] += along;
71  corners[2] -= along;
72  corners[3] += along;
73  }
74  return true;
75 }
static Vector2 ComputeAlongVector(const Matrix &transform, bool allow_zero_length, Point p0, Point p1, Scalar width)
Point Vector2
Definition: point.h:430

References ComputeAlongVector(), p1, and transform.

Referenced by impeller::LineContents::CalculatePerVertex(), and GetCoverage().

◆ ComputePixelHalfWidth()

Scalar impeller::LineGeometry::ComputePixelHalfWidth ( const Matrix &  transform,
Scalar  width 
)
static

Definition at line 18 of file line_geometry.cc.

19  {
20  Scalar max_basis = transform.GetMaxBasisLengthXY();
21  if (max_basis == 0) {
22  return {};
23  }
24 
25  Scalar min_size = kMinStrokeSize / max_basis;
26  return std::max(width, min_size) * 0.5f;
27 }
static constexpr Scalar kMinStrokeSize
Definition: geometry.h:19

References impeller::kMinStrokeSize, and transform.

Referenced by ComputeAlongVector(), and impeller::CircleGeometry::GetPositionBuffer().

◆ CoversArea()

bool impeller::LineGeometry::CoversArea ( const Matrix &  transform,
const IRect &  rect 
) const
overridevirtual

Determines if this geometry, transformed by the given transform, will completely cover all of the pixels within the given integer rect.

The integer rect, by definition, will contain all of the area covered by any pixel within its boundary.

The return value can be a conservative estimate which will still be useful for certain optimizations. It may return false for obscure cases that might actually contain all of the pixels if it is too computationally costly to prove containment, but it should never return 'true' unless the implementation can prove that all pixels are fully covered (rendered) by the geometry.

Returns
true if the transformed geometry is guaranteed to cover the given rect. May return false in some cases where the transformed geometry does in fact cover the rect.

Reimplemented from impeller::Geometry.

Definition at line 170 of file line_geometry.cc.

171  {
172  if (!transform.IsTranslationScaleOnly() || !IsAxisAlignedRect()) {
173  return false;
174  }
175  auto coverage = GetCoverage(transform);
176  return coverage.has_value() ? coverage->Contains(rect) : false;
177 }
bool IsAxisAlignedRect() const override
std::optional< Rect > GetCoverage(const Matrix &transform) const override
The coverage rectangle of this geometry, transformed by the transform argument.

References GetCoverage(), IsAxisAlignedRect(), and transform.

◆ GetCap()

Cap impeller::LineGeometry::GetCap ( ) const
inline

Definition at line 34 of file line_geometry.h.

34 { return cap_; }

Referenced by impeller::LineContents::CalculatePerVertex().

◆ GetCoverage()

std::optional< Rect > impeller::LineGeometry::GetCoverage ( const Matrix &  transform) const
overridevirtual

The coverage rectangle of this geometry, transformed by the transform argument.

Implements impeller::Geometry.

Definition at line 156 of file line_geometry.cc.

156  {
157  Point corners[4];
158  // Note: MSAA boolean doesn't matter for coverage computation.
159  if (!ComputeCorners(corners, transform, cap_ != Cap::kButt, p0_, p1_,
160  width_)) {
161  return {};
162  }
163 
164  for (int i = 0; i < 4; i++) {
165  corners[i] = transform * corners[i];
166  }
167  return Rect::MakePointBounds(std::begin(corners), std::end(corners));
168 }
static bool ComputeCorners(Point corners[4], const Matrix &transform, bool extend_endpoints, Point p0, Point p1, Scalar width)
TPoint< Scalar > Point
Definition: point.h:426
constexpr static std::optional< TRect > MakePointBounds(const U &value)
Definition: rect.h:189
const size_t end

References ComputeCorners(), end, impeller::kButt, impeller::TRect< Scalar >::MakePointBounds(), and transform.

Referenced by CoversArea().

◆ GetP0()

Point impeller::LineGeometry::GetP0 ( ) const
inline

Definition at line 31 of file line_geometry.h.

31 { return p0_; }

Referenced by impeller::LineContents::CalculatePerVertex().

◆ GetP1()

Point impeller::LineGeometry::GetP1 ( ) const
inline

Definition at line 32 of file line_geometry.h.

32 { return p1_; }

Referenced by impeller::LineContents::CalculatePerVertex().

◆ GetWidth()

Scalar impeller::LineGeometry::GetWidth ( ) const
inline

Definition at line 33 of file line_geometry.h.

33 { return width_; }

Referenced by impeller::LineContents::CalculatePerVertex().

◆ IsAxisAlignedRect()

bool impeller::LineGeometry::IsAxisAlignedRect ( ) const
overridevirtual

Reimplemented from impeller::Geometry.

Definition at line 179 of file line_geometry.cc.

179  {
180  return cap_ != Cap::kRound && (p0_.x == p1_.x || p0_.y == p1_.y);
181 }

References impeller::kRound.

Referenced by CoversArea().


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