Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7af4dfcc authored by Conn O'Griofa's avatar Conn O'Griofa Committed by Ricardo Cerqueira
Browse files

Allow purging of asset bitmaps

It seems that neither CM9 nor CM10.x includes the actual framework-side
code to facilitate user-controllable bitmap purging. Odd, since the
CyanogenMod Settings app in both CM9/CM10.x includes the option.

Backported from original Gingerbread commit:
http://review.cyanogenmod.org/#/c/3908

Original description:

Allow the system to reclaim more free RAM when needed on 'low' memory devices
(e.g. Droid/Milestone) that are struggling with 2.3. This option enabled
efectively restores the froyo way of forcePurgeable BitmapFactory asset
handling.

Change-Id: I6a3b8a05b7be9c214a8548d6c6d1621e6533a1e0
parent 6c34adb9
Loading
Loading
Loading
Loading
+10 −2
Original line number Original line Diff line number Diff line
@@ -18,6 +18,7 @@
#include "GraphicsJNI.h"
#include "GraphicsJNI.h"


#include <android_runtime/AndroidRuntime.h>
#include <android_runtime/AndroidRuntime.h>
#include <cutils/properties.h>
#include <androidfw/Asset.h>
#include <androidfw/Asset.h>
#include <androidfw/ResourceTypes.h>
#include <androidfw/ResourceTypes.h>
#include <netinet/in.h>
#include <netinet/in.h>
@@ -53,6 +54,8 @@ jfieldID gBitmap_layoutBoundsFieldID;


using namespace android;
using namespace android;


bool mPurgeableAssets;

static inline int32_t validOrNeg1(bool isValid, int32_t value) {
static inline int32_t validOrNeg1(bool isValid, int32_t value) {
//    return isValid ? value : -1;
//    return isValid ? value : -1;
    SkASSERT((int)isValid == 0 || (int)isValid == 1);
    SkASSERT((int)isValid == 0 || (int)isValid == 1);
@@ -530,8 +533,8 @@ static jobject nativeDecodeAsset(JNIEnv* env, jobject clazz, jint native_asset,


    SkStreamRewindable* stream;
    SkStreamRewindable* stream;
    Asset* asset = reinterpret_cast<Asset*>(native_asset);
    Asset* asset = reinterpret_cast<Asset*>(native_asset);
    bool forcePurgeable = optionsPurgeable(env, options);
    bool forcePurgeable = mPurgeableAssets;
    if (forcePurgeable) {
    if (forcePurgeable || optionsPurgeable(env, options)) {
        // if we could "ref/reopen" the asset, we may not need to copy it here
        // 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
        // and we could assume optionsShareable, since assets are always RO
        stream = CopyAssetToStream(asset);
        stream = CopyAssetToStream(asset);
@@ -640,6 +643,11 @@ int register_android_graphics_BitmapFactory(JNIEnv* env) {
    SkASSERT(bitmap_class);
    SkASSERT(bitmap_class);
    gBitmap_nativeBitmapFieldID = getFieldIDCheck(env, bitmap_class, "mNativeBitmap", "I");
    gBitmap_nativeBitmapFieldID = getFieldIDCheck(env, bitmap_class, "mNativeBitmap", "I");
    gBitmap_layoutBoundsFieldID = getFieldIDCheck(env, bitmap_class, "mLayoutBounds", "[I");
    gBitmap_layoutBoundsFieldID = getFieldIDCheck(env, bitmap_class, "mLayoutBounds", "[I");

    char value[PROPERTY_VALUE_MAX];
    property_get("persist.sys.purgeable_assets", value, "0");
    mPurgeableAssets = atoi(value) == 1;

    int ret = AndroidRuntime::registerNativeMethods(env,
    int ret = AndroidRuntime::registerNativeMethods(env,
                                    "android/graphics/BitmapFactory$Options",
                                    "android/graphics/BitmapFactory$Options",
                                    gOptionsMethods,
                                    gOptionsMethods,