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/private/SkPathRef.h"
14 #include "include/private/SkTo.h"
15 
16 #include <initializer_list>
17 
18 class SkAutoPathBoundsUpdate;
19 class SkData;
20 class SkRRect;
21 class SkWStream;
22 
23 // WIP -- define this locally, and fix call-sites to use SkPathBuilder (skbug.com/9000)
24 //#define SK_HIDE_PATH_EDIT_METHODS
25 
44 class SK_API SkPath {
45 public:
65  static SkPath Make(const SkPoint[], int pointCount,
66  const uint8_t[], int verbCount,
67  const SkScalar[], int conicWeightCount,
68  SkPathFillType, bool isVolatile = false);
69 
71  unsigned startIndex = 0);
73  static SkPath Oval(const SkRect&, SkPathDirection, unsigned startIndex);
74  static SkPath Circle(SkScalar center_x, SkScalar center_y, SkScalar radius,
77  static SkPath RRect(const SkRRect&, SkPathDirection, unsigned startIndex);
78  static SkPath RRect(const SkRect& bounds, SkScalar rx, SkScalar ry,
80 
81  static SkPath Polygon(const SkPoint pts[], int count, bool isClosed,
83  bool isVolatile = false);
84 
85  static SkPath Polygon(const std::initializer_list<SkPoint>& list, bool isClosed,
87  bool isVolatile = false) {
88  return Polygon(list.begin(), SkToInt(list.size()), isClosed, fillType, isVolatile);
89  }
90 
91  static SkPath Line(const SkPoint a, const SkPoint b) {
92  return Polygon({a, b}, false);
93  }
94 
103 
118  SkPath(const SkPath& path);
119 
125 
140  SkPath& operator=(const SkPath& path);
141 
149  friend SK_API bool operator==(const SkPath& a, const SkPath& b);
150 
158  friend bool operator!=(const SkPath& a, const SkPath& b) {
159  return !(a == b);
160  }
161 
174  bool isInterpolatable(const SkPath& compare) const;
175 
197  bool interpolate(const SkPath& ending, SkScalar weight, SkPath* out) const;
198 
203  SkPathFillType getFillType() const { return (SkPathFillType)fFillType; }
204 
209  fFillType = SkToU8(ft);
210  }
211 
217  bool isInverseFillType() const { return SkPathFillType_IsInverse(this->getFillType()); }
218 
223  fFillType ^= 2;
224  }
225 
228  bool isConvex() const {
229  return SkPathConvexity::kConvex == this->getConvexity();
230  }
231 
243  bool isOval(SkRect* bounds) const;
244 
257  bool isRRect(SkRRect* rrect) const;
258 
268 
281 
288  bool isEmpty() const {
289  SkDEBUGCODE(this->validate();)
290  return 0 == fPathRef->countVerbs();
291  }
292 
301  bool isLastContourClosed() const;
302 
309  bool isFinite() const {
310  SkDEBUGCODE(this->validate();)
311  return fPathRef->isFinite();
312  }
313 
321  bool isVolatile() const {
322  return SkToBool(fIsVolatile);
323  }
324 
341  SkPath& setIsVolatile(bool isVolatile) {
342  fIsVolatile = isVolatile;
343  return *this;
344  }
345 
360  static bool IsLineDegenerate(const SkPoint& p1, const SkPoint& p2, bool exact);
361 
373  static bool IsQuadDegenerate(const SkPoint& p1, const SkPoint& p2,
374  const SkPoint& p3, bool exact);
375 
388  static bool IsCubicDegenerate(const SkPoint& p1, const SkPoint& p2,
389  const SkPoint& p3, const SkPoint& p4, bool exact);
390 
402  bool isLine(SkPoint line[2]) const;
403 
411  int countPoints() const;
412 
422  SkPoint getPoint(int index) const;
423 
434  int getPoints(SkPoint points[], int max) const;
435 
443  int countVerbs() const;
444 
454  int getVerbs(uint8_t verbs[], int max) const;
455 
460  size_t approximateBytesUsed() const;
461 
474  void swap(SkPath& other);
475 
485  const SkRect& getBounds() const {
486  return fPathRef->getBounds();
487  }
488 
497  void updateBoundsCache() const {
498  // for now, just calling getBounds() is sufficient
499  this->getBounds();
500  }
501 
520 
534  bool conservativelyContainsRect(const SkRect& rect) const;
535 
544  void incReserve(int extraPtCount);
545 
546 #ifdef SK_HIDE_PATH_EDIT_METHODS
547 private:
548 #endif
549 
559 
565  SkPath& moveTo(const SkPoint& p) {
566  return this->moveTo(p.fX, p.fY);
567  }
568 
581 
595 
605  SkPath& lineTo(const SkPoint& p) {
606  return this->lineTo(p.fX, p.fY);
607  }
608 
626 
644 
657  SkPath& quadTo(const SkPoint& p1, const SkPoint& p2) {
658  return this->quadTo(p1.fX, p1.fY, p2.fX, p2.fY);
659  }
660 
684 
708  SkScalar w);
709 
730  SkPath& conicTo(const SkPoint& p1, const SkPoint& p2, SkScalar w) {
731  return this->conicTo(p1.fX, p1.fY, p2.fX, p2.fY, w);
732  }
733 
760  SkScalar w);
761 
779  SkScalar x3, SkScalar y3);
780 
794  SkPath& cubicTo(const SkPoint& p1, const SkPoint& p2, const SkPoint& p3) {
795  return this->cubicTo(p1.fX, p1.fY, p2.fX, p2.fY, p3.fX, p3.fY);
796  }
797 
819  SkScalar dx3, SkScalar dy3);
820 
838  SkPath& arcTo(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle, bool forceMoveTo);
839 
866 
886  SkPath& arcTo(const SkPoint p1, const SkPoint p2, SkScalar radius) {
887  return this->arcTo(p1.fX, p1.fY, p2.fX, p2.fY, radius);
888  }
889 
894  enum ArcSize {
897  };
898 
923  SkPath& arcTo(SkScalar rx, SkScalar ry, SkScalar xAxisRotate, ArcSize largeArc,
924  SkPathDirection sweep, SkScalar x, SkScalar y);
925 
949  SkPath& arcTo(const SkPoint r, SkScalar xAxisRotate, ArcSize largeArc, SkPathDirection sweep,
950  const SkPoint xy) {
951  return this->arcTo(r.fX, r.fY, xAxisRotate, largeArc, sweep, xy.fX, xy.fY);
952  }
953 
980  SkPath& rArcTo(SkScalar rx, SkScalar ry, SkScalar xAxisRotate, ArcSize largeArc,
981  SkPathDirection sweep, SkScalar dx, SkScalar dy);
982 
996 
997 #ifdef SK_HIDE_PATH_EDIT_METHODS
998 public:
999 #endif
1000 
1027  static int ConvertConicToQuads(const SkPoint& p0, const SkPoint& p1, const SkPoint& p2,
1028  SkScalar w, SkPoint pts[], int pow2);
1029 
1044  bool isRect(SkRect* rect, bool* isClosed = nullptr, SkPathDirection* direction = nullptr) const;
1045 
1046 #ifdef SK_HIDE_PATH_EDIT_METHODS
1047 private:
1048 #endif
1049 
1075  SkPath& addRect(const SkRect& rect, SkPathDirection dir, unsigned start);
1076 
1078  return this->addRect(rect, dir, 0);
1079  }
1080 
1081  SkPath& addRect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom,
1083  return this->addRect({left, top, right, bottom}, dir, 0);
1084  }
1085 
1098 
1111  SkPath& addOval(const SkRect& oval, SkPathDirection dir, unsigned start);
1112 
1127 
1144  SkPath& addArc(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle);
1145 
1166 
1176  SkPath& addRoundRect(const SkRect& rect, const SkScalar radii[],
1178 
1193 
1205  SkPath& addRRect(const SkRRect& rrect, SkPathDirection dir, unsigned start);
1206 
1222  SkPath& addPoly(const SkPoint pts[], int count, bool close);
1223 
1234  SkPath& addPoly(const std::initializer_list<SkPoint>& list, bool close) {
1235  return this->addPoly(list.begin(), SkToInt(list.size()), close);
1236  }
1237 
1238 #ifdef SK_HIDE_PATH_EDIT_METHODS
1239 public:
1240 #endif
1241 
1249  };
1250 
1263  SkPath& addPath(const SkPath& src, SkScalar dx, SkScalar dy,
1264  AddPathMode mode = kAppend_AddPathMode);
1265 
1276  SkPath& addPath(const SkPath& src, AddPathMode mode = kAppend_AddPathMode) {
1277  SkMatrix m;
1278  m.reset();
1279  return this->addPath(src, m, mode);
1280  }
1281 
1294  SkPath& addPath(const SkPath& src, const SkMatrix& matrix,
1295  AddPathMode mode = kAppend_AddPathMode);
1296 
1306 
1316  void offset(SkScalar dx, SkScalar dy, SkPath* dst) const;
1317 
1323  void offset(SkScalar dx, SkScalar dy) {
1324  this->offset(dx, dy, this);
1325  }
1326 
1338  void transform(const SkMatrix& matrix, SkPath* dst,
1340 
1348  void transform(const SkMatrix& matrix,
1350  this->transform(matrix, this, pc);
1351  }
1352 
1355  SkPath dst;
1356  this->transform(m, &dst, pc);
1357  return dst;
1358  }
1359 
1361  return this->makeTransform(SkMatrix::Scale(sx, sy), SkApplyPerspectiveClip::kNo);
1362  }
1363 
1372  bool getLastPt(SkPoint* lastPt) const;
1373 
1383 
1389  void setLastPt(const SkPoint& p) {
1390  this->setLastPt(p.fX, p.fY);
1391  }
1392 
1398  kLine_SegmentMask = kLine_SkPathSegmentMask,
1399  kQuad_SegmentMask = kQuad_SkPathSegmentMask,
1400  kConic_SegmentMask = kConic_SkPathSegmentMask,
1401  kCubic_SegmentMask = kCubic_SkPathSegmentMask,
1402  };
1403 
1412  uint32_t getSegmentMasks() const { return fPathRef->getSegmentMasks(); }
1413 
1418  enum Verb {
1419  kMove_Verb = static_cast<int>(SkPathVerb::kMove),
1420  kLine_Verb = static_cast<int>(SkPathVerb::kLine),
1421  kQuad_Verb = static_cast<int>(SkPathVerb::kQuad),
1422  kConic_Verb = static_cast<int>(SkPathVerb::kConic),
1423  kCubic_Verb = static_cast<int>(SkPathVerb::kCubic),
1424  kClose_Verb = static_cast<int>(SkPathVerb::kClose),
1425  kDone_Verb = kClose_Verb + 1
1426  };
1427 
1433  class SK_API Iter {
1434  public:
1435 
1444  Iter();
1445 
1456  Iter(const SkPath& path, bool forceClose);
1457 
1467  void setPath(const SkPath& path, bool forceClose);
1468 
1479  Verb next(SkPoint pts[4]);
1480 
1488  SkScalar conicWeight() const { return *fConicWeights; }
1489 
1499  bool isCloseLine() const { return SkToBool(fCloseLine); }
1500 
1509  bool isClosedContour() const;
1510 
1511  private:
1512  const SkPoint* fPts;
1513  const uint8_t* fVerbs;
1514  const uint8_t* fVerbStop;
1515  const SkScalar* fConicWeights;
1516  SkPoint fMoveTo;
1517  SkPoint fLastPt;
1518  bool fForceClose;
1519  bool fNeedClose;
1520  bool fCloseLine;
1521 
1522  Verb autoClose(SkPoint pts[2]);
1523  };
1524 
1525 private:
1532  class RangeIter {
1533  public:
1534  RangeIter() = default;
1535  RangeIter(const uint8_t* verbs, const SkPoint* points, const SkScalar* weights)
1536  : fVerb(verbs), fPoints(points), fWeights(weights) {
1537  SkDEBUGCODE(fInitialPoints = fPoints;)
1538  }
1539  bool operator!=(const RangeIter& that) const {
1540  return fVerb != that.fVerb;
1541  }
1542  bool operator==(const RangeIter& that) const {
1543  return fVerb == that.fVerb;
1544  }
1545  RangeIter& operator++() {
1546  auto verb = static_cast<SkPathVerb>(*fVerb++);
1547  fPoints += pts_advance_after_verb(verb);
1548  if (verb == SkPathVerb::kConic) {
1549  ++fWeights;
1550  }
1551  return *this;
1552  }
1553  RangeIter operator++(int) {
1554  RangeIter copy = *this;
1555  this->operator++();
1556  return copy;
1557  }
1558  SkPathVerb peekVerb() const {
1559  return static_cast<SkPathVerb>(*fVerb);
1560  }
1561  std::tuple<SkPathVerb, const SkPoint*, const SkScalar*> operator*() const {
1562  SkPathVerb verb = this->peekVerb();
1563  // We provide the starting point for beziers by peeking backwards from the current
1564  // point, which works fine as long as there is always a kMove before any geometry.
1565  // (SkPath::injectMoveToIfNeeded should have guaranteed this to be the case.)
1566  int backset = pts_backset_for_verb(verb);
1567  SkASSERT(fPoints + backset >= fInitialPoints);
1568  return {verb, fPoints + backset, fWeights};
1569  }
1570  private:
1571  constexpr static int pts_advance_after_verb(SkPathVerb verb) {
1572  switch (verb) {
1573  case SkPathVerb::kMove: return 1;
1574  case SkPathVerb::kLine: return 1;
1575  case SkPathVerb::kQuad: return 2;
1576  case SkPathVerb::kConic: return 2;
1577  case SkPathVerb::kCubic: return 3;
1578  case SkPathVerb::kClose: return 0;
1579  }
1580  SkUNREACHABLE;
1581  }
1582  constexpr static int pts_backset_for_verb(SkPathVerb verb) {
1583  switch (verb) {
1584  case SkPathVerb::kMove: return 0;
1585  case SkPathVerb::kLine: return -1;
1586  case SkPathVerb::kQuad: return -1;
1587  case SkPathVerb::kConic: return -1;
1588  case SkPathVerb::kCubic: return -1;
1589  case SkPathVerb::kClose: return -1;
1590  }
1591  SkUNREACHABLE;
1592  }
1593  const uint8_t* fVerb = nullptr;
1594  const SkPoint* fPoints = nullptr;
1595  const SkScalar* fWeights = nullptr;
1596  SkDEBUGCODE(const SkPoint* fInitialPoints = nullptr;)
1597  };
1598 public:
1599 
1603  class SK_API RawIter {
1604  public:
1605 
1611  RawIter() {}
1612 
1618  RawIter(const SkPath& path) {
1619  setPath(path);
1620  }
1621 
1627  void setPath(const SkPath&);
1628 
1637 
1642  Verb peek() const {
1643  return (fIter != fEnd) ? static_cast<Verb>(std::get<0>(*fIter)) : kDone_Verb;
1644  }
1645 
1654  return fConicWeight;
1655  }
1656 
1657  private:
1658  RangeIter fIter;
1659  RangeIter fEnd;
1660  SkScalar fConicWeight = 0;
1661  friend class SkPath;
1662 
1663  };
1664 
1674  bool contains(SkScalar x, SkScalar y) const;
1675 
1685  void dump(SkWStream* stream, bool dumpAsHex) const;
1686 
1687  void dump() const { this->dump(nullptr, false); }
1688  void dumpHex() const { this->dump(nullptr, true); }
1689 
1690  // Like dump(), but outputs for the SkPath::Make() factory
1691  void dumpArrays(SkWStream* stream, bool dumpAsHex) const;
1692  void dumpArrays() const { this->dumpArrays(nullptr, false); }
1693 
1708  size_t writeToMemory(void* buffer) const;
1709 
1723 
1739  size_t readFromMemory(const void* buffer, size_t length);
1740 
1754  uint32_t getGenerationID() const;
1755 
1762  bool isValid() const { return this->isValidImpl() && fPathRef->isValid(); }
1763 
1764 private:
1765  SkPath(sk_sp<SkPathRef>, SkPathFillType, bool isVolatile, SkPathConvexity,
1766  SkPathFirstDirection firstDirection);
1767 
1768  sk_sp<SkPathRef> fPathRef;
1769  int fLastMoveToIndex;
1770  mutable std::atomic<uint8_t> fConvexity; // SkPathConvexity
1771  mutable std::atomic<uint8_t> fFirstDirection; // SkPathFirstDirection
1772  uint8_t fFillType : 2;
1773  uint8_t fIsVolatile : 1;
1774 
1779  void resetFields();
1780 
1785  void copyFields(const SkPath& that);
1786 
1787  size_t writeToMemoryAsRRect(void* buffer) const;
1788  size_t readAsRRect(const void*, size_t);
1789  size_t readFromMemory_EQ4Or5(const void*, size_t);
1790 
1791  friend class Iter;
1792  friend class SkPathPriv;
1793  friend class SkPathStroker;
1794 
1795  /* Append, in reverse order, the first contour of path, ignoring path's
1796  last point. If no moveTo() call has been made for this contour, the
1797  first point is automatically set to (0,0).
1798  */
1799  SkPath& reversePathTo(const SkPath&);
1800 
1801  // called before we add points for lineTo, quadTo, cubicTo, checking to see
1802  // if we need to inject a leading moveTo first
1803  //
1804  // SkPath path; path.lineTo(...); <--- need a leading moveTo(0, 0)
1805  // SkPath path; ... path.close(); path.lineTo(...) <-- need a moveTo(previous moveTo)
1806  //
1807  inline void injectMoveToIfNeeded();
1808 
1809  inline bool hasOnlyMoveTos() const;
1810 
1811  SkPathConvexity computeConvexity() const;
1812 
1816  SkDEBUGCODE(void validate() const { SkASSERT(this->isValidImpl()); } )
1817  bool isValidImpl() const;
1818  SkDEBUGCODE(void validateRef() const { fPathRef->validate(); } )
1819 
1820  // called by stroker to see if all points (in the last contour) are equal and worthy of a cap
1821  bool isZeroLengthSincePoint(int startPtIndex) const;
1822 
1826  bool hasComputedBounds() const {
1827  SkDEBUGCODE(this->validate();)
1828  return fPathRef->hasComputedBounds();
1829  }
1830 
1831 
1832  // 'rect' needs to be sorted
1833  void setBounds(const SkRect& rect) {
1834  SkPathRef::Editor ed(&fPathRef);
1835 
1836  ed.setBounds(rect);
1837  }
1838 
1839  void setPt(int index, SkScalar x, SkScalar y);
1840 
1841  SkPath& dirtyAfterEdit();
1842 
1843  // Bottlenecks for working with fConvexity and fFirstDirection.
1844  // Notice the setters are const... these are mutable atomic fields.
1845  void setConvexity(SkPathConvexity) const;
1846 
1847  void setFirstDirection(SkPathFirstDirection) const;
1848  SkPathFirstDirection getFirstDirection() const;
1849 
1853  SkPathConvexity getConvexity() const;
1854 
1855  SkPathConvexity getConvexityOrUnknown() const {
1856  return (SkPathConvexity)fConvexity.load(std::memory_order_relaxed);
1857  }
1858 
1859  // Compares the cached value with a freshly computed one (computeConvexity())
1860  bool isConvexityAccurate() const;
1861 
1868  void setConvexity(SkPathConvexity convexity);
1869 
1876  void shrinkToFit();
1877 
1878  friend class SkAutoPathBoundsUpdate;
1879  friend class SkAutoDisableOvalCheck;
1880  friend class SkAutoDisableDirectionCheck;
1881  friend class SkPathBuilder;
1882  friend class SkPathEdgeIter;
1883  friend class SkPathWriter;
1884  friend class SkOpBuilder;
1885  friend class SkBench_AddPathTest; // perf test reversePathTo
1886  friend class PathTest_Private; // unit test reversePathTo
1887  friend class ForceIsRRect_Private; // unit test isRRect
1888  friend class FuzzPath; // for legacy access to validateRef
1889 };
1890 
1891 #endif
SkPath::computeTightBounds
SkRect computeTightBounds() const
Returns minimum and maximum axes values of the lines and curves in SkPath.
SkPath::close
SkPath & close()
Appends kClose_Verb to SkPath.
SkPath::arcTo
SkPath & arcTo(const SkPoint p1, const SkPoint p2, SkScalar radius)
Appends arc to SkPath, after appending line if needed.
Definition: SkPath.h:886
SkPath::RawIter::setPath
void setPath(const SkPath &)
Sets SkPath::Iter to return elements of verb array, SkPoint array, and conic weight in path.
SkPathFillType_IsInverse
static bool SkPathFillType_IsInverse(SkPathFillType ft)
Definition: SkPathTypes.h:28
SkPath::quadTo
SkPath & quadTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2)
Adds quad from last point towards (x1, y1), to (x2, y2).
SkPath::Iter::conicWeight
SkScalar conicWeight() const
Returns conic weight if next() returned kConic_Verb.
Definition: SkPath.h:1488
SkPath::kAppend_AddPathMode
@ kAppend_AddPathMode
appended to destination unaltered
Definition: SkPath.h:1247
operator==
bool operator==(const sk_sp< T > &a, const sk_sp< U > &b)
Definition: SkRefCnt.h:338
SkPath::Line
static SkPath Line(const SkPoint a, const SkPoint b)
Definition: SkPath.h:91
SkPath::addOval
SkPath & addOval(const SkRect &oval, SkPathDirection dir, unsigned start)
Adds oval to SkPath, appending kMove_Verb, four kConic_Verb, and kClose_Verb.
SkPath::IsQuadDegenerate
static bool IsQuadDegenerate(const SkPoint &p1, const SkPoint &p2, const SkPoint &p3, bool exact)
Tests if quad is degenerate.
SkMatrix::reset
SkMatrix & reset()
Sets SkMatrix to identity; which has no effect on mapped SkPoint.
kConic_SkPathSegmentMask
@ kConic_SkPathSegmentMask
Definition: SkPathTypes.h:46
SkPath
Definition: SkPath.h:44
SkPath::getBounds
const SkRect & getBounds() const
Returns minimum and maximum axes values of SkPoint array.
Definition: SkPath.h:485
SkPathVerb::kClose
@ kClose
SkPath::RawIter returns 0 points.
SkPath::addArc
SkPath & addArc(const SkRect &oval, SkScalar startAngle, SkScalar sweepAngle)
Appends arc to SkPath, as the start of new contour.
SkPath::rewind
SkPath & rewind()
Sets SkPath to its initial state, preserving internal storage.
SkPath::kExtend_AddPathMode
@ kExtend_AddPathMode
add line if prior contour is not closed
Definition: SkPath.h:1248
SkPath::readFromMemory
size_t readFromMemory(const void *buffer, size_t length)
Initializes SkPath from buffer of size length.
SkPath::Polygon
static SkPath Polygon(const SkPoint pts[], int count, bool isClosed, SkPathFillType=SkPathFillType::kWinding, bool isVolatile=false)
SkPathVerb::kMove
@ kMove
SkPath::RawIter returns 1 point.
SkPathVerb::kQuad
@ kQuad
SkPath::RawIter returns 3 points.
SkPathFillType::kWinding
@ kWinding
Specifies that "inside" is computed by a non-zero sum of signed edge crossings.
SkPath::Circle
static SkPath Circle(SkScalar center_x, SkScalar center_y, SkScalar radius, SkPathDirection dir=SkPathDirection::kCW)
SkPath::cubicTo
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:794
SkPath::RRect
static SkPath RRect(const SkRRect &, SkPathDirection dir=SkPathDirection::kCW)
SkPath::conicTo
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::makeScale
SkPath makeScale(SkScalar sx, SkScalar sy)
Definition: SkPath.h:1360
SkPath::Verb
Verb
Definition: SkPath.h:1418
SkPathDirection
SkPathDirection
Definition: SkPathTypes.h:36
SkApplyPerspectiveClip::kYes
@ kYes
Do pre-clip the geometry before applying the (perspective) matrix.
SkPath::Iter::Iter
Iter(const SkPath &path, bool forceClose)
Sets SkPath::Iter to return elements of verb array, SkPoint array, and conic weight in path.
SkPath::rCubicTo
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::Iter::next
Verb next(SkPoint pts[4])
Returns next SkPath::Verb in verb array, and advances SkPath::Iter.
SkPathVerb::kLine
@ kLine
SkPath::RawIter returns 2 points.
SkPath::arcTo
SkPath & arcTo(const SkPoint r, SkScalar xAxisRotate, ArcSize largeArc, SkPathDirection sweep, const SkPoint xy)
Appends arc to SkPath.
Definition: SkPath.h:949
SkPath::addPoly
SkPath & addPoly(const std::initializer_list< SkPoint > &list, bool close)
Adds contour created from list.
Definition: SkPath.h:1234
SkPath::Iter::Iter
Iter()
Initializes SkPath::Iter with an empty SkPath.
SkPath::conicTo
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:730
SkPath::addRRect
SkPath & addRRect(const SkRRect &rrect, SkPathDirection dir=SkPathDirection::kCW)
Adds rrect to SkPath, creating a new closed contour.
SkPath::cubicTo
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::SegmentMask
SegmentMask
Definition: SkPath.h:1397
SkPath::lineTo
SkPath & lineTo(const SkPoint &p)
Adds line from last point to SkPoint p.
Definition: SkPath.h:605
SkPathTypes.h
SkPath::addRect
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::addRect
SkPath & addRect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom, SkPathDirection dir=SkPathDirection::kCW)
Definition: SkPath.h:1081
SkPath::addPath
SkPath & addPath(const SkPath &src, SkScalar dx, SkScalar dy, AddPathMode mode=kAppend_AddPathMode)
Appends src to SkPath, offset by (dx, dy).
SkPath::rConicTo
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.
kLine_SkPathSegmentMask
@ kLine_SkPathSegmentMask
Definition: SkPathTypes.h:44
SkData
SkData holds an immutable data buffer.
Definition: SkData.h:22
SkPath::isLine
bool isLine(SkPoint line[2]) const
Returns true if SkPath contains only one line; SkPath::Verb array has two entries: kMove_Verb,...
SkPathVerb
SkPathVerb
Definition: SkPathTypes.h:50
SkPathFillType
SkPathFillType
Definition: SkPathTypes.h:13
SkPath::Iter::setPath
void setPath(const SkPath &path, bool forceClose)
Sets SkPath::Iter to return elements of verb array, SkPoint array, and conic weight in path.
SkPath::getFillType
SkPathFillType getFillType() const
Returns SkPathFillType, the rule used to fill SkPath.
Definition: SkPath.h:203
SkPath::offset
void offset(SkScalar dx, SkScalar dy)
Offsets SkPoint array by (dx, dy).
Definition: SkPath.h:1323
operator!=
bool operator!=(const sk_sp< T > &a, const sk_sp< U > &b)
Definition: SkRefCnt.h:348
SkPath::isConvex
bool isConvex() const
Returns true if the path is convex.
Definition: SkPath.h:228
SkRRect
Definition: SkRRect.h:31
SkPath::dumpArrays
void dumpArrays() const
Definition: SkPath.h:1692
SkPath::AddPathMode
AddPathMode
Definition: SkPath.h:1246
SkPath::transform
void transform(const SkMatrix &matrix, SkPath *dst, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
Transforms verb array, SkPoint array, and weight by matrix.
kQuad_SkPathSegmentMask
@ kQuad_SkPathSegmentMask
Definition: SkPathTypes.h:45
SkPath::getGenerationID
uint32_t getGenerationID() const
(See Skia bug 1762.) Returns a non-zero, globally unique value.
SkPath::~SkPath
~SkPath()
Releases ownership of any shared data and deletes data if SkPath is sole owner.
sk_sp< SkData >
SkPath::dump
void dump(SkWStream *stream, bool dumpAsHex) const
Writes text representation of SkPath to stream.
SkPath::RawIter::RawIter
RawIter()
Initializes RawIter with an empty SkPath.
Definition: SkPath.h:1611
SkPath::dumpArrays
void dumpArrays(SkWStream *stream, bool dumpAsHex) const
SkPath::arcTo
SkPath & arcTo(const SkRect &oval, SkScalar startAngle, SkScalar sweepAngle, bool forceMoveTo)
Appends arc to SkPath.
SkPath::isEmpty
bool isEmpty() const
Returns if SkPath is empty.
Definition: SkPath.h:288
SkPath::conservativelyContainsRect
bool conservativelyContainsRect(const SkRect &rect) const
Returns true if rect is contained by SkPath.
SkPoint
Definition: SkPoint.h:160
SkPath::getPoints
int getPoints(SkPoint points[], int max) const
Returns number of points in SkPath.
SkPath::setLastPt
void setLastPt(const SkPoint &p)
Sets the last point on the path.
Definition: SkPath.h:1389
SkToBool
static constexpr bool SkToBool(const T &x)
Definition: SkTypes.h:497
SkPath::incReserve
void incReserve(int extraPtCount)
Grows SkPath verb array and SkPoint array to contain extraPtCount additional SkPoint.
SkPath::getLastPt
bool getLastPt(SkPoint *lastPt) const
Returns last point on SkPath in lastPt.
SkPath::Oval
static SkPath Oval(const SkRect &, SkPathDirection=SkPathDirection::kCW)
SkDEBUGCODE
#define SkDEBUGCODE(...)
Definition: SkTypes.h:467
SkPath::kSmall_ArcSize
@ kSmall_ArcSize
smaller of arc pair
Definition: SkPath.h:895
SkPath::addCircle
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,...
SkPath::serialize
sk_sp< SkData > serialize() const
Writes SkPath to buffer, returning the buffer written to, wrapped in SkData.
SK_API
#define SK_API
Definition: SkTypes.h:181
SkASSERT
#define SkASSERT(cond)
Definition: SkTypes.h:460
SkPath::Make
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.
SkPath::setLastPt
void setLastPt(SkScalar x, SkScalar y)
Sets last point to (x, y).
SkPath::addPoly
SkPath & addPoly(const SkPoint pts[], int count, bool close)
Adds contour created from line array, adding (count - 1) line segments.
SkPath::Iter::isClosedContour
bool isClosedContour() const
Returns true if subsequent calls to next() return kClose_Verb before returning kMove_Verb.
SkPath::Polygon
static SkPath Polygon(const std::initializer_list< SkPoint > &list, bool isClosed, SkPathFillType fillType=SkPathFillType::kWinding, bool isVolatile=false)
Definition: SkPath.h:85
SkPath::operator=
SkPath & operator=(const SkPath &path)
Constructs a copy of an existing path.
SkPath::transform
void transform(const SkMatrix &matrix, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes)
Transforms verb array, SkPoint array, and weight by matrix.
Definition: SkPath.h:1348
SkPath::reverseAddPath
SkPath & reverseAddPath(const SkPath &src)
Appends src to SkPath, from back to front.
SkPath::RawIter::next
Verb next(SkPoint[4])
Returns next SkPath::Verb in verb array, and advances RawIter.
SkPath::isLastContourClosed
bool isLastContourClosed() const
Returns if contour is closed.
SkPoint::fY
SkScalar fY
y-axis value
Definition: SkPoint.h:162
SkPath::RawIter
Definition: SkPath.h:1603
SkPath::getPoint
SkPoint getPoint(int index) const
Returns SkPoint at index in SkPoint array.
SkPath::offset
void offset(SkScalar dx, SkScalar dy, SkPath *dst) const
Offsets SkPoint array by (dx, dy).
SkPath::moveTo
SkPath & moveTo(SkScalar x, SkScalar y)
Adds beginning of contour at SkPoint (x, y).
SkPath::Oval
static SkPath Oval(const SkRect &, SkPathDirection, unsigned startIndex)
SkPath::isRRect
bool isRRect(SkRRect *rrect) const
Returns true if path is representable as SkRRect.
SkPath::reset
SkPath & reset()
Sets SkPath to its initial state.
SkPath::contains
bool contains(SkScalar x, SkScalar y) const
Returns true if the point (x, y) is contained by SkPath, taking into account FillType.
SkPath::countVerbs
int countVerbs() const
Returns the number of verbs: kMove_Verb, kLine_Verb, kQuad_Verb, kConic_Verb, kCubic_Verb,...
kCubic_SkPathSegmentMask
@ kCubic_SkPathSegmentMask
Definition: SkPathTypes.h:47
SkPath::addRoundRect
SkPath & addRoundRect(const SkRect &rect, const SkScalar radii[], SkPathDirection dir=SkPathDirection::kCW)
Appends SkRRect to SkPath, creating a new closed contour.
SkPath::isValid
bool isValid() const
Returns if SkPath data is consistent.
Definition: SkPath.h:1762
SkPath::interpolate
bool interpolate(const SkPath &ending, SkScalar weight, SkPath *out) const
Interpolates between SkPath with SkPoint array of equal size.
SkPath::getVerbs
int getVerbs(uint8_t verbs[], int max) const
Returns the number of verbs in the path.
SkPath::ConvertConicToQuads
static int ConvertConicToQuads(const SkPoint &p0, const SkPoint &p1, const SkPoint &p2, SkScalar w, SkPoint pts[], int pow2)
Approximates conic with quad array.
SkPath::approximateBytesUsed
size_t approximateBytesUsed() const
Returns the approximate byte size of the SkPath in memory.
SkPath::arcTo
SkPath & arcTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar radius)
Appends arc to SkPath, after appending line if needed.
SkPath::addPath
SkPath & addPath(const SkPath &src, const SkMatrix &matrix, AddPathMode mode=kAppend_AddPathMode)
Appends src to SkPath, transformed by matrix.
SkPath::addRRect
SkPath & addRRect(const SkRRect &rrect, SkPathDirection dir, unsigned start)
Adds rrect to SkPath, creating a new closed contour.
SkPath::ArcSize
ArcSize
Definition: SkPath.h:894
SkScalar
float SkScalar
Definition: SkScalar.h:16
SkPath::rArcTo
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.
SkPath::writeToMemory
size_t writeToMemory(void *buffer) const
Writes SkPath to buffer, returning the number of bytes written.
SkApplyPerspectiveClip::kNo
@ kNo
Don't pre-clip the geometry before applying the (perspective) matrix.
SkOpBuilder
Perform a series of path operations, optimized for unioning many paths together.
Definition: SkPathOps.h:86
SkPath::addOval
SkPath & addOval(const SkRect &oval, SkPathDirection dir=SkPathDirection::kCW)
Adds oval to path, appending kMove_Verb, four kConic_Verb, and kClose_Verb.
SkPath::addRect
SkPath & addRect(const SkRect &rect, SkPathDirection dir=SkPathDirection::kCW)
Definition: SkPath.h:1077
SkPath::quadTo
SkPath & quadTo(const SkPoint &p1, const SkPoint &p2)
Adds quad from last point towards SkPoint p1, to SkPoint p2.
Definition: SkPath.h:657
SkPath::lineTo
SkPath & lineTo(SkScalar x, SkScalar y)
Adds line from last point to (x, y).
SkPoint::fX
SkScalar fX
x-axis value
Definition: SkPoint.h:161
SkPath::Iter::isCloseLine
bool isCloseLine() const
Returns true if last kLine_Verb returned by next() was generated by kClose_Verb.
Definition: SkPath.h:1499
SkPath::RRect
static SkPath RRect(const SkRect &bounds, SkScalar rx, SkScalar ry, SkPathDirection dir=SkPathDirection::kCW)
SkPath::isRect
bool isRect(SkRect *rect, bool *isClosed=nullptr, SkPathDirection *direction=nullptr) const
Returns true if SkPath is equivalent to SkRect when filled.
SkUNREACHABLE
#define SkUNREACHABLE
Definition: SkTypes.h:256
SkPath::rLineTo
SkPath & rLineTo(SkScalar dx, SkScalar dy)
Adds line from last point to vector (dx, dy).
SkPath::operator==
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...
SkMatrix::Scale
static SkMatrix SK_WARN_UNUSED_RESULT Scale(SkScalar sx, SkScalar sy)
Sets SkMatrix to scale by (sx, sy).
Definition: SkMatrix.h:69
SkMatrix
Definition: SkMatrix.h:48
SkMatrix.h
SkPath::rQuadTo
SkPath & rQuadTo(SkScalar dx1, SkScalar dy1, SkScalar dx2, SkScalar dy2)
Adds quad from last point towards vector (dx1, dy1), to vector (dx2, dy2).
SkPath::IsCubicDegenerate
static bool IsCubicDegenerate(const SkPoint &p1, const SkPoint &p2, const SkPoint &p3, const SkPoint &p4, bool exact)
Tests if cubic is degenerate.
SkPathDirection::kCW
@ kCW
clockwise direction for adding closed contours
SkPath::operator!=
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:158
SkPath::moveTo
SkPath & moveTo(const SkPoint &p)
Adds beginning of contour at SkPoint p.
Definition: SkPath.h:565
SkPath::addPath
SkPath & addPath(const SkPath &src, AddPathMode mode=kAppend_AddPathMode)
Appends src to SkPath.
Definition: SkPath.h:1276
SkApplyPerspectiveClip
SkApplyPerspectiveClip
When we transform points through a matrix containing perspective (the bottom row is something other t...
Definition: SkMatrix.h:27
SkWStream
Definition: SkStream.h:227
SkPath::makeTransform
SkPath makeTransform(const SkMatrix &m, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
Definition: SkPath.h:1353
SkPath::setFillType
void setFillType(SkPathFillType ft)
Sets FillType, the rule used to fill SkPath.
Definition: SkPath.h:208
SkPath::rMoveTo
SkPath & rMoveTo(SkScalar dx, SkScalar dy)
Adds beginning of contour relative to last point.
SkPath::updateBoundsCache
void updateBoundsCache() const
Updates internal bounds so that subsequent calls to getBounds() are instantaneous.
Definition: SkPath.h:497
SkPath::Iter
Definition: SkPath.h:1433
SkPath::isVolatile
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:321
SkPath::toggleInverseFillType
void toggleInverseFillType()
Replaces FillType with its inverse.
Definition: SkPath.h:222
SkPathVerb::kCubic
@ kCubic
SkPath::RawIter returns 4 points.
SkPath::getSegmentMasks
uint32_t getSegmentMasks() const
Returns a mask, where each set bit corresponds to a SegmentMask constant if SkPath contains one or mo...
Definition: SkPath.h:1412
SkPath::SkPath
SkPath()
Constructs an empty SkPath.
SkPath::SkPath
SkPath(const SkPath &path)
Constructs a copy of an existing path.
SkRect
Definition: SkRect.h:572
SkPathVerb::kConic
@ kConic
SkPath::RawIter returns 3 points + 1 weight.
SkPath::countPoints
int countPoints() const
Returns the number of points in SkPath.
SkPath::dump
void dump() const
Definition: SkPath.h:1687
SkPath::IsLineDegenerate
static bool IsLineDegenerate(const SkPoint &p1, const SkPoint &p2, bool exact)
Tests if line between SkPoint pair is degenerate.
SkPath::isFinite
bool isFinite() const
Returns true for finite SkPoint array values between negative SK_ScalarMax and positive SK_ScalarMax.
Definition: SkPath.h:309
SkPath::dumpHex
void dumpHex() const
Definition: SkPath.h:1688
SkPath::setIsVolatile
SkPath & setIsVolatile(bool isVolatile)
Specifies whether SkPath is volatile; whether it will be altered or discarded by the caller after it ...
Definition: SkPath.h:341
SkPathBuilder
Definition: SkPathBuilder.h:16
SkPath::isInterpolatable
bool isInterpolatable(const SkPath &compare) const
Returns true if SkPath contain equal verbs and equal weights.
SkPath::RawIter::conicWeight
SkScalar conicWeight() const
Returns conic weight if next() returned kConic_Verb.
Definition: SkPath.h:1653
SkPath::RawIter::RawIter
RawIter(const SkPath &path)
Sets RawIter to return elements of verb array, SkPoint array, and conic weight in path.
Definition: SkPath.h:1618
SkPath::swap
void swap(SkPath &other)
Exchanges the verb array, SkPoint array, weights, and SkPath::FillType with other.
SkPath::isOval
bool isOval(SkRect *bounds) const
Returns true if this path is recognized as an oval or circle.
SkPath::RRect
static SkPath RRect(const SkRRect &, SkPathDirection, unsigned startIndex)
SkPath::arcTo
SkPath & arcTo(SkScalar rx, SkScalar ry, SkScalar xAxisRotate, ArcSize largeArc, SkPathDirection sweep, SkScalar x, SkScalar y)
Appends arc to SkPath.
SkPath::kLarge_ArcSize
@ kLarge_ArcSize
larger of arc pair
Definition: SkPath.h:896
SkPath::Rect
static SkPath Rect(const SkRect &, SkPathDirection=SkPathDirection::kCW, unsigned startIndex=0)
SkPath::addRoundRect
SkPath & addRoundRect(const SkRect &rect, SkScalar rx, SkScalar ry, SkPathDirection dir=SkPathDirection::kCW)
Appends SkRRect to SkPath, creating a new closed contour.
SkPath::RawIter::peek
Verb peek() const
Returns next SkPath::Verb, but does not advance RawIter.
Definition: SkPath.h:1642
SkPath::isInverseFillType
bool isInverseFillType() const
Returns if FillType describes area outside SkPath geometry.
Definition: SkPath.h:217