Merge "Fix bug #6408393 Character corruption is caused when locale is changed" into jb-dev

This commit is contained in:
Fabrice Di Meglio
2012-05-08 10:54:41 -07:00
committed by Android (Google) Code Review
5 changed files with 47 additions and 2 deletions

View File

@@ -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<ComponentCallbacks2> 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<N; i++) {
@@ -3709,6 +3715,17 @@ public final class ActivityThread {
}
}
final void freeTextLayoutCachesIfNeeded(int configDiff) {
if (configDiff != 0) {
// Ask text layout engine to free its caches if there is a locale change
boolean hasLocaleConfigChange = ((configDiff & ActivityInfo.CONFIG_LOCALE) != 0);
if (hasLocaleConfigChange) {
Canvas.freeTextLayoutCaches();
if (DEBUG_CONFIGURATION) Slog.v(TAG, "Cleared TextLayout Caches");
}
}
}
final void handleActivityConfigurationChanged(IBinder token) {
ActivityClientRecord r = mActivities.get(token);
if (r == null || r.activity == null) {
@@ -3719,6 +3736,8 @@ public final class ActivityThread {
+ r.activityInfo.name);
performConfigurationChanged(r.activity, mCompatConfiguration);
freeTextLayoutCachesIfNeeded(r.activity.mCurrentConfig.diff(mCompatConfiguration));
}
final void handleProfilerControl(boolean start, ProfilerControlData pcd, int profileType) {
@@ -3821,6 +3840,9 @@ public final class ActivityThread {
// Ask graphics to free up as much as possible (font/image caches)
Canvas.freeCaches();
// Ask text layout engine to free also as much as possible
Canvas.freeTextLayoutCaches();
BinderInternal.forceGc("mem");
}

View File

@@ -69,7 +69,11 @@ public:
SkImageRef_GlobalPool::SetRAMUsed(0);
SkGraphics::PurgeFontCache();
}
static void freeTextLayoutCaches(JNIEnv* env, jobject) {
TextLayoutEngine::getInstance().purgeCaches();
}
static jboolean isOpaque(JNIEnv* env, jobject jcanvas) {
NPE_CHECK_RETURN_ZERO(env, jcanvas);
SkCanvas* canvas = GraphicsJNI::getNativeCanvas(env, jcanvas);
@@ -986,7 +990,9 @@ static JNINativeMethod gCanvasMethods[] = {
(void*) SkCanvasGlue::drawTextOnPath__StringPathFFPaint},
{"native_drawPicture", "(II)V", (void*) SkCanvasGlue::drawPicture},
{"freeCaches", "()V", (void*) SkCanvasGlue::freeCaches}
{"freeCaches", "()V", (void*) SkCanvasGlue::freeCaches},
{"freeTextLayoutCaches", "()V", (void*) SkCanvasGlue::freeTextLayoutCaches}
};
///////////////////////////////////////////////////////////////////////////////

View File

@@ -1015,4 +1015,11 @@ sp<TextLayoutValue> TextLayoutEngine::getValue(const SkPaint* paint, const jchar
return value;
}
void TextLayoutEngine::purgeCaches() {
#if USE_TEXT_LAYOUT_CACHE
mTextLayoutCache->clear();
#endif
}
} // namespace android

View File

@@ -310,6 +310,9 @@ public:
sp<TextLayoutValue> getValue(const SkPaint* paint, const jchar* text, jint start,
jint count, jint contextCount, jint dirFlags);
void purgeCaches();
private:
TextLayoutCache* mTextLayoutCache;
TextLayoutShaper* mShaper;

View File

@@ -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,