diff --git a/core/jni/android/graphics/Graphics.cpp b/core/jni/android/graphics/Graphics.cpp index 6c28e65e11f75..64bd20775ac1d 100644 --- a/core/jni/android/graphics/Graphics.cpp +++ b/core/jni/android/graphics/Graphics.cpp @@ -350,14 +350,10 @@ jobject GraphicsJNI::createBitmap(JNIEnv* env, SkBitmap* bitmap, jbyteArray buff SkASSERT(bitmap); SkASSERT(bitmap->pixelRef()); - jobject obj = env->AllocObject(gBitmap_class); - if (obj) { - env->CallVoidMethod(obj, gBitmap_constructorMethodID, - (jint)bitmap, buffer, isMutable, ninepatch, density); - if (hasException(env)) { - obj = NULL; - } - } + jobject obj = env->NewObject(gBitmap_class, gBitmap_constructorMethodID, + static_cast(reinterpret_cast(bitmap)), + buffer, isMutable, ninepatch, density); + hasException(env); // For the side effect of logging. return obj; } @@ -372,30 +368,19 @@ jobject GraphicsJNI::createBitmapRegionDecoder(JNIEnv* env, SkBitmapRegionDecode { SkASSERT(bitmap != NULL); - jobject obj = env->AllocObject(gBitmapRegionDecoder_class); - if (hasException(env)) { - obj = NULL; - return obj; - } - if (obj) { - env->CallVoidMethod(obj, gBitmapRegionDecoder_constructorMethodID, (jint)bitmap); - if (hasException(env)) { - obj = NULL; - } - } + jobject obj = env->NewObject(gBitmapRegionDecoder_class, + gBitmapRegionDecoder_constructorMethodID, + static_cast(reinterpret_cast(bitmap))); + hasException(env); // For the side effect of logging. return obj; } jobject GraphicsJNI::createRegion(JNIEnv* env, SkRegion* region) { SkASSERT(region != NULL); - jobject obj = env->AllocObject(gRegion_class); - if (obj) { - env->CallVoidMethod(obj, gRegion_constructorMethodID, (jint)region, 0); - if (hasException(env)) { - obj = NULL; - } - } + jobject obj = env->NewObject(gRegion_class, gRegion_constructorMethodID, + static_cast(reinterpret_cast(region)), 0); + hasException(env); // For the side effect of logging. return obj; } diff --git a/core/jni/android/graphics/Movie.cpp b/core/jni/android/graphics/Movie.cpp index 7145433990033..c112423838141 100644 --- a/core/jni/android/graphics/Movie.cpp +++ b/core/jni/android/graphics/Movie.cpp @@ -23,11 +23,8 @@ jobject create_jmovie(JNIEnv* env, SkMovie* moov) { if (NULL == moov) { return NULL; } - jobject obj = env->AllocObject(gMovie_class); - if (obj) { - env->CallVoidMethod(obj, gMovie_constructorMethodID, (jint)moov); - } - return obj; + return env->NewObject(gMovie_class, gMovie_constructorMethodID, + static_cast(reinterpret_cast(moov))); } static SkMovie* J2Movie(JNIEnv* env, jobject movie) { diff --git a/core/jni/android_emoji_EmojiFactory.cpp b/core/jni/android_emoji_EmojiFactory.cpp index 56859b8d905ab..81dae88c1e115 100644 --- a/core/jni/android_emoji_EmojiFactory.cpp +++ b/core/jni/android_emoji_EmojiFactory.cpp @@ -106,15 +106,11 @@ static void InitializeCaller() { static jobject create_java_EmojiFactory( JNIEnv* env, EmojiFactory* factory, jstring name) { - jobject obj = env->AllocObject(gEmojiFactory_class); - if (obj) { - env->CallVoidMethod(obj, gEmojiFactory_constructorMethodID, - (jint)factory, name); - if (env->ExceptionCheck() != 0) { - LOGE("*** Uncaught exception returned from Java call!\n"); - env->ExceptionDescribe(); - obj = NULL; - } + jobject obj = env->NewObject(gEmojiFactory_class, gEmojiFactory_constructorMethodID, + static_cast(reinterpret_cast(factory)), name); + if (env->ExceptionCheck() != 0) { + LOGE("*** Uncaught exception returned from Java call!\n"); + env->ExceptionDescribe(); } return obj; } @@ -180,17 +176,12 @@ static jobject android_emoji_EmojiFactory_getBitmapFromAndroidPua( return NULL; } - jobject obj = env->AllocObject(gBitmap_class); - if (obj) { - env->CallVoidMethod(obj, gBitmap_constructorMethodID, - reinterpret_cast(bitmap), NULL, false, NULL, -1); - if (env->ExceptionCheck() != 0) { - LOGE("*** Uncaught exception returned from Java call!\n"); - env->ExceptionDescribe(); - return NULL; - } + jobject obj = env->NewObject(gBitmap_class, gBitmap_constructorMethodID, + static_cast(reinterpret_cast(bitmap)), NULL, false, NULL, -1); + if (env->ExceptionCheck() != 0) { + LOGE("*** Uncaught exception returned from Java call!\n"); + env->ExceptionDescribe(); } - return obj; }