Chromium Code Reviews| Index: src/gpu/GrAtlasTextContext.cpp |
| diff --git a/src/gpu/GrAtlasTextContext.cpp b/src/gpu/GrAtlasTextContext.cpp |
| index 4d6a675d991b56c6a573749708b20d86a21d041f..9a271f897e2f58b05ae44df8c1ea6834cdaf6d27 100644 |
| --- a/src/gpu/GrAtlasTextContext.cpp |
| +++ b/src/gpu/GrAtlasTextContext.cpp |
| @@ -27,6 +27,7 @@ |
| #include "SkDraw.h" |
| #include "SkDrawFilter.h" |
| #include "SkDrawProcs.h" |
| +#include "SkFindAndPlaceGlyph.h" |
| #include "SkGlyphCache.h" |
| #include "SkGpuDevice.h" |
| #include "SkGrPriv.h" |
| @@ -915,134 +916,30 @@ void GrAtlasTextContext::internalDrawBMPPosText(GrAtlasTextBlob* blob, int runIn |
| // Get GrFontScaler from cache |
| GrFontScaler* fontScaler = GetGrFontScaler(cache); |
| - const char* stop = text + byteLength; |
| SkTextAlignProc alignProc(skPaint.getTextAlign()); |
| SkTextMapStateProc tmsProc(viewMatrix, offset, scalarsPerPosition); |
| - if (cache->isSubpixel()) { |
| - // maybe we should skip the rounding if linearText is set |
| - SkAxisAlignment baseline = SkComputeAxisAlignmentForHText(viewMatrix); |
| - |
| - SkFixed fxMask = ~0; |
| - SkFixed fyMask = ~0; |
| - SkScalar halfSampleX = SkFixedToScalar(SkGlyph::kSubpixelRound); |
| - SkScalar halfSampleY = SkFixedToScalar(SkGlyph::kSubpixelRound); |
| - if (kX_SkAxisAlignment == baseline) { |
| - fyMask = 0; |
| - halfSampleY = SK_ScalarHalf; |
| - } else if (kY_SkAxisAlignment == baseline) { |
| - fxMask = 0; |
| - halfSampleX = SK_ScalarHalf; |
| - } |
| - |
| - if (SkPaint::kLeft_Align == skPaint.getTextAlign()) { |
| - while (text < stop) { |
| - SkPoint tmsLoc; |
| - tmsProc(pos, &tmsLoc); |
| - Sk48Dot16 fx = SkScalarTo48Dot16(tmsLoc.fX + halfSampleX); |
| - Sk48Dot16 fy = SkScalarTo48Dot16(tmsLoc.fY + halfSampleY); |
| - |
| - const SkGlyph& glyph = glyphCacheProc(cache, &text, |
| - fx & fxMask, fy & fyMask); |
| - |
| - if (glyph.fWidth) { |
| - this->bmpAppendGlyph(blob, |
| - runIndex, |
| - glyph, |
| - Sk48Dot16FloorToInt(fx), |
| - Sk48Dot16FloorToInt(fy), |
| - color, |
| - fontScaler, |
| - clipRect); |
| - } |
| - pos += scalarsPerPosition; |
| - } |
| - } else { |
| - while (text < stop) { |
| - const char* currentText = text; |
| - const SkGlyph& metricGlyph = glyphCacheProc(cache, &text, 0, 0); |
| - |
| - if (metricGlyph.fWidth) { |
| - SkDEBUGCODE(SkFixed prevAdvX = metricGlyph.fAdvanceX;) |
| - SkDEBUGCODE(SkFixed prevAdvY = metricGlyph.fAdvanceY;) |
| - SkPoint tmsLoc; |
| - tmsProc(pos, &tmsLoc); |
| - SkPoint alignLoc; |
| - alignProc(tmsLoc, metricGlyph, &alignLoc); |
| - |
| - Sk48Dot16 fx = SkScalarTo48Dot16(alignLoc.fX + halfSampleX); |
| - Sk48Dot16 fy = SkScalarTo48Dot16(alignLoc.fY + halfSampleY); |
| - |
| - // have to call again, now that we've been "aligned" |
| - const SkGlyph& glyph = glyphCacheProc(cache, ¤tText, |
| - fx & fxMask, fy & fyMask); |
| - // the assumption is that the metrics haven't changed |
| - SkASSERT(prevAdvX == glyph.fAdvanceX); |
| - SkASSERT(prevAdvY == glyph.fAdvanceY); |
| - SkASSERT(glyph.fWidth); |
| - |
| - this->bmpAppendGlyph(blob, |
| - runIndex, |
| - glyph, |
| - Sk48Dot16FloorToInt(fx), |
| - Sk48Dot16FloorToInt(fy), |
| - color, |
| - fontScaler, |
| - clipRect); |
| - } |
| - pos += scalarsPerPosition; |
| - } |
| - } |
| - } else { // not subpixel |
| - |
| - if (SkPaint::kLeft_Align == skPaint.getTextAlign()) { |
| - while (text < stop) { |
| - // the last 2 parameters are ignored |
| - const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); |
| - |
| - if (glyph.fWidth) { |
| - SkPoint tmsLoc; |
| - tmsProc(pos, &tmsLoc); |
| - |
| - Sk48Dot16 fx = SkScalarTo48Dot16(tmsLoc.fX + SK_ScalarHalf); //halfSampleX; |
| - Sk48Dot16 fy = SkScalarTo48Dot16(tmsLoc.fY + SK_ScalarHalf); //halfSampleY; |
| - this->bmpAppendGlyph(blob, |
| - runIndex, |
| - glyph, |
| - Sk48Dot16FloorToInt(fx), |
| - Sk48Dot16FloorToInt(fy), |
| - color, |
| - fontScaler, |
| - clipRect); |
| - } |
| - pos += scalarsPerPosition; |
| - } |
| - } else { |
| - while (text < stop) { |
| - // the last 2 parameters are ignored |
| - const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); |
| + auto processOneGlyph = |
| + [&](const SkGlyph& glyph, SkPoint position, SkPoint rounding) { |
| + position += rounding; |
| + this->bmpAppendGlyph(blob, |
| + runIndex, |
| + glyph, |
| + SkScalarFloorToInt(position.fX), |
| + SkScalarFloorToInt(position.fY), |
| + color, |
| + fontScaler, |
| + clipRect); |
| - if (glyph.fWidth) { |
| - SkPoint tmsLoc; |
| - tmsProc(pos, &tmsLoc); |
| + }; |
| - SkPoint alignLoc; |
| - alignProc(tmsLoc, glyph, &alignLoc); |
| - Sk48Dot16 fx = SkScalarTo48Dot16(alignLoc.fX + SK_ScalarHalf); //halfSampleX; |
| - Sk48Dot16 fy = SkScalarTo48Dot16(alignLoc.fY + SK_ScalarHalf); //halfSampleY; |
| - this->bmpAppendGlyph(blob, |
| - runIndex, |
| - glyph, |
| - Sk48Dot16FloorToInt(fx), |
| - Sk48Dot16FloorToInt(fy), |
| - color, |
| - fontScaler, |
| - clipRect); |
| - } |
| - pos += scalarsPerPosition; |
| - } |
| - } |
| + if (!SkFindAndPlaceGlyph::SpecializedProcessPosText( |
|
mtklein
2015/11/09 22:24:45
Now I'm thinking we should probably move Specializ
herb_g
2015/11/09 22:38:01
I think we want to leave them separate for now, be
|
| + text, byteLength, offset, viewMatrix, pos, scalarsPerPosition, skPaint.getTextAlign(), |
| + glyphCacheProc, cache, processOneGlyph)) { |
| + SkFindAndPlaceGlyph::ProcessPosText( |
| + text, byteLength, offset, viewMatrix, pos, scalarsPerPosition, skPaint.getTextAlign(), |
| + glyphCacheProc, cache, processOneGlyph); |
| } |
| } |