diff options
author | Mike Reed <reed@google.com> | 2009-04-27 14:32:05 -0400 |
---|---|---|
committer | Mike Reed <reed@google.com> | 2009-04-27 14:32:05 -0400 |
commit | caf0df1b7f99736aed1a0b923ef278fc4fd0fcca (patch) | |
tree | 59d8cc6a5756bb0a637d16768b4a6f41c997bbe2 | |
parent | fc8db53eee11568b286e8d9c17e211bd6781fab6 (diff) | |
download | frameworks_base-caf0df1b7f99736aed1a0b923ef278fc4fd0fcca.zip frameworks_base-caf0df1b7f99736aed1a0b923ef278fc4fd0fcca.tar.gz frameworks_base-caf0df1b7f99736aed1a0b923ef278fc4fd0fcca.tar.bz2 |
Add call to (new) Canvas.freeCaches() in response to low-memory
This is in conjunction with removing a similar call made by the browser.
Now it will be centralized, and the browser's call site will be removed.
-rw-r--r-- | core/java/android/app/ActivityThread.java | 3 | ||||
-rw-r--r-- | core/jni/android/graphics/Canvas.cpp | 9 | ||||
-rw-r--r-- | graphics/java/android/graphics/Canvas.java | 12 |
3 files changed, 21 insertions, 3 deletions
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java index 09862d2..3bd76a6 100644 --- a/core/java/android/app/ActivityThread.java +++ b/core/java/android/app/ActivityThread.java @@ -3496,6 +3496,9 @@ public final class ActivityThread { int sqliteReleased = SQLiteDatabase.releaseMemory(); EventLog.writeEvent(SQLITE_MEM_RELEASED_EVENT_LOG_TAG, sqliteReleased); } + + // Ask graphics to free up as much as possible (font/image caches) + Canvas.freeCaches(); BinderInternal.forceGc("mem"); } diff --git a/core/jni/android/graphics/Canvas.cpp b/core/jni/android/graphics/Canvas.cpp index 605e4b8..bd6fea8 100644 --- a/core/jni/android/graphics/Canvas.cpp +++ b/core/jni/android/graphics/Canvas.cpp @@ -21,6 +21,8 @@ #include "SkCanvas.h" #include "SkDevice.h" #include "SkGLCanvas.h" +#include "SkGraphics.h" +#include "SkImageRef_GlobalPool.h" #include "SkShader.h" #include "SkTemplates.h" @@ -58,8 +60,11 @@ public: return new SkGLCanvas; } - static void freeGlCaches(JNIEnv* env, jobject) { + static void freeCaches(JNIEnv* env, jobject) { + // these are called in no particular order SkGLCanvas::DeleteAllTextures(); + SkImageRef_GlobalPool::SetRAMUsed(0); + SkGraphics::SetFontCacheUsed(0); } static jboolean isOpaque(JNIEnv* env, jobject jcanvas) { @@ -933,7 +938,7 @@ static JNINativeMethod gCanvasMethods[] = { (void*) SkCanvasGlue::drawTextOnPath__StringPathFFPaint}, {"native_drawPicture", "(II)V", (void*) SkCanvasGlue::drawPicture}, - {"freeGlCaches", "()V", (void*) SkCanvasGlue::freeGlCaches} + {"freeCaches", "()V", (void*) SkCanvasGlue::freeCaches} }; #include <android_runtime/AndroidRuntime.h> diff --git a/graphics/java/android/graphics/Canvas.java b/graphics/java/android/graphics/Canvas.java index 32ecd9f..06d53e3 100644 --- a/graphics/java/android/graphics/Canvas.java +++ b/graphics/java/android/graphics/Canvas.java @@ -112,7 +112,9 @@ public class Canvas { * on behalf of the Canvas. Any subsequent drawing with a GL-backed Canvas * will have to recreate those resources. */ - public static native void freeGlCaches(); + public static void freeGlCaches() { + freeCaches(); + } /** * Specify a bitmap for the canvas to draw into. @@ -1405,6 +1407,14 @@ public class Canvas { finalizer(mNativeCanvas); } + /** + * Free up as much memory as possible from private caches (e.g. fonts, + * images) + * + * @hide - for now + */ + public static native void freeCaches(); + private static native int initRaster(int nativeBitmapOrZero); private static native int initGL(); private static native void native_setBitmap(int nativeCanvas, int bitmap); |