start removing legacy paint calls

Bug: skia:
Change-Id: I2a5c98c65e587015beb0ed6f6d5bcf5a3a1b69a2
Reviewed-on: https://skia-review.googlesource.com/c/177066
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
diff --git a/src/core/SkLiteDL.cpp b/src/core/SkLiteDL.cpp
index 93aba33..053d0d5 100644
--- a/src/core/SkLiteDL.cpp
+++ b/src/core/SkLiteDL.cpp
@@ -587,7 +587,7 @@
 
 void SkLiteDL::drawTextRSXform(const void* text, size_t bytes,
                                const SkRSXform xforms[], const SkRect* cull, const SkPaint& paint) {
-    int n = paint.countText(text, bytes);
+    int n = SkFont::LEGACY_ExtractFromPaint(paint).countText(text, bytes, paint.getTextEncoding());
     void* pod = this->push<DrawTextRSXform>(bytes+n*sizeof(SkRSXform), bytes, n, cull, paint);
     copy_v(pod, xforms,n, (const char*)text,bytes);
 }
diff --git a/src/core/SkPaint_text.cpp b/src/core/SkPaint_text.cpp
index a82af19..e241176 100644
--- a/src/core/SkPaint_text.cpp
+++ b/src/core/SkPaint_text.cpp
@@ -61,6 +61,7 @@
 #include "SkGlyphCache.h"
 #include "SkUtils.h"
 
+#ifdef SK_SUPPORT_LEGACY_PAINT_TEXTMEASURE
 int SkPaint::countText(const void* text, size_t length) const {
     return SkFont::LEGACY_ExtractFromPaint(*this).countText(text, length, this->getTextEncoding());
 }
@@ -75,6 +76,7 @@
     return SkFont::LEGACY_ExtractFromPaint(*this).containsText(text, length,
                                                                this->getTextEncoding());
 }
+#endif
 
 void SkPaint::glyphsToUnichars(const uint16_t glyphs[], int count, SkUnichar textData[]) const {
     SkFont::LEGACY_ExtractFromPaint(*this).glyphsToUnichars(glyphs, count, textData);
@@ -297,6 +299,7 @@
     return x;
 }
 
+#ifdef SK_SUPPORT_LEGACY_PAINT_TEXTMEASURE
 SkScalar SkPaint::measureText(const void* textData, size_t length, SkRect* bounds) const {
     const char* text = (const char*)textData;
     SkASSERT(text != nullptr || length == 0);
@@ -330,20 +333,10 @@
     return width;
 }
 
-#ifdef SK_SUPPORT_LEGACY_PAINT_BREAKTEXT
-size_t SkPaint::breakText(const void* textD, size_t length, SkScalar maxWidth,
-                          SkScalar* measuredWidth) const {
-    return SkFont::LEGACY_ExtractFromPaint(*this).breakText(textD, length,
-                                                this->getTextEncoding(), maxWidth, measuredWidth);
-}
-#endif
-
 SkScalar SkPaint::getFontMetrics(SkFontMetrics* metrics) const {
     return SkFont::LEGACY_ExtractFromPaint(*this).getMetrics(metrics);
 }
 
-///////////////////////////////////////////////////////////////////////////////
-
 int SkPaint::getTextWidths(const void* text, size_t len, SkScalar widths[], SkRect bounds[]) const {
     const SkFont font = SkFont::LEGACY_ExtractFromPaint(*this);
     SkAutoToGlyphs gly(font, text, len, this->getTextEncoding());
@@ -351,8 +344,19 @@
     return gly.count();
 }
 
+#endif
+
+#ifdef SK_SUPPORT_LEGACY_PAINT_BREAKTEXT
+size_t SkPaint::breakText(const void* textD, size_t length, SkScalar maxWidth,
+                          SkScalar* measuredWidth) const {
+    return SkFont::LEGACY_ExtractFromPaint(*this).breakText(textD, length,
+                                                this->getTextEncoding(), maxWidth, measuredWidth);
+}
+#endif
+
 ///////////////////////////////////////////////////////////////////////////////
 
+#ifdef SK_SUPPORT_LEGACY_PAINT_TEXTMEASURE
 #include "SkDraw.h"
 
 struct PathPosRec {
@@ -390,6 +394,7 @@
     PathPosRec rec = { path, pos };
     font.getPaths(gly.glyphs(), gly.count(), PathPosProc, &rec);
 }
+#endif
 
 int SkPaint::getTextBlobIntercepts(const SkTextBlob* blob, const SkScalar bounds[2],
                                    SkScalar* intervals) const {
diff --git a/src/core/SkPictureRecord.cpp b/src/core/SkPictureRecord.cpp
index 642cafd..a2d5c97 100644
--- a/src/core/SkPictureRecord.cpp
+++ b/src/core/SkPictureRecord.cpp
@@ -564,7 +564,7 @@
 void SkPictureRecord::onDrawTextRSXform(const void* text, size_t byteLength,
                                         const SkRSXform xform[], const SkRect* cull,
                                         const SkPaint& paint) {
-    const int count = paint.countText(text, byteLength);
+    const int count = SkFont::LEGACY_ExtractFromPaint(paint).countText(text, byteLength, paint.getTextEncoding());
     // [op + paint-index + count + flags + length] + [text] + [xform] + cull
     size_t size = 5 * kUInt32Size + SkAlign4(byteLength) + count * sizeof(SkRSXform);
     uint32_t flags = 0;
diff --git a/src/core/SkRecorder.cpp b/src/core/SkRecorder.cpp
index a33251d..b887654 100644
--- a/src/core/SkRecorder.cpp
+++ b/src/core/SkRecorder.cpp
@@ -268,7 +268,7 @@
            paint,
            this->copy((const char*)text, byteLength),
            byteLength,
-           this->copy(xform, paint.countText(text, byteLength)),
+           this->copy(xform, SkFont::LEGACY_ExtractFromPaint(paint).countText(text, byteLength, paint.getTextEncoding())),
            this->copy(cull));
 }
 
diff --git a/src/utils/SkTextUtils.cpp b/src/utils/SkTextUtils.cpp
index e588d3c..570643c 100644
--- a/src/utils/SkTextUtils.cpp
+++ b/src/utils/SkTextUtils.cpp
@@ -6,48 +6,21 @@
  */
 
 #include "SkTextUtils.h"
+#include "SkTextBlob.h"
 
 void SkTextUtils::DrawText(SkCanvas* canvas, const void* text, size_t size, SkScalar x, SkScalar y,
-                            const SkPaint& origPaint, Align align) {
-    int count = origPaint.countText(text, size);
-    if (!count) {
-        return;
-    }
+                            const SkPaint& paint, Align align) {
 
-    SkPaint paint(origPaint);
-    SkAutoSTArray<32, uint16_t> glyphStorage;
-    const uint16_t* glyphs;
-
-    if (paint.getTextEncoding() != kGlyphID_SkTextEncoding) {
-        glyphStorage.reset(count);
-        paint.textToGlyphs(text, size, glyphStorage.get());
-        glyphs = glyphStorage.get();
-        paint.setTextEncoding(kGlyphID_SkTextEncoding);
-    } else {
-        glyphs = static_cast<const uint16_t*>(text);
-    }
-
-    SkAutoSTArray<32, SkScalar> widthStorage(count);
-    SkScalar* widths = widthStorage.get();
-    paint.getTextWidths(glyphs, count * sizeof(uint16_t), widths);
+    SkFont font = SkFont::LEGACY_ExtractFromPaint(paint);
 
     if (align != kLeft_Align) {
-        SkScalar offset = 0;
-        for (int i = 0; i < count; ++i) {
-            offset += widths[i];
-        }
+        SkScalar width = font.measureText(text, size, paint.getTextEncoding());
         if (align == kCenter_Align) {
-            offset *= 0.5f;
+            width *= 0.5f;
         }
-        x -= offset;
+        x -= width;
     }
 
-    // Turn widths into h-positions
-    for (int i = 0; i < count; ++i) {
-        SkScalar w = widths[i];
-        widths[i] = x;
-        x += w;
-    }
-    canvas->drawPosTextH(glyphs, count * sizeof(uint16_t), widths, y, paint);
+    canvas->drawTextBlob(SkTextBlob::MakeFromText(text, size, font, paint.getTextEncoding()), x, y, paint);
 }