OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkMatrix44.h" | 8 #include "SkMatrix44.h" |
9 | 9 |
10 static inline bool eq4(const SkMScalar* SK_RESTRICT a, | 10 static inline bool eq4(const SkMScalar* SK_RESTRICT a, |
(...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
895 SkDebugf(format, | 895 SkDebugf(format, |
896 fMat[0][0], fMat[0][1], fMat[0][2], fMat[0][3], | 896 fMat[0][0], fMat[0][1], fMat[0][2], fMat[0][3], |
897 fMat[1][0], fMat[1][1], fMat[1][2], fMat[1][3], | 897 fMat[1][0], fMat[1][1], fMat[1][2], fMat[1][3], |
898 fMat[2][0], fMat[2][1], fMat[2][2], fMat[2][3], | 898 fMat[2][0], fMat[2][1], fMat[2][2], fMat[2][3], |
899 fMat[3][0], fMat[3][1], fMat[3][2], fMat[3][3]); | 899 fMat[3][0], fMat[3][1], fMat[3][2], fMat[3][3]); |
900 #endif | 900 #endif |
901 } | 901 } |
902 | 902 |
903 /////////////////////////////////////////////////////////////////////////////// | 903 /////////////////////////////////////////////////////////////////////////////// |
904 | 904 |
905 // TODO: make this support src' perspective elements | |
906 // | |
907 static void initFromMatrix(SkMScalar dst[4][4], const SkMatrix& src) { | 905 static void initFromMatrix(SkMScalar dst[4][4], const SkMatrix& src) { |
908 dst[0][0] = SkScalarToMScalar(src[SkMatrix::kMScaleX]); | 906 dst[0][0] = SkScalarToMScalar(src[SkMatrix::kMScaleX]); |
909 dst[1][0] = SkScalarToMScalar(src[SkMatrix::kMSkewX]); | 907 dst[1][0] = SkScalarToMScalar(src[SkMatrix::kMSkewX]); |
910 dst[2][0] = 0; | 908 dst[2][0] = 0; |
911 dst[3][0] = SkScalarToMScalar(src[SkMatrix::kMTransX]); | 909 dst[3][0] = SkScalarToMScalar(src[SkMatrix::kMTransX]); |
912 dst[0][1] = SkScalarToMScalar(src[SkMatrix::kMSkewY]); | 910 dst[0][1] = SkScalarToMScalar(src[SkMatrix::kMSkewY]); |
913 dst[1][1] = SkScalarToMScalar(src[SkMatrix::kMScaleY]); | 911 dst[1][1] = SkScalarToMScalar(src[SkMatrix::kMScaleY]); |
914 dst[2][1] = 0; | 912 dst[2][1] = 0; |
915 dst[3][1] = SkScalarToMScalar(src[SkMatrix::kMTransY]); | 913 dst[3][1] = SkScalarToMScalar(src[SkMatrix::kMTransY]); |
916 dst[0][2] = 0; | 914 dst[0][2] = 0; |
917 dst[1][2] = 0; | 915 dst[1][2] = 0; |
918 dst[2][2] = 1; | 916 dst[2][2] = 1; |
919 dst[3][2] = 0; | 917 dst[3][2] = 0; |
920 dst[0][3] = 0; | 918 dst[0][3] = SkScalarToMScalar(src[SkMatrix::kMPersp0]); |
921 dst[1][3] = 0; | 919 dst[1][3] = SkScalarToMScalar(src[SkMatrix::kMPersp1]); |
922 dst[2][3] = 0; | 920 dst[2][3] = 0; |
923 dst[3][3] = 1; | 921 dst[3][3] = SkScalarToMScalar(src[SkMatrix::kMPersp2]); |
924 } | 922 } |
925 | 923 |
926 SkMatrix44::SkMatrix44(const SkMatrix& src) { | 924 SkMatrix44::SkMatrix44(const SkMatrix& src) { |
927 initFromMatrix(fMat, src); | 925 initFromMatrix(fMat, src); |
928 } | 926 } |
929 | 927 |
930 SkMatrix44& SkMatrix44::operator=(const SkMatrix& src) { | 928 SkMatrix44& SkMatrix44::operator=(const SkMatrix& src) { |
931 initFromMatrix(fMat, src); | 929 initFromMatrix(fMat, src); |
932 | 930 |
933 if (src.isIdentity()) { | 931 if (src.isIdentity()) { |
934 this->setTypeMask(kIdentity_Mask); | 932 this->setTypeMask(kIdentity_Mask); |
935 } else { | 933 } else { |
936 this->dirtyTypeMask(); | 934 this->dirtyTypeMask(); |
937 } | 935 } |
938 return *this; | 936 return *this; |
939 } | 937 } |
940 | 938 |
941 // TODO: make this support our perspective elements | |
942 // | |
943 SkMatrix44::operator SkMatrix() const { | 939 SkMatrix44::operator SkMatrix() const { |
944 SkMatrix dst; | 940 SkMatrix dst; |
945 dst.reset(); // setup our perspective correctly for identity | |
946 | 941 |
947 dst[SkMatrix::kMScaleX] = SkMScalarToScalar(fMat[0][0]); | 942 dst[SkMatrix::kMScaleX] = SkMScalarToScalar(fMat[0][0]); |
948 dst[SkMatrix::kMSkewX] = SkMScalarToScalar(fMat[1][0]); | 943 dst[SkMatrix::kMSkewX] = SkMScalarToScalar(fMat[1][0]); |
949 dst[SkMatrix::kMTransX] = SkMScalarToScalar(fMat[3][0]); | 944 dst[SkMatrix::kMTransX] = SkMScalarToScalar(fMat[3][0]); |
950 | 945 |
951 dst[SkMatrix::kMSkewY] = SkMScalarToScalar(fMat[0][1]); | 946 dst[SkMatrix::kMSkewY] = SkMScalarToScalar(fMat[0][1]); |
952 dst[SkMatrix::kMScaleY] = SkMScalarToScalar(fMat[1][1]); | 947 dst[SkMatrix::kMScaleY] = SkMScalarToScalar(fMat[1][1]); |
953 dst[SkMatrix::kMTransY] = SkMScalarToScalar(fMat[3][1]); | 948 dst[SkMatrix::kMTransY] = SkMScalarToScalar(fMat[3][1]); |
954 | 949 |
| 950 dst[SkMatrix::kMPersp0] = SkMScalarToScalar(fMat[0][3]); |
| 951 dst[SkMatrix::kMPersp1] = SkMScalarToScalar(fMat[1][3]); |
| 952 dst[SkMatrix::kMPersp2] = SkMScalarToScalar(fMat[3][3]); |
| 953 |
955 return dst; | 954 return dst; |
956 } | 955 } |
OLD | NEW |