Bug 1182665 - Use a direct JNI call to determine screen size in nsScreenManagerAndroid r=jchen
☠☠ backed out by 6e0f7cb0fc3a ☠ ☠
authorJames Willcox <snorp@snorp.net>
Wed, 26 Aug 2015 15:25:40 -0500
changeset 294627 4080fb4b9a7f535b71cee23fc5692219e312b16b
parent 294626 c8549221c366b0bab175841af01af1edaeb55f94
child 294628 9559cead8d0831bb26d15e7e8d94402f19e186ca
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjchen
bugs1182665
milestone43.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 1182665 - Use a direct JNI call to determine screen size in nsScreenManagerAndroid r=jchen
mobile/android/base/GeckoAppShell.java
widget/android/GeneratedJNIWrappers.cpp
widget/android/GeneratedJNIWrappers.h
widget/android/bindings/AndroidRect-classes.txt
widget/android/bindings/Makefile.in
widget/android/bindings/moz.build
widget/android/nsScreenManagerAndroid.cpp
--- a/mobile/android/base/GeckoAppShell.java
+++ b/mobile/android/base/GeckoAppShell.java
@@ -76,16 +76,17 @@ import android.graphics.Color;
 import android.graphics.ImageFormat;
 import android.graphics.Paint;
 import android.graphics.PixelFormat;
 import android.graphics.Rect;
 import android.graphics.RectF;
 import android.graphics.SurfaceTexture;
 import android.graphics.drawable.BitmapDrawable;
 import android.graphics.drawable.Drawable;
+import android.hardware.display.DisplayManager;
 import android.hardware.Sensor;
 import android.hardware.SensorEventListener;
 import android.hardware.SensorManager;
 import android.location.Criteria;
 import android.location.Location;
 import android.location.LocationListener;
 import android.location.LocationManager;
 import android.net.ConnectivityManager;
@@ -102,16 +103,17 @@ import android.os.Vibrator;
 import android.provider.Browser;
 import android.provider.Settings;
 import android.telephony.TelephonyManager;
 import android.text.TextUtils;
 import android.util.Base64;
 import android.util.DisplayMetrics;
 import android.util.Log;
 import android.view.ContextThemeWrapper;
+import android.view.Display;
 import android.view.HapticFeedbackConstants;
 import android.view.Surface;
 import android.view.SurfaceView;
 import android.view.TextureView;
 import android.view.View;
 import android.view.inputmethod.InputMethodManager;
 import android.webkit.MimeTypeMap;
 import android.webkit.URLUtil;
@@ -2666,9 +2668,20 @@ public class GeckoAppShell
             // 2 fingers
             return 2;
         } else if (pm.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN)) {
             // 1 finger
             return 1;
         }
         return 0;
     }
+
+    @WrapForJNI
+    static Rect getScreenSize() {
+        DisplayManager dm = (DisplayManager)getContext().getSystemService(Context.DISPLAY_SERVICE);
+        if (dm == null) {
+          return new Rect(0, 0, 0, 0);
+        }
+
+        Display disp = dm.getDisplay(Display.DEFAULT_DISPLAY);
+        return new Rect(0, 0, disp.getWidth(), disp.getHeight());
+    }
 }
--- a/widget/android/GeneratedJNIWrappers.cpp
+++ b/widget/android/GeneratedJNIWrappers.cpp
@@ -388,16 +388,24 @@ auto GeckoAppShell::GetScreenDepthWrappe
 constexpr char GeckoAppShell::GetScreenOrientationWrapper_t::name[];
 constexpr char GeckoAppShell::GetScreenOrientationWrapper_t::signature[];
 
 auto GeckoAppShell::GetScreenOrientationWrapper() -> int16_t
 {
     return mozilla::jni::Method<GetScreenOrientationWrapper_t>::Call(nullptr, nullptr);
 }
 
+constexpr char GeckoAppShell::GetScreenSize_t::name[];
+constexpr char GeckoAppShell::GetScreenSize_t::signature[];
+
+auto GeckoAppShell::GetScreenSize() -> mozilla::jni::Object::LocalRef
+{
+    return mozilla::jni::Method<GetScreenSize_t>::Call(nullptr, nullptr);
+}
+
 constexpr char GeckoAppShell::GetShowPasswordSetting_t::name[];
 constexpr char GeckoAppShell::GetShowPasswordSetting_t::signature[];
 
 auto GeckoAppShell::GetShowPasswordSetting() -> bool
 {
     return mozilla::jni::Method<GetShowPasswordSetting_t>::Call(nullptr, nullptr);
 }
 
--- a/widget/android/GeneratedJNIWrappers.h
+++ b/widget/android/GeneratedJNIWrappers.h
@@ -940,16 +940,33 @@ public:
         static const bool isMultithreaded = false;
         static const mozilla::jni::ExceptionMode exceptionMode =
                 mozilla::jni::ExceptionMode::ABORT;
     };
 
     static auto GetScreenOrientationWrapper() -> int16_t;
 
 public:
+    struct GetScreenSize_t {
+        typedef GeckoAppShell Owner;
+        typedef mozilla::jni::Object::LocalRef ReturnType;
+        typedef mozilla::jni::Object::Param SetterType;
+        typedef mozilla::jni::Args<> Args;
+        static constexpr char name[] = "getScreenSize";
+        static constexpr char signature[] =
+                "()Landroid/graphics/Rect;";
+        static const bool isStatic = true;
+        static const bool isMultithreaded = false;
+        static const mozilla::jni::ExceptionMode exceptionMode =
+                mozilla::jni::ExceptionMode::ABORT;
+    };
+
+    static auto GetScreenSize() -> mozilla::jni::Object::LocalRef;
+
+public:
     struct GetShowPasswordSetting_t {
         typedef GeckoAppShell Owner;
         typedef bool ReturnType;
         typedef bool SetterType;
         typedef mozilla::jni::Args<> Args;
         static constexpr char name[] = "getShowPasswordSetting";
         static constexpr char signature[] =
                 "()Z";
new file mode 100644
--- /dev/null
+++ b/widget/android/bindings/AndroidRect-classes.txt
@@ -0,0 +1,2 @@
+android.graphics.Rect
+android.graphics.RectF
--- a/widget/android/bindings/Makefile.in
+++ b/widget/android/bindings/Makefile.in
@@ -19,15 +19,16 @@ sdk_processor := \
 # MediaCodec-classes.txt.  This formulation invokes the SDK processor
 # at most once.
 
 %.cpp %.h: $(ANDROID_SDK)/android.jar %-classes.txt
 	$(sdk_processor) $(ANDROID_SDK)/android.jar $(srcdir)/$*-classes.txt $(CURDIR) $* 16
 
 # We'd like these to be defined in a future GENERATED_EXPORTS list.
 bindings_exports_FILES := \
+	AndroidRect.h \
   Bundle.h \
   MediaCodec.h \
   SurfaceTexture.h \
   $(NULL)
 bindings_exports_DEST = $(DIST)/include
 bindings_exports_TARGET := export
 INSTALL_TARGETS += bindings_exports
--- a/widget/android/bindings/moz.build
+++ b/widget/android/bindings/moz.build
@@ -2,19 +2,20 @@
 # vim: set filetype=python:
 # 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/.
 
 # List of stems to generate .cpp and .h files for.  To add a stem, add it to
 # this list and ensure that $(stem)-classes.txt exists in this directory.
 generated = [
+    'AndroidRect',
     'Bundle',
     'MediaCodec',
-    'SurfaceTexture',
+    'SurfaceTexture'
 ]
 
 SOURCES += ['!%s.cpp' % stem for stem in generated]
 
 # We'd like to add these to a future GENERATED_EXPORTS list, but for now we mark
 # them as generated here and manually install them in Makefile.in.
 GENERATED_FILES += [stem + '.h' for stem in generated]
 
--- a/widget/android/nsScreenManagerAndroid.cpp
+++ b/widget/android/nsScreenManagerAndroid.cpp
@@ -3,16 +3,19 @@
  * 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/. */
 
 #define MOZ_FATAL_ASSERTIONS_FOR_THREAD_SAFETY
 
 #include "nsScreenManagerAndroid.h"
 #include "nsWindow.h"
 #include "AndroidBridge.h"
+#include "GeneratedJNIWrappers.h"
+#include "AndroidRect.h"
+#include <mozilla/jni/Refs.h>
 
 using namespace mozilla;
 
 nsScreenAndroid::nsScreenAndroid(void *nativeScreen)
 {
 }
 
 nsScreenAndroid::~nsScreenAndroid()
@@ -24,23 +27,21 @@ nsScreenAndroid::GetId(uint32_t *outId)
 {
     *outId = 1;
     return NS_OK;
 }
 
 NS_IMETHODIMP
 nsScreenAndroid::GetRect(int32_t *outLeft, int32_t *outTop, int32_t *outWidth, int32_t *outHeight)
 {
-    gfxIntSize sz = nsWindow::GetAndroidScreenBounds();
-
-    *outLeft = 0;
-    *outTop = 0;
-
-    *outWidth = sz.width;
-    *outHeight = sz.height;
+    widget::sdk::Rect::LocalRef rect = widget::GeckoAppShell::GetScreenSize();
+    rect->Left(outLeft);
+    rect->Top(outTop);
+    rect->Width(outWidth);
+    rect->Height(outHeight);
 
     return NS_OK;
 }
 
 
 NS_IMETHODIMP
 nsScreenAndroid::GetAvailRect(int32_t *outLeft, int32_t *outTop, int32_t *outWidth, int32_t *outHeight)
 {