Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1327)

Side by Side Diff: src/core/SkMatrix.cpp

Issue 1048593002: Refactor Sk2x<T> + Sk4x<T> into SkNf<N,T> and SkNi<N,T> (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: This is actually faster Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkGeometry.cpp ('k') | src/core/SkNx.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "Sk4x.h" 11 #include "SkNx.h"
12 12
13 #include <stddef.h> 13 #include <stddef.h>
14 14
15 static void normalize_perspective(SkScalar mat[9]) { 15 static void normalize_perspective(SkScalar mat[9]) {
16 // If it was interesting to never store the last element, we could divide al l 8 other 16 // If it was interesting to never store the last element, we could divide al l 8 other
17 // elements here by the 9th, making it 1.0... 17 // elements here by the 9th, making it 1.0...
18 // 18 //
19 // When SkScalar was SkFixed, we would sometimes rescale the entire matrix t o keep its 19 // When SkScalar was SkFixed, we would sometimes rescale the entire matrix t o keep its
20 // component values from getting too large. This is not a concern when using floats/doubles, 20 // component values from getting too large. This is not a concern when using floats/doubles,
21 // so we do nothing now. 21 // so we do nothing now.
(...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 void SkMatrix::Identity_pts(const SkMatrix& m, SkPoint dst[], const SkPoint src[ ], int count) { 871 void SkMatrix::Identity_pts(const SkMatrix& m, SkPoint dst[], const SkPoint src[ ], int count) {
872 SkASSERT(m.getType() == 0); 872 SkASSERT(m.getType() == 0);
873 873
874 if (dst != src && count > 0) { 874 if (dst != src && count > 0) {
875 memcpy(dst, src, count * sizeof(SkPoint)); 875 memcpy(dst, src, count * sizeof(SkPoint));
876 } 876 }
877 } 877 }
878 878
879 void SkMatrix::Trans_pts(const SkMatrix& m, SkPoint dst[], const SkPoint src[], int count) { 879 void SkMatrix::Trans_pts(const SkMatrix& m, SkPoint dst[], const SkPoint src[], int count) {
880 SkASSERT(m.getType() <= kTranslate_Mask); 880 SkASSERT(m.getType() <= kTranslate_Mask);
881 881
882 if (count > 0) { 882 if (count > 0) {
883 SkScalar tx = m.getTranslateX(); 883 SkScalar tx = m.getTranslateX();
884 SkScalar ty = m.getTranslateY(); 884 SkScalar ty = m.getTranslateY();
885 if (count & 1) { 885 if (count & 1) {
886 dst->fX = src->fX + tx; 886 dst->fX = src->fX + tx;
887 dst->fY = src->fY + ty; 887 dst->fY = src->fY + ty;
888 src += 1; 888 src += 1;
889 dst += 1; 889 dst += 1;
890 } 890 }
891 Sk4f trans4(tx, ty, tx, ty); 891 Sk4s trans4(tx, ty, tx, ty);
892 count >>= 1; 892 count >>= 1;
893 if (count & 1) { 893 if (count & 1) {
894 (Sk4f::Load(&src->fX) + trans4).store(&dst->fX); 894 (Sk4s::Load(&src->fX) + trans4).store(&dst->fX);
895 src += 2; 895 src += 2;
896 dst += 2; 896 dst += 2;
897 } 897 }
898 count >>= 1; 898 count >>= 1;
899 for (int i = 0; i < count; ++i) { 899 for (int i = 0; i < count; ++i) {
900 (Sk4f::Load(&src[0].fX) + trans4).store(&dst[0].fX); 900 (Sk4s::Load(&src[0].fX) + trans4).store(&dst[0].fX);
901 (Sk4f::Load(&src[2].fX) + trans4).store(&dst[2].fX); 901 (Sk4s::Load(&src[2].fX) + trans4).store(&dst[2].fX);
902 src += 4; 902 src += 4;
903 dst += 4; 903 dst += 4;
904 } 904 }
905 } 905 }
906 } 906 }
907 907
908 void SkMatrix::Scale_pts(const SkMatrix& m, SkPoint dst[], const SkPoint src[], int count) { 908 void SkMatrix::Scale_pts(const SkMatrix& m, SkPoint dst[], const SkPoint src[], int count) {
909 SkASSERT(m.getType() <= (kScale_Mask | kTranslate_Mask)); 909 SkASSERT(m.getType() <= (kScale_Mask | kTranslate_Mask));
910 910
911 if (count > 0) { 911 if (count > 0) {
912 SkScalar tx = m.getTranslateX(); 912 SkScalar tx = m.getTranslateX();
913 SkScalar ty = m.getTranslateY(); 913 SkScalar ty = m.getTranslateY();
914 SkScalar sx = m.getScaleX(); 914 SkScalar sx = m.getScaleX();
915 SkScalar sy = m.getScaleY(); 915 SkScalar sy = m.getScaleY();
916 if (count & 1) { 916 if (count & 1) {
917 dst->fX = src->fX * sx + tx; 917 dst->fX = src->fX * sx + tx;
918 dst->fY = src->fY * sy + ty; 918 dst->fY = src->fY * sy + ty;
919 src += 1; 919 src += 1;
920 dst += 1; 920 dst += 1;
921 } 921 }
922 Sk4f trans4(tx, ty, tx, ty); 922 Sk4s trans4(tx, ty, tx, ty);
923 Sk4f scale4(sx, sy, sx, sy); 923 Sk4s scale4(sx, sy, sx, sy);
924 count >>= 1; 924 count >>= 1;
925 if (count & 1) { 925 if (count & 1) {
926 (Sk4f::Load(&src->fX) * scale4 + trans4).store(&dst->fX); 926 (Sk4s::Load(&src->fX) * scale4 + trans4).store(&dst->fX);
927 src += 2; 927 src += 2;
928 dst += 2; 928 dst += 2;
929 } 929 }
930 count >>= 1; 930 count >>= 1;
931 for (int i = 0; i < count; ++i) { 931 for (int i = 0; i < count; ++i) {
932 (Sk4f::Load(&src[0].fX) * scale4 + trans4).store(&dst[0].fX); 932 (Sk4s::Load(&src[0].fX) * scale4 + trans4).store(&dst[0].fX);
933 (Sk4f::Load(&src[2].fX) * scale4 + trans4).store(&dst[2].fX); 933 (Sk4s::Load(&src[2].fX) * scale4 + trans4).store(&dst[2].fX);
934 src += 4; 934 src += 4;
935 dst += 4; 935 dst += 4;
936 } 936 }
937 } 937 }
938 } 938 }
939 939
940 void SkMatrix::Rot_pts(const SkMatrix& m, SkPoint dst[], 940 void SkMatrix::Rot_pts(const SkMatrix& m, SkPoint dst[],
941 const SkPoint src[], int count) { 941 const SkPoint src[], int count) {
942 SkASSERT((m.getType() & (kPerspective_Mask | kTranslate_Mask)) == 0); 942 SkASSERT((m.getType() & (kPerspective_Mask | kTranslate_Mask)) == 0);
943 943
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 SkScalar sx = m.getScaleX(); 1021 SkScalar sx = m.getScaleX();
1022 SkScalar sy = m.getScaleY(); 1022 SkScalar sy = m.getScaleY();
1023 SkScalar kx = m.getSkewX(); 1023 SkScalar kx = m.getSkewX();
1024 SkScalar ky = m.getSkewY(); 1024 SkScalar ky = m.getSkewY();
1025 if (count & 1) { 1025 if (count & 1) {
1026 dst->set(src->fX * sx + src->fY * kx + tx, 1026 dst->set(src->fX * sx + src->fY * kx + tx,
1027 src->fX * ky + src->fY * sy + ty); 1027 src->fX * ky + src->fY * sy + ty);
1028 src += 1; 1028 src += 1;
1029 dst += 1; 1029 dst += 1;
1030 } 1030 }
1031 Sk4f trans4(tx, ty, tx, ty); 1031 Sk4s trans4(tx, ty, tx, ty);
1032 Sk4f scale4(sx, sy, sx, sy); 1032 Sk4s scale4(sx, sy, sx, sy);
1033 Sk4f skew4(kx, ky, kx, ky); // applied to swizzle of src4 1033 Sk4s skew4(kx, ky, kx, ky); // applied to swizzle of src4
1034 count >>= 1; 1034 count >>= 1;
1035 for (int i = 0; i < count; ++i) { 1035 for (int i = 0; i < count; ++i) {
1036 Sk4f src4 = Sk4f::Load(&src->fX); 1036 Sk4s src4 = Sk4s::Load(&src->fX);
1037 Sk4f swz4(src[0].fY, src[0].fX, src[1].fY, src[1].fX); // need ABCD -> BADC 1037 Sk4s swz4(src[0].fY, src[0].fX, src[1].fY, src[1].fX); // need ABCD -> BADC
1038 (src4 * scale4 + swz4 * skew4 + trans4).store(&dst->fX); 1038 (src4 * scale4 + swz4 * skew4 + trans4).store(&dst->fX);
1039 src += 2; 1039 src += 2;
1040 dst += 2; 1040 dst += 2;
1041 } 1041 }
1042 } 1042 }
1043 } 1043 }
1044 1044
1045 const SkMatrix::MapPtsProc SkMatrix::gMapPtsProcs[] = { 1045 const SkMatrix::MapPtsProc SkMatrix::gMapPtsProcs[] = {
1046 SkMatrix::Identity_pts, SkMatrix::Trans_pts, 1046 SkMatrix::Identity_pts, SkMatrix::Trans_pts,
1047 SkMatrix::Scale_pts, SkMatrix::Scale_pts, 1047 SkMatrix::Scale_pts, SkMatrix::Scale_pts,
(...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after
1845 rotation1->fX = cos1; 1845 rotation1->fX = cos1;
1846 rotation1->fY = sin1; 1846 rotation1->fY = sin1;
1847 } 1847 }
1848 if (rotation2) { 1848 if (rotation2) {
1849 rotation2->fX = cos2; 1849 rotation2->fX = cos2;
1850 rotation2->fY = sin2; 1850 rotation2->fY = sin2;
1851 } 1851 }
1852 1852
1853 return true; 1853 return true;
1854 } 1854 }
OLDNEW
« no previous file with comments | « src/core/SkGeometry.cpp ('k') | src/core/SkNx.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698