| Flutter Impeller |

path_source.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef FLUTTER_IMPELLER_GEOMETRY_PATH_SOURCE_H_
6 #define FLUTTER_IMPELLER_GEOMETRY_PATH_SOURCE_H_
7
8 #include "impeller/geometry/point.h"
9 #include "impeller/geometry/rect.h"
10
11 namespace impeller {
12
13 enum class FillType {
14 kNonZero, // The default winding order.
15 kOdd,
16 };
17
18 enum class Convexity {
19 kUnknown,
20 kConvex,
21 };
22
23 /// @brief Collection of functions to receive path segments from the
24 /// underlying path representation via the DlPath::Dispatch method.
25 ///
26 /// The conic_to function is optional. If the receiver understands rational
27 /// quadratic Bezier curve forms then it should accept the curve parameters
28 /// and return true, otherwise it can return false and the dispatcher will
29 /// provide the path segment in a different form via the other methods.
30 ///
31 /// The dispatcher might not call the recommend_size or recommend_bounds
32 /// functions if the original path does not contain such information. If
33 /// it does call these functions then they should be called before any
34 /// path segments are dispatched.
35 ///
36 /// The dispatcher will always call the path_info function, though the
37 /// is_convex parameter may be conservatively reported as false if the
38 /// original path does not contain such info.
39 ///
40 /// Finally the dispatcher will always call the PathEnd function as the
41 /// last action before returning control to the method that called it.
42 class PathReceiver {
43 public:
44 virtual ~PathReceiver() = default;
45 virtual void MoveTo(const Point& p2, bool will_be_closed) = 0;
46 virtual void LineTo(const Point& p2) = 0;
47 virtual void QuadTo(const Point& cp, const Point& p2) = 0;
48 virtual bool ConicTo(const Point& cp, const Point& p2, Scalar weight) {
49 return false;
50 }
51 virtual void CubicTo(const Point& cp1, const Point& cp2, const Point& p2) = 0;
52 virtual void Close() = 0;
53 };
54
55 class PathSource {
56 public:
57 virtual ~PathSource() = default;
58 virtual FillType GetFillType() const = 0;
59 virtual Rect GetBounds() const = 0;
60 virtual bool IsConvex() const = 0;
61 virtual void Dispatch(PathReceiver& receiver) const = 0;
62 };
63
64 /// @brief A PathSource object that provides path iteration for any TRect.
65 class RectPathSource : public PathSource {
66 public:
67 template <class T>
68 explicit RectPathSource(const TRect<T>& r) : rect_(r) {}
69
70 ~RectPathSource();
71
72 // |PathSource|
73 FillType GetFillType() const override;
74
75 // |PathSource|
76 Rect GetBounds() const override;
77
78 // |PathSource|
79 bool IsConvex() const override;
80
81 // |PathSource|
82 void Dispatch(PathReceiver& receiver) const override;
83
84 private:
85 const Rect rect_;
86 };
87
88 /// @brief A PathSource object that provides path iteration for any ellipse
89 /// inscribed within a Rect bounds.
90 class EllipsePathSource : public PathSource {
91 public:
92 explicit EllipsePathSource(const Rect& bounds);
93
94 ~EllipsePathSource();
95
96 // |PathSource|
97 FillType GetFillType() const override;
98
99 // |PathSource|
100 Rect GetBounds() const override;
101
102 // |PathSource|
103 bool IsConvex() const override;
104
105 // |PathSource|
106 void Dispatch(PathReceiver& receiver) const override;
107
108 private:
109 const Rect bounds_;
110 };
111
112 /// A utility class to receive path segments from a source, transform them
113 /// by a matrix, and pass them along to a subsequent receiver.
114 class PathTransformer : public impeller::PathReceiver {
115 public:
116 PathTransformer(PathReceiver& receiver [[clang::lifetimebound]],
117 const impeller::Matrix& matrix [[clang::lifetimebound]])
118 : receiver_(receiver), matrix_(matrix) {}
119
120 void MoveTo(const Point& p2, bool will_be_closed) override {
121 receiver_.MoveTo(matrix_ * p2, will_be_closed);
122 }
123
124 void LineTo(const Point& p2) override { receiver_.LineTo(matrix_ * p2); }
125
126 void QuadTo(const Point& cp, const Point& p2) override {
127 receiver_.QuadTo(matrix_ * cp, matrix_ * p2);
128 }
129
130 bool ConicTo(const Point& cp, const Point& p2, Scalar weight) override {
131 return receiver_.ConicTo(matrix_ * cp, matrix_ * p2, weight);
132 }
133
134 void CubicTo(const Point& cp1, const Point& cp2, const Point& p2) override {
135 receiver_.CubicTo(matrix_ * cp1, matrix_ * cp2, matrix_ * p2);
136 }
137
138 void Close() override { receiver_.Close(); }
139
140 private:
141 PathReceiver& receiver_;
142 const impeller::Matrix& matrix_;
143 };
144
145 } // namespace impeller
146
147 #endif // FLUTTER_IMPELLER_GEOMETRY_PATH_SOURCE_H_
impeller::EllipsePathSource
A PathSource object that provides path iteration for any ellipse inscribed within a Rect bounds.
Definition: path_source.h:90
impeller::EllipsePathSource::EllipsePathSource
EllipsePathSource(const Rect &bounds)
Definition: path_source.cc:32
impeller::EllipsePathSource::Dispatch
void Dispatch(PathReceiver &receiver) const override
Definition: path_source.cc:48
impeller::EllipsePathSource::IsConvex
bool IsConvex() const override
Definition: path_source.cc:44
impeller::EllipsePathSource::~EllipsePathSource
~EllipsePathSource()
impeller::EllipsePathSource::GetBounds
Rect GetBounds() const override
Definition: path_source.cc:40
impeller::EllipsePathSource::GetFillType
FillType GetFillType() const override
Definition: path_source.cc:36
impeller::PathReceiver
Collection of functions to receive path segments from the underlying path representation via the DlPa...
Definition: path_source.h:42
impeller::PathReceiver::~PathReceiver
virtual ~PathReceiver()=default
impeller::PathReceiver::CubicTo
virtual void CubicTo(const Point &cp1, const Point &cp2, const Point &p2)=0
impeller::PathReceiver::LineTo
virtual void LineTo(const Point &p2)=0
impeller::PathReceiver::QuadTo
virtual void QuadTo(const Point &cp, const Point &p2)=0
impeller::PathReceiver::Close
virtual void Close()=0
impeller::PathReceiver::MoveTo
virtual void MoveTo(const Point &p2, bool will_be_closed)=0
impeller::PathReceiver::ConicTo
virtual bool ConicTo(const Point &cp, const Point &p2, Scalar weight)
Definition: path_source.h:48
impeller::PathSource
Definition: path_source.h:55
impeller::PathSource::GetBounds
virtual Rect GetBounds() const =0
impeller::PathSource::~PathSource
virtual ~PathSource()=default
impeller::PathSource::GetFillType
virtual FillType GetFillType() const =0
impeller::PathSource::Dispatch
virtual void Dispatch(PathReceiver &receiver) const =0
impeller::PathSource::IsConvex
virtual bool IsConvex() const =0
impeller::PathTransformer
Definition: path_source.h:114
impeller::PathTransformer::LineTo
void LineTo(const Point &p2) override
Definition: path_source.h:124
impeller::PathTransformer::QuadTo
void QuadTo(const Point &cp, const Point &p2) override
Definition: path_source.h:126
impeller::PathTransformer::ConicTo
bool ConicTo(const Point &cp, const Point &p2, Scalar weight) override
Definition: path_source.h:130
impeller::PathTransformer::PathTransformer
PathTransformer(PathReceiver &receiver[[clang::lifetimebound]], const impeller::Matrix &matrix[[clang::lifetimebound]])
Definition: path_source.h:116
impeller::PathTransformer::MoveTo
void MoveTo(const Point &p2, bool will_be_closed) override
Definition: path_source.h:120
impeller::PathTransformer::CubicTo
void CubicTo(const Point &cp1, const Point &cp2, const Point &p2) override
Definition: path_source.h:134
impeller::PathTransformer::Close
void Close() override
Definition: path_source.h:138
impeller::RectPathSource
A PathSource object that provides path iteration for any TRect.
Definition: path_source.h:65
impeller::RectPathSource::GetFillType
FillType GetFillType() const override
Definition: path_source.cc:15
impeller::RectPathSource::RectPathSource
RectPathSource(const TRect< T > &r)
Definition: path_source.h:68
impeller::RectPathSource::IsConvex
bool IsConvex() const override
Definition: path_source.cc:11
impeller::RectPathSource::GetBounds
Rect GetBounds() const override
Definition: path_source.cc:19
impeller::RectPathSource::~RectPathSource
~RectPathSource()
impeller::RectPathSource::Dispatch
void Dispatch(PathReceiver &receiver) const override
Definition: path_source.cc:23
impeller
Definition: allocation.cc:12
impeller::Scalar
float Scalar
Definition: scalar.h:19
impeller::FillType
FillType
Definition: path_source.h:13
impeller::FillType::kOdd
@ kOdd
impeller::FillType::kNonZero
@ kNonZero
impeller::Convexity
Convexity
Definition: path_source.h:18
impeller::Convexity::kUnknown
@ kUnknown
impeller::Convexity::kConvex
@ kConvex
point.h
rect.h
p2
Point p2
Definition: round_superellipse_param.cc:317
weight
Scalar weight
Definition: round_superellipse_param.cc:319
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
impeller::TPoint< Scalar >
impeller::TRect< Scalar >