blob: 5b7c5205ce3a74a61d23ab1b9a0e01a920f90a6b [file] [log] [blame]
Jeff Brown4ed8fe72012-08-30 18:18:29 -07001/*
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
17package com.android.server.display;
18
19import android.graphics.Rect;
Andrii Kuliancd097992017-03-23 18:31:59 -070020import android.hardware.display.DisplayManagerInternal;
Adrian Roos9ee5dff2018-08-22 20:19:49 +020021import android.os.SystemProperties;
Jeff Brownc5df37c2012-09-13 11:45:07 -070022import android.view.Display;
Jeff Brown4ed8fe72012-08-30 18:18:29 -070023import android.view.DisplayInfo;
24import android.view.Surface;
Robert Carrae606b42018-02-15 15:36:23 -080025import android.view.SurfaceControl;
Jeff Brown4ed8fe72012-08-30 18:18:29 -070026
Adrian Roos8c28c7c2018-08-20 13:43:38 +020027import com.android.server.wm.utils.InsetUtils;
28
Jeff Brown4ed8fe72012-08-30 18:18:29 -070029import java.io.PrintWriter;
Michael Wright3f145a22014-07-22 19:46:03 -070030import java.util.Arrays;
Jeff Brown4ed8fe72012-08-30 18:18:29 -070031import java.util.List;
Narayan Kamath607223f2018-02-19 14:09:02 +000032import java.util.Objects;
Jeff Brown4ed8fe72012-08-30 18:18:29 -070033
34/**
35 * Describes how a logical display is configured.
36 * <p>
37 * At this time, we only support logical displays that are coupled to a particular
38 * primary display device from which the logical display derives its basic properties
39 * such as its size, density and refresh rate.
40 * </p><p>
41 * A logical display may be mirrored onto multiple display devices in addition to its
42 * primary display device. Note that the contents of a logical display may not
43 * always be visible, even on its primary display device, such as in the case where
44 * the primary display device is currently mirroring content from a different
45 * logical display.
46 * </p><p>
47 * This object is designed to encapsulate as much of the policy of logical
48 * displays as possible. The idea is to make it easy to implement new kinds of
49 * logical displays mostly by making local changes to this class.
50 * </p><p>
51 * Note: The display manager architecture does not actually require logical displays
52 * to be associated with any individual display device. Logical displays and
53 * display devices are orthogonal concepts. Some mapping will exist between
54 * logical displays and display devices but it can be many-to-many and
55 * and some might have no relation at all.
56 * </p><p>
57 * Logical displays are guarded by the {@link DisplayManagerService.SyncRoot} lock.
58 * </p>
59 */
60final class LogicalDisplay {
Adrian Roos9ee5dff2018-08-22 20:19:49 +020061 private static final String PROP_MASKING_INSET_TOP = "persist.sys.displayinset.top";
62
Jeff Brown4ed8fe72012-08-30 18:18:29 -070063 private final DisplayInfo mBaseDisplayInfo = new DisplayInfo();
64
Jeff Brown8ec09432012-10-16 16:19:23 -070065 // The layer stack we use when the display has been blanked to prevent any
66 // of its content from appearing.
67 private static final int BLANK_LAYER_STACK = -1;
68
Jeff Brownd728bf52012-09-08 18:05:28 -070069 private final int mDisplayId;
Jeff Brown4ed8fe72012-08-30 18:18:29 -070070 private final int mLayerStack;
Andrii Kuliancd097992017-03-23 18:31:59 -070071 /**
72 * Override information set by the window manager. Will be reported instead of {@link #mInfo}
73 * if not null.
74 * @see #setDisplayInfoOverrideFromWindowManagerLocked(DisplayInfo)
75 * @see #getDisplayInfoLocked()
76 */
77 private DisplayInfo mOverrideDisplayInfo;
78 /**
79 * Current display info. Initialized with {@link #mBaseDisplayInfo}. Set to {@code null} if
80 * needs to be updated.
81 * @see #getDisplayInfoLocked()
82 */
Jeff Brown4ed8fe72012-08-30 18:18:29 -070083 private DisplayInfo mInfo;
84
85 // The display device that this logical display is based on and which
86 // determines the base metrics that it uses.
87 private DisplayDevice mPrimaryDisplayDevice;
88 private DisplayDeviceInfo mPrimaryDisplayDeviceInfo;
89
Craig Mautner722285e2012-09-07 13:55:58 -070090 // True if the logical display has unique content.
91 private boolean mHasContent;
92
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -070093 private int mRequestedModeId;
Michael Wright1c9977b2016-07-12 13:30:10 -070094 private int mRequestedColorMode;
Michael Wright3f145a22014-07-22 19:46:03 -070095
Filip Gruszczynskid2e86402015-02-19 13:05:03 -080096 // The display offsets to apply to the display projection.
97 private int mDisplayOffsetX;
98 private int mDisplayOffsetY;
99
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700100 // Temporary rectangle used when needed.
Mathias Agopian63f1c432012-09-04 19:29:13 -0700101 private final Rect mTempLayerStackRect = new Rect();
102 private final Rect mTempDisplayRect = new Rect();
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700103
Jeff Brownd728bf52012-09-08 18:05:28 -0700104 public LogicalDisplay(int displayId, int layerStack, DisplayDevice primaryDisplayDevice) {
105 mDisplayId = displayId;
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700106 mLayerStack = layerStack;
107 mPrimaryDisplayDevice = primaryDisplayDevice;
108 }
109
110 /**
Jeff Brownd728bf52012-09-08 18:05:28 -0700111 * Gets the logical display id of this logical display.
112 *
113 * @return The logical display id.
114 */
115 public int getDisplayIdLocked() {
116 return mDisplayId;
117 }
118
119 /**
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700120 * Gets the primary display device associated with this logical display.
121 *
122 * @return The primary display device.
123 */
124 public DisplayDevice getPrimaryDisplayDeviceLocked() {
125 return mPrimaryDisplayDevice;
126 }
127
128 /**
129 * Gets information about the logical display.
130 *
131 * @return The device info, which should be treated as immutable by the caller.
132 * The logical display should allocate a new display info object whenever
133 * the data changes.
134 */
135 public DisplayInfo getDisplayInfoLocked() {
136 if (mInfo == null) {
137 mInfo = new DisplayInfo();
P.Y. Laliganded896d42015-05-12 10:43:38 -0700138 mInfo.copyFrom(mBaseDisplayInfo);
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700139 if (mOverrideDisplayInfo != null) {
P.Y. Laliganded896d42015-05-12 10:43:38 -0700140 mInfo.appWidth = mOverrideDisplayInfo.appWidth;
141 mInfo.appHeight = mOverrideDisplayInfo.appHeight;
142 mInfo.smallestNominalAppWidth = mOverrideDisplayInfo.smallestNominalAppWidth;
143 mInfo.smallestNominalAppHeight = mOverrideDisplayInfo.smallestNominalAppHeight;
144 mInfo.largestNominalAppWidth = mOverrideDisplayInfo.largestNominalAppWidth;
145 mInfo.largestNominalAppHeight = mOverrideDisplayInfo.largestNominalAppHeight;
146 mInfo.logicalWidth = mOverrideDisplayInfo.logicalWidth;
147 mInfo.logicalHeight = mOverrideDisplayInfo.logicalHeight;
148 mInfo.overscanLeft = mOverrideDisplayInfo.overscanLeft;
149 mInfo.overscanTop = mOverrideDisplayInfo.overscanTop;
150 mInfo.overscanRight = mOverrideDisplayInfo.overscanRight;
151 mInfo.overscanBottom = mOverrideDisplayInfo.overscanBottom;
152 mInfo.rotation = mOverrideDisplayInfo.rotation;
Adrian Roos1cf585052018-01-03 18:43:27 +0100153 mInfo.displayCutout = mOverrideDisplayInfo.displayCutout;
P.Y. Laliganded896d42015-05-12 10:43:38 -0700154 mInfo.logicalDensityDpi = mOverrideDisplayInfo.logicalDensityDpi;
Jeff Brownfe4ad332015-06-09 18:26:31 -0700155 mInfo.physicalXDpi = mOverrideDisplayInfo.physicalXDpi;
156 mInfo.physicalYDpi = mOverrideDisplayInfo.physicalYDpi;
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700157 }
158 }
159 return mInfo;
160 }
161
162 /**
Andrii Kuliancd097992017-03-23 18:31:59 -0700163 * @see DisplayManagerInternal#getNonOverrideDisplayInfo(int, DisplayInfo)
164 */
165 void getNonOverrideDisplayInfoLocked(DisplayInfo outInfo) {
166 outInfo.copyFrom(mBaseDisplayInfo);
167 }
168
169 /**
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700170 * Sets overridden logical display information from the window manager.
171 * This method can be used to adjust application insets, rotation, and other
172 * properties that the window manager takes care of.
173 *
174 * @param info The logical display information, may be null.
175 */
Jeff Brownef981a42013-08-07 14:13:37 -0700176 public boolean setDisplayInfoOverrideFromWindowManagerLocked(DisplayInfo info) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700177 if (info != null) {
178 if (mOverrideDisplayInfo == null) {
179 mOverrideDisplayInfo = new DisplayInfo(info);
180 mInfo = null;
Jeff Brownef981a42013-08-07 14:13:37 -0700181 return true;
182 }
183 if (!mOverrideDisplayInfo.equals(info)) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700184 mOverrideDisplayInfo.copyFrom(info);
185 mInfo = null;
Jeff Brownef981a42013-08-07 14:13:37 -0700186 return true;
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700187 }
188 } else if (mOverrideDisplayInfo != null) {
189 mOverrideDisplayInfo = null;
190 mInfo = null;
Jeff Brownef981a42013-08-07 14:13:37 -0700191 return true;
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700192 }
Jeff Brownef981a42013-08-07 14:13:37 -0700193 return false;
Dianne Hackbornc652de82013-02-15 16:32:56 -0800194 }
195
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700196 /**
197 * Returns true if the logical display is in a valid state.
Craig Mautner722285e2012-09-07 13:55:58 -0700198 * This method should be checked after calling {@link #updateLocked} to handle the
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700199 * case where a logical display should be removed because all of its associated
200 * display devices are gone or if it is otherwise no longer needed.
201 *
202 * @return True if the logical display is still valid.
203 */
204 public boolean isValidLocked() {
205 return mPrimaryDisplayDevice != null;
206 }
207
208 /**
209 * Updates the state of the logical display based on the available display devices.
210 * The logical display might become invalid if it is attached to a display device
211 * that no longer exists.
212 *
213 * @param devices The list of all connected display devices.
214 */
215 public void updateLocked(List<DisplayDevice> devices) {
216 // Nothing to update if already invalid.
217 if (mPrimaryDisplayDevice == null) {
218 return;
219 }
220
221 // Check whether logical display has become invalid.
222 if (!devices.contains(mPrimaryDisplayDevice)) {
223 mPrimaryDisplayDevice = null;
224 return;
225 }
226
227 // Bootstrap the logical display using its associated primary physical display.
228 // We might use more elaborate configurations later. It's possible that the
229 // configuration of several physical displays might be used to determine the
230 // logical display that they are sharing. (eg. Adjust size for pixel-perfect
231 // mirroring over HDMI.)
232 DisplayDeviceInfo deviceInfo = mPrimaryDisplayDevice.getDisplayDeviceInfoLocked();
Narayan Kamath607223f2018-02-19 14:09:02 +0000233 if (!Objects.equals(mPrimaryDisplayDeviceInfo, deviceInfo)) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700234 mBaseDisplayInfo.layerStack = mLayerStack;
Jeff Brownc5df37c2012-09-13 11:45:07 -0700235 mBaseDisplayInfo.flags = 0;
Jeff Brown77aebfd2012-10-01 21:07:03 -0700236 if ((deviceInfo.flags & DisplayDeviceInfo.FLAG_SUPPORTS_PROTECTED_BUFFERS) != 0) {
237 mBaseDisplayInfo.flags |= Display.FLAG_SUPPORTS_PROTECTED_BUFFERS;
Jeff Brownc5df37c2012-09-13 11:45:07 -0700238 }
Jeff Brownf0681b32012-10-23 17:35:57 -0700239 if ((deviceInfo.flags & DisplayDeviceInfo.FLAG_SECURE) != 0) {
240 mBaseDisplayInfo.flags |= Display.FLAG_SECURE;
241 }
Jeff Browna506a6e2013-06-04 00:02:38 -0700242 if ((deviceInfo.flags & DisplayDeviceInfo.FLAG_PRIVATE) != 0) {
243 mBaseDisplayInfo.flags |= Display.FLAG_PRIVATE;
Andrii Kulian250d6532017-02-08 23:30:45 -0800244 // For private displays by default content is destroyed on removal.
245 mBaseDisplayInfo.removeMode = Display.REMOVE_MODE_DESTROY_CONTENT;
Jeff Browna506a6e2013-06-04 00:02:38 -0700246 }
rongliu1e90fc32017-10-04 17:30:30 -0700247 if ((deviceInfo.flags & DisplayDeviceInfo.FLAG_DESTROY_CONTENT_ON_REMOVAL) != 0) {
248 mBaseDisplayInfo.removeMode = Display.REMOVE_MODE_DESTROY_CONTENT;
249 }
Jeff Brown7d00aff2013-08-02 19:03:49 -0700250 if ((deviceInfo.flags & DisplayDeviceInfo.FLAG_PRESENTATION) != 0) {
251 mBaseDisplayInfo.flags |= Display.FLAG_PRESENTATION;
252 }
Adam Powell49e7ff92015-05-14 16:18:53 -0700253 if ((deviceInfo.flags & DisplayDeviceInfo.FLAG_ROUND) != 0) {
254 mBaseDisplayInfo.flags |= Display.FLAG_ROUND;
255 }
Andrii Kulian7211d2e2017-01-27 15:58:05 -0800256 if ((deviceInfo.flags & DisplayDeviceInfo.FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD) != 0) {
257 mBaseDisplayInfo.flags |= Display.FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD;
Andrii Kulianfc8f82b2017-01-26 13:17:27 -0800258 }
Adrian Roos8c28c7c2018-08-20 13:43:38 +0200259 Rect maskingInsets = getMaskingInsets(deviceInfo);
260 int maskedWidth = deviceInfo.width - maskingInsets.left - maskingInsets.right;
261 int maskedHeight = deviceInfo.height - maskingInsets.top - maskingInsets.bottom;
262
Jeff Brown92130f62012-10-24 21:28:33 -0700263 mBaseDisplayInfo.type = deviceInfo.type;
264 mBaseDisplayInfo.address = deviceInfo.address;
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700265 mBaseDisplayInfo.name = deviceInfo.name;
Wale Ogunwale361ca212014-11-20 11:42:38 -0800266 mBaseDisplayInfo.uniqueId = deviceInfo.uniqueId;
Adrian Roos8c28c7c2018-08-20 13:43:38 +0200267 mBaseDisplayInfo.appWidth = maskedWidth;
268 mBaseDisplayInfo.appHeight = maskedHeight;
269 mBaseDisplayInfo.logicalWidth = maskedWidth;
270 mBaseDisplayInfo.logicalHeight = maskedHeight;
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700271 mBaseDisplayInfo.rotation = Surface.ROTATION_0;
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700272 mBaseDisplayInfo.modeId = deviceInfo.modeId;
273 mBaseDisplayInfo.defaultModeId = deviceInfo.defaultModeId;
274 mBaseDisplayInfo.supportedModes = Arrays.copyOf(
275 deviceInfo.supportedModes, deviceInfo.supportedModes.length);
Michael Wright1c9977b2016-07-12 13:30:10 -0700276 mBaseDisplayInfo.colorMode = deviceInfo.colorMode;
277 mBaseDisplayInfo.supportedColorModes = Arrays.copyOf(
278 deviceInfo.supportedColorModes,
279 deviceInfo.supportedColorModes.length);
Michael Wright9ff94c02016-03-30 18:05:40 -0700280 mBaseDisplayInfo.hdrCapabilities = deviceInfo.hdrCapabilities;
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700281 mBaseDisplayInfo.logicalDensityDpi = deviceInfo.densityDpi;
282 mBaseDisplayInfo.physicalXDpi = deviceInfo.xDpi;
283 mBaseDisplayInfo.physicalYDpi = deviceInfo.yDpi;
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700284 mBaseDisplayInfo.appVsyncOffsetNanos = deviceInfo.appVsyncOffsetNanos;
285 mBaseDisplayInfo.presentationDeadlineNanos = deviceInfo.presentationDeadlineNanos;
Jeff Brown037c33e2014-04-09 00:31:55 -0700286 mBaseDisplayInfo.state = deviceInfo.state;
Adrian Roos8c28c7c2018-08-20 13:43:38 +0200287 mBaseDisplayInfo.smallestNominalAppWidth = maskedWidth;
288 mBaseDisplayInfo.smallestNominalAppHeight = maskedHeight;
289 mBaseDisplayInfo.largestNominalAppWidth = maskedWidth;
290 mBaseDisplayInfo.largestNominalAppHeight = maskedHeight;
Jeff Browna506a6e2013-06-04 00:02:38 -0700291 mBaseDisplayInfo.ownerUid = deviceInfo.ownerUid;
292 mBaseDisplayInfo.ownerPackageName = deviceInfo.ownerPackageName;
Adrian Roos8c28c7c2018-08-20 13:43:38 +0200293 boolean maskCutout =
294 (deviceInfo.flags & DisplayDeviceInfo.FLAG_MASK_DISPLAY_CUTOUT) != 0;
295 mBaseDisplayInfo.displayCutout = maskCutout ? null : deviceInfo.displayCutout;
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700296
297 mPrimaryDisplayDeviceInfo = deviceInfo;
298 mInfo = null;
299 }
300 }
301
302 /**
Adrian Roos9ee5dff2018-08-22 20:19:49 +0200303 * 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 Roos8c28c7c2018-08-20 13:43:38 +0200314 * 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 Brown4ed8fe72012-08-30 18:18:29 -0700326 * 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 Brown8ec09432012-10-16 16:19:23 -0700340 * @param isBlanked True if the device is being blanked.
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700341 */
Robert Carrae606b42018-02-15 15:36:23 -0800342 public void configureDisplayLocked(SurfaceControl.Transaction t,
343 DisplayDevice device,
Jeff Brown8ec09432012-10-16 16:19:23 -0700344 boolean isBlanked) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700345 // Set the layer stack.
Robert Carrae606b42018-02-15 15:36:23 -0800346 device.setLayerStackLocked(t, isBlanked ? BLANK_LAYER_STACK : mLayerStack);
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700347
Michael Wright1c9977b2016-07-12 13:30:10 -0700348 // Set the color mode and mode.
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700349 if (device == mPrimaryDisplayDevice) {
Robert Carrae606b42018-02-15 15:36:23 -0800350 device.requestDisplayModesLocked(
Michael Wright1c9977b2016-07-12 13:30:10 -0700351 mRequestedColorMode, mRequestedModeId);
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700352 } else {
Robert Carrae606b42018-02-15 15:36:23 -0800353 device.requestDisplayModesLocked(0, 0); // Revert to default.
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700354 }
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 Wright3f145a22014-07-22 19:46:03 -0700359
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700360 // 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 Agopian63f1c432012-09-04 19:29:13 -0700363 mTempLayerStackRect.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700364
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 Anderson8786ed92013-11-01 13:27:39 -0700369 if ((displayDeviceInfo.flags & DisplayDeviceInfo.FLAG_ROTATES_WITH_CONTENT) != 0) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700370 orientation = displayInfo.rotation;
371 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700372
Jeff Brown27f1d672012-10-17 18:32:34 -0700373 // Apply the physical rotation of the display device itself.
374 orientation = (orientation + displayDeviceInfo.rotation) % 4;
375
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700376 // 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 Roos8c28c7c2018-08-20 13:43:38 +0200386 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 Brown4ed8fe72012-08-30 18:18:29 -0700392 // 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 Agopian63f1c432012-09-04 19:29:13 -0700399 int displayRectWidth, displayRectHeight;
Jeff Brownd46747a2015-04-15 19:02:36 -0700400 if ((displayInfo.flags & Display.FLAG_SCALING_DISABLED) != 0) {
401 displayRectWidth = displayInfo.logicalWidth;
402 displayRectHeight = displayInfo.logicalHeight;
403 } else if (physWidth * displayInfo.logicalHeight
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700404 < physHeight * displayInfo.logicalWidth) {
405 // Letter box.
Mathias Agopian63f1c432012-09-04 19:29:13 -0700406 displayRectWidth = physWidth;
407 displayRectHeight = displayInfo.logicalHeight * physWidth / displayInfo.logicalWidth;
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700408 } else {
409 // Pillar box.
Mathias Agopian63f1c432012-09-04 19:29:13 -0700410 displayRectWidth = displayInfo.logicalWidth * physHeight / displayInfo.logicalHeight;
411 displayRectHeight = physHeight;
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700412 }
Mathias Agopian63f1c432012-09-04 19:29:13 -0700413 int displayRectTop = (physHeight - displayRectHeight) / 2;
414 int displayRectLeft = (physWidth - displayRectWidth) / 2;
415 mTempDisplayRect.set(displayRectLeft, displayRectTop,
416 displayRectLeft + displayRectWidth, displayRectTop + displayRectHeight);
417
Adrian Roos8c28c7c2018-08-20 13:43:38 +0200418 // Now add back the offset for the masked area.
419 mTempDisplayRect.offset(maskingInsets.left, maskingInsets.top);
420
Filip Gruszczynskid2e86402015-02-19 13:05:03 -0800421 mTempDisplayRect.left += mDisplayOffsetX;
422 mTempDisplayRect.right += mDisplayOffsetX;
423 mTempDisplayRect.top += mDisplayOffsetY;
424 mTempDisplayRect.bottom += mDisplayOffsetY;
Robert Carrae606b42018-02-15 15:36:23 -0800425 device.setProjectionLocked(t, orientation, mTempLayerStackRect, mTempDisplayRect);
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700426 }
427
Craig Mautner722285e2012-09-07 13:55:58 -0700428 /**
429 * Returns true if the logical display has unique content.
430 * <p>
431 * If the display has unique content then we will try to ensure that it is
432 * visible on at least its primary display device. Otherwise we will ignore the
433 * logical display and perhaps show mirrored content on the primary display device.
434 * </p>
435 *
436 * @return True if the display has unique content.
437 */
438 public boolean hasContentLocked() {
439 return mHasContent;
440 }
441
442 /**
443 * Sets whether the logical display has unique content.
444 *
445 * @param hasContent True if the display has unique content.
446 */
447 public void setHasContentLocked(boolean hasContent) {
448 mHasContent = hasContent;
449 }
450
Michael Wright3f145a22014-07-22 19:46:03 -0700451 /**
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700452 * Requests the given mode.
Michael Wright3f145a22014-07-22 19:46:03 -0700453 */
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700454 public void setRequestedModeIdLocked(int modeId) {
455 mRequestedModeId = modeId;
Michael Wright3f145a22014-07-22 19:46:03 -0700456 }
457
458 /**
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700459 * Returns the pending requested mode.
Michael Wright3f145a22014-07-22 19:46:03 -0700460 */
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700461 public int getRequestedModeIdLocked() {
462 return mRequestedModeId;
Michael Wright3f145a22014-07-22 19:46:03 -0700463 }
464
Filip Gruszczynskid2e86402015-02-19 13:05:03 -0800465 /**
Michael Wright1c9977b2016-07-12 13:30:10 -0700466 * Requests the given color mode.
Michael Wright58e829f2015-09-15 00:13:26 +0100467 */
Michael Wright1c9977b2016-07-12 13:30:10 -0700468 public void setRequestedColorModeLocked(int colorMode) {
469 mRequestedColorMode = colorMode;
Michael Wright58e829f2015-09-15 00:13:26 +0100470 }
471
Michael Wright1c9977b2016-07-12 13:30:10 -0700472 /** Returns the pending requested color mode. */
473 public int getRequestedColorModeLocked() {
474 return mRequestedColorMode;
Michael Wright58e829f2015-09-15 00:13:26 +0100475 }
476
477 /**
Filip Gruszczynskid2e86402015-02-19 13:05:03 -0800478 * Gets the burn-in offset in X.
479 */
480 public int getDisplayOffsetXLocked() {
481 return mDisplayOffsetX;
482 }
483
484 /**
485 * Gets the burn-in offset in Y.
486 */
487 public int getDisplayOffsetYLocked() {
488 return mDisplayOffsetY;
489 }
490
491 /**
492 * Sets the burn-in offsets.
493 */
494 public void setDisplayOffsetsLocked(int x, int y) {
495 mDisplayOffsetX = x;
496 mDisplayOffsetY = y;
497 }
498
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700499 public void dumpLocked(PrintWriter pw) {
Jeff Brownc2726642012-10-02 16:17:31 -0700500 pw.println("mDisplayId=" + mDisplayId);
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700501 pw.println("mLayerStack=" + mLayerStack);
Jeff Brownc2726642012-10-02 16:17:31 -0700502 pw.println("mHasContent=" + mHasContent);
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700503 pw.println("mRequestedMode=" + mRequestedModeId);
Michael Wright1c9977b2016-07-12 13:30:10 -0700504 pw.println("mRequestedColorMode=" + mRequestedColorMode);
Filip Gruszczynskid2e86402015-02-19 13:05:03 -0800505 pw.println("mDisplayOffset=(" + mDisplayOffsetX + ", " + mDisplayOffsetY + ")");
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700506 pw.println("mPrimaryDisplayDevice=" + (mPrimaryDisplayDevice != null ?
507 mPrimaryDisplayDevice.getNameLocked() : "null"));
508 pw.println("mBaseDisplayInfo=" + mBaseDisplayInfo);
509 pw.println("mOverrideDisplayInfo=" + mOverrideDisplayInfo);
510 }
Michael Wrightc39d47a2014-07-08 18:07:36 -0700511}