Bug 1476106 - Part 4 - Refresh ScreenManager data when detecting orientation changes. r=snorp
authorJan Henning <jh+bugzilla@buttercookie.de>
Thu, 02 Aug 2018 22:03:59 +0200
changeset 431783 67b327d75ce6ff41b854ce731739e0a6851674ca
parent 431782 e936ef6b4b50fc09d0ffb988cb563f4a79d7b34c
child 431784 73efbce701a9880e35a5139dc67757fa68ad892a
push id106548
push userdvarga@mozilla.com
push dateWed, 15 Aug 2018 22:25:34 +0000
treeherdermozilla-inbound@baba90c7c28f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1476106, 1475875
milestone63.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 1476106 - Part 4 - Refresh ScreenManager data when detecting orientation changes. r=snorp As of bug 1475875, cached screen data is now held by Gecko, so - we no longer need to cache the screen size (retrieval of which can be expensive when called en masse, as required e.g. by font inflation) within GeckoAppShell, and - we need to trigger a refresh of that data instead when the activity orientation changes. MozReview-Commit-ID: JsY6sBCcOih
mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoScreenOrientation.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/ScreenManagerHelper.java
widget/android/ScreenHelperAndroid.cpp
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
@@ -233,18 +233,16 @@ public class GeckoAppShell
 
     // helper methods
     @WrapForJNI
     /* package */ static native void reportJavaCrash(Throwable exc, String stackTrace);
 
     @WrapForJNI(dispatchTo = "gecko")
     public static native void notifyUriVisited(String uri);
 
-    private static Rect sScreenSize;
-
     @WrapForJNI(stubName = "NotifyObservers", dispatchTo = "gecko")
     private static native void nativeNotifyObservers(String topic, String data);
 
     @RobocopTarget
     public static void notifyObservers(final String topic, final String data) {
         notifyObservers(topic, data, GeckoThread.State.RUNNING);
     }
 
@@ -1820,29 +1818,22 @@ public class GeckoAppShell
             return 2;
         } else if (pm.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN)) {
             // 1 finger
             return 1;
         }
         return 0;
     }
 
-    public static synchronized void resetScreenSize() {
-        sScreenSize = null;
-    }
-
     @WrapForJNI(calledFrom = "gecko")
-    private static synchronized Rect getScreenSize() {
-        if (sScreenSize == null) {
-            final WindowManager wm = (WindowManager)
-                    getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
-            final Display disp = wm.getDefaultDisplay();
-            sScreenSize = new Rect(0, 0, disp.getWidth(), disp.getHeight());
-        }
-        return sScreenSize;
+    private static Rect getScreenSize() {
+        final WindowManager wm = (WindowManager)
+                getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
+        final Display disp = wm.getDefaultDisplay();
+        return new Rect(0, 0, disp.getWidth(), disp.getHeight());
     }
 
     @WrapForJNI(calledFrom = "any")
     public static int getAudioOutputFramesPerBuffer() {
         final int DEFAULT = 512;
 
         if (SysInfo.getVersion() < 17) {
             return DEFAULT;
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoScreenOrientation.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoScreenOrientation.java
@@ -172,17 +172,17 @@ public class GeckoScreenOrientation {
 
             if (GeckoThread.isRunning()) {
                 onOrientationChange(aScreenOrientation.value, getAngle());
             } else {
                 GeckoThread.queueNativeCall(GeckoScreenOrientation.class, "onOrientationChange",
                                             aScreenOrientation.value, getAngle());
             }
         }
-        GeckoAppShell.resetScreenSize();
+        ScreenManagerHelper.refreshScreenInfo();
         return true;
     }
 
     private void notifyListeners(final ScreenOrientation newOrientation) {
         final Runnable notifier = new Runnable() {
             @Override
             public void run() {
                 for (OrientationChangeListener listener : mListeners) {
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/ScreenManagerHelper.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/ScreenManagerHelper.java
@@ -13,16 +13,30 @@ class ScreenManagerHelper {
     /**
      * The following display types use the same definition in nsIScreen.idl
      */
     final static int DISPLAY_PRIMARY  = 0; // primary screen
     final static int DISPLAY_EXTERNAL = 1; // wired displays, such as HDMI, DisplayPort, etc.
     final static int DISPLAY_VIRTUAL  = 2; // wireless displays, such as Chromecast, WiFi-Display, etc.
 
     /**
+     * Trigger a refresh of the cached screen information held by Gecko.
+     */
+    public static void refreshScreenInfo() {
+        // Screen data is initialised automatically on startup, so no need to queue the call if
+        // Gecko isn't running yet.
+        if (GeckoThread.isRunning()) {
+            nativeRefreshScreenInfo();
+        }
+    }
+
+    @WrapForJNI(stubName = "RefreshScreenInfo", dispatchTo = "gecko")
+    private native static void nativeRefreshScreenInfo();
+
+    /**
      * Add a new nsScreen when a new display in Android is available.
      *
      * @param displayType the display type of the nsScreen would be added
      * @param width       the width of the new nsScreen
      * @param height      the height of the new nsScreen
      * @param density     the density of the new nsScreen
      *
      * @return            return the ID of the added nsScreen
--- a/widget/android/ScreenHelperAndroid.cpp
+++ b/widget/android/ScreenHelperAndroid.cpp
@@ -21,16 +21,20 @@ using namespace mozilla::widget;
 static ScreenHelperAndroid* gHelper = nullptr;
 
 class ScreenHelperAndroid::ScreenHelperSupport final
     : public ScreenManagerHelper::Natives<ScreenHelperSupport>
 {
 public:
     typedef ScreenManagerHelper::Natives<ScreenHelperSupport> Base;
 
+    static void RefreshScreenInfo() {
+      gHelper->Refresh();
+    }
+
     static int32_t AddDisplay(int32_t aDisplayType, int32_t aWidth, int32_t aHeight, float aDensity) {
         static Atomic<uint32_t> nextId;
 
         uint32_t screenId = ++nextId;
         NS_DispatchToMainThread(NS_NewRunnableFunction(
             "ScreenHelperAndroid::ScreenHelperSupport::AddDisplay",
             [aDisplayType, aWidth, aHeight, aDensity, screenId] {
                 MOZ_ASSERT(NS_IsMainThread());