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
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java
@@ -232,18 +232,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);
}
@@ -1825,29 +1823,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());