diff options
Diffstat (limited to 'native')
-rw-r--r-- | native/graphics/jni/bitmap.cpp | 12 |
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; |