Flutter Engine
 
Loading...
Searching...
No Matches
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 Rect &rect) const override
 Determines if this geometry, transformed by the given transform, will completely cover all surface area of the given rect.
 
bool IsAxisAlignedRect () const override
 
Scalar ComputeAlphaCoverage (const Matrix &transform) const override
 
std::optional< RectGetCoverage (const Matrix &transform) const override
 
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< GeometryMakeFillPath (const flutter::DlPath &path, std::optional< Rect > inner_rect=std::nullopt)
 
static std::unique_ptr< GeometryMakeStrokePath (const flutter::DlPath &path, const StrokeParameters &stroke={})
 
static std::unique_ptr< GeometryMakeCover ()
 
static std::unique_ptr< GeometryMakeRect (const Rect &rect)
 
static std::unique_ptr< GeometryMakeOval (const Rect &rect)
 
static std::unique_ptr< GeometryMakeLine (const Point &p0, const Point &p1, const StrokeParameters &stroke)
 
static std::unique_ptr< GeometryMakeCircle (const Point &center, Scalar radius)
 
static std::unique_ptr< GeometryMakeStrokedCircle (const Point &center, Scalar radius, Scalar stroke_width)
 
static std::unique_ptr< GeometryMakeFilledArc (const Rect &oval_bounds, Degrees start, Degrees sweep, bool include_center)
 
static std::unique_ptr< GeometryMakeStrokedArc (const Rect &oval_bounds, Degrees start, Degrees sweep, const StrokeParameters &stroke)
 
static std::unique_ptr< GeometryMakeRoundRect (const Rect &rect, const Size &radii)
 
static std::unique_ptr< GeometryMakeRoundSuperellipse (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.
 
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}
#define FML_DCHECK(condition)
Definition logging.h:122

References FML_DCHECK.

◆ ~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)
size_t length
float Scalar
Definition scalar.h:19
constexpr float kEhCloseEnough
Definition constants.h:57
int32_t width

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

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:331

References ComputeAlongVector(), transform, and width.

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, transform, and width.

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

◆ CoversArea()

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

Determines if this geometry, transformed by the given transform, will completely cover all surface area of the given rect.

This is a conservative estimate useful for certain optimizations.

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

Reimplemented from impeller::Geometry.

Definition at line 170 of file line_geometry.cc.

170 {
171 if (!transform.IsTranslationScaleOnly() || !IsAxisAlignedRect()) {
172 return false;
173 }
174 auto coverage = GetCoverage(transform);
175 return coverage.has_value() ? coverage->Contains(rect) : false;
176}
bool IsAxisAlignedRect() const override
std::optional< Rect > GetCoverage(const Matrix &transform) const override

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

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:327
static constexpr std::optional< TRect > MakePointBounds(const U &value)
Definition rect.h:165

References ComputeCorners(), i, 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 178 of file line_geometry.cc.

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

References impeller::kRound.

Referenced by CoversArea().


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