summaryrefslogtreecommitdiffstats
path: root/native
diff options
context:
space:
mode:
authorJohn Reck <jreck@google.com>2015-05-06 14:55:05 -0700
committerJohn Reck <jreck@google.com>2015-05-06 15:30:16 -0700
commitae2e8b4891491e8e89bed5f2c9626415adee09cb (patch)
tree13904c288c850c7bdc6d3fa3e38f1a477763d40e /native
parentfbb34dd8df7bc89ae972c545130e76c5bbb4176e (diff)
downloadframeworks_base-ae2e8b4891491e8e89bed5f2c9626415adee09cb.zip
frameworks_base-ae2e8b4891491e8e89bed5f2c9626415adee09cb.tar.gz
frameworks_base-ae2e8b4891491e8e89bed5f2c9626415adee09cb.tar.bz2
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
Diffstat (limited to 'native')
-rw-r--r--native/graphics/jni/bitmap.cpp12
1 files changed, 9 insertions, 3 deletions
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 @@ int AndroidBitmap_lockPixels(JNIEnv* env, jobject jbitmap, void** addrPtr) {
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 @@ int AndroidBitmap_lockPixels(JNIEnv* env, jobject jbitmap, void** addrPtr) {
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 @@ int AndroidBitmap_unlockPixels(JNIEnv* env, jobject jbitmap) {
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 @@ int AndroidBitmap_unlockPixels(JNIEnv* env, jobject jbitmap) {
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;