Chromium Code Reviews| Index: ui/android/java/src/org/chromium/ui/display/VirtualDisplayAndroid.java |
| diff --git a/ui/android/java/src/org/chromium/ui/display/VirtualDisplayAndroid.java b/ui/android/java/src/org/chromium/ui/display/VirtualDisplayAndroid.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..448d283d2a7bcc6b94f8e14b5fa37eb5dbe637b0 |
| --- /dev/null |
| +++ b/ui/android/java/src/org/chromium/ui/display/VirtualDisplayAndroid.java |
| @@ -0,0 +1,121 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.ui.display; |
| + |
| +import android.graphics.Point; |
| + |
| +/** |
| + * An instance of DisplayAndroid not associated with any physical display. |
| + */ |
| +public class VirtualDisplayAndroid extends DisplayAndroid { |
|
amp
2016/11/23 19:18:09
Would it be possible to add an 'isVirtual' field t
mthiesse
2016/11/23 19:22:23
Preferably, virtual vs. physical displays would be
amp
2016/11/23 19:34:34
I agree that ideally no code would need to know th
mthiesse
2016/11/23 19:44:51
I really don't think we should convey VR-ness or w
amp
2016/11/23 20:09:22
I'm interested in other solutions if possible. An
|
| + private final int mDisplayId; |
| + private Point mSize; |
| + private Point mPhysicalSize; |
| + private float mDipScale; |
| + private int mBitsPerPixel; |
| + private int mBitsPerComponent; |
| + private int mRotation; |
| + |
| + /** |
| + * @param displayId Display ID for this virtual display. |
| + */ |
| + public static VirtualDisplayAndroid createVirtualDisplay(int displayId) { |
| + VirtualDisplayAndroid display = new VirtualDisplayAndroid(displayId); |
| + getManager().addVirtualDisplay(display); |
| + return display; |
| + } |
| + |
| + private VirtualDisplayAndroid(int displayId) { |
| + mDisplayId = displayId; |
| + } |
| + |
| + /** |
| + * @param other Sets the properties of this display to those of the other display. |
| + */ |
| + public void setTo(DisplayAndroid other) { |
| + update(new Point(other.getDisplayWidth(), other.getDisplayHeight()), |
| + new Point(other.getPhysicalDisplayWidth(), other.getPhysicalDisplayHeight()), |
| + other.getDipScale(), other.getBitsPerPixel(), |
| + other.getBitsPerComponent(), other.getRotation()); |
| + } |
| + |
| + /** |
| + * Update the display to the provided parameters. Null values leave the parameter unchanged. |
| + */ |
| + public void update(Point size, Point physicalSize, Float dipScale, Integer bitsPerPixel, |
| + Integer bitsPerComponent, Integer rotation) { |
| + boolean dipScaleChanged = dipScale != null && mDipScale != dipScale; |
| + boolean rotationChanged = rotation != null && mRotation != rotation; |
| + mSize = size == null ? mSize : size; |
| + mPhysicalSize = size == null ? mPhysicalSize : physicalSize; |
| + mDipScale = size == null ? mDipScale : dipScale; |
| + mBitsPerPixel = size == null ? mBitsPerPixel : bitsPerPixel; |
| + mBitsPerComponent = size == null ? mBitsPerComponent : bitsPerComponent; |
| + mRotation = size == null ? mRotation : rotation; |
| + getManager().updateDisplayOnNativeSide(this); |
| + notifyObservers(dipScaleChanged, rotationChanged); |
| + } |
| + |
| + private void notifyObservers(boolean dipScaleChanged, boolean rotationChanged) { |
| + if (!dipScaleChanged && !rotationChanged) return; |
| + DisplayAndroidObserver[] observers = getObservers(); |
| + for (DisplayAndroidObserver o : observers) { |
| + if (dipScaleChanged) o.onDIPScaleChanged(mDipScale); |
| + if (rotationChanged) o.onRotationChanged(mRotation); |
| + } |
| + } |
| + |
| + @Override |
| + public int getSdkDisplayId() { |
| + return mDisplayId; |
| + } |
| + |
| + @Override |
| + public int getDisplayHeight() { |
| + return mSize.y; |
| + } |
| + |
| + @Override |
| + public int getDisplayWidth() { |
| + return mSize.x; |
| + } |
| + |
| + @Override |
| + public int getPhysicalDisplayHeight() { |
| + return mPhysicalSize.y; |
| + } |
| + |
| + @Override |
| + public int getPhysicalDisplayWidth() { |
| + return mPhysicalSize.x; |
| + } |
| + |
| + @Override |
| + public int getRotation() { |
| + return mRotation; |
| + } |
| + |
| + @Override |
| + public float getDipScale() { |
| + return mDipScale; |
| + } |
| + |
| + @Override |
| + /* package */ int getBitsPerPixel() { |
| + return mBitsPerPixel; |
| + } |
| + |
| + @Override |
| + /* package */ int getBitsPerComponent() { |
| + return mBitsPerComponent; |
| + } |
| + |
| + /** |
| + * Removes this Virtual Display from the DisplayManger. |
| + */ |
| + public void destroy() { |
| + getManager().removeVirtualDisplay(this); |
| + } |
| +} |