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

Side by Side Diff: src/utils/SkMatrix44.cpp

Issue 50423004: Remove SkMatrix44 float conversions without precision loss (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: One more SkMScalarToFloat Created 7 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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 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 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 fMat[3][1] = dy; 222 fMat[3][1] = dy;
223 fMat[3][2] = dz; 223 fMat[3][2] = dz;
224 this->setTypeMask(kTranslate_Mask); 224 this->setTypeMask(kTranslate_Mask);
225 } 225 }
226 226
227 void SkMatrix44::preTranslate(SkMScalar dx, SkMScalar dy, SkMScalar dz) { 227 void SkMatrix44::preTranslate(SkMScalar dx, SkMScalar dy, SkMScalar dz) {
228 if (!dx && !dy && !dz) { 228 if (!dx && !dy && !dz) {
229 return; 229 return;
230 } 230 }
231 231
232 const double X = SkMScalarToDouble(dx);
233 const double Y = SkMScalarToDouble(dy);
234 const double Z = SkMScalarToDouble(dz);
235
236 double tmp;
237 for (int i = 0; i < 4; ++i) { 232 for (int i = 0; i < 4; ++i) {
238 tmp = fMat[0][i] * X + fMat[1][i] * Y + fMat[2][i] * Z + fMat[3][i]; 233 fMat[3][i] = fMat[0][i] * dx + fMat[1][i] * dy + fMat[2][i] * dz + fMat[ 3][i];
239 fMat[3][i] = SkDoubleToMScalar(tmp);
240 } 234 }
241 this->dirtyTypeMask(); 235 this->dirtyTypeMask();
242 } 236 }
243 237
244 void SkMatrix44::postTranslate(SkMScalar dx, SkMScalar dy, SkMScalar dz) { 238 void SkMatrix44::postTranslate(SkMScalar dx, SkMScalar dy, SkMScalar dz) {
245 if (!dx && !dy && !dz) { 239 if (!dx && !dy && !dz) {
246 return; 240 return;
247 } 241 }
248 242
249 if (this->getType() & kPerspective_Mask) { 243 if (this->getType() & kPerspective_Mask) {
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 dst4[1] = mat[1][1] * src2[1] + mat[3][1]; 770 dst4[1] = mat[1][1] * src2[1] + mat[3][1];
777 dst4[2] = mat[3][2]; 771 dst4[2] = mat[3][2];
778 dst4[3] = 1; 772 dst4[3] = 1;
779 src2 += 2; 773 src2 += 2;
780 dst4 += 4; 774 dst4 += 4;
781 } 775 }
782 } 776 }
783 777
784 static void map2_af(const SkMScalar mat[][4], const float* SK_RESTRICT src2, 778 static void map2_af(const SkMScalar mat[][4], const float* SK_RESTRICT src2,
785 int count, float* SK_RESTRICT dst4) { 779 int count, float* SK_RESTRICT dst4) {
786 double r; 780 SkMScalar r;
787 for (int n = 0; n < count; ++n) { 781 for (int n = 0; n < count; ++n) {
788 double sx = src2[0]; 782 SkMScalar sx = SkFloatToMScalar(src2[0]);
789 double sy = src2[1]; 783 SkMScalar sy = SkFloatToMScalar(src2[1]);
790 r = mat[0][0] * sx + mat[1][0] * sy + mat[3][0]; 784 r = mat[0][0] * sx + mat[1][0] * sy + mat[3][0];
791 dst4[0] = SkMScalarToFloat(r); 785 dst4[0] = SkMScalarToFloat(r);
792 r = mat[0][1] * sx + mat[1][1] * sy + mat[3][1]; 786 r = mat[0][1] * sx + mat[1][1] * sy + mat[3][1];
793 dst4[1] = SkMScalarToFloat(r); 787 dst4[1] = SkMScalarToFloat(r);
794 r = mat[0][2] * sx + mat[1][2] * sy + mat[3][2]; 788 r = mat[0][2] * sx + mat[1][2] * sy + mat[3][2];
795 dst4[2] = SkMScalarToFloat(r); 789 dst4[2] = SkMScalarToFloat(r);
796 dst4[3] = 1; 790 dst4[3] = 1;
797 src2 += 2; 791 src2 += 2;
798 dst4 += 4; 792 dst4 += 4;
799 } 793 }
800 } 794 }
801 795
802 static void map2_ad(const SkMScalar mat[][4], const double* SK_RESTRICT src2, 796 static void map2_ad(const SkMScalar mat[][4], const double* SK_RESTRICT src2,
803 int count, double* SK_RESTRICT dst4) { 797 int count, double* SK_RESTRICT dst4) {
804 for (int n = 0; n < count; ++n) { 798 for (int n = 0; n < count; ++n) {
805 double sx = src2[0]; 799 double sx = src2[0];
806 double sy = src2[1]; 800 double sy = src2[1];
807 dst4[0] = mat[0][0] * sx + mat[1][0] * sy + mat[3][0]; 801 dst4[0] = mat[0][0] * sx + mat[1][0] * sy + mat[3][0];
808 dst4[1] = mat[0][1] * sx + mat[1][1] * sy + mat[3][1]; 802 dst4[1] = mat[0][1] * sx + mat[1][1] * sy + mat[3][1];
809 dst4[2] = mat[0][2] * sx + mat[1][2] * sy + mat[3][2]; 803 dst4[2] = mat[0][2] * sx + mat[1][2] * sy + mat[3][2];
810 dst4[3] = 1; 804 dst4[3] = 1;
811 src2 += 2; 805 src2 += 2;
812 dst4 += 4; 806 dst4 += 4;
813 } 807 }
814 } 808 }
815 809
816 static void map2_pf(const SkMScalar mat[][4], const float* SK_RESTRICT src2, 810 static void map2_pf(const SkMScalar mat[][4], const float* SK_RESTRICT src2,
817 int count, float* SK_RESTRICT dst4) { 811 int count, float* SK_RESTRICT dst4) {
812 SkMScalar r;
818 for (int n = 0; n < count; ++n) { 813 for (int n = 0; n < count; ++n) {
819 float sx = src2[0]; 814 SkMScalar sx = SkFloatToMScalar(src2[0]);
820 float sy = src2[1]; 815 SkMScalar sy = SkFloatToMScalar(src2[1]);
821 for (int i = 0; i < 4; i++) { 816 for (int i = 0; i < 4; i++) {
822 dst4[i] = 817 r = mat[0][i] * sx + mat[1][i] * sy + mat[3][i];
823 SkMScalarToFloat(mat[0][i]) * sx + 818 dst4[i] = SkMScalarToFloat(r);
824 SkMScalarToFloat(mat[1][i]) * sy +
825 SkMScalarToFloat(mat[3][i]);
826 } 819 }
827 src2 += 2; 820 src2 += 2;
828 dst4 += 4; 821 dst4 += 4;
829 } 822 }
830 } 823 }
831 824
832 static void map2_pd(const SkMScalar mat[][4], const double* SK_RESTRICT src2, 825 static void map2_pd(const SkMScalar mat[][4], const double* SK_RESTRICT src2,
833 int count, double* SK_RESTRICT dst4) { 826 int count, double* SK_RESTRICT dst4) {
834 for (int n = 0; n < count; ++n) { 827 for (int n = 0; n < count; ++n) {
835 double sx = src2[0]; 828 double sx = src2[0];
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
928 dst[SkMatrix::kMSkewY] = SkMScalarToScalar(fMat[0][1]); 921 dst[SkMatrix::kMSkewY] = SkMScalarToScalar(fMat[0][1]);
929 dst[SkMatrix::kMScaleY] = SkMScalarToScalar(fMat[1][1]); 922 dst[SkMatrix::kMScaleY] = SkMScalarToScalar(fMat[1][1]);
930 dst[SkMatrix::kMTransY] = SkMScalarToScalar(fMat[3][1]); 923 dst[SkMatrix::kMTransY] = SkMScalarToScalar(fMat[3][1]);
931 924
932 dst[SkMatrix::kMPersp0] = SkMScalarToScalar(fMat[0][3]); 925 dst[SkMatrix::kMPersp0] = SkMScalarToScalar(fMat[0][3]);
933 dst[SkMatrix::kMPersp1] = SkMScalarToScalar(fMat[1][3]); 926 dst[SkMatrix::kMPersp1] = SkMScalarToScalar(fMat[1][3]);
934 dst[SkMatrix::kMPersp2] = SkMScalarToScalar(fMat[3][3]); 927 dst[SkMatrix::kMPersp2] = SkMScalarToScalar(fMat[3][3]);
935 928
936 return dst; 929 return dst;
937 } 930 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698