diff options
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; } |