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