Measure text with the appropriate text encoding.
Bug #4546327

Change-Id: I8eb593b03a81145e08be92579706ddd775feb0a2
diff --git a/libs/hwui/OpenGLRenderer.cpp b/libs/hwui/OpenGLRenderer.cpp
index 45f4a42..8558054 100644
--- a/libs/hwui/OpenGLRenderer.cpp
+++ b/libs/hwui/OpenGLRenderer.cpp
@@ -1949,7 +1949,16 @@
     }
     if (mSnapshot->isIgnored()) return;
 
+    // TODO: We should probably make a copy of the paint instead of modifying
+    //       it; modifying the paint will change its generationID the first
+    //       time, which might impact caches. More investigation needed to
+    //       see if it matters.
+    //       If we make a copy, then drawTextDecorations() should *not* make
+    //       its own copy as it does right now.
     paint->setAntiAlias(true);
+#if RENDER_TEXT_AS_GLYPHS
+    paint->setTextEncoding(SkPaint::kGlyphID_TextEncoding);
+#endif
 
     float length = -1.0f;
     switch (paint->getTextAlign()) {
@@ -1983,8 +1992,8 @@
 
     if (mHasShadow) {
         mCaches.dropShadowCache.setFontRenderer(fontRenderer);
-        const ShadowTexture* shadow = mCaches.dropShadowCache.get(paint, text, bytesCount,
-                count, mShadowRadius);
+        const ShadowTexture* shadow = mCaches.dropShadowCache.get(
+                paint, text, bytesCount, count, mShadowRadius);
         const AutoTexture autoCleanup(shadow);
 
         const float sx = oldX - shadow->left + mShadowDx;
@@ -2226,10 +2235,6 @@
     uint32_t flags = paint->getFlags();
     if (flags & (SkPaint::kUnderlineText_Flag | SkPaint::kStrikeThruText_Flag)) {
         SkPaint paintCopy(*paint);
-#if RENDER_TEXT_AS_GLYPHS
-        paintCopy.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
-#endif
-
         float underlineWidth = length;
         // If length is > 0.0f, we already measured the text for the text alignment
         if (length <= 0.0f) {