summaryrefslogtreecommitdiffstats
path: root/native
diff options
context:
space:
mode:
authorJohn Reck <jreck@google.com>2015-04-10 13:52:57 -0700
committerJohn Reck <jreck@google.com>2015-04-30 12:46:57 -0700
commited207b92747234eac88dd3664ecfb535e45d8ed1 (patch)
tree1dbef1ad7b0dc01fbcbb2da189c6824005153c4e /native
parentb77a7551121561f4ea7d5ce0c4030aeb7ce709e8 (diff)
downloadframeworks_base-ed207b92747234eac88dd3664ecfb535e45d8ed1.zip
frameworks_base-ed207b92747234eac88dd3664ecfb535e45d8ed1.tar.gz
frameworks_base-ed207b92747234eac88dd3664ecfb535e45d8ed1.tar.bz2
Change how Java Bitmaps are accessed in a few places
Stop assuming that a Java Bitmap has a SkBitmap* that has some externally managed lifecycle, and instead switch a bunch of users to accessing the bitmap by providing their own SkBitmap* on which to set the (ref counted!) SkPixelRef* instead Attempt #2 to land this, original issue was in getSkBitmap and should be fixed Change-Id: I0fd9e193968b41e5597784140d56b4885906864a
Diffstat (limited to 'native')
-rw-r--r--native/graphics/jni/bitmap.cpp35
1 files changed, 18 insertions, 17 deletions
diff --git a/native/graphics/jni/bitmap.cpp b/native/graphics/jni/bitmap.cpp
index ddb01a0..0521833 100644
--- a/native/graphics/jni/bitmap.cpp
+++ b/native/graphics/jni/bitmap.cpp
@@ -27,18 +27,16 @@ int AndroidBitmap_getInfo(JNIEnv* env, jobject jbitmap,
return ANDROID_BITMAP_RESULT_BAD_PARAMETER;
}
- SkBitmap* bm = GraphicsJNI::getSkBitmap(env, jbitmap);
- if (NULL == bm) {
- return ANDROID_BITMAP_RESULT_JNI_EXCEPTION;
- }
+ SkBitmap bm;
+ GraphicsJNI::getSkBitmap(env, jbitmap, &bm);
if (info) {
- info->width = bm->width();
- info->height = bm->height();
- info->stride = bm->rowBytes();
+ info->width = bm.width();
+ info->height = bm.height();
+ info->stride = bm.rowBytes();
info->flags = 0;
- switch (bm->colorType()) {
+ switch (bm.colorType()) {
case kN32_SkColorType:
info->format = ANDROID_BITMAP_FORMAT_RGBA_8888;
break;
@@ -64,17 +62,18 @@ int AndroidBitmap_lockPixels(JNIEnv* env, jobject jbitmap, void** addrPtr) {
return ANDROID_BITMAP_RESULT_BAD_PARAMETER;
}
- SkBitmap* bm = GraphicsJNI::getSkBitmap(env, jbitmap);
- if (NULL == bm) {
+ SkPixelRef* pixelRef = GraphicsJNI::getSkPixelRef(env, jbitmap);
+ if (!pixelRef) {
return ANDROID_BITMAP_RESULT_JNI_EXCEPTION;
}
- bm->lockPixels();
- void* addr = bm->getPixels();
+ pixelRef->lockPixels();
+ void* addr = pixelRef->pixels();
if (NULL == addr) {
- bm->unlockPixels();
+ pixelRef->unlockPixels();
return ANDROID_BITMAP_RESULT_ALLOCATION_FAILED;
}
+ pixelRef->ref();
if (addrPtr) {
*addrPtr = addr;
@@ -87,8 +86,8 @@ int AndroidBitmap_unlockPixels(JNIEnv* env, jobject jbitmap) {
return ANDROID_BITMAP_RESULT_BAD_PARAMETER;
}
- SkBitmap* bm = GraphicsJNI::getSkBitmap(env, jbitmap);
- if (NULL == bm) {
+ SkPixelRef* pixelRef = GraphicsJNI::getSkPixelRef(env, jbitmap);
+ if (!pixelRef) {
return ANDROID_BITMAP_RESULT_JNI_EXCEPTION;
}
@@ -96,9 +95,11 @@ int AndroidBitmap_unlockPixels(JNIEnv* env, jobject jbitmap) {
// bitmaps. Note that this will slow down read-only accesses to the
// bitmaps, but the NDK methods are primarily intended to be used for
// writes.
- bm->notifyPixelsChanged();
+ pixelRef->notifyPixelsChanged();
+
+ pixelRef->unlockPixels();
+ pixelRef->unref();
- bm->unlockPixels();
return ANDROID_BITMAP_RESULT_SUCCESS;
}