Bug 844275 - Fold the carcass of AndroidLayerView* into AndroidBridge. r=Cwiiis
authorKartikaya Gupta <kgupta@mozilla.com>
Thu, 28 Feb 2013 13:28:24 -0500
changeset 133768 c1bcca41d5518164f3e756a9f740b8ec8b78e904
parent 133767 cd5fe1593b6f9856c481c230e7849ec1c4010394
child 133769 0d76808a48e997bd5b50fb70473f2bf94b1dedf8
push id2452
push userlsblakk@mozilla.com
push dateMon, 13 May 2013 16:59:38 +0000
treeherdermozilla-beta@d4b152d29d8d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersCwiiis
bugs844275
milestone22.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
Bug 844275 - Fold the carcass of AndroidLayerView* into AndroidBridge. r=Cwiiis
widget/android/AndroidBridge.cpp
widget/android/AndroidBridge.h
widget/android/AndroidLayerViewWrapper.cpp
widget/android/AndroidLayerViewWrapper.h
widget/android/Makefile.in
--- a/widget/android/AndroidBridge.cpp
+++ b/widget/android/AndroidBridge.cpp
@@ -89,16 +89,17 @@ AndroidBridge::Init(JNIEnv *jEnv,
 {
     ALOG_BRIDGE("AndroidBridge::Init");
     jEnv->GetJavaVM(&mJavaVM);
 
     AutoLocalJNIFrame jniFrame(jEnv);
 
     mJNIEnv = nullptr;
     mThread = nullptr;
+    mGLControllerObj = nullptr;
     mOpenedGraphicsLibraries = false;
     mHasNativeBitmapAccess = false;
     mHasNativeWindowAccess = false;
     mHasNativeWindowFallback = false;
 
     mGeckoAppShellClass = (jclass) jEnv->NewGlobalRef(jGeckoAppShellClass);
 
     jclass jAndroidSmsMessageClass = jEnv->FindClass("android/telephony/SmsMessage");
@@ -210,18 +211,26 @@ AndroidBridge::Init(JNIEnv *jEnv,
 
     jPumpMessageLoop = (jmethodID) jEnv->GetStaticMethodID(jGeckoAppShellClass, "pumpMessageLoop", "()Z");
 
     jAddPluginView = jEnv->GetStaticMethodID(jGeckoAppShellClass, "addPluginView", "(Landroid/view/View;IIIIZ)V");
     jRemovePluginView = jEnv->GetStaticMethodID(jGeckoAppShellClass, "removePluginView", "(Landroid/view/View;Z)V");
 
     jLayerView = (jclass) jEnv->NewGlobalRef(jEnv->FindClass("org/mozilla/gecko/gfx/LayerView"));
 
-    AndroidGLController::Init(jEnv);
-    AndroidEGLObject::Init(jEnv);
+    jclass glControllerClass = jEnv->FindClass("org/mozilla/gecko/gfx/GLController");
+    jProvideEGLSurfaceMethod = jEnv->GetMethodID(glControllerClass, "provideEGLSurface",
+                                                  "()Ljavax/microedition/khronos/egl/EGLSurface;");
+
+    jclass eglClass = jEnv->FindClass("com/google/android/gles_jni/EGLSurfaceImpl");
+    if (eglClass) {
+        jEGLSurfacePointerField = jEnv->GetFieldID(eglClass, "mEGLSurface", "I");
+    } else {
+        jEGLSurfacePointerField = 0;
+    }
 
     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;
@@ -1114,42 +1123,58 @@ AndroidBridge::ShowInputMethodPicker()
     JNIEnv *env = GetJNIEnv();
     if (!env)
         return;
 
     AutoLocalJNIFrame jniFrame(env, 0);
     env->CallStaticVoidMethod(mGeckoAppShellClass, jShowInputMethodPicker);
 }
 
-static AndroidGLController sController;
-
 void
 AndroidBridge::RegisterCompositor(JNIEnv *env)
 {
     ALOG_BRIDGE("AndroidBridge::RegisterCompositor");
-    if (!env)
+    if (mGLControllerObj) {
+        // we already have this set up, no need to do it again
+        return;
+    }
+
+    if (!env) {
         env = GetJNIForThread();    // called on the compositor thread
-    if (!env)
+    }
+    if (!env) {
         return;
+    }
 
     AutoLocalJNIFrame jniFrame(env);
 
     jmethodID registerCompositor = env->GetStaticMethodID(jLayerView, "registerCxxCompositor", "()Lorg/mozilla/gecko/gfx/GLController;");
 
     jobject glController = env->CallStaticObjectMethod(jLayerView, registerCompositor);
     if (jniFrame.CheckForException())
         return;
 
-    sController.Acquire(env, glController);
+    mGLControllerObj = env->NewGlobalRef(glController);
 }
 
 EGLSurface
 AndroidBridge::ProvideEGLSurface()
 {
-    return sController.ProvideEGLSurface();
+    if (!jEGLSurfacePointerField) {
+        return NULL;
+    }
+    MOZ_ASSERT(mGLControllerObj, "AndroidBridge::ProvideEGLSurface called with a null GL controller ref");
+
+    JNIEnv* env = GetJNIForThread(); // called on the compositor thread
+    AutoLocalJNIFrame jniFrame(env);
+    jobject eglSurface = env->CallObjectMethod(mGLControllerObj, jProvideEGLSurfaceMethod);
+    if (jniFrame.CheckForException() || !eglSurface)
+        return NULL;
+
+    return reinterpret_cast<EGLSurface>(env->GetIntField(eglSurface, jEGLSurfacePointerField));
 }
 
 bool
 AndroidBridge::GetStaticIntField(const char *className, const char *fieldName, int32_t* aInt, JNIEnv* env /* = nullptr */)
 {
     ALOG_BRIDGE("AndroidBridge::GetStaticIntField %s", fieldName);
 
     if (!env) {
--- a/widget/android/AndroidBridge.h
+++ b/widget/android/AndroidBridge.h
@@ -12,17 +12,16 @@
 #include <pthread.h>
 
 #include "nsCOMPtr.h"
 #include "nsCOMArray.h"
 #include "nsIRunnable.h"
 #include "nsIObserver.h"
 #include "nsThreadUtils.h"
 
-#include "AndroidLayerViewWrapper.h"
 #include "AndroidJavaWrappers.h"
 
 #include "nsIMutableArray.h"
 #include "nsIMIMEInfo.h"
 #include "nsColor.h"
 #include "gfxRect.h"
 
 #include "nsIAndroidBridge.h"
@@ -84,16 +83,18 @@ typedef struct AndroidSystemColors {
     nscolor textColorTertiaryInverse;
     nscolor textColorHighlight;
     nscolor colorForeground;
     nscolor colorBackground;
     nscolor panelColorForeground;
     nscolor panelColorBackground;
 } AndroidSystemColors;
 
+typedef void* EGLSurface;
+
 class nsFilePickerCallback : nsISupports {
 public:
     NS_DECL_ISUPPORTS
     virtual void handleResult(nsAString& filePath) = 0;
     nsFilePickerCallback() {}
 protected:
     virtual ~nsFilePickerCallback() {}
 };
@@ -492,17 +493,19 @@ protected:
     // for GfxInfo (gfx feature detection and blacklisting)
     jmethodID jGetGfxInfoData;
 
     // For native surface stuff
     jclass jSurfaceClass;
     jfieldID jSurfacePointerField;
 
     jclass jLayerView;
-    jmethodID jRegisterCompositorMethod;
+    jmethodID jProvideEGLSurfaceMethod;
+    jfieldID jEGLSurfacePointerField;
+    jobject mGLControllerObj;
 
     // some convinient types to have around
     jclass jStringClass;
 
     // 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);
deleted file mode 100644
--- a/widget/android/AndroidLayerViewWrapper.cpp
+++ /dev/null
@@ -1,62 +0,0 @@
-/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
-* This Source Code Form is subject to the terms of the Mozilla Public
-* License, v. 2.0. If a copy of the MPL was not distributed with this
-* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "AndroidLayerViewWrapper.h"
-#include "AndroidBridge.h"
-#include "nsDebug.h"
-
-using namespace mozilla;
-
-#define ASSERT_THREAD() \
-        NS_ASSERTION(pthread_self() == mThread, "Something is calling AndroidGLController from the wrong thread!")
-
-static jfieldID jEGLSurfacePointerField = 0;
-
-void AndroidEGLObject::Init(JNIEnv* aJEnv) {
-    AutoLocalJNIFrame jniFrame(aJEnv);
-
-    jclass jClass;
-    jClass = reinterpret_cast<jclass>
-        (aJEnv->NewGlobalRef(aJEnv->FindClass("com/google/android/gles_jni/EGLSurfaceImpl")));
-    if (!jClass)
-        return;
-
-    jEGLSurfacePointerField = aJEnv->GetFieldID(jClass, "mEGLSurface", "I");
-}
-
-jmethodID AndroidGLController::jProvideEGLSurfaceMethod = 0;
-
-void
-AndroidGLController::Init(JNIEnv* aJEnv)
-{
-    jclass jClass = reinterpret_cast<jclass>(aJEnv->NewGlobalRef(aJEnv->FindClass("org/mozilla/gecko/gfx/GLController")));
-
-    jProvideEGLSurfaceMethod = aJEnv->GetMethodID(jClass, "provideEGLSurface",
-                                                  "()Ljavax/microedition/khronos/egl/EGLSurface;");
-}
-
-void
-AndroidGLController::Acquire(JNIEnv* aJEnv, jobject aJObj)
-{
-    mJEnv = aJEnv;
-    mThread = pthread_self();
-    mJObj = aJEnv->NewGlobalRef(aJObj);
-}
-
-EGLSurface
-AndroidGLController::ProvideEGLSurface()
-{
-    ASSERT_THREAD();
-
-    if (!jEGLSurfacePointerField)
-        return NULL;
-
-    AutoLocalJNIFrame jniFrame(mJEnv);
-    jobject jObj = mJEnv->CallObjectMethod(mJObj, jProvideEGLSurfaceMethod);
-    if (jniFrame.CheckForException() || !jObj)
-        return NULL;
-
-    return reinterpret_cast<EGLSurface>(mJEnv->GetIntField(jObj, jEGLSurfacePointerField));
-}
deleted file mode 100644
--- a/widget/android/AndroidLayerViewWrapper.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
-* This Source Code Form is subject to the terms of the Mozilla Public
-* License, v. 2.0. If a copy of the MPL was not distributed with this
-* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef AndroidLayerViewWrapper_h__
-#define AndroidLayerViewWrapper_h__
-
-#include <jni.h>
-#include <pthread.h>
-
-class AndroidEGLObject {
-public:
-    static void Init(JNIEnv* aJEnv);
-};
-
-typedef void* EGLSurface;
-
-class AndroidGLController {
-public:
-    static void Init(JNIEnv* aJEnv);
-
-    void Acquire(JNIEnv* aJEnv, jobject aJObj);
-    EGLSurface ProvideEGLSurface();
-
-private:
-    static jmethodID jProvideEGLSurfaceMethod;
-
-    // the JNIEnv for the compositor thread
-    JNIEnv* mJEnv;
-    pthread_t mThread;
-    jobject mJObj;
-};
-
-#endif
-
--- a/widget/android/Makefile.in
+++ b/widget/android/Makefile.in
@@ -28,17 +28,16 @@ endif
 
 CPPSRCS	= \
 	GfxInfo.cpp \
 	nsWidgetFactory.cpp \
 	nsAppShell.cpp \
 	AndroidJavaWrappers.cpp \
 	AndroidBridge.cpp \
 	AndroidDirectTexture.cpp \
-	AndroidLayerViewWrapper.cpp \
 	AndroidGraphicBuffer.cpp \
 	AndroidJNI.cpp \
 	nsWindow.cpp \
 	nsLookAndFeel.cpp \
 	nsScreenManagerAndroid.cpp \
 	nsIdleServiceAndroid.cpp \
 	nsClipboard.cpp \
 	nsFilePicker.cpp \
@@ -57,17 +56,17 @@ NOT_THERE_YET_CPPSRCS = \
 	$(NULL)
 
 XPIDLSRCS	= \
 	nsIAndroidBridge.idl \
 	$(NULL)
 
 SHARED_LIBRARY_LIBS = ../xpwidgets/libxpwidgets_s.a
 
-EXPORTS = AndroidBridge.h AndroidJavaWrappers.h AndroidLayerViewWrapper.h
+EXPORTS = AndroidBridge.h AndroidJavaWrappers.h
 
 include $(topsrcdir)/config/rules.mk
 
 DEFINES += -D_IMPL_NS_WIDGET
 #DEFINES += -DDEBUG_WIDGETS
 
 LOCAL_INCLUDES += \
 	-I$(topsrcdir)/widget/xpwidgets \