Bug 748531 - Propagate the JNIEnv through DrawWindow*lay helpers instead of unnecessarily re-calling GetJNIForThread everywhere. r=blassey

This commit is contained in:
Kartikaya Gupta 2012-05-04 11:08:46 -04:00
Родитель c9ba70055f
Коммит f1210a54dd
3 изменённых файлов: 44 добавлений и 77 удалений

Просмотреть файл

@ -587,23 +587,23 @@ AndroidGeckoLayerClient::Init(jobject jobj)
}
void
AndroidLayerRendererFrame::Init(jobject jobj)
AndroidLayerRendererFrame::Init(JNIEnv *env, jobject jobj)
{
if (!isNull()) {
Dispose();
Dispose(env);
}
wrapped_obj = GetJNIForThread()->NewGlobalRef(jobj);
wrapped_obj = env->NewGlobalRef(jobj);
}
void
AndroidLayerRendererFrame::Dispose()
AndroidLayerRendererFrame::Dispose(JNIEnv *env)
{
if (isNull()) {
return;
}
GetJNIForThread()->DeleteGlobalRef(wrapped_obj);
env->DeleteGlobalRef(wrapped_obj);
wrapped_obj = 0;
}
@ -754,88 +754,46 @@ AndroidGeckoSurfaceView::GetSurfaceHolder()
}
void
AndroidGeckoLayerClient::CreateFrame(AndroidLayerRendererFrame& aFrame)
AndroidGeckoLayerClient::CreateFrame(JNIEnv *env, AndroidLayerRendererFrame& aFrame)
{
JNIEnv *env = GetJNIForThread();
NS_ABORT_IF_FALSE(env, "No JNI environment at CreateFrame()!");
if (!env) {
return;
}
jobject frameJObj = env->CallObjectMethod(wrapped_obj, jCreateFrameMethod);
NS_ABORT_IF_FALSE(frameJObj, "No frame object!");
aFrame.Init(frameJObj);
aFrame.Init(env, frameJObj);
}
void
AndroidGeckoLayerClient::ActivateProgram()
AndroidGeckoLayerClient::ActivateProgram(JNIEnv *env)
{
JNIEnv *env = GetJNIForThread();
NS_ABORT_IF_FALSE(env, "No JNI environment at ActivateProgram()!");
if (!env) {
return;
}
env->CallVoidMethod(wrapped_obj, jActivateProgramMethod);
}
void
AndroidGeckoLayerClient::DeactivateProgram()
AndroidGeckoLayerClient::DeactivateProgram(JNIEnv *env)
{
JNIEnv *env = GetJNIForThread();
NS_ABORT_IF_FALSE(env, "No JNI environment at DeactivateProgram()!");
if (!env) {
return;
}
env->CallVoidMethod(wrapped_obj, jDeactivateProgramMethod);
}
void
AndroidLayerRendererFrame::BeginDrawing()
AndroidLayerRendererFrame::BeginDrawing(JNIEnv *env)
{
JNIEnv *env = GetJNIForThread();
NS_ABORT_IF_FALSE(env, "No JNI environment at BeginDrawing()!");
if (!env) {
return;
}
env->CallVoidMethod(wrapped_obj, jBeginDrawingMethod);
}
void
AndroidLayerRendererFrame::DrawBackground()
AndroidLayerRendererFrame::DrawBackground(JNIEnv *env)
{
JNIEnv *env = GetJNIForThread();
NS_ABORT_IF_FALSE(env, "No JNI environment at DrawBackground()!");
if (!env) {
return;
}
env->CallVoidMethod(wrapped_obj, jDrawBackgroundMethod);
}
void
AndroidLayerRendererFrame::DrawForeground()
AndroidLayerRendererFrame::DrawForeground(JNIEnv *env)
{
JNIEnv *env = GetJNIForThread();
NS_ABORT_IF_FALSE(env, "No JNI environment at DrawForeground()!");
if (!env) {
return;
}
env->CallVoidMethod(wrapped_obj, jDrawForegroundMethod);
}
void
AndroidLayerRendererFrame::EndDrawing()
AndroidLayerRendererFrame::EndDrawing(JNIEnv *env)
{
JNIEnv *env = GetJNIForThread();
NS_ABORT_IF_FALSE(env, "No JNI environment at EndDrawing()!");
if (!env) {
return;
}
env->CallVoidMethod(wrapped_obj, jEndDrawingMethod);
}

Просмотреть файл

@ -177,13 +177,13 @@ class AndroidLayerRendererFrame : public WrappedJavaObject {
public:
static void InitLayerRendererFrameClass(JNIEnv *jEnv);
void Init(jobject jobj);
void Dispose();
void Init(JNIEnv *env, jobject jobj);
void Dispose(JNIEnv *env);
void BeginDrawing();
void DrawBackground();
void DrawForeground();
void EndDrawing();
void BeginDrawing(JNIEnv *env);
void DrawBackground(JNIEnv *env);
void DrawForeground(JNIEnv *env);
void EndDrawing(JNIEnv *env);
private:
static jclass jLayerRendererFrameClass;
@ -207,9 +207,9 @@ public:
void SetPageSize(float aZoom, float aPageWidth, float aPageHeight, float aCssPageWidth, float aCssPageHeight);
void SyncViewportInfo(const nsIntRect& aDisplayPort, float aDisplayResolution, bool aLayersUpdated,
nsIntPoint& aScrollOffset, float& aScaleX, float& aScaleY);
void CreateFrame(AndroidLayerRendererFrame& aFrame);
void ActivateProgram();
void DeactivateProgram();
void CreateFrame(JNIEnv *env, AndroidLayerRendererFrame& aFrame);
void ActivateProgram(JNIEnv *env);
void DeactivateProgram(JNIEnv *env);
protected:
static jclass jGeckoLayerClientClass;

Просмотреть файл

@ -2220,31 +2220,40 @@ nsWindow::GetIMEUpdatePreference()
#ifdef MOZ_JAVA_COMPOSITOR
void
nsWindow::DrawWindowUnderlay(LayerManager* aManager, nsIntRect aRect) {
AndroidBridge::AutoLocalJNIFrame jniFrame(GetJNIForThread());
JNIEnv *env = GetJNIForThread();
NS_ABORT_IF_FALSE(env, "No JNI environment at DrawWindowUnderlay()!");
if (!env)
return;
AndroidBridge::AutoLocalJNIFrame jniFrame(env);
AndroidGeckoLayerClient& client = AndroidBridge::Bridge()->GetLayerClient();
client.CreateFrame(mLayerRendererFrame);
client.ActivateProgram();
mLayerRendererFrame.BeginDrawing();
mLayerRendererFrame.DrawBackground();
client.DeactivateProgram();
client.CreateFrame(env, mLayerRendererFrame);
client.ActivateProgram(env);
mLayerRendererFrame.BeginDrawing(env);
mLayerRendererFrame.DrawBackground(env);
client.DeactivateProgram(env);
}
void
nsWindow::DrawWindowOverlay(LayerManager* aManager, nsIntRect aRect) {
AndroidBridge::AutoLocalJNIFrame jniFrame(GetJNIForThread());
JNIEnv *env = GetJNIForThread();
NS_ABORT_IF_FALSE(env, "No JNI environment at DrawWindowOverlay()!");
if (!env)
return;
AndroidBridge::AutoLocalJNIFrame jniFrame(env);
NS_ABORT_IF_FALSE(!mLayerRendererFrame.isNull(),
"Frame should have been created in DrawWindowUnderlay()!");
AndroidGeckoLayerClient& client = AndroidBridge::Bridge()->GetLayerClient();
client.ActivateProgram();
mLayerRendererFrame.DrawForeground();
mLayerRendererFrame.EndDrawing();
client.DeactivateProgram();
client.ActivateProgram(env);
mLayerRendererFrame.DrawForeground(env);
mLayerRendererFrame.EndDrawing(env);
client.DeactivateProgram(env);
mLayerRendererFrame.Dispose();
mLayerRendererFrame.Dispose(env);
}
// off-main-thread compositor fields and functions