From 64eea5d6972d2018954858c04283cbe58c12069a Mon Sep 17 00:00:00 2001 From: Brad Lassey Date: Fri, 16 Nov 2012 12:13:57 -0800 Subject: [PATCH] bug 812594 - PushLocalFrame in AutoLocalJNIFrame::Push taking more than 100ms when called from AndroidGeckoLayerClient::ProgressiveUpdateCallback on a Samsung Galaxy Q r=kats --HG-- extra : rebase_source : 4aba48c1c6c784f098ffa9bcc05006a054f9ab14 --- widget/android/AndroidBridge.h | 34 ++++++++++++++++++++++++++ widget/android/AndroidJavaWrappers.cpp | 23 ++++++++--------- 2 files changed, 46 insertions(+), 11 deletions(-) diff --git a/widget/android/AndroidBridge.h b/widget/android/AndroidBridge.h index b09955f8b9e..639ecb39d2b 100644 --- a/widget/android/AndroidBridge.h +++ b/widget/android/AndroidBridge.h @@ -539,6 +539,40 @@ protected: void (* Region_set)(void* region, void* rect); }; +class AutoJObject { +public: + AutoJObject(JNIEnv* aJNIEnv = NULL) : mObject(NULL) + { + mJNIEnv = aJNIEnv ? aJNIEnv : AndroidBridge::GetJNIEnv(); + } + + AutoJObject(JNIEnv* aJNIEnv, jobject aObject) + { + mJNIEnv = aJNIEnv ? aJNIEnv : AndroidBridge::GetJNIEnv(); + mObject = aObject; + } + + ~AutoJObject() { + if (mObject) + mJNIEnv->DeleteLocalRef(mObject); + } + + jobject operator=(jobject aObject) + { + if (mObject) { + mJNIEnv->DeleteLocalRef(mObject); + } + return mObject = aObject; + } + + operator jobject() { + return mObject; + } +private: + JNIEnv* mJNIEnv; + jobject mObject; +}; + class AutoLocalJNIFrame { public: AutoLocalJNIFrame(int nEntries = 128) diff --git a/widget/android/AndroidJavaWrappers.cpp b/widget/android/AndroidJavaWrappers.cpp index ab5b94900ca..a07efdb94b5 100644 --- a/widget/android/AndroidJavaWrappers.cpp +++ b/widget/android/AndroidJavaWrappers.cpp @@ -861,18 +861,19 @@ AndroidGeckoLayerClient::ProgressiveUpdateCallback(bool aHasPendingNewThebesCont if (!env) return false; - AutoLocalJNIFrame jniFrame(env); - - jobject progressiveUpdateDataJObj = env->CallObjectMethod(wrapped_obj, - jProgressiveUpdateCallbackMethod, - aHasPendingNewThebesContent, - (float)aDisplayPort.x, - (float)aDisplayPort.y, - (float)aDisplayPort.width, - (float)aDisplayPort.height, - aDisplayResolution); - if (jniFrame.CheckForException()) + AutoJObject progressiveUpdateDataJObj(env, env->CallObjectMethod(wrapped_obj, + jProgressiveUpdateCallbackMethod, + aHasPendingNewThebesContent, + (float)aDisplayPort.x, + (float)aDisplayPort.y, + (float)aDisplayPort.width, + (float)aDisplayPort.height, + aDisplayResolution)); + if (env->ExceptionCheck()) { + env->ExceptionDescribe(); + env->ExceptionClear(); return false; + } NS_ABORT_IF_FALSE(progressiveUpdateDataJObj, "No progressive update data!");