diff options
author | John Reck <jreck@google.com> | 2015-04-10 13:52:57 -0700 |
---|---|---|
committer | John Reck <jreck@google.com> | 2015-04-13 09:50:42 -0700 |
commit | a771b9861d11671c780092d35c0062eeefcf37c0 (patch) | |
tree | a575dc870712330cb8ddc70b5dccd0df26806a6a /native | |
parent | 4147877b388eb4a6f4e1ee116edfa58a018891ca (diff) | |
download | frameworks_base-a771b9861d11671c780092d35c0062eeefcf37c0.zip frameworks_base-a771b9861d11671c780092d35c0062eeefcf37c0.tar.gz frameworks_base-a771b9861d11671c780092d35c0062eeefcf37c0.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
Change-Id: I0fd9e193968b41e5597784140d56b4885906864a
Diffstat (limited to 'native')
-rw-r--r-- | native/graphics/jni/bitmap.cpp | 35 |
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; } |