Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
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
10
11namespace impeller {
12
13enum class FillType {
14 kNonZero, // The default winding order.
15 kOdd,
16};
17
18enum class Convexity {
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.
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
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.
65class RectPathSource : public PathSource {
66 public:
67 template <class T>
68 explicit RectPathSource(const TRect<T>& r) : rect_(r) {}
69
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.
91 public:
92 explicit EllipsePathSource(const Rect& bounds);
93
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.
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_
A PathSource object that provides path iteration for any ellipse inscribed within a Rect bounds.
Definition path_source.h:90
void Dispatch(PathReceiver &receiver) const override
bool IsConvex() const override
Rect GetBounds() const override
FillType GetFillType() const override
Collection of functions to receive path segments from the underlying path representation via the DlPa...
Definition path_source.h:42
virtual ~PathReceiver()=default
virtual void CubicTo(const Point &cp1, const Point &cp2, const Point &p2)=0
virtual void LineTo(const Point &p2)=0
virtual void QuadTo(const Point &cp, const Point &p2)=0
virtual void Close()=0
virtual void MoveTo(const Point &p2, bool will_be_closed)=0
virtual bool ConicTo(const Point &cp, const Point &p2, Scalar weight)
Definition path_source.h:48
virtual Rect GetBounds() const =0
virtual ~PathSource()=default
virtual FillType GetFillType() const =0
virtual void Dispatch(PathReceiver &receiver) const =0
virtual bool IsConvex() const =0
void LineTo(const Point &p2) override
void QuadTo(const Point &cp, const Point &p2) override
bool ConicTo(const Point &cp, const Point &p2, Scalar weight) override
PathTransformer(PathReceiver &receiver, const impeller::Matrix &matrix)
void MoveTo(const Point &p2, bool will_be_closed) override
void CubicTo(const Point &cp1, const Point &cp2, const Point &p2) override
A PathSource object that provides path iteration for any TRect.
Definition path_source.h:65
FillType GetFillType() const override
RectPathSource(const TRect< T > &r)
Definition path_source.h:68
bool IsConvex() const override
Rect GetBounds() const override
void Dispatch(PathReceiver &receiver) const override
float Scalar
Definition scalar.h:19
A 4x4 matrix using column-major storage.
Definition matrix.h:37