Chromium Code Reviews| Index: ui/android/java/src/org/chromium/ui/display/DisplayAndroidManager.java |
| diff --git a/ui/android/java/src/org/chromium/ui/display/DisplayAndroidManager.java b/ui/android/java/src/org/chromium/ui/display/DisplayAndroidManager.java |
| index dd86c1e152987fb92f81c3f873db1459a87e09d8..5aaff6b979247db49365354cf1bf5f1cf385631b 100644 |
| --- a/ui/android/java/src/org/chromium/ui/display/DisplayAndroidManager.java |
| +++ b/ui/android/java/src/org/chromium/ui/display/DisplayAndroidManager.java |
| @@ -17,11 +17,13 @@ import android.view.WindowManager; |
| import org.chromium.base.ContextUtils; |
| import org.chromium.base.ThreadUtils; |
| +import org.chromium.base.annotations.JNINamespace; |
| import org.chromium.ui.gfx.DeviceDisplayInfo; |
| /** |
| * DisplayAndroidManager is a class that informs its observers Display changes. |
| */ |
| +@JNINamespace("display") |
| /* package */ class DisplayAndroidManager { |
| /** |
| * DisplayListenerBackend is an interface that abstract the mechanism used for the actual |
| @@ -158,6 +160,13 @@ import org.chromium.ui.gfx.DeviceDisplayInfo; |
| @Override |
| public void onDisplayRemoved(int sdkDisplayId) { |
| + // Never remove the primary display. |
| + if (sdkDisplayId == Display.DEFAULT_DISPLAY) return; |
| + |
| + DisplayAndroid displayAndroid = mIdMap.get(sdkDisplayId); |
| + if (displayAndroid == null) return; |
| + |
| + nativeRemoveDisplay(sdkDisplayId); |
| mIdMap.remove(sdkDisplayId); |
| } |
| @@ -209,6 +218,14 @@ import org.chromium.ui.gfx.DeviceDisplayInfo; |
| mIdMap = new SparseArray<>(); |
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { |
| mBackend = new DisplayListenerBackendImpl(); |
| + // Make sure the display map contains the built-in primary display if it exists. |
| + // The primary display is never removed. |
| + Display display = getDisplayManager().getDisplay(Display.DEFAULT_DISPLAY); |
| + if (display != null) { |
| + addDisplay(display); |
| + } else { |
| + nativeSetNoPrimaryDisplay(); |
|
mthiesse
2016/10/27 14:30:30
This feels scary - should we not just use getDispl
Tima Vaisburd
2016/10/27 17:56:23
Sorry, I did not quite get your idea. Do you sugge
mthiesse
2016/10/27 19:51:51
Yes, that's what I'm suggesting. I'm not sure what
Tima Vaisburd
2016/10/27 20:22:30
I do not know, maybe not possible.
Another idea is
mthiesse
2016/10/27 20:29:13
I'll have to defer to Bo here, I don't know enough
boliu
2016/10/27 22:17:49
I don't this that can ever happen. throw an except
Tima Vaisburd
2016/10/31 23:36:15
Got Display from the application context. I had to
|
| + } |
| } else { |
| Display display = getDisplayFromContext(getContext()); |
| mBackend = new DisplayListenerAPI16(display.getDisplayId()); |
| @@ -238,6 +255,22 @@ import org.chromium.ui.gfx.DeviceDisplayInfo; |
| int sdkDisplayId = display.getDisplayId(); |
| DisplayAndroid displayAndroid = new DisplayAndroid(display); |
| mIdMap.put(sdkDisplayId, displayAndroid); |
| + |
| + updateDisplayOnNativeSide(displayAndroid); |
| return displayAndroid; |
| } |
| + |
| + /* package */ void updateDisplayOnNativeSide(DisplayAndroid displayAndroid) { |
| + nativeUpdateDisplay(displayAndroid.getSdkDisplayId(), |
| + displayAndroid.getPhysicalDisplayWidth(), displayAndroid.getPhysicalDisplayHeight(), |
| + displayAndroid.getDisplayWidth(), displayAndroid.getDisplayHeight(), |
| + displayAndroid.getDIPScale(), displayAndroid.getRotationDegrees(), |
| + displayAndroid.getBitsPerPixel(), displayAndroid.getBitsPerComponent()); |
| + } |
| + |
| + private static native void nativeUpdateDisplay(int sdkDisplayId, int physicalWidth, |
| + int physicalHeight, int width, int height, float dipScale, int rotationDegrees, |
| + int bitsPerPixel, int bitsPerComponent); |
| + private static native void nativeRemoveDisplay(int sdkDisplayId); |
| + private static native void nativeSetNoPrimaryDisplay(); |
| } |