| 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..8bae484e5514aef208e1d7af99723962d73598ce
|
| --- /dev/null
|
| +++ b/ui/android/java/src/org/chromium/ui/display/VirtualDisplayAndroid.java
|
| @@ -0,0 +1,119 @@
|
| +// 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 {
|
| + private final int mDisplayId;
|
| + private Point mSize;
|
| + private Point mPhysicalSize;
|
| + private float mDipScale;
|
| + private int mBitsPerPixel;
|
| + private int mBitsPerComponent;
|
| + private int mRotation;
|
| +
|
| + public static VirtualDisplayAndroid createVirtualDisplay() {
|
| + VirtualDisplayAndroid display = new VirtualDisplayAndroid(
|
| + getManager().getNextVirtualDisplayId());
|
| + 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 = physicalSize == null ? mPhysicalSize : physicalSize;
|
| + mDipScale = dipScale == null ? mDipScale : dipScale;
|
| + mBitsPerPixel = bitsPerPixel == null ? mBitsPerPixel : bitsPerPixel;
|
| + mBitsPerComponent = bitsPerComponent == null ? mBitsPerComponent : bitsPerComponent;
|
| + mRotation = rotation == 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 getDisplayId() {
|
| + 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);
|
| + }
|
| +}
|
|
|