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/GrDistanceFieldTextContext.cpp b/src/gpu/GrDistanceFieldTextContext.cpp
index ce2b175..9fa0c1d 100755
--- a/src/gpu/GrDistanceFieldTextContext.cpp
+++ b/src/gpu/GrDistanceFieldTextContext.cpp
@@ -28,9 +28,6 @@
 #include "SkStrokeRec.h"
 #include "effects/GrDistanceFieldTextureEffect.h"
 
-#include "SkDrawProcs.h"
-#include "SkTextMapStateProc.h"
-
 SK_CONF_DECLARE(bool, c_DumpFontCache, "gpu.dumpFontCache", false,
                 "Dump the contents of the font cache before every purge.");
 
@@ -210,6 +207,81 @@
     }
 }
 
+void GrDistanceFieldTextContext::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 or can't draw
+    if (text == NULL || byteLength == 0 /* no raster clip? || fRC->isEmpty()*/
+        || fSkPaint.getRasterizer()) {
+        return;
+    }
+
+    this->init(paint, skPaint);
+
+    SkScalar sizeRatio = fTextRatio;
+
+    SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc();
+
+    SkAutoGlyphCacheNoGamma    autoCache(fSkPaint, &fDeviceProperties, NULL);
+    SkGlyphCache*              cache = autoCache.getCache();
+    GrFontScaler*              fontScaler = GetGrFontScaler(cache);
+
+    setup_gamma_texture(fContext, cache, fDeviceProperties, &fGammaTexture);
+
+    // need to measure first
+    // TODO - generate positions and pre-load cache as well?
+    const char* stop = text + byteLength;
+    if (fSkPaint.getTextAlign() != SkPaint::kLeft_Align) {
+        SkFixed    stopX = 0;
+        SkFixed    stopY = 0;
+
+        const char* textPtr = text;
+        while (textPtr < stop) {
+            // don't need x, y here, since all subpixel variants will have the
+            // same advance
+            const SkGlyph& glyph = glyphCacheProc(cache, &textPtr, 0, 0);
+
+            stopX += glyph.fAdvanceX;
+            stopY += glyph.fAdvanceY;
+        }
+        SkASSERT(textPtr == stop);
+
+        SkScalar alignX = SkFixedToScalar(stopX)*sizeRatio;
+        SkScalar alignY = SkFixedToScalar(stopY)*sizeRatio;
+
+        if (fSkPaint.getTextAlign() == SkPaint::kCenter_Align) {
+            alignX = SkScalarHalf(alignX);
+            alignY = SkScalarHalf(alignY);
+        }
+
+        x -= alignX;
+        y -= alignY;
+    }
+
+    SkFixed fx = SkScalarToFixed(x);
+    SkFixed fy = SkScalarToFixed(y);
+    SkFixed fixedScale = SkScalarToFixed(sizeRatio);
+    while (text < stop) {
+        const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0);
+
+        if (glyph.fWidth) {
+            this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(),
+                                            glyph.getSubXFixed(),
+                                            glyph.getSubYFixed()),
+                              fx,
+                              fy,
+                              fontScaler);
+        }
+
+        fx += SkFixedMul_portable(glyph.fAdvanceX, fixedScale);
+        fy += SkFixedMul_portable(glyph.fAdvanceY, fixedScale);
+    }
+
+    this->finish();
+}
+
 void GrDistanceFieldTextContext::onDrawPosText(const GrPaint& paint, const SkPaint& skPaint,
                                              const char text[], size_t byteLength,
                                              const SkScalar pos[], int scalarsPerPosition,
@@ -254,8 +326,7 @@
             pos += scalarsPerPosition;
         }
     } else {
-        SkScalar alignMul = SkPaint::kCenter_Align == fSkPaint.getTextAlign() ? SK_ScalarHalf
-                                                                              : SK_Scalar1;
+        int alignShift = SkPaint::kCenter_Align == fSkPaint.getTextAlign() ? 1 : 0;
         while (text < stop) {
             // the last 2 parameters are ignored
             const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0);
@@ -264,14 +335,11 @@
                 SkScalar x = offset.x() + pos[0];
                 SkScalar y = offset.y() + (2 == scalarsPerPosition ? pos[1] : 0);
 
-                SkScalar advanceX = SkFixedToScalar(glyph.fAdvanceX)*alignMul*fTextRatio;
-                SkScalar advanceY = SkFixedToScalar(glyph.fAdvanceY)*alignMul*fTextRatio;
-
                 this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(),
                                                 glyph.getSubXFixed(),
                                                 glyph.getSubYFixed()),
-                                  SkScalarToFixed(x - advanceX),
-                                  SkScalarToFixed(y - advanceY),
+                                  SkScalarToFixed(x) - (glyph.fAdvanceX >> alignShift),
+                                  SkScalarToFixed(y) - (glyph.fAdvanceY >> alignShift),
                                   fontScaler);
             }
             pos += scalarsPerPosition;