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