Skia
2D Graphics Library
SkPath.h
Go to the documentation of this file.
1 /*
2  * Copyright 2006 The Android Open Source Project
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef SkPath_DEFINED
9 #define SkPath_DEFINED
10 
11 #include "include/core/SkMatrix.h"
13 #include "include/core/SkPoint.h"
14 #include "include/core/SkRect.h"
15 #include "include/core/SkRefCnt.h"
16 #include "include/core/SkScalar.h"
17 #include "include/core/SkTypes.h"
18 #include "include/private/base/SkDebug.h"
19 #include "include/private/base/SkTo.h"
20 #include "include/private/base/SkTypeTraits.h"
21 
22 #include <atomic>
23 #include <cstddef>
24 #include <cstdint>
25 #include <initializer_list>
26 #include <tuple>
27 #include <type_traits>
28 
29 class SkData;
30 class SkPathRef;
31 class SkRRect;
32 class SkWStream;
33 enum class SkPathConvexity;
34 enum class SkPathFirstDirection;
35 struct SkPathVerbAnalysis;
36 
37 // WIP -- define this locally, and fix call-sites to use SkPathBuilder (skbug.com/9000)
38 //#define SK_HIDE_PATH_EDIT_METHODS
39 
58 class SK_API SkPath {
59 public:
79  static SkPath Make(const SkPoint[], int pointCount,
80  const uint8_t[], int verbCount,
81  const SkScalar[], int conicWeightCount,
82  SkPathFillType, bool isVolatile = false);
83 
85  unsigned startIndex = 0);
87  static SkPath Oval(const SkRect&, SkPathDirection, unsigned startIndex);
88  static SkPath Circle(SkScalar center_x, SkScalar center_y, SkScalar radius,
91  static SkPath RRect(const SkRRect&, SkPathDirection, unsigned startIndex);
92  static SkPath RRect(const SkRect& bounds, SkScalar rx, SkScalar ry,
94 
95  static SkPath Polygon(const SkPoint pts[], int count, bool isClosed,
97  bool isVolatile = false);
98 
99  static SkPath Polygon(const std::initializer_list<SkPoint>& list, bool isClosed,
101  bool isVolatile = false) {
102  return Polygon(list.begin(), SkToInt(list.size()), isClosed, fillType, isVolatile);
103  }
104 
105  static SkPath Line(const SkPoint a, const SkPoint b) {
106  return Polygon({a, b}, false);
107  }
108 
117 
132  SkPath(const SkPath& path);
133 
139 
154  SkPath& operator=(const SkPath& path);
155 
163  friend SK_API bool operator==(const SkPath& a, const SkPath& b);
164 
172  friend bool operator!=(const SkPath& a, const SkPath& b) {
173  return !(a == b);
174  }
175 
188  bool isInterpolatable(const SkPath& compare) const;
189 
211  bool interpolate(const SkPath& ending, SkScalar weight, SkPath* out) const;
212 
217  SkPathFillType getFillType() const { return (SkPathFillType)fFillType; }
218 
223  fFillType = SkToU8(ft);
224  }
225 
231  bool isInverseFillType() const { return SkPathFillType_IsInverse(this->getFillType()); }
232 
237  fFillType ^= 2;
238  }
239 
242  bool isConvex() const;
243 
255  bool isOval(SkRect* bounds) const;
256 
269  bool isRRect(SkRRect* rrect) const;
270 
280 
293 
300  bool isEmpty() const;
301 
310  bool isLastContourClosed() const;
311 
318  bool isFinite() const;
319 
327  bool isVolatile() const {
328  return SkToBool(fIsVolatile);
329  }
330 
347  SkPath& setIsVolatile(bool isVolatile) {
348  fIsVolatile = isVolatile;
349  return *this;
350  }
351 
366  static bool IsLineDegenerate(const SkPoint& p1, const SkPoint& p2, bool exact);
367 
379  static bool IsQuadDegenerate(const SkPoint& p1, const SkPoint& p2,
380  const SkPoint& p3, bool exact);
381 
394  static bool IsCubicDegenerate(const SkPoint& p1, const SkPoint& p2,
395  const SkPoint& p3, const SkPoint& p4, bool exact);
396 
408  bool isLine(SkPoint line[2]) const;
409 
417  int countPoints() const;
418 
428  SkPoint getPoint(int index) const;
429 
440  int getPoints(SkPoint points[], int max) const;
441 
449  int countVerbs() const;
450 
460  int getVerbs(uint8_t verbs[], int max) const;
461 
466  size_t approximateBytesUsed() const;
467 
480  void swap(SkPath& other);
481 
491  const SkRect& getBounds() const;
492 
501  void updateBoundsCache() const {
502  // for now, just calling getBounds() is sufficient
503  this->getBounds();
504  }
505 
524 
538  bool conservativelyContainsRect(const SkRect& rect) const;
539 
548  void incReserve(int extraPtCount);
549 
550 #ifdef SK_HIDE_PATH_EDIT_METHODS
551 private:
552 #endif
553 
563 
569  SkPath& moveTo(const SkPoint& p) {
570  return this->moveTo(p.fX, p.fY);
571  }
572 
585 
599 
609  SkPath& lineTo(const SkPoint& p) {
610  return this->lineTo(p.fX, p.fY);
611  }
612 
630 
648 
661  SkPath& quadTo(const SkPoint& p1, const SkPoint& p2) {
662  return this->quadTo(p1.fX, p1.fY, p2.fX, p2.fY);
663  }
664 
688 
712  SkScalar w);
713 
734  SkPath& conicTo(const SkPoint& p1, const SkPoint& p2, SkScalar w) {
735  return this->conicTo(p1.fX, p1.fY, p2.fX, p2.fY, w);
736  }
737 
764  SkScalar w);
765 
783  SkScalar x3, SkScalar y3);
784 
798  SkPath& cubicTo(const SkPoint& p1, const SkPoint& p2, const SkPoint& p3) {
799  return this->cubicTo(p1.fX, p1.fY, p2.fX, p2.fY, p3.fX, p3.fY);
800  }
801 
823  SkScalar dx3, SkScalar dy3);
824 
842  SkPath& arcTo(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle, bool forceMoveTo);
843 
870 
890  SkPath& arcTo(const SkPoint p1, const SkPoint p2, SkScalar radius) {
891  return this->arcTo(p1.fX, p1.fY, p2.fX, p2.fY, radius);
892  }
893 
898  enum ArcSize {
901  };
902 
927  SkPath& arcTo(SkScalar rx, SkScalar ry, SkScalar xAxisRotate, ArcSize largeArc,
928  SkPathDirection sweep, SkScalar x, SkScalar y);
929 
953  SkPath& arcTo(const SkPoint r, SkScalar xAxisRotate, ArcSize largeArc, SkPathDirection sweep,
954  const SkPoint xy) {
955  return this->arcTo(r.fX, r.fY, xAxisRotate, largeArc, sweep, xy.fX, xy.fY);
956  }
957 
984  SkPath& rArcTo(SkScalar rx, SkScalar ry, SkScalar xAxisRotate, ArcSize largeArc,
985  SkPathDirection sweep, SkScalar dx, SkScalar dy);
986 
1000 
1001 #ifdef SK_HIDE_PATH_EDIT_METHODS
1002 public:
1003 #endif
1004 
1031  static int ConvertConicToQuads(const SkPoint& p0, const SkPoint& p1, const SkPoint& p2,
1032  SkScalar w, SkPoint pts[], int pow2);
1033 
1048  bool isRect(SkRect* rect, bool* isClosed = nullptr, SkPathDirection* direction = nullptr) const;
1049 
1050 #ifdef SK_HIDE_PATH_EDIT_METHODS
1051 private:
1052 #endif
1053 
1079  SkPath& addRect(const SkRect& rect, SkPathDirection dir, unsigned start);
1080 
1082  return this->addRect(rect, dir, 0);
1083  }
1084 
1085  SkPath& addRect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom,
1087  return this->addRect({left, top, right, bottom}, dir, 0);
1088  }
1089 
1102 
1115  SkPath& addOval(const SkRect& oval, SkPathDirection dir, unsigned start);
1116 
1131 
1148  SkPath& addArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle);
1149 
1170 
1180  SkPath& addRoundRect(const SkRect& rect, const SkScalar radii[],
1182 
1197 
1209  SkPath& addRRect(const SkRRect& rrect, SkPathDirection dir, unsigned start);
1210 
1226  SkPath& addPoly(const SkPoint pts[], int count, bool close);
1227 
1238  SkPath& addPoly(const std::initializer_list<SkPoint>& list, bool close) {
1239  return this->addPoly(list.begin(), SkToInt(list.size()), close);
1240  }
1241 
1242 #ifdef SK_HIDE_PATH_EDIT_METHODS
1243 public:
1244 #endif
1245 
1261  };
1262 
1275  SkPath& addPath(const SkPath& src, SkScalar dx, SkScalar dy,
1276  AddPathMode mode = kAppend_AddPathMode);
1277 
1288  SkPath& addPath(const SkPath& src, AddPathMode mode = kAppend_AddPathMode) {
1289  SkMatrix m;
1290  m.reset();
1291  return this->addPath(src, m, mode);
1292  }
1293 
1306  SkPath& addPath(const SkPath& src, const SkMatrix& matrix,
1307  AddPathMode mode = kAppend_AddPathMode);
1308 
1318 
1328  void offset(SkScalar dx, SkScalar dy, SkPath* dst) const;
1329 
1335  void offset(SkScalar dx, SkScalar dy) {
1336  this->offset(dx, dy, this);
1337  }
1338 
1350  void transform(const SkMatrix& matrix, SkPath* dst,
1352 
1360  void transform(const SkMatrix& matrix,
1362  this->transform(matrix, this, pc);
1363  }
1364 
1367  SkPath dst;
1368  this->transform(m, &dst, pc);
1369  return dst;
1370  }
1371 
1373  return this->makeTransform(SkMatrix::Scale(sx, sy), SkApplyPerspectiveClip::kNo);
1374  }
1375 
1384  bool getLastPt(SkPoint* lastPt) const;
1385 
1395 
1401  void setLastPt(const SkPoint& p) {
1402  this->setLastPt(p.fX, p.fY);
1403  }
1404 
1410  kLine_SegmentMask = kLine_SkPathSegmentMask,
1411  kQuad_SegmentMask = kQuad_SkPathSegmentMask,
1412  kConic_SegmentMask = kConic_SkPathSegmentMask,
1413  kCubic_SegmentMask = kCubic_SkPathSegmentMask,
1414  };
1415 
1424  uint32_t getSegmentMasks() const;
1425 
1430  enum Verb {
1431  kMove_Verb = static_cast<int>(SkPathVerb::kMove),
1432  kLine_Verb = static_cast<int>(SkPathVerb::kLine),
1433  kQuad_Verb = static_cast<int>(SkPathVerb::kQuad),
1434  kConic_Verb = static_cast<int>(SkPathVerb::kConic),
1435  kCubic_Verb = static_cast<int>(SkPathVerb::kCubic),
1436  kClose_Verb = static_cast<int>(SkPathVerb::kClose),
1437  kDone_Verb = kClose_Verb + 1
1438  };
1439 
1445  class SK_API Iter {
1446  public:
1447 
1456  Iter();
1457 
1468  Iter(const SkPath& path, bool forceClose);
1469 
1479  void setPath(const SkPath& path, bool forceClose);
1480 
1491  Verb next(SkPoint pts[4]);
1492 
1500  SkScalar conicWeight() const { return *fConicWeights; }
1501 
1511  bool isCloseLine() const { return SkToBool(fCloseLine); }
1512 
1521  bool isClosedContour() const;
1522 
1523  private:
1524  const SkPoint* fPts;
1525  const uint8_t* fVerbs;
1526  const uint8_t* fVerbStop;
1527  const SkScalar* fConicWeights;
1528  SkPoint fMoveTo;
1529  SkPoint fLastPt;
1530  bool fForceClose;
1531  bool fNeedClose;
1532  bool fCloseLine;
1533 
1534  Verb autoClose(SkPoint pts[2]);
1535  };
1536 
1537 private:
1544  class RangeIter {
1545  public:
1546  RangeIter() = default;
1547  RangeIter(const uint8_t* verbs, const SkPoint* points, const SkScalar* weights)
1548  : fVerb(verbs), fPoints(points), fWeights(weights) {
1549  SkDEBUGCODE(fInitialPoints = fPoints;)
1550  }
1551  bool operator!=(const RangeIter& that) const {
1552  return fVerb != that.fVerb;
1553  }
1554  bool operator==(const RangeIter& that) const {
1555  return fVerb == that.fVerb;
1556  }
1557  RangeIter& operator++() {
1558  auto verb = static_cast<SkPathVerb>(*fVerb++);
1559  fPoints += pts_advance_after_verb(verb);
1560  if (verb == SkPathVerb::kConic) {
1561  ++fWeights;
1562  }
1563  return *this;
1564  }
1565  RangeIter operator++(int) {
1566  RangeIter copy = *this;
1567  this->operator++();
1568  return copy;
1569  }
1570  SkPathVerb peekVerb() const {
1571  return static_cast<SkPathVerb>(*fVerb);
1572  }
1573  std::tuple<SkPathVerb, const SkPoint*, const SkScalar*> operator*() const {
1574  SkPathVerb verb = this->peekVerb();
1575  // We provide the starting point for beziers by peeking backwards from the current
1576  // point, which works fine as long as there is always a kMove before any geometry.
1577  // (SkPath::injectMoveToIfNeeded should have guaranteed this to be the case.)
1578  int backset = pts_backset_for_verb(verb);
1579  SkASSERT(fPoints + backset >= fInitialPoints);
1580  return {verb, fPoints + backset, fWeights};
1581  }
1582  private:
1583  constexpr static int pts_advance_after_verb(SkPathVerb verb) {
1584  switch (verb) {
1585  case SkPathVerb::kMove: return 1;
1586  case SkPathVerb::kLine: return 1;
1587  case SkPathVerb::kQuad: return 2;
1588  case SkPathVerb::kConic: return 2;
1589  case SkPathVerb::kCubic: return 3;
1590  case SkPathVerb::kClose: return 0;
1591  }
1592  SkUNREACHABLE;
1593  }
1594  constexpr static int pts_backset_for_verb(SkPathVerb verb) {
1595  switch (verb) {
1596  case SkPathVerb::kMove: return 0;
1597  case SkPathVerb::kLine: return -1;
1598  case SkPathVerb::kQuad: return -1;
1599  case SkPathVerb::kConic: return -1;
1600  case SkPathVerb::kCubic: return -1;
1601  case SkPathVerb::kClose: return -1;
1602  }
1603  SkUNREACHABLE;
1604  }
1605  const uint8_t* fVerb = nullptr;
1606  const SkPoint* fPoints = nullptr;
1607  const SkScalar* fWeights = nullptr;
1608  SkDEBUGCODE(const SkPoint* fInitialPoints = nullptr;)
1609  };
1610 public:
1611 
1615  class SK_API RawIter {
1616  public:
1617 
1623  RawIter() {}
1624 
1630  RawIter(const SkPath& path) {
1631  setPath(path);
1632  }
1633 
1639  void setPath(const SkPath&);
1640 
1648  Verb next(SkPoint[4]);
1649 
1654  Verb peek() const {
1655  return (fIter != fEnd) ? static_cast<Verb>(std::get<0>(*fIter)) : kDone_Verb;
1656  }
1657 
1666  return fConicWeight;
1667  }
1668 
1669  private:
1670  RangeIter fIter;
1671  RangeIter fEnd;
1672  SkScalar fConicWeight = 0;
1673  friend class SkPath;
1674 
1675  };
1676 
1686  bool contains(SkScalar x, SkScalar y) const;
1687 
1697  void dump(SkWStream* stream, bool dumpAsHex) const;
1698 
1699  void dump() const { this->dump(nullptr, false); }
1700  void dumpHex() const { this->dump(nullptr, true); }
1701 
1702  // Like dump(), but outputs for the SkPath::Make() factory
1703  void dumpArrays(SkWStream* stream, bool dumpAsHex) const;
1704  void dumpArrays() const { this->dumpArrays(nullptr, false); }
1705 
1720  size_t writeToMemory(void* buffer) const;
1721 
1735 
1751  size_t readFromMemory(const void* buffer, size_t length);
1752 
1766  uint32_t getGenerationID() const;
1767 
1774  bool isValid() const;
1775 
1776  using sk_is_trivially_relocatable = std::true_type;
1777 
1778 private:
1779  SkPath(sk_sp<SkPathRef>, SkPathFillType, bool isVolatile, SkPathConvexity,
1780  SkPathFirstDirection firstDirection);
1781 
1782  sk_sp<SkPathRef> fPathRef;
1783  int fLastMoveToIndex;
1784  mutable std::atomic<uint8_t> fConvexity; // SkPathConvexity
1785  mutable std::atomic<uint8_t> fFirstDirection; // SkPathFirstDirection
1786  uint8_t fFillType : 2;
1787  uint8_t fIsVolatile : 1;
1788 
1789  static_assert(::sk_is_trivially_relocatable<decltype(fPathRef)>::value);
1790 
1795  void resetFields();
1796 
1801  void copyFields(const SkPath& that);
1802 
1803  size_t writeToMemoryAsRRect(void* buffer) const;
1804  size_t readAsRRect(const void*, size_t);
1805  size_t readFromMemory_EQ4Or5(const void*, size_t);
1806 
1807  friend class Iter;
1808  friend class SkPathPriv;
1809  friend class SkPathStroker;
1810 
1811  /* Append, in reverse order, the first contour of path, ignoring path's
1812  last point. If no moveTo() call has been made for this contour, the
1813  first point is automatically set to (0,0).
1814  */
1815  SkPath& reversePathTo(const SkPath&);
1816 
1817  // called before we add points for lineTo, quadTo, cubicTo, checking to see
1818  // if we need to inject a leading moveTo first
1819  //
1820  // SkPath path; path.lineTo(...); <--- need a leading moveTo(0, 0)
1821  // SkPath path; ... path.close(); path.lineTo(...) <-- need a moveTo(previous moveTo)
1822  //
1823  inline void injectMoveToIfNeeded();
1824 
1825  inline bool hasOnlyMoveTos() const;
1826 
1827  SkPathConvexity computeConvexity() const;
1828 
1829  bool isValidImpl() const;
1833 #ifdef SK_DEBUG
1834  void validate() const;
1835  void validateRef() const;
1836 #endif
1837 
1838  // called by stroker to see if all points (in the last contour) are equal and worthy of a cap
1839  bool isZeroLengthSincePoint(int startPtIndex) const;
1840 
1844  bool hasComputedBounds() const;
1845 
1846  // 'rect' needs to be sorted
1847  void setBounds(const SkRect& rect);
1848 
1849  void setPt(int index, SkScalar x, SkScalar y);
1850 
1851  SkPath& dirtyAfterEdit();
1852 
1853  // Bottlenecks for working with fConvexity and fFirstDirection.
1854  // Notice the setters are const... these are mutable atomic fields.
1855  void setConvexity(SkPathConvexity) const;
1856 
1857  void setFirstDirection(SkPathFirstDirection) const;
1858  SkPathFirstDirection getFirstDirection() const;
1859 
1863  SkPathConvexity getConvexity() const;
1864 
1865  SkPathConvexity getConvexityOrUnknown() const;
1866 
1867  // Compares the cached value with a freshly computed one (computeConvexity())
1868  bool isConvexityAccurate() const;
1869 
1876  void setConvexity(SkPathConvexity convexity);
1877 
1884  void shrinkToFit();
1885 
1886  // Creates a new Path after the supplied arguments have been validated by
1887  // sk_path_analyze_verbs().
1888  static SkPath MakeInternal(const SkPathVerbAnalysis& analsis,
1889  const SkPoint points[],
1890  const uint8_t verbs[],
1891  int verbCount,
1892  const SkScalar conics[],
1893  SkPathFillType fillType,
1894  bool isVolatile);
1895 
1896  friend class SkAutoPathBoundsUpdate;
1897  friend class SkAutoDisableOvalCheck;
1898  friend class SkAutoDisableDirectionCheck;
1899  friend class SkPathBuilder;
1900  friend class SkPathEdgeIter;
1901  friend class SkPathWriter;
1902  friend class SkOpBuilder;
1903  friend class SkBench_AddPathTest; // perf test reversePathTo
1904  friend class PathTest_Private; // unit test reversePathTo
1905  friend class ForceIsRRect_Private; // unit test isRRect
1906  friend class FuzzPath; // for legacy access to validateRef
1907 };
1908 
1909 #endif
SkApplyPerspectiveClip
When we transform points through a matrix containing perspective (the bottom row is something other t...
Definition: SkMatrix.h:34
@ kYes
Do pre-clip the geometry before applying the (perspective) matrix.
@ kNo
Don't pre-clip the geometry before applying the (perspective) matrix.
@ kCubic_SkPathSegmentMask
Definition: SkPathTypes.h:45
@ kConic_SkPathSegmentMask
Definition: SkPathTypes.h:44
@ kQuad_SkPathSegmentMask
Definition: SkPathTypes.h:43
@ kLine_SkPathSegmentMask
Definition: SkPathTypes.h:42
static bool SkPathFillType_IsInverse(SkPathFillType ft)
Definition: SkPathTypes.h:26
SkPathDirection
Definition: SkPathTypes.h:34
@ kCW
clockwise direction for adding closed contours
SkPathFillType
Definition: SkPathTypes.h:11
@ kWinding
Specifies that "inside" is computed by a non-zero sum of signed edge crossings.
SkPathVerb
Definition: SkPathTypes.h:48
@ kClose
SkPath::RawIter returns 0 points.
@ kCubic
SkPath::RawIter returns 4 points.
@ kConic
SkPath::RawIter returns 3 points + 1 weight.
@ kQuad
SkPath::RawIter returns 3 points.
@ kMove
SkPath::RawIter returns 1 point.
@ kLine
SkPath::RawIter returns 2 points.
bool operator!=(const sk_sp< T > &a, const sk_sp< U > &b)
Definition: SkRefCnt.h:355
bool operator==(const sk_sp< T > &a, const sk_sp< U > &b)
Definition: SkRefCnt.h:345
float SkScalar
Definition: SkScalar.h:14
SkData holds an immutable data buffer.
Definition: SkData.h:25
SkMatrix holds a 3x3 matrix for transforming coordinates.
Definition: SkMatrix.h:53
SkMatrix & reset()
Sets SkMatrix to identity; which has no effect on mapped SkPoint.
static SkMatrix Scale(SkScalar sx, SkScalar sy)
Sets SkMatrix to scale by (sx, sy).
Definition: SkMatrix.h:74
Perform a series of path operations, optimized for unioning many paths together.
Definition: SkPathOps.h:86
Definition: SkPathBuilder.h:25
Iterates through verb array, and associated SkPoint array and conic weight.
Definition: SkPath.h:1445
bool isClosedContour() const
Returns true if subsequent calls to next() return kClose_Verb before returning kMove_Verb.
void setPath(const SkPath &path, bool forceClose)
Sets SkPath::Iter to return elements of verb array, SkPoint array, and conic weight in path.
Verb next(SkPoint pts[4])
Returns next SkPath::Verb in verb array, and advances SkPath::Iter.
SkScalar conicWeight() const
Returns conic weight if next() returned kConic_Verb.
Definition: SkPath.h:1500
Iter()
Initializes SkPath::Iter with an empty SkPath.
Iter(const SkPath &path, bool forceClose)
Sets SkPath::Iter to return elements of verb array, SkPoint array, and conic weight in path.
bool isCloseLine() const
Returns true if last kLine_Verb returned by next() was generated by kClose_Verb.
Definition: SkPath.h:1511
Use Iter instead.
Definition: SkPath.h:1615
SkScalar conicWeight() const
Returns conic weight if next() returned kConic_Verb.
Definition: SkPath.h:1665
RawIter(const SkPath &path)
Sets RawIter to return elements of verb array, SkPoint array, and conic weight in path.
Definition: SkPath.h:1630
RawIter()
Initializes RawIter with an empty SkPath.
Definition: SkPath.h:1623
Verb peek() const
Returns next SkPath::Verb, but does not advance RawIter.
Definition: SkPath.h:1654
Verb next(SkPoint[4])
Returns next SkPath::Verb in verb array, and advances RawIter.
void setPath(const SkPath &)
Sets SkPath::Iter to return elements of verb array, SkPoint array, and conic weight in path.
SkPath contain geometry.
Definition: SkPath.h:58
SegmentMask
Definition: SkPath.h:1409
bool isEmpty() const
Returns if SkPath is empty.
size_t readFromMemory(const void *buffer, size_t length)
Initializes SkPath from buffer of size length.
void dumpArrays() const
Definition: SkPath.h:1704
bool isInverseFillType() const
Returns if FillType describes area outside SkPath geometry.
Definition: SkPath.h:231
uint32_t getGenerationID() const
(See Skia bug 1762.) Returns a non-zero, globally unique value.
SkPath & operator=(const SkPath &path)
Constructs a copy of an existing path.
static SkPath Oval(const SkRect &, SkPathDirection=SkPathDirection::kCW)
SkPath & conicTo(const SkPoint &p1, const SkPoint &p2, SkScalar w)
Adds conic from last point towards SkPoint p1, to SkPoint p2, weighted by w.
Definition: SkPath.h:734
SkPath & rMoveTo(SkScalar dx, SkScalar dy)
Adds beginning of contour relative to last point.
void offset(SkScalar dx, SkScalar dy, SkPath *dst) const
Offsets SkPoint array by (dx, dy).
SkPath & rQuadTo(SkScalar dx1, SkScalar dy1, SkScalar dx2, SkScalar dy2)
Adds quad from last point towards vector (dx1, dy1), to vector (dx2, dy2).
int countPoints() const
Returns the number of points in SkPath.
SkPath()
Constructs an empty SkPath.
bool conservativelyContainsRect(const SkRect &rect) const
Returns true if rect is contained by SkPath.
void setLastPt(SkScalar x, SkScalar y)
Sets last point to (x, y).
static bool IsQuadDegenerate(const SkPoint &p1, const SkPoint &p2, const SkPoint &p3, bool exact)
Tests if quad is degenerate.
bool isFinite() const
Returns true for finite SkPoint array values between negative SK_ScalarMax and positive SK_ScalarMax.
SkPath & lineTo(const SkPoint &p)
Adds line from last point to SkPoint p.
Definition: SkPath.h:609
SkPoint getPoint(int index) const
Returns SkPoint at index in SkPoint array.
SkPath & arcTo(SkScalar rx, SkScalar ry, SkScalar xAxisRotate, ArcSize largeArc, SkPathDirection sweep, SkScalar x, SkScalar y)
Appends arc to SkPath.
bool isLine(SkPoint line[2]) const
Returns true if SkPath contains only one line; SkPath::Verb array has two entries: kMove_Verb,...
friend SK_API bool operator==(const SkPath &a, const SkPath &b)
Compares a and b; returns true if SkPath::FillType, verb array, SkPoint array, and weights are equiva...
SkPath & addCircle(SkScalar x, SkScalar y, SkScalar radius, SkPathDirection dir=SkPathDirection::kCW)
Adds circle centered at (x, y) of size radius to SkPath, appending kMove_Verb, four kConic_Verb,...
void incReserve(int extraPtCount)
Grows SkPath verb array and SkPoint array to contain extraPtCount additional SkPoint.
SkPath & addRect(const SkRect &rect, SkPathDirection dir=SkPathDirection::kCW)
Definition: SkPath.h:1081
bool getLastPt(SkPoint *lastPt) const
Returns last point on SkPath in lastPt.
SkPath & addOval(const SkRect &oval, SkPathDirection dir, unsigned start)
Adds oval to SkPath, appending kMove_Verb, four kConic_Verb, and kClose_Verb.
static SkPath Circle(SkScalar center_x, SkScalar center_y, SkScalar radius, SkPathDirection dir=SkPathDirection::kCW)
SkPath & addRect(const SkRect &rect, SkPathDirection dir, unsigned start)
Adds a new contour to the path, defined by the rect, and wound in the specified direction.
SkPath & rCubicTo(SkScalar dx1, SkScalar dy1, SkScalar dx2, SkScalar dy2, SkScalar dx3, SkScalar dy3)
Adds cubic from last point towards vector (dx1, dy1), then towards vector (dx2, dy2),...
SkPath & close()
Appends kClose_Verb to SkPath.
SkPath & addPath(const SkPath &src, SkScalar dx, SkScalar dy, AddPathMode mode=kAppend_AddPathMode)
Appends src to SkPath, offset by (dx, dy).
SkPathFillType getFillType() const
Returns SkPathFillType, the rule used to fill SkPath.
Definition: SkPath.h:217
int getPoints(SkPoint points[], int max) const
Returns number of points in SkPath.
void setFillType(SkPathFillType ft)
Sets FillType, the rule used to fill SkPath.
Definition: SkPath.h:222
SkPath & addRRect(const SkRRect &rrect, SkPathDirection dir, unsigned start)
Adds rrect to SkPath, creating a new closed contour.
SkPath & rLineTo(SkScalar dx, SkScalar dy)
Adds line from last point to vector (dx, dy).
SkPath & arcTo(const SkRect &oval, SkScalar startAngle, SkScalar sweepAngle, bool forceMoveTo)
Appends arc to SkPath.
SkPath & lineTo(SkScalar x, SkScalar y)
Adds line from last point to (x, y).
friend bool operator!=(const SkPath &a, const SkPath &b)
Compares a and b; returns true if SkPath::FillType, verb array, SkPoint array, and weights are not eq...
Definition: SkPath.h:172
static SkPath Make(const SkPoint[], int pointCount, const uint8_t[], int verbCount, const SkScalar[], int conicWeightCount, SkPathFillType, bool isVolatile=false)
Create a new path with the specified segments.
void toggleInverseFillType()
Replaces FillType with its inverse.
Definition: SkPath.h:236
SkPath & setIsVolatile(bool isVolatile)
Specifies whether SkPath is volatile; whether it will be altered or discarded by the caller after it ...
Definition: SkPath.h:347
SkRect computeTightBounds() const
Returns minimum and maximum axes values of the lines and curves in SkPath.
size_t approximateBytesUsed() const
Returns the approximate byte size of the SkPath in memory.
SkPath & addArc(const SkRect &oval, SkScalar startAngle, SkScalar sweepAngle)
Appends arc to SkPath, as the start of new contour.
void offset(SkScalar dx, SkScalar dy)
Offsets SkPoint array by (dx, dy).
Definition: SkPath.h:1335
SkPath & reset()
Sets SkPath to its initial state.
~SkPath()
Releases ownership of any shared data and deletes data if SkPath is sole owner.
void updateBoundsCache() const
Updates internal bounds so that subsequent calls to getBounds() are instantaneous.
Definition: SkPath.h:501
bool isVolatile() const
Returns true if the path is volatile; it will not be altered or discarded by the caller after it is d...
Definition: SkPath.h:327
SkPath & moveTo(SkScalar x, SkScalar y)
Adds beginning of contour at SkPoint (x, y).
void dump() const
Definition: SkPath.h:1699
SkPath & addOval(const SkRect &oval, SkPathDirection dir=SkPathDirection::kCW)
Adds oval to path, appending kMove_Verb, four kConic_Verb, and kClose_Verb.
bool isInterpolatable(const SkPath &compare) const
Returns true if SkPath contain equal verbs and equal weights.
bool interpolate(const SkPath &ending, SkScalar weight, SkPath *out) const
Interpolates between SkPath with SkPoint array of equal size.
std::true_type sk_is_trivially_relocatable
Definition: SkPath.h:1776
SkPath makeScale(SkScalar sx, SkScalar sy)
Definition: SkPath.h:1372
static SkPath Polygon(const std::initializer_list< SkPoint > &list, bool isClosed, SkPathFillType fillType=SkPathFillType::kWinding, bool isVolatile=false)
Definition: SkPath.h:99
void setLastPt(const SkPoint &p)
Sets the last point on the path.
Definition: SkPath.h:1401
SkPath & moveTo(const SkPoint &p)
Adds beginning of contour at SkPoint p.
Definition: SkPath.h:569
static int ConvertConicToQuads(const SkPoint &p0, const SkPoint &p1, const SkPoint &p2, SkScalar w, SkPoint pts[], int pow2)
Approximates conic with quad array.
SkPath & cubicTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar x3, SkScalar y3)
Adds cubic from last point towards (x1, y1), then towards (x2, y2), ending at (x3,...
SkPath & rArcTo(SkScalar rx, SkScalar ry, SkScalar xAxisRotate, ArcSize largeArc, SkPathDirection sweep, SkScalar dx, SkScalar dy)
Appends arc to SkPath, relative to last SkPath SkPoint.
bool isOval(SkRect *bounds) const
Returns true if this path is recognized as an oval or circle.
void transform(const SkMatrix &matrix, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes)
Transforms verb array, SkPoint array, and weight by matrix.
Definition: SkPath.h:1360
SkPath & rewind()
Sets SkPath to its initial state, preserving internal storage.
SkPath & addRoundRect(const SkRect &rect, SkScalar rx, SkScalar ry, SkPathDirection dir=SkPathDirection::kCW)
Appends SkRRect to SkPath, creating a new closed contour.
static bool IsCubicDegenerate(const SkPoint &p1, const SkPoint &p2, const SkPoint &p3, const SkPoint &p4, bool exact)
Tests if cubic is degenerate.
int getVerbs(uint8_t verbs[], int max) const
Returns the number of verbs in the path.
SkPath & cubicTo(const SkPoint &p1, const SkPoint &p2, const SkPoint &p3)
Adds cubic from last point towards SkPoint p1, then towards SkPoint p2, ending at SkPoint p3.
Definition: SkPath.h:798
SkPath & quadTo(const SkPoint &p1, const SkPoint &p2)
Adds quad from last point towards SkPoint p1, to SkPoint p2.
Definition: SkPath.h:661
ArcSize
Definition: SkPath.h:898
@ kSmall_ArcSize
smaller of arc pair
Definition: SkPath.h:899
@ kLarge_ArcSize
larger of arc pair
Definition: SkPath.h:900
static SkPath RRect(const SkRRect &, SkPathDirection dir=SkPathDirection::kCW)
SkPath & conicTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar w)
Adds conic from last point towards (x1, y1), to (x2, y2), weighted by w.
SkPath & addPath(const SkPath &src, AddPathMode mode=kAppend_AddPathMode)
Appends src to SkPath.
Definition: SkPath.h:1288
bool isConvex() const
Returns true if the path is convex.
SkPath & arcTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar radius)
Appends arc to SkPath, after appending line if needed.
SkPath(const SkPath &path)
Constructs a copy of an existing path.
SkPath & rConicTo(SkScalar dx1, SkScalar dy1, SkScalar dx2, SkScalar dy2, SkScalar w)
Adds conic from last point towards vector (dx1, dy1), to vector (dx2, dy2), weighted by w.
sk_sp< SkData > serialize() const
Writes SkPath to buffer, returning the buffer written to, wrapped in SkData.
SkPath & reverseAddPath(const SkPath &src)
Appends src to SkPath, from back to front.
SkPath & addPoly(const SkPoint pts[], int count, bool close)
Adds contour created from line array, adding (count - 1) line segments.
AddPathMode
Definition: SkPath.h:1250
@ kExtend_AddPathMode
Extends the last contour of the destination path with the first countour of the source path,...
Definition: SkPath.h:1260
@ kAppend_AddPathMode
Contours are appended to the destination path as new contours.
Definition: SkPath.h:1253
uint32_t getSegmentMasks() const
Returns a mask, where each set bit corresponds to a SegmentMask constant if SkPath contains one or mo...
void dumpHex() const
Definition: SkPath.h:1700
SkPath & arcTo(const SkPoint r, SkScalar xAxisRotate, ArcSize largeArc, SkPathDirection sweep, const SkPoint xy)
Appends arc to SkPath.
Definition: SkPath.h:953
size_t writeToMemory(void *buffer) const
Writes SkPath to buffer, returning the number of bytes written.
static SkPath Oval(const SkRect &, SkPathDirection, unsigned startIndex)
void dumpArrays(SkWStream *stream, bool dumpAsHex) const
SkPath & addRect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom, SkPathDirection dir=SkPathDirection::kCW)
Definition: SkPath.h:1085
int countVerbs() const
Returns the number of verbs: kMove_Verb, kLine_Verb, kQuad_Verb, kConic_Verb, kCubic_Verb,...
Verb
Definition: SkPath.h:1430
const SkRect & getBounds() const
Returns minimum and maximum axes values of SkPoint array.
bool isLastContourClosed() const
Returns if contour is closed.
SkPath & addPoly(const std::initializer_list< SkPoint > &list, bool close)
Adds contour created from list.
Definition: SkPath.h:1238
static SkPath Polygon(const SkPoint pts[], int count, bool isClosed, SkPathFillType=SkPathFillType::kWinding, bool isVolatile=false)
bool isValid() const
Returns if SkPath data is consistent.
void swap(SkPath &other)
Exchanges the verb array, SkPoint array, weights, and SkPath::FillType with other.
static bool IsLineDegenerate(const SkPoint &p1, const SkPoint &p2, bool exact)
Tests if line between SkPoint pair is degenerate.
bool isRect(SkRect *rect, bool *isClosed=nullptr, SkPathDirection *direction=nullptr) const
Returns true if SkPath is equivalent to SkRect when filled.
SkPath & quadTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2)
Adds quad from last point towards (x1, y1), to (x2, y2).
void transform(const SkMatrix &matrix, SkPath *dst, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
Transforms verb array, SkPoint array, and weight by matrix.
void dump(SkWStream *stream, bool dumpAsHex) const
Writes text representation of SkPath to stream.
SkPath & addRoundRect(const SkRect &rect, const SkScalar radii[], SkPathDirection dir=SkPathDirection::kCW)
Appends SkRRect to SkPath, creating a new closed contour.
bool isRRect(SkRRect *rrect) const
Returns true if path is representable as SkRRect.
static SkPath RRect(const SkRRect &, SkPathDirection, unsigned startIndex)
SkPath & arcTo(const SkPoint p1, const SkPoint p2, SkScalar radius)
Appends arc to SkPath, after appending line if needed.
Definition: SkPath.h:890
SkPath & addPath(const SkPath &src, const SkMatrix &matrix, AddPathMode mode=kAppend_AddPathMode)
Appends src to SkPath, transformed by matrix.
SkPath makeTransform(const SkMatrix &m, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
Definition: SkPath.h:1365
SkPath & addRRect(const SkRRect &rrect, SkPathDirection dir=SkPathDirection::kCW)
Adds rrect to SkPath, creating a new closed contour.
static SkPath Rect(const SkRect &, SkPathDirection=SkPathDirection::kCW, unsigned startIndex=0)
bool contains(SkScalar x, SkScalar y) const
Returns true if the point (x, y) is contained by SkPath, taking into account FillType.
static SkPath Line(const SkPoint a, const SkPoint b)
Definition: SkPath.h:105
static SkPath RRect(const SkRect &bounds, SkScalar rx, SkScalar ry, SkPathDirection dir=SkPathDirection::kCW)
SkRRect describes a rounded rectangle with a bounds and a pair of radii for each corner.
Definition: SkRRect.h:35
Definition: SkStream.h:218
SkRect holds four float coordinates describing the upper and lower bounds of a rectangle.
Definition: SkRect.h:582