Bug 1257304 - [1.2] Cache screen size and update only on orientation change. r=jchen
☠☠ backed out by 6166a6070ec2 ☠ ☠
authorEugen Sawin <esawin@mozilla.com>
Thu, 31 Mar 2016 23:28:27 +0200
changeset 291413 288b6ba19e644cec4aa6a3c2cf609cf8c7e975f8
parent 291412 8f29950faaa3c187b19aeffe12359cdbd86dc2d4
child 291414 d82bdcd0b640dc5aefb0c10ea108a2c04c81d98c
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjchen
bugs1257304
milestone48.0a1
Bug 1257304 - [1.2] Cache screen size and update only on orientation change. r=jchen
mobile/android/base/java/org/mozilla/gecko/GeckoAppShell.java
mobile/android/base/java/org/mozilla/gecko/GeckoScreenOrientation.java
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoAppShell.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoAppShell.java
@@ -297,16 +297,17 @@ public class GeckoAppShell
     public static native SurfaceBits getSurfaceBits(Surface surface);
 
     public static native void addPresentationSurface(Surface surface);
     public static native void removePresentationSurface(Surface surface);
 
     public static native void onFullScreenPluginHidden(View view);
 
     private static LayerView sLayerView;
+    private static Rect sScreenSize;
 
     public static void setLayerView(LayerView lv) {
         if (sLayerView == lv) {
             return;
         }
         sLayerView = lv;
     }
 
@@ -1262,17 +1263,17 @@ public class GeckoAppShell
     }
 
     private static Intent getOpenURIIntentInner(final Context context,  final String targetURI,
             final String mimeType, final String action, final String title) {
 
         if (action.equalsIgnoreCase(Intent.ACTION_SEND)) {
             Intent shareIntent = getShareIntent(context, targetURI, mimeType, title);
             return Intent.createChooser(shareIntent,
-                                        context.getResources().getString(R.string.share_title)); 
+                                        context.getResources().getString(R.string.share_title));
         }
 
         Uri uri = normalizeUriScheme(targetURI.indexOf(':') >= 0 ? Uri.parse(targetURI) : new Uri.Builder().scheme(targetURI).build());
         if (!TextUtils.isEmpty(mimeType)) {
             Intent intent = getIntentForActionString(action);
             intent.setDataAndType(uri, mimeType);
             return intent;
         }
@@ -1728,17 +1729,17 @@ public class GeckoAppShell
         GeckoProcessesVisitor visitor = new GeckoProcessesVisitor() {
             @Override
             public boolean callback(int pid) {
                 if (pid != android.os.Process.myPid())
                     android.os.Process.killProcess(pid);
                 return true;
             }
         };
-            
+
         EnumerateGeckoProcesses(visitor);
     }
 
     interface GeckoProcessesVisitor{
         boolean callback(int pid);
     }
 
     private static void EnumerateGeckoProcesses(GeckoProcessesVisitor visiter) {
@@ -1750,17 +1751,17 @@ public class GeckoAppShell
             java.lang.Process ps = Runtime.getRuntime().exec("ps");
             BufferedReader in = new BufferedReader(new InputStreamReader(ps.getInputStream()),
                                                    2048);
 
             String headerOutput = in.readLine();
 
             // figure out the column offsets.  We only care about the pid and user fields
             StringTokenizer st = new StringTokenizer(headerOutput);
-            
+
             int tokenSoFar = 0;
             while (st.hasMoreTokens()) {
                 String next = st.nextToken();
                 if (next.equalsIgnoreCase("PID"))
                     pidColumn = tokenSoFar;
                 else if (next.equalsIgnoreCase("USER"))
                     userColumn = tokenSoFar;
                 tokenSoFar++;
@@ -1883,17 +1884,17 @@ public class GeckoAppShell
             return null;
         }
     }
 
     public static String getMimeTypeFromExtension(String ext) {
         final MimeTypeMap mtm = MimeTypeMap.getSingleton();
         return mtm.getMimeTypeFromExtension(ext);
     }
-    
+
     private static Drawable getDrawableForExtension(PackageManager pm, String aExt) {
         Intent intent = new Intent(Intent.ACTION_VIEW);
         final String mimeType = getMimeTypeFromExtension(aExt);
         if (mimeType != null && mimeType.length() > 0)
             intent.setType(mimeType);
         else
             return null;
 
@@ -2607,17 +2608,17 @@ public class GeckoAppShell
     @WrapForJNI(stubName = "GetProxyForURIWrapper")
     public static String getProxyForURI(String spec, String scheme, String host, int port) {
         final ProxySelector ps = new ProxySelector();
 
         Proxy proxy = ps.select(scheme, host);
         if (Proxy.NO_PROXY.equals(proxy)) {
             return "DIRECT";
         }
-        
+
         switch (proxy.type()) {
             case HTTP:
                 return "PROXY " + proxy.address().toString();
             case SOCKS:
                 return "SOCKS " + proxy.address().toString();
         }
 
         return "DIRECT";
@@ -2850,16 +2851,23 @@ public class GeckoAppShell
             return 2;
         } else if (pm.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN)) {
             // 1 finger
             return 1;
         }
         return 0;
     }
 
+    public static synchronized Rect getScreenSize(final boolean update) {
+        if (update || 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;
+    }
+
     @WrapForJNI
-    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());
+    public static Rect getScreenSize() {
+        return getScreenSize(/* update */ false);
     }
 }
--- a/mobile/android/base/java/org/mozilla/gecko/GeckoScreenOrientation.java
+++ b/mobile/android/base/java/org/mozilla/gecko/GeckoScreenOrientation.java
@@ -35,17 +35,17 @@ public class GeckoScreenOrientation {
         DEFAULT(1 << 4);
 
         public final short value;
 
         private ScreenOrientation(int value) {
             this.value = (short)value;
         }
 
-        private final static ScreenOrientation[] sValues = ScreenOrientation.values(); 
+        private final static ScreenOrientation[] sValues = ScreenOrientation.values();
 
         public static ScreenOrientation get(int value) {
             for (ScreenOrientation orient: sValues) {
                 if (orient.value == value) {
                     return orient;
                 }
             }
             return NONE;
@@ -151,16 +151,18 @@ public class GeckoScreenOrientation {
                 aScreenOrientation = ScreenOrientation.PORTRAIT_PRIMARY;
             } else if (aScreenOrientation == ScreenOrientation.LANDSCAPE) {
                 aScreenOrientation = ScreenOrientation.LANDSCAPE_PRIMARY;
             }
             GeckoAppShell.sendEventToGecko(
                 GeckoEvent.createScreenOrientationEvent(aScreenOrientation.value,
                                                         getAngle()));
         }
+        // Update screen size.
+        GeckoAppShell.getScreenSize(/* update */ true);
         return true;
     }
 
     /*
      * @return The Android orientation (Configuration.orientation).
      */
     public int getAndroidOrientation() {
         return screenOrientationToAndroidOrientation(getScreenOrientation());