Bug 1200426 - Convert PROCESS_OBJECT GeckoEvent to native call; r=snorp
authorJim Chen <nchen@mozilla.com>
Thu, 08 Oct 2015 15:25:49 -0400
changeset 266980 dee668cc4bb8a13d8225ee45628d55b9e824baa5
parent 266979 8ca3465da60607ebbfa2902f4031cf93aca71cbb
child 266981 25b2caf967ea2adefefe4b215d0bc4558fea9ac6
push id29504
push usercbook@mozilla.com
push dateFri, 09 Oct 2015 09:43:23 +0000
treeherdermozilla-central@d01dd42e654b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1200426
milestone44.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 1200426 - Convert PROCESS_OBJECT GeckoEvent to native call; r=snorp The PROCESS_OBJECT GeckoEvent is used to set the layer client object in Gecko once Gecko is done loading. This patch converts it to a native call in GeckoView.Window.
mobile/android/base/GeckoEvent.java
mobile/android/base/GeckoView.java
widget/android/AndroidJavaWrappers.cpp
widget/android/AndroidJavaWrappers.h
widget/android/GeneratedJNINatives.h
widget/android/GeneratedJNIWrappers.cpp
widget/android/GeneratedJNIWrappers.h
widget/android/nsAppShell.cpp
widget/android/nsWindow.cpp
--- a/mobile/android/base/GeckoEvent.java
+++ b/mobile/android/base/GeckoEvent.java
@@ -68,17 +68,16 @@ public class GeckoEvent {
     // Make sure to keep these values in sync with the enum in
     // AndroidGeckoEvent in widget/android/AndroidJavaWrappers.h
     @JNITarget
     private enum NativeGeckoEvent {
         NATIVE_POKE(0),
         KEY_EVENT(1),
         MOTION_EVENT(2),
         SENSOR_EVENT(3),
-        PROCESS_OBJECT(4),
         LOCATION_EVENT(5),
         IME_EVENT(6),
         SIZE_CHANGED(8),
         APP_BACKGROUNDING(9),
         APP_FOREGROUNDING(10),
         LOAD_URI(12),
         NOOP(15),
         BROADCAST(19),
@@ -154,18 +153,16 @@ public class GeckoEvent {
     public static final int ACTION_MAGNIFY_END = 13;
 
     public static final int ACTION_GAMEPAD_ADDED = 1;
     public static final int ACTION_GAMEPAD_REMOVED = 2;
 
     public static final int ACTION_GAMEPAD_BUTTON = 1;
     public static final int ACTION_GAMEPAD_AXES = 2;
 
-    public static final int ACTION_OBJECT_LAYER_CLIENT = 1;
-
     private final int mType;
     private int mAction;
     private boolean mAckNeeded;
     private long mTime;
     private Point[] mPoints;
     private int[] mPointIndicies;
     private int mPointerIndex; // index of the point that has changed
     private float[] mOrientations;
@@ -217,18 +214,16 @@ public class GeckoEvent {
     private int mHeight;
 
     private int mID;
     private int mGamepadButton;
     private boolean mGamepadButtonPressed;
     private float mGamepadButtonValue;
     private float[] mGamepadValues;
 
-    private Object mObject;
-
     private GeckoEvent(NativeGeckoEvent event) {
         mType = event.value;
     }
 
     public static GeckoEvent createAppBackgroundingEvent() {
         return GeckoEvent.get(NativeGeckoEvent.APP_BACKGROUNDING);
     }
 
@@ -579,23 +574,16 @@ public class GeckoEvent {
             event.mY = s.values[1];
             event.mZ = s.values[2];
             event.mW = s.values[3];
             break;
         }
         return event;
     }
 
-    public static GeckoEvent createObjectEvent(final int action, final Object object) {
-        GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.PROCESS_OBJECT);
-        event.mAction = action;
-        event.mObject = object;
-        return event;
-    }
-
     public static GeckoEvent createLocationEvent(Location l) {
         GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.LOCATION_EVENT);
         event.mLocation = l;
         return event;
     }
 
     public static GeckoEvent createIMEEvent(ImeAction action) {
         GeckoEvent event = GeckoEvent.get(NativeGeckoEvent.IME_EVENT);
--- a/mobile/android/base/GeckoView.java
+++ b/mobile/android/base/GeckoView.java
@@ -105,16 +105,17 @@ public class GeckoView extends LayerView
                 Log.w(LOGTAG, "handleMessage threw for " + event, e);
             }
         }
     };
 
     @WrapForJNI
     private static final class Window extends JNIObject {
         static native void open(Window instance, int width, int height);
+        static native void setLayerClient(Object client);
         @Override protected native void disposeNative();
     }
 
     private final Window window = new Window();
 
     public GeckoView(Context context) {
         super(context);
         init(context, null, true);
@@ -137,18 +138,24 @@ public class GeckoView extends LayerView
             setGeckoInterface(new BaseGeckoInterface(context));
             GeckoAppShell.setContextGetter(this);
         }
 
         // Perform common initialization for Fennec/GeckoView.
         GeckoAppShell.setLayerView(this);
 
         initializeView(EventDispatcher.getInstance());
-        GeckoAppShell.sendEventToGecko(GeckoEvent.createObjectEvent(
-                GeckoEvent.ACTION_OBJECT_LAYER_CLIENT, getLayerClientObject()));
+
+        if (GeckoThread.isStateAtLeast(GeckoThread.State.JNI_READY)) {
+            Window.setLayerClient(getLayerClientObject());
+        } else {
+            GeckoThread.queueNativeCallUntil(GeckoThread.State.JNI_READY,
+                    Window.class, "setLayerClient",
+                    Object.class, getLayerClientObject());
+        }
 
         // TODO: Fennec currently takes care of its own initialization, so this
         // flag is a hack used in Fennec to prevent GeckoView initialization.
         // This should go away once Fennec also uses GeckoView for
         // initialization.
         if (!doInit)
             return;
 
--- a/widget/android/AndroidJavaWrappers.cpp
+++ b/widget/android/AndroidJavaWrappers.cpp
@@ -65,17 +65,16 @@ jfieldID AndroidGeckoEvent::jScreenAngle
 jfieldID AndroidGeckoEvent::jByteBufferField = 0;
 jfieldID AndroidGeckoEvent::jWidthField = 0;
 jfieldID AndroidGeckoEvent::jHeightField = 0;
 jfieldID AndroidGeckoEvent::jIDField = 0;
 jfieldID AndroidGeckoEvent::jGamepadButtonField = 0;
 jfieldID AndroidGeckoEvent::jGamepadButtonPressedField = 0;
 jfieldID AndroidGeckoEvent::jGamepadButtonValueField = 0;
 jfieldID AndroidGeckoEvent::jGamepadValuesField = 0;
-jfieldID AndroidGeckoEvent::jObjectField = 0;
 
 jclass AndroidPoint::jPointClass = 0;
 jfieldID AndroidPoint::jXField = 0;
 jfieldID AndroidPoint::jYField = 0;
 
 jclass AndroidRect::jRectClass = 0;
 jfieldID AndroidRect::jBottomField = 0;
 jfieldID AndroidRect::jLeftField = 0;
@@ -173,17 +172,16 @@ AndroidGeckoEvent::InitGeckoEventClass(J
     jByteBufferField = geckoEvent.getField("mBuffer", "Ljava/nio/ByteBuffer;");
     jWidthField = geckoEvent.getField("mWidth", "I");
     jHeightField = geckoEvent.getField("mHeight", "I");
     jIDField = geckoEvent.getField("mID", "I");
     jGamepadButtonField = geckoEvent.getField("mGamepadButton", "I");
     jGamepadButtonPressedField = geckoEvent.getField("mGamepadButtonPressed", "Z");
     jGamepadButtonValueField = geckoEvent.getField("mGamepadButtonValue", "F");
     jGamepadValuesField = geckoEvent.getField("mGamepadValues", "[F");
-    jObjectField = geckoEvent.getField("mObject", "Ljava/lang/Object;");
 }
 
 void
 AndroidLocation::InitLocationClass(JNIEnv *jEnv)
 {
     AutoJNIClass location(jEnv, "android/location/Location");
     jLocationClass = location.getGlobalRef();
     jGetLatitudeMethod = location.getMethod("getLatitude", "()D");
@@ -468,23 +466,16 @@ AndroidGeckoEvent::Init(JNIEnv *jenv, jo
              mX = jenv->GetDoubleField(jobj, jXField);
              mY = jenv->GetDoubleField(jobj, jYField);
              mZ = jenv->GetDoubleField(jobj, jZField);
              mW = jenv->GetDoubleField(jobj, jWField);
              mFlags = jenv->GetIntField(jobj, jFlagsField);
              mMetaState = jenv->GetIntField(jobj, jMetaStateField);
              break;
 
-        case PROCESS_OBJECT: {
-            const jobject obj = jenv->GetObjectField(jobj, jObjectField);
-            mObject.Init(obj, jenv);
-            jenv->DeleteLocalRef(obj);
-            break;
-        }
-
         case LOCATION_EVENT: {
             jobject location = jenv->GetObjectField(jobj, jLocationField);
             mGeoPosition = AndroidLocation::CreateGeoPosition(jenv, location);
             break;
         }
 
         case LOAD_URI: {
             ReadCharactersField(jenv);
--- a/widget/android/AndroidJavaWrappers.h
+++ b/widget/android/AndroidJavaWrappers.h
@@ -566,17 +566,16 @@ public:
     int Width() { return mWidth; }
     int Height() { return mHeight; }
     int ID() { return mID; }
     int GamepadButton() { return mGamepadButton; }
     bool GamepadButtonPressed() { return mGamepadButtonPressed; }
     float GamepadButtonValue() { return mGamepadButtonValue; }
     const nsTArray<float>& GamepadValues() { return mGamepadValues; }
     int RequestId() { return mCount; } // for convenience
-    const AutoGlobalWrappedJavaObject& Object() { return mObject; }
     bool CanCoalesceWith(AndroidGeckoEvent* ae);
     WidgetTouchEvent MakeTouchEvent(nsIWidget* widget);
     MultiTouchInput MakeMultiTouchInput(nsIWidget* widget);
     WidgetMouseEvent MakeMouseEvent(nsIWidget* widget);
     void UnionRect(nsIntRect const& aRect);
     nsIObserver *Observer() { return mObserver; }
     mozilla::layers::ScrollableLayerGuid ApzGuid();
     uint64_t ApzInputBlockId();
@@ -619,17 +618,16 @@ protected:
     bool mGamepadButtonPressed;
     float mGamepadButtonValue;
     nsTArray<float> mGamepadValues;
     nsCOMPtr<nsIObserver> mObserver;
     MultiTouchInput mApzInput;
     mozilla::layers::ScrollableLayerGuid mApzGuid;
     uint64_t mApzInputBlockId;
     nsEventStatus mApzEventStatus;
-    AutoGlobalWrappedJavaObject mObject;
 
     void ReadIntArray(nsTArray<int> &aVals,
                       JNIEnv *jenv,
                       jfieldID field,
                       int32_t count);
     void ReadFloatArray(nsTArray<float> &aVals,
                         JNIEnv *jenv,
                         jfieldID field,
@@ -702,25 +700,22 @@ protected:
     static jfieldID jHeightField;
 
     static jfieldID jIDField;
     static jfieldID jGamepadButtonField;
     static jfieldID jGamepadButtonPressedField;
     static jfieldID jGamepadButtonValueField;
     static jfieldID jGamepadValuesField;
 
-    static jfieldID jObjectField;
-
 public:
     enum {
         NATIVE_POKE = 0,
         KEY_EVENT = 1,
         MOTION_EVENT = 2,
         SENSOR_EVENT = 3,
-        PROCESS_OBJECT = 4,
         LOCATION_EVENT = 5,
         IME_EVENT = 6,
         SIZE_CHANGED = 8,
         APP_BACKGROUNDING = 9,
         APP_FOREGROUNDING = 10,
         LOAD_URI = 12,
         NOOP = 15,
         FORCED_RESIZE = 16, // used internally in nsAppShell/nsWindow
@@ -781,21 +776,16 @@ public:
         ACTION_GAMEPAD_ADDED = 1,
         ACTION_GAMEPAD_REMOVED = 2
     };
 
     enum {
         ACTION_GAMEPAD_BUTTON = 1,
         ACTION_GAMEPAD_AXES = 2
     };
-
-    enum {
-        ACTION_OBJECT_LAYER_CLIENT = 1,
-        dummy_object_enum_list_end
-    };
 };
 
 class nsJNIString : public nsString
 {
 public:
     nsJNIString(jstring jstr, JNIEnv *jenv);
 };
 
--- a/widget/android/GeneratedJNINatives.h
+++ b/widget/android/GeneratedJNINatives.h
@@ -147,17 +147,21 @@ public:
     static constexpr JNINativeMethod methods[] = {
 
         mozilla::jni::MakeNativeMethod<GeckoView::Window::DisposeNative_t>(
                 mozilla::jni::NativeStub<GeckoView::Window::DisposeNative_t, Impl>
                 ::template Wrap<&Impl::DisposeNative>),
 
         mozilla::jni::MakeNativeMethod<GeckoView::Window::Open_t>(
                 mozilla::jni::NativeStub<GeckoView::Window::Open_t, Impl>
-                ::template Wrap<&Impl::Open>)
+                ::template Wrap<&Impl::Open>),
+
+        mozilla::jni::MakeNativeMethod<GeckoView::Window::SetLayerClient_t>(
+                mozilla::jni::NativeStub<GeckoView::Window::SetLayerClient_t, Impl>
+                ::template Wrap<&Impl::SetLayerClient>)
     };
 };
 
 template<class Impl>
 constexpr JNINativeMethod GeckoView::Window::Natives<Impl>::methods[];
 
 template<class Impl>
 class PrefsHelper::Natives : public mozilla::jni::NativeImpl<PrefsHelper, Impl>
--- a/widget/android/GeneratedJNIWrappers.cpp
+++ b/widget/android/GeneratedJNIWrappers.cpp
@@ -1026,16 +1026,19 @@ auto GeckoView::Window::New() -> Window:
 }
 
 constexpr char GeckoView::Window::DisposeNative_t::name[];
 constexpr char GeckoView::Window::DisposeNative_t::signature[];
 
 constexpr char GeckoView::Window::Open_t::name[];
 constexpr char GeckoView::Window::Open_t::signature[];
 
+constexpr char GeckoView::Window::SetLayerClient_t::name[];
+constexpr char GeckoView::Window::SetLayerClient_t::signature[];
+
 constexpr char PrefsHelper::name[];
 
 constexpr char PrefsHelper::GetPrefsById_t::name[];
 constexpr char PrefsHelper::GetPrefsById_t::signature[];
 
 constexpr char PrefsHelper::RemovePrefsObserver_t::name[];
 constexpr char PrefsHelper::RemovePrefsObserver_t::signature[];
 
--- a/widget/android/GeneratedJNIWrappers.h
+++ b/widget/android/GeneratedJNIWrappers.h
@@ -2656,16 +2656,32 @@ public:
                 "(Lorg/mozilla/gecko/GeckoView$Window;II)V";
         static const bool isStatic = true;
         static const bool isMultithreaded = true;
         static const mozilla::jni::ExceptionMode exceptionMode =
                 mozilla::jni::ExceptionMode::ABORT;
     };
 
 public:
+    struct SetLayerClient_t {
+        typedef Window Owner;
+        typedef void ReturnType;
+        typedef void SetterType;
+        typedef mozilla::jni::Args<
+                mozilla::jni::Object::Param> Args;
+        static constexpr char name[] = "setLayerClient";
+        static constexpr char signature[] =
+                "(Ljava/lang/Object;)V";
+        static const bool isStatic = true;
+        static const bool isMultithreaded = true;
+        static const mozilla::jni::ExceptionMode exceptionMode =
+                mozilla::jni::ExceptionMode::ABORT;
+    };
+
+public:
     template<class Impl> class Natives;
 };
 
 class PrefsHelper : public mozilla::jni::Class<PrefsHelper>
 {
 public:
     typedef mozilla::jni::Ref<PrefsHelper> Ref;
     typedef mozilla::jni::LocalRef<PrefsHelper> LocalRef;
--- a/widget/android/nsAppShell.cpp
+++ b/widget/android/nsAppShell.cpp
@@ -429,27 +429,16 @@ nsAppShell::LegacyGeckoEvent::Run()
         }
 
         const hal::SensorAccuracyType &accuracy = (hal::SensorAccuracyType) curEvent->MetaState();
         hal::SensorData sdata(type, PR_Now(), values, accuracy);
         hal::NotifySensorChange(sdata);
       }
       break;
 
-    case AndroidGeckoEvent::PROCESS_OBJECT: {
-
-      switch (curEvent->Action()) {
-      case AndroidGeckoEvent::ACTION_OBJECT_LAYER_CLIENT:
-        AndroidBridge::Bridge()->SetLayerClient(
-                widget::GeckoLayerClient::Ref::From(curEvent->Object().wrappedObject()));
-        break;
-      }
-      break;
-    }
-
     case AndroidGeckoEvent::LOCATION_EVENT: {
         if (!gLocationCallback)
             break;
 
         nsGeoPosition* p = curEvent->GeoPosition();
         if (p)
             gLocationCallback->Update(curEvent->GeoPosition());
         else
--- a/widget/android/nsWindow.cpp
+++ b/widget/android/nsWindow.cpp
@@ -182,16 +182,24 @@ public:
 
     // Detach and destroy the window that we created in Open().
     void DisposeNative(const GeckoView::Window::LocalRef& instance);
 
     // Create and attach a window.
     static void Open(const jni::ClassObject::LocalRef& cls,
                      GeckoView::Window::Param gvWindow,
                      int32_t width, int32_t height);
+
+    // Set the active layer client object
+    static void SetLayerClient(jni::Object::Param client)
+    {
+        MOZ_ASSERT(NS_IsMainThread());
+        AndroidBridge::Bridge()->SetLayerClient(
+                widget::GeckoLayerClient::Ref::From(client.Get()));
+    }
 };
 
 void
 nsWindow::Natives::Open(const jni::ClassObject::LocalRef& cls,
                         GeckoView::Window::Param gvWindow,
                         int32_t width, int32_t height)
 {
     MOZ_ASSERT(NS_IsMainThread());