OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
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 "SkMatrix.h" | 8 #include "SkMatrix.h" |
9 #include "SkFloatBits.h" | 9 #include "SkFloatBits.h" |
10 #include "SkString.h" | 10 #include "SkString.h" |
(...skipping 1002 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1013 }; | 1013 }; |
1014 | 1014 |
1015 void SkMatrix::mapPoints(SkPoint dst[], const SkPoint src[], int count) const { | 1015 void SkMatrix::mapPoints(SkPoint dst[], const SkPoint src[], int count) const { |
1016 SkASSERT((dst && src && count > 0) || 0 == count); | 1016 SkASSERT((dst && src && count > 0) || 0 == count); |
1017 // no partial overlap | 1017 // no partial overlap |
1018 SkASSERT(src == dst || &dst[count] <= &src[0] || &src[count] <= &dst[0]); | 1018 SkASSERT(src == dst || &dst[count] <= &src[0] || &src[count] <= &dst[0]); |
1019 | 1019 |
1020 this->getMapPtsProc()(*this, dst, src, count); | 1020 this->getMapPtsProc()(*this, dst, src, count); |
1021 } | 1021 } |
1022 | 1022 |
| 1023 #include "Sk4x.h" |
| 1024 |
| 1025 void SkMatrix::mapPts(SkPoint dst[], const SkPoint src[], int count) const { |
| 1026 if (count <= 0) { |
| 1027 return; |
| 1028 } |
| 1029 |
| 1030 unsigned mask = this->getType() & 0xF; |
| 1031 |
| 1032 if (SkMatrix::kIdentity_Mask == mask) { |
| 1033 if (src != dst) { |
| 1034 memcpy(dst, src, count * sizeof(SkPoint)); |
| 1035 } |
| 1036 return; |
| 1037 } |
| 1038 if (SkMatrix::kTranslate_Mask == mask) { |
| 1039 SkScalar tx = this->getTranslateX(); |
| 1040 SkScalar ty = this->getTranslateY(); |
| 1041 if (count & 1) { |
| 1042 dst->fX = src->fX + tx; |
| 1043 dst->fY = src->fY + ty; |
| 1044 src += 1; |
| 1045 dst += 1; |
| 1046 } |
| 1047 Sk4f trans4(tx, ty, tx, ty); |
| 1048 count >>= 1; |
| 1049 for (int i = 0; i < count; ++i) { |
| 1050 (Sk4f::Load(&src->fX) + trans4).store(&dst->fX); |
| 1051 src += 2; |
| 1052 dst += 2; |
| 1053 } |
| 1054 return; |
| 1055 } |
| 1056 if (mask <= SkMatrix::kScale_Mask + SkMatrix::kTranslate_Mask) { |
| 1057 SkScalar tx = this->getTranslateX(); |
| 1058 SkScalar ty = this->getTranslateY(); |
| 1059 SkScalar sx = this->getScaleX(); |
| 1060 SkScalar sy = this->getScaleY(); |
| 1061 if (count & 1) { |
| 1062 dst->fX = src->fX * sx + tx; |
| 1063 dst->fY = src->fY * sy + ty; |
| 1064 src += 1; |
| 1065 dst += 1; |
| 1066 } |
| 1067 Sk4f trans4(tx, ty, tx, ty); |
| 1068 Sk4f scale4(sx, sy, sx, sy); |
| 1069 count >>= 1; |
| 1070 for (int i = 0; i < count; ++i) { |
| 1071 (Sk4f::Load(&src->fX) * scale4 + trans4).store(&dst->fX); |
| 1072 src += 2; |
| 1073 dst += 2; |
| 1074 } |
| 1075 return; |
| 1076 } |
| 1077 if (mask < SkMatrix::kPerspective_Mask) { // affine |
| 1078 SkScalar tx = this->getTranslateX(); |
| 1079 SkScalar ty = this->getTranslateY(); |
| 1080 SkScalar sx = this->getScaleX(); |
| 1081 SkScalar sy = this->getScaleY(); |
| 1082 SkScalar kx = this->getSkewX(); |
| 1083 SkScalar ky = this->getSkewY(); |
| 1084 if (count & 1) { |
| 1085 dst->set(src->fX * sx + src->fY * kx + tx, |
| 1086 src->fX * ky + src->fY * sy + ty); |
| 1087 src += 1; |
| 1088 dst += 1; |
| 1089 } |
| 1090 Sk4f trans4(tx, ty, tx, ty); |
| 1091 Sk4f scale4(sx, sy, sx, sy); |
| 1092 Sk4f skew4(kx, ky, kx, ky); // applied to swizzle of src4 |
| 1093 count >>= 1; |
| 1094 for (int i = 0; i < count; ++i) { |
| 1095 Sk4f src4 = Sk4f::Load(&src->fX); |
| 1096 Sk4f swz4(src[0].fY, src[0].fX, src[1].fY, src[1].fX); // need ABCD
-> BADC |
| 1097 (src4 * scale4 + swz4 * skew4 + trans4).store(&dst->fX); |
| 1098 src += 2; |
| 1099 dst += 2; |
| 1100 } |
| 1101 return; |
| 1102 } |
| 1103 // fall through for perspective |
| 1104 this->mapPoints(dst, src, count); |
| 1105 } |
| 1106 |
1023 /////////////////////////////////////////////////////////////////////////////// | 1107 /////////////////////////////////////////////////////////////////////////////// |
1024 | 1108 |
1025 void SkMatrix::mapHomogeneousPoints(SkScalar dst[], const SkScalar src[], int co
unt) const { | 1109 void SkMatrix::mapHomogeneousPoints(SkScalar dst[], const SkScalar src[], int co
unt) const { |
1026 SkASSERT((dst && src && count > 0) || 0 == count); | 1110 SkASSERT((dst && src && count > 0) || 0 == count); |
1027 // no partial overlap | 1111 // no partial overlap |
1028 SkASSERT(src == dst || &dst[3*count] <= &src[0] || &src[3*count] <= &dst[0])
; | 1112 SkASSERT(src == dst || &dst[3*count] <= &src[0] || &src[3*count] <= &dst[0])
; |
1029 | 1113 |
1030 if (count > 0) { | 1114 if (count > 0) { |
1031 if (this->isIdentity()) { | 1115 if (this->isIdentity()) { |
1032 memcpy(dst, src, 3*count*sizeof(SkScalar)); | 1116 memcpy(dst, src, 3*count*sizeof(SkScalar)); |
(...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1806 rotation1->fX = cos1; | 1890 rotation1->fX = cos1; |
1807 rotation1->fY = sin1; | 1891 rotation1->fY = sin1; |
1808 } | 1892 } |
1809 if (rotation2) { | 1893 if (rotation2) { |
1810 rotation2->fX = cos2; | 1894 rotation2->fX = cos2; |
1811 rotation2->fY = sin2; | 1895 rotation2->fY = sin2; |
1812 } | 1896 } |
1813 | 1897 |
1814 return true; | 1898 return true; |
1815 } | 1899 } |
OLD | NEW |