Merge "Fix bug #5846413 "phone" keyboard layout is broken on master"
diff --git a/core/jni/android/graphics/Canvas.cpp b/core/jni/android/graphics/Canvas.cpp
index 3e9ab86..c8b725a 100644
--- a/core/jni/android/graphics/Canvas.cpp
+++ b/core/jni/android/graphics/Canvas.cpp
@@ -776,9 +776,6 @@
 
     static void doDrawGlyphs(SkCanvas* canvas, const jchar* glyphArray, int index, int count,
             jfloat x, jfloat y, int flags, SkPaint* paint) {
-        // TODO: need to suppress this code after the GL renderer is modified for not
-        // copying the paint
-
         // Beware: this needs Glyph encoding (already done on the Paint constructor)
         canvas->drawText(glyphArray + index * 2, count * 2, x, y, *paint);
     }
diff --git a/core/jni/android/graphics/Paint.cpp b/core/jni/android/graphics/Paint.cpp
index 9f3238ab..9bcfa5f 100644
--- a/core/jni/android/graphics/Paint.cpp
+++ b/core/jni/android/graphics/Paint.cpp
@@ -466,7 +466,8 @@
         jchar* glyphsArray = env->GetCharArrayElements(glyphs, NULL);
 
         TextLayoutCacheValue value(contextCount);
-        TextLayoutEngine::getInstance().computeValues(&value, paint, text, start, count, contextCount, flags);
+        TextLayoutEngine::getInstance().computeValues(&value, paint, text, start, count,
+                contextCount, flags);
         const jchar* shapedGlyphs = value.getGlyphs();
         size_t glyphsCount = value.getGlyphsCount();
         memcpy(glyphsArray, shapedGlyphs, sizeof(jchar) * glyphsCount);
@@ -673,13 +674,25 @@
         }
     }
 
-    static int breakText(JNIEnv* env, const SkPaint& paint, const jchar text[],
+    static int breakText(JNIEnv* env, SkPaint& paint, const jchar text[],
                          int count, float maxWidth, jfloatArray jmeasured,
                          SkPaint::TextBufferDirection tbd) {
-        SkASSERT(paint.getTextEncoding() == SkPaint::kUTF16_TextEncoding);
+        sp<TextLayoutCacheValue> value;
+#if USE_TEXT_LAYOUT_CACHE
+        value = TextLayoutCache::getInstance().getValue(&paint, text, 0, count,
+                count, paint.getFlags());
+        if (value == NULL) {
+            ALOGE("Cannot get TextLayoutCache value for text = '%s'",
+                    String8(text, count).string());
+        }
+#else
+        value = new TextLayoutCacheValue(count);
+        TextLayoutEngine::getInstance().computeValues(value.get(), &paint,
+                reinterpret_cast<const UChar*>(text), 0, count, count, paint.getFlags());
+#endif
 
         SkScalar     measured;
-        size_t       bytes = paint.breakText(text, count << 1,
+        size_t       bytes = paint.breakText(value->getGlyphs(), value->getGlyphsCount() << 1,
                                    SkFloatToScalar(maxWidth), &measured, tbd);
         SkASSERT((bytes & 1) == 0);
 
@@ -743,7 +756,20 @@
         SkRect  r;
         SkIRect ir;
 
-        paint.measureText(text, count << 1, &r);
+        sp<TextLayoutCacheValue> value;
+#if USE_TEXT_LAYOUT_CACHE
+        value = TextLayoutCache::getInstance().getValue(&paint, text, 0, count,
+                count, paint.getFlags());
+        if (value == NULL) {
+            ALOGE("Cannot get TextLayoutCache value for text = '%s'",
+                    String8(text, count).string());
+        }
+#else
+        value = new TextLayoutCacheValue(count);
+        TextLayoutEngine::getInstance().computeValues(value.get(), &paint,
+                reinterpret_cast<const UChar*>(text), 0, count, count, paint.getFlags());
+#endif
+        paint.measureText(value->getGlyphs(), value->getGlyphsCount() << 1, &r);
         r.roundOut(&ir);
         GraphicsJNI::irect_to_jrect(ir, env, bounds);
     }
diff --git a/core/jni/android/graphics/TextLayoutCache.cpp b/core/jni/android/graphics/TextLayoutCache.cpp
index d26f563..71c283a 100644
--- a/core/jni/android/graphics/TextLayoutCache.cpp
+++ b/core/jni/android/graphics/TextLayoutCache.cpp
@@ -93,7 +93,7 @@
 /*
  * Caching
  */
-sp<TextLayoutCacheValue> TextLayoutCache::getValue(SkPaint* paint,
+sp<TextLayoutCacheValue> TextLayoutCache::getValue(const SkPaint* paint,
             const jchar* text, jint start, jint count, jint contextCount, jint dirFlags) {
     AutoMutex _l(mLock);
     nsecs_t startTime = 0;
@@ -360,7 +360,7 @@
     // we don't bother at the moment
 }
 
-void TextLayoutEngine::computeValues(TextLayoutCacheValue* value, SkPaint* paint, const UChar* chars,
+void TextLayoutEngine::computeValues(TextLayoutCacheValue* value, const SkPaint* paint, const UChar* chars,
         size_t start, size_t count, size_t contextCount, int dirFlags) {
 
     computeValues(paint, chars, start, count, contextCount, dirFlags,
@@ -371,7 +371,7 @@
 #endif
 }
 
-void TextLayoutEngine::computeValues(SkPaint* paint, const UChar* chars,
+void TextLayoutEngine::computeValues(const SkPaint* paint, const UChar* chars,
         size_t start, size_t count, size_t contextCount, int dirFlags,
         Vector<jfloat>* const outAdvances, jfloat* outTotalAdvance,
         Vector<jchar>* const outGlyphs) {
@@ -513,7 +513,7 @@
     }
 }
 
-void TextLayoutEngine::computeRunValues(SkPaint* paint, const UChar* chars,
+void TextLayoutEngine::computeRunValues(const SkPaint* paint, const UChar* chars,
         size_t count, bool isRTL,
         Vector<jfloat>* const outAdvances, jfloat* outTotalAdvance,
         Vector<jchar>* const outGlyphs) {
@@ -719,7 +719,7 @@
 }
 
 
-size_t TextLayoutEngine::shapeFontRun(SkPaint* paint, bool isRTL) {
+size_t TextLayoutEngine::shapeFontRun(const SkPaint* paint, bool isRTL) {
     // Reset kerning
     mShaperItem.kerning_applied = false;
 
diff --git a/core/jni/android/graphics/TextLayoutCache.h b/core/jni/android/graphics/TextLayoutCache.h
index 510aa18..956e8ca 100644
--- a/core/jni/android/graphics/TextLayoutCache.h
+++ b/core/jni/android/graphics/TextLayoutCache.h
@@ -179,7 +179,7 @@
      */
     void operator()(TextLayoutCacheKey& text, sp<TextLayoutCacheValue>& desc);
 
-    sp<TextLayoutCacheValue> getValue(SkPaint* paint, const jchar* text, jint start, jint count,
+    sp<TextLayoutCacheValue> getValue(const SkPaint* paint, const jchar* text, jint start, jint count,
             jint contextCount, jint dirFlags);
 
     /**
@@ -224,7 +224,7 @@
     TextLayoutEngine();
     virtual ~TextLayoutEngine();
 
-    void computeValues(TextLayoutCacheValue* value, SkPaint* paint, const UChar* chars,
+    void computeValues(TextLayoutCacheValue* value, const SkPaint* paint, const UChar* chars,
             size_t start, size_t count, size_t contextCount, int dirFlags);
 
 private:
@@ -273,14 +273,14 @@
      */
     UnicodeString mBuffer;
 
-    size_t shapeFontRun(SkPaint* paint, bool isRTL);
+    size_t shapeFontRun(const SkPaint* paint, bool isRTL);
 
-    void computeValues(SkPaint* paint, const UChar* chars,
+    void computeValues(const SkPaint* paint, const UChar* chars,
             size_t start, size_t count, size_t contextCount, int dirFlags,
             Vector<jfloat>* const outAdvances, jfloat* outTotalAdvance,
             Vector<jchar>* const outGlyphs);
 
-    void computeRunValues(SkPaint* paint, const UChar* chars,
+    void computeRunValues(const SkPaint* paint, const UChar* chars,
             size_t count, bool isRTL,
             Vector<jfloat>* const outAdvances, jfloat* outTotalAdvance,
             Vector<jchar>* const outGlyphs);