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

Unified Diff: src/core/SkTextMapStateProc.h

Issue 335573002: Extract "text align proc" functions as reusable classes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: address review comments Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkDrawProcs.h ('k') | src/gpu/GrBitmapTextContext.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkTextMapStateProc.h
diff --git a/src/core/SkTextMapStateProc.h b/src/core/SkTextMapStateProc.h
new file mode 100644
index 0000000000000000000000000000000000000000..5a8dcaa3b1a5b9e84c2fc3e127498a644c9d0697
--- /dev/null
+++ b/src/core/SkTextMapStateProc.h
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkTextMapStateProc_DEFINED
+#define SkTextMapStateProc_DEFINED
+
+#include "SkPoint.h"
+#include "SkMatrix.h"
+
+class SkTextMapStateProc {
+public:
+ SkTextMapStateProc(const SkMatrix& matrix, SkScalar y, int scalarsPerPosition)
+ : fMatrix(matrix)
+ , fProc(matrix.getMapXYProc())
+ , fY(y)
+ , fScaleX(fMatrix.getScaleX())
+ , fTransX(fMatrix.getTranslateX()) {
+ SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
+ if (1 == scalarsPerPosition) {
+ unsigned mtype = fMatrix.getType();
+ if (mtype & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask)) {
+ fMapCase = kX;
+ } else {
+ fY = SkScalarMul(y, fMatrix.getScaleY()) +
+ fMatrix.getTranslateY();
+ if (mtype & SkMatrix::kScale_Mask) {
+ fMapCase = kOnlyScaleX;
+ } else {
+ fMapCase = kOnlyTransX;
+ }
+ }
+ } else {
+ fMapCase = kXY;
+ }
+ }
+
+ void operator()(const SkScalar pos[], SkPoint* loc) const;
+
+private:
+ const SkMatrix& fMatrix;
+ enum {
+ kXY,
+ kOnlyScaleX,
+ kOnlyTransX,
+ kX
+ } fMapCase;
+ const SkMatrix::MapXYProc fProc;
+ SkScalar fY; // Ignored by kXY case.
+ SkScalar fScaleX, fTransX; // These are only used by Only... cases.
+};
+
+inline void SkTextMapStateProc::operator()(const SkScalar pos[], SkPoint* loc) const {
+ switch(fMapCase) {
+ case kXY:
+ fProc(fMatrix, pos[0], pos[1], loc);
+ break;
+ case kOnlyScaleX:
+ loc->set(SkScalarMul(fScaleX, *pos) + fTransX, fY);
+ break;
+ case kOnlyTransX:
+ loc->set(*pos + fTransX, fY);
+ break;
+ default:
+ SkASSERT(false);
+ case kX:
+ fProc(fMatrix, *pos, fY, loc);
+ break;
+ }
+}
+
+#endif
+
« no previous file with comments | « src/core/SkDrawProcs.h ('k') | src/gpu/GrBitmapTextContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698