Skip to content

Commit

Permalink
Allow purging of asset bitmaps
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nadlabak committed Jan 5, 2012
1 parent df09147 commit b479680
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions core/jni/android/graphics/BitmapFactory.cpp
Expand Up @@ -15,6 +15,7 @@
#include "JNIHelp.h"

#include <android_runtime/AndroidRuntime.h>
#include <cutils/properties.h>
#include <utils/Asset.h>
#include <utils/ResourceTypes.h>
#include <netinet/in.h>
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -359,8 +362,8 @@ static jobject nativeDecodeAsset(JNIEnv* env, jobject clazz,
jobject options) { // BitmapFactory$Options
SkStream* stream;
Asset* asset = reinterpret_cast<Asset*>(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);
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit b479680

Please sign in to comment.