/* * Copyright (C) 2012 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.server.display; import android.graphics.Rect; import android.view.Display; import android.view.DisplayInfo; import android.view.Surface; import java.io.PrintWriter; import java.util.List; import libcore.util.Objects; /** * Describes how a logical display is configured. *
* At this time, we only support logical displays that are coupled to a particular * primary display device from which the logical display derives its basic properties * such as its size, density and refresh rate. *
* A logical display may be mirrored onto multiple display devices in addition to its * primary display device. Note that the contents of a logical display may not * always be visible, even on its primary display device, such as in the case where * the primary display device is currently mirroring content from a different * logical display. *
* This object is designed to encapsulate as much of the policy of logical * displays as possible. The idea is to make it easy to implement new kinds of * logical displays mostly by making local changes to this class. *
* Note: The display manager architecture does not actually require logical displays * to be associated with any individual display device. Logical displays and * display devices are orthogonal concepts. Some mapping will exist between * logical displays and display devices but it can be many-to-many and * and some might have no relation at all. *
* Logical displays are guarded by the {@link DisplayManagerService.SyncRoot} lock. *
*/ final class LogicalDisplay { private final DisplayInfo mBaseDisplayInfo = new DisplayInfo(); // The layer stack we use when the display has been blanked to prevent any // of its content from appearing. private static final int BLANK_LAYER_STACK = -1; private final int mDisplayId; private final int mLayerStack; private DisplayInfo mOverrideDisplayInfo; // set by the window manager private DisplayInfo mInfo; // The display device that this logical display is based on and which // determines the base metrics that it uses. private DisplayDevice mPrimaryDisplayDevice; private DisplayDeviceInfo mPrimaryDisplayDeviceInfo; // True if the logical display has unique content. private boolean mHasContent; // Temporary rectangle used when needed. private final Rect mTempLayerStackRect = new Rect(); private final Rect mTempDisplayRect = new Rect(); public LogicalDisplay(int displayId, int layerStack, DisplayDevice primaryDisplayDevice) { mDisplayId = displayId; mLayerStack = layerStack; mPrimaryDisplayDevice = primaryDisplayDevice; } /** * Gets the logical display id of this logical display. * * @return The logical display id. */ public int getDisplayIdLocked() { return mDisplayId; } /** * Gets the primary display device associated with this logical display. * * @return The primary display device. */ public DisplayDevice getPrimaryDisplayDeviceLocked() { return mPrimaryDisplayDevice; } /** * Gets information about the logical display. * * @return The device info, which should be treated as immutable by the caller. * The logical display should allocate a new display info object whenever * the data changes. */ public DisplayInfo getDisplayInfoLocked() { if (mInfo == null) { mInfo = new DisplayInfo(); if (mOverrideDisplayInfo != null) { mInfo.copyFrom(mOverrideDisplayInfo); mInfo.layerStack = mBaseDisplayInfo.layerStack; mInfo.name = mBaseDisplayInfo.name; } else { mInfo.copyFrom(mBaseDisplayInfo); } } return mInfo; } /** * Sets overridden logical display information from the window manager. * This method can be used to adjust application insets, rotation, and other * properties that the window manager takes care of. * * @param info The logical display information, may be null. */ public boolean setDisplayInfoOverrideFromWindowManagerLocked(DisplayInfo info) { if (info != null) { if (mOverrideDisplayInfo == null) { mOverrideDisplayInfo = new DisplayInfo(info); mInfo = null; return true; } if (!mOverrideDisplayInfo.equals(info)) { mOverrideDisplayInfo.copyFrom(info); mInfo = null; return true; } } else if (mOverrideDisplayInfo != null) { mOverrideDisplayInfo = null; mInfo = null; return true; } return false; } /** * Returns true if the logical display is in a valid state. * This method should be checked after calling {@link #updateLocked} to handle the * case where a logical display should be removed because all of its associated * display devices are gone or if it is otherwise no longer needed. * * @return True if the logical display is still valid. */ public boolean isValidLocked() { return mPrimaryDisplayDevice != null; } /** * Updates the state of the logical display based on the available display devices. * The logical display might become invalid if it is attached to a display device * that no longer exists. * * @param devices The list of all connected display devices. */ public void updateLocked(List* If the display has unique content then we will try to ensure that it is * visible on at least its primary display device. Otherwise we will ignore the * logical display and perhaps show mirrored content on the primary display device. *
* * @return True if the display has unique content. */ public boolean hasContentLocked() { return mHasContent; } /** * Sets whether the logical display has unique content. * * @param hasContent True if the display has unique content. */ public void setHasContentLocked(boolean hasContent) { mHasContent = hasContent; } public void dumpLocked(PrintWriter pw) { pw.println("mDisplayId=" + mDisplayId); pw.println("mLayerStack=" + mLayerStack); pw.println("mHasContent=" + mHasContent); pw.println("mPrimaryDisplayDevice=" + (mPrimaryDisplayDevice != null ? mPrimaryDisplayDevice.getNameLocked() : "null")); pw.println("mBaseDisplayInfo=" + mBaseDisplayInfo); pw.println("mOverrideDisplayInfo=" + mOverrideDisplayInfo); } }