diff options
| author | 2014-08-26 21:47:45 +0000 | |
|---|---|---|
| committer | 2014-08-26 21:47:46 +0000 | |
| commit | b34eeb70a695af5daf876d13502df0cb20b8e4bb (patch) | |
| tree | f4f0d92755d30a893b8aa0fe3cee71eec8012ca7 /graphics/java/android | |
| parent | 7837dac4627cc2e9c23d37d1bdb83cb6d763dfd5 (diff) | |
| parent | 4cd7dbc90f93893f521dce32d8cd25c02a185a24 (diff) | |
Merge "Notify VM of native pixelref allocations" into lmp-dev
Diffstat (limited to 'graphics/java/android')
| -rw-r--r-- | graphics/java/android/graphics/Bitmap.java | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/graphics/java/android/graphics/Bitmap.java b/graphics/java/android/graphics/Bitmap.java index 4d0bb75e7cc9..3090ffd896a5 100644 --- a/graphics/java/android/graphics/Bitmap.java +++ b/graphics/java/android/graphics/Bitmap.java @@ -21,6 +21,7 @@ import android.os.Parcel; import android.os.Parcelable; import android.os.Trace; import android.util.DisplayMetrics; +import dalvik.system.VMRuntime; import java.io.OutputStream; import java.nio.Buffer; @@ -122,15 +123,18 @@ public final class Bitmap implements Parcelable { mIsMutable = isMutable; mRequestPremultiplied = requestPremultiplied; mBuffer = buffer; + // we delete this in our finalizer mNativeBitmap = nativeBitmap; - mFinalizer = new BitmapFinalizer(nativeBitmap); mNinePatchChunk = ninePatchChunk; mNinePatchInsets = ninePatchInsets; if (density >= 0) { mDensity = density; } + + int nativeAllocationByteCount = buffer == null ? getByteCount() : 0; + mFinalizer = new BitmapFinalizer(nativeBitmap, nativeAllocationByteCount); } /** @@ -1574,8 +1578,17 @@ public final class Bitmap implements Parcelable { private static class BitmapFinalizer { private final long mNativeBitmap; - BitmapFinalizer(long nativeBitmap) { + // Native memory allocated for the duration of the Bitmap, + // if pixel data allocated into native memory, instead of java byte[] + private final int mNativeAllocationByteCount; + + BitmapFinalizer(long nativeBitmap, int nativeAllocationByteCount) { mNativeBitmap = nativeBitmap; + mNativeAllocationByteCount = nativeAllocationByteCount; + + if (mNativeAllocationByteCount != 0) { + VMRuntime.getRuntime().registerNativeAllocation(mNativeAllocationByteCount); + } } @Override @@ -1585,6 +1598,9 @@ public final class Bitmap implements Parcelable { } catch (Throwable t) { // Ignore } finally { + if (mNativeAllocationByteCount != 0) { + VMRuntime.getRuntime().registerNativeFree(mNativeAllocationByteCount); + } nativeDestructor(mNativeBitmap); } } |