Cleanup Bitmap#recycle
Test: Build, CTS
mNativePtr can never be 0 (it is final, and the constructor prevents
setting it to 0), so do not check for it. nativeRecycle only ever
returns true, so make it return void.
Change-Id: Ib94c0304ca7303d6899f085e64be7c051908d173
diff --git a/core/jni/android/graphics/Bitmap.cpp b/core/jni/android/graphics/Bitmap.cpp
index 7352324..4f318ff3 100755
--- a/core/jni/android/graphics/Bitmap.cpp
+++ b/core/jni/android/graphics/Bitmap.cpp
@@ -851,10 +851,9 @@
return static_cast<jlong>(reinterpret_cast<uintptr_t>(&Bitmap_destruct));
}
-static jboolean Bitmap_recycle(JNIEnv* env, jobject, jlong bitmapHandle) {
+static void Bitmap_recycle(JNIEnv* env, jobject, jlong bitmapHandle) {
LocalScopedBitmap bitmap(bitmapHandle);
bitmap->freePixels();
- return JNI_TRUE;
}
static void Bitmap_reconfigure(JNIEnv* env, jobject clazz, jlong bitmapHandle,
@@ -1600,7 +1599,7 @@
{ "nativeCopyAshmemConfig", "(JI)Landroid/graphics/Bitmap;",
(void*)Bitmap_copyAshmemConfig },
{ "nativeGetNativeFinalizer", "()J", (void*)Bitmap_getNativeFinalizer },
- { "nativeRecycle", "(J)Z", (void*)Bitmap_recycle },
+ { "nativeRecycle", "(J)V", (void*)Bitmap_recycle },
{ "nativeReconfigure", "(JIIIZ)V", (void*)Bitmap_reconfigure },
{ "nativeCompress", "(JIILjava/io/OutputStream;[B)Z",
(void*)Bitmap_compress },
diff --git a/graphics/java/android/graphics/Bitmap.java b/graphics/java/android/graphics/Bitmap.java
index d6c119f..0ff958f 100644
--- a/graphics/java/android/graphics/Bitmap.java
+++ b/graphics/java/android/graphics/Bitmap.java
@@ -344,14 +344,9 @@
* there are no more references to this bitmap.
*/
public void recycle() {
- if (!mRecycled && mNativePtr != 0) {
- if (nativeRecycle(mNativePtr)) {
- // return value indicates whether native pixel object was actually recycled.
- // false indicates that it is still in use at the native level and these
- // objects should not be collected now. They will be collected later when the
- // Bitmap itself is collected.
- mNinePatchChunk = null;
- }
+ if (!mRecycled) {
+ nativeRecycle(mNativePtr);
+ mNinePatchChunk = null;
mRecycled = true;
}
}
@@ -2052,7 +2047,7 @@
private static native Bitmap nativeCopyAshmem(long nativeSrcBitmap);
private static native Bitmap nativeCopyAshmemConfig(long nativeSrcBitmap, int nativeConfig);
private static native long nativeGetNativeFinalizer();
- private static native boolean nativeRecycle(long nativeBitmap);
+ private static native void nativeRecycle(long nativeBitmap);
private static native void nativeReconfigure(long nativeBitmap, int width, int height,
int config, boolean isPremultiplied);