Add warning if an in-use Bitmap is reconfigured
Bug: 18928352
Also fix an issue around re-configure not properly handling
mPinnedCount in android::Bitmap
Change-Id: I1815b121f1474ad931060771bb1d52ef31d2aac7
diff --git a/native/graphics/jni/bitmap.cpp b/native/graphics/jni/bitmap.cpp
index 0521833..6d2de98 100644
--- a/native/graphics/jni/bitmap.cpp
+++ b/native/graphics/jni/bitmap.cpp
@@ -62,7 +62,7 @@
return ANDROID_BITMAP_RESULT_BAD_PARAMETER;
}
- SkPixelRef* pixelRef = GraphicsJNI::getSkPixelRef(env, jbitmap);
+ SkPixelRef* pixelRef = GraphicsJNI::refSkPixelRef(env, jbitmap);
if (!pixelRef) {
return ANDROID_BITMAP_RESULT_JNI_EXCEPTION;
}
@@ -71,9 +71,9 @@
void* addr = pixelRef->pixels();
if (NULL == addr) {
pixelRef->unlockPixels();
+ pixelRef->unref();
return ANDROID_BITMAP_RESULT_ALLOCATION_FAILED;
}
- pixelRef->ref();
if (addrPtr) {
*addrPtr = addr;
@@ -86,7 +86,7 @@
return ANDROID_BITMAP_RESULT_BAD_PARAMETER;
}
- SkPixelRef* pixelRef = GraphicsJNI::getSkPixelRef(env, jbitmap);
+ SkPixelRef* pixelRef = GraphicsJNI::refSkPixelRef(env, jbitmap);
if (!pixelRef) {
return ANDROID_BITMAP_RESULT_JNI_EXCEPTION;
}
@@ -98,6 +98,12 @@
pixelRef->notifyPixelsChanged();
pixelRef->unlockPixels();
+ // Awkward in that we need to double-unref as the call to get the SkPixelRef
+ // did a ref(), so we need to unref() for the local ref and for the previous
+ // AndroidBitmap_lockPixels(). However this keeps GraphicsJNI a bit safer
+ // if others start using it without knowing about android::Bitmap's "fun"
+ // ref counting mechanism(s).
+ pixelRef->unref();
pixelRef->unref();
return ANDROID_BITMAP_RESULT_SUCCESS;