Debian Codegraph @

include/core/SkMatrix.h

raw
1 /*
2 * Copyright 2006 The Android Open Source Project
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #ifndef SkMatrix_DEFINED
9 #define SkMatrix_DEFINED
10
11 #include "include/core/SkPoint.h"
12 #include "include/core/SkPoint3.h"
13 #include "include/core/SkRect.h"
14 #include "include/core/SkScalar.h"
15 #include "include/core/SkSpan.h"
16 #include "include/core/SkTypes.h"
17 #include "include/private/base/SkFloatingPoint.h"
18 #include "include/private/base/SkMacros.h"
19 #include "include/private/base/SkTo.h"
20
21 #include <cstdint>
22 #include <cstring>
23 #include <optional>
24
25 struct SkRSXform;
26 struct SkSize;
27
28 // Remove when clients are updated to live without this
29 #define SK_SUPPORT_LEGACY_MATRIX_RECTTORECT
30
31 /** \class SkMatrix
32 SkMatrix holds a 3x3 matrix for transforming coordinates. This allows mapping
33 SkPoint and vectors with translation, scaling, skewing, rotation, and
34 perspective.
35
36 SkMatrix elements are in row major order.
37 SkMatrix constexpr default constructs to identity.
38
39 SkMatrix includes a hidden variable that classifies the type of matrix to
40 improve performance. SkMatrix is not thread safe unless getType() is called first.
41
42 example: https://fiddle.skia.org/c/@Matrix_063
43 */
44 SK_BEGIN_REQUIRE_DENSE
45 class SK_API SkMatrix {
46 public:
47
48 /** Creates an identity SkMatrix:
49
50 | 1 0 0 |
51 | 0 1 0 |
52 | 0 0 1 |
53 */
54 constexpr SkMatrix() : SkMatrix(1,0,0, 0,1,0, 0,0,1, kIdentity_Mask | kRectStaysRect_Mask) {}
55
56 /** Sets SkMatrix to scale by (sx, sy). Returned matrix is:
57
58 | sx 0 0 |
59 | 0 sy 0 |
60 | 0 0 1 |
61
62 @param sx horizontal scale factor
63 @param sy vertical scale factor
64 @return SkMatrix with scale
65 */
66 [[nodiscard]] static SkMatrix Scale(SkScalar sx, SkScalar sy) {
67 SkMatrix m;
68 m.setScale(sx, sy);
69 return m;
70 }
71
72 /** Sets SkMatrix to translate by (dx, dy). Returned matrix is:
73
74 | 1 0 dx |
75 | 0 1 dy |
76 | 0 0 1 |
77
78 @param dx horizontal translation
79 @param dy vertical translation
80 @return SkMatrix with translation
81 */
82 [[nodiscard]] static SkMatrix Translate(SkScalar dx, SkScalar dy) {
83 SkMatrix m;
84 m.setTranslate(dx, dy);
85 return m;
86 }
87 [[nodiscard]] static SkMatrix Translate(SkVector t) { return Translate(t.x(), t.y()); }
88 [[nodiscard]] static SkMatrix Translate(SkIVector t) { return Translate(t.x(), t.y()); }
89
90 [[nodiscard]] static SkMatrix ScaleTranslate(float sx, float sy, float tx, float ty);
91
92 /** Sets SkMatrix to rotate by |deg| about a pivot point at (0, 0).
93
94 @param deg rotation angle in degrees (positive rotates clockwise)
95 @return SkMatrix with rotation
96 */
97 [[nodiscard]] static SkMatrix RotateDeg(SkScalar deg) {
98 SkMatrix m;
99 m.setRotate(deg);
100 return m;
101 }
102 [[nodiscard]] static SkMatrix RotateDeg(SkScalar deg, SkPoint pt) {
103 SkMatrix m;
104 m.setRotate(deg, pt.x(), pt.y());
105 return m;
106 }
107 [[nodiscard]] static SkMatrix RotateRad(SkScalar rad) {
108 return RotateDeg(SkRadiansToDegrees(rad));
109 }
110
111 /** Sets SkMatrix to skew by (kx, ky) about pivot point (0, 0).
112
113 @param kx horizontal skew factor
114 @param ky vertical skew factor
115 @return SkMatrix with skew
116 */
117 [[nodiscard]] static SkMatrix Skew(SkScalar kx, SkScalar ky) {
118 SkMatrix m;
119 m.setSkew(kx, ky);
120 return m;
121 }
122
123 /** \enum SkMatrix::ScaleToFit
124 ScaleToFit describes how SkMatrix is constructed to map one SkRect to another.
125 ScaleToFit may allow SkMatrix to have unequal horizontal and vertical scaling,
126 or may restrict SkMatrix to square scaling. If restricted, ScaleToFit specifies
127 how SkMatrix maps to the side or center of the destination SkRect.
128 */
129 enum ScaleToFit {
130 kFill_ScaleToFit, //!< scales in x and y to fill destination SkRect
131 kStart_ScaleToFit, //!< scales and aligns to left and top
132 kCenter_ScaleToFit, //!< scales and aligns to center
133 kEnd_ScaleToFit, //!< scales and aligns to right and bottom
134 };
135
136 /** Sets SkMatrix to:
137
138 | scaleX skewX transX |
139 | skewY scaleY transY |
140 | pers0 pers1 pers2 |
141
142 @param scaleX horizontal scale factor
143 @param skewX horizontal skew factor
144 @param transX horizontal translation
145 @param skewY vertical skew factor
146 @param scaleY vertical scale factor
147 @param transY vertical translation
148 @param pers0 input x-axis perspective factor
149 @param pers1 input y-axis perspective factor
150 @param pers2 perspective scale factor
151 @return SkMatrix constructed from parameters
152 */
153 [[nodiscard]] static SkMatrix MakeAll(SkScalar scaleX, SkScalar skewX, SkScalar transX,
154 SkScalar skewY, SkScalar scaleY, SkScalar transY,
155 SkScalar pers0, SkScalar pers1, SkScalar pers2) {
156 SkMatrix m;
157 m.setAll(scaleX, skewX, transX, skewY, scaleY, transY, pers0, pers1, pers2);
158 return m;
159 }
160
161 /** \enum SkMatrix::TypeMask
162 Enum of bit fields for mask returned by getType().
163 Used to identify the complexity of SkMatrix, to optimize performance.
164 */
165 enum TypeMask {
166 kIdentity_Mask = 0, //!< identity SkMatrix; all bits clear
167 kTranslate_Mask = 0x01, //!< translation SkMatrix
168 kScale_Mask = 0x02, //!< scale SkMatrix
169 kAffine_Mask = 0x04, //!< skew or rotate SkMatrix
170 kPerspective_Mask = 0x08, //!< perspective SkMatrix
171 };
172
173 /** Returns a bit field describing the transformations the matrix may
174 perform. The bit field is computed conservatively, so it may include
175 false positives. For example, when kPerspective_Mask is set, all
176 other bits are set.
177
178 @return kIdentity_Mask, or combinations of: kTranslate_Mask, kScale_Mask,
179 kAffine_Mask, kPerspective_Mask
180 */
181 TypeMask getType() const {
182 if (fTypeMask & kUnknown_Mask) {
183 fTypeMask = this->computeTypeMask();
184 }
185 // only return the public masks
186 return (TypeMask)(fTypeMask & 0xF);
187 }
188
189 /** Returns true if SkMatrix is identity. Identity matrix is:
190
191 | 1 0 0 |
192 | 0 1 0 |
193 | 0 0 1 |
194
195 @return true if SkMatrix has no effect
196 */
197 bool isIdentity() const {
198 return this->getType() == 0;
199 }
200
201 /** Returns true if SkMatrix at most scales and translates. SkMatrix may be identity,
202 contain only scale elements, only translate elements, or both. SkMatrix form is:
203
204 | scale-x 0 translate-x |
205 | 0 scale-y translate-y |
206 | 0 0 1 |
207
208 @return true if SkMatrix is identity; or scales, translates, or both
209 */
210 bool isScaleTranslate() const {
211 return !(this->getType() & ~(kScale_Mask | kTranslate_Mask));
212 }
213
214 /** Returns true if SkMatrix is identity, or translates. SkMatrix form is:
215
216 | 1 0 translate-x |
217 | 0 1 translate-y |
218 | 0 0 1 |
219
220 @return true if SkMatrix is identity, or translates
221 */
222 bool isTranslate() const { return !(this->getType() & ~(kTranslate_Mask)); }
223
224 /** Returns true SkMatrix maps SkRect to another SkRect. If true, SkMatrix is identity,
225 or scales, or rotates a multiple of 90 degrees, or mirrors on axes. In all
226 cases, SkMatrix may also have translation. SkMatrix form is either:
227
228 | scale-x 0 translate-x |
229 | 0 scale-y translate-y |
230 | 0 0 1 |
231
232 or
233
234 | 0 rotate-x translate-x |
235 | rotate-y 0 translate-y |
236 | 0 0 1 |
237
238 for non-zero values of scale-x, scale-y, rotate-x, and rotate-y.
239
240 Also called preservesAxisAlignment(); use the one that provides better inline
241 documentation.
242
243 @return true if SkMatrix maps one SkRect into another
244 */
245 bool rectStaysRect() const {
246 if (fTypeMask & kUnknown_Mask) {
247 fTypeMask = this->computeTypeMask();
248 }
249 return (fTypeMask & kRectStaysRect_Mask) != 0;
250 }
251
252 /** Returns true SkMatrix maps SkRect to another SkRect. If true, SkMatrix is identity,
253 or scales, or rotates a multiple of 90 degrees, or mirrors on axes. In all
254 cases, SkMatrix may also have translation. SkMatrix form is either:
255
256 | scale-x 0 translate-x |
257 | 0 scale-y translate-y |
258 | 0 0 1 |
259
260 or
261
262 | 0 rotate-x translate-x |
263 | rotate-y 0 translate-y |
264 | 0 0 1 |
265
266 for non-zero values of scale-x, scale-y, rotate-x, and rotate-y.
267
268 Also called rectStaysRect(); use the one that provides better inline
269 documentation.
270
271 @return true if SkMatrix maps one SkRect into another
272 */
273 bool preservesAxisAlignment() const { return this->rectStaysRect(); }
274
275 /** Returns true if the matrix contains perspective elements. SkMatrix form is:
276
277 | -- -- -- |
278 | -- -- -- |
279 | perspective-x perspective-y perspective-scale |
280
281 where perspective-x or perspective-y is non-zero, or perspective-scale is
282 not one. All other elements may have any value.
283
284 @return true if SkMatrix is in most general form
285 */
286 bool hasPerspective() const {
287 return SkToBool(this->getPerspectiveTypeMaskOnly() &
288 kPerspective_Mask);
289 }
290
291 /** Returns true if SkMatrix contains only translation, rotation, reflection, and
292 uniform scale.
293 Returns false if SkMatrix contains different scales, skewing, perspective, or
294 degenerate forms that collapse to a line or point.
295
296 Describes that the SkMatrix makes rendering with and without the matrix are
297 visually alike; a transformed circle remains a circle. Mathematically, this is
298 referred to as similarity of a Euclidean space, or a similarity transformation.
299
300 Preserves right angles, keeping the arms of the angle equal lengths.
301
302 @param tol to be deprecated
303 @return true if SkMatrix only rotates, uniformly scales, translates
304
305 example: https://fiddle.skia.org/c/@Matrix_isSimilarity
306 */
307 bool isSimilarity(SkScalar tol = SK_ScalarNearlyZero) const;
308
309 /** Returns true if SkMatrix contains only translation, rotation, reflection, and
310 scale. Scale may differ along rotated axes.
311 Returns false if SkMatrix skewing, perspective, or degenerate forms that collapse
312 to a line or point.
313
314 Preserves right angles, but not requiring that the arms of the angle
315 retain equal lengths.
316
317 @param tol to be deprecated
318 @return true if SkMatrix only rotates, scales, translates
319
320 example: https://fiddle.skia.org/c/@Matrix_preservesRightAngles
321 */
322 bool preservesRightAngles(SkScalar tol = SK_ScalarNearlyZero) const;
323
324 /** SkMatrix organizes its values in row-major order. These members correspond to
325 each value in SkMatrix.
326 */
327 static constexpr int kMScaleX = 0; //!< horizontal scale factor
328 static constexpr int kMSkewX = 1; //!< horizontal skew factor
329 static constexpr int kMTransX = 2; //!< horizontal translation
330 static constexpr int kMSkewY = 3; //!< vertical skew factor
331 static constexpr int kMScaleY = 4; //!< vertical scale factor
332 static constexpr int kMTransY = 5; //!< vertical translation
333 static constexpr int kMPersp0 = 6; //!< input x perspective factor
334 static constexpr int kMPersp1 = 7; //!< input y perspective factor
335 static constexpr int kMPersp2 = 8; //!< perspective bias
336
337 /** Affine arrays are in column-major order to match the matrix used by
338 PDF and XPS.
339 */
340 static constexpr int kAScaleX = 0; //!< horizontal scale factor
341 static constexpr int kASkewY = 1; //!< vertical skew factor
342 static constexpr int kASkewX = 2; //!< horizontal skew factor
343 static constexpr int kAScaleY = 3; //!< vertical scale factor
344 static constexpr int kATransX = 4; //!< horizontal translation
345 static constexpr int kATransY = 5; //!< vertical translation
346
347 /** Returns one matrix value. Asserts if index is out of range and SK_DEBUG is
348 defined.
349
350 @param index one of: kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY,
351 kMPersp0, kMPersp1, kMPersp2
352 @return value corresponding to index
353 */
354 SkScalar operator[](int index) const {
355 SkASSERT((unsigned)index < 9);
356 return fMat[index];
357 }
358
359 /** Returns one matrix value. Asserts if index is out of range and SK_DEBUG is
360 defined.
361
362 @param index one of: kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY,
363 kMPersp0, kMPersp1, kMPersp2
364 @return value corresponding to index
365 */
366 SkScalar get(int index) const {
367 SkASSERT((unsigned)index < 9);
368 return fMat[index];
369 }
370
371 /** Returns one matrix value from a particular row/column. Asserts if index is out
372 of range and SK_DEBUG is defined.
373
374 @param r matrix row to fetch
375 @param c matrix column to fetch
376 @return value at the given matrix position
377 */
378 SkScalar rc(int r, int c) const {
379 SkASSERT(r >= 0 && r <= 2);
380 SkASSERT(c >= 0 && c <= 2);
381 return fMat[r*3 + c];
382 }
383
384 /** Returns scale factor multiplied by x-axis input, contributing to x-axis output.
385 With mapPoints(), scales SkPoint along the x-axis.
386
387 @return horizontal scale factor
388 */
389 SkScalar getScaleX() const { return fMat[kMScaleX]; }
390
391 /** Returns scale factor multiplied by y-axis input, contributing to y-axis output.
392 With mapPoints(), scales SkPoint along the y-axis.
393
394 @return vertical scale factor
395 */
396 SkScalar getScaleY() const { return fMat[kMScaleY]; }
397
398 /** Returns scale factor multiplied by x-axis input, contributing to y-axis output.
399 With mapPoints(), skews SkPoint along the y-axis.
400 Skewing both axes can rotate SkPoint.
401
402 @return vertical skew factor
403 */
404 SkScalar getSkewY() const { return fMat[kMSkewY]; }
405
406 /** Returns scale factor multiplied by y-axis input, contributing to x-axis output.
407 With mapPoints(), skews SkPoint along the x-axis.
408 Skewing both axes can rotate SkPoint.
409
410 @return horizontal scale factor
411 */
412 SkScalar getSkewX() const { return fMat[kMSkewX]; }
413
414 /** Returns translation contributing to x-axis output.
415 With mapPoints(), moves SkPoint along the x-axis.
416
417 @return horizontal translation factor
418 */
419 SkScalar getTranslateX() const { return fMat[kMTransX]; }
420
421 /** Returns translation contributing to y-axis output.
422 With mapPoints(), moves SkPoint along the y-axis.
423
424 @return vertical translation factor
425 */
426 SkScalar getTranslateY() const { return fMat[kMTransY]; }
427
428 /** Returns factor scaling input x-axis relative to input y-axis.
429
430 @return input x-axis perspective factor
431 */
432 SkScalar getPerspX() const { return fMat[kMPersp0]; }
433
434 /** Returns factor scaling input y-axis relative to input x-axis.
435
436 @return input y-axis perspective factor
437 */
438 SkScalar getPerspY() const { return fMat[kMPersp1]; }
439
440 /** Returns writable SkMatrix value. Asserts if index is out of range and SK_DEBUG is
441 defined. Clears internal cache anticipating that caller will change SkMatrix value.
442
443 Next call to read SkMatrix state may recompute cache; subsequent writes to SkMatrix
444 value must be followed by dirtyMatrixTypeCache().
445
446 @param index one of: kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY,
447 kMPersp0, kMPersp1, kMPersp2
448 @return writable value corresponding to index
449 */
450 SkScalar& operator[](int index) {
451 SkASSERT((unsigned)index < 9);
452 this->setTypeMask(kUnknown_Mask);
453 return fMat[index];
454 }
455
456 /** Sets SkMatrix value. Asserts if index is out of range and SK_DEBUG is
457 defined. Safer than operator[]; internal cache is always maintained.
458
459 @param index one of: kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY,
460 kMPersp0, kMPersp1, kMPersp2
461 @param value scalar to store in SkMatrix
462 */
463 SkMatrix& set(int index, SkScalar value) {
464 SkASSERT((unsigned)index < 9);
465 fMat[index] = value;
466 this->setTypeMask(kUnknown_Mask);
467 return *this;
468 }
469
470 /** Sets horizontal scale factor.
471
472 @param v horizontal scale factor to store
473 */
474 SkMatrix& setScaleX(SkScalar v) { return this->set(kMScaleX, v); }
475
476 /** Sets vertical scale factor.
477
478 @param v vertical scale factor to store
479 */
480 SkMatrix& setScaleY(SkScalar v) { return this->set(kMScaleY, v); }
481
482 /** Sets vertical skew factor.
483
484 @param v vertical skew factor to store
485 */
486 SkMatrix& setSkewY(SkScalar v) { return this->set(kMSkewY, v); }
487
488 /** Sets horizontal skew factor.
489
490 @param v horizontal skew factor to store
491 */
492 SkMatrix& setSkewX(SkScalar v) { return this->set(kMSkewX, v); }
493
494 /** Sets horizontal translation.
495
496 @param v horizontal translation to store
497 */
498 SkMatrix& setTranslateX(SkScalar v) { return this->set(kMTransX, v); }
499
500 /** Sets vertical translation.
501
502 @param v vertical translation to store
503 */
504 SkMatrix& setTranslateY(SkScalar v) { return this->set(kMTransY, v); }
505
506 /** Sets input x-axis perspective factor, which causes mapPoints() to vary input x-axis values
507 inversely proportional to input y-axis values.
508
509 @param v perspective factor
510 */
511 SkMatrix& setPerspX(SkScalar v) { return this->set(kMPersp0, v); }
512
513 /** Sets input y-axis perspective factor, which causes mapPoints() to vary input y-axis values
514 inversely proportional to input x-axis values.
515
516 @param v perspective factor
517 */
518 SkMatrix& setPerspY(SkScalar v) { return this->set(kMPersp1, v); }
519
520 /** Sets all values from parameters. Sets matrix to:
521
522 | scaleX skewX transX |
523 | skewY scaleY transY |
524 | persp0 persp1 persp2 |
525
526 @param scaleX horizontal scale factor to store
527 @param skewX horizontal skew factor to store
528 @param transX horizontal translation to store
529 @param skewY vertical skew factor to store
530 @param scaleY vertical scale factor to store
531 @param transY vertical translation to store
532 @param persp0 input x-axis values perspective factor to store
533 @param persp1 input y-axis values perspective factor to store
534 @param persp2 perspective scale factor to store
535 */
536 SkMatrix& setAll(SkScalar scaleX, SkScalar skewX, SkScalar transX,
537 SkScalar skewY, SkScalar scaleY, SkScalar transY,
538 SkScalar persp0, SkScalar persp1, SkScalar persp2) {
539 fMat[kMScaleX] = scaleX;
540 fMat[kMSkewX] = skewX;
541 fMat[kMTransX] = transX;
542 fMat[kMSkewY] = skewY;
543 fMat[kMScaleY] = scaleY;
544 fMat[kMTransY] = transY;
545 fMat[kMPersp0] = persp0;
546 fMat[kMPersp1] = persp1;
547 fMat[kMPersp2] = persp2;
548 this->setTypeMask(kUnknown_Mask);
549 return *this;
550 }
551
552 /** Copies nine scalar values contained by SkMatrix into buffer, in member value
553 ascending order: kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY,
554 kMPersp0, kMPersp1, kMPersp2.
555
556 @param buffer storage for nine scalar values
557 */
558 void get9(SkScalar buffer[9]) const {
559 memcpy(buffer, fMat, 9 * sizeof(SkScalar));
560 }
561
562 /** Sets SkMatrix to nine scalar values in buffer, in member value ascending order:
563 kMScaleX, kMSkewX, kMTransX, kMSkewY, kMScaleY, kMTransY, kMPersp0, kMPersp1,
564 kMPersp2.
565
566 Sets matrix to:
567
568 | buffer[0] buffer[1] buffer[2] |
569 | buffer[3] buffer[4] buffer[5] |
570 | buffer[6] buffer[7] buffer[8] |
571
572 In the future, set9 followed by get9 may not return the same values. Since SkMatrix
573 maps non-homogeneous coordinates, scaling all nine values produces an equivalent
574 transformation, possibly improving precision.
575
576 @param buffer nine scalar values
577 */
578 SkMatrix& set9(const SkScalar buffer[9]);
579
580 /** Sets SkMatrix to identity; which has no effect on mapped SkPoint. Sets SkMatrix to:
581
582 | 1 0 0 |
583 | 0 1 0 |
584 | 0 0 1 |
585
586 Also called setIdentity(); use the one that provides better inline
587 documentation.
588 */
589 SkMatrix& reset();
590
591 /** Sets SkMatrix to identity; which has no effect on mapped SkPoint. Sets SkMatrix to:
592
593 | 1 0 0 |
594 | 0 1 0 |
595 | 0 0 1 |
596
597 Also called reset(); use the one that provides better inline
598 documentation.
599 */
600 SkMatrix& setIdentity() { return this->reset(); }
601
602 /** Sets SkMatrix to translate by (dx, dy).
603
604 @param dx horizontal translation
605 @param dy vertical translation
606 */
607 SkMatrix& setTranslate(SkScalar dx, SkScalar dy);
608
609 /** Sets SkMatrix to translate by (v.fX, v.fY).
610
611 @param v vector containing horizontal and vertical translation
612 */
613 SkMatrix& setTranslate(const SkVector& v) { return this->setTranslate(v.fX, v.fY); }
614
615 /** Sets SkMatrix to scale by sx and sy, about a pivot point at (px, py).
616 The pivot point is unchanged when mapped with SkMatrix.
617
618 @param sx horizontal scale factor
619 @param sy vertical scale factor
620 @param px pivot on x-axis
621 @param py pivot on y-axis
622 */
623 SkMatrix& setScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py);
624
625 /** Sets SkMatrix to scale by sx and sy about at pivot point at (0, 0).
626
627 @param sx horizontal scale factor
628 @param sy vertical scale factor
629 */
630 SkMatrix& setScale(SkScalar sx, SkScalar sy);
631
632 /** Sets SkMatrix to rotate by degrees about a pivot point at (px, py).
633 The pivot point is unchanged when mapped with SkMatrix.
634
635 Positive degrees rotates clockwise.
636
637 @param degrees angle of axes relative to upright axes
638 @param px pivot on x-axis
639 @param py pivot on y-axis
640 */
641 SkMatrix& setRotate(SkScalar degrees, SkScalar px, SkScalar py);
642
643 /** Sets SkMatrix to rotate by degrees about a pivot point at (0, 0).
644 Positive degrees rotates clockwise.
645
646 @param degrees angle of axes relative to upright axes
647 */
648 SkMatrix& setRotate(SkScalar degrees);
649
650 /** Sets SkMatrix to rotate by sinValue and cosValue, about a pivot point at (px, py).
651 The pivot point is unchanged when mapped with SkMatrix.
652
653 Vector (sinValue, cosValue) describes the angle of rotation relative to (0, 1).
654 Vector length specifies scale.
655
656 @param sinValue rotation vector x-axis component
657 @param cosValue rotation vector y-axis component
658 @param px pivot on x-axis
659 @param py pivot on y-axis
660 */
661 SkMatrix& setSinCos(SkScalar sinValue, SkScalar cosValue,
662 SkScalar px, SkScalar py);
663
664 /** Sets SkMatrix to rotate by sinValue and cosValue, about a pivot point at (0, 0).
665
666 Vector (sinValue, cosValue) describes the angle of rotation relative to (0, 1).
667 Vector length specifies scale.
668
669 @param sinValue rotation vector x-axis component
670 @param cosValue rotation vector y-axis component
671 */
672 SkMatrix& setSinCos(SkScalar sinValue, SkScalar cosValue);
673
674 /** Sets SkMatrix to rotate, scale, and translate using a compressed matrix form.
675
676 Vector (rsxForm.fSSin, rsxForm.fSCos) describes the angle of rotation relative
677 to (0, 1). Vector length specifies scale. Mapped point is rotated and scaled
678 by vector, then translated by (rsxForm.fTx, rsxForm.fTy).
679
680 @param rsxForm compressed SkRSXform matrix
681 @return reference to SkMatrix
682
683 example: https://fiddle.skia.org/c/@Matrix_setRSXform
684 */
685 SkMatrix& setRSXform(const SkRSXform& rsxForm);
686
687 /** Sets SkMatrix to skew by kx and ky, about a pivot point at (px, py).
688 The pivot point is unchanged when mapped with SkMatrix.
689
690 @param kx horizontal skew factor
691 @param ky vertical skew factor
692 @param px pivot on x-axis
693 @param py pivot on y-axis
694 */
695 SkMatrix& setSkew(SkScalar kx, SkScalar ky, SkScalar px, SkScalar py);
696
697 /** Sets SkMatrix to skew by kx and ky, about a pivot point at (0, 0).
698
699 @param kx horizontal skew factor
700 @param ky vertical skew factor
701 */
702 SkMatrix& setSkew(SkScalar kx, SkScalar ky);
703
704 /** Sets SkMatrix to SkMatrix a multiplied by SkMatrix b. Either a or b may be this.
705
706 Given:
707
708 | A B C | | J K L |
709 a = | D E F |, b = | M N O |
710 | G H I | | P Q R |
711
712 sets SkMatrix to:
713
714 | A B C | | J K L | | AJ+BM+CP AK+BN+CQ AL+BO+CR |
715 a * b = | D E F | * | M N O | = | DJ+EM+FP DK+EN+FQ DL+EO+FR |
716 | G H I | | P Q R | | GJ+HM+IP GK+HN+IQ GL+HO+IR |
717
718 @param a SkMatrix on left side of multiply expression
719 @param b SkMatrix on right side of multiply expression
720 */
721 SkMatrix& setConcat(const SkMatrix& a, const SkMatrix& b);
722
723 /** Sets SkMatrix to SkMatrix multiplied by SkMatrix constructed from translation (dx, dy).
724 This can be thought of as moving the point to be mapped before applying SkMatrix.
725
726 Given:
727
728 | A B C | | 1 0 dx |
729 Matrix = | D E F |, T(dx, dy) = | 0 1 dy |
730 | G H I | | 0 0 1 |
731
732 sets SkMatrix to:
733
734 | A B C | | 1 0 dx | | A B A*dx+B*dy+C |
735 Matrix * T(dx, dy) = | D E F | | 0 1 dy | = | D E D*dx+E*dy+F |
736 | G H I | | 0 0 1 | | G H G*dx+H*dy+I |
737
738 @param dx x-axis translation before applying SkMatrix
739 @param dy y-axis translation before applying SkMatrix
740 */
741 SkMatrix& preTranslate(SkScalar dx, SkScalar dy);
742
743 /** Sets SkMatrix to SkMatrix multiplied by SkMatrix constructed from scaling by (sx, sy)
744 about pivot point (px, py).
745 This can be thought of as scaling about a pivot point before applying SkMatrix.
746
747 Given:
748
749 | A B C | | sx 0 dx |
750 Matrix = | D E F |, S(sx, sy, px, py) = | 0 sy dy |
751 | G H I | | 0 0 1 |
752
753 where
754
755 dx = px - sx * px
756 dy = py - sy * py
757
758 sets SkMatrix to:
759
760 | A B C | | sx 0 dx | | A*sx B*sy A*dx+B*dy+C |
761 Matrix * S(sx, sy, px, py) = | D E F | | 0 sy dy | = | D*sx E*sy D*dx+E*dy+F |
762 | G H I | | 0 0 1 | | G*sx H*sy G*dx+H*dy+I |
763
764 @param sx horizontal scale factor
765 @param sy vertical scale factor
766 @param px pivot on x-axis
767 @param py pivot on y-axis
768 */
769 SkMatrix& preScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py);
770
771 /** Sets SkMatrix to SkMatrix multiplied by SkMatrix constructed from scaling by (sx, sy)
772 about pivot point (0, 0).
773 This can be thought of as scaling about the origin before applying SkMatrix.
774
775 Given:
776
777 | A B C | | sx 0 0 |
778 Matrix = | D E F |, S(sx, sy) = | 0 sy 0 |
779 | G H I | | 0 0 1 |
780
781 sets SkMatrix to:
782
783 | A B C | | sx 0 0 | | A*sx B*sy C |
784 Matrix * S(sx, sy) = | D E F | | 0 sy 0 | = | D*sx E*sy F |
785 | G H I | | 0 0 1 | | G*sx H*sy I |
786
787 @param sx horizontal scale factor
788 @param sy vertical scale factor
789 */
790 SkMatrix& preScale(SkScalar sx, SkScalar sy);
791
792 /** Sets SkMatrix to SkMatrix multiplied by SkMatrix constructed from rotating by degrees
793 about pivot point (px, py).
794 This can be thought of as rotating about a pivot point before applying SkMatrix.
795
796 Positive degrees rotates clockwise.
797
798 Given:
799
800 | A B C | | c -s dx |
801 Matrix = | D E F |, R(degrees, px, py) = | s c dy |
802 | G H I | | 0 0 1 |
803
804 where
805
806 c = cos(degrees)
807 s = sin(degrees)
808 dx = s * py + (1 - c) * px
809 dy = -s * px + (1 - c) * py
810
811 sets SkMatrix to:
812
813 | A B C | | c -s dx | | Ac+Bs -As+Bc A*dx+B*dy+C |
814 Matrix * R(degrees, px, py) = | D E F | | s c dy | = | Dc+Es -Ds+Ec D*dx+E*dy+F |
815 | G H I | | 0 0 1 | | Gc+Hs -Gs+Hc G*dx+H*dy+I |
816
817 @param degrees angle of axes relative to upright axes
818 @param px pivot on x-axis
819 @param py pivot on y-axis
820 */
821 SkMatrix& preRotate(SkScalar degrees, SkScalar px, SkScalar py);
822
823 /** Sets SkMatrix to SkMatrix multiplied by SkMatrix constructed from rotating by degrees
824 about pivot point (0, 0).
825 This can be thought of as rotating about the origin before applying SkMatrix.
826
827 Positive degrees rotates clockwise.
828
829 Given:
830
831 | A B C | | c -s 0 |
832 Matrix = | D E F |, R(degrees, px, py) = | s c 0 |
833 | G H I | | 0 0 1 |
834
835 where
836
837 c = cos(degrees)
838 s = sin(degrees)
839
840 sets SkMatrix to:
841
842 | A B C | | c -s 0 | | Ac+Bs -As+Bc C |
843 Matrix * R(degrees, px, py) = | D E F | | s c 0 | = | Dc+Es -Ds+Ec F |
844 | G H I | | 0 0 1 | | Gc+Hs -Gs+Hc I |
845
846 @param degrees angle of axes relative to upright axes
847 */
848 SkMatrix& preRotate(SkScalar degrees);
849
850 /** Sets SkMatrix to SkMatrix multiplied by SkMatrix constructed from skewing by (kx, ky)
851 about pivot point (px, py).
852 This can be thought of as skewing about a pivot point before applying SkMatrix.
853
854 Given:
855
856 | A B C | | 1 kx dx |
857 Matrix = | D E F |, K(kx, ky, px, py) = | ky 1 dy |
858 | G H I | | 0 0 1 |
859
860 where
861
862 dx = -kx * py
863 dy = -ky * px
864
865 sets SkMatrix to:
866
867 | A B C | | 1 kx dx | | A+B*ky A*kx+B A*dx+B*dy+C |
868 Matrix * K(kx, ky, px, py) = | D E F | | ky 1 dy | = | D+E*ky D*kx+E D*dx+E*dy+F |
869 | G H I | | 0 0 1 | | G+H*ky G*kx+H G*dx+H*dy+I |
870
871 @param kx horizontal skew factor
872 @param ky vertical skew factor
873 @param px pivot on x-axis
874 @param py pivot on y-axis
875 */
876 SkMatrix& preSkew(SkScalar kx, SkScalar ky, SkScalar px, SkScalar py);
877
878 /** Sets SkMatrix to SkMatrix multiplied by SkMatrix constructed from skewing by (kx, ky)
879 about pivot point (0, 0).
880 This can be thought of as skewing about the origin before applying SkMatrix.
881
882 Given:
883
884 | A B C | | 1 kx 0 |
885 Matrix = | D E F |, K(kx, ky) = | ky 1 0 |
886 | G H I | | 0 0 1 |
887
888 sets SkMatrix to:
889
890 | A B C | | 1 kx 0 | | A+B*ky A*kx+B C |
891 Matrix * K(kx, ky) = | D E F | | ky 1 0 | = | D+E*ky D*kx+E F |
892 | G H I | | 0 0 1 | | G+H*ky G*kx+H I |
893
894 @param kx horizontal skew factor
895 @param ky vertical skew factor
896 */
897 SkMatrix& preSkew(SkScalar kx, SkScalar ky);
898
899 /** Sets SkMatrix to SkMatrix multiplied by SkMatrix other.
900 This can be thought of mapping by other before applying SkMatrix.
901
902 Given:
903
904 | A B C | | J K L |
905 Matrix = | D E F |, other = | M N O |
906 | G H I | | P Q R |
907
908 sets SkMatrix to:
909
910 | A B C | | J K L | | AJ+BM+CP AK+BN+CQ AL+BO+CR |
911 Matrix * other = | D E F | * | M N O | = | DJ+EM+FP DK+EN+FQ DL+EO+FR |
912 | G H I | | P Q R | | GJ+HM+IP GK+HN+IQ GL+HO+IR |
913
914 @param other SkMatrix on right side of multiply expression
915 */
916 SkMatrix& preConcat(const SkMatrix& other);
917
918 /** Sets SkMatrix to SkMatrix constructed from translation (dx, dy) multiplied by SkMatrix.
919 This can be thought of as moving the point to be mapped after applying SkMatrix.
920
921 Given:
922
923 | J K L | | 1 0 dx |
924 Matrix = | M N O |, T(dx, dy) = | 0 1 dy |
925 | P Q R | | 0 0 1 |
926
927 sets SkMatrix to:
928
929 | 1 0 dx | | J K L | | J+dx*P K+dx*Q L+dx*R |
930 T(dx, dy) * Matrix = | 0 1 dy | | M N O | = | M+dy*P N+dy*Q O+dy*R |
931 | 0 0 1 | | P Q R | | P Q R |
932
933 @param dx x-axis translation after applying SkMatrix
934 @param dy y-axis translation after applying SkMatrix
935 */
936 SkMatrix& postTranslate(SkScalar dx, SkScalar dy);
937
938 /** Sets SkMatrix to SkMatrix constructed from scaling by (sx, sy) about pivot point
939 (px, py), multiplied by SkMatrix.
940 This can be thought of as scaling about a pivot point after applying SkMatrix.
941
942 Given:
943
944 | J K L | | sx 0 dx |
945 Matrix = | M N O |, S(sx, sy, px, py) = | 0 sy dy |
946 | P Q R | | 0 0 1 |
947
948 where
949
950 dx = px - sx * px
951 dy = py - sy * py
952
953 sets SkMatrix to:
954
955 | sx 0 dx | | J K L | | sx*J+dx*P sx*K+dx*Q sx*L+dx+R |
956 S(sx, sy, px, py) * Matrix = | 0 sy dy | | M N O | = | sy*M+dy*P sy*N+dy*Q sy*O+dy*R |
957 | 0 0 1 | | P Q R | | P Q R |
958
959 @param sx horizontal scale factor
960 @param sy vertical scale factor
961 @param px pivot on x-axis
962 @param py pivot on y-axis
963 */
964 SkMatrix& postScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py);
965
966 /** Sets SkMatrix to SkMatrix constructed from scaling by (sx, sy) about pivot point
967 (0, 0), multiplied by SkMatrix.
968 This can be thought of as scaling about the origin after applying SkMatrix.
969
970 Given:
971
972 | J K L | | sx 0 0 |
973 Matrix = | M N O |, S(sx, sy) = | 0 sy 0 |
974 | P Q R | | 0 0 1 |
975
976 sets SkMatrix to:
977
978 | sx 0 0 | | J K L | | sx*J sx*K sx*L |
979 S(sx, sy) * Matrix = | 0 sy 0 | | M N O | = | sy*M sy*N sy*O |
980 | 0 0 1 | | P Q R | | P Q R |
981
982 @param sx horizontal scale factor
983 @param sy vertical scale factor
984 */
985 SkMatrix& postScale(SkScalar sx, SkScalar sy);
986
987 /** Sets SkMatrix to SkMatrix constructed from rotating by degrees about pivot point
988 (px, py), multiplied by SkMatrix.
989 This can be thought of as rotating about a pivot point after applying SkMatrix.
990
991 Positive degrees rotates clockwise.
992
993 Given:
994
995 | J K L | | c -s dx |
996 Matrix = | M N O |, R(degrees, px, py) = | s c dy |
997 | P Q R | | 0 0 1 |
998
999 where
1000
1001 c = cos(degrees)
1002 s = sin(degrees)
1003 dx = s * py + (1 - c) * px
1004 dy = -s * px + (1 - c) * py
1005
1006 sets SkMatrix to:
1007
1008 |c -s dx| |J K L| |cJ-sM+dx*P cK-sN+dx*Q cL-sO+dx+R|
1009 R(degrees, px, py) * Matrix = |s c dy| |M N O| = |sJ+cM+dy*P sK+cN+dy*Q sL+cO+dy*R|
1010 |0 0 1| |P Q R| | P Q R|
1011
1012 @param degrees angle of axes relative to upright axes
1013 @param px pivot on x-axis
1014 @param py pivot on y-axis
1015 */
1016 SkMatrix& postRotate(SkScalar degrees, SkScalar px, SkScalar py);
1017
1018 /** Sets SkMatrix to SkMatrix constructed from rotating by degrees about pivot point
1019 (0, 0), multiplied by SkMatrix.
1020 This can be thought of as rotating about the origin after applying SkMatrix.
1021
1022 Positive degrees rotates clockwise.
1023
1024 Given:
1025
1026 | J K L | | c -s 0 |
1027 Matrix = | M N O |, R(degrees, px, py) = | s c 0 |
1028 | P Q R | | 0 0 1 |
1029
1030 where
1031
1032 c = cos(degrees)
1033 s = sin(degrees)
1034
1035 sets SkMatrix to:
1036
1037 | c -s dx | | J K L | | cJ-sM cK-sN cL-sO |
1038 R(degrees, px, py) * Matrix = | s c dy | | M N O | = | sJ+cM sK+cN sL+cO |
1039 | 0 0 1 | | P Q R | | P Q R |
1040
1041 @param degrees angle of axes relative to upright axes
1042 */
1043 SkMatrix& postRotate(SkScalar degrees);
1044
1045 /** Sets SkMatrix to SkMatrix constructed from skewing by (kx, ky) about pivot point
1046 (px, py), multiplied by SkMatrix.
1047 This can be thought of as skewing about a pivot point after applying SkMatrix.
1048
1049 Given:
1050
1051 | J K L | | 1 kx dx |
1052 Matrix = | M N O |, K(kx, ky, px, py) = | ky 1 dy |
1053 | P Q R | | 0 0 1 |
1054
1055 where
1056
1057 dx = -kx * py
1058 dy = -ky * px
1059
1060 sets SkMatrix to:
1061
1062 | 1 kx dx| |J K L| |J+kx*M+dx*P K+kx*N+dx*Q L+kx*O+dx+R|
1063 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|
1064 | 0 0 1| |P Q R| | P Q R|
1065
1066 @param kx horizontal skew factor
1067 @param ky vertical skew factor
1068 @param px pivot on x-axis
1069 @param py pivot on y-axis
1070 */
1071 SkMatrix& postSkew(SkScalar kx, SkScalar ky, SkScalar px, SkScalar py);
1072
1073 /** Sets SkMatrix to SkMatrix constructed from skewing by (kx, ky) about pivot point
1074 (0, 0), multiplied by SkMatrix.
1075 This can be thought of as skewing about the origin after applying SkMatrix.
1076
1077 Given:
1078
1079 | J K L | | 1 kx 0 |
1080 Matrix = | M N O |, K(kx, ky) = | ky 1 0 |
1081 | P Q R | | 0 0 1 |
1082
1083 sets SkMatrix to:
1084
1085 | 1 kx 0 | | J K L | | J+kx*M K+kx*N L+kx*O |
1086 K(kx, ky) * Matrix = | ky 1 0 | | M N O | = | ky*J+M ky*K+N ky*L+O |
1087 | 0 0 1 | | P Q R | | P Q R |
1088
1089 @param kx horizontal skew factor
1090 @param ky vertical skew factor
1091 */
1092 SkMatrix& postSkew(SkScalar kx, SkScalar ky);
1093
1094 /** Sets SkMatrix to SkMatrix other multiplied by SkMatrix.
1095 This can be thought of mapping by other after applying SkMatrix.
1096
1097 Given:
1098
1099 | J K L | | A B C |
1100 Matrix = | M N O |, other = | D E F |
1101 | P Q R | | G H I |
1102
1103 sets SkMatrix to:
1104
1105 | A B C | | J K L | | AJ+BM+CP AK+BN+CQ AL+BO+CR |
1106 other * Matrix = | D E F | * | M N O | = | DJ+EM+FP DK+EN+FQ DL+EO+FR |
1107 | G H I | | P Q R | | GJ+HM+IP GK+HN+IQ GL+HO+IR |
1108
1109 @param other SkMatrix on left side of multiply expression
1110 */
1111 SkMatrix& postConcat(const SkMatrix& other);
1112
1113 /** If possible, return a matrix that will transform the src rect to the dst rect.
1114 * If the src is empty, this will return {}.
1115 * If the dst is empty, this will return the zero matrix (degenerate).
1116 */
1117 static std::optional<SkMatrix> Rect2Rect(const SkRect& src, const SkRect& dst,
1118 ScaleToFit = kFill_ScaleToFit);
1119
1120 static SkMatrix RectToRectOrIdentity(const SkRect& src, const SkRect& dst,
1121 ScaleToFit stf = kFill_ScaleToFit) {
1122 return Rect2Rect(src, dst, stf).value_or(SkMatrix::I());
1123 }
1124
1125 #ifdef SK_SUPPORT_LEGACY_MATRIX_RECTTORECT
1126 bool setRectToRect(const SkRect& src, const SkRect& dst, ScaleToFit stf) {
1127 if (auto mx = Rect2Rect(src, dst, stf)) {
1128 *this = *mx;
1129 return true;
1130 }
1131 this->reset();
1132 return false;
1133 }
1134
1135 static SkMatrix MakeRectToRect(const SkRect& src, const SkRect& dst, ScaleToFit stf) {
1136 if (auto mx = Rect2Rect(src, dst, stf)) {
1137 return *mx;
1138 }
1139 return SkMatrix::I();
1140 }
1141
1142 [[nodiscard]] static SkMatrix RectToRect(const SkRect& src, const SkRect& dst,
1143 ScaleToFit mode = kFill_ScaleToFit) {
1144 return MakeRectToRect(src, dst, mode);
1145 }
1146 #endif
1147
1148 /** Compute a matrix from two polygons, such that if the matrix was applied
1149 * to the src polygon, it would produce the dst polygon.
1150 *
1151 * If the size of the two spans are not equal, or if they are > 4, return {}.
1152 * If the resulting matrix is non-invertible, return {}.
1153 *
1154 * example: https://fiddle.skia.org/c/@Matrix_setPolyToPoly
1155 */
1156 static std::optional<SkMatrix> PolyToPoly(SkSpan<const SkPoint> src, SkSpan<const SkPoint> dst);
1157
1158 bool setPolyToPoly(SkSpan<const SkPoint> src, SkSpan<const SkPoint> dst) {
1159 if (auto mx = PolyToPoly(src, dst)) {
1160 *this = *mx;
1161 return true;
1162 }
1163 return false;
1164 }
1165
1166 /*
1167 * If this matrix is invertible, return its inverse, else return {}.
1168 */
1169 std::optional<SkMatrix> invert() const;
1170
1171 // deprecated
1172 [[nodiscard]] bool invert(SkMatrix* inverse) const {
1173 if (auto inv = this->invert()) {
1174 if (inverse) {
1175 *inverse = *inv;
1176 }
1177 return true;
1178 }
1179 return false;
1180 }
1181
1182 /** Fills affine with identity values in column major order.
1183 Sets affine to:
1184
1185 | 1 0 0 |
1186 | 0 1 0 |
1187
1188 Affine 3 by 2 matrices in column major order are used by OpenGL and XPS.
1189
1190 @param affine storage for 3 by 2 affine matrix
1191
1192 example: https://fiddle.skia.org/c/@Matrix_SetAffineIdentity
1193 */
1194 static void SetAffineIdentity(SkScalar affine[6]);
1195
1196 /** Fills affine in column major order. Sets affine to:
1197
1198 | scale-x skew-x translate-x |
1199 | skew-y scale-y translate-y |
1200
1201 If SkMatrix contains perspective, returns false and leaves affine unchanged.
1202
1203 @param affine storage for 3 by 2 affine matrix; may be nullptr
1204 @return true if SkMatrix does not contain perspective
1205 */
1206 [[nodiscard]] bool asAffine(SkScalar affine[6]) const;
1207
1208 /** Sets SkMatrix to affine values, passed in column major order. Given affine,
1209 column, then row, as:
1210
1211 | scale-x skew-x translate-x |
1212 | skew-y scale-y translate-y |
1213
1214 SkMatrix is set, row, then column, to:
1215
1216 | scale-x skew-x translate-x |
1217 | skew-y scale-y translate-y |
1218 | 0 0 1 |
1219
1220 @param affine 3 by 2 affine matrix
1221 */
1222 SkMatrix& setAffine(const SkScalar affine[6]);
1223
1224 /**
1225 * A matrix is categorized as 'perspective' if the bottom row is not [0, 0, 1].
1226 * However, for most uses (e.g. mapPoints) a bottom row of [0, 0, X] behaves like a
1227 * non-perspective matrix, though it will be categorized as perspective. Calling
1228 * normalizePerspective() will change the matrix such that, if its bottom row was [0, 0, X],
1229 * it will be changed to [0, 0, 1] by scaling the rest of the matrix by 1/X.
1230 *
1231 * | A B C | | A/X B/X C/X |
1232 * | D E F | -> | D/X E/X F/X | for X != 0
1233 * | 0 0 X | | 0 0 1 |
1234 */
1235 void normalizePerspective() {
1236 if (fMat[8] != 1) {
1237 this->doNormalizePerspective();
1238 }
1239 }
1240
1241 /** Maps src SkPoint array of length count to dst SkPoint array of equal or greater
1242 length. SkPoint are mapped by multiplying each SkPoint by SkMatrix. Given:
1243
1244 | A B C | | x |
1245 Matrix = | D E F |, pt = | y |
1246 | G H I | | 1 |
1247
1248 where
1249
1250 for (i = 0; i < count; ++i) {
1251 x = src[i].fX
1252 y = src[i].fY
1253 }
1254
1255 each dst SkPoint is computed as:
1256
1257 |A B C| |x| Ax+By+C Dx+Ey+F
1258 Matrix * pt = |D E F| |y| = |Ax+By+C Dx+Ey+F Gx+Hy+I| = ------- , -------
1259 |G H I| |1| Gx+Hy+I Gx+Hy+I
1260
1261 src and dst may point to the same storage.
1262
1263 @param dst span where the transformed points are written
1264 @param src spen where the points are read from
1265
1266 Note: min(dst.size(), src.size()) is the number of points that will be written to dst.
1267
1268 example: https://fiddle.skia.org/c/@Matrix_mapPoints
1269 */
1270 void mapPoints(SkSpan<SkPoint> dst, SkSpan<const SkPoint> src) const;
1271
1272 /** Maps pts SkPoint array of length count in place. SkPoint are mapped by multiplying
1273 each SkPoint by SkMatrix. Given:
1274
1275 | A B C | | x |
1276 Matrix = | D E F |, pt = | y |
1277 | G H I | | 1 |
1278
1279 where
1280
1281 for (i = 0; i < count; ++i) {
1282 x = pts[i].fX
1283 y = pts[i].fY
1284 }
1285
1286 each resulting pts SkPoint is computed as:
1287
1288 |A B C| |x| Ax+By+C Dx+Ey+F
1289 Matrix * pt = |D E F| |y| = |Ax+By+C Dx+Ey+F Gx+Hy+I| = ------- , -------
1290 |G H I| |1| Gx+Hy+I Gx+Hy+I
1291
1292 @param pts span of points to be transformed in-place
1293 */
1294 void mapPoints(SkSpan<SkPoint> pts) const {
1295 this->mapPoints(pts, pts);
1296 }
1297
1298 /** Maps src SkPoint3 array of length count to dst SkPoint3 array, which must of length count or
1299 greater. SkPoint3 array is mapped by multiplying each SkPoint3 by SkMatrix. Given:
1300
1301 | A B C | | x |
1302 Matrix = | D E F |, src = | y |
1303 | G H I | | z |
1304
1305 each resulting dst SkPoint is computed as:
1306
1307 |A B C| |x|
1308 Matrix * src = |D E F| |y| = |Ax+By+Cz Dx+Ey+Fz Gx+Hy+Iz|
1309 |G H I| |z|
1310
1311 @param dst span where the transformed points are written
1312 @param src spen where the points are read from
1313
1314 Note: min(dst.size(), src.size()) is the number of points that will be written to dst.
1315
1316 example: https://fiddle.skia.org/c/@Matrix_mapHomogeneousPoints
1317 */
1318 void mapHomogeneousPoints(SkSpan<SkPoint3> dst, SkSpan<const SkPoint3> src) const;
1319
1320 SkPoint3 mapHomogeneousPoint(SkPoint3 src) const {
1321 SkPoint3 dst;
1322 this->mapHomogeneousPoints({&dst, 1}, {&src, 1});
1323 return dst;
1324 }
1325
1326 /**
1327 * Returns homogeneous points, starting with 2D src points (with implied w = 1).
1328 *
1329 * Note: min(dst.size(), src.size()) is the number of points that will be written to dst.
1330
1331 */
1332 void mapPointsToHomogeneous(SkSpan<SkPoint3> dst, SkSpan<const SkPoint> src) const;
1333
1334 SkPoint3 mapPointToHomogeneous(SkPoint src) const {
1335 SkPoint3 dst;
1336 this->mapPointsToHomogeneous({&dst, 1}, {&src, 1});
1337 return dst;
1338 }
1339
1340 /** Returns SkPoint pt multiplied by SkMatrix. Given:
1341
1342 | A B C | | x |
1343 Matrix = | D E F |, pt = | y |
1344 | G H I | | 1 |
1345
1346 result is computed as:
1347
1348 |A B C| |x| Ax+By+C Dx+Ey+F
1349 Matrix * pt = |D E F| |y| = |Ax+By+C Dx+Ey+F Gx+Hy+I| = ------- , -------
1350 |G H I| |1| Gx+Hy+I Gx+Hy+I
1351
1352 @param p SkPoint to map
1353 @return mapped SkPoint
1354 */
1355 SkPoint mapPoint(SkPoint p) const {
1356 if (this->hasPerspective()) {
1357 return this->mapPointPerspective(p);
1358 } else {
1359 return this->mapPointAffine(p);
1360 }
1361 }
1362
1363 /*
1364 * If the caller knows the matrix has no perspective, this will inline the
1365 * math, making it more efficient than calling mapPoint().
1366 */
1367 SkPoint mapPointAffine(SkPoint p) const {
1368 SkASSERT(!this->hasPerspective());
1369 return {
1370 (p.fX * fMat[0] + p.fY * fMat[1]) + fMat[2],
1371 (p.fX * fMat[3] + p.fY * fMat[4]) + fMat[5],
1372 };
1373 }
1374
1375 /** Returns (0, 0) multiplied by SkMatrix. Given:
1376
1377 | A B C | | 0 |
1378 Matrix = | D E F |, pt = | 0 |
1379 | G H I | | 1 |
1380
1381 result is computed as:
1382
1383 |A B C| |0| C F
1384 Matrix * pt = |D E F| |0| = |C F I| = - , -
1385 |G H I| |1| I I
1386
1387 @return mapped (0, 0)
1388 */
1389 SkPoint mapOrigin() const {
1390 SkScalar x = this->getTranslateX(),
1391 y = this->getTranslateY();
1392 if (this->hasPerspective()) {
1393 SkScalar w = fMat[kMPersp2];
1394 if ((bool)w) { w = 1 / w; }
1395 x *= w;
1396 y *= w;
1397 }
1398 return {x, y};
1399 }
1400
1401 /** Maps src vector array of length count to vector SkPoint array of equal or greater
1402 length. Vectors are mapped by multiplying each vector by SkMatrix, treating
1403 SkMatrix translation as zero. Given:
1404
1405 | A B 0 | | x |
1406 Matrix = | D E 0 |, src = | y |
1407 | G H I | | 1 |
1408
1409 where
1410
1411 for (i = 0; i < count; ++i) {
1412 x = src[i].fX
1413 y = src[i].fY
1414 }
1415
1416 each dst vector is computed as:
1417
1418 |A B 0| |x| Ax+By Dx+Ey
1419 Matrix * src = |D E 0| |y| = |Ax+By Dx+Ey Gx+Hy+I| = ------- , -------
1420 |G H I| |1| Gx+Hy+I Gx+Hy+I
1421
1422 src and dst may point to the same storage.
1423
1424 @param dst span where the transformed vectors are written
1425 @param src spen where the vectors are read from
1426
1427 Note: min(dst.size(), src.size()) is the number of points that will be written to dst.
1428
1429 example: https://fiddle.skia.org/c/@Matrix_mapVectors
1430 */
1431 void mapVectors(SkSpan<SkVector> dst, SkSpan<const SkVector> src) const;
1432
1433 /** Maps vecs vector array of length count in place, multiplying each vector by
1434 SkMatrix, treating SkMatrix translation as zero. Given:
1435
1436 | A B 0 | | x |
1437 Matrix = | D E 0 |, vec = | y |
1438 | G H I | | 1 |
1439
1440 where
1441
1442 for (i = 0; i < count; ++i) {
1443 x = vecs[i].fX
1444 y = vecs[i].fY
1445 }
1446
1447 each result vector is computed as:
1448
1449 |A B 0| |x| Ax+By Dx+Ey
1450 Matrix * vec = |D E 0| |y| = |Ax+By Dx+Ey Gx+Hy+I| = ------- , -------
1451 |G H I| |1| Gx+Hy+I Gx+Hy+I
1452
1453 @param vecs vectors to transform, and storage for mapped vectors
1454 */
1455 void mapVectors(SkSpan<SkVector> vecs) const {
1456 this->mapVectors(vecs, vecs);
1457 }
1458
1459 /** Returns vector (dx, dy) multiplied by SkMatrix, treating SkMatrix translation as zero.
1460 Given:
1461
1462 | A B 0 | | dx |
1463 Matrix = | D E 0 |, vec = | dy |
1464 | G H I | | 1 |
1465
1466 each result vector is computed as:
1467
1468 |A B 0| |dx| A*dx+B*dy D*dx+E*dy
1469 Matrix * vec = |D E 0| |dy| = |A*dx+B*dy D*dx+E*dy G*dx+H*dy+I| = ----------- , -----------
1470 |G H I| | 1| G*dx+H*dy+I G*dx+*dHy+I
1471
1472 @param dx x-axis value of vector to map
1473 @param dy y-axis value of vector to map
1474 @return mapped vector
1475 */
1476 SkVector mapVector(SkVector vec) const {
1477 this->mapVectors({&vec, 1});
1478 return vec;
1479 }
1480 SkVector mapVector(SkScalar dx, SkScalar dy) const {
1481 return this->mapVector({dx, dy});
1482 }
1483
1484 /** Sets dst to bounds of src corners mapped by SkMatrix.
1485 Returns true if mapped corners are dst corners.
1486
1487 Returned value is the same as calling rectStaysRect().
1488
1489 @param dst storage for bounds of mapped SkPoint
1490 @param src SkRect to map
1491 @param pc whether to apply perspective clipping
1492 @return true if dst is equivalent to mapped src
1493
1494 example: https://fiddle.skia.org/c/@Matrix_mapRect
1495 */
1496 bool mapRect(SkRect* dst, const SkRect& src) const;
1497
1498 /** Sets rect to bounds of rect corners mapped by SkMatrix.
1499 Returns true if mapped corners are computed rect corners.
1500
1501 Returned value is the same as calling rectStaysRect().
1502
1503 @param rect rectangle to map, and storage for bounds of mapped corners
1504 @param pc whether to apply perspective clipping
1505 @return true if result is equivalent to mapped rect
1506 */
1507 bool mapRect(SkRect* rect) const {
1508 return this->mapRect(rect, *rect);
1509 }
1510
1511 /** Returns bounds of src corners mapped by SkMatrix.
1512
1513 @param src rectangle to map
1514 @return mapped bounds
1515 */
1516 SkRect mapRect(const SkRect& src) const {
1517 SkRect dst;
1518 (void)this->mapRect(&dst, src);
1519 return dst;
1520 }
1521
1522 /** Maps four corners of rect to dst. SkPoint are mapped by multiplying each
1523 rect corner by SkMatrix. rect corner is processed in this order:
1524 (rect.fLeft, rect.fTop), (rect.fRight, rect.fTop), (rect.fRight, rect.fBottom),
1525 (rect.fLeft, rect.fBottom).
1526
1527 rect may be empty: rect.fLeft may be greater than or equal to rect.fRight;
1528 rect.fTop may be greater than or equal to rect.fBottom.
1529
1530 Given:
1531
1532 | A B C | | x |
1533 Matrix = | D E F |, pt = | y |
1534 | G H I | | 1 |
1535
1536 where pt is initialized from each of (rect.fLeft, rect.fTop),
1537 (rect.fRight, rect.fTop), (rect.fRight, rect.fBottom), (rect.fLeft, rect.fBottom),
1538 each dst SkPoint is computed as:
1539
1540 |A B C| |x| Ax+By+C Dx+Ey+F
1541 Matrix * pt = |D E F| |y| = |Ax+By+C Dx+Ey+F Gx+Hy+I| = ------- , -------
1542 |G H I| |1| Gx+Hy+I Gx+Hy+I
1543
1544 @param dst storage for mapped corner SkPoint
1545 @param rect SkRect to map
1546
1547 Note: this does not perform perspective clipping (as that might result in more than
1548 4 points, so results are suspect if the matrix contains perspective.
1549 */
1550 void mapRectToQuad(SkPoint dst[4], const SkRect& rect) const {
1551 // This could potentially be faster if we only transformed each x and y of the rect once.
1552 this->mapPoints({dst, 4}, rect.toQuad());
1553 }
1554
1555 /** Sets dst to bounds of src corners mapped by SkMatrix. If matrix contains
1556 elements other than scale or translate: asserts if SK_DEBUG is defined;
1557 otherwise, results are undefined.
1558
1559 @param dst storage for bounds of mapped SkPoint
1560 @param src SkRect to map
1561
1562 example: https://fiddle.skia.org/c/@Matrix_mapRectScaleTranslate
1563 */
1564 void mapRectScaleTranslate(SkRect* dst, const SkRect& src) const;
1565
1566 /** Returns geometric mean radius of ellipse formed by constructing circle of
1567 size radius, and mapping constructed circle with SkMatrix. The result squared is
1568 equal to the major axis length times the minor axis length.
1569 Result is not meaningful if SkMatrix contains perspective elements.
1570
1571 @param radius circle size to map
1572 @return average mapped radius
1573
1574 example: https://fiddle.skia.org/c/@Matrix_mapRadius
1575 */
1576 SkScalar mapRadius(SkScalar radius) const;
1577
1578 /** Compares a and b; returns true if a and b are numerically equal. Returns true
1579 even if sign of zero values are different. Returns false if either SkMatrix
1580 contains NaN, even if the other SkMatrix also contains NaN.
1581
1582 @param a SkMatrix to compare
1583 @param b SkMatrix to compare
1584 @return true if SkMatrix a and SkMatrix b are numerically equal
1585 */
1586 friend SK_API bool operator==(const SkMatrix& a, const SkMatrix& b);
1587
1588 /** Compares a and b; returns true if a and b are not numerically equal. Returns false
1589 even if sign of zero values are different. Returns true if either SkMatrix
1590 contains NaN, even if the other SkMatrix also contains NaN.
1591
1592 @param a SkMatrix to compare
1593 @param b SkMatrix to compare
1594 @return true if SkMatrix a and SkMatrix b are numerically not equal
1595 */
1596 friend SK_API bool operator!=(const SkMatrix& a, const SkMatrix& b) {
1597 return !(a == b);
1598 }
1599
1600 /** Writes text representation of SkMatrix to standard output. Floating point values
1601 are written with limited precision; it may not be possible to reconstruct
1602 original SkMatrix from output.
1603
1604 example: https://fiddle.skia.org/c/@Matrix_dump
1605 */
1606 void dump() const;
1607
1608 /** Returns the minimum scaling factor of SkMatrix by decomposing the scaling and
1609 skewing elements.
1610 Returns -1 if scale factor overflows or SkMatrix contains perspective.
1611
1612 @return minimum scale factor
1613
1614 example: https://fiddle.skia.org/c/@Matrix_getMinScale
1615 */
1616 SkScalar getMinScale() const;
1617
1618 /** Returns the maximum scaling factor of SkMatrix by decomposing the scaling and
1619 skewing elements.
1620 Returns -1 if scale factor overflows or SkMatrix contains perspective.
1621
1622 @return maximum scale factor
1623
1624 example: https://fiddle.skia.org/c/@Matrix_getMaxScale
1625 */
1626 SkScalar getMaxScale() const;
1627
1628 /** Sets scaleFactors[0] to the minimum scaling factor, and scaleFactors[1] to the
1629 maximum scaling factor. Scaling factors are computed by decomposing
1630 the SkMatrix scaling and skewing elements.
1631
1632 Returns true if scaleFactors are found; otherwise, returns false and sets
1633 scaleFactors to undefined values.
1634
1635 @param scaleFactors storage for minimum and maximum scale factors
1636 @return true if scale factors were computed correctly
1637 */
1638 [[nodiscard]] bool getMinMaxScales(SkScalar scaleFactors[2]) const;
1639
1640 /** Decomposes SkMatrix into scale components and whatever remains. Returns false if
1641 SkMatrix could not be decomposed.
1642
1643 Sets scale to portion of SkMatrix that scale axes. Sets remaining to SkMatrix
1644 with scaling factored out. remaining may be passed as nullptr
1645 to determine if SkMatrix can be decomposed without computing remainder.
1646
1647 Returns true if scale components are found. scale and remaining are
1648 unchanged if SkMatrix contains perspective; scale factors are not finite, or
1649 are nearly zero.
1650
1651 On success: Matrix = Remaining * scale.
1652
1653 @param scale axes scaling factors; may be nullptr
1654 @param remaining SkMatrix without scaling; may be nullptr
1655 @return true if scale can be computed
1656
1657 example: https://fiddle.skia.org/c/@Matrix_decomposeScale
1658 */
1659 bool decomposeScale(SkSize* scale, SkMatrix* remaining = nullptr) const;
1660
1661 /** Returns reference to const identity SkMatrix. Returned SkMatrix is set to:
1662
1663 | 1 0 0 |
1664 | 0 1 0 |
1665 | 0 0 1 |
1666
1667 @return const identity SkMatrix
1668
1669 example: https://fiddle.skia.org/c/@Matrix_I
1670 */
1671 static const SkMatrix& I();
1672
1673 /** Returns reference to a const SkMatrix with invalid values. Returned SkMatrix is set
1674 to:
1675
1676 | SK_ScalarMax SK_ScalarMax SK_ScalarMax |
1677 | SK_ScalarMax SK_ScalarMax SK_ScalarMax |
1678 | SK_ScalarMax SK_ScalarMax SK_ScalarMax |
1679
1680 @return const invalid SkMatrix
1681
1682 example: https://fiddle.skia.org/c/@Matrix_InvalidMatrix
1683 */
1684 static const SkMatrix& InvalidMatrix();
1685
1686 /** Returns SkMatrix a multiplied by SkMatrix b.
1687
1688 Given:
1689
1690 | A B C | | J K L |
1691 a = | D E F |, b = | M N O |
1692 | G H I | | P Q R |
1693
1694 sets SkMatrix to:
1695
1696 | A B C | | J K L | | AJ+BM+CP AK+BN+CQ AL+BO+CR |
1697 a * b = | D E F | * | M N O | = | DJ+EM+FP DK+EN+FQ DL+EO+FR |
1698 | G H I | | P Q R | | GJ+HM+IP GK+HN+IQ GL+HO+IR |
1699
1700 @param a SkMatrix on left side of multiply expression
1701 @param b SkMatrix on right side of multiply expression
1702 @return SkMatrix computed from a times b
1703 */
1704 static SkMatrix Concat(const SkMatrix& a, const SkMatrix& b) {
1705 SkMatrix result;
1706 result.setConcat(a, b);
1707 return result;
1708 }
1709
1710 friend SkMatrix operator*(const SkMatrix& a, const SkMatrix& b) {
1711 return Concat(a, b);
1712 }
1713
1714 /** Sets internal cache to unknown state. Use to force update after repeated
1715 modifications to SkMatrix element reference returned by operator[](int index).
1716 */
1717 void dirtyMatrixTypeCache() {
1718 this->setTypeMask(kUnknown_Mask);
1719 }
1720
1721 /** Initializes SkMatrix with scale and translate elements.
1722
1723 | sx 0 tx |
1724 | 0 sy ty |
1725 | 0 0 1 |
1726
1727 @param sx horizontal scale factor to store
1728 @param sy vertical scale factor to store
1729 @param tx horizontal translation to store
1730 @param ty vertical translation to store
1731 */
1732 void setScaleTranslate(SkScalar sx, SkScalar sy, SkScalar tx, SkScalar ty) {
1733 *this = SkMatrix::ScaleTranslate(sx, sy, tx, ty);
1734 }
1735
1736 /** Returns true if all elements of the matrix are finite. Returns false if any
1737 element is infinity, or NaN.
1738
1739 @return true if matrix has only finite elements
1740 */
1741 bool isFinite() const { return SkIsFinite(fMat, 9); }
1742
1743 #ifdef SK_SUPPORT_UNSPANNED_APIS
1744 bool setPolyToPoly(const SkPoint src[], const SkPoint dst[], int count) {
1745 return this->setPolyToPoly({src, count}, {dst, count});
1746 }
1747
1748 void mapPoints(SkPoint dst[], const SkPoint src[], int count) const {
1749 this->mapPoints({dst, count}, {src, count});
1750 }
1751 void mapPoints(SkPoint pts[], int count) const {
1752 this->mapPoints(pts, pts, count);
1753 }
1754
1755 void mapHomogeneousPoints(SkPoint3 dst[], const SkPoint3 src[], int count) const {
1756 this->mapHomogeneousPoints({dst, count}, {src, count});
1757 }
1758 void mapHomogeneousPoints(SkPoint3 dst[], const SkPoint src[], int count) const {
1759 this->mapPointsToHomogeneous({dst, count}, {src, count});
1760 }
1761
1762 void mapVectors(SkVector dst[], const SkVector src[], int count) const {
1763 this->mapVectors({dst, count}, {src, count});
1764 }
1765 void mapVectors(SkVector vecs[], int count) const {
1766 this->mapVectors({vecs, count});
1767 }
1768 void mapXY(SkScalar x, SkScalar y, SkPoint* result) const {
1769 *result = this->mapPoint({x, y});
1770 }
1771 SkPoint mapXY(SkScalar x, SkScalar y) const {
1772 return this->mapPoint({x, y});
1773 }
1774 void mapVector(SkScalar dx, SkScalar dy, SkVector* result) const {
1775 SkVector vec = { dx, dy };
1776 this->mapVectors({result, 1}, {&vec, 1});
1777 }
1778 #endif
1779
1780 private:
1781 /** Set if the matrix will map a rectangle to another rectangle. This
1782 can be true if the matrix is scale-only, or rotates a multiple of
1783 90 degrees.
1784
1785 This bit will be set on identity matrices
1786 */
1787 static constexpr int kRectStaysRect_Mask = 0x10;
1788
1789 /** Set if the perspective bit is valid even though the rest of
1790 the matrix is Unknown.
1791 */
1792 static constexpr int kOnlyPerspectiveValid_Mask = 0x40;
1793
1794 static constexpr int kUnknown_Mask = 0x80;
1795
1796 static constexpr int kORableMasks = kTranslate_Mask |
1797 kScale_Mask |
1798 kAffine_Mask |
1799 kPerspective_Mask;
1800
1801 static constexpr int kAllMasks = kTranslate_Mask |
1802 kScale_Mask |
1803 kAffine_Mask |
1804 kPerspective_Mask |
1805 kRectStaysRect_Mask;
1806
1807 SkScalar fMat[9];
1808 mutable int32_t fTypeMask;
1809
1810 constexpr SkMatrix(SkScalar sx, SkScalar kx, SkScalar tx,
1811 SkScalar ky, SkScalar sy, SkScalar ty,
1812 SkScalar p0, SkScalar p1, SkScalar p2, int typeMask)
1813 : fMat{sx, kx, tx,
1814 ky, sy, ty,
1815 p0, p1, p2}
1816 , fTypeMask(typeMask) {}
1817
1818 static void ComputeInv(SkScalar dst[9], const SkScalar src[9], double invDet, bool isPersp);
1819
1820 uint8_t computeTypeMask() const;
1821 uint8_t computePerspectiveTypeMask() const;
1822
1823 void setTypeMask(int mask) {
1824 // allow kUnknown or a valid mask
1825 SkASSERT(kUnknown_Mask == mask || (mask & kAllMasks) == mask ||
1826 ((kUnknown_Mask | kOnlyPerspectiveValid_Mask) & mask)
1827 == (kUnknown_Mask | kOnlyPerspectiveValid_Mask));
1828 fTypeMask = mask;
1829 }
1830
1831 void orTypeMask(int mask) {
1832 SkASSERT((mask & kORableMasks) == mask);
1833 fTypeMask |= mask;
1834 }
1835
1836 void clearTypeMask(int mask) {
1837 // only allow a valid mask
1838 SkASSERT((mask & kAllMasks) == mask);
1839 fTypeMask &= ~mask;
1840 }
1841
1842 TypeMask getPerspectiveTypeMaskOnly() const {
1843 if ((fTypeMask & kUnknown_Mask) &&
1844 !(fTypeMask & kOnlyPerspectiveValid_Mask)) {
1845 fTypeMask = this->computePerspectiveTypeMask();
1846 }
1847 return (TypeMask)(fTypeMask & 0xF);
1848 }
1849
1850 /** Returns true if we already know that the matrix is identity;
1851 false otherwise.
1852 */
1853 bool isTriviallyIdentity() const {
1854 if (fTypeMask & kUnknown_Mask) {
1855 return false;
1856 }
1857 return ((fTypeMask & 0xF) == 0);
1858 }
1859
1860 inline void updateTranslateMask() {
1861 if ((fMat[kMTransX] != 0) | (fMat[kMTransY] != 0)) {
1862 fTypeMask |= kTranslate_Mask;
1863 } else {
1864 fTypeMask &= ~kTranslate_Mask;
1865 }
1866 }
1867
1868 /*
1869 * If the caller knows the matrix perspective, this dos the extra work to
1870 * correctly compute the mapping. mapPoint() calls this, but only after
1871 * checking if the matrix includes perspective.
1872 */
1873 SkPoint mapPointPerspective(SkPoint pt) const;
1874
1875 typedef void (*MapPtsProc)(const SkMatrix& mat, SkPoint dst[],
1876 const SkPoint src[], int count);
1877
1878 static MapPtsProc GetMapPtsProc(TypeMask mask) {
1879 SkASSERT((mask & ~kAllMasks) == 0);
1880 return gMapPtsProcs[mask & kAllMasks];
1881 }
1882
1883 MapPtsProc getMapPtsProc() const {
1884 return GetMapPtsProc(this->getType());
1885 }
1886
1887 static bool Poly2Proc(const SkPoint[], SkMatrix*);
1888 static bool Poly3Proc(const SkPoint[], SkMatrix*);
1889 static bool Poly4Proc(const SkPoint[], SkMatrix*);
1890
1891 static void Identity_pts(const SkMatrix&, SkPoint[], const SkPoint[], int);
1892 static void Trans_pts(const SkMatrix&, SkPoint dst[], const SkPoint[], int);
1893 static void Scale_pts(const SkMatrix&, SkPoint dst[], const SkPoint[], int);
1894 static void ScaleTrans_pts(const SkMatrix&, SkPoint dst[], const SkPoint[],
1895 int count);
1896 static void Persp_pts(const SkMatrix&, SkPoint dst[], const SkPoint[], int);
1897
1898 static void Affine_vpts(const SkMatrix&, SkPoint dst[], const SkPoint[], int);
1899
1900 static const MapPtsProc gMapPtsProcs[];
1901
1902 // return the number of bytes written, whether or not buffer is null
1903 size_t writeToMemory(void* buffer) const;
1904 /**
1905 * Reads data from the buffer parameter
1906 *
1907 * @param buffer Memory to read from
1908 * @param length Amount of memory available in the buffer
1909 * @return number of bytes read (must be a multiple of 4) or
1910 * 0 if there was not enough memory available
1911 */
1912 size_t readFromMemory(const void* buffer, size_t length);
1913
1914 // legacy method -- still needed? why not just postScale(1/divx, ...)?
1915 bool postIDiv(int divx, int divy);
1916 void doNormalizePerspective();
1917
1918 friend class SkPerspIter;
1919 friend class SkMatrixPriv;
1920 friend class SerializationTest;
1921 };
1922 SK_END_REQUIRE_DENSE
1923
1924 #endif