Skia
2D Graphics Library
SkMatrix.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 SkMatrix_DEFINED
9 #define SkMatrix_DEFINED
10 
11 #include "include/core/SkRect.h"
12 #include "include/private/SkMacros.h"
13 #include "include/private/SkTo.h"
14 
15 struct SkRSXform;
16 struct SkPoint3;
17 
18 // Remove when clients are updated to live without this
19 #define SK_SUPPORT_LEGACY_MATRIX_RECTTORECT
20 
28  kNo,
29  kYes,
30 };
31 
47 SK_BEGIN_REQUIRE_DENSE
49 public:
50 
57  constexpr SkMatrix() : SkMatrix(1,0,0, 0,1,0, 0,0,1, kIdentity_Mask | kRectStaysRect_Mask) {}
58 
70  SkMatrix m;
71  m.setScale(sx, sy);
72  return m;
73  }
74 
86  SkMatrix m;
87  m.setTranslate(dx, dy);
88  return m;
89  }
90  static SkMatrix SK_WARN_UNUSED_RESULT Translate(SkVector t) { return Translate(t.x(), t.y()); }
91  static SkMatrix SK_WARN_UNUSED_RESULT Translate(SkIVector t) { return Translate(t.x(), t.y()); }
92 
99  SkMatrix m;
100  m.setRotate(deg);
101  return m;
102  }
104  SkMatrix m;
105  m.setRotate(deg, pt.x(), pt.y());
106  return m;
107  }
109  return RotateDeg(SkRadiansToDegrees(rad));
110  }
111 
118  enum ScaleToFit {
123  };
124 
139  static SkMatrix SK_WARN_UNUSED_RESULT RectToRect(const SkRect& src, const SkRect& dst,
140  ScaleToFit mode = kFill_ScaleToFit) {
141  return MakeRectToRect(src, dst, mode);
142  }
143 
162  SkScalar skewY, SkScalar scaleY, SkScalar transY,
163  SkScalar pers0, SkScalar pers1, SkScalar pers2) {
164  SkMatrix m;
165  m.setAll(scaleX, skewX, transX, skewY, scaleY, transY, pers0, pers1, pers2);
166  return m;
167  }
168 
173  enum TypeMask {
174  kIdentity_Mask = 0,
175  kTranslate_Mask = 0x01,
176  kScale_Mask = 0x02,
177  kAffine_Mask = 0x04,
178  kPerspective_Mask = 0x08,
179  };
180 
189  TypeMask getType() const {
190  if (fTypeMask & kUnknown_Mask) {
191  fTypeMask = this->computeTypeMask();
192  }
193  // only return the public masks
194  return (TypeMask)(fTypeMask & 0xF);
195  }
196 
205  bool isIdentity() const {
206  return this->getType() == 0;
207  }
208 
218  bool isScaleTranslate() const {
219  return !(this->getType() & ~(kScale_Mask | kTranslate_Mask));
220  }
221 
230  bool isTranslate() const { return !(this->getType() & ~(kTranslate_Mask)); }
231 
253  bool rectStaysRect() const {
254  if (fTypeMask & kUnknown_Mask) {
255  fTypeMask = this->computeTypeMask();
256  }
257  return (fTypeMask & kRectStaysRect_Mask) != 0;
258  }
259 
281  bool preservesAxisAlignment() const { return this->rectStaysRect(); }
282 
294  bool hasPerspective() const {
295  return SkToBool(this->getPerspectiveTypeMaskOnly() &
296  kPerspective_Mask);
297  }
298 
316 
331 
335  static constexpr int kMScaleX = 0;
336  static constexpr int kMSkewX = 1;
337  static constexpr int kMTransX = 2;
338  static constexpr int kMSkewY = 3;
339  static constexpr int kMScaleY = 4;
340  static constexpr int kMTransY = 5;
341  static constexpr int kMPersp0 = 6;
342  static constexpr int kMPersp1 = 7;
343  static constexpr int kMPersp2 = 8;
344 
348  static constexpr int kAScaleX = 0;
349  static constexpr int kASkewY = 1;
350  static constexpr int kASkewX = 2;
351  static constexpr int kAScaleY = 3;
352  static constexpr int kATransX = 4;
353  static constexpr int kATransY = 5;
354 
362  SkScalar operator[](int index) const {
363  SkASSERT((unsigned)index < 9);
364  return fMat[index];
365  }
366 
374  SkScalar get(int index) const {
375  SkASSERT((unsigned)index < 9);
376  return fMat[index];
377  }
378 
386  SkScalar rc(int r, int c) const {
387  SkASSERT(r >= 0 && r <= 2);
388  SkASSERT(c >= 0 && c <= 2);
389  return fMat[r*3 + c];
390  }
391 
397  SkScalar getScaleX() const { return fMat[kMScaleX]; }
398 
404  SkScalar getScaleY() const { return fMat[kMScaleY]; }
405 
412  SkScalar getSkewY() const { return fMat[kMSkewY]; }
413 
420  SkScalar getSkewX() const { return fMat[kMSkewX]; }
421 
427  SkScalar getTranslateX() const { return fMat[kMTransX]; }
428 
434  SkScalar getTranslateY() const { return fMat[kMTransY]; }
435 
440  SkScalar getPerspX() const { return fMat[kMPersp0]; }
441 
446  SkScalar getPerspY() const { return fMat[kMPersp1]; }
447 
458  SkScalar& operator[](int index) {
459  SkASSERT((unsigned)index < 9);
460  this->setTypeMask(kUnknown_Mask);
461  return fMat[index];
462  }
463 
471  SkMatrix& set(int index, SkScalar value) {
472  SkASSERT((unsigned)index < 9);
473  fMat[index] = value;
474  this->setTypeMask(kUnknown_Mask);
475  return *this;
476  }
477 
482  SkMatrix& setScaleX(SkScalar v) { return this->set(kMScaleX, v); }
483 
488  SkMatrix& setScaleY(SkScalar v) { return this->set(kMScaleY, v); }
489 
494  SkMatrix& setSkewY(SkScalar v) { return this->set(kMSkewY, v); }
495 
500  SkMatrix& setSkewX(SkScalar v) { return this->set(kMSkewX, v); }
501 
506  SkMatrix& setTranslateX(SkScalar v) { return this->set(kMTransX, v); }
507 
512  SkMatrix& setTranslateY(SkScalar v) { return this->set(kMTransY, v); }
513 
519  SkMatrix& setPerspX(SkScalar v) { return this->set(kMPersp0, v); }
520 
526  SkMatrix& setPerspY(SkScalar v) { return this->set(kMPersp1, v); }
527 
544  SkMatrix& setAll(SkScalar scaleX, SkScalar skewX, SkScalar transX,
545  SkScalar skewY, SkScalar scaleY, SkScalar transY,
546  SkScalar persp0, SkScalar persp1, SkScalar persp2) {
547  fMat[kMScaleX] = scaleX;
548  fMat[kMSkewX] = skewX;
549  fMat[kMTransX] = transX;
550  fMat[kMSkewY] = skewY;
551  fMat[kMScaleY] = scaleY;
552  fMat[kMTransY] = transY;
553  fMat[kMPersp0] = persp0;
554  fMat[kMPersp1] = persp1;
555  fMat[kMPersp2] = persp2;
556  this->setTypeMask(kUnknown_Mask);
557  return *this;
558  }
559 
566  void get9(SkScalar buffer[9]) const {
567  memcpy(buffer, fMat, 9 * sizeof(SkScalar));
568  }
569 
586  SkMatrix& set9(const SkScalar buffer[9]);
587 
598 
608  SkMatrix& setIdentity() { return this->reset(); }
609 
616 
621  SkMatrix& setTranslate(const SkVector& v) { return this->setTranslate(v.fX, v.fY); }
622 
632 
639 
650 
657 
669  SkMatrix& setSinCos(SkScalar sinValue, SkScalar cosValue,
670  SkScalar px, SkScalar py);
671 
680  SkMatrix& setSinCos(SkScalar sinValue, SkScalar cosValue);
681 
693  SkMatrix& setRSXform(const SkRSXform& rsxForm);
694 
704 
711 
729  SkMatrix& setConcat(const SkMatrix& a, const SkMatrix& b);
730 
750 
778 
799 
830 
857 
885 
906 
924  SkMatrix& preConcat(const SkMatrix& other);
925 
945 
973 
994 
1025 
1052 
1080 
1101 
1119  SkMatrix& postConcat(const SkMatrix& other);
1120 
1121 #ifndef SK_SUPPORT_LEGACY_MATRIX_RECTTORECT
1122 private:
1123 #endif
1124 
1139  bool setRectToRect(const SkRect& src, const SkRect& dst, ScaleToFit stf);
1140 
1154  static SkMatrix MakeRectToRect(const SkRect& src, const SkRect& dst, ScaleToFit stf) {
1155  SkMatrix m;
1156  m.setRectToRect(src, dst, stf);
1157  return m;
1158  }
1159 #ifndef SK_SUPPORT_LEGACY_MATRIX_RECTTORECT
1160 public:
1161 #endif
1162 
1178  bool setPolyToPoly(const SkPoint src[], const SkPoint dst[], int count);
1179 
1188  bool SK_WARN_UNUSED_RESULT invert(SkMatrix* inverse) const {
1189  // Allow the trivial case to be inlined.
1190  if (this->isIdentity()) {
1191  if (inverse) {
1192  inverse->reset();
1193  }
1194  return true;
1195  }
1196  return this->invertNonIdentity(inverse);
1197  }
1198 
1211  static void SetAffineIdentity(SkScalar affine[6]);
1212 
1223  bool SK_WARN_UNUSED_RESULT asAffine(SkScalar affine[6]) const;
1224 
1239  SkMatrix& setAffine(const SkScalar affine[6]);
1240 
1253  if (fMat[8] != 1) {
1254  this->doNormalizePerspective();
1255  }
1256  }
1257 
1286  void mapPoints(SkPoint dst[], const SkPoint src[], int count) const;
1287 
1311  void mapPoints(SkPoint pts[], int count) const {
1312  this->mapPoints(pts, pts, count);
1313  }
1314 
1334  void mapHomogeneousPoints(SkPoint3 dst[], const SkPoint3 src[], int count) const;
1335 
1339  void mapHomogeneousPoints(SkPoint3 dst[], const SkPoint src[], int count) const;
1340 
1357  SkPoint result;
1358  this->mapXY(pt.x(), pt.y(), &result);
1359  return result;
1360  }
1361 
1380  void mapXY(SkScalar x, SkScalar y, SkPoint* result) const;
1381 
1399  SkPoint result;
1400  this->mapXY(x,y, &result);
1401  return result;
1402  }
1403 
1404 
1419  SkPoint mapOrigin() const {
1420  SkScalar x = this->getTranslateX(),
1421  y = this->getTranslateY();
1422  if (this->hasPerspective()) {
1423  SkScalar w = fMat[kMPersp2];
1424  if (w) { w = 1 / w; }
1425  x *= w;
1426  y *= w;
1427  }
1428  return {x, y};
1429  }
1430 
1460  void mapVectors(SkVector dst[], const SkVector src[], int count) const;
1461 
1485  void mapVectors(SkVector vecs[], int count) const {
1486  this->mapVectors(vecs, vecs, count);
1487  }
1488 
1506  void mapVector(SkScalar dx, SkScalar dy, SkVector* result) const {
1507  SkVector vec = { dx, dy };
1508  this->mapVectors(result, &vec, 1);
1509  }
1510 
1529  SkVector vec = { dx, dy };
1530  this->mapVectors(&vec, &vec, 1);
1531  return vec;
1532  }
1533 
1546  bool mapRect(SkRect* dst, const SkRect& src,
1548 
1559  return this->mapRect(rect, *rect, pc);
1560  }
1561 
1567  SkRect mapRect(const SkRect& src,
1569  SkRect dst;
1570  (void)this->mapRect(&dst, src, pc);
1571  return dst;
1572  }
1573 
1602  void mapRectToQuad(SkPoint dst[4], const SkRect& rect) const {
1603  // This could potentially be faster if we only transformed each x and y of the rect once.
1604  rect.toQuad(dst);
1605  this->mapPoints(dst, 4);
1606  }
1607 
1617  void mapRectScaleTranslate(SkRect* dst, const SkRect& src) const;
1618 
1629  SkScalar mapRadius(SkScalar radius) const;
1630 
1639  friend SK_API bool operator==(const SkMatrix& a, const SkMatrix& b);
1640 
1649  friend SK_API bool operator!=(const SkMatrix& a, const SkMatrix& b) {
1650  return !(a == b);
1651  }
1652 
1659  void dump() const;
1660 
1670 
1680 
1691  bool SK_WARN_UNUSED_RESULT getMinMaxScales(SkScalar scaleFactors[2]) const;
1692 
1712  bool decomposeScale(SkSize* scale, SkMatrix* remaining = nullptr) const;
1713 
1724  static const SkMatrix& I();
1725 
1737  static const SkMatrix& InvalidMatrix();
1738 
1757  static SkMatrix Concat(const SkMatrix& a, const SkMatrix& b) {
1758  SkMatrix result;
1759  result.setConcat(a, b);
1760  return result;
1761  }
1762 
1763  friend SkMatrix operator*(const SkMatrix& a, const SkMatrix& b) {
1764  return Concat(a, b);
1765  }
1766 
1771  this->setTypeMask(kUnknown_Mask);
1772  }
1773 
1786  fMat[kMScaleX] = sx;
1787  fMat[kMSkewX] = 0;
1788  fMat[kMTransX] = tx;
1789 
1790  fMat[kMSkewY] = 0;
1791  fMat[kMScaleY] = sy;
1792  fMat[kMTransY] = ty;
1793 
1794  fMat[kMPersp0] = 0;
1795  fMat[kMPersp1] = 0;
1796  fMat[kMPersp2] = 1;
1797 
1798  int mask = 0;
1799  if (sx != 1 || sy != 1) {
1800  mask |= kScale_Mask;
1801  }
1802  if (tx || ty) {
1803  mask |= kTranslate_Mask;
1804  }
1805  this->setTypeMask(mask | kRectStaysRect_Mask);
1806  }
1807 
1813  bool isFinite() const { return SkScalarsAreFinite(fMat, 9); }
1814 
1815 private:
1822  static constexpr int kRectStaysRect_Mask = 0x10;
1823 
1827  static constexpr int kOnlyPerspectiveValid_Mask = 0x40;
1828 
1829  static constexpr int kUnknown_Mask = 0x80;
1830 
1831  static constexpr int kORableMasks = kTranslate_Mask |
1832  kScale_Mask |
1833  kAffine_Mask |
1834  kPerspective_Mask;
1835 
1836  static constexpr int kAllMasks = kTranslate_Mask |
1837  kScale_Mask |
1838  kAffine_Mask |
1839  kPerspective_Mask |
1840  kRectStaysRect_Mask;
1841 
1842  SkScalar fMat[9];
1843  mutable int32_t fTypeMask;
1844 
1845  constexpr SkMatrix(SkScalar sx, SkScalar kx, SkScalar tx,
1846  SkScalar ky, SkScalar sy, SkScalar ty,
1847  SkScalar p0, SkScalar p1, SkScalar p2, int typeMask)
1848  : fMat{sx, kx, tx,
1849  ky, sy, ty,
1850  p0, p1, p2}
1851  , fTypeMask(typeMask) {}
1852 
1853  static void ComputeInv(SkScalar dst[9], const SkScalar src[9], double invDet, bool isPersp);
1854 
1855  uint8_t computeTypeMask() const;
1856  uint8_t computePerspectiveTypeMask() const;
1857 
1858  void setTypeMask(int mask) {
1859  // allow kUnknown or a valid mask
1860  SkASSERT(kUnknown_Mask == mask || (mask & kAllMasks) == mask ||
1861  ((kUnknown_Mask | kOnlyPerspectiveValid_Mask) & mask)
1862  == (kUnknown_Mask | kOnlyPerspectiveValid_Mask));
1863  fTypeMask = mask;
1864  }
1865 
1866  void orTypeMask(int mask) {
1867  SkASSERT((mask & kORableMasks) == mask);
1868  fTypeMask |= mask;
1869  }
1870 
1871  void clearTypeMask(int mask) {
1872  // only allow a valid mask
1873  SkASSERT((mask & kAllMasks) == mask);
1874  fTypeMask &= ~mask;
1875  }
1876 
1877  TypeMask getPerspectiveTypeMaskOnly() const {
1878  if ((fTypeMask & kUnknown_Mask) &&
1879  !(fTypeMask & kOnlyPerspectiveValid_Mask)) {
1880  fTypeMask = this->computePerspectiveTypeMask();
1881  }
1882  return (TypeMask)(fTypeMask & 0xF);
1883  }
1884 
1888  bool isTriviallyIdentity() const {
1889  if (fTypeMask & kUnknown_Mask) {
1890  return false;
1891  }
1892  return ((fTypeMask & 0xF) == 0);
1893  }
1894 
1895  inline void updateTranslateMask() {
1896  if ((fMat[kMTransX] != 0) | (fMat[kMTransY] != 0)) {
1897  fTypeMask |= kTranslate_Mask;
1898  } else {
1899  fTypeMask &= ~kTranslate_Mask;
1900  }
1901  }
1902 
1903  typedef void (*MapXYProc)(const SkMatrix& mat, SkScalar x, SkScalar y,
1904  SkPoint* result);
1905 
1906  static MapXYProc GetMapXYProc(TypeMask mask) {
1907  SkASSERT((mask & ~kAllMasks) == 0);
1908  return gMapXYProcs[mask & kAllMasks];
1909  }
1910 
1911  MapXYProc getMapXYProc() const {
1912  return GetMapXYProc(this->getType());
1913  }
1914 
1915  typedef void (*MapPtsProc)(const SkMatrix& mat, SkPoint dst[],
1916  const SkPoint src[], int count);
1917 
1918  static MapPtsProc GetMapPtsProc(TypeMask mask) {
1919  SkASSERT((mask & ~kAllMasks) == 0);
1920  return gMapPtsProcs[mask & kAllMasks];
1921  }
1922 
1923  MapPtsProc getMapPtsProc() const {
1924  return GetMapPtsProc(this->getType());
1925  }
1926 
1927  bool SK_WARN_UNUSED_RESULT invertNonIdentity(SkMatrix* inverse) const;
1928 
1929  static bool Poly2Proc(const SkPoint[], SkMatrix*);
1930  static bool Poly3Proc(const SkPoint[], SkMatrix*);
1931  static bool Poly4Proc(const SkPoint[], SkMatrix*);
1932 
1933  static void Identity_xy(const SkMatrix&, SkScalar, SkScalar, SkPoint*);
1934  static void Trans_xy(const SkMatrix&, SkScalar, SkScalar, SkPoint*);
1935  static void Scale_xy(const SkMatrix&, SkScalar, SkScalar, SkPoint*);
1936  static void ScaleTrans_xy(const SkMatrix&, SkScalar, SkScalar, SkPoint*);
1937  static void Rot_xy(const SkMatrix&, SkScalar, SkScalar, SkPoint*);
1938  static void RotTrans_xy(const SkMatrix&, SkScalar, SkScalar, SkPoint*);
1939  static void Persp_xy(const SkMatrix&, SkScalar, SkScalar, SkPoint*);
1940 
1941  static const MapXYProc gMapXYProcs[];
1942 
1943  static void Identity_pts(const SkMatrix&, SkPoint[], const SkPoint[], int);
1944  static void Trans_pts(const SkMatrix&, SkPoint dst[], const SkPoint[], int);
1945  static void Scale_pts(const SkMatrix&, SkPoint dst[], const SkPoint[], int);
1946  static void ScaleTrans_pts(const SkMatrix&, SkPoint dst[], const SkPoint[],
1947  int count);
1948  static void Persp_pts(const SkMatrix&, SkPoint dst[], const SkPoint[], int);
1949 
1950  static void Affine_vpts(const SkMatrix&, SkPoint dst[], const SkPoint[], int);
1951 
1952  static const MapPtsProc gMapPtsProcs[];
1953 
1954  // return the number of bytes written, whether or not buffer is null
1955  size_t writeToMemory(void* buffer) const;
1964  size_t readFromMemory(const void* buffer, size_t length);
1965 
1966  // legacy method -- still needed? why not just postScale(1/divx, ...)?
1967  bool postIDiv(int divx, int divy);
1968  void doNormalizePerspective();
1969 
1970  friend class SkPerspIter;
1971  friend class SkMatrixPriv;
1972  friend class SerializationTest;
1973 };
1974 SK_END_REQUIRE_DENSE
1975 
1976 #endif
SkMatrix::postRotate
SkMatrix & postRotate(SkScalar degrees, SkScalar px, SkScalar py)
Sets SkMatrix to SkMatrix constructed from rotating by degrees about pivot point (px,...
SkMatrix::kEnd_ScaleToFit
@ kEnd_ScaleToFit
scales and aligns to right and bottom
Definition: SkMatrix.h:122
SkMatrix::postSkew
SkMatrix & postSkew(SkScalar kx, SkScalar ky)
Sets SkMatrix to SkMatrix constructed from skewing by (kx, ky) about pivot point (0,...
SkMatrix::setTranslate
SkMatrix & setTranslate(SkScalar dx, SkScalar dy)
Sets SkMatrix to translate by (dx, dy).
SkMatrix::setPerspX
SkMatrix & setPerspX(SkScalar v)
Sets input x-axis perspective factor, which causes mapXY() to vary input x-axis values inversely prop...
Definition: SkMatrix.h:519
SkMatrix::reset
SkMatrix & reset()
Sets SkMatrix to identity; which has no effect on mapped SkPoint.
SkMatrix::set
SkMatrix & set(int index, SkScalar value)
Sets SkMatrix value.
Definition: SkMatrix.h:471
SkMatrix::dirtyMatrixTypeCache
void dirtyMatrixTypeCache()
Sets internal cache to unknown state.
Definition: SkMatrix.h:1770
SkMatrix::mapPoints
void mapPoints(SkPoint pts[], int count) const
Maps pts SkPoint array of length count in place.
Definition: SkMatrix.h:1311
SkMatrix::dump
void dump() const
Writes text representation of SkMatrix to standard output.
SkMatrix::mapXY
void mapXY(SkScalar x, SkScalar y, SkPoint *result) const
Maps SkPoint (x, y) to result.
SkPoint3
Definition: SkPoint3.h:13
SkMatrix::mapVector
void mapVector(SkScalar dx, SkScalar dy, SkVector *result) const
Maps vector (dx, dy) to result.
Definition: SkMatrix.h:1506
SkMatrix::RotateDeg
static SkMatrix SK_WARN_UNUSED_RESULT RotateDeg(SkScalar deg, SkPoint pt)
Definition: SkMatrix.h:103
SkMatrix::setScaleTranslate
void setScaleTranslate(SkScalar sx, SkScalar sy, SkScalar tx, SkScalar ty)
Initializes SkMatrix with scale and translate elements.
Definition: SkMatrix.h:1785
SkRSXform
A compressed form of a rotation+scale matrix.
Definition: SkRSXform.h:21
SkMatrix::SkMatrix
constexpr SkMatrix()
Creates an identity SkMatrix:
Definition: SkMatrix.h:57
SkMatrix::postRotate
SkMatrix & postRotate(SkScalar degrees)
Sets SkMatrix to SkMatrix constructed from rotating by degrees about pivot point (0,...
SkMatrix::getSkewX
SkScalar getSkewX() const
Returns scale factor multiplied by y-axis input, contributing to x-axis output.
Definition: SkMatrix.h:420
SkMatrix::rc
SkScalar rc(int r, int c) const
Returns one matrix value from a particular row/column.
Definition: SkMatrix.h:386
SkApplyPerspectiveClip::kYes
@ kYes
Do pre-clip the geometry before applying the (perspective) matrix.
SkMatrix::setRSXform
SkMatrix & setRSXform(const SkRSXform &rsxForm)
Sets SkMatrix to rotate, scale, and translate using a compressed matrix form.
SkMatrix::setSkewY
SkMatrix & setSkewY(SkScalar v)
Sets vertical skew factor.
Definition: SkMatrix.h:494
SkRect.h
SkMatrix::mapRectToQuad
void mapRectToQuad(SkPoint dst[4], const SkRect &rect) const
Maps four corners of rect to dst.
Definition: SkMatrix.h:1602
SkMatrix::operator*
friend SkMatrix operator*(const SkMatrix &a, const SkMatrix &b)
Definition: SkMatrix.h:1763
SkMatrix::RotateRad
static SkMatrix SK_WARN_UNUSED_RESULT RotateRad(SkScalar rad)
Definition: SkMatrix.h:108
SkMatrix::getScaleX
SkScalar getScaleX() const
Returns scale factor multiplied by x-axis input, contributing to x-axis output.
Definition: SkMatrix.h:397
SkMatrix::RotateDeg
static SkMatrix SK_WARN_UNUSED_RESULT RotateDeg(SkScalar deg)
Sets SkMatrix to rotate by |deg| about a pivot point at (0, 0).
Definition: SkMatrix.h:98
SkMatrix::preScale
SkMatrix & preScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
Sets SkMatrix to SkMatrix multiplied by SkMatrix constructed from scaling by (sx, sy) about pivot poi...
SkIPoint::y
constexpr int32_t y() const
Returns y-axis value of SkIPoint.
Definition: SkPoint.h:49
SkMatrix::preSkew
SkMatrix & preSkew(SkScalar kx, SkScalar ky, SkScalar px, SkScalar py)
Sets SkMatrix to SkMatrix multiplied by SkMatrix constructed from skewing by (kx, ky) about pivot poi...
SkIPoint::x
constexpr int32_t x() const
Returns x-axis value of SkIPoint.
Definition: SkPoint.h:43
SkMatrix::getMaxScale
SkScalar getMaxScale() const
Returns the maximum scaling factor of SkMatrix by decomposing the scaling and skewing elements.
SkMatrix::mapRect
SkRect mapRect(const SkRect &src, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
Returns bounds of src corners mapped by SkMatrix.
Definition: SkMatrix.h:1567
SkMatrix::mapRectScaleTranslate
void mapRectScaleTranslate(SkRect *dst, const SkRect &src) const
Sets dst to bounds of src corners mapped by SkMatrix.
SkMatrix::setSkew
SkMatrix & setSkew(SkScalar kx, SkScalar ky, SkScalar px, SkScalar py)
Sets SkMatrix to skew by kx and ky, about a pivot point at (px, py).
SkMatrix::mapVectors
void mapVectors(SkVector dst[], const SkVector src[], int count) const
Maps src vector array of length count to vector SkPoint array of equal or greater length.
SkMatrix::setIdentity
SkMatrix & setIdentity()
Sets SkMatrix to identity; which has no effect on mapped SkPoint.
Definition: SkMatrix.h:608
SkMatrix::kCenter_ScaleToFit
@ kCenter_ScaleToFit
scales and aligns to center
Definition: SkMatrix.h:121
SkMatrix::postScale
SkMatrix & postScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
Sets SkMatrix to SkMatrix constructed from scaling by (sx, sy) about pivot point (px,...
SkMatrix::mapHomogeneousPoints
void mapHomogeneousPoints(SkPoint3 dst[], const SkPoint3 src[], int count) const
Maps src SkPoint3 array of length count to dst SkPoint3 array, which must of length count or greater.
SkMatrix::postScale
SkMatrix & postScale(SkScalar sx, SkScalar sy)
Sets SkMatrix to SkMatrix constructed from scaling by (sx, sy) about pivot point (0,...
SkMatrix::getType
TypeMask getType() const
Returns a bit field describing the transformations the matrix may perform.
Definition: SkMatrix.h:189
SkMatrix::operator[]
SkScalar operator[](int index) const
Returns one matrix value.
Definition: SkMatrix.h:362
SkMatrix::operator[]
SkScalar & operator[](int index)
Returns writable SkMatrix value.
Definition: SkMatrix.h:458
SkMatrix::mapPoints
void mapPoints(SkPoint dst[], const SkPoint src[], int count) const
Maps src SkPoint array of length count to dst SkPoint array of equal or greater length.
SkMatrix::mapRect
bool mapRect(SkRect *dst, const SkRect &src, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
Sets dst to bounds of src corners mapped by SkMatrix.
SkMatrix::setRotate
SkMatrix & setRotate(SkScalar degrees, SkScalar px, SkScalar py)
Sets SkMatrix to rotate by degrees about a pivot point at (px, py).
SkMatrix::setRotate
SkMatrix & setRotate(SkScalar degrees)
Sets SkMatrix to rotate by degrees about a pivot point at (0, 0).
SkMatrix::operator!=
friend SK_API bool operator!=(const SkMatrix &a, const SkMatrix &b)
Compares a and b; returns true if a and b are not numerically equal.
Definition: SkMatrix.h:1649
SkPoint
Definition: SkPoint.h:160
SkMatrix::isTranslate
bool isTranslate() const
Returns true if SkMatrix is identity, or translates.
Definition: SkMatrix.h:230
SkMatrix::rectStaysRect
bool rectStaysRect() const
Returns true SkMatrix maps SkRect to another SkRect.
Definition: SkMatrix.h:253
SkToBool
static constexpr bool SkToBool(const T &x)
Definition: SkTypes.h:497
SkRect::toQuad
void toQuad(SkPoint quad[4]) const
Returns four points in quad that enclose SkRect ordered as: top-left, top-right, bottom-right,...
SkMatrix::mapVector
SkVector mapVector(SkScalar dx, SkScalar dy) const
Returns vector (dx, dy) multiplied by SkMatrix, treating SkMatrix translation as zero.
Definition: SkMatrix.h:1528
SK_API
#define SK_API
Definition: SkTypes.h:181
SkASSERT
#define SkASSERT(cond)
Definition: SkTypes.h:460
SK_ScalarNearlyZero
#define SK_ScalarNearlyZero
Definition: SkScalar.h:134
SkMatrix::TypeMask
TypeMask
Definition: SkMatrix.h:173
SkMatrix::getSkewY
SkScalar getSkewY() const
Returns scale factor multiplied by x-axis input, contributing to y-axis output.
Definition: SkMatrix.h:412
SkMatrix::preRotate
SkMatrix & preRotate(SkScalar degrees)
Sets SkMatrix to SkMatrix multiplied by SkMatrix constructed from rotating by degrees about pivot poi...
SkMatrix::isFinite
bool isFinite() const
Returns true if all elements of the matrix are finite.
Definition: SkMatrix.h:1813
SkMatrix::SetAffineIdentity
static void SetAffineIdentity(SkScalar affine[6])
Fills affine with identity values in column major order.
SkMatrix::getTranslateY
SkScalar getTranslateY() const
Returns translation contributing to y-axis output.
Definition: SkMatrix.h:434
SkMatrix::mapHomogeneousPoints
void mapHomogeneousPoints(SkPoint3 dst[], const SkPoint src[], int count) const
Returns homogeneous points, starting with 2D src points (with implied w = 1).
SkMatrix::getPerspX
SkScalar getPerspX() const
Returns factor scaling input x-axis relative to input y-axis.
Definition: SkMatrix.h:440
SkPoint::fY
SkScalar fY
y-axis value
Definition: SkPoint.h:162
SkMatrix::setScale
SkMatrix & setScale(SkScalar sx, SkScalar sy)
Sets SkMatrix to scale by sx and sy about at pivot point at (0, 0).
SkMatrix::setSinCos
SkMatrix & setSinCos(SkScalar sinValue, SkScalar cosValue)
Sets SkMatrix to rotate by sinValue and cosValue, about a pivot point at (0, 0).
SkSize
Definition: SkSize.h:49
SkMatrix::setAll
SkMatrix & setAll(SkScalar scaleX, SkScalar skewX, SkScalar transX, SkScalar skewY, SkScalar scaleY, SkScalar transY, SkScalar persp0, SkScalar persp1, SkScalar persp2)
Sets all values from parameters.
Definition: SkMatrix.h:544
SkMatrix::kFill_ScaleToFit
@ kFill_ScaleToFit
scales in x and y to fill destination SkRect
Definition: SkMatrix.h:119
SkMatrix::setSkew
SkMatrix & setSkew(SkScalar kx, SkScalar ky)
Sets SkMatrix to skew by kx and ky, about a pivot point at (0, 0).
SkMatrix::mapOrigin
SkPoint mapOrigin() const
Returns (0, 0) multiplied by SkMatrix.
Definition: SkMatrix.h:1419
SkMatrix::setScaleX
SkMatrix & setScaleX(SkScalar v)
Sets horizontal scale factor.
Definition: SkMatrix.h:482
SkMatrix::mapPoint
SkPoint mapPoint(SkPoint pt) const
Returns SkPoint pt multiplied by SkMatrix.
Definition: SkMatrix.h:1356
SkMatrix::Translate
static SkMatrix SK_WARN_UNUSED_RESULT Translate(SkScalar dx, SkScalar dy)
Sets SkMatrix to translate by (dx, dy).
Definition: SkMatrix.h:85
SkMatrix::hasPerspective
bool hasPerspective() const
Returns true if the matrix contains perspective elements.
Definition: SkMatrix.h:294
SkMatrix::decomposeScale
bool decomposeScale(SkSize *scale, SkMatrix *remaining=nullptr) const
Decomposes SkMatrix into scale components and whatever remains.
SkMatrix::setTranslate
SkMatrix & setTranslate(const SkVector &v)
Sets SkMatrix to translate by (v.fX, v.fY).
Definition: SkMatrix.h:621
SkMatrix::getTranslateX
SkScalar getTranslateX() const
Returns translation contributing to x-axis output.
Definition: SkMatrix.h:427
SkMatrix::preSkew
SkMatrix & preSkew(SkScalar kx, SkScalar ky)
Sets SkMatrix to SkMatrix multiplied by SkMatrix constructed from skewing by (kx, ky) about pivot poi...
SkMatrix::ScaleToFit
ScaleToFit
Definition: SkMatrix.h:118
SkMatrix::getScaleY
SkScalar getScaleY() const
Returns scale factor multiplied by y-axis input, contributing to y-axis output.
Definition: SkMatrix.h:404
SkMatrix::isIdentity
bool isIdentity() const
Returns true if SkMatrix is identity.
Definition: SkMatrix.h:205
SkMatrix::postConcat
SkMatrix & postConcat(const SkMatrix &other)
Sets SkMatrix to SkMatrix other multiplied by SkMatrix.
SkMatrix::preRotate
SkMatrix & preRotate(SkScalar degrees, SkScalar px, SkScalar py)
Sets SkMatrix to SkMatrix multiplied by SkMatrix constructed from rotating by degrees about pivot poi...
SkScalar
float SkScalar
Definition: SkScalar.h:16
SkMatrix::get9
void get9(SkScalar buffer[9]) const
Copies nine scalar values contained by SkMatrix into buffer, in member value ascending order: kMScale...
Definition: SkMatrix.h:566
SkMatrix::postTranslate
SkMatrix & postTranslate(SkScalar dx, SkScalar dy)
Sets SkMatrix to SkMatrix constructed from translation (dx, dy) multiplied by SkMatrix.
SkMatrix::setSkewX
SkMatrix & setSkewX(SkScalar v)
Sets horizontal skew factor.
Definition: SkMatrix.h:500
SkMatrix::preservesAxisAlignment
bool preservesAxisAlignment() const
Returns true SkMatrix maps SkRect to another SkRect.
Definition: SkMatrix.h:281
SkMatrix::preConcat
SkMatrix & preConcat(const SkMatrix &other)
Sets SkMatrix to SkMatrix multiplied by SkMatrix other.
SkMatrix::mapRadius
SkScalar mapRadius(SkScalar radius) const
Returns geometric mean radius of ellipse formed by constructing circle of size radius,...
SkMatrix::I
static const SkMatrix & I()
Returns reference to const identity SkMatrix.
SkApplyPerspectiveClip::kNo
@ kNo
Don't pre-clip the geometry before applying the (perspective) matrix.
SkScalarsAreFinite
static bool SkScalarsAreFinite(SkScalar a, SkScalar b)
Definition: SkScalar.h:73
SkMatrix::RectToRect
static SkMatrix SK_WARN_UNUSED_RESULT RectToRect(const SkRect &src, const SkRect &dst, ScaleToFit mode=kFill_ScaleToFit)
Returns SkMatrix set to scale and translate src to dst.
Definition: SkMatrix.h:139
SkMatrix::operator==
friend SK_API bool operator==(const SkMatrix &a, const SkMatrix &b)
Compares a and b; returns true if a and b are numerically equal.
SkMatrix::preScale
SkMatrix & preScale(SkScalar sx, SkScalar sy)
Sets SkMatrix to SkMatrix multiplied by SkMatrix constructed from scaling by (sx, sy) about pivot poi...
SkMatrix::preservesRightAngles
bool preservesRightAngles(SkScalar tol=SK_ScalarNearlyZero) const
Returns true if SkMatrix contains only translation, rotation, reflection, and scale.
SkRadiansToDegrees
#define SkRadiansToDegrees(radians)
Definition: SkScalar.h:113
SkMatrix::asAffine
bool SK_WARN_UNUSED_RESULT asAffine(SkScalar affine[6]) const
Fills affine in column major order.
SkPoint::fX
SkScalar fX
x-axis value
Definition: SkPoint.h:161
SkMatrix::setScaleY
SkMatrix & setScaleY(SkScalar v)
Sets vertical scale factor.
Definition: SkMatrix.h:488
SkMatrix::Translate
static SkMatrix SK_WARN_UNUSED_RESULT Translate(SkVector t)
Definition: SkMatrix.h:90
SkMatrix::getMinMaxScales
bool SK_WARN_UNUSED_RESULT getMinMaxScales(SkScalar scaleFactors[2]) const
Sets scaleFactors[0] to the minimum scaling factor, and scaleFactors[1] to the maximum scaling factor...
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::mapVectors
void mapVectors(SkVector vecs[], int count) const
Maps vecs vector array of length count in place, multiplying each vector by SkMatrix,...
Definition: SkMatrix.h:1485
SkMatrix::setScale
SkMatrix & setScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
Sets SkMatrix to scale by sx and sy, about a pivot point at (px, py).
SK_WARN_UNUSED_RESULT
#define SK_WARN_UNUSED_RESULT
Definition: SkTypes.h:60
SkPoint::y
constexpr SkScalar y() const
Returns y-axis value of SkPoint or vector.
Definition: SkPoint.h:184
SkMatrix::get
SkScalar get(int index) const
Returns one matrix value.
Definition: SkMatrix.h:374
SkMatrix::invert
bool SK_WARN_UNUSED_RESULT invert(SkMatrix *inverse) const
Sets inverse to reciprocal matrix, returning true if SkMatrix can be inverted.
Definition: SkMatrix.h:1188
SkApplyPerspectiveClip
SkApplyPerspectiveClip
When we transform points through a matrix containing perspective (the bottom row is something other t...
Definition: SkMatrix.h:27
SkMatrix::mapRect
bool mapRect(SkRect *rect, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
Sets rect to bounds of rect corners mapped by SkMatrix.
Definition: SkMatrix.h:1558
SkMatrix::setPerspY
SkMatrix & setPerspY(SkScalar v)
Sets input y-axis perspective factor, which causes mapXY() to vary input y-axis values inversely prop...
Definition: SkMatrix.h:526
SkMatrix::setConcat
SkMatrix & setConcat(const SkMatrix &a, const SkMatrix &b)
Sets SkMatrix to SkMatrix a multiplied by SkMatrix b.
SkMatrix::postSkew
SkMatrix & postSkew(SkScalar kx, SkScalar ky, SkScalar px, SkScalar py)
Sets SkMatrix to SkMatrix constructed from skewing by (kx, ky) about pivot point (px,...
SkMatrix::InvalidMatrix
static const SkMatrix & InvalidMatrix()
Returns reference to a const SkMatrix with invalid values.
SkMatrix::setTranslateY
SkMatrix & setTranslateY(SkScalar v)
Sets vertical translation.
Definition: SkMatrix.h:512
SkMatrix::isScaleTranslate
bool isScaleTranslate() const
Returns true if SkMatrix at most scales and translates.
Definition: SkMatrix.h:218
SkMatrix::setAffine
SkMatrix & setAffine(const SkScalar affine[6])
Sets SkMatrix to affine values, passed in column major order.
SkMatrix::MakeRectToRect
static SkMatrix MakeRectToRect(const SkRect &src, const SkRect &dst, ScaleToFit stf)
Returns SkMatrix set to scale and translate src SkRect to dst SkRect.
Definition: SkMatrix.h:1154
SkRect
Definition: SkRect.h:572
SkMatrix::getMinScale
SkScalar getMinScale() const
Returns the minimum scaling factor of SkMatrix by decomposing the scaling and skewing elements.
SkMatrix::Translate
static SkMatrix SK_WARN_UNUSED_RESULT Translate(SkIVector t)
Definition: SkMatrix.h:91
SkMatrix::mapXY
SkPoint mapXY(SkScalar x, SkScalar y) const
Returns SkPoint (x, y) multiplied by SkMatrix.
Definition: SkMatrix.h:1398
SkMatrix::preTranslate
SkMatrix & preTranslate(SkScalar dx, SkScalar dy)
Sets SkMatrix to SkMatrix multiplied by SkMatrix constructed from translation (dx,...
SkIPoint
Definition: SkPoint.h:25
SkMatrix::getPerspY
SkScalar getPerspY() const
Returns factor scaling input y-axis relative to input x-axis.
Definition: SkMatrix.h:446
SkMatrix::setTranslateX
SkMatrix & setTranslateX(SkScalar v)
Sets horizontal translation.
Definition: SkMatrix.h:506
SkMatrix::Concat
static SkMatrix Concat(const SkMatrix &a, const SkMatrix &b)
Returns SkMatrix a multiplied by SkMatrix b.
Definition: SkMatrix.h:1757
SkMatrix::set9
SkMatrix & set9(const SkScalar buffer[9])
Sets SkMatrix to nine scalar values in buffer, in member value ascending order: kMScaleX,...
SkMatrix::kStart_ScaleToFit
@ kStart_ScaleToFit
scales and aligns to left and top
Definition: SkMatrix.h:120
SkMatrix::setSinCos
SkMatrix & setSinCos(SkScalar sinValue, SkScalar cosValue, SkScalar px, SkScalar py)
Sets SkMatrix to rotate by sinValue and cosValue, about a pivot point at (px, py).
SkMatrix::setRectToRect
bool setRectToRect(const SkRect &src, const SkRect &dst, ScaleToFit stf)
Sets SkMatrix to scale and translate src SkRect to dst SkRect.
SkMatrix::MakeAll
static SkMatrix SK_WARN_UNUSED_RESULT MakeAll(SkScalar scaleX, SkScalar skewX, SkScalar transX, SkScalar skewY, SkScalar scaleY, SkScalar transY, SkScalar pers0, SkScalar pers1, SkScalar pers2)
Sets SkMatrix to:
Definition: SkMatrix.h:161
SkMatrix::setPolyToPoly
bool setPolyToPoly(const SkPoint src[], const SkPoint dst[], int count)
Sets SkMatrix to map src to dst.
SkMatrix::normalizePerspective
void normalizePerspective()
A matrix is categorized as 'perspective' if the bottom row is not [0, 0, 1].
Definition: SkMatrix.h:1252
SkMatrix::isSimilarity
bool isSimilarity(SkScalar tol=SK_ScalarNearlyZero) const
Returns true if SkMatrix contains only translation, rotation, reflection, and uniform scale.
SkPoint::x
constexpr SkScalar x() const
Returns x-axis value of SkPoint or vector.
Definition: SkPoint.h:178