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

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

Issue 806543002: add get9 and set9 to matrix, to aid in making keys (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years 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 | « include/core/SkMatrix.h ('k') | tests/MatrixTest.cpp » ('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 11
12 #include <stddef.h> 12 #include <stddef.h>
13 13
14 static void normalize_perspective(SkScalar mat[9]) {
15 // If it was interesting to never store the last element, we could divide al l 8 other
16 // elements here by the 9th, making it 1.0...
17 //
18 // When SkScalar was SkFixed, we would sometimes rescale the entire matrix t o keep its
19 // component values from getting too large. This is not a concern when using floats/doubles,
20 // so we do nothing now.
21
22 // Disable this for now, but it could be enabled.
23 #if 0
24 if (0 == mat[SkMatrix::kMPersp0] && 0 == mat[SkMatrix::kMPersp1]) {
25 SkScalar p2 = mat[SkMatrix::kMPersp2];
26 if (p2 != 0 && p2 != 1) {
27 double inv = 1.0 / p2;
28 for (int i = 0; i < 6; ++i) {
29 mat[i] = SkDoubleToScalar(mat[i] * inv);
30 }
31 mat[SkMatrix::kMPersp2] = 1;
32 }
33 }
34 #endif
35 }
36
14 // In a few places, we performed the following 37 // In a few places, we performed the following
15 // a * b + c * d + e 38 // a * b + c * d + e
16 // as 39 // as
17 // a * b + (c * d + e) 40 // a * b + (c * d + e)
18 // 41 //
19 // sdot and scross are indended to capture these compound operations into a 42 // sdot and scross are indended to capture these compound operations into a
20 // function, with an eye toward considering upscaling the intermediates to 43 // function, with an eye toward considering upscaling the intermediates to
21 // doubles for more precision (as we do in concat and invert). 44 // doubles for more precision (as we do in concat and invert).
22 // 45 //
23 // However, these few lines that performed the last add before the "dot", cause 46 // However, these few lines that performed the last add before the "dot", cause
24 // tiny image differences, so we guard that change until we see the impact on 47 // tiny image differences, so we guard that change until we see the impact on
25 // chrome's layouttests. 48 // chrome's layouttests.
26 // 49 //
27 #define SK_LEGACY_MATRIX_MATH_ORDER 50 #define SK_LEGACY_MATRIX_MATH_ORDER
28 51
29 static inline float SkDoubleToFloat(double x) { 52 static inline float SkDoubleToFloat(double x) {
30 return static_cast<float>(x); 53 return static_cast<float>(x);
31 } 54 }
32 55
33 /* [scale-x skew-x trans-x] [X] [X'] 56 /* [scale-x skew-x trans-x] [X] [X']
34 [skew-y scale-y trans-y] * [Y] = [Y'] 57 [skew-y scale-y trans-y] * [Y] = [Y']
35 [persp-0 persp-1 persp-2] [1] [1 ] 58 [persp-0 persp-1 persp-2] [1] [1 ]
36 */ 59 */
37 60
38 void SkMatrix::reset() { 61 void SkMatrix::reset() {
39 fMat[kMScaleX] = fMat[kMScaleY] = fMat[kMPersp2] = 1; 62 fMat[kMScaleX] = fMat[kMScaleY] = fMat[kMPersp2] = 1;
40 fMat[kMSkewX] = fMat[kMSkewY] = 63 fMat[kMSkewX] = fMat[kMSkewY] =
41 fMat[kMTransX] = fMat[kMTransY] = 64 fMat[kMTransX] = fMat[kMTransY] =
42 fMat[kMPersp0] = fMat[kMPersp1] = 0; 65 fMat[kMPersp0] = fMat[kMPersp1] = 0;
66 this->setTypeMask(kIdentity_Mask | kRectStaysRect_Mask);
67 }
43 68
44 this->setTypeMask(kIdentity_Mask | kRectStaysRect_Mask); 69 void SkMatrix::set9(const SkScalar buffer[]) {
70 memcpy(fMat, buffer, 9 * sizeof(SkScalar));
71 normalize_perspective(fMat);
72 this->setTypeMask(kUnknown_Mask);
73 }
74
75 void SkMatrix::setAffine(const SkScalar buffer[]) {
76 fMat[kMScaleX] = buffer[kAScaleX];
77 fMat[kMSkewX] = buffer[kASkewX];
78 fMat[kMTransX] = buffer[kATransX];
79 fMat[kMSkewY] = buffer[kASkewY];
80 fMat[kMScaleY] = buffer[kAScaleY];
81 fMat[kMTransY] = buffer[kATransY];
82 fMat[kMPersp0] = 0;
83 fMat[kMPersp1] = 0;
84 fMat[kMPersp2] = 1;
85 this->setTypeMask(kUnknown_Mask);
45 } 86 }
46 87
47 // this guy aligns with the masks, so we can compute a mask from a varaible 0/1 88 // this guy aligns with the masks, so we can compute a mask from a varaible 0/1
48 enum { 89 enum {
49 kTranslate_Shift, 90 kTranslate_Shift,
50 kScale_Shift, 91 kScale_Shift,
51 kAffine_Shift, 92 kAffine_Shift,
52 kPerspective_Shift, 93 kPerspective_Shift,
53 kRectStaysRect_Shift 94 kRectStaysRect_Shift
54 }; 95 };
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 /////////////////////////////////////////////////////////////////////////////// 602 ///////////////////////////////////////////////////////////////////////////////
562 603
563 static inline float muladdmul(float a, float b, float c, float d) { 604 static inline float muladdmul(float a, float b, float c, float d) {
564 return SkDoubleToFloat((double)a * b + (double)c * d); 605 return SkDoubleToFloat((double)a * b + (double)c * d);
565 } 606 }
566 607
567 static inline float rowcol3(const float row[], const float col[]) { 608 static inline float rowcol3(const float row[], const float col[]) {
568 return row[0] * col[0] + row[1] * col[3] + row[2] * col[6]; 609 return row[0] * col[0] + row[1] * col[3] + row[2] * col[6];
569 } 610 }
570 611
571 static void normalize_perspective(SkScalar mat[9]) {
572 // If it was interesting to never store the last element, we could divide al l 8 other
573 // elements here by the 9th, making it 1.0...
574 //
575 // When SkScalar was SkFixed, we would sometimes rescale the entire matrix t o keep its
576 // component values from getting too large. This is not a concern when using floats/doubles,
577 // so we do nothing now.
578 }
579
580 static bool only_scale_and_translate(unsigned mask) { 612 static bool only_scale_and_translate(unsigned mask) {
581 return 0 == (mask & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask)); 613 return 0 == (mask & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask));
582 } 614 }
583 615
584 void SkMatrix::setConcat(const SkMatrix& a, const SkMatrix& b) { 616 void SkMatrix::setConcat(const SkMatrix& a, const SkMatrix& b) {
585 TypeMask aType = a.getType(); 617 TypeMask aType = a.getType();
586 TypeMask bType = b.getType(); 618 TypeMask bType = b.getType();
587 619
588 if (a.isTriviallyIdentity()) { 620 if (a.isTriviallyIdentity()) {
589 *this = b; 621 *this = b;
(...skipping 1162 matching lines...) Expand 10 before | Expand all | Expand 10 after
1752 rotation1->fX = cos1; 1784 rotation1->fX = cos1;
1753 rotation1->fY = sin1; 1785 rotation1->fY = sin1;
1754 } 1786 }
1755 if (rotation2) { 1787 if (rotation2) {
1756 rotation2->fX = cos2; 1788 rotation2->fX = cos2;
1757 rotation2->fY = sin2; 1789 rotation2->fY = sin2;
1758 } 1790 }
1759 1791
1760 return true; 1792 return true;
1761 } 1793 }
OLDNEW
« no previous file with comments | « include/core/SkMatrix.h ('k') | tests/MatrixTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698