Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(393)

Unified Diff: ui/android/java/src/org/chromium/ui/display/DisplayAndroid.java

Issue 2416403002: Reland of Android: support multiple displays on C++ side (Closed)
Patch Set: Ensure primary display. New jni scheme Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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();
+ PixelFormat.getPixelFormatInfo(mPixelFormatId, info);
+ return info.bitsPerPixel;
+ }
+
+ /**
+ * @return Number of bits per each color component.
+ */
+ @SuppressWarnings("deprecation")
+ public 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.
*/
@@ -175,11 +249,19 @@ public class DisplayAndroid {
mSize = new Point();
mPhysicalSize = new Point();
mDisplayMetrics = new DisplayMetrics();
+ mPixelFormatId = PixelFormat.RGBA_8888;
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);
mthiesse 2016/10/27 14:30:30 I think this should be moved into the manager, Dis
Tima Vaisburd 2016/10/27 17:56:23 I thought about that, this method could have retur
Tima Vaisburd 2016/10/27 18:34:26 On the second thought: yes, I will split this meth
boliu 2016/10/27 22:17:49 Whatever you end up doing, do keep this property.
Tima Vaisburd 2016/10/31 23:36:15 The split is not done, I'll try in the next PS.
- if (rotationChanged) {
+ if (oldRotation != mRotation) {
DisplayAndroidObserver[] observers = getObservers();
for (DisplayAndroidObserver o : observers) {
o.onRotationChanged(mRotation);

Powered by Google App Engine
This is Rietveld 408576698