Move registerCxxCompositor to FlexView
authorBenoit Girard <b56girard@gmail.com>
Wed, 01 Feb 2012 14:15:52 -0500
changeset 89050 280c07f00920d8803130ce55fece99af418ccd73
parent 89049 ed29c74e3c01fb33e6298ec69fc95988df9ace73
child 89051 e31cee42a32f05a9b69c439f78dfb4b401422127
push id22242
push userkgupta@mozilla.com
push dateWed, 14 Mar 2012 15:19:09 +0000
treeherdermozilla-central@936ef50fa498 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone12.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Move registerCxxCompositor to FlexView
mobile/android/base/Makefile.in
mobile/android/base/gfx/FlexibleGLSurfaceView.java
widget/android/AndroidBridge.cpp
widget/android/AndroidBridge.h
widget/android/AndroidJNI.cpp
widget/android/nsWindow.cpp
--- a/mobile/android/base/Makefile.in
+++ b/mobile/android/base/Makefile.in
@@ -128,17 +128,16 @@ FENNEC_JAVA_FILES = \
   gfx/RectUtils.java \
   gfx/ScrollbarLayer.java \
   gfx/SingleTileLayer.java \
   gfx/TextLayer.java \
   gfx/TextureReaper.java \
   gfx/TileLayer.java \
   gfx/ViewportMetrics.java \
   gfx/WidgetTileLayer.java \
-  gfx/layers/OGLSurfaceView.java \
   ui/Axis.java \
   ui/PanZoomController.java \
   ui/SimpleScaleGestureDetector.java \
   ui/SubdocumentScrollHelper.java \
   GeckoNetworkManager.java \
   $(NULL)
 
 ifdef MOZ_WEBSMS_BACKEND
--- a/mobile/android/base/gfx/FlexibleGLSurfaceView.java
+++ b/mobile/android/base/gfx/FlexibleGLSurfaceView.java
@@ -148,16 +148,50 @@ public class FlexibleGLSurfaceView exten
 
     public synchronized void surfaceDestroyed(SurfaceHolder holder) {
         mController.surfaceDestroyed();
         if (mGLThread != null) {
             mGLThread.surfaceDestroyed();
         }
     }
 
+    // Called from the compositor thread
+    public static GLController registerCxxCompositor() {
+        System.out.println("register layer comp");
+/*
+        synchronized (FlexibleGLSurfaceView.class) {
+            // Wait for the layer controller if by some miracle
+            // gecko beats the java thread here.
+            while (mLayerController == null) {
+                try {
+                    OGLSurfaceView.class.wait();
+                } catch (InterruptedException e) {}
+            }
+            final LayerController controller = mLayerController;
+
+            GeckoApp.mAppContext.runOnUiThread(new Runnable() {
+                public void run() {
+                    synchronized (OGLSurfaceView.class) {
+                        OGLSurfaceView surfaceView =
+                            new OGLSurfaceView(controller.getContext(), controller);
+                        OGLSurfaceView.class.notifyAll();
+                    }
+                }
+            });
+
+            // Wait for the compositor to be setup on the
+            // Java UI thread.
+            try {
+                OGLSurfaceView.class.wait();
+            } catch (InterruptedException e) {}
+        }
+*/
+        return null;
+    }
+
     public static class FlexibleGLSurfaceViewException extends RuntimeException {
         public static final long serialVersionUID = 1L;
 
         FlexibleGLSurfaceViewException(String e) {
             super(e);
         }
     }
 }
--- a/widget/android/AndroidBridge.cpp
+++ b/widget/android/AndroidBridge.cpp
@@ -169,17 +169,17 @@ AndroidBridge::Init(JNIEnv *jEnv,
 
     jEGLContextClass = (jclass) jEnv->NewGlobalRef(jEnv->FindClass("javax/microedition/khronos/egl/EGLContext"));
     jEGL10Class = (jclass) jEnv->NewGlobalRef(jEnv->FindClass("javax/microedition/khronos/egl/EGL10"));
     jEGLSurfaceImplClass = (jclass) jEnv->NewGlobalRef(jEnv->FindClass("com/google/android/gles_jni/EGLSurfaceImpl"));
     jEGLContextImplClass = (jclass) jEnv->NewGlobalRef(jEnv->FindClass("com/google/android/gles_jni/EGLContextImpl"));
     jEGLConfigImplClass = (jclass) jEnv->NewGlobalRef(jEnv->FindClass("com/google/android/gles_jni/EGLConfigImpl"));
     jEGLDisplayImplClass = (jclass) jEnv->NewGlobalRef(jEnv->FindClass("com/google/android/gles_jni/EGLDisplayImpl"));
 
-    jOGLSurfaceView = (jclass) jEnv->NewGlobalRef(jEnv->FindClass("org/mozilla/gecko/gfx/layers/OGLSurfaceView"));
+    jFlexSurfaceView = (jclass) jEnv->NewGlobalRef(jEnv->FindClass("org/mozilla/gecko/gfx/FlexibleGLSurfaceView"));
 
     InitAndroidJavaWrappers(jEnv);
 
     // jEnv should NOT be cached here by anything -- the jEnv here
     // is not valid for the real gecko main thread, which is set
     // at SetMainThread time.
 
     return true;
@@ -1019,21 +1019,24 @@ AndroidBridge::CallEglCreateWindowSurfac
 
     return (void*) realSurface;
 }
 
 void
 AndroidBridge::RegisterCompositor()
 {
     ALOG_BRIDGE("AndroidBridge::RegisterCompositor");
-    AutoLocalJNIFrame jniFrame(GetJNIForThread());
+    JNIEnv *env = GetJNIForThread();
+    if (!env)
+        return;
 
-    jmethodID registerCompositor = GetJNIForThread()->GetStaticMethodID(jOGLSurfaceView, "registerCompositor", "()V");
+    AutoLocalJNIFrame jniFrame(env, 3);
+    jmethodID registerCompositor = env->GetStaticMethodID(jFlexSurfaceView, "registerCxxCompositor", "()Lorg/mozilla/gecko/gfx/GLController;");
 
-    GetJNIForThread()->CallStaticVoidMethod(jOGLSurfaceView, registerCompositor);
+    jobject glController = env->CallStaticObjectMethod(jFlexSurfaceView, registerCompositor);
 }
 
 bool
 AndroidBridge::GetStaticIntField(const char *className, const char *fieldName, PRInt32* aInt)
 {
     ALOG_BRIDGE("AndroidBridge::GetStaticIntField %s", fieldName);
     JNIEnv *env = GetJNIEnv();
     if (!env)
--- a/widget/android/AndroidBridge.h
+++ b/widget/android/AndroidBridge.h
@@ -481,17 +481,17 @@ protected:
     // stuff we need for CallEglCreateWindowSurface
     jclass jEGLSurfaceImplClass;
     jclass jEGLContextImplClass;
     jclass jEGLConfigImplClass;
     jclass jEGLDisplayImplClass;
     jclass jEGLContextClass;
     jclass jEGL10Class;
 
-    jclass jOGLSurfaceView;
+    jclass jFlexSurfaceView;
 
     // calls we've dlopened from libjnigraphics.so
     int (* AndroidBitmap_getInfo)(JNIEnv *env, jobject bitmap, void *info);
     int (* AndroidBitmap_lockPixels)(JNIEnv *env, jobject bitmap, void **buffer);
     int (* AndroidBitmap_unlockPixels)(JNIEnv *env, jobject bitmap);
 
     void* (*ANativeWindow_fromSurface)(JNIEnv *env, jobject surface);
     void (*ANativeWindow_release)(void *window);
--- a/widget/android/AndroidJNI.cpp
+++ b/widget/android/AndroidJNI.cpp
@@ -103,17 +103,16 @@ extern "C" {
     NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_notifyListCreated(JNIEnv* jenv, jclass, jint, jint, jstring, jstring, jstring, jlong, jint, jlong);
     NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_notifyGotNextMessage(JNIEnv* jenv, jclass, jint, jstring, jstring, jstring, jlong, jint, jlong);
     NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_notifyReadingMessageListFailed(JNIEnv* jenv, jclass, jint, jint, jlong);
 
 #ifdef MOZ_JAVA_COMPOSITOR
     NS_EXPORT void JNICALL Java_org_mozilla_gecko_GeckoAppShell_bindWidgetTexture(JNIEnv* jenv, jclass);
 #endif
 
-    NS_EXPORT void JNICALL Java_org_mozilla_gfx_layers_OGLSurfaceView_setSurfaceView(JNIEnv *jenv, jclass, jobject sv);
 }
 
 
 /*
  * Incoming JNI methods
  */
 
 NS_EXPORT void JNICALL
@@ -140,22 +139,16 @@ Java_org_mozilla_gecko_GeckoAppShell_pro
 
 NS_EXPORT void JNICALL
 Java_org_mozilla_gecko_GeckoAppShell_setSurfaceView(JNIEnv *jenv, jclass, jobject obj)
 {
     AndroidBridge::Bridge()->SetSurfaceView(jenv->NewGlobalRef(obj));
 }
 
 NS_EXPORT void JNICALL
-Java_org_mozilla_gfx_layers_OGLSurfaceView_setSurfaceView(JNIEnv *jenv, jclass, jobject obj)
-{
-    AndroidBridge::Bridge()->SetSurfaceView(jenv->NewGlobalRef(obj));
-}
-
-NS_EXPORT void JNICALL
 Java_org_mozilla_gecko_GeckoAppShell_setSoftwareLayerClient(JNIEnv *jenv, jclass, jobject obj)
 {
     AndroidBridge::Bridge()->SetSoftwareLayerClient(jenv->NewGlobalRef(obj));
 }
 
 NS_EXPORT void JNICALL
 Java_org_mozilla_gecko_GeckoAppShell_onLowMemory(JNIEnv *jenv, jclass jc)
 {
--- a/widget/android/nsWindow.cpp
+++ b/widget/android/nsWindow.cpp
@@ -765,33 +765,34 @@ nsWindow::GetLayerManager(PLayersChild*,
     nsWindow *topWindow = TopWindow();
 
     if (!topWindow) {
         printf_stderr(" -- no topwindow\n");
         mLayerManager = CreateBasicLayerManager();
         return mLayerManager;
     }
 
+    bool useCompositor =
+        Preferences::GetBool("layers.offmainthreadcomposition.enabled", false);
+
+    if (useCompositor) {
+        CreateCompositor();
+        sFailedToCreateGLContext = !mLayerManager;
+    }
+
     mUseAcceleratedRendering = GetShouldAccelerate();
 
     if (!mUseAcceleratedRendering ||
         sFailedToCreateGLContext)
     {
         printf_stderr(" -- creating basic, not accelerated\n");
         mLayerManager = CreateBasicLayerManager();
         return mLayerManager;
     }
 
-    bool useCompositor =
-        Preferences::GetBool("layers.offmainthreadcomposition.enabled", false);
-
-    if (useCompositor) {
-        CreateCompositor();
-    }
-
     if (!mLayerManager) {
         if (!sGLContext) {
             // the window we give doesn't matter here
             sGLContext = mozilla::gl::GLContextProvider::CreateForWindow(this);
         }
 
         if (sGLContext) {
                 nsRefPtr<mozilla::layers::LayerManagerOGL> layerManager =