From ed207b92747234eac88dd3664ecfb535e45d8ed1 Mon Sep 17 00:00:00 2001 From: John Reck Date: Fri, 10 Apr 2015 13:52:57 -0700 Subject: 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 --- native/graphics/jni/bitmap.cpp | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'native') 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; } -- cgit v1.1