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

Side by Side Diff: src/core/SkTextMapStateProc.h

Issue 609223003: Revert of Fix SkTextBlob offset semantics. (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Created 6 years, 2 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/SkDraw.cpp ('k') | src/device/xps/SkXPSDevice.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 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, const SkPoint& offset, int scalar sPerPosition) 16 SkTextMapStateProc(const SkMatrix& matrix, SkScalar y, int scalarsPerPositio n)
17 : fMatrix(matrix) 17 : fMatrix(matrix)
18 , fProc(matrix.getMapXYProc()) 18 , fProc(matrix.getMapXYProc())
19 , fOffset(offset) 19 , fY(y)
20 , fScaleX(fMatrix.getScaleX()) { 20 , fScaleX(fMatrix.getScaleX())
21 , fTransX(fMatrix.getTranslateX()) {
21 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); 22 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
22 if (1 == scalarsPerPosition) { 23 if (1 == scalarsPerPosition) {
23 unsigned mtype = fMatrix.getType(); 24 unsigned mtype = fMatrix.getType();
24 if (mtype & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask)) { 25 if (mtype & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask)) {
25 fMapCase = kX; 26 fMapCase = kX;
26 } else { 27 } else {
27 // Bake the matrix scale/translation components into fOffset, 28 fY = SkScalarMul(y, fMatrix.getScaleY()) +
28 // to expedite proc computations. 29 fMatrix.getTranslateY();
29 fOffset.set(SkScalarMul(offset.x(), fMatrix.getScaleX()) + fMatr ix.getTranslateX(),
30 SkScalarMul(offset.y(), fMatrix.getScaleY()) + fMatr ix.getTranslateY());
31
32 if (mtype & SkMatrix::kScale_Mask) { 30 if (mtype & SkMatrix::kScale_Mask) {
33 fMapCase = kOnlyScaleX; 31 fMapCase = kOnlyScaleX;
34 } else { 32 } else {
35 fMapCase = kOnlyTransX; 33 fMapCase = kOnlyTransX;
36 } 34 }
37 } 35 }
38 } else { 36 } else {
39 fMapCase = kXY; 37 fMapCase = kXY;
40 } 38 }
41 } 39 }
42 40
43 void operator()(const SkScalar pos[], SkPoint* loc) const; 41 void operator()(const SkScalar pos[], SkPoint* loc) const;
44 42
45 private: 43 private:
46 const SkMatrix& fMatrix; 44 const SkMatrix& fMatrix;
47 enum { 45 enum {
48 kXY, 46 kXY,
49 kOnlyScaleX, 47 kOnlyScaleX,
50 kOnlyTransX, 48 kOnlyTransX,
51 kX 49 kX
52 } fMapCase; 50 } fMapCase;
53 const SkMatrix::MapXYProc fProc; 51 const SkMatrix::MapXYProc fProc;
54 SkPoint fOffset; // In kOnly* mode, this includes the matrix translation co mponent. 52 SkScalar fY; // Ignored by kXY case.
55 SkScalar fScaleX; // This is only used by kOnly... cases. 53 SkScalar fScaleX, fTransX; // These are only used by Only... cases.
56 }; 54 };
57 55
58 inline void SkTextMapStateProc::operator()(const SkScalar pos[], SkPoint* loc) c onst { 56 inline void SkTextMapStateProc::operator()(const SkScalar pos[], SkPoint* loc) c onst {
59 switch(fMapCase) { 57 switch(fMapCase) {
60 case kXY: 58 case kXY:
61 fProc(fMatrix, pos[0] + fOffset.x(), pos[1] + fOffset.y(), loc); 59 fProc(fMatrix, pos[0], pos[1], loc);
62 break; 60 break;
63 case kOnlyScaleX: 61 case kOnlyScaleX:
64 loc->set(SkScalarMul(fScaleX, *pos) + fOffset.x(), fOffset.y()); 62 loc->set(SkScalarMul(fScaleX, *pos) + fTransX, fY);
65 break; 63 break;
66 case kOnlyTransX: 64 case kOnlyTransX:
67 loc->set(*pos + fOffset.x(), fOffset.y()); 65 loc->set(*pos + fTransX, fY);
68 break; 66 break;
69 default: 67 default:
70 SkASSERT(false); 68 SkASSERT(false);
71 case kX: 69 case kX:
72 fProc(fMatrix, *pos + fOffset.x(), fOffset.y(), loc); 70 fProc(fMatrix, *pos, fY, loc);
73 break; 71 break;
74 } 72 }
75 } 73 }
76 74
77 #endif 75 #endif
78 76
OLDNEW
« no previous file with comments | « src/core/SkDraw.cpp ('k') | src/device/xps/SkXPSDevice.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698