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 
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 
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 
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 } // namespace impeller
113 
114 #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
EllipsePathSource(const Rect &bounds)
Definition: path_source.cc:32
void Dispatch(PathReceiver &receiver) const override
Definition: path_source.cc:48
bool IsConvex() const override
Definition: path_source.cc:44
Rect GetBounds() const override
Definition: path_source.cc:40
FillType GetFillType() const override
Definition: path_source.cc:36
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
A PathSource object that provides path iteration for any TRect.
Definition: path_source.h:65
FillType GetFillType() const override
Definition: path_source.cc:15
RectPathSource(const TRect< T > &r)
Definition: path_source.h:68
bool IsConvex() const override
Definition: path_source.cc:11
Rect GetBounds() const override
Definition: path_source.cc:19
void Dispatch(PathReceiver &receiver) const override
Definition: path_source.cc:23
float Scalar
Definition: scalar.h:19