Chromium Code Reviews| 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 383762052237046274f70350b97706de7f08fdfa..13c434b977a34f914b943960d2ea2138560ddc72 100644 |
| --- a/ui/android/java/src/org/chromium/ui/display/DisplayAndroid.java |
| +++ b/ui/android/java/src/org/chromium/ui/display/DisplayAndroid.java |
| @@ -6,10 +6,12 @@ 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; |
| @@ -56,6 +58,8 @@ public class DisplayAndroid { |
| private final Point mSize; |
| private final Point mPhysicalSize; |
| private final DisplayMetrics mDisplayMetrics; |
| + private final PixelFormat mPixelFormatInfo; |
| + private int mPixelFormatId; |
| private int mRotation; |
| // When this object exists, a positive value means that the forced DIP scale is set and |
| @@ -114,6 +118,13 @@ public class DisplayAndroid { |
| } |
| /** |
| + * @return Display id as defined in Android's Display. |
| + */ |
| + public int getSdkDisplayId() { |
|
boliu
2016/11/12 00:34:13
I prefer to keep new methods package visible until
Tima Vaisburd
2016/11/12 01:57:27
Done.
|
| + return mSdkDisplayId; |
| + } |
| + |
| + /** |
| * @return Display height in physical pixels. |
| */ |
| public int getDisplayHeight() { |
| @@ -149,6 +160,26 @@ public class DisplayAndroid { |
| } |
| /** |
| + * @return current orientation in degrees. One of the values 0, 90, 180, 270. |
| + */ |
| + public int getRotationDegrees() { |
| + switch (mRotation) { |
| + case Surface.ROTATION_0: |
| + return 0; |
| + case Surface.ROTATION_90: |
| + return 90; |
| + case Surface.ROTATION_180: |
| + return 180; |
| + case Surface.ROTATION_270: |
| + return 270; |
| + } |
| + |
| + // This should not happen. |
| + assert false; |
| + return 0; |
| + } |
| + |
| + /** |
| * @return A scaling factor for the Density Independent Pixel unit. |
| */ |
| public float getDipScale() { |
| @@ -156,6 +187,48 @@ public class DisplayAndroid { |
| } |
| /** |
| + * @return Number of bits per pixel. |
| + */ |
| + public int getBitsPerPixel() { |
| + return mPixelFormatInfo.bitsPerPixel; |
| + } |
| + |
| + /** |
| + * @return Number of bits per each color component. |
| + */ |
| + @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; |
| + } |
| + } |
| + |
| + /** |
| * Add observer. Note repeat observers will be called only one. |
| * Observers are held only weakly by Display. |
| */ |
| @@ -192,12 +265,17 @@ public class DisplayAndroid { |
| mSize = new Point(); |
| mPhysicalSize = new Point(); |
| mDisplayMetrics = new DisplayMetrics(); |
| - updateFromDisplay(display); |
| + mPixelFormatInfo = new PixelFormat(); |
| } |
| + @SuppressWarnings("deprecation") |
| @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) |
| /* package */ void updateFromDisplay(Display display) { |
| - float oldDensity = mDisplayMetrics.density; |
| + 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); |
| @@ -208,11 +286,24 @@ public class DisplayAndroid { |
| display.getRealSize(mPhysicalSize); |
| } |
| - int newRotation = display.getRotation(); |
| - boolean rotationChanged = newRotation != mRotation; |
| - mRotation = newRotation; |
| + // 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); |
| + } |
| + |
| + mRotation = display.getRotation(); |
| + |
| + final boolean noChanges = oldSize.equals(mSize) && oldPhysicalSize.equals(mPhysicalSize) |
| + && oldDensity == mDisplayMetrics.density && oldPixelFormatId == mPixelFormatId |
| + && oldRotation == mRotation; |
| + if (noChanges) return; |
| + |
| + getManager().updateDisplayOnNativeSide(this); |
| - if (rotationChanged) { |
| + if (oldRotation != mRotation) { |
| DisplayAndroidObserver[] observers = getObservers(); |
| for (DisplayAndroidObserver o : observers) { |
| o.onRotationChanged(mRotation); |