From 226e891da2e0ee60064f8b8c89b456da3a7fb46e Mon Sep 17 00:00:00 2001 From: James Willcox Date: Wed, 26 Aug 2015 15:25:40 -0500 Subject: [PATCH] Bug 1182665 - Use a direct JNI call to determine screen size in nsScreenManagerAndroid r=jchen --- mobile/android/base/GeckoAppShell.java | 13 +++++++++++++ widget/android/GeneratedJNIWrappers.cpp | 8 ++++++++ widget/android/GeneratedJNIWrappers.h | 17 +++++++++++++++++ widget/android/bindings/AndroidRect-classes.txt | 2 ++ widget/android/bindings/Makefile.in | 1 + widget/android/bindings/moz.build | 3 ++- widget/android/nsScreenManagerAndroid.cpp | 15 ++++++++------- 7 files changed, 51 insertions(+), 8 deletions(-) create mode 100644 widget/android/bindings/AndroidRect-classes.txt diff --git a/mobile/android/base/GeckoAppShell.java b/mobile/android/base/GeckoAppShell.java index 2094c05a0f9c..fb514ad4876c 100644 --- a/mobile/android/base/GeckoAppShell.java +++ b/mobile/android/base/GeckoAppShell.java @@ -81,6 +81,7 @@ 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; @@ -107,6 +108,7 @@ 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; @@ -2671,4 +2673,15 @@ public class GeckoAppShell } 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()); + } } diff --git a/widget/android/GeneratedJNIWrappers.cpp b/widget/android/GeneratedJNIWrappers.cpp index 7664ce8deaf4..285cf4c8372b 100644 --- a/widget/android/GeneratedJNIWrappers.cpp +++ b/widget/android/GeneratedJNIWrappers.cpp @@ -393,6 +393,14 @@ auto GeckoAppShell::GetScreenOrientationWrapper() -> int16_t return mozilla::jni::Method::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::Call(nullptr, nullptr); +} + constexpr char GeckoAppShell::GetShowPasswordSetting_t::name[]; constexpr char GeckoAppShell::GetShowPasswordSetting_t::signature[]; diff --git a/widget/android/GeneratedJNIWrappers.h b/widget/android/GeneratedJNIWrappers.h index b77c60d5f434..1523c7588d70 100644 --- a/widget/android/GeneratedJNIWrappers.h +++ b/widget/android/GeneratedJNIWrappers.h @@ -944,6 +944,23 @@ public: 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; diff --git a/widget/android/bindings/AndroidRect-classes.txt b/widget/android/bindings/AndroidRect-classes.txt new file mode 100644 index 000000000000..cbacca81e1a4 --- /dev/null +++ b/widget/android/bindings/AndroidRect-classes.txt @@ -0,0 +1,2 @@ +android.graphics.Rect +android.graphics.RectF diff --git a/widget/android/bindings/Makefile.in b/widget/android/bindings/Makefile.in index c42ce48862d1..644c2e19688a 100644 --- a/widget/android/bindings/Makefile.in +++ b/widget/android/bindings/Makefile.in @@ -24,6 +24,7 @@ sdk_processor := \ # We'd like these to be defined in a future GENERATED_EXPORTS list. bindings_exports_FILES := \ + AndroidRect.h \ Bundle.h \ MediaCodec.h \ SurfaceTexture.h \ diff --git a/widget/android/bindings/moz.build b/widget/android/bindings/moz.build index 622e4f6394a6..a70bf79ac61a 100644 --- a/widget/android/bindings/moz.build +++ b/widget/android/bindings/moz.build @@ -7,9 +7,10 @@ # 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] diff --git a/widget/android/nsScreenManagerAndroid.cpp b/widget/android/nsScreenManagerAndroid.cpp index 4cc09728299b..9a8b3651fe79 100644 --- a/widget/android/nsScreenManagerAndroid.cpp +++ b/widget/android/nsScreenManagerAndroid.cpp @@ -8,6 +8,9 @@ #include "nsScreenManagerAndroid.h" #include "nsWindow.h" #include "AndroidBridge.h" +#include "GeneratedJNIWrappers.h" +#include "AndroidRect.h" +#include using namespace mozilla; @@ -29,13 +32,11 @@ nsScreenAndroid::GetId(uint32_t *outId) 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; }