Commit b7c67709 authored by mlamouri@chromium.org's avatar mlamouri@chromium.org

Use Display instead of DisplayMetrics to find out the Display size.

It solves issues where we were sometimes getting stale data,
especially if reading information after a DisplayListener event.

BUG=354275

Review URL: https://codereview.chromium.org/212933012

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@260223 0039d316-1c4b-4281-b951-d872f2087c98
parent 6f585553
...@@ -31,6 +31,7 @@ public class DeviceDisplayInfo { ...@@ -31,6 +31,7 @@ public class DeviceDisplayInfo {
private final Context mAppContext; private final Context mAppContext;
private final WindowManager mWinManager; private final WindowManager mWinManager;
private Point mTempPoint = new Point(); private Point mTempPoint = new Point();
private DisplayMetrics mTempMetrics = new DisplayMetrics();
private DeviceDisplayInfo(Context context) { private DeviceDisplayInfo(Context context) {
mAppContext = context.getApplicationContext(); mAppContext = context.getApplicationContext();
...@@ -42,7 +43,8 @@ public class DeviceDisplayInfo { ...@@ -42,7 +43,8 @@ public class DeviceDisplayInfo {
*/ */
@CalledByNative @CalledByNative
public int getDisplayHeight() { public int getDisplayHeight() {
return getMetrics().heightPixels; getDisplay().getSize(mTempPoint);
return mTempPoint.y;
} }
/** /**
...@@ -50,7 +52,8 @@ public class DeviceDisplayInfo { ...@@ -50,7 +52,8 @@ public class DeviceDisplayInfo {
*/ */
@CalledByNative @CalledByNative
public int getDisplayWidth() { public int getDisplayWidth() {
return getMetrics().widthPixels; getDisplay().getSize(mTempPoint);
return mTempPoint.x;
} }
/** /**
...@@ -140,7 +143,8 @@ public class DeviceDisplayInfo { ...@@ -140,7 +143,8 @@ public class DeviceDisplayInfo {
*/ */
@CalledByNative @CalledByNative
public double getDIPScale() { public double getDIPScale() {
return getMetrics().density; getDisplay().getMetrics(mTempMetrics);
return mTempMetrics.density;
} }
/** /**
...@@ -178,10 +182,6 @@ public class DeviceDisplayInfo { ...@@ -178,10 +182,6 @@ public class DeviceDisplayInfo {
return mWinManager.getDefaultDisplay(); return mWinManager.getDefaultDisplay();
} }
private DisplayMetrics getMetrics() {
return mAppContext.getResources().getDisplayMetrics();
}
/** /**
* Creates DeviceDisplayInfo for a given Context. * Creates DeviceDisplayInfo for a given Context.
* *
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment