OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #ifndef SkMatrix_DEFINED | 10 #ifndef SkMatrix_DEFINED |
(...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
703 } | 703 } |
704 | 704 |
705 /** | 705 /** |
706 * Testing routine; the matrix's type cache should never need to be | 706 * Testing routine; the matrix's type cache should never need to be |
707 * manually invalidated during normal use. | 707 * manually invalidated during normal use. |
708 */ | 708 */ |
709 void dirtyMatrixTypeCache() { | 709 void dirtyMatrixTypeCache() { |
710 this->setTypeMask(kUnknown_Mask); | 710 this->setTypeMask(kUnknown_Mask); |
711 } | 711 } |
712 | 712 |
| 713 /** |
| 714 * Initialize the matrix to be scale + post-translate. |
| 715 */ |
| 716 void setScaleTranslate(SkScalar sx, SkScalar sy, SkScalar tx, SkScalar ty) { |
| 717 fMat[kMScaleX] = sx; |
| 718 fMat[kMSkewX] = 0; |
| 719 fMat[kMTransX] = tx; |
| 720 |
| 721 fMat[kMSkewY] = 0; |
| 722 fMat[kMScaleY] = sy; |
| 723 fMat[kMTransY] = ty; |
| 724 |
| 725 fMat[kMPersp0] = 0; |
| 726 fMat[kMPersp1] = 0; |
| 727 fMat[kMPersp2] = 1; |
| 728 |
| 729 unsigned mask = 0; |
| 730 if (sx != 1 || sy != 1) { |
| 731 mask |= kScale_Mask; |
| 732 } |
| 733 if (tx || ty) { |
| 734 mask |= kTranslate_Mask; |
| 735 } |
| 736 this->setTypeMask(mask | kRectStaysRect_Mask); |
| 737 } |
| 738 |
713 private: | 739 private: |
714 enum { | 740 enum { |
715 /** Set if the matrix will map a rectangle to another rectangle. This | 741 /** Set if the matrix will map a rectangle to another rectangle. This |
716 can be true if the matrix is scale-only, or rotates a multiple of | 742 can be true if the matrix is scale-only, or rotates a multiple of |
717 90 degrees. | 743 90 degrees. |
718 | 744 |
719 This bit will be set on identity matrices | 745 This bit will be set on identity matrices |
720 */ | 746 */ |
721 kRectStaysRect_Mask = 0x10, | 747 kRectStaysRect_Mask = 0x10, |
722 | 748 |
(...skipping 18 matching lines...) Expand all Loading... |
741 | 767 |
742 SkScalar fMat[9]; | 768 SkScalar fMat[9]; |
743 mutable uint32_t fTypeMask; | 769 mutable uint32_t fTypeMask; |
744 | 770 |
745 /** Are all elements of the matrix finite? | 771 /** Are all elements of the matrix finite? |
746 */ | 772 */ |
747 bool isFinite() const { return SkScalarsAreFinite(fMat, 9); } | 773 bool isFinite() const { return SkScalarsAreFinite(fMat, 9); } |
748 | 774 |
749 static void ComputeInv(SkScalar dst[9], const SkScalar src[9], double invDet
, bool isPersp); | 775 static void ComputeInv(SkScalar dst[9], const SkScalar src[9], double invDet
, bool isPersp); |
750 | 776 |
751 void setScaleTranslate(SkScalar sx, SkScalar sy, SkScalar tx, SkScalar ty) { | |
752 fMat[kMScaleX] = sx; | |
753 fMat[kMSkewX] = 0; | |
754 fMat[kMTransX] = tx; | |
755 | |
756 fMat[kMSkewY] = 0; | |
757 fMat[kMScaleY] = sy; | |
758 fMat[kMTransY] = ty; | |
759 | |
760 fMat[kMPersp0] = 0; | |
761 fMat[kMPersp1] = 0; | |
762 fMat[kMPersp2] = 1; | |
763 | |
764 unsigned mask = 0; | |
765 if (sx != 1 || sy != 1) { | |
766 mask |= kScale_Mask; | |
767 } | |
768 if (tx || ty) { | |
769 mask |= kTranslate_Mask; | |
770 } | |
771 this->setTypeMask(mask | kRectStaysRect_Mask); | |
772 } | |
773 | |
774 uint8_t computeTypeMask() const; | 777 uint8_t computeTypeMask() const; |
775 uint8_t computePerspectiveTypeMask() const; | 778 uint8_t computePerspectiveTypeMask() const; |
776 | 779 |
777 void setTypeMask(int mask) { | 780 void setTypeMask(int mask) { |
778 // allow kUnknown or a valid mask | 781 // allow kUnknown or a valid mask |
779 SkASSERT(kUnknown_Mask == mask || (mask & kAllMasks) == mask || | 782 SkASSERT(kUnknown_Mask == mask || (mask & kAllMasks) == mask || |
780 ((kUnknown_Mask | kOnlyPerspectiveValid_Mask) & mask) | 783 ((kUnknown_Mask | kOnlyPerspectiveValid_Mask) & mask) |
781 == (kUnknown_Mask | kOnlyPerspectiveValid_Mask)); | 784 == (kUnknown_Mask | kOnlyPerspectiveValid_Mask)); |
782 fTypeMask = SkToU8(mask); | 785 fTypeMask = SkToU8(mask); |
783 } | 786 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
836 | 839 |
837 static void Affine_vpts(const SkMatrix&, SkPoint dst[], const SkPoint[], int
); | 840 static void Affine_vpts(const SkMatrix&, SkPoint dst[], const SkPoint[], int
); |
838 | 841 |
839 static const MapPtsProc gMapPtsProcs[]; | 842 static const MapPtsProc gMapPtsProcs[]; |
840 | 843 |
841 friend class SkPerspIter; | 844 friend class SkPerspIter; |
842 }; | 845 }; |
843 SK_END_REQUIRE_DENSE | 846 SK_END_REQUIRE_DENSE |
844 | 847 |
845 #endif | 848 #endif |
OLD | NEW |