Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
flutter::CanvasPath Class Reference

#include <path.h>

Inheritance diagram for flutter::CanvasPath:
flutter::RefCountedDartWrappable< CanvasPath > fml::RefCountedThreadSafe< T > tonic::DartWrappable fml::internal::RefCountedThreadSafeBase

Public Member Functions

 ~CanvasPath () override
 
int getFillType ()
 
void setFillType (int fill_type)
 
void moveTo (double x, double y)
 
void relativeMoveTo (double x, double y)
 
void lineTo (double x, double y)
 
void relativeLineTo (double x, double y)
 
void quadraticBezierTo (double x1, double y1, double x2, double y2)
 
void relativeQuadraticBezierTo (double x1, double y1, double x2, double y2)
 
void cubicTo (double x1, double y1, double x2, double y2, double x3, double y3)
 
void relativeCubicTo (double x1, double y1, double x2, double y2, double x3, double y3)
 
void conicTo (double x1, double y1, double x2, double y2, double w)
 
void relativeConicTo (double x1, double y1, double x2, double y2, double w)
 
void arcTo (double left, double top, double right, double bottom, double startAngle, double sweepAngle, bool forceMoveTo)
 
void arcToPoint (double arcEndX, double arcEndY, double radiusX, double radiusY, double xAxisRotation, bool isLargeArc, bool isClockwiseDirection)
 
void relativeArcToPoint (double arcEndDeltaX, double arcEndDeltaY, double radiusX, double radiusY, double xAxisRotation, bool isLargeArc, bool isClockwiseDirection)
 
void addRect (double left, double top, double right, double bottom)
 
void addOval (double left, double top, double right, double bottom)
 
void addArc (double left, double top, double right, double bottom, double startAngle, double sweepAngle)
 
void addPolygon (const tonic::Float32List &points, bool close)
 
void addRRect (const RRect &rrect)
 
void addRSuperellipse (const RSuperellipse *rse)
 
void addPath (CanvasPath *path, double dx, double dy)
 
void addPathWithMatrix (CanvasPath *path, double dx, double dy, Dart_Handle matrix4_handle)
 
void extendWithPath (CanvasPath *path, double dx, double dy)
 
void extendWithPathAndMatrix (CanvasPath *path, double dx, double dy, Dart_Handle matrix4_handle)
 
void close ()
 
void reset ()
 
bool contains (double x, double y)
 
void shift (Dart_Handle path_handle, double dx, double dy)
 
void transform (Dart_Handle path_handle, Dart_Handle matrix4_handle)
 
tonic::Float32List getBounds ()
 
bool op (CanvasPath *path1, CanvasPath *path2, int operation)
 
void clone (Dart_Handle path_handle)
 
const DlPathpath () const
 
- Public Member Functions inherited from flutter::RefCountedDartWrappable< CanvasPath >
virtual void RetainDartWrappableReference () const override
 
virtual void ReleaseDartWrappableReference () const override
 
- Public Member Functions inherited from fml::RefCountedThreadSafe< T >
void Release () const
 
- Public Member Functions inherited from fml::internal::RefCountedThreadSafeBase
void AddRef () const
 
bool HasOneRef () const
 
void AssertHasOneRef () const
 
- Public Member Functions inherited from tonic::DartWrappable
 DartWrappable ()
 
virtual const DartWrapperInfoGetDartWrapperInfo () const =0
 
Dart_Handle CreateDartWrapper (DartState *dart_state)
 
void AssociateWithDartWrapper (Dart_Handle wrappable)
 
void ClearDartWrapper ()
 
Dart_WeakPersistentHandle dart_wrapper () const
 

Static Public Member Functions

static void CreateFrom (Dart_Handle path_handle, const SkPath &src)
 
static fml::RefPtr< CanvasPathCreate (Dart_Handle wrapper)
 

Additional Inherited Members

- Public Types inherited from tonic::DartWrappable
enum  DartNativeFields {
  kPeerIndex ,
  kNumberOfNativeFields
}
 
- Protected Member Functions inherited from fml::RefCountedThreadSafe< T >
 RefCountedThreadSafe ()
 
 ~RefCountedThreadSafe ()
 
- Protected Member Functions inherited from fml::internal::RefCountedThreadSafeBase
 RefCountedThreadSafeBase ()
 
 ~RefCountedThreadSafeBase ()
 
bool Release () const
 
void Adopt ()
 
- Protected Member Functions inherited from tonic::DartWrappable
virtual ~DartWrappable ()
 
- Static Protected Member Functions inherited from tonic::DartWrappable
static Dart_PersistentHandle GetTypeForWrapper (tonic::DartState *dart_state, const tonic::DartWrapperInfo &wrapper_info)
 

Detailed Description

Definition at line 19 of file path.h.

Constructor & Destructor Documentation

◆ ~CanvasPath()

flutter::CanvasPath::~CanvasPath ( )
overridedefault

Member Function Documentation

◆ addArc()

void flutter::CanvasPath::addArc ( double  left,
double  top,
double  right,
double  bottom,
double  startAngle,
double  sweepAngle 
)

Definition at line 185 of file path.cc.

190 {
191 sk_path_.addArc(SkRect::MakeLTRB(SafeNarrow(left), SafeNarrow(top),
192 SafeNarrow(right), SafeNarrow(bottom)),
193 SafeNarrow(startAngle) * 180.0f / static_cast<float>(M_PI),
194 SafeNarrow(sweepAngle) * 180.0f / static_cast<float>(M_PI));
195 resetVolatility();
196}
static float SafeNarrow(double value)

References flutter::SafeNarrow().

◆ addOval()

void flutter::CanvasPath::addOval ( double  left,
double  top,
double  right,
double  bottom 
)

Definition at line 179 of file path.cc.

179 {
180 sk_path_.addOval(SkRect::MakeLTRB(SafeNarrow(left), SafeNarrow(top),
181 SafeNarrow(right), SafeNarrow(bottom)));
182 resetVolatility();
183}

References flutter::SafeNarrow().

◆ addPath()

void flutter::CanvasPath::addPath ( CanvasPath path,
double  dx,
double  dy 
)

Definition at line 220 of file path.cc.

220 {
221 if (!path) {
222 Dart_ThrowException(ToDart("Path.addPath called with non-genuine Path."));
223 return;
224 }
225 sk_path_.addPath(path->path().GetSkPath(), SafeNarrow(dx), SafeNarrow(dy),
226 SkPath::kAppend_AddPathMode);
227 resetVolatility();
228}
const DlPath & path() const
Definition path.cc:344
const SkPath & GetSkPath() const
Definition dl_path.cc:116
Dart_Handle ToDart(const T &object)

References flutter::DlPath::GetSkPath(), path(), and flutter::SafeNarrow().

◆ addPathWithMatrix()

void flutter::CanvasPath::addPathWithMatrix ( CanvasPath path,
double  dx,
double  dy,
Dart_Handle  matrix4_handle 
)

Definition at line 230 of file path.cc.

233 {
234 tonic::Float64List matrix4(matrix4_handle);
235
236 if (!path) {
237 matrix4.Release();
238 Dart_ThrowException(
239 ToDart("Path.addPathWithMatrix called with non-genuine Path."));
240 return;
241 }
242
243 SkMatrix matrix = ToSkMatrix(matrix4);
244 matrix4.Release();
245 matrix.setTranslateX(matrix.getTranslateX() + SafeNarrow(dx));
246 matrix.setTranslateY(matrix.getTranslateY() + SafeNarrow(dy));
247 sk_path_.addPath(path->path().GetSkPath(), matrix,
248 SkPath::kAppend_AddPathMode);
249 resetVolatility();
250}
SkMatrix ToSkMatrix(const DlMatrix &matrix)

References flutter::DlPath::GetSkPath(), path(), flutter::SafeNarrow(), and flutter::ToSkMatrix().

◆ addPolygon()

void flutter::CanvasPath::addPolygon ( const tonic::Float32List &  points,
bool  close 
)

Definition at line 198 of file path.cc.

198 {
199 SkSpan<const SkPoint> ptsSpan = {
200 reinterpret_cast<const SkPoint*>(points.data()),
201 points.num_elements() / 2};
202 sk_path_.addPolygon(ptsSpan, close);
203 resetVolatility();
204}
std::vector< Point > points

References close(), and points.

◆ addRect()

void flutter::CanvasPath::addRect ( double  left,
double  top,
double  right,
double  bottom 
)

Definition at line 173 of file path.cc.

173 {
174 sk_path_.addRect(SkRect::MakeLTRB(SafeNarrow(left), SafeNarrow(top),
175 SafeNarrow(right), SafeNarrow(bottom)));
176 resetVolatility();
177}

References flutter::SafeNarrow().

◆ addRRect()

void flutter::CanvasPath::addRRect ( const RRect rrect)

Definition at line 206 of file path.cc.

206 {
207 sk_path_.addRRect(ToSkRRect(rrect.rrect));
208 resetVolatility();
209}
const SkRRect ToSkRRect(const DlRoundRect &round_rect)

References flutter::RRect::rrect, and flutter::ToSkRRect().

◆ addRSuperellipse()

void flutter::CanvasPath::addRSuperellipse ( const RSuperellipse rse)

Definition at line 211 of file path.cc.

211 {
212 DlPathBuilder builder;
213 builder.AddRoundSuperellipse(DlRoundSuperellipse::MakeRectRadii(
214 rsuperellipse->bounds(), rsuperellipse->radii()));
215 sk_path_.addPath(builder.TakePath().GetSkPath(), SkPath::kAppend_AddPathMode);
216
217 resetVolatility();
218}
static RoundSuperellipse MakeRectRadii(const Rect &rect, const RoundingRadii &radii)

References flutter::DlPathBuilder::AddRoundSuperellipse(), flutter::RSuperellipse::bounds(), flutter::DlPath::GetSkPath(), impeller::RoundSuperellipse::MakeRectRadii(), flutter::RSuperellipse::radii(), and flutter::DlPathBuilder::TakePath().

◆ arcTo()

void flutter::CanvasPath::arcTo ( double  left,
double  top,
double  right,
double  bottom,
double  startAngle,
double  sweepAngle,
bool  forceMoveTo 
)

Definition at line 123 of file path.cc.

129 {
130 sk_path_.arcTo(SkRect::MakeLTRB(SafeNarrow(left), SafeNarrow(top),
131 SafeNarrow(right), SafeNarrow(bottom)),
132 SafeNarrow(startAngle) * 180.0f / static_cast<float>(M_PI),
133 SafeNarrow(sweepAngle) * 180.0f / static_cast<float>(M_PI),
134 forceMoveTo);
135 resetVolatility();
136}

References flutter::SafeNarrow().

◆ arcToPoint()

void flutter::CanvasPath::arcToPoint ( double  arcEndX,
double  arcEndY,
double  radiusX,
double  radiusY,
double  xAxisRotation,
bool  isLargeArc,
bool  isClockwiseDirection 
)

Definition at line 138 of file path.cc.

144 {
145 const auto arcSize = isLargeArc ? SkPathBuilder::ArcSize::kLarge_ArcSize
146 : SkPathBuilder::ArcSize::kSmall_ArcSize;
147 const auto direction =
148 isClockwiseDirection ? SkPathDirection::kCW : SkPathDirection::kCCW;
149
150 sk_path_.arcTo({SafeNarrow(radiusX), SafeNarrow(radiusY)},
151 SafeNarrow(xAxisRotation), arcSize, direction,
152 {SafeNarrow(arcEndX), SafeNarrow(arcEndY)});
153 resetVolatility();
154}

References flutter::SafeNarrow().

◆ clone()

void flutter::CanvasPath::clone ( Dart_Handle  path_handle)

Definition at line 337 of file path.cc.

337 {
338 fml::RefPtr<CanvasPath> path = Create(path_handle);
339 // per Skia docs, this will create a fast copy
340 // data is shared until the source path or dest path are mutated
341 path->sk_path_ = this->sk_path_;
342}
static fml::RefPtr< CanvasPath > Create(Dart_Handle wrapper)
Definition path.h:32

References Create(), and path().

◆ close()

void flutter::CanvasPath::close ( )

Definition at line 285 of file path.cc.

285 {
286 sk_path_.close();
287 resetVolatility();
288}

Referenced by addPolygon().

◆ conicTo()

void flutter::CanvasPath::conicTo ( double  x1,
double  y1,
double  x2,
double  y2,
double  w 
)

Definition at line 107 of file path.cc.

107 {
108 sk_path_.conicTo({SafeNarrow(x1), SafeNarrow(y1)},
109 {SafeNarrow(x2), SafeNarrow(y2)}, SafeNarrow(w));
110 resetVolatility();
111}

References flutter::SafeNarrow().

◆ contains()

bool flutter::CanvasPath::contains ( double  x,
double  y 
)

Definition at line 295 of file path.cc.

295 {
296 return sk_path_.contains({SafeNarrow(x), SafeNarrow(y)});
297}
int32_t x
double y

References flutter::SafeNarrow(), x, and y.

◆ Create()

static fml::RefPtr< CanvasPath > flutter::CanvasPath::Create ( Dart_Handle  wrapper)
inlinestatic

Definition at line 32 of file path.h.

32 {
34 auto res = fml::MakeRefCounted<CanvasPath>();
35 res->AssociateWithDartWrapper(wrapper);
36 return res;
37 }
static void ThrowIfUIOperationsProhibited()

References flutter::UIDartState::ThrowIfUIOperationsProhibited().

Referenced by clone(), flutter::CanvasPathMeasure::getSegment(), shift(), and transform().

◆ CreateFrom()

static void flutter::CanvasPath::CreateFrom ( Dart_Handle  path_handle,
const SkPath &  src 
)
inlinestatic

Definition at line 26 of file path.h.

26 {
27 auto path = fml::MakeRefCounted<CanvasPath>();
28 path->AssociateWithDartWrapper(path_handle);
29 path->sk_path_ = src;
30 }

References path().

Referenced by flutter::CanvasPathMeasure::getSegment().

◆ cubicTo()

void flutter::CanvasPath::cubicTo ( double  x1,
double  y1,
double  x2,
double  y2,
double  x3,
double  y3 
)

Definition at line 83 of file path.cc.

88 {
89 sk_path_.cubicTo({SafeNarrow(x1), SafeNarrow(y1)},
90 {SafeNarrow(x2), SafeNarrow(y2)},
91 {SafeNarrow(x3), SafeNarrow(y3)});
92 resetVolatility();
93}

References flutter::SafeNarrow().

◆ extendWithPath()

void flutter::CanvasPath::extendWithPath ( CanvasPath path,
double  dx,
double  dy 
)

Definition at line 252 of file path.cc.

252 {
253 if (!path) {
254 Dart_ThrowException(
255 ToDart("Path.extendWithPath called with non-genuine Path."));
256 return;
257 }
258 sk_path_.addPath(path->path().GetSkPath(), SafeNarrow(dx), SafeNarrow(dy),
259 SkPath::kExtend_AddPathMode);
260 resetVolatility();
261}

References flutter::DlPath::GetSkPath(), path(), and flutter::SafeNarrow().

◆ extendWithPathAndMatrix()

void flutter::CanvasPath::extendWithPathAndMatrix ( CanvasPath path,
double  dx,
double  dy,
Dart_Handle  matrix4_handle 
)

Definition at line 263 of file path.cc.

266 {
267 tonic::Float64List matrix4(matrix4_handle);
268
269 if (!path) {
270 matrix4.Release();
271 Dart_ThrowException(
272 ToDart("Path.addPathWithMatrix called with non-genuine Path."));
273 return;
274 }
275
276 SkMatrix matrix = ToSkMatrix(matrix4);
277 matrix4.Release();
278 matrix.setTranslateX(matrix.getTranslateX() + SafeNarrow(dx));
279 matrix.setTranslateY(matrix.getTranslateY() + SafeNarrow(dy));
280 sk_path_.addPath(path->path().GetSkPath(), matrix,
281 SkPath::kExtend_AddPathMode);
282 resetVolatility();
283}

References flutter::DlPath::GetSkPath(), path(), flutter::SafeNarrow(), and flutter::ToSkMatrix().

◆ getBounds()

tonic::Float32List flutter::CanvasPath::getBounds ( )

Definition at line 315 of file path.cc.

315 {
316 tonic::Float32List rect(Dart_NewTypedData(Dart_TypedData_kFloat32, 4));
317 const SkRect& bounds = sk_path_.computeFiniteBounds().value_or(SkRect());
318 rect[0] = bounds.left();
319 rect[1] = bounds.top();
320 rect[2] = bounds.right();
321 rect[3] = bounds.bottom();
322 return rect;
323}

◆ getFillType()

int flutter::CanvasPath::getFillType ( )

Definition at line 39 of file path.cc.

39 {
40 return static_cast<int>(sk_path_.fillType());
41}

◆ lineTo()

void flutter::CanvasPath::lineTo ( double  x,
double  y 
)

Definition at line 58 of file path.cc.

58 {
59 sk_path_.lineTo({SafeNarrow(x), SafeNarrow(y)});
60 resetVolatility();
61}

References flutter::SafeNarrow(), x, and y.

◆ moveTo()

void flutter::CanvasPath::moveTo ( double  x,
double  y 
)

Definition at line 48 of file path.cc.

48 {
49 sk_path_.moveTo(SafeNarrow(x), SafeNarrow(y));
50 resetVolatility();
51}

References flutter::SafeNarrow(), x, and y.

◆ op()

bool flutter::CanvasPath::op ( CanvasPath path1,
CanvasPath path2,
int  operation 
)

Definition at line 325 of file path.cc.

325 {
326 std::optional<SkPath> result =
327 Op(path1->path().GetSkPath(), path2->path().GetSkPath(),
328 static_cast<SkPathOp>(operation));
329 if (result) {
330 sk_path_ = result.value();
331 resetVolatility();
332 return true;
333 }
334 return false;
335}
void Op(SkPathBuilder *one, SkPathBuilder *two, SkPathOp op)
Definition path_ops.cc:44

References flutter::DlPath::GetSkPath(), flutter::Op(), and path().

◆ path()

const DlPath & flutter::CanvasPath::path ( ) const

Definition at line 344 of file path.cc.

344 {
345 if (!dl_path_.has_value()) {
346 dl_path_.emplace(sk_path_.snapshot());
347 }
348 return dl_path_.value();
349}

Referenced by addPath(), addPathWithMatrix(), clone(), CreateFrom(), extendWithPath(), extendWithPathAndMatrix(), op(), shift(), and transform().

◆ quadraticBezierTo()

void flutter::CanvasPath::quadraticBezierTo ( double  x1,
double  y1,
double  x2,
double  y2 
)

Definition at line 68 of file path.cc.

68 {
69 sk_path_.quadTo({SafeNarrow(x1), SafeNarrow(y1)},
70 {SafeNarrow(x2), SafeNarrow(y2)});
71 resetVolatility();
72}

References flutter::SafeNarrow().

◆ relativeArcToPoint()

void flutter::CanvasPath::relativeArcToPoint ( double  arcEndDeltaX,
double  arcEndDeltaY,
double  radiusX,
double  radiusY,
double  xAxisRotation,
bool  isLargeArc,
bool  isClockwiseDirection 
)

Definition at line 156 of file path.cc.

162 {
163 const auto arcSize = isLargeArc ? SkPathBuilder::ArcSize::kLarge_ArcSize
164 : SkPathBuilder::ArcSize::kSmall_ArcSize;
165 const auto direction =
166 isClockwiseDirection ? SkPathDirection::kCW : SkPathDirection::kCCW;
167 sk_path_.rArcTo({SafeNarrow(radiusX), SafeNarrow(radiusY)},
168 SafeNarrow(xAxisRotation), arcSize, direction,
169 {SafeNarrow(arcEndDeltaX), SafeNarrow(arcEndDeltaY)});
170 resetVolatility();
171}

References flutter::SafeNarrow().

◆ relativeConicTo()

void flutter::CanvasPath::relativeConicTo ( double  x1,
double  y1,
double  x2,
double  y2,
double  w 
)

Definition at line 113 of file path.cc.

117 {
118 sk_path_.rConicTo({SafeNarrow(x1), SafeNarrow(y1)},
119 {SafeNarrow(x2), SafeNarrow(y2)}, SafeNarrow(w));
120 resetVolatility();
121}

References flutter::SafeNarrow().

◆ relativeCubicTo()

void flutter::CanvasPath::relativeCubicTo ( double  x1,
double  y1,
double  x2,
double  y2,
double  x3,
double  y3 
)

Definition at line 95 of file path.cc.

100 {
101 sk_path_.rCubicTo({SafeNarrow(x1), SafeNarrow(y1)},
102 {SafeNarrow(x2), SafeNarrow(y2)},
103 {SafeNarrow(x3), SafeNarrow(y3)});
104 resetVolatility();
105}

References flutter::SafeNarrow().

◆ relativeLineTo()

void flutter::CanvasPath::relativeLineTo ( double  x,
double  y 
)

Definition at line 63 of file path.cc.

63 {
64 sk_path_.rLineTo({SafeNarrow(x), SafeNarrow(y)});
65 resetVolatility();
66}

References flutter::SafeNarrow(), x, and y.

◆ relativeMoveTo()

void flutter::CanvasPath::relativeMoveTo ( double  x,
double  y 
)

Definition at line 53 of file path.cc.

53 {
54 sk_path_.rMoveTo({SafeNarrow(x), SafeNarrow(y)});
55 resetVolatility();
56}

References flutter::SafeNarrow(), x, and y.

◆ relativeQuadraticBezierTo()

void flutter::CanvasPath::relativeQuadraticBezierTo ( double  x1,
double  y1,
double  x2,
double  y2 
)

Definition at line 74 of file path.cc.

77 {
78 sk_path_.rQuadTo({SafeNarrow(x1), SafeNarrow(y1)},
79 {SafeNarrow(x2), SafeNarrow(y2)});
80 resetVolatility();
81}

References flutter::SafeNarrow().

◆ reset()

void flutter::CanvasPath::reset ( )

Definition at line 290 of file path.cc.

290 {
291 sk_path_.reset();
292 resetVolatility();
293}

Referenced by impeller::compiler::CompilerSkSL::compile().

◆ setFillType()

void flutter::CanvasPath::setFillType ( int  fill_type)

Definition at line 43 of file path.cc.

43 {
44 sk_path_.setFillType(static_cast<SkPathFillType>(fill_type));
45 resetVolatility();
46}

◆ shift()

void flutter::CanvasPath::shift ( Dart_Handle  path_handle,
double  dx,
double  dy 
)

Definition at line 299 of file path.cc.

299 {
300 fml::RefPtr<CanvasPath> path = Create(path_handle);
301 path->sk_path_ = sk_path_;
302 path->sk_path_.offset(SafeNarrow(dx), SafeNarrow(dy));
303}

References Create(), path(), and flutter::SafeNarrow().

◆ transform()

void flutter::CanvasPath::transform ( Dart_Handle  path_handle,
Dart_Handle  matrix4_handle 
)

Definition at line 305 of file path.cc.

306 {
307 tonic::Float64List matrix4(matrix4_handle);
308 auto sk_matrix = ToSkMatrix(matrix4);
309 matrix4.Release();
310 fml::RefPtr<CanvasPath> path = Create(path_handle);
311 path->sk_path_ = sk_path_;
312 path->sk_path_.transform(sk_matrix);
313}
SkMatrix sk_matrix

References Create(), path(), sk_matrix, and flutter::ToSkMatrix().


The documentation for this class was generated from the following files: