From 30ca5cd11a23f06f2f8eeaa587685450826f800f Mon Sep 17 00:00:00 2001 From: Fabrice Di Meglio Date: Mon, 7 May 2012 17:45:44 -0700 Subject: [PATCH] Fix bug #6408393 Character corruption is caused when locale is changed - free the TextLayoutCache on Locale change - also free TextLayoutCache when memory is low Change-Id: I39a37ac8ec3c292cfb1c0eea4bb41ff71897d089 --- core/java/android/app/ActivityThread.java | 22 +++++++++++++++++++ core/jni/android/graphics/Canvas.cpp | 10 +++++++-- core/jni/android/graphics/TextLayoutCache.cpp | 7 ++++++ core/jni/android/graphics/TextLayoutCache.h | 3 +++ graphics/java/android/graphics/Canvas.java | 7 ++++++ 5 files changed, 47 insertions(+), 2 deletions(-) diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index b55ee26a500b3..e53438c5bf6ea 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -2639,6 +2639,7 @@ public final class ActivityThread { if (DEBUG_CONFIGURATION) Slog.v(TAG, "Resuming activity " + r.activityInfo.name + " with newConfig " + r.newConfig); performConfigurationChanged(r.activity, r.newConfig); + freeTextLayoutCachesIfNeeded(r.activity.mCurrentConfig.diff(r.newConfig)); r.newConfig = null; } if (localLOGV) Slog.v(TAG, "Resuming " + r + " with isForward=" @@ -2955,6 +2956,7 @@ public final class ActivityThread { if (DEBUG_CONFIGURATION) Slog.v(TAG, "Updating activity vis " + r.activityInfo.name + " with new config " + r.newConfig); performConfigurationChanged(r.activity, r.newConfig); + freeTextLayoutCachesIfNeeded(r.activity.mCurrentConfig.diff(r.newConfig)); r.newConfig = null; } } else { @@ -3669,6 +3671,7 @@ public final class ActivityThread { final void handleConfigurationChanged(Configuration config, CompatibilityInfo compat) { ArrayList callbacks = null; + int configDiff = 0; synchronized (mPackages) { if (mPendingConfiguration != null) { @@ -3693,6 +3696,7 @@ public final class ActivityThread { if (!mConfiguration.isOtherSeqNewer(config) && compat == null) { return; } + configDiff = mConfiguration.diff(config); mConfiguration.updateFrom(config); config = applyCompatConfiguration(); callbacks = collectComponentCallbacksLocked(false, config); @@ -3701,6 +3705,8 @@ public final class ActivityThread { // Cleanup hardware accelerated stuff WindowManagerImpl.getDefault().trimLocalMemory(); + freeTextLayoutCachesIfNeeded(configDiff); + if (callbacks != null) { final int N = callbacks.size(); for (int i=0; i TextLayoutEngine::getValue(const SkPaint* paint, const jchar return value; } +void TextLayoutEngine::purgeCaches() { +#if USE_TEXT_LAYOUT_CACHE + mTextLayoutCache->clear(); +#endif +} + + } // namespace android diff --git a/core/jni/android/graphics/TextLayoutCache.h b/core/jni/android/graphics/TextLayoutCache.h index 7d7caacadfa75..7308367f6bbbc 100644 --- a/core/jni/android/graphics/TextLayoutCache.h +++ b/core/jni/android/graphics/TextLayoutCache.h @@ -309,6 +309,9 @@ public: sp getValue(const SkPaint* paint, const jchar* text, jint start, jint count, jint contextCount, jint dirFlags); + + void purgeCaches(); + private: TextLayoutCache* mTextLayoutCache; TextLayoutShaper* mShaper; diff --git a/graphics/java/android/graphics/Canvas.java b/graphics/java/android/graphics/Canvas.java index 7e92973817334..3949afdd4a2ae 100644 --- a/graphics/java/android/graphics/Canvas.java +++ b/graphics/java/android/graphics/Canvas.java @@ -1617,6 +1617,13 @@ public class Canvas { */ public static native void freeCaches(); + /** + * Free up text layout caches + * + * @hide + */ + public static native void freeTextLayoutCaches(); + private static native int initRaster(int nativeBitmapOrZero); private static native void native_setBitmap(int nativeCanvas, int bitmap); private static native int native_saveLayer(int nativeCanvas, RectF bounds,