diff options
author | Chris Craik <ccraik@google.com> | 2013-09-10 17:18:04 -0700 |
---|---|---|
committer | Chris Craik <ccraik@google.com> | 2013-09-10 18:13:48 -0700 |
commit | 28a1222bafbc5b3124cc8a5c400024c037047699 (patch) | |
tree | 1233ede2e42ada57c90036d46b7786ef4fed1d34 /core | |
parent | cd0ba71aa942f35fcdb26808b86f20073b8aff92 (diff) | |
download | frameworks_base-28a1222bafbc5b3124cc8a5c400024c037047699.zip frameworks_base-28a1222bafbc5b3124cc8a5c400024c037047699.tar.gz frameworks_base-28a1222bafbc5b3124cc8a5c400024c037047699.tar.bz2 |
Avoid ref-ing AndroidPixelRefs that wrap others in globalRef/Unref
bug:10691404
Only ref the wrapped pixel refs, so that they are the single source of
correct refcount, since the wrapping pixel ref can change out from
underneath an SkBitmap.
Change-Id: I253b8737d2afdcc567a26725fa40b1d9ef0e6a92
Diffstat (limited to 'core')
-rw-r--r-- | core/jni/android/graphics/Graphics.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/core/jni/android/graphics/Graphics.cpp b/core/jni/android/graphics/Graphics.cpp index 1ff0d63..8cb152d 100644 --- a/core/jni/android/graphics/Graphics.cpp +++ b/core/jni/android/graphics/Graphics.cpp @@ -479,7 +479,13 @@ void AndroidPixelRef::globalRef(void* localref) { if (fWrappedPixelRef) { // delegate java obj management to the wrapped ref fWrappedPixelRef->globalRef(localref); - } else if (fOnJavaHeap && sk_atomic_inc(&fGlobalRefCnt) == 0) { + + // Note: we only ref and unref the wrapped AndroidPixelRef so that + // bitmap->pixelRef()->globalRef() and globalUnref() can be used in a pair, even if + // the bitmap has its underlying AndroidPixelRef swapped out/wrapped + return; + } + if (fOnJavaHeap && sk_atomic_inc(&fGlobalRefCnt) == 0) { JNIEnv *env = vm2env(fVM); // If JNI ref was passed, it is always used @@ -506,7 +512,9 @@ void AndroidPixelRef::globalUnref() { if (fWrappedPixelRef) { // delegate java obj management to the wrapped ref fWrappedPixelRef->globalUnref(); - } else if (fOnJavaHeap && sk_atomic_dec(&fGlobalRefCnt) == 1) { + return; + } + if (fOnJavaHeap && sk_atomic_dec(&fGlobalRefCnt) == 1) { JNIEnv *env = vm2env(fVM); if (!fHasGlobalRef) { SkDebugf("We don't have a global ref!"); |