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

Unified Diff: src/gpu/GrBitmapTextContext.cpp

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/SkTextMapStateProc.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrBitmapTextContext.cpp
diff --git a/src/gpu/GrBitmapTextContext.cpp b/src/gpu/GrBitmapTextContext.cpp
index a3e9cb3d794905ce6e673dbd21ac3453585740a5..b7a858dcaba13de8fd53d032f4a1ab3b60678c2b 100755
--- a/src/gpu/GrBitmapTextContext.cpp
+++ b/src/gpu/GrBitmapTextContext.cpp
@@ -20,9 +20,11 @@
#include "SkAutoKern.h"
#include "SkDraw.h"
+#include "SkDrawProcs.h"
#include "SkGlyphCache.h"
#include "SkGpuDevice.h"
#include "SkGr.h"
+#include "SkTextMapStateProc.h"
SK_CONF_DECLARE(bool, c_DumpFontCache, "gpu.dumpFontCache", false,
"Dump the contents of the font cache before every purge.");
@@ -263,98 +265,6 @@ void GrBitmapTextContext::drawText(const GrPaint& paint, const SkPaint& skPaint,
this->finish();
}
-///////////////////////////////////////////////////////////////////////////////
-// Copied from SkDraw
-
-// last parameter is interpreted as SkFixed [x, y]
-// return the fixed position, which may be rounded or not by the caller
-// e.g. subpixel doesn't round
-typedef void (*AlignProc)(const SkPoint&, const SkGlyph&, SkIPoint*);
-
-static void leftAlignProc(const SkPoint& loc, const SkGlyph& glyph, SkIPoint* dst) {
- dst->set(SkScalarToFixed(loc.fX), SkScalarToFixed(loc.fY));
-}
-
-static void centerAlignProc(const SkPoint& loc, const SkGlyph& glyph, SkIPoint* dst) {
- dst->set(SkScalarToFixed(loc.fX) - (glyph.fAdvanceX >> 1),
- SkScalarToFixed(loc.fY) - (glyph.fAdvanceY >> 1));
-}
-
-static void rightAlignProc(const SkPoint& loc, const SkGlyph& glyph, SkIPoint* dst) {
- dst->set(SkScalarToFixed(loc.fX) - glyph.fAdvanceX,
- SkScalarToFixed(loc.fY) - glyph.fAdvanceY);
-}
-
-static AlignProc pick_align_proc(SkPaint::Align align) {
- static const AlignProc gProcs[] = {
- leftAlignProc, centerAlignProc, rightAlignProc
- };
-
- SkASSERT((unsigned)align < SK_ARRAY_COUNT(gProcs));
-
- return gProcs[align];
-}
-
-class BitmapTextMapState {
-public:
- mutable SkPoint fLoc;
-
- BitmapTextMapState(const SkMatrix& matrix, SkScalar y)
- : fMatrix(matrix), fProc(matrix.getMapXYProc()), fY(y) {}
-
- typedef void (*Proc)(const BitmapTextMapState&, const SkScalar pos[]);
-
- Proc pickProc(int scalarsPerPosition);
-
-private:
- const SkMatrix& fMatrix;
- SkMatrix::MapXYProc fProc;
- SkScalar fY; // ignored by MapXYProc
- // these are only used by Only... procs
- SkScalar fScaleX, fTransX, fTransformedY;
-
- static void MapXProc(const BitmapTextMapState& state, const SkScalar pos[]) {
- state.fProc(state.fMatrix, *pos, state.fY, &state.fLoc);
- }
-
- static void MapXYProc(const BitmapTextMapState& state, const SkScalar pos[]) {
- state.fProc(state.fMatrix, pos[0], pos[1], &state.fLoc);
- }
-
- static void MapOnlyScaleXProc(const BitmapTextMapState& state,
- const SkScalar pos[]) {
- state.fLoc.set(SkScalarMul(state.fScaleX, *pos) + state.fTransX,
- state.fTransformedY);
- }
-
- static void MapOnlyTransXProc(const BitmapTextMapState& state,
- const SkScalar pos[]) {
- state.fLoc.set(*pos + state.fTransX, state.fTransformedY);
- }
-};
-
-BitmapTextMapState::Proc BitmapTextMapState::pickProc(int scalarsPerPosition) {
- SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
-
- if (1 == scalarsPerPosition) {
- unsigned mtype = fMatrix.getType();
- if (mtype & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask)) {
- return MapXProc;
- } else {
- fScaleX = fMatrix.getScaleX();
- fTransX = fMatrix.getTranslateX();
- fTransformedY = SkScalarMul(fY, fMatrix.getScaleY()) +
- fMatrix.getTranslateY();
- return (mtype & SkMatrix::kScale_Mask) ?
- MapOnlyScaleXProc : MapOnlyTransXProc;
- }
- } else {
- return MapXYProc;
- }
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
void GrBitmapTextContext::drawPosText(const GrPaint& paint, const SkPaint& skPaint,
const char text[], size_t byteLength,
const SkScalar pos[], SkScalar constY,
@@ -381,9 +291,8 @@ void GrBitmapTextContext::drawPosText(const GrPaint& paint, const SkPaint& skPai
autoMatrix.setIdentity(fContext, &fPaint);
const char* stop = text + byteLength;
- AlignProc alignProc = pick_align_proc(fSkPaint.getTextAlign());
- BitmapTextMapState tms(ctm, constY);
- BitmapTextMapState::Proc tmsProc = tms.pickProc(scalarsPerPosition);
+ SkTextAlignProc alignProc(fSkPaint.getTextAlign());
+ SkTextMapStateProc tmsProc(ctm, constY, scalarsPerPosition);
SkFixed halfSampleX = 0, halfSampleY = 0;
if (cache->isSubpixel()) {
@@ -406,9 +315,10 @@ void GrBitmapTextContext::drawPosText(const GrPaint& paint, const SkPaint& skPai
if (SkPaint::kLeft_Align == fSkPaint.getTextAlign()) {
while (text < stop) {
- tmsProc(tms, pos);
- SkFixed fx = SkScalarToFixed(tms.fLoc.fX) + halfSampleX;
- SkFixed fy = SkScalarToFixed(tms.fLoc.fY) + halfSampleY;
+ SkPoint tmsLoc;
+ tmsProc(pos, &tmsLoc);
+ SkFixed fx = SkScalarToFixed(tmsLoc.fX) + halfSampleX;
+ SkFixed fy = SkScalarToFixed(tmsLoc.fY) + halfSampleY;
const SkGlyph& glyph = glyphCacheProc(cache, &text,
fx & fxMask, fy & fyMask);
@@ -431,10 +341,10 @@ void GrBitmapTextContext::drawPosText(const GrPaint& paint, const SkPaint& skPai
if (metricGlyph.fWidth) {
SkDEBUGCODE(SkFixed prevAdvX = metricGlyph.fAdvanceX;)
SkDEBUGCODE(SkFixed prevAdvY = metricGlyph.fAdvanceY;)
-
- tmsProc(tms, pos);
+ SkPoint tmsLoc;
+ tmsProc(pos, &tmsLoc);
SkIPoint fixedLoc;
- alignProc(tms.fLoc, metricGlyph, &fixedLoc);
+ alignProc(tmsLoc, metricGlyph, &fixedLoc);
SkFixed fx = fixedLoc.fX + halfSampleX;
SkFixed fy = fixedLoc.fY + halfSampleY;
@@ -465,10 +375,11 @@ void GrBitmapTextContext::drawPosText(const GrPaint& paint, const SkPaint& skPai
const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0);
if (glyph.fWidth) {
- tmsProc(tms, pos);
+ SkPoint tmsLoc;
+ tmsProc(pos, &tmsLoc);
- SkFixed fx = SkScalarToFixed(tms.fLoc.fX) + SK_FixedHalf; //halfSampleX;
- SkFixed fy = SkScalarToFixed(tms.fLoc.fY) + SK_FixedHalf; //halfSampleY;
+ SkFixed fx = SkScalarToFixed(tmsLoc.fX) + SK_FixedHalf; //halfSampleX;
+ SkFixed fy = SkScalarToFixed(tmsLoc.fY) + SK_FixedHalf; //halfSampleY;
this->drawPackedGlyph(GrGlyph::Pack(glyph.getGlyphID(),
glyph.getSubXFixed(),
glyph.getSubYFixed()),
@@ -484,10 +395,11 @@ void GrBitmapTextContext::drawPosText(const GrPaint& paint, const SkPaint& skPai
const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0);
if (glyph.fWidth) {
- tmsProc(tms, pos);
+ SkPoint tmsLoc;
+ tmsProc(pos, &tmsLoc);
SkIPoint fixedLoc;
- alignProc(tms.fLoc, glyph, &fixedLoc);
+ alignProc(tmsLoc, glyph, &fixedLoc);
SkFixed fx = fixedLoc.fX + SK_FixedHalf; //halfSampleX;
SkFixed fy = fixedLoc.fY + SK_FixedHalf; //halfSampleY;
« no previous file with comments | « src/core/SkTextMapStateProc.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698