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 862 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
873 SkDebugf(format, | 873 SkDebugf(format, |
874 fMat[0][0], fMat[0][1], fMat[0][2], fMat[0][3], | 874 fMat[0][0], fMat[0][1], fMat[0][2], fMat[0][3], |
875 fMat[1][0], fMat[1][1], fMat[1][2], fMat[1][3], | 875 fMat[1][0], fMat[1][1], fMat[1][2], fMat[1][3], |
876 fMat[2][0], fMat[2][1], fMat[2][2], fMat[2][3], | 876 fMat[2][0], fMat[2][1], fMat[2][2], fMat[2][3], |
877 fMat[3][0], fMat[3][1], fMat[3][2], fMat[3][3]); | 877 fMat[3][0], fMat[3][1], fMat[3][2], fMat[3][3]); |
878 #endif | 878 #endif |
879 } | 879 } |
880 | 880 |
881 /////////////////////////////////////////////////////////////////////////////// | 881 /////////////////////////////////////////////////////////////////////////////// |
882 | 882 |
883 // TODO: make this support src' perspective elements | |
884 // | |
885 static void initFromMatrix(SkMScalar dst[4][4], const SkMatrix& src) { | 883 static void initFromMatrix(SkMScalar dst[4][4], const SkMatrix& src) { |
886 sk_bzero(dst, 16 * sizeof(SkMScalar)); | 884 sk_bzero(dst, 16 * sizeof(SkMScalar)); |
887 dst[0][0] = SkScalarToMScalar(src[SkMatrix::kMScaleX]); | 885 dst[0][0] = SkScalarToMScalar(src[SkMatrix::kMScaleX]); |
888 dst[1][0] = SkScalarToMScalar(src[SkMatrix::kMSkewX]); | 886 dst[1][0] = SkScalarToMScalar(src[SkMatrix::kMSkewX]); |
889 dst[3][0] = SkScalarToMScalar(src[SkMatrix::kMTransX]); | 887 dst[3][0] = SkScalarToMScalar(src[SkMatrix::kMTransX]); |
890 dst[0][1] = SkScalarToMScalar(src[SkMatrix::kMSkewY]); | 888 dst[0][1] = SkScalarToMScalar(src[SkMatrix::kMSkewY]); |
891 dst[1][1] = SkScalarToMScalar(src[SkMatrix::kMScaleY]); | 889 dst[1][1] = SkScalarToMScalar(src[SkMatrix::kMScaleY]); |
892 dst[3][1] = SkScalarToMScalar(src[SkMatrix::kMTransY]); | 890 dst[3][1] = SkScalarToMScalar(src[SkMatrix::kMTransY]); |
893 dst[2][2] = dst[3][3] = 1; | 891 dst[0][3] = SkScalarToMScalar(src[SkMatrix::kMPersp0]); |
| 892 dst[1][3] = SkScalarToMScalar(src[SkMatrix::kMPersp1]); |
| 893 dst[3][3] = SkScalarToMScalar(src[SkMatrix::kMPersp2]); |
| 894 dst[2][2] = 1; |
894 } | 895 } |
895 | 896 |
896 SkMatrix44::SkMatrix44(const SkMatrix& src) { | 897 SkMatrix44::SkMatrix44(const SkMatrix& src) { |
897 initFromMatrix(fMat, src); | 898 initFromMatrix(fMat, src); |
898 } | 899 } |
899 | 900 |
900 SkMatrix44& SkMatrix44::operator=(const SkMatrix& src) { | 901 SkMatrix44& SkMatrix44::operator=(const SkMatrix& src) { |
901 initFromMatrix(fMat, src); | 902 initFromMatrix(fMat, src); |
902 | 903 |
903 if (src.isIdentity()) { | 904 if (src.isIdentity()) { |
904 this->setTypeMask(kIdentity_Mask); | 905 this->setTypeMask(kIdentity_Mask); |
905 } else { | 906 } else { |
906 this->dirtyTypeMask(); | 907 this->dirtyTypeMask(); |
907 } | 908 } |
908 return *this; | 909 return *this; |
909 } | 910 } |
910 | 911 |
911 // TODO: make this support our perspective elements | |
912 // | |
913 SkMatrix44::operator SkMatrix() const { | 912 SkMatrix44::operator SkMatrix() const { |
914 SkMatrix dst; | 913 SkMatrix dst; |
915 dst.reset(); // setup our perspective correctly for identity | |
916 | 914 |
917 dst[SkMatrix::kMScaleX] = SkMScalarToScalar(fMat[0][0]); | 915 dst[SkMatrix::kMScaleX] = SkMScalarToScalar(fMat[0][0]); |
918 dst[SkMatrix::kMSkewX] = SkMScalarToScalar(fMat[1][0]); | 916 dst[SkMatrix::kMSkewX] = SkMScalarToScalar(fMat[1][0]); |
919 dst[SkMatrix::kMTransX] = SkMScalarToScalar(fMat[3][0]); | 917 dst[SkMatrix::kMTransX] = SkMScalarToScalar(fMat[3][0]); |
920 | 918 |
921 dst[SkMatrix::kMSkewY] = SkMScalarToScalar(fMat[0][1]); | 919 dst[SkMatrix::kMSkewY] = SkMScalarToScalar(fMat[0][1]); |
922 dst[SkMatrix::kMScaleY] = SkMScalarToScalar(fMat[1][1]); | 920 dst[SkMatrix::kMScaleY] = SkMScalarToScalar(fMat[1][1]); |
923 dst[SkMatrix::kMTransY] = SkMScalarToScalar(fMat[3][1]); | 921 dst[SkMatrix::kMTransY] = SkMScalarToScalar(fMat[3][1]); |
924 | 922 |
| 923 dst[SkMatrix::kMPersp0] = SkMScalarToScalar(fMat[0][3]); |
| 924 dst[SkMatrix::kMPersp1] = SkMScalarToScalar(fMat[1][3]); |
| 925 dst[SkMatrix::kMPersp2] = SkMScalarToScalar(fMat[3][3]); |
| 926 |
925 return dst; | 927 return dst; |
926 } | 928 } |
OLD | NEW |