| Index: ui/android/java/src/org/chromium/ui/gfx/DeviceDisplayInfo.java
|
| diff --git a/ui/android/java/src/org/chromium/ui/gfx/DeviceDisplayInfo.java b/ui/android/java/src/org/chromium/ui/gfx/DeviceDisplayInfo.java
|
| index 863fa1b5e16d41c2a6fbbceb807823ed8af87af8..98f51507bee9e004a26fc51356b51702704e8ce5 100644
|
| --- a/ui/android/java/src/org/chromium/ui/gfx/DeviceDisplayInfo.java
|
| +++ b/ui/android/java/src/org/chromium/ui/gfx/DeviceDisplayInfo.java
|
| @@ -4,9 +4,7 @@
|
|
|
| package org.chromium.ui.gfx;
|
|
|
| -import android.content.ComponentCallbacks;
|
| import android.content.Context;
|
| -import android.content.res.Configuration;
|
| import android.graphics.PixelFormat;
|
| import android.graphics.Point;
|
| import android.os.Build;
|
| @@ -28,6 +26,8 @@ import org.chromium.base.JNINamespace;
|
| public class DeviceDisplayInfo {
|
|
|
|
|
| + private static DeviceDisplayInfo sInstance;
|
| +
|
| private final Context mAppContext;
|
| private final WindowManager mWinManager;
|
| private Point mTempPoint = new Point();
|
| @@ -42,7 +42,8 @@ public class DeviceDisplayInfo {
|
| */
|
| @CalledByNative
|
| public int getDisplayHeight() {
|
| - return getMetrics().heightPixels;
|
| + getDisplay().getSize(mTempPoint);
|
| + return mTempPoint.y;
|
| }
|
|
|
| /**
|
| @@ -50,7 +51,8 @@ public class DeviceDisplayInfo {
|
| */
|
| @CalledByNative
|
| public int getDisplayWidth() {
|
| - return getMetrics().widthPixels;
|
| + getDisplay().getSize(mTempPoint);
|
| + return mTempPoint.x;
|
| }
|
|
|
| /**
|
| @@ -79,11 +81,8 @@ public class DeviceDisplayInfo {
|
|
|
| @SuppressWarnings("deprecation")
|
| private int getPixelFormat() {
|
| - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
| - return getDisplay().getPixelFormat();
|
| - }
|
| - // JellyBean MR1 and later always uses RGBA_8888.
|
| - return PixelFormat.RGBA_8888;
|
| + // API Level newer than JELLY_BEAN_MR1 will always return RGBA_8888.
|
| + return getDisplay().getPixelFormat();
|
| }
|
|
|
| /**
|
| @@ -140,7 +139,9 @@ public class DeviceDisplayInfo {
|
| */
|
| @CalledByNative
|
| public double getDIPScale() {
|
| - return getMetrics().density;
|
| + DisplayMetrics metrics = new DisplayMetrics();
|
| + getDisplay().getMetrics(metrics);
|
| + return metrics.density;
|
| }
|
|
|
| /**
|
| @@ -152,21 +153,7 @@ public class DeviceDisplayInfo {
|
| return mAppContext.getResources().getConfiguration().smallestScreenWidthDp;
|
| }
|
|
|
| - private void registerListener() {
|
| - mAppContext.registerComponentCallbacks(
|
| - new ComponentCallbacks() {
|
| - @Override
|
| - public void onConfigurationChanged(Configuration configuration) {
|
| - updateNativeSharedDisplayInfo();
|
| - }
|
| -
|
| - @Override
|
| - public void onLowMemory() {
|
| - }
|
| - });
|
| - }
|
| -
|
| - private void updateNativeSharedDisplayInfo() {
|
| + public void updateNativeSharedDisplayInfo() {
|
| nativeUpdateSharedDeviceDisplayInfo(
|
| getDisplayHeight(), getDisplayWidth(),
|
| getPhysicalDisplayHeight(), getPhysicalDisplayWidth(),
|
| @@ -178,25 +165,24 @@ public class DeviceDisplayInfo {
|
| return mWinManager.getDefaultDisplay();
|
| }
|
|
|
| - private DisplayMetrics getMetrics() {
|
| - return mAppContext.getResources().getDisplayMetrics();
|
| - }
|
| -
|
| /**
|
| - * Creates DeviceDisplayInfo for a given Context.
|
| + * Return the DeviceDisplayInfo associated with that context and process.
|
| + * In practice, we use the application context which is the same for all the
|
| + * contexts from a given process.
|
| + * TODO(mlamouri): we might want to handle multiple Display, see http://crbug.com/310763
|
| *
|
| * @param context A context to use.
|
| * @return DeviceDisplayInfo associated with a given Context.
|
| */
|
| - public static DeviceDisplayInfo create(Context context) {
|
| - return new DeviceDisplayInfo(context);
|
| - }
|
| -
|
| @CalledByNative
|
| - private static DeviceDisplayInfo createWithListener(Context context) {
|
| - DeviceDisplayInfo deviceDisplayInfo = new DeviceDisplayInfo(context);
|
| - deviceDisplayInfo.registerListener();
|
| - return deviceDisplayInfo;
|
| + public static DeviceDisplayInfo getInstance(Context context) {
|
| + if (sInstance == null) {
|
| + sInstance = new DeviceDisplayInfo(context);
|
| + }
|
| +
|
| + assert context.getApplicationContext() == sInstance.mAppContext;
|
| +
|
| + return sInstance;
|
| }
|
|
|
| private native void nativeUpdateSharedDeviceDisplayInfo(
|
|
|