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/SkPoint.h"
12 #include "include/core/SkRect.h"
13 #include "include/core/SkScalar.h"
14 #include "include/core/SkTypes.h"
15 #include "include/private/base/SkMacros.h"
16 #include "include/private/base/SkTo.h"
17 
18 #include <cstdint>
19 #include <cstring>
20 
21 struct SkPoint3;
22 struct SkRSXform;
23 struct SkSize;
24 
25 // Remove when clients are updated to live without this
26 #define SK_SUPPORT_LEGACY_MATRIX_RECTTORECT
27 
35  kNo,
36  kYes,
37 };
38 
52 SK_BEGIN_REQUIRE_DENSE
53 class SK_API SkMatrix {
54 public:
55 
62  constexpr SkMatrix() : SkMatrix(1,0,0, 0,1,0, 0,0,1, kIdentity_Mask | kRectStaysRect_Mask) {}
63 
74  [[nodiscard]] static SkMatrix Scale(SkScalar sx, SkScalar sy) {
75  SkMatrix m;
76  m.setScale(sx, sy);
77  return m;
78  }
79 
90  [[nodiscard]] static SkMatrix Translate(SkScalar dx, SkScalar dy) {
91  SkMatrix m;
92  m.setTranslate(dx, dy);
93  return m;
94  }
95  [[nodiscard]] static SkMatrix Translate(SkVector t) { return Translate(t.x(), t.y()); }
96  [[nodiscard]] static SkMatrix Translate(SkIVector t) { return Translate(t.x(), t.y()); }
97 
103  [[nodiscard]] static SkMatrix RotateDeg(SkScalar deg) {
104  SkMatrix m;
105  m.setRotate(deg);
106  return m;
107  }
108  [[nodiscard]] static SkMatrix RotateDeg(SkScalar deg, SkPoint pt) {
109  SkMatrix m;
110  m.setRotate(deg, pt.x(), pt.y());
111  return m;
112  }
113  [[nodiscard]] static SkMatrix RotateRad(SkScalar rad) {
114  return RotateDeg(SkRadiansToDegrees(rad));
115  }
116 
123  [[nodiscard]] static SkMatrix Skew(SkScalar kx, SkScalar ky) {
124  SkMatrix m;
125  m.setSkew(kx, ky);
126  return m;
127  }
128 
135  enum ScaleToFit {
140  };
141 
156  [[nodiscard]] static SkMatrix RectToRect(const SkRect& src, const SkRect& dst,
157  ScaleToFit mode = kFill_ScaleToFit) {
158  return MakeRectToRect(src, dst, mode);
159  }
160 
178  [[nodiscard]] static SkMatrix MakeAll(SkScalar scaleX, SkScalar skewX, SkScalar transX,
179  SkScalar skewY, SkScalar scaleY, SkScalar transY,
180  SkScalar pers0, SkScalar pers1, SkScalar pers2) {
181  SkMatrix m;
182  m.setAll(scaleX, skewX, transX, skewY, scaleY, transY, pers0, pers1, pers2);
183  return m;
184  }
185 
190  enum TypeMask {
191  kIdentity_Mask = 0,
192  kTranslate_Mask = 0x01,
193  kScale_Mask = 0x02,
194  kAffine_Mask = 0x04,
195  kPerspective_Mask = 0x08,
196  };
197 
206  TypeMask getType() const {
207  if (fTypeMask & kUnknown_Mask) {
208  fTypeMask = this->computeTypeMask();
209  }
210  // only return the public masks
211  return (TypeMask)(fTypeMask & 0xF);
212  }
213 
222  bool isIdentity() const {
223  return this->getType() == 0;
224  }
225 
235  bool isScaleTranslate() const {
236  return !(this->getType() & ~(kScale_Mask | kTranslate_Mask));
237  }
238 
247  bool isTranslate() const { return !(this->getType() & ~(kTranslate_Mask)); }
248 
270  bool rectStaysRect() const {
271  if (fTypeMask & kUnknown_Mask) {
272  fTypeMask = this->computeTypeMask();
273  }
274  return (fTypeMask & kRectStaysRect_Mask) != 0;
275  }
276 
298  bool preservesAxisAlignment() const { return this->rectStaysRect(); }
299 
311  bool hasPerspective() const {
312  return SkToBool(this->getPerspectiveTypeMaskOnly() &
313  kPerspective_Mask);
314  }
315 
333 
348 
352  static constexpr int kMScaleX = 0;
353  static constexpr int kMSkewX = 1;
354  static constexpr int kMTransX = 2;
355  static constexpr int kMSkewY = 3;
356  static constexpr int kMScaleY = 4;
357  static constexpr int kMTransY = 5;
358  static constexpr int kMPersp0 = 6;
359  static constexpr int kMPersp1 = 7;
360  static constexpr int kMPersp2 = 8;
361 
365  static constexpr int kAScaleX = 0;
366  static constexpr int kASkewY = 1;
367  static constexpr int kASkewX = 2;
368  static constexpr int kAScaleY = 3;
369  static constexpr int kATransX = 4;
370  static constexpr int kATransY = 5;
371 
379  SkScalar operator[](int index) const {
380  SkASSERT((unsigned)index < 9);
381  return fMat[index];
382  }
383 
391  SkScalar get(int index) const {
392  SkASSERT((unsigned)index < 9);
393  return fMat[index];
394  }
395 
403  SkScalar rc(int r, int c) const {
404  SkASSERT(r >= 0 && r <= 2);
405  SkASSERT(c >= 0 && c <= 2);
406  return fMat[r*3 + c];
407  }
408 
414  SkScalar getScaleX() const { return fMat[kMScaleX]; }
415 
421  SkScalar getScaleY() const { return fMat[kMScaleY]; }
422 
429  SkScalar getSkewY() const { return fMat[kMSkewY]; }
430 
437  SkScalar getSkewX() const { return fMat[kMSkewX]; }
438 
444  SkScalar getTranslateX() const { return fMat[kMTransX]; }
445 
451  SkScalar getTranslateY() const { return fMat[kMTransY]; }
452 
457  SkScalar getPerspX() const { return fMat[kMPersp0]; }
458 
463  SkScalar getPerspY() const { return fMat[kMPersp1]; }
464 
475  SkScalar& operator[](int index) {
476  SkASSERT((unsigned)index < 9);
477  this->setTypeMask(kUnknown_Mask);
478  return fMat[index];
479  }
480 
488  SkMatrix& set(int index, SkScalar value) {
489  SkASSERT((unsigned)index < 9);
490  fMat[index] = value;
491  this->setTypeMask(kUnknown_Mask);
492  return *this;
493  }
494 
499  SkMatrix& setScaleX(SkScalar v) { return this->set(kMScaleX, v); }
500 
505  SkMatrix& setScaleY(SkScalar v) { return this->set(kMScaleY, v); }
506 
511  SkMatrix& setSkewY(SkScalar v) { return this->set(kMSkewY, v); }
512 
517  SkMatrix& setSkewX(SkScalar v) { return this->set(kMSkewX, v); }
518 
523  SkMatrix& setTranslateX(SkScalar v) { return this->set(kMTransX, v); }
524 
529  SkMatrix& setTranslateY(SkScalar v) { return this->set(kMTransY, v); }
530 
536  SkMatrix& setPerspX(SkScalar v) { return this->set(kMPersp0, v); }
537 
543  SkMatrix& setPerspY(SkScalar v) { return this->set(kMPersp1, v); }
544 
561  SkMatrix& setAll(SkScalar scaleX, SkScalar skewX, SkScalar transX,
562  SkScalar skewY, SkScalar scaleY, SkScalar transY,
563  SkScalar persp0, SkScalar persp1, SkScalar persp2) {
564  fMat[kMScaleX] = scaleX;
565  fMat[kMSkewX] = skewX;
566  fMat[kMTransX] = transX;
567  fMat[kMSkewY] = skewY;
568  fMat[kMScaleY] = scaleY;
569  fMat[kMTransY] = transY;
570  fMat[kMPersp0] = persp0;
571  fMat[kMPersp1] = persp1;
572  fMat[kMPersp2] = persp2;
573  this->setTypeMask(kUnknown_Mask);
574  return *this;
575  }
576 
583  void get9(SkScalar buffer[9]) const {
584  memcpy(buffer, fMat, 9 * sizeof(SkScalar));
585  }
586 
603  SkMatrix& set9(const SkScalar buffer[9]);
604 
615 
625  SkMatrix& setIdentity() { return this->reset(); }
626 
633 
638  SkMatrix& setTranslate(const SkVector& v) { return this->setTranslate(v.fX, v.fY); }
639 
649 
656 
667 
674 
686  SkMatrix& setSinCos(SkScalar sinValue, SkScalar cosValue,
687  SkScalar px, SkScalar py);
688 
697  SkMatrix& setSinCos(SkScalar sinValue, SkScalar cosValue);
698 
710  SkMatrix& setRSXform(const SkRSXform& rsxForm);
711 
721 
728 
746  SkMatrix& setConcat(const SkMatrix& a, const SkMatrix& b);
747 
767 
795 
816 
847 
874 
902 
923 
941  SkMatrix& preConcat(const SkMatrix& other);
942 
962 
990 
1011 
1042 
1069 
1097 
1118 
1136  SkMatrix& postConcat(const SkMatrix& other);
1137 
1138 #ifndef SK_SUPPORT_LEGACY_MATRIX_RECTTORECT
1139 private:
1140 #endif
1156  bool setRectToRect(const SkRect& src, const SkRect& dst, ScaleToFit stf);
1157 
1171  static SkMatrix MakeRectToRect(const SkRect& src, const SkRect& dst, ScaleToFit stf) {
1172  SkMatrix m;
1173  m.setRectToRect(src, dst, stf);
1174  return m;
1175  }
1176 #ifndef SK_SUPPORT_LEGACY_MATRIX_RECTTORECT
1177 public:
1178 #endif
1179 
1195  bool setPolyToPoly(const SkPoint src[], const SkPoint dst[], int count);
1196 
1205  [[nodiscard]] bool invert(SkMatrix* inverse) const {
1206  // Allow the trivial case to be inlined.
1207  if (this->isIdentity()) {
1208  if (inverse) {
1209  inverse->reset();
1210  }
1211  return true;
1212  }
1213  return this->invertNonIdentity(inverse);
1214  }
1215 
1228  static void SetAffineIdentity(SkScalar affine[6]);
1229 
1240  [[nodiscard]] bool asAffine(SkScalar affine[6]) const;
1241 
1256  SkMatrix& setAffine(const SkScalar affine[6]);
1257 
1270  if (fMat[8] != 1) {
1271  this->doNormalizePerspective();
1272  }
1273  }
1274 
1303  void mapPoints(SkPoint dst[], const SkPoint src[], int count) const;
1304 
1328  void mapPoints(SkPoint pts[], int count) const {
1329  this->mapPoints(pts, pts, count);
1330  }
1331 
1351  void mapHomogeneousPoints(SkPoint3 dst[], const SkPoint3 src[], int count) const;
1352 
1356  void mapHomogeneousPoints(SkPoint3 dst[], const SkPoint src[], int count) const;
1357 
1373  SkPoint mapPoint(SkPoint pt) const {
1374  SkPoint result;
1375  this->mapXY(pt.x(), pt.y(), &result);
1376  return result;
1377  }
1378 
1397  void mapXY(SkScalar x, SkScalar y, SkPoint* result) const;
1398 
1415  SkPoint mapXY(SkScalar x, SkScalar y) const {
1416  SkPoint result;
1417  this->mapXY(x,y, &result);
1418  return result;
1419  }
1420 
1421 
1436  SkPoint mapOrigin() const {
1437  SkScalar x = this->getTranslateX(),
1438  y = this->getTranslateY();
1439  if (this->hasPerspective()) {
1440  SkScalar w = fMat[kMPersp2];
1441  if (w) { w = 1 / w; }
1442  x *= w;
1443  y *= w;
1444  }
1445  return {x, y};
1446  }
1447 
1477  void mapVectors(SkVector dst[], const SkVector src[], int count) const;
1478 
1502  void mapVectors(SkVector vecs[], int count) const {
1503  this->mapVectors(vecs, vecs, count);
1504  }
1505 
1523  void mapVector(SkScalar dx, SkScalar dy, SkVector* result) const {
1524  SkVector vec = { dx, dy };
1525  this->mapVectors(result, &vec, 1);
1526  }
1527 
1545  SkVector mapVector(SkScalar dx, SkScalar dy) const {
1546  SkVector vec = { dx, dy };
1547  this->mapVectors(&vec, &vec, 1);
1548  return vec;
1549  }
1550 
1563  bool mapRect(SkRect* dst, const SkRect& src,
1565 
1576  return this->mapRect(rect, *rect, pc);
1577  }
1578 
1584  SkRect mapRect(const SkRect& src,
1586  SkRect dst;
1587  (void)this->mapRect(&dst, src, pc);
1588  return dst;
1589  }
1590 
1619  void mapRectToQuad(SkPoint dst[4], const SkRect& rect) const {
1620  // This could potentially be faster if we only transformed each x and y of the rect once.
1621  rect.toQuad(dst);
1622  this->mapPoints(dst, 4);
1623  }
1624 
1634  void mapRectScaleTranslate(SkRect* dst, const SkRect& src) const;
1635 
1646  SkScalar mapRadius(SkScalar radius) const;
1647 
1656  friend SK_API bool operator==(const SkMatrix& a, const SkMatrix& b);
1657 
1666  friend SK_API bool operator!=(const SkMatrix& a, const SkMatrix& b) {
1667  return !(a == b);
1668  }
1669 
1676  void dump() const;
1677 
1687 
1697 
1708  [[nodiscard]] bool getMinMaxScales(SkScalar scaleFactors[2]) const;
1709 
1729  bool decomposeScale(SkSize* scale, SkMatrix* remaining = nullptr) const;
1730 
1741  static const SkMatrix& I();
1742 
1754  static const SkMatrix& InvalidMatrix();
1755 
1774  static SkMatrix Concat(const SkMatrix& a, const SkMatrix& b) {
1775  SkMatrix result;
1776  result.setConcat(a, b);
1777  return result;
1778  }
1779 
1780  friend SkMatrix operator*(const SkMatrix& a, const SkMatrix& b) {
1781  return Concat(a, b);
1782  }
1783 
1788  this->setTypeMask(kUnknown_Mask);
1789  }
1790 
1803  fMat[kMScaleX] = sx;
1804  fMat[kMSkewX] = 0;
1805  fMat[kMTransX] = tx;
1806 
1807  fMat[kMSkewY] = 0;
1808  fMat[kMScaleY] = sy;
1809  fMat[kMTransY] = ty;
1810 
1811  fMat[kMPersp0] = 0;
1812  fMat[kMPersp1] = 0;
1813  fMat[kMPersp2] = 1;
1814 
1815  int mask = 0;
1816  if (sx != 1 || sy != 1) {
1817  mask |= kScale_Mask;
1818  }
1819  if (tx != 0.0f || ty != 0.0f) {
1820  mask |= kTranslate_Mask;
1821  }
1822  if (sx != 0 && sy != 0) {
1823  mask |= kRectStaysRect_Mask;
1824  }
1825  this->setTypeMask(mask);
1826  }
1827 
1833  bool isFinite() const { return SkScalarsAreFinite(fMat, 9); }
1834 
1835 private:
1842  static constexpr int kRectStaysRect_Mask = 0x10;
1843 
1847  static constexpr int kOnlyPerspectiveValid_Mask = 0x40;
1848 
1849  static constexpr int kUnknown_Mask = 0x80;
1850 
1851  static constexpr int kORableMasks = kTranslate_Mask |
1852  kScale_Mask |
1853  kAffine_Mask |
1854  kPerspective_Mask;
1855 
1856  static constexpr int kAllMasks = kTranslate_Mask |
1857  kScale_Mask |
1858  kAffine_Mask |
1859  kPerspective_Mask |
1860  kRectStaysRect_Mask;
1861 
1862  SkScalar fMat[9];
1863  mutable int32_t fTypeMask;
1864 
1865  constexpr SkMatrix(SkScalar sx, SkScalar kx, SkScalar tx,
1866  SkScalar ky, SkScalar sy, SkScalar ty,
1867  SkScalar p0, SkScalar p1, SkScalar p2, int typeMask)
1868  : fMat{sx, kx, tx,
1869  ky, sy, ty,
1870  p0, p1, p2}
1871  , fTypeMask(typeMask) {}
1872 
1873  static void ComputeInv(SkScalar dst[9], const SkScalar src[9], double invDet, bool isPersp);
1874 
1875  uint8_t computeTypeMask() const;
1876  uint8_t computePerspectiveTypeMask() const;
1877 
1878  void setTypeMask(int mask) {
1879  // allow kUnknown or a valid mask
1880  SkASSERT(kUnknown_Mask == mask || (mask & kAllMasks) == mask ||
1881  ((kUnknown_Mask | kOnlyPerspectiveValid_Mask) & mask)
1882  == (kUnknown_Mask | kOnlyPerspectiveValid_Mask));
1883  fTypeMask = mask;
1884  }
1885 
1886  void orTypeMask(int mask) {
1887  SkASSERT((mask & kORableMasks) == mask);
1888  fTypeMask |= mask;
1889  }
1890 
1891  void clearTypeMask(int mask) {
1892  // only allow a valid mask
1893  SkASSERT((mask & kAllMasks) == mask);
1894  fTypeMask &= ~mask;
1895  }
1896 
1897  TypeMask getPerspectiveTypeMaskOnly() const {
1898  if ((fTypeMask & kUnknown_Mask) &&
1899  !(fTypeMask & kOnlyPerspectiveValid_Mask)) {
1900  fTypeMask = this->computePerspectiveTypeMask();
1901  }
1902  return (TypeMask)(fTypeMask & 0xF);
1903  }
1904 
1908  bool isTriviallyIdentity() const {
1909  if (fTypeMask & kUnknown_Mask) {
1910  return false;
1911  }
1912  return ((fTypeMask & 0xF) == 0);
1913  }
1914 
1915  inline void updateTranslateMask() {
1916  if ((fMat[kMTransX] != 0) | (fMat[kMTransY] != 0)) {
1917  fTypeMask |= kTranslate_Mask;
1918  } else {
1919  fTypeMask &= ~kTranslate_Mask;
1920  }
1921  }
1922 
1923  typedef void (*MapXYProc)(const SkMatrix& mat, SkScalar x, SkScalar y,
1924  SkPoint* result);
1925 
1926  static MapXYProc GetMapXYProc(TypeMask mask) {
1927  SkASSERT((mask & ~kAllMasks) == 0);
1928  return gMapXYProcs[mask & kAllMasks];
1929  }
1930 
1931  MapXYProc getMapXYProc() const {
1932  return GetMapXYProc(this->getType());
1933  }
1934 
1935  typedef void (*MapPtsProc)(const SkMatrix& mat, SkPoint dst[],
1936  const SkPoint src[], int count);
1937 
1938  static MapPtsProc GetMapPtsProc(TypeMask mask) {
1939  SkASSERT((mask & ~kAllMasks) == 0);
1940  return gMapPtsProcs[mask & kAllMasks];
1941  }
1942 
1943  MapPtsProc getMapPtsProc() const {
1944  return GetMapPtsProc(this->getType());
1945  }
1946 
1947  [[nodiscard]] bool invertNonIdentity(SkMatrix* inverse) const;
1948 
1949  static bool Poly2Proc(const SkPoint[], SkMatrix*);
1950  static bool Poly3Proc(const SkPoint[], SkMatrix*);
1951  static bool Poly4Proc(const SkPoint[], SkMatrix*);
1952 
1953  static void Identity_xy(const SkMatrix&, SkScalar, SkScalar, SkPoint*);
1954  static void Trans_xy(const SkMatrix&, SkScalar, SkScalar, SkPoint*);
1955  static void Scale_xy(const SkMatrix&, SkScalar, SkScalar, SkPoint*);
1956  static void ScaleTrans_xy(const SkMatrix&, SkScalar, SkScalar, SkPoint*);
1957  static void Rot_xy(const SkMatrix&, SkScalar, SkScalar, SkPoint*);
1958  static void RotTrans_xy(const SkMatrix&, SkScalar, SkScalar, SkPoint*);
1959  static void Persp_xy(const SkMatrix&, SkScalar, SkScalar, SkPoint*);
1960 
1961  static const MapXYProc gMapXYProcs[];
1962 
1963  static void Identity_pts(const SkMatrix&, SkPoint[], const SkPoint[], int);
1964  static void Trans_pts(const SkMatrix&, SkPoint dst[], const SkPoint[], int);
1965  static void Scale_pts(const SkMatrix&, SkPoint dst[], const SkPoint[], int);
1966  static void ScaleTrans_pts(const SkMatrix&, SkPoint dst[], const SkPoint[],
1967  int count);
1968  static void Persp_pts(const SkMatrix&, SkPoint dst[], const SkPoint[], int);
1969 
1970  static void Affine_vpts(const SkMatrix&, SkPoint dst[], const SkPoint[], int);
1971 
1972  static const MapPtsProc gMapPtsProcs[];
1973 
1974  // return the number of bytes written, whether or not buffer is null
1975  size_t writeToMemory(void* buffer) const;
1984  size_t readFromMemory(const void* buffer, size_t length);
1985 
1986  // legacy method -- still needed? why not just postScale(1/divx, ...)?
1987  bool postIDiv(int divx, int divy);
1988  void doNormalizePerspective();
1989 
1990  friend class SkPerspIter;
1991  friend class SkMatrixPriv;
1992  friend class SerializationTest;
1993 };
1994 SK_END_REQUIRE_DENSE
1995 
1996 #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.
static bool SkScalarsAreFinite(SkScalar a, SkScalar b)
Definition: SkScalar.h:70
#define SK_ScalarNearlyZero
Definition: SkScalar.h:111
#define SkRadiansToDegrees(radians)
Definition: SkScalar.h:90
float SkScalar
Definition: SkScalar.h:14
SkMatrix holds a 3x3 matrix for transforming coordinates.
Definition: SkMatrix.h:53
static const SkMatrix & InvalidMatrix()
Returns reference to a const SkMatrix with invalid values.
SkMatrix & set(int index, SkScalar value)
Sets SkMatrix value.
Definition: SkMatrix.h:488
SkScalar mapRadius(SkScalar radius) const
Returns geometric mean radius of ellipse formed by constructing circle of size radius,...
SkMatrix & postSkew(SkScalar kx, SkScalar ky)
Sets SkMatrix to SkMatrix constructed from skewing by (kx, ky) about pivot point (0,...
SkMatrix & setSkewY(SkScalar v)
Sets vertical skew factor.
Definition: SkMatrix.h:511
SkMatrix & postRotate(SkScalar degrees)
Sets SkMatrix to SkMatrix constructed from rotating by degrees about pivot point (0,...
static const SkMatrix & I()
Returns reference to const identity SkMatrix.
SkScalar getPerspY() const
Returns factor scaling input y-axis relative to input x-axis.
Definition: SkMatrix.h:463
SkMatrix & setRSXform(const SkRSXform &rsxForm)
Sets SkMatrix to rotate, scale, and translate using a compressed matrix form.
static SkMatrix RectToRect(const SkRect &src, const SkRect &dst, ScaleToFit mode=kFill_ScaleToFit)
Returns SkMatrix set to scale and translate src to dst.
Definition: SkMatrix.h:156
SkMatrix & setScale(SkScalar sx, SkScalar sy)
Sets SkMatrix to scale by sx and sy about at pivot point at (0, 0).
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:561
bool getMinMaxScales(SkScalar scaleFactors[2]) const
Sets scaleFactors[0] to the minimum scaling factor, and scaleFactors[1] to the maximum scaling factor...
void mapHomogeneousPoints(SkPoint3 dst[], const SkPoint src[], int count) const
Returns homogeneous points, starting with 2D src points (with implied w = 1).
static SkMatrix RotateDeg(SkScalar deg)
Sets SkMatrix to rotate by |deg| about a pivot point at (0, 0).
Definition: SkMatrix.h:103
SkScalar getSkewY() const
Returns scale factor multiplied by x-axis input, contributing to y-axis output.
Definition: SkMatrix.h:429
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 & setPerspY(SkScalar v)
Sets input y-axis perspective factor, which causes mapXY() to vary input y-axis values inversely prop...
Definition: SkMatrix.h:543
static SkMatrix RotateRad(SkScalar rad)
Definition: SkMatrix.h:113
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.
static SkMatrix Translate(SkIVector t)
Definition: SkMatrix.h:96
static SkMatrix Translate(SkScalar dx, SkScalar dy)
Sets SkMatrix to translate by (dx, dy).
Definition: SkMatrix.h:90
SkMatrix & setSkewX(SkScalar v)
Sets horizontal skew factor.
Definition: SkMatrix.h:517
void mapVectors(SkVector vecs[], int count) const
Maps vecs vector array of length count in place, multiplying each vector by SkMatrix,...
Definition: SkMatrix.h:1502
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...
SkMatrix & setRotate(SkScalar degrees, SkScalar px, SkScalar py)
Sets SkMatrix to rotate by degrees about a pivot point at (px, py).
SkScalar getTranslateY() const
Returns translation contributing to y-axis output.
Definition: SkMatrix.h:451
ScaleToFit
Definition: SkMatrix.h:135
@ kStart_ScaleToFit
scales and aligns to left and top
Definition: SkMatrix.h:137
@ kEnd_ScaleToFit
scales and aligns to right and bottom
Definition: SkMatrix.h:139
@ kCenter_ScaleToFit
scales and aligns to center
Definition: SkMatrix.h:138
@ kFill_ScaleToFit
scales in x and y to fill destination SkRect
Definition: SkMatrix.h:136
static void SetAffineIdentity(SkScalar affine[6])
Fills affine with identity values in column major order.
constexpr SkMatrix()
Creates an identity SkMatrix:
Definition: SkMatrix.h:62
SkScalar rc(int r, int c) const
Returns one matrix value from a particular row/column.
Definition: SkMatrix.h:403
void setScaleTranslate(SkScalar sx, SkScalar sy, SkScalar tx, SkScalar ty)
Initializes SkMatrix with scale and translate elements.
Definition: SkMatrix.h:1802
bool preservesRightAngles(SkScalar tol=SK_ScalarNearlyZero) const
Returns true if SkMatrix contains only translation, rotation, reflection, and scale.
void dump() const
Writes text representation of SkMatrix to standard output.
bool asAffine(SkScalar affine[6]) const
Fills affine in column major order.
SkMatrix & postScale(SkScalar sx, SkScalar sy)
Sets SkMatrix to SkMatrix constructed from scaling by (sx, sy) about pivot point (0,...
SkPoint mapPoint(SkPoint pt) const
Returns SkPoint pt multiplied by SkMatrix.
Definition: SkMatrix.h:1373
SkMatrix & reset()
Sets SkMatrix to identity; which has no effect on mapped SkPoint.
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 & postScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
Sets SkMatrix to SkMatrix constructed from scaling by (sx, sy) about pivot point (px,...
static SkMatrix 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:178
void mapPoints(SkPoint pts[], int count) const
Maps pts SkPoint array of length count in place.
Definition: SkMatrix.h:1328
SkMatrix & preRotate(SkScalar degrees)
Sets SkMatrix to SkMatrix multiplied by SkMatrix constructed from rotating by degrees about pivot poi...
SkMatrix & preSkew(SkScalar kx, SkScalar ky)
Sets SkMatrix to SkMatrix multiplied by SkMatrix constructed from skewing by (kx, ky) about pivot poi...
SkMatrix & setIdentity()
Sets SkMatrix to identity; which has no effect on mapped SkPoint.
Definition: SkMatrix.h:625
SkMatrix & setTranslate(const SkVector &v)
Sets SkMatrix to translate by (v.fX, v.fY).
Definition: SkMatrix.h:638
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).
static SkMatrix Concat(const SkMatrix &a, const SkMatrix &b)
Returns SkMatrix a multiplied by SkMatrix b.
Definition: SkMatrix.h:1774
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...
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:1666
SkMatrix & setRotate(SkScalar degrees)
Sets SkMatrix to rotate by degrees about a pivot point at (0, 0).
SkScalar getSkewX() const
Returns scale factor multiplied by y-axis input, contributing to x-axis output.
Definition: SkMatrix.h:437
bool setPolyToPoly(const SkPoint src[], const SkPoint dst[], int count)
Sets SkMatrix to map src to dst.
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 & setTranslateY(SkScalar v)
Sets vertical translation.
Definition: SkMatrix.h:529
bool invert(SkMatrix *inverse) const
Sets inverse to reciprocal matrix, returning true if SkMatrix can be inverted.
Definition: SkMatrix.h:1205
SkMatrix & preScale(SkScalar sx, SkScalar sy)
Sets SkMatrix to SkMatrix multiplied by SkMatrix constructed from scaling by (sx, sy) about pivot poi...
bool isTranslate() const
Returns true if SkMatrix is identity, or translates.
Definition: SkMatrix.h:247
void mapXY(SkScalar x, SkScalar y, SkPoint *result) const
Maps SkPoint (x, y) to result.
SkMatrix & postTranslate(SkScalar dx, SkScalar dy)
Sets SkMatrix to SkMatrix constructed from translation (dx, dy) multiplied by SkMatrix.
bool rectStaysRect() const
Returns true SkMatrix maps SkRect to another SkRect.
Definition: SkMatrix.h:270
SkScalar & operator[](int index)
Returns writable SkMatrix value.
Definition: SkMatrix.h:475
bool mapRect(SkRect *rect, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
Sets rect to bounds of rect corners mapped by SkMatrix.
Definition: SkMatrix.h:1575
static SkMatrix RotateDeg(SkScalar deg, SkPoint pt)
Definition: SkMatrix.h:108
SkScalar getScaleX() const
Returns scale factor multiplied by x-axis input, contributing to x-axis output.
Definition: SkMatrix.h:414
SkScalar getMinScale() const
Returns the minimum scaling factor of SkMatrix by decomposing the scaling and skewing elements.
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 & setPerspX(SkScalar v)
Sets input x-axis perspective factor, which causes mapXY() to vary input x-axis values inversely prop...
Definition: SkMatrix.h:536
SkMatrix & setScaleX(SkScalar v)
Sets horizontal scale factor.
Definition: SkMatrix.h:499
bool decomposeScale(SkSize *scale, SkMatrix *remaining=nullptr) const
Decomposes SkMatrix into scale components and whatever remains.
SkMatrix & preConcat(const SkMatrix &other)
Sets SkMatrix to SkMatrix multiplied by SkMatrix other.
void get9(SkScalar buffer[9]) const
Copies nine scalar values contained by SkMatrix into buffer, in member value ascending order: kMScale...
Definition: SkMatrix.h:583
SkRect mapRect(const SkRect &src, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
Returns bounds of src corners mapped by SkMatrix.
Definition: SkMatrix.h:1584
void mapRectScaleTranslate(SkRect *dst, const SkRect &src) const
Sets dst to bounds of src corners mapped by SkMatrix.
SkScalar getScaleY() const
Returns scale factor multiplied by y-axis input, contributing to y-axis output.
Definition: SkMatrix.h:421
SkPoint mapOrigin() const
Returns (0, 0) multiplied by SkMatrix.
Definition: SkMatrix.h:1436
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:1171
bool isScaleTranslate() const
Returns true if SkMatrix at most scales and translates.
Definition: SkMatrix.h:235
SkScalar operator[](int index) const
Returns one matrix value.
Definition: SkMatrix.h:379
void normalizePerspective()
A matrix is categorized as 'perspective' if the bottom row is not [0, 0, 1].
Definition: SkMatrix.h:1269
SkMatrix & setScaleY(SkScalar v)
Sets vertical scale factor.
Definition: SkMatrix.h:505
SkMatrix & preRotate(SkScalar degrees, SkScalar px, SkScalar py)
Sets SkMatrix to SkMatrix multiplied by SkMatrix constructed from rotating by degrees about pivot poi...
SkScalar getMaxScale() const
Returns the maximum scaling factor of SkMatrix by decomposing the scaling and skewing elements.
SkMatrix & set9(const SkScalar buffer[9])
Sets SkMatrix to nine scalar values in buffer, in member value ascending order: kMScaleX,...
SkVector mapVector(SkScalar dx, SkScalar dy) const
Returns vector (dx, dy) multiplied by SkMatrix, treating SkMatrix translation as zero.
Definition: SkMatrix.h:1545
SkMatrix & preTranslate(SkScalar dx, SkScalar dy)
Sets SkMatrix to SkMatrix multiplied by SkMatrix constructed from translation (dx,...
bool hasPerspective() const
Returns true if the matrix contains perspective elements.
Definition: SkMatrix.h:311
SkPoint mapXY(SkScalar x, SkScalar y) const
Returns SkPoint (x, y) multiplied by SkMatrix.
Definition: SkMatrix.h:1415
SkMatrix & setTranslate(SkScalar dx, SkScalar dy)
Sets SkMatrix to translate by (dx, dy).
SkMatrix & setAffine(const SkScalar affine[6])
Sets SkMatrix to affine values, passed in column major order.
bool isFinite() const
Returns true if all elements of the matrix are finite.
Definition: SkMatrix.h:1833
friend SkMatrix operator*(const SkMatrix &a, const SkMatrix &b)
Definition: SkMatrix.h:1780
SkScalar get(int index) const
Returns one matrix value.
Definition: SkMatrix.h:391
bool setRectToRect(const SkRect &src, const SkRect &dst, ScaleToFit stf)
Sets SkMatrix to scale and translate src SkRect to dst SkRect.
SkMatrix & setSkew(SkScalar kx, SkScalar ky)
Sets SkMatrix to skew by kx and ky, about a pivot point at (0, 0).
bool preservesAxisAlignment() const
Returns true SkMatrix maps SkRect to another SkRect.
Definition: SkMatrix.h:298
SkScalar getPerspX() const
Returns factor scaling input x-axis relative to input y-axis.
Definition: SkMatrix.h:457
bool isSimilarity(SkScalar tol=SK_ScalarNearlyZero) const
Returns true if SkMatrix contains only translation, rotation, reflection, and uniform scale.
static SkMatrix Scale(SkScalar sx, SkScalar sy)
Sets SkMatrix to scale by (sx, sy).
Definition: SkMatrix.h:74
SkMatrix & postConcat(const SkMatrix &other)
Sets SkMatrix to SkMatrix other multiplied by SkMatrix.
static SkMatrix Skew(SkScalar kx, SkScalar ky)
Sets SkMatrix to skew by (kx, ky) about pivot point (0, 0).
Definition: SkMatrix.h:123
SkMatrix & postRotate(SkScalar degrees, SkScalar px, SkScalar py)
Sets SkMatrix to SkMatrix constructed from rotating by degrees about pivot point (px,...
SkMatrix & setSinCos(SkScalar sinValue, SkScalar cosValue)
Sets SkMatrix to rotate by sinValue and cosValue, about a pivot point at (0, 0).
SkMatrix & setTranslateX(SkScalar v)
Sets horizontal translation.
Definition: SkMatrix.h:523
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 & setConcat(const SkMatrix &a, const SkMatrix &b)
Sets SkMatrix to SkMatrix a multiplied by SkMatrix b.
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).
bool mapRect(SkRect *dst, const SkRect &src, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
Sets dst to bounds of src corners mapped by SkMatrix.
static SkMatrix Translate(SkVector t)
Definition: SkMatrix.h:95
SkScalar getTranslateX() const
Returns translation contributing to x-axis output.
Definition: SkMatrix.h:444
TypeMask
Definition: SkMatrix.h:190
void mapVector(SkScalar dx, SkScalar dy, SkVector *result) const
Maps vector (dx, dy) to result.
Definition: SkMatrix.h:1523
TypeMask getType() const
Returns a bit field describing the transformations the matrix may perform.
Definition: SkMatrix.h:206
bool isIdentity() const
Returns true if SkMatrix is identity.
Definition: SkMatrix.h:222
void dirtyMatrixTypeCache()
Sets internal cache to unknown state.
Definition: SkMatrix.h:1787
void mapRectToQuad(SkPoint dst[4], const SkRect &rect) const
Maps four corners of rect to dst.
Definition: SkMatrix.h:1619
Definition: SkPoint3.h:14
A compressed form of a rotation+scale matrix.
Definition: SkRSXform.h:21
SkRect holds four float coordinates describing the upper and lower bounds of a rectangle.
Definition: SkRect.h:582
void toQuad(SkPoint quad[4]) const
Returns four points in quad that enclose SkRect ordered as: top-left, top-right, bottom-right,...
Definition: SkSize.h:51