| Index: ui/android/java/src/org/chromium/ui/display/DisplayAndroid.java
|
| diff --git a/ui/android/java/src/org/chromium/ui/display/DisplayAndroid.java b/ui/android/java/src/org/chromium/ui/display/DisplayAndroid.java
|
| index fc17ef77548ab1e562913d10993dd28720278112..e725f95da9e691bd016ad15a29f55fc94e2864b7 100644
|
| --- a/ui/android/java/src/org/chromium/ui/display/DisplayAndroid.java
|
| +++ b/ui/android/java/src/org/chromium/ui/display/DisplayAndroid.java
|
| @@ -4,18 +4,11 @@
|
|
|
| package org.chromium.ui.display;
|
|
|
| -import android.annotation.TargetApi;
|
| import android.content.Context;
|
| -import android.graphics.PixelFormat;
|
| import android.graphics.Point;
|
| -import android.os.Build;
|
| -import android.util.DisplayMetrics;
|
| import android.view.Display;
|
| import android.view.Surface;
|
|
|
| -import org.chromium.base.CommandLine;
|
| -import org.chromium.base.Log;
|
| -
|
| import java.util.WeakHashMap;
|
|
|
| /**
|
| @@ -45,55 +38,21 @@ public class DisplayAndroid {
|
| void onDIPScaleChanged(float dipScale);
|
| }
|
|
|
| - private static final String TAG = "DisplayAndroid";
|
| -
|
| private static final DisplayAndroidObserver[] EMPTY_OBSERVER_ARRAY =
|
| new DisplayAndroidObserver[0];
|
|
|
| - private final int mSdkDisplayId;
|
| private final WeakHashMap<DisplayAndroidObserver, Object /* null */> mObservers;
|
| // Do NOT add strong references to objects with potentially complex lifetime, like Context.
|
|
|
| - // Updated by updateFromDisplay.
|
| - private final Point mSize;
|
| - private final Point mPhysicalSize;
|
| - private final DisplayMetrics mDisplayMetrics;
|
| - private final PixelFormat mPixelFormatInfo;
|
| - private int mPixelFormatId;
|
| + private final int mDisplayId;
|
| + private Point mSize;
|
| + private Point mPhysicalSize;
|
| + private float mDipScale;
|
| + private int mBitsPerPixel;
|
| + private int mBitsPerComponent;
|
| private int mRotation;
|
|
|
| - // When this object exists, a positive value means that the forced DIP scale is set and
|
| - // the zero means it is not. The non existing object (i.e. null reference) means that
|
| - // the existence and value of the forced DIP scale has not yet been determined.
|
| - private static Float sForcedDIPScale;
|
| -
|
| - private static boolean hasForcedDIPScale() {
|
| - if (sForcedDIPScale == null) {
|
| - String forcedScaleAsString = CommandLine.getInstance().getSwitchValue(
|
| - DisplaySwitches.FORCE_DEVICE_SCALE_FACTOR);
|
| - if (forcedScaleAsString == null) {
|
| - sForcedDIPScale = Float.valueOf(0.0f);
|
| - } else {
|
| - boolean isInvalid = false;
|
| - try {
|
| - sForcedDIPScale = Float.valueOf(forcedScaleAsString);
|
| - // Negative values are discarded.
|
| - if (sForcedDIPScale.floatValue() <= 0.0f) isInvalid = true;
|
| - } catch (NumberFormatException e) {
|
| - // Strings that do not represent numbers are discarded.
|
| - isInvalid = true;
|
| - }
|
| -
|
| - if (isInvalid) {
|
| - Log.w(TAG, "Ignoring invalid forced DIP scale '" + forcedScaleAsString + "'");
|
| - sForcedDIPScale = Float.valueOf(0.0f);
|
| - }
|
| - }
|
| - }
|
| - return sForcedDIPScale.floatValue() > 0;
|
| - }
|
| -
|
| - private static DisplayAndroidManager getManager() {
|
| + protected static DisplayAndroidManager getManager() {
|
| return DisplayAndroidManager.getInstance();
|
| }
|
|
|
| @@ -118,10 +77,10 @@ public class DisplayAndroid {
|
| }
|
|
|
| /**
|
| - * @return Display id as defined in Android's Display.
|
| + * @return Display id that does not necessarily match the one defined in Android's Display.
|
| */
|
| - public int getSdkDisplayId() {
|
| - return mSdkDisplayId;
|
| + public int getDisplayId() {
|
| + return mDisplayId;
|
| }
|
|
|
| /**
|
| @@ -163,7 +122,7 @@ public class DisplayAndroid {
|
| * @return current orientation in degrees. One of the values 0, 90, 180, 270.
|
| */
|
| /* package */ int getRotationDegrees() {
|
| - switch (mRotation) {
|
| + switch (getRotation()) {
|
| case Surface.ROTATION_0:
|
| return 0;
|
| case Surface.ROTATION_90:
|
| @@ -183,14 +142,14 @@ public class DisplayAndroid {
|
| * @return A scaling factor for the Density Independent Pixel unit.
|
| */
|
| public float getDipScale() {
|
| - return mDisplayMetrics.density;
|
| + return mDipScale;
|
| }
|
|
|
| /**
|
| * @return Number of bits per pixel.
|
| */
|
| /* package */ int getBitsPerPixel() {
|
| - return mPixelFormatInfo.bitsPerPixel;
|
| + return mBitsPerPixel;
|
| }
|
|
|
| /**
|
| @@ -198,34 +157,7 @@ public class DisplayAndroid {
|
| */
|
| @SuppressWarnings("deprecation")
|
| /* package */ int getBitsPerComponent() {
|
| - switch (mPixelFormatId) {
|
| - case PixelFormat.RGBA_4444:
|
| - return 4;
|
| -
|
| - case PixelFormat.RGBA_5551:
|
| - return 5;
|
| -
|
| - case PixelFormat.RGBA_8888:
|
| - case PixelFormat.RGBX_8888:
|
| - case PixelFormat.RGB_888:
|
| - return 8;
|
| -
|
| - case PixelFormat.RGB_332:
|
| - return 2;
|
| -
|
| - case PixelFormat.RGB_565:
|
| - return 5;
|
| -
|
| - // Non-RGB formats.
|
| - case PixelFormat.A_8:
|
| - case PixelFormat.LA_88:
|
| - case PixelFormat.L_8:
|
| - return 0;
|
| -
|
| - // Unknown format. Use 8 as a sensible default.
|
| - default:
|
| - return 8;
|
| - }
|
| + return mBitsPerComponent;
|
| }
|
|
|
| /**
|
| @@ -259,70 +191,56 @@ public class DisplayAndroid {
|
| getManager().startAccurateListening();
|
| }
|
|
|
| - /* package */ DisplayAndroid(Display display) {
|
| - mSdkDisplayId = display.getDisplayId();
|
| + protected DisplayAndroid(int displayId) {
|
| + mDisplayId = displayId;
|
| mObservers = new WeakHashMap<>();
|
| mSize = new Point();
|
| mPhysicalSize = new Point();
|
| - mDisplayMetrics = new DisplayMetrics();
|
| - mPixelFormatInfo = new PixelFormat();
|
| }
|
|
|
| - @SuppressWarnings("deprecation")
|
| - @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
|
| - /* package */ void updateFromDisplay(Display display) {
|
| - final Point oldSize = new Point(mSize);
|
| - final Point oldPhysicalSize = new Point(mPhysicalSize);
|
| - final float oldDensity = mDisplayMetrics.density;
|
| - final int oldPixelFormatId = mPixelFormatId;
|
| - final int oldRotation = mRotation;
|
| -
|
| - display.getSize(mSize);
|
| - display.getMetrics(mDisplayMetrics);
|
| -
|
| - if (hasForcedDIPScale()) mDisplayMetrics.density = sForcedDIPScale.floatValue();
|
| -
|
| - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
| - display.getRealSize(mPhysicalSize);
|
| - }
|
| + private DisplayAndroidObserver[] getObservers() {
|
| + // Makes a copy to allow concurrent edit.
|
| + return mObservers.keySet().toArray(EMPTY_OBSERVER_ARRAY);
|
| + }
|
|
|
| - // JellyBean MR1 and later always uses RGBA_8888.
|
| - mPixelFormatId = (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1)
|
| - ? display.getPixelFormat()
|
| - : PixelFormat.RGBA_8888;
|
| - if (oldPixelFormatId != mPixelFormatId) {
|
| - PixelFormat.getPixelFormatInfo(mPixelFormatId, mPixelFormatInfo);
|
| - }
|
| + /**
|
| + * Update the display to the provided parameters. Null values leave the parameter unchanged.
|
| + */
|
| + protected void update(Point size, Point physicalSize, Float dipScale, Integer bitsPerPixel,
|
| + Integer bitsPerComponent, Integer rotation) {
|
| + boolean sizeChanged = size != null && !mSize.equals(size);
|
| + boolean physicalSizeChanged = physicalSize != null && !mPhysicalSize.equals(physicalSize);
|
| + // Intentional comparison of floats: we assume that if scales differ, they differ
|
| + // significantly.
|
| + boolean dipScaleChanged = dipScale != null && mDipScale != dipScale;
|
| + boolean bitsPerPixelChanged = bitsPerPixel != null && mBitsPerPixel != bitsPerPixel;
|
| + boolean bitsPerComponentChanged = bitsPerComponent != null
|
| + && mBitsPerComponent != bitsPerComponent;
|
| + boolean rotationChanged = rotation != null && mRotation != rotation;
|
|
|
| - mRotation = display.getRotation();
|
| + boolean changed = sizeChanged || physicalSizeChanged || dipScaleChanged
|
| + || bitsPerPixelChanged || bitsPerComponentChanged || rotationChanged;
|
| + if (!changed) return;
|
|
|
| - final boolean noChanges = oldSize.equals(mSize) && oldPhysicalSize.equals(mPhysicalSize)
|
| - && oldDensity == mDisplayMetrics.density && oldPixelFormatId == mPixelFormatId
|
| - && oldRotation == mRotation;
|
| - if (noChanges) return;
|
| + if (sizeChanged) mSize = size;
|
| + if (physicalSizeChanged) mPhysicalSize = physicalSize;
|
| + if (dipScaleChanged) mDipScale = dipScale;
|
| + if (bitsPerPixelChanged) mBitsPerPixel = bitsPerPixel;
|
| + if (bitsPerComponentChanged) mBitsPerComponent = bitsPerComponent;
|
| + if (rotationChanged) mRotation = rotation;
|
|
|
| getManager().updateDisplayOnNativeSide(this);
|
| -
|
| - if (oldRotation != mRotation) {
|
| + if (rotationChanged) {
|
| DisplayAndroidObserver[] observers = getObservers();
|
| for (DisplayAndroidObserver o : observers) {
|
| o.onRotationChanged(mRotation);
|
| }
|
| }
|
| -
|
| - // Intentional comparison of floats: we assume that if scales differ,
|
| - // they differ significantly.
|
| - boolean dipScaleChanged = oldDensity != mDisplayMetrics.density;
|
| if (dipScaleChanged) {
|
| DisplayAndroidObserver[] observers = getObservers();
|
| for (DisplayAndroidObserver o : observers) {
|
| - o.onDIPScaleChanged(mDisplayMetrics.density);
|
| + o.onDIPScaleChanged(mDipScale);
|
| }
|
| }
|
| }
|
| -
|
| - private DisplayAndroidObserver[] getObservers() {
|
| - // Makes a copy to allow concurrent edit.
|
| - return mObservers.keySet().toArray(EMPTY_OBSERVER_ARRAY);
|
| - }
|
| }
|
|
|