From b479680a04217ac38f833f418f617bd2add09ba9 Mon Sep 17 00:00:00 2001 From: nadlabak Date: Wed, 16 Mar 2011 03:02:32 +0100 Subject: [PATCH] Allow purging of asset bitmaps Allow the system to reclaim more free RAM when needed on 'low' memory devices (e.g. Droid/Milestone). This option enabled efectively restores the froyo way of forcePurgeable BitmapFactory asset handling. Change-Id: If454e92743bf91efae42a8e4bcc2d2e7f9b90e91 --- core/jni/android/graphics/BitmapFactory.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/core/jni/android/graphics/BitmapFactory.cpp b/core/jni/android/graphics/BitmapFactory.cpp index ea35006f65a34..6e97a7f74c978 100644 --- a/core/jni/android/graphics/BitmapFactory.cpp +++ b/core/jni/android/graphics/BitmapFactory.cpp @@ -15,6 +15,7 @@ #include "JNIHelp.h" #include +#include #include #include #include @@ -44,6 +45,8 @@ jfieldID gBitmap_nativeBitmapFieldID; using namespace android; +bool mPurgeableAssets; + static inline int32_t validOrNeg1(bool isValid, int32_t value) { // return isValid ? value : -1; SkASSERT((int)isValid == 0 || (int)isValid == 1); @@ -359,8 +362,8 @@ static jobject nativeDecodeAsset(JNIEnv* env, jobject clazz, jobject options) { // BitmapFactory$Options SkStream* stream; Asset* asset = reinterpret_cast(native_asset); - bool forcePurgeable = optionsPurgeable(env, options); - if (forcePurgeable) { + bool forcePurgeable = mPurgeableAssets; + if (forcePurgeable || optionsPurgeable(env, options)) { // if we could "ref/reopen" the asset, we may not need to copy it here // and we could assume optionsShareable, since assets are always RO stream = copyAssetToStream(asset); @@ -530,6 +533,10 @@ int register_android_graphics_BitmapFactory(JNIEnv* env) { SkASSERT(bitmap_class); gBitmap_nativeBitmapFieldID = getFieldIDCheck(env, bitmap_class, "mNativeBitmap", "I"); + char value[PROPERTY_VALUE_MAX]; + property_get("persist.sys.purgeable_assets", value, "0"); + mPurgeableAssets = atoi(value) == 1; + int ret = AndroidRuntime::registerNativeMethods(env, "android/graphics/BitmapFactory$Options", gOptionsMethods,