OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 #ifndef SkTextMapStateProc_DEFINED | 8 #ifndef SkTextMapStateProc_DEFINED |
9 #define SkTextMapStateProc_DEFINED | 9 #define SkTextMapStateProc_DEFINED |
10 | 10 |
11 #include "SkPoint.h" | 11 #include "SkPoint.h" |
12 #include "SkMatrix.h" | 12 #include "SkMatrix.h" |
13 | 13 |
14 class SkTextMapStateProc { | 14 class SkTextMapStateProc { |
15 public: | 15 public: |
16 SkTextMapStateProc(const SkMatrix& matrix, SkScalar y, int scalarsPerPositio
n) | 16 SkTextMapStateProc(const SkMatrix& matrix, const SkPoint& offset, int scalar
sPerPosition) |
17 : fMatrix(matrix) | 17 : fMatrix(matrix) |
18 , fProc(matrix.getMapXYProc()) | 18 , fProc(matrix.getMapXYProc()) |
19 , fY(y) | 19 , fOffset(offset) |
20 , fScaleX(fMatrix.getScaleX()) | 20 , fScaleX(fMatrix.getScaleX()) { |
21 , fTransX(fMatrix.getTranslateX()) { | |
22 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); | 21 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); |
23 if (1 == scalarsPerPosition) { | 22 if (1 == scalarsPerPosition) { |
24 unsigned mtype = fMatrix.getType(); | 23 unsigned mtype = fMatrix.getType(); |
25 if (mtype & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask))
{ | 24 if (mtype & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask))
{ |
26 fMapCase = kX; | 25 fMapCase = kX; |
27 } else { | 26 } else { |
28 fY = SkScalarMul(y, fMatrix.getScaleY()) + | 27 // Bake the matrix scale/translation components into fOffset, |
29 fMatrix.getTranslateY(); | 28 // to expedite proc computations. |
| 29 fOffset.set(SkScalarMul(offset.x(), fMatrix.getScaleX()) + fMatr
ix.getTranslateX(), |
| 30 SkScalarMul(offset.y(), fMatrix.getScaleY()) + fMatr
ix.getTranslateY()); |
| 31 |
30 if (mtype & SkMatrix::kScale_Mask) { | 32 if (mtype & SkMatrix::kScale_Mask) { |
31 fMapCase = kOnlyScaleX; | 33 fMapCase = kOnlyScaleX; |
32 } else { | 34 } else { |
33 fMapCase = kOnlyTransX; | 35 fMapCase = kOnlyTransX; |
34 } | 36 } |
35 } | 37 } |
36 } else { | 38 } else { |
37 fMapCase = kXY; | 39 fMapCase = kXY; |
38 } | 40 } |
39 } | 41 } |
40 | 42 |
41 void operator()(const SkScalar pos[], SkPoint* loc) const; | 43 void operator()(const SkScalar pos[], SkPoint* loc) const; |
42 | 44 |
43 private: | 45 private: |
44 const SkMatrix& fMatrix; | 46 const SkMatrix& fMatrix; |
45 enum { | 47 enum { |
46 kXY, | 48 kXY, |
47 kOnlyScaleX, | 49 kOnlyScaleX, |
48 kOnlyTransX, | 50 kOnlyTransX, |
49 kX | 51 kX |
50 } fMapCase; | 52 } fMapCase; |
51 const SkMatrix::MapXYProc fProc; | 53 const SkMatrix::MapXYProc fProc; |
52 SkScalar fY; // Ignored by kXY case. | 54 SkPoint fOffset; // In kOnly* mode, this includes the matrix translation co
mponent. |
53 SkScalar fScaleX, fTransX; // These are only used by Only... cases. | 55 SkScalar fScaleX; // This is only used by kOnly... cases. |
54 }; | 56 }; |
55 | 57 |
56 inline void SkTextMapStateProc::operator()(const SkScalar pos[], SkPoint* loc) c
onst { | 58 inline void SkTextMapStateProc::operator()(const SkScalar pos[], SkPoint* loc) c
onst { |
57 switch(fMapCase) { | 59 switch(fMapCase) { |
58 case kXY: | 60 case kXY: |
59 fProc(fMatrix, pos[0], pos[1], loc); | 61 fProc(fMatrix, pos[0] + fOffset.x(), pos[1] + fOffset.y(), loc); |
60 break; | 62 break; |
61 case kOnlyScaleX: | 63 case kOnlyScaleX: |
62 loc->set(SkScalarMul(fScaleX, *pos) + fTransX, fY); | 64 loc->set(SkScalarMul(fScaleX, *pos) + fOffset.x(), fOffset.y()); |
63 break; | 65 break; |
64 case kOnlyTransX: | 66 case kOnlyTransX: |
65 loc->set(*pos + fTransX, fY); | 67 loc->set(*pos + fOffset.x(), fOffset.y()); |
66 break; | 68 break; |
67 default: | 69 default: |
68 SkASSERT(false); | 70 SkASSERT(false); |
69 case kX: | 71 case kX: |
70 fProc(fMatrix, *pos, fY, loc); | 72 fProc(fMatrix, *pos + fOffset.x(), fOffset.y(), loc); |
71 break; | 73 break; |
72 } | 74 } |
73 } | 75 } |
74 | 76 |
75 #endif | 77 #endif |
76 | 78 |
OLD | NEW |