Merge "Don't allocate a raw object then call its constructor manually..."

This commit is contained in:
Elliott Hughes
2011-04-13 10:17:46 -07:00
committed by Android (Google) Code Review
3 changed files with 23 additions and 50 deletions

View File

@@ -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<jint>(reinterpret_cast<uintptr_t>(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<jint>(reinterpret_cast<uintptr_t>(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<jint>(reinterpret_cast<uintptr_t>(region)), 0);
hasException(env); // For the side effect of logging.
return obj;
}

View File

@@ -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<jint>(reinterpret_cast<uintptr_t>(moov)));
}
static SkMovie* J2Movie(JNIEnv* env, jobject movie) {

View File

@@ -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<jint>(reinterpret_cast<uintptr_t>(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<jint>(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<jint>(reinterpret_cast<uintptr_t>(bitmap)), NULL, false, NULL, -1);
if (env->ExceptionCheck() != 0) {
LOGE("*** Uncaught exception returned from Java call!\n");
env->ExceptionDescribe();
}
return obj;
}