Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.server.display; |
| 18 | |
| 19 | import android.graphics.Rect; |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 20 | import android.hardware.display.DisplayManagerInternal; |
Jeff Brown | c5df37c | 2012-09-13 11:45:07 -0700 | [diff] [blame] | 21 | import android.view.Display; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 22 | import android.view.DisplayInfo; |
| 23 | import android.view.Surface; |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 24 | import android.view.SurfaceControl; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 25 | |
Adrian Roos | 8c28c7c | 2018-08-20 13:43:38 +0200 | [diff] [blame] | 26 | import com.android.server.wm.utils.InsetUtils; |
| 27 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 28 | import java.io.PrintWriter; |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 29 | import java.util.Arrays; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 30 | import java.util.List; |
Narayan Kamath | 607223f | 2018-02-19 14:09:02 +0000 | [diff] [blame] | 31 | import java.util.Objects; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 32 | |
| 33 | /** |
| 34 | * Describes how a logical display is configured. |
| 35 | * <p> |
| 36 | * At this time, we only support logical displays that are coupled to a particular |
| 37 | * primary display device from which the logical display derives its basic properties |
| 38 | * such as its size, density and refresh rate. |
| 39 | * </p><p> |
| 40 | * A logical display may be mirrored onto multiple display devices in addition to its |
| 41 | * primary display device. Note that the contents of a logical display may not |
| 42 | * always be visible, even on its primary display device, such as in the case where |
| 43 | * the primary display device is currently mirroring content from a different |
| 44 | * logical display. |
| 45 | * </p><p> |
| 46 | * This object is designed to encapsulate as much of the policy of logical |
| 47 | * displays as possible. The idea is to make it easy to implement new kinds of |
| 48 | * logical displays mostly by making local changes to this class. |
| 49 | * </p><p> |
| 50 | * Note: The display manager architecture does not actually require logical displays |
| 51 | * to be associated with any individual display device. Logical displays and |
| 52 | * display devices are orthogonal concepts. Some mapping will exist between |
| 53 | * logical displays and display devices but it can be many-to-many and |
| 54 | * and some might have no relation at all. |
| 55 | * </p><p> |
| 56 | * Logical displays are guarded by the {@link DisplayManagerService.SyncRoot} lock. |
| 57 | * </p> |
| 58 | */ |
| 59 | final class LogicalDisplay { |
| 60 | private final DisplayInfo mBaseDisplayInfo = new DisplayInfo(); |
| 61 | |
Jeff Brown | 8ec0943 | 2012-10-16 16:19:23 -0700 | [diff] [blame] | 62 | // The layer stack we use when the display has been blanked to prevent any |
| 63 | // of its content from appearing. |
| 64 | private static final int BLANK_LAYER_STACK = -1; |
| 65 | |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 66 | private final int mDisplayId; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 67 | private final int mLayerStack; |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 68 | /** |
| 69 | * Override information set by the window manager. Will be reported instead of {@link #mInfo} |
| 70 | * if not null. |
| 71 | * @see #setDisplayInfoOverrideFromWindowManagerLocked(DisplayInfo) |
| 72 | * @see #getDisplayInfoLocked() |
| 73 | */ |
| 74 | private DisplayInfo mOverrideDisplayInfo; |
| 75 | /** |
| 76 | * Current display info. Initialized with {@link #mBaseDisplayInfo}. Set to {@code null} if |
| 77 | * needs to be updated. |
| 78 | * @see #getDisplayInfoLocked() |
| 79 | */ |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 80 | private DisplayInfo mInfo; |
| 81 | |
| 82 | // The display device that this logical display is based on and which |
| 83 | // determines the base metrics that it uses. |
| 84 | private DisplayDevice mPrimaryDisplayDevice; |
| 85 | private DisplayDeviceInfo mPrimaryDisplayDeviceInfo; |
| 86 | |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 87 | // True if the logical display has unique content. |
| 88 | private boolean mHasContent; |
| 89 | |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 90 | private int mRequestedModeId; |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 91 | private int mRequestedColorMode; |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 92 | |
Filip Gruszczynski | d2e8640 | 2015-02-19 13:05:03 -0800 | [diff] [blame] | 93 | // The display offsets to apply to the display projection. |
| 94 | private int mDisplayOffsetX; |
| 95 | private int mDisplayOffsetY; |
| 96 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 97 | // Temporary rectangle used when needed. |
Mathias Agopian | 63f1c43 | 2012-09-04 19:29:13 -0700 | [diff] [blame] | 98 | private final Rect mTempLayerStackRect = new Rect(); |
| 99 | private final Rect mTempDisplayRect = new Rect(); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 100 | |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 101 | public LogicalDisplay(int displayId, int layerStack, DisplayDevice primaryDisplayDevice) { |
| 102 | mDisplayId = displayId; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 103 | mLayerStack = layerStack; |
| 104 | mPrimaryDisplayDevice = primaryDisplayDevice; |
| 105 | } |
| 106 | |
| 107 | /** |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 108 | * Gets the logical display id of this logical display. |
| 109 | * |
| 110 | * @return The logical display id. |
| 111 | */ |
| 112 | public int getDisplayIdLocked() { |
| 113 | return mDisplayId; |
| 114 | } |
| 115 | |
| 116 | /** |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 117 | * Gets the primary display device associated with this logical display. |
| 118 | * |
| 119 | * @return The primary display device. |
| 120 | */ |
| 121 | public DisplayDevice getPrimaryDisplayDeviceLocked() { |
| 122 | return mPrimaryDisplayDevice; |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Gets information about the logical display. |
| 127 | * |
| 128 | * @return The device info, which should be treated as immutable by the caller. |
| 129 | * The logical display should allocate a new display info object whenever |
| 130 | * the data changes. |
| 131 | */ |
| 132 | public DisplayInfo getDisplayInfoLocked() { |
| 133 | if (mInfo == null) { |
| 134 | mInfo = new DisplayInfo(); |
P.Y. Laligand | ed896d4 | 2015-05-12 10:43:38 -0700 | [diff] [blame] | 135 | mInfo.copyFrom(mBaseDisplayInfo); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 136 | if (mOverrideDisplayInfo != null) { |
P.Y. Laligand | ed896d4 | 2015-05-12 10:43:38 -0700 | [diff] [blame] | 137 | mInfo.appWidth = mOverrideDisplayInfo.appWidth; |
| 138 | mInfo.appHeight = mOverrideDisplayInfo.appHeight; |
| 139 | mInfo.smallestNominalAppWidth = mOverrideDisplayInfo.smallestNominalAppWidth; |
| 140 | mInfo.smallestNominalAppHeight = mOverrideDisplayInfo.smallestNominalAppHeight; |
| 141 | mInfo.largestNominalAppWidth = mOverrideDisplayInfo.largestNominalAppWidth; |
| 142 | mInfo.largestNominalAppHeight = mOverrideDisplayInfo.largestNominalAppHeight; |
| 143 | mInfo.logicalWidth = mOverrideDisplayInfo.logicalWidth; |
| 144 | mInfo.logicalHeight = mOverrideDisplayInfo.logicalHeight; |
| 145 | mInfo.overscanLeft = mOverrideDisplayInfo.overscanLeft; |
| 146 | mInfo.overscanTop = mOverrideDisplayInfo.overscanTop; |
| 147 | mInfo.overscanRight = mOverrideDisplayInfo.overscanRight; |
| 148 | mInfo.overscanBottom = mOverrideDisplayInfo.overscanBottom; |
| 149 | mInfo.rotation = mOverrideDisplayInfo.rotation; |
Adrian Roos | 1cf58505 | 2018-01-03 18:43:27 +0100 | [diff] [blame] | 150 | mInfo.displayCutout = mOverrideDisplayInfo.displayCutout; |
P.Y. Laligand | ed896d4 | 2015-05-12 10:43:38 -0700 | [diff] [blame] | 151 | mInfo.logicalDensityDpi = mOverrideDisplayInfo.logicalDensityDpi; |
Jeff Brown | fe4ad33 | 2015-06-09 18:26:31 -0700 | [diff] [blame] | 152 | mInfo.physicalXDpi = mOverrideDisplayInfo.physicalXDpi; |
| 153 | mInfo.physicalYDpi = mOverrideDisplayInfo.physicalYDpi; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 154 | } |
| 155 | } |
| 156 | return mInfo; |
| 157 | } |
| 158 | |
| 159 | /** |
Andrii Kulian | cd09799 | 2017-03-23 18:31:59 -0700 | [diff] [blame] | 160 | * @see DisplayManagerInternal#getNonOverrideDisplayInfo(int, DisplayInfo) |
| 161 | */ |
| 162 | void getNonOverrideDisplayInfoLocked(DisplayInfo outInfo) { |
| 163 | outInfo.copyFrom(mBaseDisplayInfo); |
| 164 | } |
| 165 | |
| 166 | /** |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 167 | * Sets overridden logical display information from the window manager. |
| 168 | * This method can be used to adjust application insets, rotation, and other |
| 169 | * properties that the window manager takes care of. |
| 170 | * |
| 171 | * @param info The logical display information, may be null. |
| 172 | */ |
Jeff Brown | ef981a4 | 2013-08-07 14:13:37 -0700 | [diff] [blame] | 173 | public boolean setDisplayInfoOverrideFromWindowManagerLocked(DisplayInfo info) { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 174 | if (info != null) { |
| 175 | if (mOverrideDisplayInfo == null) { |
| 176 | mOverrideDisplayInfo = new DisplayInfo(info); |
| 177 | mInfo = null; |
Jeff Brown | ef981a4 | 2013-08-07 14:13:37 -0700 | [diff] [blame] | 178 | return true; |
| 179 | } |
| 180 | if (!mOverrideDisplayInfo.equals(info)) { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 181 | mOverrideDisplayInfo.copyFrom(info); |
| 182 | mInfo = null; |
Jeff Brown | ef981a4 | 2013-08-07 14:13:37 -0700 | [diff] [blame] | 183 | return true; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 184 | } |
| 185 | } else if (mOverrideDisplayInfo != null) { |
| 186 | mOverrideDisplayInfo = null; |
| 187 | mInfo = null; |
Jeff Brown | ef981a4 | 2013-08-07 14:13:37 -0700 | [diff] [blame] | 188 | return true; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 189 | } |
Jeff Brown | ef981a4 | 2013-08-07 14:13:37 -0700 | [diff] [blame] | 190 | return false; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 191 | } |
| 192 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 193 | /** |
| 194 | * Returns true if the logical display is in a valid state. |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 195 | * This method should be checked after calling {@link #updateLocked} to handle the |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 196 | * case where a logical display should be removed because all of its associated |
| 197 | * display devices are gone or if it is otherwise no longer needed. |
| 198 | * |
| 199 | * @return True if the logical display is still valid. |
| 200 | */ |
| 201 | public boolean isValidLocked() { |
| 202 | return mPrimaryDisplayDevice != null; |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * Updates the state of the logical display based on the available display devices. |
| 207 | * The logical display might become invalid if it is attached to a display device |
| 208 | * that no longer exists. |
| 209 | * |
| 210 | * @param devices The list of all connected display devices. |
| 211 | */ |
| 212 | public void updateLocked(List<DisplayDevice> devices) { |
| 213 | // Nothing to update if already invalid. |
| 214 | if (mPrimaryDisplayDevice == null) { |
| 215 | return; |
| 216 | } |
| 217 | |
| 218 | // Check whether logical display has become invalid. |
| 219 | if (!devices.contains(mPrimaryDisplayDevice)) { |
| 220 | mPrimaryDisplayDevice = null; |
| 221 | return; |
| 222 | } |
| 223 | |
| 224 | // Bootstrap the logical display using its associated primary physical display. |
| 225 | // We might use more elaborate configurations later. It's possible that the |
| 226 | // configuration of several physical displays might be used to determine the |
| 227 | // logical display that they are sharing. (eg. Adjust size for pixel-perfect |
| 228 | // mirroring over HDMI.) |
| 229 | DisplayDeviceInfo deviceInfo = mPrimaryDisplayDevice.getDisplayDeviceInfoLocked(); |
Narayan Kamath | 607223f | 2018-02-19 14:09:02 +0000 | [diff] [blame] | 230 | if (!Objects.equals(mPrimaryDisplayDeviceInfo, deviceInfo)) { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 231 | mBaseDisplayInfo.layerStack = mLayerStack; |
Jeff Brown | c5df37c | 2012-09-13 11:45:07 -0700 | [diff] [blame] | 232 | mBaseDisplayInfo.flags = 0; |
Jeff Brown | 77aebfd | 2012-10-01 21:07:03 -0700 | [diff] [blame] | 233 | if ((deviceInfo.flags & DisplayDeviceInfo.FLAG_SUPPORTS_PROTECTED_BUFFERS) != 0) { |
| 234 | mBaseDisplayInfo.flags |= Display.FLAG_SUPPORTS_PROTECTED_BUFFERS; |
Jeff Brown | c5df37c | 2012-09-13 11:45:07 -0700 | [diff] [blame] | 235 | } |
Jeff Brown | f0681b3 | 2012-10-23 17:35:57 -0700 | [diff] [blame] | 236 | if ((deviceInfo.flags & DisplayDeviceInfo.FLAG_SECURE) != 0) { |
| 237 | mBaseDisplayInfo.flags |= Display.FLAG_SECURE; |
| 238 | } |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 239 | if ((deviceInfo.flags & DisplayDeviceInfo.FLAG_PRIVATE) != 0) { |
| 240 | mBaseDisplayInfo.flags |= Display.FLAG_PRIVATE; |
Andrii Kulian | 250d653 | 2017-02-08 23:30:45 -0800 | [diff] [blame] | 241 | // For private displays by default content is destroyed on removal. |
| 242 | mBaseDisplayInfo.removeMode = Display.REMOVE_MODE_DESTROY_CONTENT; |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 243 | } |
rongliu | 1e90fc3 | 2017-10-04 17:30:30 -0700 | [diff] [blame] | 244 | if ((deviceInfo.flags & DisplayDeviceInfo.FLAG_DESTROY_CONTENT_ON_REMOVAL) != 0) { |
| 245 | mBaseDisplayInfo.removeMode = Display.REMOVE_MODE_DESTROY_CONTENT; |
| 246 | } |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 247 | if ((deviceInfo.flags & DisplayDeviceInfo.FLAG_PRESENTATION) != 0) { |
| 248 | mBaseDisplayInfo.flags |= Display.FLAG_PRESENTATION; |
| 249 | } |
Adam Powell | 49e7ff9 | 2015-05-14 16:18:53 -0700 | [diff] [blame] | 250 | if ((deviceInfo.flags & DisplayDeviceInfo.FLAG_ROUND) != 0) { |
| 251 | mBaseDisplayInfo.flags |= Display.FLAG_ROUND; |
| 252 | } |
Andrii Kulian | 7211d2e | 2017-01-27 15:58:05 -0800 | [diff] [blame] | 253 | if ((deviceInfo.flags & DisplayDeviceInfo.FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD) != 0) { |
| 254 | mBaseDisplayInfo.flags |= Display.FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD; |
Andrii Kulian | fc8f82b | 2017-01-26 13:17:27 -0800 | [diff] [blame] | 255 | } |
Louis Chang | bd48dca | 2018-08-29 17:44:34 +0800 | [diff] [blame] | 256 | if ((deviceInfo.flags & DisplayDeviceInfo.FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS) != 0) { |
| 257 | mBaseDisplayInfo.flags |= Display.FLAG_SHOULD_SHOW_SYSTEM_DECORATIONS; |
| 258 | } |
Adrian Roos | 8c28c7c | 2018-08-20 13:43:38 +0200 | [diff] [blame] | 259 | Rect maskingInsets = getMaskingInsets(deviceInfo); |
| 260 | int maskedWidth = deviceInfo.width - maskingInsets.left - maskingInsets.right; |
| 261 | int maskedHeight = deviceInfo.height - maskingInsets.top - maskingInsets.bottom; |
| 262 | |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 263 | mBaseDisplayInfo.type = deviceInfo.type; |
| 264 | mBaseDisplayInfo.address = deviceInfo.address; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 265 | mBaseDisplayInfo.name = deviceInfo.name; |
Wale Ogunwale | 361ca21 | 2014-11-20 11:42:38 -0800 | [diff] [blame] | 266 | mBaseDisplayInfo.uniqueId = deviceInfo.uniqueId; |
Adrian Roos | 8c28c7c | 2018-08-20 13:43:38 +0200 | [diff] [blame] | 267 | mBaseDisplayInfo.appWidth = maskedWidth; |
| 268 | mBaseDisplayInfo.appHeight = maskedHeight; |
| 269 | mBaseDisplayInfo.logicalWidth = maskedWidth; |
| 270 | mBaseDisplayInfo.logicalHeight = maskedHeight; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 271 | mBaseDisplayInfo.rotation = Surface.ROTATION_0; |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 272 | mBaseDisplayInfo.modeId = deviceInfo.modeId; |
| 273 | mBaseDisplayInfo.defaultModeId = deviceInfo.defaultModeId; |
| 274 | mBaseDisplayInfo.supportedModes = Arrays.copyOf( |
| 275 | deviceInfo.supportedModes, deviceInfo.supportedModes.length); |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 276 | mBaseDisplayInfo.colorMode = deviceInfo.colorMode; |
| 277 | mBaseDisplayInfo.supportedColorModes = Arrays.copyOf( |
| 278 | deviceInfo.supportedColorModes, |
| 279 | deviceInfo.supportedColorModes.length); |
Michael Wright | 9ff94c0 | 2016-03-30 18:05:40 -0700 | [diff] [blame] | 280 | mBaseDisplayInfo.hdrCapabilities = deviceInfo.hdrCapabilities; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 281 | mBaseDisplayInfo.logicalDensityDpi = deviceInfo.densityDpi; |
| 282 | mBaseDisplayInfo.physicalXDpi = deviceInfo.xDpi; |
| 283 | mBaseDisplayInfo.physicalYDpi = deviceInfo.yDpi; |
Andy McFadden | e8b1aeb | 2014-06-13 14:05:40 -0700 | [diff] [blame] | 284 | mBaseDisplayInfo.appVsyncOffsetNanos = deviceInfo.appVsyncOffsetNanos; |
| 285 | mBaseDisplayInfo.presentationDeadlineNanos = deviceInfo.presentationDeadlineNanos; |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 286 | mBaseDisplayInfo.state = deviceInfo.state; |
Adrian Roos | 8c28c7c | 2018-08-20 13:43:38 +0200 | [diff] [blame] | 287 | mBaseDisplayInfo.smallestNominalAppWidth = maskedWidth; |
| 288 | mBaseDisplayInfo.smallestNominalAppHeight = maskedHeight; |
| 289 | mBaseDisplayInfo.largestNominalAppWidth = maskedWidth; |
| 290 | mBaseDisplayInfo.largestNominalAppHeight = maskedHeight; |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 291 | mBaseDisplayInfo.ownerUid = deviceInfo.ownerUid; |
| 292 | mBaseDisplayInfo.ownerPackageName = deviceInfo.ownerPackageName; |
Adrian Roos | 8c28c7c | 2018-08-20 13:43:38 +0200 | [diff] [blame] | 293 | boolean maskCutout = |
| 294 | (deviceInfo.flags & DisplayDeviceInfo.FLAG_MASK_DISPLAY_CUTOUT) != 0; |
| 295 | mBaseDisplayInfo.displayCutout = maskCutout ? null : deviceInfo.displayCutout; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 296 | |
| 297 | mPrimaryDisplayDeviceInfo = deviceInfo; |
| 298 | mInfo = null; |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | /** |
Adrian Roos | 9ee5dff | 2018-08-22 20:19:49 +0200 | [diff] [blame] | 303 | * Return the insets currently applied to the display. |
| 304 | * |
| 305 | * Note that the base DisplayInfo already takes these insets into account, so if you want to |
| 306 | * find out the <b>true</b> size of the display, you need to add them back to the logical |
| 307 | * dimensions. |
| 308 | */ |
| 309 | public Rect getInsets() { |
| 310 | return getMaskingInsets(mPrimaryDisplayDeviceInfo); |
| 311 | } |
| 312 | |
| 313 | /** |
Adrian Roos | 8c28c7c | 2018-08-20 13:43:38 +0200 | [diff] [blame] | 314 | * Returns insets in ROTATION_0 for areas that are masked. |
| 315 | */ |
| 316 | private static Rect getMaskingInsets(DisplayDeviceInfo deviceInfo) { |
| 317 | boolean maskCutout = (deviceInfo.flags & DisplayDeviceInfo.FLAG_MASK_DISPLAY_CUTOUT) != 0; |
| 318 | if (maskCutout && deviceInfo.displayCutout != null) { |
| 319 | return deviceInfo.displayCutout.getSafeInsets(); |
| 320 | } else { |
| 321 | return new Rect(); |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | /** |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 326 | * Applies the layer stack and transformation to the given display device |
| 327 | * so that it shows the contents of this logical display. |
| 328 | * |
| 329 | * We know that the given display device is only ever showing the contents of |
| 330 | * a single logical display, so this method is expected to blow away all of its |
| 331 | * transformation properties to make it happen regardless of what the |
| 332 | * display device was previously showing. |
| 333 | * |
| 334 | * The caller must have an open Surface transaction. |
| 335 | * |
| 336 | * The display device may not be the primary display device, in the case |
| 337 | * where the display is being mirrored. |
| 338 | * |
| 339 | * @param device The display device to modify. |
Jeff Brown | 8ec0943 | 2012-10-16 16:19:23 -0700 | [diff] [blame] | 340 | * @param isBlanked True if the device is being blanked. |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 341 | */ |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 342 | public void configureDisplayLocked(SurfaceControl.Transaction t, |
| 343 | DisplayDevice device, |
Jeff Brown | 8ec0943 | 2012-10-16 16:19:23 -0700 | [diff] [blame] | 344 | boolean isBlanked) { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 345 | // Set the layer stack. |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 346 | device.setLayerStackLocked(t, isBlanked ? BLANK_LAYER_STACK : mLayerStack); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 347 | |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 348 | // Set the color mode and mode. |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 349 | if (device == mPrimaryDisplayDevice) { |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 350 | device.requestDisplayModesLocked( |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 351 | mRequestedColorMode, mRequestedModeId); |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 352 | } else { |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 353 | device.requestDisplayModesLocked(0, 0); // Revert to default. |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | // Only grab the display info now as it may have been changed based on the requests above. |
| 357 | final DisplayInfo displayInfo = getDisplayInfoLocked(); |
| 358 | final DisplayDeviceInfo displayDeviceInfo = device.getDisplayDeviceInfoLocked(); |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 359 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 360 | // Set the viewport. |
| 361 | // This is the area of the logical display that we intend to show on the |
| 362 | // display device. For now, it is always the full size of the logical display. |
Mathias Agopian | 63f1c43 | 2012-09-04 19:29:13 -0700 | [diff] [blame] | 363 | mTempLayerStackRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 364 | |
| 365 | // Set the orientation. |
| 366 | // The orientation specifies how the physical coordinate system of the display |
| 367 | // is rotated when the contents of the logical display are rendered. |
| 368 | int orientation = Surface.ROTATION_0; |
Scott Anderson | 8786ed9 | 2013-11-01 13:27:39 -0700 | [diff] [blame] | 369 | if ((displayDeviceInfo.flags & DisplayDeviceInfo.FLAG_ROTATES_WITH_CONTENT) != 0) { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 370 | orientation = displayInfo.rotation; |
| 371 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 372 | |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 373 | // Apply the physical rotation of the display device itself. |
| 374 | orientation = (orientation + displayDeviceInfo.rotation) % 4; |
| 375 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 376 | // Set the frame. |
| 377 | // The frame specifies the rotated physical coordinates into which the viewport |
| 378 | // is mapped. We need to take care to preserve the aspect ratio of the viewport. |
| 379 | // Currently we maximize the area to fill the display, but we could try to be |
| 380 | // more clever and match resolutions. |
| 381 | boolean rotated = (orientation == Surface.ROTATION_90 |
| 382 | || orientation == Surface.ROTATION_270); |
| 383 | int physWidth = rotated ? displayDeviceInfo.height : displayDeviceInfo.width; |
| 384 | int physHeight = rotated ? displayDeviceInfo.width : displayDeviceInfo.height; |
| 385 | |
Adrian Roos | 8c28c7c | 2018-08-20 13:43:38 +0200 | [diff] [blame] | 386 | Rect maskingInsets = getMaskingInsets(displayDeviceInfo); |
| 387 | InsetUtils.rotateInsets(maskingInsets, orientation); |
| 388 | // Don't consider the masked area as available when calculating the scaling below. |
| 389 | physWidth -= maskingInsets.left + maskingInsets.right; |
| 390 | physHeight -= maskingInsets.top + maskingInsets.bottom; |
| 391 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 392 | // Determine whether the width or height is more constrained to be scaled. |
| 393 | // physWidth / displayInfo.logicalWidth => letter box |
| 394 | // or physHeight / displayInfo.logicalHeight => pillar box |
| 395 | // |
| 396 | // We avoid a division (and possible floating point imprecision) here by |
| 397 | // multiplying the fractions by the product of their denominators before |
| 398 | // comparing them. |
Mathias Agopian | 63f1c43 | 2012-09-04 19:29:13 -0700 | [diff] [blame] | 399 | int displayRectWidth, displayRectHeight; |
Jeff Brown | d46747a | 2015-04-15 19:02:36 -0700 | [diff] [blame] | 400 | if ((displayInfo.flags & Display.FLAG_SCALING_DISABLED) != 0) { |
| 401 | displayRectWidth = displayInfo.logicalWidth; |
| 402 | displayRectHeight = displayInfo.logicalHeight; |
| 403 | } else if (physWidth * displayInfo.logicalHeight |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 404 | < physHeight * displayInfo.logicalWidth) { |
| 405 | // Letter box. |
Mathias Agopian | 63f1c43 | 2012-09-04 19:29:13 -0700 | [diff] [blame] | 406 | displayRectWidth = physWidth; |
| 407 | displayRectHeight = displayInfo.logicalHeight * physWidth / displayInfo.logicalWidth; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 408 | } else { |
| 409 | // Pillar box. |
Mathias Agopian | 63f1c43 | 2012-09-04 19:29:13 -0700 | [diff] [blame] | 410 | displayRectWidth = displayInfo.logicalWidth * physHeight / displayInfo.logicalHeight; |
| 411 | displayRectHeight = physHeight; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 412 | } |
Mathias Agopian | 63f1c43 | 2012-09-04 19:29:13 -0700 | [diff] [blame] | 413 | int displayRectTop = (physHeight - displayRectHeight) / 2; |
| 414 | int displayRectLeft = (physWidth - displayRectWidth) / 2; |
| 415 | mTempDisplayRect.set(displayRectLeft, displayRectTop, |
| 416 | displayRectLeft + displayRectWidth, displayRectTop + displayRectHeight); |
| 417 | |
Adrian Roos | 8c28c7c | 2018-08-20 13:43:38 +0200 | [diff] [blame] | 418 | // Now add back the offset for the masked area. |
| 419 | mTempDisplayRect.offset(maskingInsets.left, maskingInsets.top); |
| 420 | |
Adrian Roos | 595416b | 2018-10-14 14:50:33 +0200 | [diff] [blame] | 421 | if (orientation == Surface.ROTATION_0) { |
| 422 | mTempDisplayRect.offset(mDisplayOffsetX, mDisplayOffsetY); |
| 423 | } else if (orientation == Surface.ROTATION_90) { |
| 424 | mTempDisplayRect.offset(mDisplayOffsetY, -mDisplayOffsetX); |
| 425 | } else if (orientation == Surface.ROTATION_180) { |
| 426 | mTempDisplayRect.offset(-mDisplayOffsetX, -mDisplayOffsetY); |
| 427 | } else { // Surface.ROTATION_270 |
| 428 | mTempDisplayRect.offset(-mDisplayOffsetY, mDisplayOffsetX); |
| 429 | } |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 430 | device.setProjectionLocked(t, orientation, mTempLayerStackRect, mTempDisplayRect); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 431 | } |
| 432 | |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 433 | /** |
| 434 | * Returns true if the logical display has unique content. |
| 435 | * <p> |
| 436 | * If the display has unique content then we will try to ensure that it is |
| 437 | * visible on at least its primary display device. Otherwise we will ignore the |
| 438 | * logical display and perhaps show mirrored content on the primary display device. |
| 439 | * </p> |
| 440 | * |
| 441 | * @return True if the display has unique content. |
| 442 | */ |
| 443 | public boolean hasContentLocked() { |
| 444 | return mHasContent; |
| 445 | } |
| 446 | |
| 447 | /** |
| 448 | * Sets whether the logical display has unique content. |
| 449 | * |
| 450 | * @param hasContent True if the display has unique content. |
| 451 | */ |
| 452 | public void setHasContentLocked(boolean hasContent) { |
| 453 | mHasContent = hasContent; |
| 454 | } |
| 455 | |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 456 | /** |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 457 | * Requests the given mode. |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 458 | */ |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 459 | public void setRequestedModeIdLocked(int modeId) { |
| 460 | mRequestedModeId = modeId; |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | /** |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 464 | * Returns the pending requested mode. |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 465 | */ |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 466 | public int getRequestedModeIdLocked() { |
| 467 | return mRequestedModeId; |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 468 | } |
| 469 | |
Filip Gruszczynski | d2e8640 | 2015-02-19 13:05:03 -0800 | [diff] [blame] | 470 | /** |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 471 | * Requests the given color mode. |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 472 | */ |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 473 | public void setRequestedColorModeLocked(int colorMode) { |
| 474 | mRequestedColorMode = colorMode; |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 475 | } |
| 476 | |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 477 | /** Returns the pending requested color mode. */ |
| 478 | public int getRequestedColorModeLocked() { |
| 479 | return mRequestedColorMode; |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | /** |
Filip Gruszczynski | d2e8640 | 2015-02-19 13:05:03 -0800 | [diff] [blame] | 483 | * Gets the burn-in offset in X. |
| 484 | */ |
| 485 | public int getDisplayOffsetXLocked() { |
| 486 | return mDisplayOffsetX; |
| 487 | } |
| 488 | |
| 489 | /** |
| 490 | * Gets the burn-in offset in Y. |
| 491 | */ |
| 492 | public int getDisplayOffsetYLocked() { |
| 493 | return mDisplayOffsetY; |
| 494 | } |
| 495 | |
| 496 | /** |
| 497 | * Sets the burn-in offsets. |
| 498 | */ |
| 499 | public void setDisplayOffsetsLocked(int x, int y) { |
| 500 | mDisplayOffsetX = x; |
| 501 | mDisplayOffsetY = y; |
| 502 | } |
| 503 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 504 | public void dumpLocked(PrintWriter pw) { |
Jeff Brown | c272664 | 2012-10-02 16:17:31 -0700 | [diff] [blame] | 505 | pw.println("mDisplayId=" + mDisplayId); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 506 | pw.println("mLayerStack=" + mLayerStack); |
Jeff Brown | c272664 | 2012-10-02 16:17:31 -0700 | [diff] [blame] | 507 | pw.println("mHasContent=" + mHasContent); |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 508 | pw.println("mRequestedMode=" + mRequestedModeId); |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 509 | pw.println("mRequestedColorMode=" + mRequestedColorMode); |
Filip Gruszczynski | d2e8640 | 2015-02-19 13:05:03 -0800 | [diff] [blame] | 510 | pw.println("mDisplayOffset=(" + mDisplayOffsetX + ", " + mDisplayOffsetY + ")"); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 511 | pw.println("mPrimaryDisplayDevice=" + (mPrimaryDisplayDevice != null ? |
| 512 | mPrimaryDisplayDevice.getNameLocked() : "null")); |
| 513 | pw.println("mBaseDisplayInfo=" + mBaseDisplayInfo); |
| 514 | pw.println("mOverrideDisplayInfo=" + mOverrideDisplayInfo); |
| 515 | } |
Michael Wright | c39d47a | 2014-07-08 18:07:36 -0700 | [diff] [blame] | 516 | } |