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 "SkRSXform.h" | 10 #include "SkRSXform.h" |
11 #include "SkString.h" | 11 #include "SkString.h" |
12 #include "SkNx.h" | 12 #include "SkNx.h" |
| 13 #include "SkOpts.h" |
13 | 14 |
14 #include <stddef.h> | 15 #include <stddef.h> |
15 | 16 |
16 static void normalize_perspective(SkScalar mat[9]) { | 17 static void normalize_perspective(SkScalar mat[9]) { |
17 // If it was interesting to never store the last element, we could divide al
l 8 other | 18 // If it was interesting to never store the last element, we could divide al
l 8 other |
18 // elements here by the 9th, making it 1.0... | 19 // elements here by the 9th, making it 1.0... |
19 // | 20 // |
20 // When SkScalar was SkFixed, we would sometimes rescale the entire matrix t
o keep its | 21 // When SkScalar was SkFixed, we would sometimes rescale the entire matrix t
o keep its |
21 // component values from getting too large. This is not a concern when using
floats/doubles, | 22 // component values from getting too large. This is not a concern when using
floats/doubles, |
22 // so we do nothing now. | 23 // so we do nothing now. |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 fMat[kMPersp0] = fMat[kMPersp1] = 0; | 439 fMat[kMPersp0] = fMat[kMPersp1] = 0; |
439 fMat[kMPersp2] = 1; | 440 fMat[kMPersp2] = 1; |
440 | 441 |
441 this->setTypeMask(kUnknown_Mask | kOnlyPerspectiveValid_Mask); | 442 this->setTypeMask(kUnknown_Mask | kOnlyPerspectiveValid_Mask); |
442 } | 443 } |
443 | 444 |
444 SkMatrix& SkMatrix::setRSXform(const SkRSXform& xform) { | 445 SkMatrix& SkMatrix::setRSXform(const SkRSXform& xform) { |
445 fMat[kMScaleX] = xform.fSCos; | 446 fMat[kMScaleX] = xform.fSCos; |
446 fMat[kMSkewX] = -xform.fSSin; | 447 fMat[kMSkewX] = -xform.fSSin; |
447 fMat[kMTransX] = xform.fTx; | 448 fMat[kMTransX] = xform.fTx; |
448 | 449 |
449 fMat[kMSkewY] = xform.fSSin; | 450 fMat[kMSkewY] = xform.fSSin; |
450 fMat[kMScaleY] = xform.fSCos; | 451 fMat[kMScaleY] = xform.fSCos; |
451 fMat[kMTransY] = xform.fTy; | 452 fMat[kMTransY] = xform.fTy; |
452 | 453 |
453 fMat[kMPersp0] = fMat[kMPersp1] = 0; | 454 fMat[kMPersp0] = fMat[kMPersp1] = 0; |
454 fMat[kMPersp2] = 1; | 455 fMat[kMPersp2] = 1; |
455 | 456 |
456 this->setTypeMask(kUnknown_Mask | kOnlyPerspectiveValid_Mask); | 457 this->setTypeMask(kUnknown_Mask | kOnlyPerspectiveValid_Mask); |
457 return *this; | 458 return *this; |
458 } | 459 } |
459 | 460 |
460 void SkMatrix::setSinCos(SkScalar sinV, SkScalar cosV) { | 461 void SkMatrix::setSinCos(SkScalar sinV, SkScalar cosV) { |
461 fMat[kMScaleX] = cosV; | 462 fMat[kMScaleX] = cosV; |
462 fMat[kMSkewX] = -sinV; | 463 fMat[kMSkewX] = -sinV; |
463 fMat[kMTransX] = 0; | 464 fMat[kMTransX] = 0; |
464 | 465 |
465 fMat[kMSkewY] = sinV; | 466 fMat[kMSkewY] = sinV; |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
900 | 901 |
901 void SkMatrix::Identity_pts(const SkMatrix& m, SkPoint dst[], const SkPoint src[
], int count) { | 902 void SkMatrix::Identity_pts(const SkMatrix& m, SkPoint dst[], const SkPoint src[
], int count) { |
902 SkASSERT(m.getType() == 0); | 903 SkASSERT(m.getType() == 0); |
903 | 904 |
904 if (dst != src && count > 0) { | 905 if (dst != src && count > 0) { |
905 memcpy(dst, src, count * sizeof(SkPoint)); | 906 memcpy(dst, src, count * sizeof(SkPoint)); |
906 } | 907 } |
907 } | 908 } |
908 | 909 |
909 void SkMatrix::Trans_pts(const SkMatrix& m, SkPoint dst[], const SkPoint src[],
int count) { | 910 void SkMatrix::Trans_pts(const SkMatrix& m, SkPoint dst[], const SkPoint src[],
int count) { |
910 SkASSERT(m.getType() <= kTranslate_Mask); | 911 return SkOpts::matrix_translate(m,dst,src,count); |
911 | |
912 if (count > 0) { | |
913 SkScalar tx = m.getTranslateX(); | |
914 SkScalar ty = m.getTranslateY(); | |
915 if (count & 1) { | |
916 dst->fX = src->fX + tx; | |
917 dst->fY = src->fY + ty; | |
918 src += 1; | |
919 dst += 1; | |
920 } | |
921 Sk4s trans4(tx, ty, tx, ty); | |
922 count >>= 1; | |
923 if (count & 1) { | |
924 (Sk4s::Load(&src->fX) + trans4).store(&dst->fX); | |
925 src += 2; | |
926 dst += 2; | |
927 } | |
928 count >>= 1; | |
929 for (int i = 0; i < count; ++i) { | |
930 (Sk4s::Load(&src[0].fX) + trans4).store(&dst[0].fX); | |
931 (Sk4s::Load(&src[2].fX) + trans4).store(&dst[2].fX); | |
932 src += 4; | |
933 dst += 4; | |
934 } | |
935 } | |
936 } | 912 } |
937 | 913 |
938 void SkMatrix::Scale_pts(const SkMatrix& m, SkPoint dst[], const SkPoint src[],
int count) { | 914 void SkMatrix::Scale_pts(const SkMatrix& m, SkPoint dst[], const SkPoint src[],
int count) { |
939 SkASSERT(m.getType() <= (kScale_Mask | kTranslate_Mask)); | 915 return SkOpts::matrix_scale_translate(m,dst,src,count); |
940 | |
941 if (count > 0) { | |
942 SkScalar tx = m.getTranslateX(); | |
943 SkScalar ty = m.getTranslateY(); | |
944 SkScalar sx = m.getScaleX(); | |
945 SkScalar sy = m.getScaleY(); | |
946 if (count & 1) { | |
947 dst->fX = src->fX * sx + tx; | |
948 dst->fY = src->fY * sy + ty; | |
949 src += 1; | |
950 dst += 1; | |
951 } | |
952 Sk4s trans4(tx, ty, tx, ty); | |
953 Sk4s scale4(sx, sy, sx, sy); | |
954 count >>= 1; | |
955 if (count & 1) { | |
956 (Sk4s::Load(&src->fX) * scale4 + trans4).store(&dst->fX); | |
957 src += 2; | |
958 dst += 2; | |
959 } | |
960 count >>= 1; | |
961 for (int i = 0; i < count; ++i) { | |
962 (Sk4s::Load(&src[0].fX) * scale4 + trans4).store(&dst[0].fX); | |
963 (Sk4s::Load(&src[2].fX) * scale4 + trans4).store(&dst[2].fX); | |
964 src += 4; | |
965 dst += 4; | |
966 } | |
967 } | |
968 } | 916 } |
969 | 917 |
970 void SkMatrix::Persp_pts(const SkMatrix& m, SkPoint dst[], | 918 void SkMatrix::Persp_pts(const SkMatrix& m, SkPoint dst[], |
971 const SkPoint src[], int count) { | 919 const SkPoint src[], int count) { |
972 SkASSERT(m.hasPerspective()); | 920 SkASSERT(m.hasPerspective()); |
973 | 921 |
974 if (count > 0) { | 922 if (count > 0) { |
975 do { | 923 do { |
976 SkScalar sy = src->fY; | 924 SkScalar sy = src->fY; |
977 SkScalar sx = src->fX; | 925 SkScalar sx = src->fX; |
(...skipping 11 matching lines...) Expand all Loading... |
989 } | 937 } |
990 | 938 |
991 dst->fY = y * z; | 939 dst->fY = y * z; |
992 dst->fX = x * z; | 940 dst->fX = x * z; |
993 dst += 1; | 941 dst += 1; |
994 } while (--count); | 942 } while (--count); |
995 } | 943 } |
996 } | 944 } |
997 | 945 |
998 void SkMatrix::Affine_vpts(const SkMatrix& m, SkPoint dst[], const SkPoint src[]
, int count) { | 946 void SkMatrix::Affine_vpts(const SkMatrix& m, SkPoint dst[], const SkPoint src[]
, int count) { |
999 SkASSERT(m.getType() != kPerspective_Mask); | 947 return SkOpts::matrix_affine(m,dst,src,count); |
1000 | |
1001 if (count > 0) { | |
1002 SkScalar tx = m.getTranslateX(); | |
1003 SkScalar ty = m.getTranslateY(); | |
1004 SkScalar sx = m.getScaleX(); | |
1005 SkScalar sy = m.getScaleY(); | |
1006 SkScalar kx = m.getSkewX(); | |
1007 SkScalar ky = m.getSkewY(); | |
1008 if (count & 1) { | |
1009 dst->set(src->fX * sx + src->fY * kx + tx, | |
1010 src->fX * ky + src->fY * sy + ty); | |
1011 src += 1; | |
1012 dst += 1; | |
1013 } | |
1014 Sk4s trans4(tx, ty, tx, ty); | |
1015 Sk4s scale4(sx, sy, sx, sy); | |
1016 Sk4s skew4(kx, ky, kx, ky); // applied to swizzle of src4 | |
1017 count >>= 1; | |
1018 for (int i = 0; i < count; ++i) { | |
1019 Sk4s src4 = Sk4s::Load(&src->fX); | |
1020 Sk4s swz4(src[0].fY, src[0].fX, src[1].fY, src[1].fX); // need ABCD
-> BADC | |
1021 (src4 * scale4 + swz4 * skew4 + trans4).store(&dst->fX); | |
1022 src += 2; | |
1023 dst += 2; | |
1024 } | |
1025 } | |
1026 } | 948 } |
1027 | 949 |
1028 const SkMatrix::MapPtsProc SkMatrix::gMapPtsProcs[] = { | 950 const SkMatrix::MapPtsProc SkMatrix::gMapPtsProcs[] = { |
1029 SkMatrix::Identity_pts, SkMatrix::Trans_pts, | 951 SkMatrix::Identity_pts, SkMatrix::Trans_pts, |
1030 SkMatrix::Scale_pts, SkMatrix::Scale_pts, | 952 SkMatrix::Scale_pts, SkMatrix::Scale_pts, |
1031 SkMatrix::Affine_vpts, SkMatrix::Affine_vpts, | 953 SkMatrix::Affine_vpts, SkMatrix::Affine_vpts, |
1032 SkMatrix::Affine_vpts, SkMatrix::Affine_vpts, | 954 SkMatrix::Affine_vpts, SkMatrix::Affine_vpts, |
1033 // repeat the persp proc 8 times | 955 // repeat the persp proc 8 times |
1034 SkMatrix::Persp_pts, SkMatrix::Persp_pts, | 956 SkMatrix::Persp_pts, SkMatrix::Persp_pts, |
1035 SkMatrix::Persp_pts, SkMatrix::Persp_pts, | 957 SkMatrix::Persp_pts, SkMatrix::Persp_pts, |
(...skipping 815 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1851 const SkScalar m11 = m00; | 1773 const SkScalar m11 = m00; |
1852 const SkScalar m12 = fTy; | 1774 const SkScalar m12 = fTy; |
1853 | 1775 |
1854 quad[0].set(m02, m12); | 1776 quad[0].set(m02, m12); |
1855 quad[1].set(m00 * width + m02, m10 * width + m12); | 1777 quad[1].set(m00 * width + m02, m10 * width + m12); |
1856 quad[2].set(m00 * width + m01 * height + m02, m10 * width + m11 * height + m
12); | 1778 quad[2].set(m00 * width + m01 * height + m02, m10 * width + m11 * height + m
12); |
1857 quad[3].set(m01 * height + m02, m11 * height + m12); | 1779 quad[3].set(m01 * height + m02, m11 * height + m12); |
1858 #endif | 1780 #endif |
1859 } | 1781 } |
1860 | 1782 |
OLD | NEW |