Revert of Change drawText() to generate positions and send to drawPosText() (patchset #4 id:60001 of https://codereview.chromium.org/653133004/)
Reason for revert:
A large number of GMs on Ubuntu12 are failing. The text layout on GPU is visibly different than that for 8888.
Original issue's description:
> Change drawText() to generate positions and send to drawPosText()
>
> The idea here is to have a central place that does layout for drawText(), and
> then always feed text through drawPosText(). This both makes all of the
> GrTextContexts consistent in drawText() output, and does a better job of
> stressing drawPosText().
>
> Because of the effect of matrices on hinting and approximation error, the
> generated text is not 100% identical to that produced by the raster pipeline.
>
> BUG=skia:2778
>
> Committed: https://skia.googlesource.com/skia/+/7851a56895c9c076f73a835a7dd51d3c6180c16f
TBR=cdalton.nvidia@gmail.com,bungeman@google.com,reed@google.com
NOTREECHECKS=true
NOTRY=true
BUG=skia:2778
Review URL: https://codereview.chromium.org/659993003
diff --git a/src/gpu/GrBitmapTextContext.cpp b/src/gpu/GrBitmapTextContext.cpp
index a1196dc..fa70d32 100755
--- a/src/gpu/GrBitmapTextContext.cpp
+++ b/src/gpu/GrBitmapTextContext.cpp
@@ -16,6 +16,7 @@
#include "GrTextStrike_impl.h"
#include "effects/GrCustomCoordsTextureEffect.h"
+#include "SkAutoKern.h"
#include "SkColorPriv.h"
#include "SkDraw.h"
#include "SkDrawProcs.h"
@@ -90,6 +91,97 @@
fMaxVertices = 0;
}
+void GrBitmapTextContext::onDrawText(const GrPaint& paint, const SkPaint& skPaint,
+ const char text[], size_t byteLength,
+ SkScalar x, SkScalar y) {
+ SkASSERT(byteLength == 0 || text != NULL);
+
+ // nothing to draw
+ if (text == NULL || byteLength == 0 /*|| fRC->isEmpty()*/) {
+ return;
+ }
+
+ this->init(paint, skPaint);
+
+ SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc();
+
+ SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, &fContext->getMatrix());
+ SkGlyphCache* cache = autoCache.getCache();
+ GrFontScaler* fontScaler = GetGrFontScaler(cache);
+
+ // transform our starting point
+ {
+ SkPoint loc;
+ fContext->getMatrix().mapXY(x, y, &loc);
+ x = loc.fX;
+ y = loc.fY;
+ }
+
+ // need to measure first
+ if (fSkPaint.getTextAlign() != SkPaint::kLeft_Align) {
+ SkVector stop;
+
+ MeasureText(cache, glyphCacheProc, text, byteLength, &stop);
+
+ SkScalar stopX = stop.fX;
+ SkScalar stopY = stop.fY;
+
+ if (fSkPaint.getTextAlign() == SkPaint::kCenter_Align) {
+ stopX = SkScalarHalf(stopX);
+ stopY = SkScalarHalf(stopY);
+ }
+ x -= stopX;
+ y -= stopY;
+ }
+
+ const char* stop = text + byteLength;
+
+ SkAutoKern autokern;
+
+ SkFixed fxMask = ~0;
+ SkFixed fyMask = ~0;
+ SkFixed halfSampleX, halfSampleY;
+ if (cache->isSubpixel()) {
+ halfSampleX = halfSampleY = (SK_FixedHalf >> SkGlyph::kSubBits);
+ SkAxisAlignment baseline = SkComputeAxisAlignmentForHText(fContext->getMatrix());
+ if (kX_SkAxisAlignment == baseline) {
+ fyMask = 0;
+ halfSampleY = SK_FixedHalf;
+ } else if (kY_SkAxisAlignment == baseline) {
+ fxMask = 0;
+ halfSampleX = SK_FixedHalf;
+ }
+ } else {
+ halfSampleX = halfSampleY = SK_FixedHalf;
+ }
+
+ SkFixed fx = SkScalarToFixed(x) + halfSampleX;
+ SkFixed fy = SkScalarToFixed(y) + halfSampleY;
+
+ GrContext::AutoMatrix autoMatrix;
+ autoMatrix.setIdentity(fContext, &fPaint);
+
+ while (text < stop) {
+ const SkGlyph& glyph = glyphCacheProc(cache, &text, fx & fxMask, fy & fyMask);
+
+ fx += autokern.adjust(glyph);
+
+ if (glyph.fWidth) {
+ this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(),
+ glyph.getSubXFixed(),
+ glyph.getSubYFixed()),
+ SkFixedFloorToFixed(fx),
+ SkFixedFloorToFixed(fy),
+ fontScaler);
+ }
+
+ fx += glyph.fAdvanceX;
+ fy += glyph.fAdvanceY;
+ }
+
+ this->finish();
+}
+
void GrBitmapTextContext::onDrawPosText(const GrPaint& paint, const SkPaint& skPaint,
const char text[], size_t byteLength,
const SkScalar pos[], int scalarsPerPosition,