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 075754c76eb64468255b561e9b672d44ef45acac..1717e9cf1076afa849857f337cbc58b3da4a2ad7 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; |
| @@ -49,6 +51,7 @@ public class DisplayAndroid { |
| private final Point mSize; |
| private final Point mPhysicalSize; |
| private final DisplayMetrics mDisplayMetrics; |
| + private int mPixelFormatId; |
| private int mRotation; |
| // When this object exists, a positive value means that the forced DIP scale is set and |
| @@ -97,6 +100,13 @@ public class DisplayAndroid { |
| } |
| /** |
| + * @return Display id as defined in Android's Display. |
| + */ |
| + public int getSdkDisplayId() { |
| + return mSdkDisplayId; |
| + } |
| + |
| + /** |
| * @return Display height in physical pixels. |
| */ |
| public int getDisplayHeight() { |
| @@ -132,6 +142,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() { |
| @@ -139,6 +169,50 @@ public class DisplayAndroid { |
| } |
| /** |
| + * @return Number of bits per pixel. |
| + */ |
| + public int getBitsPerPixel() { |
| + PixelFormat info = new PixelFormat(); |
|
boliu
2016/11/01 17:11:04
move this to updateFromDisplay
allocating heap ob
Tima Vaisburd
2016/11/01 23:04:36
Done.
|
| + PixelFormat.getPixelFormatInfo(mPixelFormatId, info); |
| + return info.bitsPerPixel; |
| + } |
| + |
| + /** |
| + * @return Number of bits per each color component. |
| + */ |
| + @SuppressWarnings("deprecation") |
| + public int getBitsPerComponent() { |
|
boliu
2016/11/01 17:11:04
package
Tima Vaisburd
2016/11/01 23:04:36
Done.
|
| + 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. |
| */ |
| @@ -175,11 +249,19 @@ public class DisplayAndroid { |
| mSize = new Point(); |
| mPhysicalSize = new Point(); |
| mDisplayMetrics = new DisplayMetrics(); |
| + mPixelFormatId = PixelFormat.RGBA_8888; |
|
boliu
2016/11/01 17:11:04
move this to updateFromDisplay
Tima Vaisburd
2016/11/01 23:04:36
Done.
|
| updateFromDisplay(display); |
| } |
| + @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); |
| @@ -189,11 +271,21 @@ public class DisplayAndroid { |
| display.getRealSize(mPhysicalSize); |
| } |
| - int newRotation = display.getRotation(); |
| - boolean rotationChanged = newRotation != mRotation; |
| - mRotation = newRotation; |
| + // JellyBean MR1 and later always uses RGBA_8888. |
| + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { |
| + mPixelFormatId = display.getPixelFormat(); |
| + } |
| + |
| + 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); |