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_LIB_UI_PAINTING_PATH_H_ |
6 | #define FLUTTER_LIB_UI_PAINTING_PATH_H_ |
7 | |
8 | #include "flutter/lib/ui/dart_wrapper.h" |
9 | #include "flutter/lib/ui/painting/rrect.h" |
10 | #include "flutter/lib/ui/ui_dart_state.h" |
11 | #include "flutter/lib/ui/volatile_path_tracker.h" |
12 | #include "third_party/skia/include/core/SkPath.h" |
13 | #include "third_party/skia/include/pathops/SkPathOps.h" |
14 | #include "third_party/tonic/typed_data/typed_list.h" |
15 | |
16 | namespace flutter { |
17 | |
18 | class CanvasPath : public RefCountedDartWrappable<CanvasPath> { |
19 | DEFINE_WRAPPERTYPEINFO(); |
20 | FML_FRIEND_MAKE_REF_COUNTED(CanvasPath); |
21 | |
22 | public: |
23 | ~CanvasPath() override; |
24 | |
25 | static void CreateFrom(Dart_Handle path_handle, const SkPath& src) { |
26 | auto path = fml::MakeRefCounted<CanvasPath>(); |
27 | path->AssociateWithDartWrapper(wrappable: path_handle); |
28 | path->tracked_path_->path = src; |
29 | } |
30 | |
31 | static fml::RefPtr<CanvasPath> Create(Dart_Handle wrapper) { |
32 | UIDartState::ThrowIfUIOperationsProhibited(); |
33 | auto res = fml::MakeRefCounted<CanvasPath>(); |
34 | res->AssociateWithDartWrapper(wrappable: wrapper); |
35 | return res; |
36 | } |
37 | |
38 | int getFillType(); |
39 | void setFillType(int fill_type); |
40 | |
41 | void moveTo(double x, double y); |
42 | void relativeMoveTo(double x, double y); |
43 | void lineTo(double x, double y); |
44 | void relativeLineTo(double x, double y); |
45 | void quadraticBezierTo(double x1, double y1, double x2, double y2); |
46 | void relativeQuadraticBezierTo(double x1, double y1, double x2, double y2); |
47 | void cubicTo(double x1, |
48 | double y1, |
49 | double x2, |
50 | double y2, |
51 | double x3, |
52 | double y3); |
53 | void relativeCubicTo(double x1, |
54 | double y1, |
55 | double x2, |
56 | double y2, |
57 | double x3, |
58 | double y3); |
59 | void conicTo(double x1, double y1, double x2, double y2, double w); |
60 | void relativeConicTo(double x1, double y1, double x2, double y2, double w); |
61 | void arcTo(double left, |
62 | double top, |
63 | double right, |
64 | double bottom, |
65 | double startAngle, |
66 | double sweepAngle, |
67 | bool forceMoveTo); |
68 | void arcToPoint(double arcEndX, |
69 | double arcEndY, |
70 | double radiusX, |
71 | double radiusY, |
72 | double xAxisRotation, |
73 | bool isLargeArc, |
74 | bool isClockwiseDirection); |
75 | void relativeArcToPoint(double arcEndDeltaX, |
76 | double arcEndDeltaY, |
77 | double radiusX, |
78 | double radiusY, |
79 | double xAxisRotation, |
80 | bool isLargeArc, |
81 | bool isClockwiseDirection); |
82 | void addRect(double left, double top, double right, double bottom); |
83 | void addOval(double left, double top, double right, double bottom); |
84 | void addArc(double left, |
85 | double top, |
86 | double right, |
87 | double bottom, |
88 | double startAngle, |
89 | double sweepAngle); |
90 | void addPolygon(const tonic::Float32List& points, bool close); |
91 | void addRRect(const RRect& rrect); |
92 | void addPath(CanvasPath* path, double dx, double dy); |
93 | |
94 | void addPathWithMatrix(CanvasPath* path, |
95 | double dx, |
96 | double dy, |
97 | Dart_Handle matrix4_handle); |
98 | |
99 | void extendWithPath(CanvasPath* path, double dx, double dy); |
100 | |
101 | void extendWithPathAndMatrix(CanvasPath* path, |
102 | double dx, |
103 | double dy, |
104 | Dart_Handle matrix4_handle); |
105 | |
106 | void close(); |
107 | void reset(); |
108 | bool contains(double x, double y); |
109 | void shift(Dart_Handle path_handle, double dx, double dy); |
110 | |
111 | void transform(Dart_Handle path_handle, Dart_Handle matrix4_handle); |
112 | |
113 | tonic::Float32List getBounds(); |
114 | bool op(CanvasPath* path1, CanvasPath* path2, int operation); |
115 | void clone(Dart_Handle path_handle); |
116 | |
117 | const SkPath& path() const { return tracked_path_->path; } |
118 | |
119 | private: |
120 | CanvasPath(); |
121 | |
122 | std::shared_ptr<VolatilePathTracker> path_tracker_; |
123 | std::shared_ptr<VolatilePathTracker::TrackedPath> tracked_path_; |
124 | |
125 | // Must be called whenever the path is created or mutated. |
126 | void resetVolatility(); |
127 | |
128 | SkPath& mutable_path() { return tracked_path_->path; } |
129 | }; |
130 | |
131 | } // namespace flutter |
132 | |
133 | #endif // FLUTTER_LIB_UI_PAINTING_PATH_H_ |
134 | |