diff options
Diffstat (limited to 'native/graphics')
-rw-r--r-- | native/graphics/jni/bitmap.cpp | 64 |
1 files changed, 6 insertions, 58 deletions
diff --git a/native/graphics/jni/bitmap.cpp b/native/graphics/jni/bitmap.cpp index 6d2de98759c8..bf5cabbe4bc2 100644 --- a/native/graphics/jni/bitmap.cpp +++ b/native/graphics/jni/bitmap.cpp @@ -15,11 +15,7 @@ */ #include <android/bitmap.h> - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-parameter" -#include <GraphicsJNI.h> -#pragma GCC diagnostic pop +#include <Bitmap.h> int AndroidBitmap_getInfo(JNIEnv* env, jobject jbitmap, AndroidBitmapInfo* info) { @@ -27,32 +23,8 @@ int AndroidBitmap_getInfo(JNIEnv* env, jobject jbitmap, return ANDROID_BITMAP_RESULT_BAD_PARAMETER; } - SkBitmap bm; - GraphicsJNI::getSkBitmap(env, jbitmap, &bm); - if (info) { - info->width = bm.width(); - info->height = bm.height(); - info->stride = bm.rowBytes(); - info->flags = 0; - - switch (bm.colorType()) { - case kN32_SkColorType: - info->format = ANDROID_BITMAP_FORMAT_RGBA_8888; - break; - case kRGB_565_SkColorType: - info->format = ANDROID_BITMAP_FORMAT_RGB_565; - break; - case kARGB_4444_SkColorType: - info->format = ANDROID_BITMAP_FORMAT_RGBA_4444; - break; - case kAlpha_8_SkColorType: - info->format = ANDROID_BITMAP_FORMAT_A_8; - break; - default: - info->format = ANDROID_BITMAP_FORMAT_NONE; - break; - } + android::bitmap::imageInfo(env, jbitmap, info); } return ANDROID_BITMAP_RESULT_SUCCESS; } @@ -62,19 +34,11 @@ int AndroidBitmap_lockPixels(JNIEnv* env, jobject jbitmap, void** addrPtr) { return ANDROID_BITMAP_RESULT_BAD_PARAMETER; } - SkPixelRef* pixelRef = GraphicsJNI::refSkPixelRef(env, jbitmap); - if (!pixelRef) { + void* addr = android::bitmap::lockPixels(env, jbitmap); + if (!addr) { return ANDROID_BITMAP_RESULT_JNI_EXCEPTION; } - pixelRef->lockPixels(); - void* addr = pixelRef->pixels(); - if (NULL == addr) { - pixelRef->unlockPixels(); - pixelRef->unref(); - return ANDROID_BITMAP_RESULT_ALLOCATION_FAILED; - } - if (addrPtr) { *addrPtr = addr; } @@ -86,26 +50,10 @@ int AndroidBitmap_unlockPixels(JNIEnv* env, jobject jbitmap) { return ANDROID_BITMAP_RESULT_BAD_PARAMETER; } - SkPixelRef* pixelRef = GraphicsJNI::refSkPixelRef(env, jbitmap); - if (!pixelRef) { + bool unlocked = android::bitmap::unlockPixels(env, jbitmap); + if (!unlocked) { return ANDROID_BITMAP_RESULT_JNI_EXCEPTION; } - - // notifyPixelsChanged() needs be called to apply writes to GL-backed - // 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. - pixelRef->notifyPixelsChanged(); - - pixelRef->unlockPixels(); - // Awkward in that we need to double-unref as the call to get the SkPixelRef - // did a ref(), so we need to unref() for the local ref and for the previous - // AndroidBitmap_lockPixels(). However this keeps GraphicsJNI a bit safer - // if others start using it without knowing about android::Bitmap's "fun" - // ref counting mechanism(s). - pixelRef->unref(); - pixelRef->unref(); - return ANDROID_BITMAP_RESULT_SUCCESS; } |