Flutter Engine
The Flutter Engine
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Friends | List of all members
SkMatrix Class Reference

#include <SkMatrix.h>

Inheritance diagram for SkMatrix:
OptionalMatrix SkRecords::TypedMatrix

Public Types

enum  ScaleToFit { kFill_ScaleToFit , kStart_ScaleToFit , kCenter_ScaleToFit , kEnd_ScaleToFit }
 
enum  TypeMask {
  kIdentity_Mask = 0 , kTranslate_Mask = 0x01 , kScale_Mask = 0x02 , kAffine_Mask = 0x04 ,
  kPerspective_Mask = 0x08
}
 

Public Member Functions

constexpr SkMatrix ()
 
TypeMask getType () const
 
bool isIdentity () const
 
bool isScaleTranslate () const
 
bool isTranslate () const
 
bool rectStaysRect () const
 
bool preservesAxisAlignment () const
 
bool hasPerspective () const
 
bool isSimilarity (SkScalar tol=SK_ScalarNearlyZero) const
 
bool preservesRightAngles (SkScalar tol=SK_ScalarNearlyZero) const
 
SkScalar operator[] (int index) const
 
SkScalar get (int index) const
 
SkScalar rc (int r, int c) const
 
SkScalar getScaleX () const
 
SkScalar getScaleY () const
 
SkScalar getSkewY () const
 
SkScalar getSkewX () const
 
SkScalar getTranslateX () const
 
SkScalar getTranslateY () const
 
SkScalar getPerspX () const
 
SkScalar getPerspY () const
 
SkScalaroperator[] (int index)
 
SkMatrixset (int index, SkScalar value)
 
SkMatrixsetScaleX (SkScalar v)
 
SkMatrixsetScaleY (SkScalar v)
 
SkMatrixsetSkewY (SkScalar v)
 
SkMatrixsetSkewX (SkScalar v)
 
SkMatrixsetTranslateX (SkScalar v)
 
SkMatrixsetTranslateY (SkScalar v)
 
SkMatrixsetPerspX (SkScalar v)
 
SkMatrixsetPerspY (SkScalar v)
 
SkMatrixsetAll (SkScalar scaleX, SkScalar skewX, SkScalar transX, SkScalar skewY, SkScalar scaleY, SkScalar transY, SkScalar persp0, SkScalar persp1, SkScalar persp2)
 
void get9 (SkScalar buffer[9]) const
 
SkMatrixset9 (const SkScalar buffer[9])
 
SkMatrixreset ()
 
SkMatrixsetIdentity ()
 
SkMatrixsetTranslate (SkScalar dx, SkScalar dy)
 
SkMatrixsetTranslate (const SkVector &v)
 
SkMatrixsetScale (SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
 
SkMatrixsetScale (SkScalar sx, SkScalar sy)
 
SkMatrixsetRotate (SkScalar degrees, SkScalar px, SkScalar py)
 
SkMatrixsetRotate (SkScalar degrees)
 
SkMatrixsetSinCos (SkScalar sinValue, SkScalar cosValue, SkScalar px, SkScalar py)
 
SkMatrixsetSinCos (SkScalar sinValue, SkScalar cosValue)
 
SkMatrixsetRSXform (const SkRSXform &rsxForm)
 
SkMatrixsetSkew (SkScalar kx, SkScalar ky, SkScalar px, SkScalar py)
 
SkMatrixsetSkew (SkScalar kx, SkScalar ky)
 
SkMatrixsetConcat (const SkMatrix &a, const SkMatrix &b)
 
SkMatrixpreTranslate (SkScalar dx, SkScalar dy)
 
SkMatrixpreScale (SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
 
SkMatrixpreScale (SkScalar sx, SkScalar sy)
 
SkMatrixpreRotate (SkScalar degrees, SkScalar px, SkScalar py)
 
SkMatrixpreRotate (SkScalar degrees)
 
SkMatrixpreSkew (SkScalar kx, SkScalar ky, SkScalar px, SkScalar py)
 
SkMatrixpreSkew (SkScalar kx, SkScalar ky)
 
SkMatrixpreConcat (const SkMatrix &other)
 
SkMatrixpostTranslate (SkScalar dx, SkScalar dy)
 
SkMatrixpostScale (SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
 
SkMatrixpostScale (SkScalar sx, SkScalar sy)
 
SkMatrixpostRotate (SkScalar degrees, SkScalar px, SkScalar py)
 
SkMatrixpostRotate (SkScalar degrees)
 
SkMatrixpostSkew (SkScalar kx, SkScalar ky, SkScalar px, SkScalar py)
 
SkMatrixpostSkew (SkScalar kx, SkScalar ky)
 
SkMatrixpostConcat (const SkMatrix &other)
 
bool setRectToRect (const SkRect &src, const SkRect &dst, ScaleToFit stf)
 
bool setPolyToPoly (const SkPoint src[], const SkPoint dst[], int count)
 
bool invert (SkMatrix *inverse) const
 
bool asAffine (SkScalar affine[6]) const
 
SkMatrixsetAffine (const SkScalar affine[6])
 
void normalizePerspective ()
 
void mapPoints (SkPoint dst[], const SkPoint src[], int count) const
 
void mapPoints (SkPoint pts[], int count) const
 
void mapHomogeneousPoints (SkPoint3 dst[], const SkPoint3 src[], int count) const
 
void mapHomogeneousPoints (SkPoint3 dst[], const SkPoint src[], int count) const
 
SkPoint mapPoint (SkPoint pt) const
 
void mapXY (SkScalar x, SkScalar y, SkPoint *result) const
 
SkPoint mapXY (SkScalar x, SkScalar y) const
 
SkPoint mapOrigin () const
 
void mapVectors (SkVector dst[], const SkVector src[], int count) const
 
void mapVectors (SkVector vecs[], int count) const
 
void mapVector (SkScalar dx, SkScalar dy, SkVector *result) const
 
SkVector mapVector (SkScalar dx, SkScalar dy) const
 
bool mapRect (SkRect *dst, const SkRect &src, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
 
bool mapRect (SkRect *rect, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
 
SkRect mapRect (const SkRect &src, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
 
void mapRectToQuad (SkPoint dst[4], const SkRect &rect) const
 
void mapRectScaleTranslate (SkRect *dst, const SkRect &src) const
 
SkScalar mapRadius (SkScalar radius) const
 
void dump () const
 
SkScalar getMinScale () const
 
SkScalar getMaxScale () const
 
bool getMinMaxScales (SkScalar scaleFactors[2]) const
 
bool decomposeScale (SkSize *scale, SkMatrix *remaining=nullptr) const
 
void dirtyMatrixTypeCache ()
 
void setScaleTranslate (SkScalar sx, SkScalar sy, SkScalar tx, SkScalar ty)
 
bool isFinite () const
 

Static Public Member Functions

static SkMatrix Scale (SkScalar sx, SkScalar sy)
 
static SkMatrix Translate (SkScalar dx, SkScalar dy)
 
static SkMatrix Translate (SkVector t)
 
static SkMatrix Translate (SkIVector t)
 
static SkMatrix RotateDeg (SkScalar deg)
 
static SkMatrix RotateDeg (SkScalar deg, SkPoint pt)
 
static SkMatrix RotateRad (SkScalar rad)
 
static SkMatrix Skew (SkScalar kx, SkScalar ky)
 
static SkMatrix RectToRect (const SkRect &src, const SkRect &dst, ScaleToFit mode=kFill_ScaleToFit)
 
static SkMatrix MakeAll (SkScalar scaleX, SkScalar skewX, SkScalar transX, SkScalar skewY, SkScalar scaleY, SkScalar transY, SkScalar pers0, SkScalar pers1, SkScalar pers2)
 
static SkMatrix MakeRectToRect (const SkRect &src, const SkRect &dst, ScaleToFit stf)
 
static void SetAffineIdentity (SkScalar affine[6])
 
static const SkMatrixI ()
 
static const SkMatrixInvalidMatrix ()
 
static SkMatrix Concat (const SkMatrix &a, const SkMatrix &b)
 

Static Public Attributes

static constexpr int kMScaleX = 0
 horizontal scale factor More...
 
static constexpr int kMSkewX = 1
 horizontal skew factor More...
 
static constexpr int kMTransX = 2
 horizontal translation More...
 
static constexpr int kMSkewY = 3
 vertical skew factor More...
 
static constexpr int kMScaleY = 4
 vertical scale factor More...
 
static constexpr int kMTransY = 5
 vertical translation More...
 
static constexpr int kMPersp0 = 6
 input x perspective factor More...
 
static constexpr int kMPersp1 = 7
 input y perspective factor More...
 
static constexpr int kMPersp2 = 8
 perspective bias More...
 
static constexpr int kAScaleX = 0
 horizontal scale factor More...
 
static constexpr int kASkewY = 1
 vertical skew factor More...
 
static constexpr int kASkewX = 2
 horizontal skew factor More...
 
static constexpr int kAScaleY = 3
 vertical scale factor More...
 
static constexpr int kATransX = 4
 horizontal translation More...
 
static constexpr int kATransY = 5
 vertical translation More...
 

Friends

class SkPerspIter
 
class SkMatrixPriv
 
class SerializationTest
 
SK_API bool operator== (const SkMatrix &a, const SkMatrix &b)
 
SK_API bool operator!= (const SkMatrix &a, const SkMatrix &b)
 
SkMatrix operator* (const SkMatrix &a, const SkMatrix &b)
 

Detailed Description

SkMatrix holds a 3x3 matrix for transforming coordinates. This allows mapping SkPoint and vectors with translation, scaling, skewing, rotation, and perspective.

SkMatrix elements are in row major order. SkMatrix constexpr default constructs to identity.

SkMatrix includes a hidden variable that classifies the type of matrix to improve performance. SkMatrix is not thread safe unless getType() is called first.

example: https://fiddle.skia.org/c/@Matrix_063

Definition at line 54 of file SkMatrix.h.

Member Enumeration Documentation

◆ ScaleToFit

Enumerator
kFill_ScaleToFit 

scales in x and y to fill destination SkRect

kStart_ScaleToFit 

scales and aligns to left and top

kCenter_ScaleToFit 

scales and aligns to center

kEnd_ScaleToFit 

scales and aligns to right and bottom

Definition at line 136 of file SkMatrix.h.

136 {
137 kFill_ScaleToFit, //!< scales in x and y to fill destination SkRect
138 kStart_ScaleToFit, //!< scales and aligns to left and top
139 kCenter_ScaleToFit, //!< scales and aligns to center
140 kEnd_ScaleToFit, //!< scales and aligns to right and bottom
141 };
@ kStart_ScaleToFit
scales and aligns to left and top
Definition: SkMatrix.h:138
@ kEnd_ScaleToFit
scales and aligns to right and bottom
Definition: SkMatrix.h:140
@ kCenter_ScaleToFit
scales and aligns to center
Definition: SkMatrix.h:139
@ kFill_ScaleToFit
scales in x and y to fill destination SkRect
Definition: SkMatrix.h:137

◆ TypeMask

Enumerator
kIdentity_Mask 

identity SkMatrix; all bits clear

kTranslate_Mask 

translation SkMatrix

kScale_Mask 

scale SkMatrix

kAffine_Mask 

skew or rotate SkMatrix

kPerspective_Mask 

perspective SkMatrix

Definition at line 191 of file SkMatrix.h.

191 {
192 kIdentity_Mask = 0, //!< identity SkMatrix; all bits clear
193 kTranslate_Mask = 0x01, //!< translation SkMatrix
194 kScale_Mask = 0x02, //!< scale SkMatrix
195 kAffine_Mask = 0x04, //!< skew or rotate SkMatrix
196 kPerspective_Mask = 0x08, //!< perspective SkMatrix
197 };
@ kPerspective_Mask
perspective SkMatrix
Definition: SkMatrix.h:196
@ kTranslate_Mask
translation SkMatrix
Definition: SkMatrix.h:193
@ kScale_Mask
scale SkMatrix
Definition: SkMatrix.h:194
@ kIdentity_Mask
identity SkMatrix; all bits clear
Definition: SkMatrix.h:192
@ kAffine_Mask
skew or rotate SkMatrix
Definition: SkMatrix.h:195

Constructor & Destructor Documentation

◆ SkMatrix()

constexpr SkMatrix::SkMatrix ( )
inlineconstexpr

Creates an identity SkMatrix:

| 1 0 0 |
| 0 1 0 |
| 0 0 1 |

Definition at line 63 of file SkMatrix.h.

63: SkMatrix(1,0,0, 0,1,0, 0,0,1, kIdentity_Mask | kRectStaysRect_Mask) {}
constexpr SkMatrix()
Definition: SkMatrix.h:63

Member Function Documentation

◆ asAffine()

bool SkMatrix::asAffine ( SkScalar  affine[6]) const

Fills affine in column major order. Sets affine to:

| scale-x  skew-x translate-x |
| skew-y  scale-y translate-y |

If SkMatrix contains perspective, returns false and leaves affine unchanged.

Parameters
affinestorage for 3 by 2 affine matrix; may be nullptr
Returns
true if SkMatrix does not contain perspective

Definition at line 755 of file SkMatrix.cpp.

755 {
756 if (this->hasPerspective()) {
757 return false;
758 }
759 if (affine) {
760 affine[kAScaleX] = this->fMat[kMScaleX];
761 affine[kASkewY] = this->fMat[kMSkewY];
762 affine[kASkewX] = this->fMat[kMSkewX];
763 affine[kAScaleY] = this->fMat[kMScaleY];
764 affine[kATransX] = this->fMat[kMTransX];
765 affine[kATransY] = this->fMat[kMTransY];
766 }
767 return true;
768}
static constexpr int kATransY
vertical translation
Definition: SkMatrix.h:371
static constexpr int kMScaleX
horizontal scale factor
Definition: SkMatrix.h:353
static constexpr int kMTransY
vertical translation
Definition: SkMatrix.h:358
static constexpr int kAScaleY
vertical scale factor
Definition: SkMatrix.h:369
static constexpr int kASkewX
horizontal skew factor
Definition: SkMatrix.h:368
static constexpr int kATransX
horizontal translation
Definition: SkMatrix.h:370
static constexpr int kAScaleX
horizontal scale factor
Definition: SkMatrix.h:366
static constexpr int kASkewY
vertical skew factor
Definition: SkMatrix.h:367
static constexpr int kMTransX
horizontal translation
Definition: SkMatrix.h:355
bool hasPerspective() const
Definition: SkMatrix.h:312
static constexpr int kMSkewY
vertical skew factor
Definition: SkMatrix.h:356
static constexpr int kMScaleY
vertical scale factor
Definition: SkMatrix.h:357
static constexpr int kMSkewX
horizontal skew factor
Definition: SkMatrix.h:354

◆ Concat()

static SkMatrix SkMatrix::Concat ( const SkMatrix a,
const SkMatrix b 
)
inlinestatic

Returns SkMatrix a multiplied by SkMatrix b.

Given:

    | A B C |      | J K L |
a = | D E F |, b = | M N O |
    | G H I |      | P Q R |

sets SkMatrix to:

        | A B C |   | J K L |   | AJ+BM+CP AK+BN+CQ AL+BO+CR |
a * b = | D E F | * | M N O | = | DJ+EM+FP DK+EN+FQ DL+EO+FR |
        | G H I |   | P Q R |   | GJ+HM+IP GK+HN+IQ GL+HO+IR |
Parameters
aSkMatrix on left side of multiply expression
bSkMatrix on right side of multiply expression
Returns
SkMatrix computed from a times b

Definition at line 1775 of file SkMatrix.h.

1775 {
1777 result.setConcat(a, b);
1778 return result;
1779 }
static bool b
struct MyStruct a[10]
GAsyncResult * result

◆ decomposeScale()

bool SkMatrix::decomposeScale ( SkSize scale,
SkMatrix remaining = nullptr 
) const

Decomposes SkMatrix into scale components and whatever remains. Returns false if SkMatrix could not be decomposed.

Sets scale to portion of SkMatrix that scale axes. Sets remaining to SkMatrix with scaling factored out. remaining may be passed as nullptr to determine if SkMatrix can be decomposed without computing remainder.

Returns true if scale components are found. scale and remaining are unchanged if SkMatrix contains perspective; scale factors are not finite, or are nearly zero.

On success: Matrix = Remaining * scale.

Parameters
scaleaxes scaling factors; may be nullptr
remainingSkMatrix without scaling; may be nullptr
Returns
true if scale can be computed

example: https://fiddle.skia.org/c/@Matrix_decomposeScale

Definition at line 1559 of file SkMatrix.cpp.

1559 {
1560 if (this->hasPerspective()) {
1561 return false;
1562 }
1563
1564 const SkScalar sx = SkVector::Length(this->getScaleX(), this->getSkewY());
1565 const SkScalar sy = SkVector::Length(this->getSkewX(), this->getScaleY());
1566 if (!SkIsFinite(sx, sy) ||
1568 return false;
1569 }
1570
1571 if (scale) {
1572 scale->set(sx, sy);
1573 }
1574 if (remaining) {
1575 *remaining = *this;
1576 remaining->preScale(SkScalarInvert(sx), SkScalarInvert(sy));
1577 }
1578 return true;
1579}
static bool SkIsFinite(T x, Pack... values)
#define SkScalarInvert(x)
Definition: SkScalar.h:73
static bool SkScalarNearlyZero(SkScalar x, SkScalar tolerance=SK_ScalarNearlyZero)
Definition: SkScalar.h:101
SkScalar getSkewY() const
Definition: SkMatrix.h:430
SkScalar getSkewX() const
Definition: SkMatrix.h:438
SkScalar getScaleX() const
Definition: SkMatrix.h:415
SkScalar getScaleY() const
Definition: SkMatrix.h:422
SkMatrix & preScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
Definition: SkMatrix.cpp:315
float SkScalar
Definition: extension.cpp:12
const Scalar scale
static float Length(float x, float y)
Definition: SkPoint.cpp:79

◆ dirtyMatrixTypeCache()

void SkMatrix::dirtyMatrixTypeCache ( )
inline

Sets internal cache to unknown state. Use to force update after repeated modifications to SkMatrix element reference returned by operator[](int index).

Definition at line 1788 of file SkMatrix.h.

1788 {
1789 this->setTypeMask(kUnknown_Mask);
1790 }

◆ dump()

void SkMatrix::dump ( ) const

Writes text representation of SkMatrix to standard output. Floating point values are written with limited precision; it may not be possible to reconstruct original SkMatrix from output.

example: https://fiddle.skia.org/c/@Matrix_dump

Definition at line 1604 of file SkMatrix.cpp.

1604 {
1605 SkString str;
1606 str.appendf("[%8.4f %8.4f %8.4f][%8.4f %8.4f %8.4f][%8.4f %8.4f %8.4f]",
1607 fMat[0], fMat[1], fMat[2], fMat[3], fMat[4], fMat[5],
1608 fMat[6], fMat[7], fMat[8]);
1609 SkDebugf("%s\n", str.c_str());
1610}
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
const char * c_str() const
Definition: SkString.h:133
void void void appendf(const char format[],...) SK_PRINTF_LIKE(2
Definition: SkString.cpp:550

◆ get()

SkScalar SkMatrix::get ( int  index) const
inline

Returns one matrix value. Asserts if index is out of range and SK_DEBUG is defined.

Parameters
indexone of: kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY, kMPersp0, kMPersp1, kMPersp2
Returns
value corresponding to index

Definition at line 392 of file SkMatrix.h.

392 {
393 SkASSERT((unsigned)index < 9);
394 return fMat[index];
395 }
#define SkASSERT(cond)
Definition: SkAssert.h:116

◆ get9()

void SkMatrix::get9 ( SkScalar  buffer[9]) const
inline

Copies nine scalar values contained by SkMatrix into buffer, in member value ascending order: kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY, kMPersp0, kMPersp1, kMPersp2.

Parameters
bufferstorage for nine scalar values

Definition at line 584 of file SkMatrix.h.

584 {
585 memcpy(buffer, fMat, 9 * sizeof(SkScalar));
586 }
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126

◆ getMaxScale()

SkScalar SkMatrix::getMaxScale ( ) const

Returns the maximum scaling factor of SkMatrix by decomposing the scaling and skewing elements. Returns -1 if scale factor overflows or SkMatrix contains perspective.

Returns
maximum scale factor

example: https://fiddle.skia.org/c/@Matrix_getMaxScale

Definition at line 1531 of file SkMatrix.cpp.

1531 {
1532 SkScalar factor;
1533 if (get_scale_factor<kMax_MinMaxOrBoth>(this->getType(), fMat, &factor)) {
1534 return factor;
1535 } else {
1536 return -1;
1537 }
1538}
TypeMask getType() const
Definition: SkMatrix.h:207

◆ getMinMaxScales()

bool SkMatrix::getMinMaxScales ( SkScalar  scaleFactors[2]) const

Sets scaleFactors[0] to the minimum scaling factor, and scaleFactors[1] to the maximum scaling factor. Scaling factors are computed by decomposing the SkMatrix scaling and skewing elements.

Returns true if scaleFactors are found; otherwise, returns false and sets scaleFactors to undefined values.

Parameters
scaleFactorsstorage for minimum and maximum scale factors
Returns
true if scale factors were computed correctly

Definition at line 1540 of file SkMatrix.cpp.

1540 {
1541 return get_scale_factor<kBoth_MinMaxOrBoth>(this->getType(), fMat, scaleFactors);
1542}

◆ getMinScale()

SkScalar SkMatrix::getMinScale ( ) const

Returns the minimum scaling factor of SkMatrix by decomposing the scaling and skewing elements. Returns -1 if scale factor overflows or SkMatrix contains perspective.

Returns
minimum scale factor

example: https://fiddle.skia.org/c/@Matrix_getMinScale

Definition at line 1522 of file SkMatrix.cpp.

1522 {
1523 SkScalar factor;
1524 if (get_scale_factor<kMin_MinMaxOrBoth>(this->getType(), fMat, &factor)) {
1525 return factor;
1526 } else {
1527 return -1;
1528 }
1529}

◆ getPerspX()

SkScalar SkMatrix::getPerspX ( ) const
inline

Returns factor scaling input x-axis relative to input y-axis.

Returns
input x-axis perspective factor

Definition at line 458 of file SkMatrix.h.

458{ return fMat[kMPersp0]; }
static constexpr int kMPersp0
input x perspective factor
Definition: SkMatrix.h:359

◆ getPerspY()

SkScalar SkMatrix::getPerspY ( ) const
inline

Returns factor scaling input y-axis relative to input x-axis.

Returns
input y-axis perspective factor

Definition at line 464 of file SkMatrix.h.

464{ return fMat[kMPersp1]; }
static constexpr int kMPersp1
input y perspective factor
Definition: SkMatrix.h:360

◆ getScaleX()

SkScalar SkMatrix::getScaleX ( ) const
inline

Returns scale factor multiplied by x-axis input, contributing to x-axis output. With mapPoints(), scales SkPoint along the x-axis.

Returns
horizontal scale factor

Definition at line 415 of file SkMatrix.h.

415{ return fMat[kMScaleX]; }

◆ getScaleY()

SkScalar SkMatrix::getScaleY ( ) const
inline

Returns scale factor multiplied by y-axis input, contributing to y-axis output. With mapPoints(), scales SkPoint along the y-axis.

Returns
vertical scale factor

Definition at line 422 of file SkMatrix.h.

422{ return fMat[kMScaleY]; }

◆ getSkewX()

SkScalar SkMatrix::getSkewX ( ) const
inline

Returns scale factor multiplied by y-axis input, contributing to x-axis output. With mapPoints(), skews SkPoint along the x-axis. Skewing both axes can rotate SkPoint.

Returns
horizontal scale factor

Definition at line 438 of file SkMatrix.h.

438{ return fMat[kMSkewX]; }

◆ getSkewY()

SkScalar SkMatrix::getSkewY ( ) const
inline

Returns scale factor multiplied by x-axis input, contributing to y-axis output. With mapPoints(), skews SkPoint along the y-axis. Skewing both axes can rotate SkPoint.

Returns
vertical skew factor

Definition at line 430 of file SkMatrix.h.

430{ return fMat[kMSkewY]; }

◆ getTranslateX()

SkScalar SkMatrix::getTranslateX ( ) const
inline

Returns translation contributing to x-axis output. With mapPoints(), moves SkPoint along the x-axis.

Returns
horizontal translation factor

Definition at line 445 of file SkMatrix.h.

445{ return fMat[kMTransX]; }

◆ getTranslateY()

SkScalar SkMatrix::getTranslateY ( ) const
inline

Returns translation contributing to y-axis output. With mapPoints(), moves SkPoint along the y-axis.

Returns
vertical translation factor

Definition at line 452 of file SkMatrix.h.

452{ return fMat[kMTransY]; }

◆ getType()

TypeMask SkMatrix::getType ( ) const
inline

Returns a bit field describing the transformations the matrix may perform. The bit field is computed conservatively, so it may include false positives. For example, when kPerspective_Mask is set, all other bits are set.

Returns
kIdentity_Mask, or combinations of: kTranslate_Mask, kScale_Mask, kAffine_Mask, kPerspective_Mask

Definition at line 207 of file SkMatrix.h.

207 {
208 if (fTypeMask & kUnknown_Mask) {
209 fTypeMask = this->computeTypeMask();
210 }
211 // only return the public masks
212 return (TypeMask)(fTypeMask & 0xF);
213 }

◆ hasPerspective()

bool SkMatrix::hasPerspective ( ) const
inline

Returns true if the matrix contains perspective elements. SkMatrix form is:

|       --            --              --          |
|       --            --              --          |
| perspective-x  perspective-y  perspective-scale |

where perspective-x or perspective-y is non-zero, or perspective-scale is not one. All other elements may have any value.

Returns
true if SkMatrix is in most general form

Definition at line 312 of file SkMatrix.h.

312 {
313 return SkToBool(this->getPerspectiveTypeMaskOnly() &
315 }
static constexpr bool SkToBool(const T &x)
Definition: SkTo.h:35

◆ I()

const SkMatrix & SkMatrix::I ( )
static

Returns reference to const identity SkMatrix. Returned SkMatrix is set to:

| 1 0 0 |
| 0 1 0 |
| 0 0 1 |
Returns
const identity SkMatrix

example: https://fiddle.skia.org/c/@Matrix_I

Definition at line 1544 of file SkMatrix.cpp.

1544 {
1545 static constexpr SkMatrix identity;
1546 SkASSERT(identity.isIdentity());
1547 return identity;
1548}

◆ InvalidMatrix()

const SkMatrix & SkMatrix::InvalidMatrix ( )
static

Returns reference to a const SkMatrix with invalid values. Returned SkMatrix is set to:

| SK_ScalarMax SK_ScalarMax SK_ScalarMax |
| SK_ScalarMax SK_ScalarMax SK_ScalarMax |
| SK_ScalarMax SK_ScalarMax SK_ScalarMax |
Returns
const invalid SkMatrix

example: https://fiddle.skia.org/c/@Matrix_InvalidMatrix

Definition at line 1550 of file SkMatrix.cpp.

1550 {
1556 return invalid;
1557}
static bool invalid(const SkISize &size)
#define SK_ScalarMax
Definition: SkScalar.h:24

◆ invert()

bool SkMatrix::invert ( SkMatrix inverse) const
inline

Sets inverse to reciprocal matrix, returning true if SkMatrix can be inverted. Geometrically, if SkMatrix maps from source to destination, inverse SkMatrix maps from destination to source. If SkMatrix can not be inverted, inverse is unchanged.

Parameters
inversestorage for inverted SkMatrix; may be nullptr
Returns
true if SkMatrix can be inverted

Definition at line 1206 of file SkMatrix.h.

1206 {
1207 // Allow the trivial case to be inlined.
1208 if (this->isIdentity()) {
1209 if (inverse) {
1210 inverse->reset();
1211 }
1212 return true;
1213 }
1214 return this->invertNonIdentity(inverse);
1215 }
SkMatrix & reset()
Definition: SkMatrix.cpp:49
bool isIdentity() const
Definition: SkMatrix.h:223

◆ isFinite()

bool SkMatrix::isFinite ( ) const
inline

Returns true if all elements of the matrix are finite. Returns false if any element is infinity, or NaN.

Returns
true if matrix has only finite elements

Definition at line 1834 of file SkMatrix.h.

1834{ return SkIsFinite(fMat, 9); }

◆ isIdentity()

bool SkMatrix::isIdentity ( ) const
inline

Returns true if SkMatrix is identity. Identity matrix is:

| 1 0 0 |
| 0 1 0 |
| 0 0 1 |
Returns
true if SkMatrix has no effect

Definition at line 223 of file SkMatrix.h.

223 {
224 return this->getType() == 0;
225 }

◆ isScaleTranslate()

bool SkMatrix::isScaleTranslate ( ) const
inline

Returns true if SkMatrix at most scales and translates. SkMatrix may be identity, contain only scale elements, only translate elements, or both. SkMatrix form is:

| scale-x    0    translate-x |
|    0    scale-y translate-y |
|    0       0         1      |
Returns
true if SkMatrix is identity; or scales, translates, or both

Definition at line 236 of file SkMatrix.h.

236 {
237 return !(this->getType() & ~(kScale_Mask | kTranslate_Mask));
238 }

◆ isSimilarity()

bool SkMatrix::isSimilarity ( SkScalar  tol = SK_ScalarNearlyZero) const

Returns true if SkMatrix contains only translation, rotation, reflection, and uniform scale. Returns false if SkMatrix contains different scales, skewing, perspective, or degenerate forms that collapse to a line or point.

Describes that the SkMatrix makes rendering with and without the matrix are visually alike; a transformed circle remains a circle. Mathematically, this is referred to as similarity of a Euclidean space, or a similarity transformation.

Preserves right angles, keeping the arms of the angle equal lengths.

Parameters
tolto be deprecated
Returns
true if SkMatrix only rotates, uniformly scales, translates

example: https://fiddle.skia.org/c/@Matrix_isSimilarity

Definition at line 180 of file SkMatrix.cpp.

180 {
181 // if identity or translate matrix
182 TypeMask mask = this->getType();
183 if (mask <= kTranslate_Mask) {
184 return true;
185 }
186 if (mask & kPerspective_Mask) {
187 return false;
188 }
189
190 SkScalar mx = fMat[kMScaleX];
191 SkScalar my = fMat[kMScaleY];
192 // if no skew, can just compare scale factors
193 if (!(mask & kAffine_Mask)) {
195 }
196 SkScalar sx = fMat[kMSkewX];
197 SkScalar sy = fMat[kMSkewY];
198
199 if (is_degenerate_2x2(mx, sx, sy, my)) {
200 return false;
201 }
202
203 // upper 2x2 is rotation/reflection + uniform scale if basis vectors
204 // are 90 degree rotations of each other
205 return (SkScalarNearlyEqual(mx, my, tol) && SkScalarNearlyEqual(sx, -sy, tol))
206 || (SkScalarNearlyEqual(mx, -my, tol) && SkScalarNearlyEqual(sx, sy, tol));
207}
static bool is_degenerate_2x2(SkScalar scaleX, SkScalar skewX, SkScalar skewY, SkScalar scaleY)
Definition: SkMatrix.cpp:172
static bool SkScalarNearlyEqual(SkScalar x, SkScalar y, SkScalar tolerance=SK_ScalarNearlyZero)
Definition: SkScalar.h:107
#define SkScalarAbs(x)
Definition: SkScalar.h:39

◆ isTranslate()

bool SkMatrix::isTranslate ( ) const
inline

Returns true if SkMatrix is identity, or translates. SkMatrix form is:

| 1 0 translate-x |
| 0 1 translate-y |
| 0 0      1      |
Returns
true if SkMatrix is identity, or translates

Definition at line 248 of file SkMatrix.h.

248{ return !(this->getType() & ~(kTranslate_Mask)); }

◆ MakeAll()

static SkMatrix SkMatrix::MakeAll ( SkScalar  scaleX,
SkScalar  skewX,
SkScalar  transX,
SkScalar  skewY,
SkScalar  scaleY,
SkScalar  transY,
SkScalar  pers0,
SkScalar  pers1,
SkScalar  pers2 
)
inlinestatic

Sets SkMatrix to:

| scaleX  skewX transX |
|  skewY scaleY transY |
|  pers0  pers1  pers2 |
Parameters
scaleXhorizontal scale factor
skewXhorizontal skew factor
transXhorizontal translation
skewYvertical skew factor
scaleYvertical scale factor
transYvertical translation
pers0input x-axis perspective factor
pers1input y-axis perspective factor
pers2perspective scale factor
Returns
SkMatrix constructed from parameters

Definition at line 179 of file SkMatrix.h.

181 {
182 SkMatrix m;
183 m.setAll(scaleX, skewX, transX, skewY, scaleY, transY, pers0, pers1, pers2);
184 return m;
185 }

◆ MakeRectToRect()

static SkMatrix SkMatrix::MakeRectToRect ( const SkRect src,
const SkRect dst,
ScaleToFit  stf 
)
inlinestatic

Returns SkMatrix set to scale and translate src SkRect to dst SkRect. stf selects whether mapping completely fills dst or preserves the aspect ratio, and how to align src within dst. Returns the identity SkMatrix if src is empty. If dst is empty, returns SkMatrix set to:

| 0 0 0 |
| 0 0 0 |
| 0 0 1 |
Parameters
srcSkRect to map from
dstSkRect to map to
Returns
SkMatrix mapping src to dst

Definition at line 1172 of file SkMatrix.h.

1172 {
1173 SkMatrix m;
1174 m.setRectToRect(src, dst, stf);
1175 return m;
1176 }
dst
Definition: cp.py:12

◆ mapHomogeneousPoints() [1/2]

void SkMatrix::mapHomogeneousPoints ( SkPoint3  dst[],
const SkPoint  src[],
int  count 
) const

Returns homogeneous points, starting with 2D src points (with implied w = 1).

Definition at line 1071 of file SkMatrix.cpp.

1071 {
1072 if (this->isIdentity()) {
1073 for (int i = 0; i < count; ++i) {
1074 dst[i] = { src[i].fX, src[i].fY, 1 };
1075 }
1076 } else if (this->hasPerspective()) {
1077 for (int i = 0; i < count; ++i) {
1078 dst[i] = {
1079 fMat[0] * src[i].fX + fMat[1] * src[i].fY + fMat[2],
1080 fMat[3] * src[i].fX + fMat[4] * src[i].fY + fMat[5],
1081 fMat[6] * src[i].fX + fMat[7] * src[i].fY + fMat[8],
1082 };
1083 }
1084 } else { // affine
1085 for (int i = 0; i < count; ++i) {
1086 dst[i] = {
1087 fMat[0] * src[i].fX + fMat[1] * src[i].fY + fMat[2],
1088 fMat[3] * src[i].fX + fMat[4] * src[i].fY + fMat[5],
1089 1,
1090 };
1091 }
1092 }
1093}
int count
Definition: FontMgrTest.cpp:50

◆ mapHomogeneousPoints() [2/2]

void SkMatrix::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. SkPoint3 array is mapped by multiplying each SkPoint3 by SkMatrix. Given:

         | A B C |         | x |
Matrix = | D E F |,  src = | y |
         | G H I |         | z |

each resulting dst SkPoint is computed as:

               |A B C| |x|
Matrix * src = |D E F| |y| = |Ax+By+Cz Dx+Ey+Fz Gx+Hy+Iz|
               |G H I| |z|
Parameters
dststorage for mapped SkPoint3 array
srcSkPoint3 array to transform
countitems in SkPoint3 array to transform

example: https://fiddle.skia.org/c/@Matrix_mapHomogeneousPoints

Definition at line 1066 of file SkMatrix.cpp.

1066 {
1068 sizeof(SkPoint3), count);
1069}
static void MapHomogeneousPointsWithStride(const SkMatrix &mx, SkPoint3 dst[], size_t dstStride, const SkPoint3 src[], size_t srcStride, int count)
Definition: SkMatrix.cpp:1026

◆ mapOrigin()

SkPoint SkMatrix::mapOrigin ( ) const
inline

Returns (0, 0) multiplied by SkMatrix. Given:

         | A B C |        | 0 |
Matrix = | D E F |,  pt = | 0 |
         | G H I |        | 1 |

result is computed as:

              |A B C| |0|             C    F
Matrix * pt = |D E F| |0| = |C F I| = -  , -
              |G H I| |1|             I    I
Returns
mapped (0, 0)

Definition at line 1437 of file SkMatrix.h.

1437 {
1438 SkScalar x = this->getTranslateX(),
1439 y = this->getTranslateY();
1440 if (this->hasPerspective()) {
1441 SkScalar w = fMat[kMPersp2];
1442 if (w) { w = 1 / w; }
1443 x *= w;
1444 y *= w;
1445 }
1446 return {x, y};
1447 }
SkScalar getTranslateY() const
Definition: SkMatrix.h:452
static constexpr int kMPersp2
perspective bias
Definition: SkMatrix.h:361
SkScalar getTranslateX() const
Definition: SkMatrix.h:445
double y
double x
SkScalar w

◆ mapPoint()

SkPoint SkMatrix::mapPoint ( SkPoint  pt) const
inline

Returns SkPoint pt multiplied by SkMatrix. Given:

         | A B C |        | x |
Matrix = | D E F |,  pt = | y |
         | G H I |        | 1 |

result is computed as:

              |A B C| |x|                               Ax+By+C   Dx+Ey+F
Matrix * pt = |D E F| |y| = |Ax+By+C Dx+Ey+F Gx+Hy+I| = ------- , -------
              |G H I| |1|                               Gx+Hy+I   Gx+Hy+I
Parameters
pSkPoint to map
Returns
mapped SkPoint

Definition at line 1374 of file SkMatrix.h.

1374 {
1376 this->mapXY(pt.x(), pt.y(), &result);
1377 return result;
1378 }
void mapXY(SkScalar x, SkScalar y, SkPoint *result) const
Definition: SkMatrix.cpp:777
constexpr float y() const
Definition: SkPoint_impl.h:187
constexpr float x() const
Definition: SkPoint_impl.h:181

◆ mapPoints() [1/2]

void SkMatrix::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. SkPoint are mapped by multiplying each SkPoint by SkMatrix. Given:

         | A B C |        | x |
Matrix = | D E F |,  pt = | y |
         | G H I |        | 1 |

where

for (i = 0; i < count; ++i) {
    x = src[i].fX
    y = src[i].fY
}

each dst SkPoint is computed as:

              |A B C| |x|                               Ax+By+C   Dx+Ey+F
Matrix * pt = |D E F| |y| = |Ax+By+C Dx+Ey+F Gx+Hy+I| = ------- , -------
              |G H I| |1|                               Gx+Hy+I   Gx+Hy+I

src and dst may point to the same storage.

Parameters
dststorage for mapped SkPoint
srcSkPoint to transform
countnumber of SkPoint to transform

example: https://fiddle.skia.org/c/@Matrix_mapPoints

Definition at line 770 of file SkMatrix.cpp.

770 {
771 SkASSERT((dst && src && count > 0) || 0 == count);
772 // no partial overlap
773 SkASSERT(src == dst || &dst[count] <= &src[0] || &src[count] <= &dst[0]);
774 this->getMapPtsProc()(*this, dst, src, count);
775}

◆ mapPoints() [2/2]

void SkMatrix::mapPoints ( SkPoint  pts[],
int  count 
) const
inline

Maps pts SkPoint array of length count in place. SkPoint are mapped by multiplying each SkPoint by SkMatrix. Given:

         | A B C |        | x |
Matrix = | D E F |,  pt = | y |
         | G H I |        | 1 |

where

for (i = 0; i < count; ++i) {
    x = pts[i].fX
    y = pts[i].fY
}

each resulting pts SkPoint is computed as:

              |A B C| |x|                               Ax+By+C   Dx+Ey+F
Matrix * pt = |D E F| |y| = |Ax+By+C Dx+Ey+F Gx+Hy+I| = ------- , -------
              |G H I| |1|                               Gx+Hy+I   Gx+Hy+I
Parameters
ptsstorage for mapped SkPoint
countnumber of SkPoint to transform

Definition at line 1329 of file SkMatrix.h.

1329 {
1330 this->mapPoints(pts, pts, count);
1331 }
void mapPoints(SkPoint dst[], const SkPoint src[], int count) const
Definition: SkMatrix.cpp:770

◆ mapRadius()

SkScalar SkMatrix::mapRadius ( SkScalar  radius) const

Returns geometric mean radius of ellipse formed by constructing circle of size radius, and mapping constructed circle with SkMatrix. The result squared is equal to the major axis length times the minor axis length. Result is not meaningful if SkMatrix contains perspective elements.

Parameters
radiuscircle size to map
Returns
average mapped radius

example: https://fiddle.skia.org/c/@Matrix_mapRadius

Definition at line 1170 of file SkMatrix.cpp.

1170 {
1171 SkVector vec[2];
1172
1173 vec[0].set(radius, 0);
1174 vec[1].set(0, radius);
1175 this->mapVectors(vec, 2);
1176
1177 SkScalar d0 = vec[0].length();
1178 SkScalar d1 = vec[1].length();
1179
1180 // return geometric mean
1181 return SkScalarSqrt(d0 * d1);
1182}
#define SkScalarSqrt(x)
Definition: SkScalar.h:42
void mapVectors(SkVector dst[], const SkVector src[], int count) const
Definition: SkMatrix.cpp:1097
void set(float x, float y)
Definition: SkPoint_impl.h:200
float length() const
Definition: SkPoint_impl.h:282

◆ mapRect() [1/3]

SkRect SkMatrix::mapRect ( const SkRect src,
SkApplyPerspectiveClip  pc = SkApplyPerspectiveClip::kYes 
) const
inline

Returns bounds of src corners mapped by SkMatrix.

Parameters
srcrectangle to map
Returns
mapped bounds

Definition at line 1585 of file SkMatrix.h.

1586 {
1587 SkRect dst;
1588 (void)this->mapRect(&dst, src, pc);
1589 return dst;
1590 }
bool mapRect(SkRect *dst, const SkRect &src, SkApplyPerspectiveClip pc=SkApplyPerspectiveClip::kYes) const
Definition: SkMatrix.cpp:1141

◆ mapRect() [2/3]

bool SkMatrix::mapRect ( SkRect dst,
const SkRect src,
SkApplyPerspectiveClip  pc = SkApplyPerspectiveClip::kYes 
) const

Sets dst to bounds of src corners mapped by SkMatrix. Returns true if mapped corners are dst corners.

Returned value is the same as calling rectStaysRect().

Parameters
dststorage for bounds of mapped SkPoint
srcSkRect to map
pcwhether to apply perspective clipping
Returns
true if dst is equivalent to mapped src

example: https://fiddle.skia.org/c/@Matrix_mapRect

Definition at line 1141 of file SkMatrix.cpp.

1141 {
1142 SkASSERT(dst);
1143
1144 if (this->getType() <= kTranslate_Mask) {
1145 SkScalar tx = fMat[kMTransX];
1146 SkScalar ty = fMat[kMTransY];
1147 skvx::float4 trans(tx, ty, tx, ty);
1148 sort_as_rect(skvx::float4::Load(&src.fLeft) + trans).store(&dst->fLeft);
1149 return true;
1150 }
1151 if (this->isScaleTranslate()) {
1152 this->mapRectScaleTranslate(dst, src);
1153 return true;
1154 } else if (pc == SkApplyPerspectiveClip::kYes && this->hasPerspective()) {
1155 SkPath path;
1156 path.addRect(src);
1157 path.transform(*this);
1158 *dst = path.getBounds();
1159 return false;
1160 } else {
1161 SkPoint quad[4];
1162
1163 src.toQuad(quad);
1164 this->mapPoints(quad, quad, 4);
1165 dst->setBoundsNoCheck(quad, 4);
1166 return this->rectStaysRect(); // might still return true if rotated by 90, etc.
1167 }
1168}
static skvx::float4 sort_as_rect(const skvx::float4 &ltrb)
Definition: SkMatrix.cpp:1119
@ kYes
Do pre-clip the geometry before applying the (perspective) matrix.
bool rectStaysRect() const
Definition: SkMatrix.h:271
void mapRectScaleTranslate(SkRect *dst, const SkRect &src) const
Definition: SkMatrix.cpp:1128
bool isScaleTranslate() const
Definition: SkMatrix.h:236
Definition: SkPath.h:59
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
Definition: SkVx.h:83
static SKVX_ALWAYS_INLINE Vec Load(const void *ptr)
Definition: SkVx.h:109
SKVX_ALWAYS_INLINE void store(void *ptr) const
Definition: SkVx.h:112

◆ mapRect() [3/3]

bool SkMatrix::mapRect ( SkRect rect,
SkApplyPerspectiveClip  pc = SkApplyPerspectiveClip::kYes 
) const
inline

Sets rect to bounds of rect corners mapped by SkMatrix. Returns true if mapped corners are computed rect corners.

Returned value is the same as calling rectStaysRect().

Parameters
rectrectangle to map, and storage for bounds of mapped corners
pcwhether to apply perspective clipping
Returns
true if result is equivalent to mapped rect

Definition at line 1576 of file SkMatrix.h.

1576 {
1577 return this->mapRect(rect, *rect, pc);
1578 }
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350

◆ mapRectScaleTranslate()

void SkMatrix::mapRectScaleTranslate ( SkRect dst,
const SkRect src 
) const

Sets dst to bounds of src corners mapped by SkMatrix. If matrix contains elements other than scale or translate: asserts if SK_DEBUG is defined; otherwise, results are undefined.

Parameters
dststorage for bounds of mapped SkPoint
srcSkRect to map

example: https://fiddle.skia.org/c/@Matrix_mapRectScaleTranslate

Definition at line 1128 of file SkMatrix.cpp.

1128 {
1129 SkASSERT(dst);
1130 SkASSERT(this->isScaleTranslate());
1131
1132 SkScalar sx = fMat[kMScaleX];
1133 SkScalar sy = fMat[kMScaleY];
1134 SkScalar tx = fMat[kMTransX];
1135 SkScalar ty = fMat[kMTransY];
1136 skvx::float4 scale(sx, sy, sx, sy);
1137 skvx::float4 trans(tx, ty, tx, ty);
1138 sort_as_rect(skvx::float4::Load(&src.fLeft) * scale + trans).store(&dst->fLeft);
1139}

◆ mapRectToQuad()

void SkMatrix::mapRectToQuad ( SkPoint  dst[4],
const SkRect rect 
) const
inline

Maps four corners of rect to dst. SkPoint are mapped by multiplying each rect corner by SkMatrix. rect corner is processed in this order: (rect.fLeft, rect.fTop), (rect.fRight, rect.fTop), (rect.fRight, rect.fBottom), (rect.fLeft, rect.fBottom).

rect may be empty: rect.fLeft may be greater than or equal to rect.fRight; rect.fTop may be greater than or equal to rect.fBottom.

Given:

         | A B C |        | x |
Matrix = | D E F |,  pt = | y |
         | G H I |        | 1 |

where pt is initialized from each of (rect.fLeft, rect.fTop), (rect.fRight, rect.fTop), (rect.fRight, rect.fBottom), (rect.fLeft, rect.fBottom), each dst SkPoint is computed as:

              |A B C| |x|                               Ax+By+C   Dx+Ey+F
Matrix * pt = |D E F| |y| = |Ax+By+C Dx+Ey+F Gx+Hy+I| = ------- , -------
              |G H I| |1|                               Gx+Hy+I   Gx+Hy+I
Parameters
dststorage for mapped corner SkPoint
rectSkRect to map

Note: this does not perform perspective clipping (as that might result in more than 4 points, so results are suspect if the matrix contains perspective.

Definition at line 1620 of file SkMatrix.h.

1620 {
1621 // This could potentially be faster if we only transformed each x and y of the rect once.
1622 rect.toQuad(dst);
1623 this->mapPoints(dst, 4);
1624 }

◆ mapVector() [1/2]

SkVector SkMatrix::mapVector ( SkScalar  dx,
SkScalar  dy 
) const
inline

Returns vector (dx, dy) multiplied by SkMatrix, treating SkMatrix translation as zero. Given:

         | A B 0 |         | dx |
Matrix = | D E 0 |,  vec = | dy |
         | G H I |         |  1 |

each result vector is computed as:

           |A B 0| |dx|                                        A*dx+B*dy     D*dx+E*dy

Matrix * vec = |D E 0| |dy| = |A*dx+B*dy D*dx+E*dy G*dx+H*dy+I| = --------— , --------— |G H I| | 1| G*dx+H*dy+I G*dx+*dHy+I

Parameters
dxx-axis value of vector to map
dyy-axis value of vector to map
Returns
mapped vector

Definition at line 1546 of file SkMatrix.h.

1546 {
1547 SkVector vec = { dx, dy };
1548 this->mapVectors(&vec, &vec, 1);
1549 return vec;
1550 }
skia_private::AutoTArray< sk_sp< SkImageFilter > > filters TypedMatrix matrix TypedMatrix matrix SkScalar dx
Definition: SkRecords.h:208

◆ mapVector() [2/2]

void SkMatrix::mapVector ( SkScalar  dx,
SkScalar  dy,
SkVector result 
) const
inline

Maps vector (dx, dy) to result. Vector is mapped by multiplying by SkMatrix, treating SkMatrix translation as zero. Given:

         | A B 0 |         | dx |
Matrix = | D E 0 |,  vec = | dy |
         | G H I |         |  1 |

each result vector is computed as:

           |A B 0| |dx|                                        A*dx+B*dy     D*dx+E*dy

Matrix * vec = |D E 0| |dy| = |A*dx+B*dy D*dx+E*dy G*dx+H*dy+I| = --------— , --------— |G H I| | 1| G*dx+H*dy+I G*dx+*dHy+I

Parameters
dxx-axis value of vector to map
dyy-axis value of vector to map
resultstorage for mapped vector

Definition at line 1524 of file SkMatrix.h.

1524 {
1525 SkVector vec = { dx, dy };
1526 this->mapVectors(result, &vec, 1);
1527 }

◆ mapVectors() [1/2]

void SkMatrix::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. Vectors are mapped by multiplying each vector by SkMatrix, treating SkMatrix translation as zero. Given:

         | A B 0 |         | x |
Matrix = | D E 0 |,  src = | y |
         | G H I |         | 1 |

where

for (i = 0; i < count; ++i) {
    x = src[i].fX
    y = src[i].fY
}

each dst vector is computed as:

               |A B 0| |x|                            Ax+By     Dx+Ey
Matrix * src = |D E 0| |y| = |Ax+By Dx+Ey Gx+Hy+I| = ------- , -------
               |G H I| |1|                           Gx+Hy+I   Gx+Hy+I

src and dst may point to the same storage.

Parameters
dststorage for mapped vectors
srcvectors to transform
countnumber of vectors to transform

example: https://fiddle.skia.org/c/@Matrix_mapVectors

Definition at line 1097 of file SkMatrix.cpp.

1097 {
1098 if (this->hasPerspective()) {
1099 SkPoint origin;
1100
1101 MapXYProc proc = this->getMapXYProc();
1102 proc(*this, 0, 0, &origin);
1103
1104 for (int i = count - 1; i >= 0; --i) {
1105 SkPoint tmp;
1106
1107 proc(*this, src[i].fX, src[i].fY, &tmp);
1108 dst[i].set(tmp.fX - origin.fX, tmp.fY - origin.fY);
1109 }
1110 } else {
1111 SkMatrix tmp = *this;
1112
1113 tmp.fMat[kMTransX] = tmp.fMat[kMTransY] = 0;
1114 tmp.clearTypeMask(kTranslate_Mask);
1115 tmp.mapPoints(dst, src, count);
1116 }
1117}
float fX
x-axis value
Definition: SkPoint_impl.h:164
float fY
y-axis value
Definition: SkPoint_impl.h:165

◆ mapVectors() [2/2]

void SkMatrix::mapVectors ( SkVector  vecs[],
int  count 
) const
inline

Maps vecs vector array of length count in place, multiplying each vector by SkMatrix, treating SkMatrix translation as zero. Given:

         | A B 0 |         | x |
Matrix = | D E 0 |,  vec = | y |
         | G H I |         | 1 |

where

for (i = 0; i < count; ++i) {
    x = vecs[i].fX
    y = vecs[i].fY
}

each result vector is computed as:

               |A B 0| |x|                            Ax+By     Dx+Ey
Matrix * vec = |D E 0| |y| = |Ax+By Dx+Ey Gx+Hy+I| = ------- , -------
               |G H I| |1|                           Gx+Hy+I   Gx+Hy+I
Parameters
vecsvectors to transform, and storage for mapped vectors
countnumber of vectors to transform

Definition at line 1503 of file SkMatrix.h.

1503 {
1504 this->mapVectors(vecs, vecs, count);
1505 }

◆ mapXY() [1/2]

SkPoint SkMatrix::mapXY ( SkScalar  x,
SkScalar  y 
) const
inline

Returns SkPoint (x, y) multiplied by SkMatrix. Given:

         | A B C |        | x |
Matrix = | D E F |,  pt = | y |
         | G H I |        | 1 |

result is computed as:

              |A B C| |x|                               Ax+By+C   Dx+Ey+F
Matrix * pt = |D E F| |y| = |Ax+By+C Dx+Ey+F Gx+Hy+I| = ------- , -------
              |G H I| |1|                               Gx+Hy+I   Gx+Hy+I
Parameters
xx-axis value of SkPoint to map
yy-axis value of SkPoint to map
Returns
mapped SkPoint

Definition at line 1416 of file SkMatrix.h.

1416 {
1418 this->mapXY(x,y, &result);
1419 return result;
1420 }

◆ mapXY() [2/2]

void SkMatrix::mapXY ( SkScalar  x,
SkScalar  y,
SkPoint result 
) const

Maps SkPoint (x, y) to result. SkPoint is mapped by multiplying by SkMatrix. Given:

         | A B C |        | x |
Matrix = | D E F |,  pt = | y |
         | G H I |        | 1 |

result is computed as:

              |A B C| |x|                               Ax+By+C   Dx+Ey+F
Matrix * pt = |D E F| |y| = |Ax+By+C Dx+Ey+F Gx+Hy+I| = ------- , -------
              |G H I| |1|                               Gx+Hy+I   Gx+Hy+I
Parameters
xx-axis value of SkPoint to map
yy-axis value of SkPoint to map
resultstorage for mapped SkPoint

example: https://fiddle.skia.org/c/@Matrix_mapXY

Definition at line 777 of file SkMatrix.cpp.

777 {
779 this->getMapXYProc()(*this, x, y, result);
780}

◆ normalizePerspective()

void SkMatrix::normalizePerspective ( )
inline

A matrix is categorized as 'perspective' if the bottom row is not [0, 0, 1]. However, for most uses (e.g. mapPoints) a bottom row of [0, 0, X] behaves like a non-perspective matrix, though it will be categorized as perspective. Calling normalizePerspective() will change the matrix such that, if its bottom row was [0, 0, X], it will be changed to [0, 0, 1] by scaling the rest of the matrix by 1/X.

| A B C | | A/X B/X C/X | | D E F | -> | D/X E/X F/X | for X != 0 | 0 0 X | | 0 0 1 |

Definition at line 1270 of file SkMatrix.h.

1270 {
1271 if (fMat[8] != 1) {
1272 this->doNormalizePerspective();
1273 }
1274 }

◆ operator[]() [1/2]

SkScalar & SkMatrix::operator[] ( int  index)
inline

Returns writable SkMatrix value. Asserts if index is out of range and SK_DEBUG is defined. Clears internal cache anticipating that caller will change SkMatrix value.

Next call to read SkMatrix state may recompute cache; subsequent writes to SkMatrix value must be followed by dirtyMatrixTypeCache().

Parameters
indexone of: kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY, kMPersp0, kMPersp1, kMPersp2
Returns
writable value corresponding to index

Definition at line 476 of file SkMatrix.h.

476 {
477 SkASSERT((unsigned)index < 9);
478 this->setTypeMask(kUnknown_Mask);
479 return fMat[index];
480 }

◆ operator[]() [2/2]

SkScalar SkMatrix::operator[] ( int  index) const
inline

Returns one matrix value. Asserts if index is out of range and SK_DEBUG is defined.

Parameters
indexone of: kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY, kMPersp0, kMPersp1, kMPersp2
Returns
value corresponding to index

Definition at line 380 of file SkMatrix.h.

380 {
381 SkASSERT((unsigned)index < 9);
382 return fMat[index];
383 }

◆ postConcat()

SkMatrix & SkMatrix::postConcat ( const SkMatrix other)

Sets SkMatrix to SkMatrix other multiplied by SkMatrix. This can be thought of mapping by other after applying SkMatrix.

Given:

         | J K L |           | A B C |
Matrix = | M N O |,  other = | D E F |
         | P Q R |           | G H I |

sets SkMatrix to:

                 | A B C |   | J K L |   | AJ+BM+CP AK+BN+CQ AL+BO+CR |
other * Matrix = | D E F | * | M N O | = | DJ+EM+FP DK+EN+FQ DL+EO+FR |
                 | G H I |   | P Q R |   | GJ+HM+IP GK+HN+IQ GL+HO+IR |
Parameters
otherSkMatrix on left side of multiply expression

Definition at line 683 of file SkMatrix.cpp.

683 {
684 // check for identity first, so we don't do a needless copy of ourselves
685 // to ourselves inside setConcat()
686 if (!mat.isIdentity()) {
687 this->setConcat(mat, *this);
688 }
689 return *this;
690}
SkMatrix & setConcat(const SkMatrix &a, const SkMatrix &b)
Definition: SkMatrix.cpp:603

◆ postRotate() [1/2]

SkMatrix & SkMatrix::postRotate ( SkScalar  degrees)

Sets SkMatrix to SkMatrix constructed from rotating by degrees about pivot point (0, 0), multiplied by SkMatrix. This can be thought of as rotating about the origin after applying SkMatrix.

Positive degrees rotates clockwise.

Given:

         | J K L |                        | c -s 0 |
Matrix = | M N O |,  R(degrees, px, py) = | s  c 0 |
         | P Q R |                        | 0  0 1 |

where

c  = cos(degrees)
s  = sin(degrees)

sets SkMatrix to:

                              | c -s dx | | J K L |   | cJ-sM cK-sN cL-sO |
R(degrees, px, py) * Matrix = | s  c dy | | M N O | = | sJ+cM sK+cN sL+cO |
                              | 0  0  1 | | P Q R |   |     P     Q     R |
Parameters
degreesangle of axes relative to upright axes

Definition at line 480 of file SkMatrix.cpp.

480 {
481 SkMatrix m;
482 m.setRotate(degrees);
483 return this->postConcat(m);
484}
SkMatrix & postConcat(const SkMatrix &other)
Definition: SkMatrix.cpp:683

◆ postRotate() [2/2]

SkMatrix & SkMatrix::postRotate ( SkScalar  degrees,
SkScalar  px,
SkScalar  py 
)

Sets SkMatrix to SkMatrix constructed from rotating by degrees about pivot point (px, py), multiplied by SkMatrix. This can be thought of as rotating about a pivot point after applying SkMatrix.

Positive degrees rotates clockwise.

Given:

         | J K L |                        | c -s dx |
Matrix = | M N O |,  R(degrees, px, py) = | s  c dy |
         | P Q R |                        | 0  0  1 |

where

c  = cos(degrees)
s  = sin(degrees)
dx =  s * py + (1 - c) * px
dy = -s * px + (1 - c) * py

sets SkMatrix to:

                              |c -s dx| |J K L|   |cJ-sM+dx*P cK-sN+dx*Q cL-sO+dx+R|
R(degrees, px, py) * Matrix = |s  c dy| |M N O| = |sJ+cM+dy*P sK+cN+dy*Q sL+cO+dy*R|
                              |0  0  1| |P Q R|   |         P          Q          R|
Parameters
degreesangle of axes relative to upright axes
pxpivot on x-axis
pypivot on y-axis

Definition at line 474 of file SkMatrix.cpp.

474 {
475 SkMatrix m;
476 m.setRotate(degrees, px, py);
477 return this->postConcat(m);
478}

◆ postScale() [1/2]

SkMatrix & SkMatrix::postScale ( SkScalar  sx,
SkScalar  sy 
)

Sets SkMatrix to SkMatrix constructed from scaling by (sx, sy) about pivot point (0, 0), multiplied by SkMatrix. This can be thought of as scaling about the origin after applying SkMatrix.

Given:

         | J K L |               | sx  0  0 |
Matrix = | M N O |,  S(sx, sy) = |  0 sy  0 |
         | P Q R |               |  0  0  1 |

sets SkMatrix to:

                     | sx  0  0 | | J K L |   | sx*J sx*K sx*L |
S(sx, sy) * Matrix = |  0 sy  0 | | M N O | = | sy*M sy*N sy*O |
                     |  0  0  1 | | P Q R |   |    P    Q    R |
Parameters
sxhorizontal scale factor
syvertical scale factor

Definition at line 369 of file SkMatrix.cpp.

369 {
370 if (1 == sx && 1 == sy) {
371 return *this;
372 }
373 SkMatrix m;
374 m.setScale(sx, sy);
375 return this->postConcat(m);
376}

◆ postScale() [2/2]

SkMatrix & SkMatrix::postScale ( SkScalar  sx,
SkScalar  sy,
SkScalar  px,
SkScalar  py 
)

Sets SkMatrix to SkMatrix constructed from scaling by (sx, sy) about pivot point (px, py), multiplied by SkMatrix. This can be thought of as scaling about a pivot point after applying SkMatrix.

Given:

         | J K L |                       | sx  0 dx |
Matrix = | M N O |,  S(sx, sy, px, py) = |  0 sy dy |
         | P Q R |                       |  0  0  1 |

where

dx = px - sx * px
dy = py - sy * py

sets SkMatrix to:

                             | sx  0 dx | | J K L |   | sx*J+dx*P sx*K+dx*Q sx*L+dx+R |
S(sx, sy, px, py) * Matrix = |  0 sy dy | | M N O | = | sy*M+dy*P sy*N+dy*Q sy*O+dy*R |
                             |  0  0  1 | | P Q R |   |         P         Q         R |
Parameters
sxhorizontal scale factor
syvertical scale factor
pxpivot on x-axis
pypivot on y-axis

Definition at line 360 of file SkMatrix.cpp.

360 {
361 if (1 == sx && 1 == sy) {
362 return *this;
363 }
364 SkMatrix m;
365 m.setScale(sx, sy, px, py);
366 return this->postConcat(m);
367}

◆ postSkew() [1/2]

SkMatrix & SkMatrix::postSkew ( SkScalar  kx,
SkScalar  ky 
)

Sets SkMatrix to SkMatrix constructed from skewing by (kx, ky) about pivot point (0, 0), multiplied by SkMatrix. This can be thought of as skewing about the origin after applying SkMatrix.

Given:

         | J K L |               |  1 kx 0 |
Matrix = | M N O |,  K(kx, ky) = | ky  1 0 |
         | P Q R |               |  0  0 1 |

sets SkMatrix to:

                     |  1 kx 0 | | J K L |   | J+kx*M K+kx*N L+kx*O |
K(kx, ky) * Matrix = | ky  1 0 | | M N O | = | ky*J+M ky*K+N ky*L+O |
                     |  0  0 1 | | P Q R |   |      P      Q      R |
Parameters
kxhorizontal skew factor
kyvertical skew factor

Definition at line 530 of file SkMatrix.cpp.

530 {
531 SkMatrix m;
532 m.setSkew(sx, sy);
533 return this->postConcat(m);
534}

◆ postSkew() [2/2]

SkMatrix & SkMatrix::postSkew ( SkScalar  kx,
SkScalar  ky,
SkScalar  px,
SkScalar  py 
)

Sets SkMatrix to SkMatrix constructed from skewing by (kx, ky) about pivot point (px, py), multiplied by SkMatrix. This can be thought of as skewing about a pivot point after applying SkMatrix.

Given:

         | J K L |                       |  1 kx dx |
Matrix = | M N O |,  K(kx, ky, px, py) = | ky  1 dy |
         | P Q R |                       |  0  0  1 |

where

dx = -kx * py
dy = -ky * px

sets SkMatrix to:

                             | 1 kx dx| |J K L|   |J+kx*M+dx*P K+kx*N+dx*Q L+kx*O+dx+R|
K(kx, ky, px, py) * Matrix = |ky  1 dy| |M N O| = |ky*J+M+dy*P ky*K+N+dy*Q ky*L+O+dy*R|
                             | 0  0  1| |P Q R|   |          P           Q           R|
Parameters
kxhorizontal skew factor
kyvertical skew factor
pxpivot on x-axis
pypivot on y-axis

Definition at line 524 of file SkMatrix.cpp.

524 {
525 SkMatrix m;
526 m.setSkew(sx, sy, px, py);
527 return this->postConcat(m);
528}

◆ postTranslate()

SkMatrix & SkMatrix::postTranslate ( SkScalar  dx,
SkScalar  dy 
)

Sets SkMatrix to SkMatrix constructed from translation (dx, dy) multiplied by SkMatrix. This can be thought of as moving the point to be mapped after applying SkMatrix.

Given:

         | J K L |               | 1 0 dx |
Matrix = | M N O |,  T(dx, dy) = | 0 1 dy |
         | P Q R |               | 0 0  1 |

sets SkMatrix to:

                     | 1 0 dx | | J K L |   | J+dx*P K+dx*Q L+dx*R |
T(dx, dy) * Matrix = | 0 1 dy | | M N O | = | M+dy*P N+dy*Q O+dy*R |
                     | 0 0  1 | | P Q R |   |      P      Q      R |
Parameters
dxx-axis translation after applying SkMatrix
dyy-axis translation after applying SkMatrix

Definition at line 281 of file SkMatrix.cpp.

281 {
282 if (this->hasPerspective()) {
283 SkMatrix m;
284 m.setTranslate(dx, dy);
285 this->postConcat(m);
286 } else {
287 fMat[kMTransX] += dx;
288 fMat[kMTransY] += dy;
289 this->updateTranslateMask();
290 }
291 return *this;
292}

◆ preConcat()

SkMatrix & SkMatrix::preConcat ( const SkMatrix other)

Sets SkMatrix to SkMatrix multiplied by SkMatrix other. This can be thought of mapping by other before applying SkMatrix.

Given:

         | A B C |          | J K L |
Matrix = | D E F |, other = | M N O |
         | G H I |          | P Q R |

sets SkMatrix to:

                 | A B C |   | J K L |   | AJ+BM+CP AK+BN+CQ AL+BO+CR |
Matrix * other = | D E F | * | M N O | = | DJ+EM+FP DK+EN+FQ DL+EO+FR |
                 | G H I |   | P Q R |   | GJ+HM+IP GK+HN+IQ GL+HO+IR |
Parameters
otherSkMatrix on right side of multiply expression

Definition at line 674 of file SkMatrix.cpp.

674 {
675 // check for identity first, so we don't do a needless copy of ourselves
676 // to ourselves inside setConcat()
677 if(!mat.isIdentity()) {
678 this->setConcat(*this, mat);
679 }
680 return *this;
681}

◆ preRotate() [1/2]

SkMatrix & SkMatrix::preRotate ( SkScalar  degrees)

Sets SkMatrix to SkMatrix multiplied by SkMatrix constructed from rotating by degrees about pivot point (0, 0). This can be thought of as rotating about the origin before applying SkMatrix.

Positive degrees rotates clockwise.

Given:

         | A B C |                        | c -s 0 |
Matrix = | D E F |,  R(degrees, px, py) = | s  c 0 |
         | G H I |                        | 0  0 1 |

where

c  = cos(degrees)
s  = sin(degrees)

sets SkMatrix to:

                              | A B C | | c -s 0 |   | Ac+Bs -As+Bc C |
Matrix * R(degrees, px, py) = | D E F | | s  c 0 | = | Dc+Es -Ds+Ec F |
                              | G H I | | 0  0 1 |   | Gc+Hs -Gs+Hc I |
Parameters
degreesangle of axes relative to upright axes

Definition at line 468 of file SkMatrix.cpp.

468 {
469 SkMatrix m;
470 m.setRotate(degrees);
471 return this->preConcat(m);
472}
SkMatrix & preConcat(const SkMatrix &other)
Definition: SkMatrix.cpp:674

◆ preRotate() [2/2]

SkMatrix & SkMatrix::preRotate ( SkScalar  degrees,
SkScalar  px,
SkScalar  py 
)

Sets SkMatrix to SkMatrix multiplied by SkMatrix constructed from rotating by degrees about pivot point (px, py). This can be thought of as rotating about a pivot point before applying SkMatrix.

Positive degrees rotates clockwise.

Given:

         | A B C |                        | c -s dx |
Matrix = | D E F |,  R(degrees, px, py) = | s  c dy |
         | G H I |                        | 0  0  1 |

where

c  = cos(degrees)
s  = sin(degrees)
dx =  s * py + (1 - c) * px
dy = -s * px + (1 - c) * py

sets SkMatrix to:

                              | A B C | | c -s dx |   | Ac+Bs -As+Bc A*dx+B*dy+C |
Matrix * R(degrees, px, py) = | D E F | | s  c dy | = | Dc+Es -Ds+Ec D*dx+E*dy+F |
                              | G H I | | 0  0  1 |   | Gc+Hs -Gs+Hc G*dx+H*dy+I |
Parameters
degreesangle of axes relative to upright axes
pxpivot on x-axis
pypivot on y-axis

Definition at line 462 of file SkMatrix.cpp.

462 {
463 SkMatrix m;
464 m.setRotate(degrees, px, py);
465 return this->preConcat(m);
466}

◆ preScale() [1/2]

SkMatrix & SkMatrix::preScale ( SkScalar  sx,
SkScalar  sy 
)

Sets SkMatrix to SkMatrix multiplied by SkMatrix constructed from scaling by (sx, sy) about pivot point (0, 0). This can be thought of as scaling about the origin before applying SkMatrix.

Given:

         | A B C |               | sx  0  0 |
Matrix = | D E F |,  S(sx, sy) = |  0 sy  0 |
         | G H I |               |  0  0  1 |

sets SkMatrix to:

                     | A B C | | sx  0  0 |   | A*sx B*sy C |
Matrix * S(sx, sy) = | D E F | |  0 sy  0 | = | D*sx E*sy F |
                     | G H I | |  0  0  1 |   | G*sx H*sy I |
Parameters
sxhorizontal scale factor
syvertical scale factor

Definition at line 325 of file SkMatrix.cpp.

325 {
326 if (1 == sx && 1 == sy) {
327 return *this;
328 }
329
330 // the assumption is that these multiplies are very cheap, and that
331 // a full concat and/or just computing the matrix type is more expensive.
332 // Also, the fixed-point case checks for overflow, but the float doesn't,
333 // so we can get away with these blind multiplies.
334
335 fMat[kMScaleX] *= sx;
336 fMat[kMSkewY] *= sx;
337 fMat[kMPersp0] *= sx;
338
339 fMat[kMSkewX] *= sy;
340 fMat[kMScaleY] *= sy;
341 fMat[kMPersp1] *= sy;
342
343 // Attempt to simplify our type when applying an inverse scale.
344 // TODO: The persp/affine preconditions are in place to keep the mask consistent with
345 // what computeTypeMask() would produce (persp/skew always implies kScale).
346 // We should investigate whether these flag dependencies are truly needed.
347 if (fMat[kMScaleX] == 1 && fMat[kMScaleY] == 1
348 && !(fTypeMask & (kPerspective_Mask | kAffine_Mask))) {
349 this->clearTypeMask(kScale_Mask);
350 } else {
351 this->orTypeMask(kScale_Mask);
352 // Remove kRectStaysRect if the preScale factors were 0
353 if (!sx || !sy) {
354 this->clearTypeMask(kRectStaysRect_Mask);
355 }
356 }
357 return *this;
358}

◆ preScale() [2/2]

SkMatrix & 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 point (px, py). This can be thought of as scaling about a pivot point before applying SkMatrix.

Given:

         | A B C |                       | sx  0 dx |
Matrix = | D E F |,  S(sx, sy, px, py) = |  0 sy dy |
         | G H I |                       |  0  0  1 |

where

dx = px - sx * px
dy = py - sy * py

sets SkMatrix to:

                             | A B C | | sx  0 dx |   | A*sx B*sy A*dx+B*dy+C |
Matrix * S(sx, sy, px, py) = | D E F | |  0 sy dy | = | D*sx E*sy D*dx+E*dy+F |
                             | G H I | |  0  0  1 |   | G*sx H*sy G*dx+H*dy+I |
Parameters
sxhorizontal scale factor
syvertical scale factor
pxpivot on x-axis
pypivot on y-axis

Definition at line 315 of file SkMatrix.cpp.

315 {
316 if (1 == sx && 1 == sy) {
317 return *this;
318 }
319
320 SkMatrix m;
321 m.setScale(sx, sy, px, py);
322 return this->preConcat(m);
323}

◆ preservesAxisAlignment()

bool SkMatrix::preservesAxisAlignment ( ) const
inline

Returns true SkMatrix maps SkRect to another SkRect. If true, SkMatrix is identity, or scales, or rotates a multiple of 90 degrees, or mirrors on axes. In all cases, SkMatrix may also have translation. SkMatrix form is either:

| scale-x    0    translate-x |
|    0    scale-y translate-y |
|    0       0         1      |

or

|    0     rotate-x translate-x |
| rotate-y    0     translate-y |
|    0        0          1      |

for non-zero values of scale-x, scale-y, rotate-x, and rotate-y.

Also called rectStaysRect(); use the one that provides better inline documentation.

Returns
true if SkMatrix maps one SkRect into another

Definition at line 299 of file SkMatrix.h.

299{ return this->rectStaysRect(); }

◆ preservesRightAngles()

bool SkMatrix::preservesRightAngles ( SkScalar  tol = SK_ScalarNearlyZero) const

Returns true if SkMatrix contains only translation, rotation, reflection, and scale. Scale may differ along rotated axes. Returns false if SkMatrix skewing, perspective, or degenerate forms that collapse to a line or point.

Preserves right angles, but not requiring that the arms of the angle retain equal lengths.

Parameters
tolto be deprecated
Returns
true if SkMatrix only rotates, scales, translates

example: https://fiddle.skia.org/c/@Matrix_preservesRightAngles

Definition at line 209 of file SkMatrix.cpp.

209 {
210 TypeMask mask = this->getType();
211
212 if (mask <= kTranslate_Mask) {
213 // identity, translate and/or scale
214 return true;
215 }
216 if (mask & kPerspective_Mask) {
217 return false;
218 }
219
221
222 SkScalar mx = fMat[kMScaleX];
223 SkScalar my = fMat[kMScaleY];
224 SkScalar sx = fMat[kMSkewX];
225 SkScalar sy = fMat[kMSkewY];
226
227 if (is_degenerate_2x2(mx, sx, sy, my)) {
228 return false;
229 }
230
231 // upper 2x2 is scale + rotation/reflection if basis vectors are orthogonal
232 SkVector vec[2];
233 vec[0].set(mx, sy);
234 vec[1].set(sx, my);
235
236 return SkScalarNearlyZero(vec[0].dot(vec[1]), SkScalarSquare(tol));
237}
static SkScalar SkScalarSquare(SkScalar x)
Definition: SkScalar.h:71
SINT T dot(const Vec< N, T > &a, const Vec< N, T > &b)
Definition: SkVx.h:964

◆ preSkew() [1/2]

SkMatrix & SkMatrix::preSkew ( SkScalar  kx,
SkScalar  ky 
)

Sets SkMatrix to SkMatrix multiplied by SkMatrix constructed from skewing by (kx, ky) about pivot point (0, 0). This can be thought of as skewing about the origin before applying SkMatrix.

Given:

         | A B C |               |  1 kx 0 |
Matrix = | D E F |,  K(kx, ky) = | ky  1 0 |
         | G H I |               |  0  0 1 |

sets SkMatrix to:

                     | A B C | |  1 kx 0 |   | A+B*ky A*kx+B C |
Matrix * K(kx, ky) = | D E F | | ky  1 0 | = | D+E*ky D*kx+E F |
                     | G H I | |  0  0 1 |   | G+H*ky G*kx+H I |
Parameters
kxhorizontal skew factor
kyvertical skew factor

Definition at line 518 of file SkMatrix.cpp.

518 {
519 SkMatrix m;
520 m.setSkew(sx, sy);
521 return this->preConcat(m);
522}

◆ preSkew() [2/2]

SkMatrix & 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 point (px, py). This can be thought of as skewing about a pivot point before applying SkMatrix.

Given:

         | A B C |                       |  1 kx dx |
Matrix = | D E F |,  K(kx, ky, px, py) = | ky  1 dy |
         | G H I |                       |  0  0  1 |

where

dx = -kx * py
dy = -ky * px

sets SkMatrix to:

                             | A B C | |  1 kx dx |   | A+B*ky A*kx+B A*dx+B*dy+C |
Matrix * K(kx, ky, px, py) = | D E F | | ky  1 dy | = | D+E*ky D*kx+E D*dx+E*dy+F |
                             | G H I | |  0  0  1 |   | G+H*ky G*kx+H G*dx+H*dy+I |
Parameters
kxhorizontal skew factor
kyvertical skew factor
pxpivot on x-axis
pypivot on y-axis

Definition at line 512 of file SkMatrix.cpp.

512 {
513 SkMatrix m;
514 m.setSkew(sx, sy, px, py);
515 return this->preConcat(m);
516}

◆ preTranslate()

SkMatrix & SkMatrix::preTranslate ( SkScalar  dx,
SkScalar  dy 
)

Sets SkMatrix to SkMatrix multiplied by SkMatrix constructed from translation (dx, dy). This can be thought of as moving the point to be mapped before applying SkMatrix.

Given:

         | A B C |               | 1 0 dx |
Matrix = | D E F |,  T(dx, dy) = | 0 1 dy |
         | G H I |               | 0 0  1 |

sets SkMatrix to:

                     | A B C | | 1 0 dx |   | A B A*dx+B*dy+C |
Matrix * T(dx, dy) = | D E F | | 0 1 dy | = | D E D*dx+E*dy+F |
                     | G H I | | 0 0  1 |   | G H G*dx+H*dy+I |
Parameters
dxx-axis translation before applying SkMatrix
dyy-axis translation before applying SkMatrix

Definition at line 263 of file SkMatrix.cpp.

263 {
264 const unsigned mask = this->getType();
265
266 if (mask <= kTranslate_Mask) {
267 fMat[kMTransX] += dx;
268 fMat[kMTransY] += dy;
269 } else if (mask & kPerspective_Mask) {
270 SkMatrix m;
271 m.setTranslate(dx, dy);
272 return this->preConcat(m);
273 } else {
274 fMat[kMTransX] += sdot(fMat[kMScaleX], dx, fMat[kMSkewX], dy);
275 fMat[kMTransY] += sdot(fMat[kMSkewY], dx, fMat[kMScaleY], dy);
276 }
277 this->updateTranslateMask();
278 return *this;
279}
static SkScalar sdot(SkScalar a, SkScalar b, SkScalar c, SkScalar d)
Definition: SkMatrix.cpp:241

◆ rc()

SkScalar SkMatrix::rc ( int  r,
int  c 
) const
inline

Returns one matrix value from a particular row/column. Asserts if index is out of range and SK_DEBUG is defined.

Parameters
rmatrix row to fetch
cmatrix column to fetch
Returns
value at the given matrix position

Definition at line 404 of file SkMatrix.h.

404 {
405 SkASSERT(r >= 0 && r <= 2);
406 SkASSERT(c >= 0 && c <= 2);
407 return fMat[r*3 + c];
408 }

◆ rectStaysRect()

bool SkMatrix::rectStaysRect ( ) const
inline

Returns true SkMatrix maps SkRect to another SkRect. If true, SkMatrix is identity, or scales, or rotates a multiple of 90 degrees, or mirrors on axes. In all cases, SkMatrix may also have translation. SkMatrix form is either:

| scale-x    0    translate-x |
|    0    scale-y translate-y |
|    0       0         1      |

or

|    0     rotate-x translate-x |
| rotate-y    0     translate-y |
|    0        0          1      |

for non-zero values of scale-x, scale-y, rotate-x, and rotate-y.

Also called preservesAxisAlignment(); use the one that provides better inline documentation.

Returns
true if SkMatrix maps one SkRect into another

Definition at line 271 of file SkMatrix.h.

271 {
272 if (fTypeMask & kUnknown_Mask) {
273 fTypeMask = this->computeTypeMask();
274 }
275 return (fTypeMask & kRectStaysRect_Mask) != 0;
276 }

◆ RectToRect()

static SkMatrix SkMatrix::RectToRect ( const SkRect src,
const SkRect dst,
ScaleToFit  mode = kFill_ScaleToFit 
)
inlinestatic

Returns SkMatrix set to scale and translate src to dst. ScaleToFit selects whether mapping completely fills dst or preserves the aspect ratio, and how to align src within dst. Returns the identity SkMatrix if src is empty. If dst is empty, returns SkMatrix set to:

| 0 0 0 |
| 0 0 0 |
| 0 0 1 |
Parameters
srcSkRect to map from
dstSkRect to map to
modeHow to handle the mapping
Returns
SkMatrix mapping src to dst

Definition at line 157 of file SkMatrix.h.

158 {
159 return MakeRectToRect(src, dst, mode);
160 }
static SkMatrix MakeRectToRect(const SkRect &src, const SkRect &dst, ScaleToFit stf)
Definition: SkMatrix.h:1172
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
Definition: switches.h:228

◆ reset()

SkMatrix & SkMatrix::reset ( )

Sets SkMatrix to identity; which has no effect on mapped SkPoint. Sets SkMatrix to:

| 1 0 0 |
| 0 1 0 |
| 0 0 1 |

Also called setIdentity(); use the one that provides better inline documentation.

Definition at line 49 of file SkMatrix.cpp.

49{ *this = SkMatrix(); return *this; }

◆ RotateDeg() [1/2]

static SkMatrix SkMatrix::RotateDeg ( SkScalar  deg)
inlinestatic

Sets SkMatrix to rotate by |deg| about a pivot point at (0, 0).

Parameters
degrotation angle in degrees (positive rotates clockwise)
Returns
SkMatrix with rotation

Definition at line 104 of file SkMatrix.h.

104 {
105 SkMatrix m;
106 m.setRotate(deg);
107 return m;
108 }

◆ RotateDeg() [2/2]

static SkMatrix SkMatrix::RotateDeg ( SkScalar  deg,
SkPoint  pt 
)
inlinestatic

Definition at line 109 of file SkMatrix.h.

109 {
110 SkMatrix m;
111 m.setRotate(deg, pt.x(), pt.y());
112 return m;
113 }

◆ RotateRad()

static SkMatrix SkMatrix::RotateRad ( SkScalar  rad)
inlinestatic

Definition at line 114 of file SkMatrix.h.

114 {
115 return RotateDeg(SkRadiansToDegrees(rad));
116 }
#define SkRadiansToDegrees(radians)
Definition: SkScalar.h:78
static SkMatrix RotateDeg(SkScalar deg)
Definition: SkMatrix.h:104

◆ Scale()

SkMatrix::Scale ( SkScalar  sx,
SkScalar  sy 
)
inlinestatic

Sets SkMatrix to scale by (sx, sy). Returned matrix is:

| sx  0  0 |
|  0 sy  0 |
|  0  0  1 |
Parameters
sxhorizontal scale factor
syvertical scale factor
Returns
SkMatrix with scale

Definition at line 75 of file SkMatrix.h.

75 {
76 SkMatrix m;
77 m.setScale(sx, sy);
78 return m;
79 }

◆ set()

SkMatrix & SkMatrix::set ( int  index,
SkScalar  value 
)
inline

Sets SkMatrix value. Asserts if index is out of range and SK_DEBUG is defined. Safer than operator[]; internal cache is always maintained.

Parameters
indexone of: kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY, kMPersp0, kMPersp1, kMPersp2
valuescalar to store in SkMatrix

Definition at line 489 of file SkMatrix.h.

489 {
490 SkASSERT((unsigned)index < 9);
491 fMat[index] = value;
492 this->setTypeMask(kUnknown_Mask);
493 return *this;
494 }
uint8_t value

◆ set9()

SkMatrix & SkMatrix::set9 ( const SkScalar  buffer[9])

Sets SkMatrix to nine scalar values in buffer, in member value ascending order: kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY, kMPersp0, kMPersp1, kMPersp2.

Sets matrix to:

| buffer[0] buffer[1] buffer[2] |
| buffer[3] buffer[4] buffer[5] |
| buffer[6] buffer[7] buffer[8] |

In the future, set9 followed by get9 may not return the same values. Since SkMatrix maps non-homogeneous coordinates, scaling all nine values produces an equivalent transformation, possibly improving precision.

Parameters
buffernine scalar values

Definition at line 51 of file SkMatrix.cpp.

51 {
52 memcpy(fMat, buffer, 9 * sizeof(SkScalar));
53 this->setTypeMask(kUnknown_Mask);
54 return *this;
55}

◆ setAffine()

SkMatrix & SkMatrix::setAffine ( const SkScalar  affine[6])

Sets SkMatrix to affine values, passed in column major order. Given affine, column, then row, as:

| scale-x  skew-x translate-x |
|  skew-y scale-y translate-y |

SkMatrix is set, row, then column, to:

| scale-x  skew-x translate-x |
|  skew-y scale-y translate-y |
|       0       0           1 |
Parameters
affine3 by 2 affine matrix

Definition at line 57 of file SkMatrix.cpp.

57 {
58 fMat[kMScaleX] = buffer[kAScaleX];
59 fMat[kMSkewX] = buffer[kASkewX];
60 fMat[kMTransX] = buffer[kATransX];
61 fMat[kMSkewY] = buffer[kASkewY];
62 fMat[kMScaleY] = buffer[kAScaleY];
63 fMat[kMTransY] = buffer[kATransY];
64 fMat[kMPersp0] = 0;
65 fMat[kMPersp1] = 0;
66 fMat[kMPersp2] = 1;
67 this->setTypeMask(kUnknown_Mask);
68 return *this;
69}

◆ SetAffineIdentity()

void SkMatrix::SetAffineIdentity ( SkScalar  affine[6])
static

Fills affine with identity values in column major order. Sets affine to:

| 1 0 0 |
| 0 1 0 |

Affine 3 by 2 matrices in column major order are used by OpenGL and XPS.

Parameters
affinestorage for 3 by 2 affine matrix

example: https://fiddle.skia.org/c/@Matrix_SetAffineIdentity

Definition at line 746 of file SkMatrix.cpp.

746 {
747 affine[kAScaleX] = 1;
748 affine[kASkewY] = 0;
749 affine[kASkewX] = 0;
750 affine[kAScaleY] = 1;
751 affine[kATransX] = 0;
752 affine[kATransY] = 0;
753}

◆ setAll()

SkMatrix & SkMatrix::setAll ( SkScalar  scaleX,
SkScalar  skewX,
SkScalar  transX,
SkScalar  skewY,
SkScalar  scaleY,
SkScalar  transY,
SkScalar  persp0,
SkScalar  persp1,
SkScalar  persp2 
)
inline

Sets all values from parameters. Sets matrix to:

| scaleX  skewX transX |
|  skewY scaleY transY |
| persp0 persp1 persp2 |
Parameters
scaleXhorizontal scale factor to store
skewXhorizontal skew factor to store
transXhorizontal translation to store
skewYvertical skew factor to store
scaleYvertical scale factor to store
transYvertical translation to store
persp0input x-axis values perspective factor to store
persp1input y-axis values perspective factor to store
persp2perspective scale factor to store

Definition at line 562 of file SkMatrix.h.

564 {
565 fMat[kMScaleX] = scaleX;
566 fMat[kMSkewX] = skewX;
567 fMat[kMTransX] = transX;
568 fMat[kMSkewY] = skewY;
569 fMat[kMScaleY] = scaleY;
570 fMat[kMTransY] = transY;
571 fMat[kMPersp0] = persp0;
572 fMat[kMPersp1] = persp1;
573 fMat[kMPersp2] = persp2;
574 this->setTypeMask(kUnknown_Mask);
575 return *this;
576 }

◆ setConcat()

SkMatrix & SkMatrix::setConcat ( const SkMatrix a,
const SkMatrix b 
)

Sets SkMatrix to SkMatrix a multiplied by SkMatrix b. Either a or b may be this.

Given:

    | A B C |      | J K L |
a = | D E F |, b = | M N O |
    | G H I |      | P Q R |

sets SkMatrix to:

        | A B C |   | J K L |   | AJ+BM+CP AK+BN+CQ AL+BO+CR |
a * b = | D E F | * | M N O | = | DJ+EM+FP DK+EN+FQ DL+EO+FR |
        | G H I |   | P Q R |   | GJ+HM+IP GK+HN+IQ GL+HO+IR |
Parameters
aSkMatrix on left side of multiply expression
bSkMatrix on right side of multiply expression

Definition at line 603 of file SkMatrix.cpp.

603 {
604 TypeMask aType = a.getType();
605 TypeMask bType = b.getType();
606
607 if (a.isTriviallyIdentity()) {
608 *this = b;
609 } else if (b.isTriviallyIdentity()) {
610 *this = a;
611 } else if (only_scale_and_translate(aType | bType)) {
612 this->setScaleTranslate(a.fMat[kMScaleX] * b.fMat[kMScaleX],
613 a.fMat[kMScaleY] * b.fMat[kMScaleY],
614 a.fMat[kMScaleX] * b.fMat[kMTransX] + a.fMat[kMTransX],
615 a.fMat[kMScaleY] * b.fMat[kMTransY] + a.fMat[kMTransY]);
616 } else {
617 SkMatrix tmp;
618
619 if ((aType | bType) & kPerspective_Mask) {
620 tmp.fMat[kMScaleX] = rowcol3(&a.fMat[0], &b.fMat[0]);
621 tmp.fMat[kMSkewX] = rowcol3(&a.fMat[0], &b.fMat[1]);
622 tmp.fMat[kMTransX] = rowcol3(&a.fMat[0], &b.fMat[2]);
623 tmp.fMat[kMSkewY] = rowcol3(&a.fMat[3], &b.fMat[0]);
624 tmp.fMat[kMScaleY] = rowcol3(&a.fMat[3], &b.fMat[1]);
625 tmp.fMat[kMTransY] = rowcol3(&a.fMat[3], &b.fMat[2]);
626 tmp.fMat[kMPersp0] = rowcol3(&a.fMat[6], &b.fMat[0]);
627 tmp.fMat[kMPersp1] = rowcol3(&a.fMat[6], &b.fMat[1]);
628 tmp.fMat[kMPersp2] = rowcol3(&a.fMat[6], &b.fMat[2]);
629
630 tmp.setTypeMask(kUnknown_Mask);
631 } else {
632 tmp.fMat[kMScaleX] = muladdmul(a.fMat[kMScaleX],
633 b.fMat[kMScaleX],
634 a.fMat[kMSkewX],
635 b.fMat[kMSkewY]);
636
637 tmp.fMat[kMSkewX] = muladdmul(a.fMat[kMScaleX],
638 b.fMat[kMSkewX],
639 a.fMat[kMSkewX],
640 b.fMat[kMScaleY]);
641
642 tmp.fMat[kMTransX] = muladdmul(a.fMat[kMScaleX],
643 b.fMat[kMTransX],
644 a.fMat[kMSkewX],
645 b.fMat[kMTransY]) + a.fMat[kMTransX];
646
647 tmp.fMat[kMSkewY] = muladdmul(a.fMat[kMSkewY],
648 b.fMat[kMScaleX],
649 a.fMat[kMScaleY],
650 b.fMat[kMSkewY]);
651
652 tmp.fMat[kMScaleY] = muladdmul(a.fMat[kMSkewY],
653 b.fMat[kMSkewX],
654 a.fMat[kMScaleY],
655 b.fMat[kMScaleY]);
656
657 tmp.fMat[kMTransY] = muladdmul(a.fMat[kMSkewY],
658 b.fMat[kMTransX],
659 a.fMat[kMScaleY],
660 b.fMat[kMTransY]) + a.fMat[kMTransY];
661
662 tmp.fMat[kMPersp0] = 0;
663 tmp.fMat[kMPersp1] = 0;
664 tmp.fMat[kMPersp2] = 1;
665 //SkDebugf("Concat mat non-persp type: %d\n", tmp.getType());
666 //SkASSERT(!(tmp.getType() & kPerspective_Mask));
667 tmp.setTypeMask(kUnknown_Mask | kOnlyPerspectiveValid_Mask);
668 }
669 *this = tmp;
670 }
671 return *this;
672}
static bool only_scale_and_translate(unsigned mask)
Definition: SkMatrix.cpp:599
static float rowcol3(const float row[], const float col[])
Definition: SkMatrix.cpp:595
static float muladdmul(float a, float b, float c, float d)
Definition: SkMatrix.cpp:591
void setScaleTranslate(SkScalar sx, SkScalar sy, SkScalar tx, SkScalar ty)
Definition: SkMatrix.h:1803

◆ setIdentity()

SkMatrix & SkMatrix::setIdentity ( )
inline

Sets SkMatrix to identity; which has no effect on mapped SkPoint. Sets SkMatrix to:

| 1 0 0 |
| 0 1 0 |
| 0 0 1 |

Also called reset(); use the one that provides better inline documentation.

Definition at line 626 of file SkMatrix.h.

626{ return this->reset(); }

◆ setPerspX()

SkMatrix & SkMatrix::setPerspX ( SkScalar  v)
inline

Sets input x-axis perspective factor, which causes mapXY() to vary input x-axis values inversely proportional to input y-axis values.

Parameters
vperspective factor

Definition at line 537 of file SkMatrix.h.

537{ return this->set(kMPersp0, v); }
SkMatrix & set(int index, SkScalar value)
Definition: SkMatrix.h:489

◆ setPerspY()

SkMatrix & SkMatrix::setPerspY ( SkScalar  v)
inline

Sets input y-axis perspective factor, which causes mapXY() to vary input y-axis values inversely proportional to input x-axis values.

Parameters
vperspective factor

Definition at line 544 of file SkMatrix.h.

544{ return this->set(kMPersp1, v); }

◆ setPolyToPoly()

bool SkMatrix::setPolyToPoly ( const SkPoint  src[],
const SkPoint  dst[],
int  count 
)

Sets SkMatrix to map src to dst. count must be zero or greater, and four or less.

If count is zero, sets SkMatrix to identity and returns true. If count is one, sets SkMatrix to translate and returns true. If count is two or more, sets SkMatrix to map SkPoint if possible; returns false if SkMatrix cannot be constructed. If count is four, SkMatrix may include perspective.

Parameters
srcSkPoint to map from
dstSkPoint to map to
countnumber of SkPoint in src and dst
Returns
true if SkMatrix was constructed successfully

example: https://fiddle.skia.org/c/@Matrix_setPolyToPoly

Definition at line 1385 of file SkMatrix.cpp.

1385 {
1386 if ((unsigned)count > 4) {
1387 SkDebugf("--- SkMatrix::setPolyToPoly count out of range %d\n", count);
1388 return false;
1389 }
1390
1391 if (0 == count) {
1392 this->reset();
1393 return true;
1394 }
1395 if (1 == count) {
1396 this->setTranslate(dst[0].fX - src[0].fX, dst[0].fY - src[0].fY);
1397 return true;
1398 }
1399
1400 const PolyMapProc gPolyMapProcs[] = {
1401 SkMatrix::Poly2Proc, SkMatrix::Poly3Proc, SkMatrix::Poly4Proc
1402 };
1403 PolyMapProc proc = gPolyMapProcs[count - 2];
1404
1405 SkMatrix tempMap, result;
1406
1407 if (!proc(src, &tempMap)) {
1408 return false;
1409 }
1410 if (!tempMap.invert(&result)) {
1411 return false;
1412 }
1413 if (!proc(dst, &tempMap)) {
1414 return false;
1415 }
1416 this->setConcat(tempMap, result);
1417 return true;
1418}
bool(* PolyMapProc)(const SkPoint[], SkMatrix *)
Definition: SkMatrix.cpp:1381
SkMatrix & setTranslate(SkScalar dx, SkScalar dy)
Definition: SkMatrix.cpp:254
bool invert(SkMatrix *inverse) const
Definition: SkMatrix.h:1206

◆ setRectToRect()

bool SkMatrix::setRectToRect ( const SkRect src,
const SkRect dst,
ScaleToFit  stf 
)

Sets SkMatrix to scale and translate src SkRect to dst SkRect. stf selects whether mapping completely fills dst or preserves the aspect ratio, and how to align src within dst. Returns false if src is empty, and sets SkMatrix to identity. Returns true if dst is empty, and sets SkMatrix to:

| 0 0 0 |
| 0 0 0 |
| 0 0 1 |
Parameters
srcSkRect to map from
dstSkRect to map to
Returns
true if SkMatrix can represent SkRect mapping

example: https://fiddle.skia.org/c/@Matrix_setRectToRect

Definition at line 538 of file SkMatrix.cpp.

538 {
539 if (src.isEmpty()) {
540 this->reset();
541 return false;
542 }
543
544 if (dst.isEmpty()) {
545 sk_bzero(fMat, 8 * sizeof(SkScalar));
546 fMat[kMPersp2] = 1;
547 this->setTypeMask(kScale_Mask);
548 } else {
549 SkScalar tx, sx = sk_ieee_float_divide(dst.width(), src.width());
550 SkScalar ty, sy = sk_ieee_float_divide(dst.height(), src.height());
551 bool xLarger = false;
552
553 if (align != kFill_ScaleToFit) {
554 if (sx > sy) {
555 xLarger = true;
556 sx = sy;
557 } else {
558 sy = sx;
559 }
560 }
561
562 tx = dst.fLeft - src.fLeft * sx;
563 ty = dst.fTop - src.fTop * sy;
564 if (align == kCenter_ScaleToFit || align == kEnd_ScaleToFit) {
565 SkScalar diff;
566
567 if (xLarger) {
568 diff = dst.width() - src.width() * sy;
569 } else {
570 diff = dst.height() - src.height() * sy;
571 }
572
573 if (align == kCenter_ScaleToFit) {
574 diff = SkScalarHalf(diff);
575 }
576
577 if (xLarger) {
578 tx += diff;
579 } else {
580 ty += diff;
581 }
582 }
583
584 this->setScaleTranslate(sx, sy, tx, ty);
585 }
586 return true;
587}
sk_bzero(glyphs, sizeof(glyphs))
static constexpr float sk_ieee_float_divide(float numer, float denom)
#define SkScalarHalf(a)
Definition: SkScalar.h:75
bool isEmpty() const
Definition: SkRect.h:693

◆ setRotate() [1/2]

SkMatrix & SkMatrix::setRotate ( SkScalar  degrees)

Sets SkMatrix to rotate by degrees about a pivot point at (0, 0). Positive degrees rotates clockwise.

Parameters
degreesangle of axes relative to upright axes

Definition at line 457 of file SkMatrix.cpp.

457 {
458 SkScalar rad = SkDegreesToRadians(degrees);
460}
#define SkDegreesToRadians(degrees)
Definition: SkScalar.h:77
static float SkScalarSinSnapToZero(SkScalar radians)
Definition: SkScalar.h:115
static float SkScalarCosSnapToZero(SkScalar radians)
Definition: SkScalar.h:120
SkMatrix & setSinCos(SkScalar sinValue, SkScalar cosValue, SkScalar px, SkScalar py)
Definition: SkMatrix.cpp:402

◆ setRotate() [2/2]

SkMatrix & SkMatrix::setRotate ( SkScalar  degrees,
SkScalar  px,
SkScalar  py 
)

Sets SkMatrix to rotate by degrees about a pivot point at (px, py). The pivot point is unchanged when mapped with SkMatrix.

Positive degrees rotates clockwise.

Parameters
degreesangle of axes relative to upright axes
pxpivot on x-axis
pypivot on y-axis

Definition at line 452 of file SkMatrix.cpp.

452 {
453 SkScalar rad = SkDegreesToRadians(degrees);
454 return this->setSinCos(SkScalarSinSnapToZero(rad), SkScalarCosSnapToZero(rad), px, py);
455}

◆ setRSXform()

SkMatrix & SkMatrix::setRSXform ( const SkRSXform rsxForm)

Sets SkMatrix to rotate, scale, and translate using a compressed matrix form.

Vector (rsxForm.fSSin, rsxForm.fSCos) describes the angle of rotation relative to (0, 1). Vector length specifies scale. Mapped point is rotated and scaled by vector, then translated by (rsxForm.fTx, rsxForm.fTy).

Parameters
rsxFormcompressed SkRSXform matrix
Returns
reference to SkMatrix

example: https://fiddle.skia.org/c/@Matrix_setRSXform

Definition at line 420 of file SkMatrix.cpp.

420 {
421 fMat[kMScaleX] = xform.fSCos;
422 fMat[kMSkewX] = -xform.fSSin;
423 fMat[kMTransX] = xform.fTx;
424
425 fMat[kMSkewY] = xform.fSSin;
426 fMat[kMScaleY] = xform.fSCos;
427 fMat[kMTransY] = xform.fTy;
428
429 fMat[kMPersp0] = fMat[kMPersp1] = 0;
430 fMat[kMPersp2] = 1;
431
432 this->setTypeMask(kUnknown_Mask | kOnlyPerspectiveValid_Mask);
433 return *this;
434}

◆ setScale() [1/2]

SkMatrix & SkMatrix::setScale ( SkScalar  sx,
SkScalar  sy 
)

Sets SkMatrix to scale by sx and sy about at pivot point at (0, 0).

Parameters
sxhorizontal scale factor
syvertical scale factor

Definition at line 305 of file SkMatrix.cpp.

305 {
306 auto rectMask = (sx == 0 || sy == 0) ? 0 : kRectStaysRect_Mask;
307 *this = SkMatrix(sx, 0, 0,
308 0, sy, 0,
309 0, 0, 1,
310 (sx == 1 && sy == 1) ? kIdentity_Mask | rectMask
311 : kScale_Mask | rectMask);
312 return *this;
313}

◆ setScale() [2/2]

SkMatrix & 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). The pivot point is unchanged when mapped with SkMatrix.

Parameters
sxhorizontal scale factor
syvertical scale factor
pxpivot on x-axis
pypivot on y-axis

Definition at line 296 of file SkMatrix.cpp.

296 {
297 if (1 == sx && 1 == sy) {
298 this->reset();
299 } else {
300 this->setScaleTranslate(sx, sy, px - sx * px, py - sy * py);
301 }
302 return *this;
303}

◆ setScaleTranslate()

void SkMatrix::setScaleTranslate ( SkScalar  sx,
SkScalar  sy,
SkScalar  tx,
SkScalar  ty 
)
inline

Initializes SkMatrix with scale and translate elements.

| sx  0 tx |
|  0 sy ty |
|  0  0  1 |
Parameters
sxhorizontal scale factor to store
syvertical scale factor to store
txhorizontal translation to store
tyvertical translation to store

Definition at line 1803 of file SkMatrix.h.

1803 {
1804 fMat[kMScaleX] = sx;
1805 fMat[kMSkewX] = 0;
1806 fMat[kMTransX] = tx;
1807
1808 fMat[kMSkewY] = 0;
1809 fMat[kMScaleY] = sy;
1810 fMat[kMTransY] = ty;
1811
1812 fMat[kMPersp0] = 0;
1813 fMat[kMPersp1] = 0;
1814 fMat[kMPersp2] = 1;
1815
1816 int mask = 0;
1817 if (sx != 1 || sy != 1) {
1818 mask |= kScale_Mask;
1819 }
1820 if (tx != 0.0f || ty != 0.0f) {
1821 mask |= kTranslate_Mask;
1822 }
1823 if (sx != 0 && sy != 0) {
1824 mask |= kRectStaysRect_Mask;
1825 }
1826 this->setTypeMask(mask);
1827 }

◆ setScaleX()

SkMatrix & SkMatrix::setScaleX ( SkScalar  v)
inline

Sets horizontal scale factor.

Parameters
vhorizontal scale factor to store

Definition at line 500 of file SkMatrix.h.

500{ return this->set(kMScaleX, v); }

◆ setScaleY()

SkMatrix & SkMatrix::setScaleY ( SkScalar  v)
inline

Sets vertical scale factor.

Parameters
vvertical scale factor to store

Definition at line 506 of file SkMatrix.h.

506{ return this->set(kMScaleY, v); }

◆ setSinCos() [1/2]

SkMatrix & SkMatrix::setSinCos ( SkScalar  sinValue,
SkScalar  cosValue 
)

Sets SkMatrix to rotate by sinValue and cosValue, about a pivot point at (0, 0).

Vector (sinValue, cosValue) describes the angle of rotation relative to (0, 1). Vector length specifies scale.

Parameters
sinValuerotation vector x-axis component
cosValuerotation vector y-axis component

Definition at line 436 of file SkMatrix.cpp.

436 {
437 fMat[kMScaleX] = cosV;
438 fMat[kMSkewX] = -sinV;
439 fMat[kMTransX] = 0;
440
441 fMat[kMSkewY] = sinV;
442 fMat[kMScaleY] = cosV;
443 fMat[kMTransY] = 0;
444
445 fMat[kMPersp0] = fMat[kMPersp1] = 0;
446 fMat[kMPersp2] = 1;
447
448 this->setTypeMask(kUnknown_Mask | kOnlyPerspectiveValid_Mask);
449 return *this;
450}

◆ setSinCos() [2/2]

SkMatrix & 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). The pivot point is unchanged when mapped with SkMatrix.

Vector (sinValue, cosValue) describes the angle of rotation relative to (0, 1). Vector length specifies scale.

Parameters
sinValuerotation vector x-axis component
cosValuerotation vector y-axis component
pxpivot on x-axis
pypivot on y-axis

Definition at line 402 of file SkMatrix.cpp.

402 {
403 const SkScalar oneMinusCosV = 1 - cosV;
404
405 fMat[kMScaleX] = cosV;
406 fMat[kMSkewX] = -sinV;
407 fMat[kMTransX] = sdot(sinV, py, oneMinusCosV, px);
408
409 fMat[kMSkewY] = sinV;
410 fMat[kMScaleY] = cosV;
411 fMat[kMTransY] = sdot(-sinV, px, oneMinusCosV, py);
412
413 fMat[kMPersp0] = fMat[kMPersp1] = 0;
414 fMat[kMPersp2] = 1;
415
416 this->setTypeMask(kUnknown_Mask | kOnlyPerspectiveValid_Mask);
417 return *this;
418}

◆ setSkew() [1/2]

SkMatrix & SkMatrix::setSkew ( SkScalar  kx,
SkScalar  ky 
)

Sets SkMatrix to skew by kx and ky, about a pivot point at (0, 0).

Parameters
kxhorizontal skew factor
kyvertical skew factor

Definition at line 496 of file SkMatrix.cpp.

496 {
497 fMat[kMScaleX] = 1;
498 fMat[kMSkewX] = sx;
499 fMat[kMTransX] = 0;
500
501 fMat[kMSkewY] = sy;
502 fMat[kMScaleY] = 1;
503 fMat[kMTransY] = 0;
504
505 fMat[kMPersp0] = fMat[kMPersp1] = 0;
506 fMat[kMPersp2] = 1;
507
508 this->setTypeMask(kUnknown_Mask | kOnlyPerspectiveValid_Mask);
509 return *this;
510}

◆ setSkew() [2/2]

SkMatrix & 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). The pivot point is unchanged when mapped with SkMatrix.

Parameters
kxhorizontal skew factor
kyvertical skew factor
pxpivot on x-axis
pypivot on y-axis

Definition at line 488 of file SkMatrix.cpp.

488 {
489 *this = SkMatrix(1, sx, -sx * py,
490 sy, 1, -sy * px,
491 0, 0, 1,
492 kUnknown_Mask | kOnlyPerspectiveValid_Mask);
493 return *this;
494}

◆ setSkewX()

SkMatrix & SkMatrix::setSkewX ( SkScalar  v)
inline

Sets horizontal skew factor.

Parameters
vhorizontal skew factor to store

Definition at line 518 of file SkMatrix.h.

518{ return this->set(kMSkewX, v); }

◆ setSkewY()

SkMatrix & SkMatrix::setSkewY ( SkScalar  v)
inline

Sets vertical skew factor.

Parameters
vvertical skew factor to store

Definition at line 512 of file SkMatrix.h.

512{ return this->set(kMSkewY, v); }

◆ setTranslate() [1/2]

SkMatrix & SkMatrix::setTranslate ( const SkVector v)
inline

Sets SkMatrix to translate by (v.fX, v.fY).

Parameters
vvector containing horizontal and vertical translation

Definition at line 639 of file SkMatrix.h.

639{ return this->setTranslate(v.fX, v.fY); }

◆ setTranslate() [2/2]

SkMatrix & SkMatrix::setTranslate ( SkScalar  dx,
SkScalar  dy 
)

Sets SkMatrix to translate by (dx, dy).

Parameters
dxhorizontal translation
dyvertical translation

Definition at line 254 of file SkMatrix.cpp.

254 {
255 *this = SkMatrix(1, 0, dx,
256 0, 1, dy,
257 0, 0, 1,
258 (dx != 0 || dy != 0) ? kTranslate_Mask | kRectStaysRect_Mask
259 : kIdentity_Mask | kRectStaysRect_Mask);
260 return *this;
261}

◆ setTranslateX()

SkMatrix & SkMatrix::setTranslateX ( SkScalar  v)
inline

Sets horizontal translation.

Parameters
vhorizontal translation to store

Definition at line 524 of file SkMatrix.h.

524{ return this->set(kMTransX, v); }

◆ setTranslateY()

SkMatrix & SkMatrix::setTranslateY ( SkScalar  v)
inline

Sets vertical translation.

Parameters
vvertical translation to store

Definition at line 530 of file SkMatrix.h.

530{ return this->set(kMTransY, v); }

◆ Skew()

static SkMatrix SkMatrix::Skew ( SkScalar  kx,
SkScalar  ky 
)
inlinestatic

Sets SkMatrix to skew by (kx, ky) about pivot point (0, 0).

Parameters
kxhorizontal skew factor
kyvertical skew factor
Returns
SkMatrix with skew

Definition at line 124 of file SkMatrix.h.

124 {
125 SkMatrix m;
126 m.setSkew(kx, ky);
127 return m;
128 }

◆ Translate() [1/3]

static SkMatrix SkMatrix::Translate ( SkIVector  t)
inlinestatic

Definition at line 97 of file SkMatrix.h.

97{ return Translate(t.x(), t.y()); }
static SkMatrix Translate(SkScalar dx, SkScalar dy)
Definition: SkMatrix.h:91
constexpr int32_t y() const
Definition: SkPoint_impl.h:52
constexpr int32_t x() const
Definition: SkPoint_impl.h:46

◆ Translate() [2/3]

static SkMatrix SkMatrix::Translate ( SkScalar  dx,
SkScalar  dy 
)
inlinestatic

Sets SkMatrix to translate by (dx, dy). Returned matrix is:

| 1 0 dx |
| 0 1 dy |
| 0 0  1 |
Parameters
dxhorizontal translation
dyvertical translation
Returns
SkMatrix with translation

Definition at line 91 of file SkMatrix.h.

91 {
92 SkMatrix m;
93 m.setTranslate(dx, dy);
94 return m;
95 }

◆ Translate() [3/3]

static SkMatrix SkMatrix::Translate ( SkVector  t)
inlinestatic

Definition at line 96 of file SkMatrix.h.

96{ return Translate(t.x(), t.y()); }

Friends And Related Function Documentation

◆ operator!=

SK_API bool operator!= ( const SkMatrix a,
const SkMatrix b 
)
friend

Compares a and b; returns true if a and b are not numerically equal. Returns false even if sign of zero values are different. Returns true if either SkMatrix contains NaN, even if the other SkMatrix also contains NaN.

Parameters
aSkMatrix to compare
bSkMatrix to compare
Returns
true if SkMatrix a and SkMatrix b are numerically not equal

Definition at line 1667 of file SkMatrix.h.

1667 {
1668 return !(a == b);
1669 }

◆ operator*

SkMatrix operator* ( const SkMatrix a,
const SkMatrix b 
)
friend

Definition at line 1781 of file SkMatrix.h.

1781 {
1782 return Concat(a, b);
1783 }
static SkMatrix Concat(const SkMatrix &a, const SkMatrix &b)
Definition: SkMatrix.h:1775

◆ operator==

SK_API bool operator== ( const SkMatrix a,
const SkMatrix b 
)
friend

Compares a and b; returns true if a and b are numerically equal. Returns true even if sign of zero values are different. Returns false if either SkMatrix contains NaN, even if the other SkMatrix also contains NaN.

Parameters
aSkMatrix to compare
bSkMatrix to compare
Returns
true if SkMatrix a and SkMatrix b are numerically equal

Definition at line 160 of file SkMatrix.cpp.

160 {
161 const SkScalar* SK_RESTRICT ma = a.fMat;
162 const SkScalar* SK_RESTRICT mb = b.fMat;
163
164 return ma[0] == mb[0] && ma[1] == mb[1] && ma[2] == mb[2] &&
165 ma[3] == mb[3] && ma[4] == mb[4] && ma[5] == mb[5] &&
166 ma[6] == mb[6] && ma[7] == mb[7] && ma[8] == mb[8];
167}
#define SK_RESTRICT
Definition: SkFeatures.h:42

◆ SerializationTest

friend class SerializationTest
friend

Definition at line 1993 of file SkMatrix.h.

◆ SkMatrixPriv

friend class SkMatrixPriv
friend

Definition at line 1992 of file SkMatrix.h.

◆ SkPerspIter

friend class SkPerspIter
friend

Definition at line 1991 of file SkMatrix.h.

Member Data Documentation

◆ kAScaleX

constexpr int SkMatrix::kAScaleX = 0
staticconstexpr

horizontal scale factor

Affine arrays are in column-major order to match the matrix used by PDF and XPS.

Definition at line 366 of file SkMatrix.h.

◆ kAScaleY

constexpr int SkMatrix::kAScaleY = 3
staticconstexpr

vertical scale factor

Definition at line 369 of file SkMatrix.h.

◆ kASkewX

constexpr int SkMatrix::kASkewX = 2
staticconstexpr

horizontal skew factor

Definition at line 368 of file SkMatrix.h.

◆ kASkewY

constexpr int SkMatrix::kASkewY = 1
staticconstexpr

vertical skew factor

Definition at line 367 of file SkMatrix.h.

◆ kATransX

constexpr int SkMatrix::kATransX = 4
staticconstexpr

horizontal translation

Definition at line 370 of file SkMatrix.h.

◆ kATransY

constexpr int SkMatrix::kATransY = 5
staticconstexpr

vertical translation

Definition at line 371 of file SkMatrix.h.

◆ kMPersp0

constexpr int SkMatrix::kMPersp0 = 6
staticconstexpr

input x perspective factor

Definition at line 359 of file SkMatrix.h.

◆ kMPersp1

constexpr int SkMatrix::kMPersp1 = 7
staticconstexpr

input y perspective factor

Definition at line 360 of file SkMatrix.h.

◆ kMPersp2

constexpr int SkMatrix::kMPersp2 = 8
staticconstexpr

perspective bias

Definition at line 361 of file SkMatrix.h.

◆ kMScaleX

constexpr int SkMatrix::kMScaleX = 0
staticconstexpr

horizontal scale factor

SkMatrix organizes its values in row-major order. These members correspond to each value in SkMatrix.

Definition at line 353 of file SkMatrix.h.

◆ kMScaleY

constexpr int SkMatrix::kMScaleY = 4
staticconstexpr

vertical scale factor

Definition at line 357 of file SkMatrix.h.

◆ kMSkewX

constexpr int SkMatrix::kMSkewX = 1
staticconstexpr

horizontal skew factor

Definition at line 354 of file SkMatrix.h.

◆ kMSkewY

constexpr int SkMatrix::kMSkewY = 3
staticconstexpr

vertical skew factor

Definition at line 356 of file SkMatrix.h.

◆ kMTransX

constexpr int SkMatrix::kMTransX = 2
staticconstexpr

horizontal translation

Definition at line 355 of file SkMatrix.h.

◆ kMTransY

constexpr int SkMatrix::kMTransY = 5
staticconstexpr

vertical translation

Definition at line 358 of file SkMatrix.h.


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