Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -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 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 19 | import android.graphics.Rect; |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 20 | import android.hardware.display.DisplayViewport; |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 21 | import android.os.IBinder; |
Dominik Laskowski | db84596 | 2019-01-27 21:20:00 -0800 | [diff] [blame] | 22 | import android.view.DisplayAddress; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 23 | import android.view.Surface; |
Mathias Agopian | 3866f0d | 2013-02-11 22:08:48 -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; |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 27 | |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 28 | /** |
| 29 | * Represents a physical display device such as the built-in display |
Jeff Brown | 848c2dc | 2012-08-19 20:18:08 -0700 | [diff] [blame] | 30 | * an external monitor, or a WiFi display. |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 31 | * <p> |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 32 | * Display devices are guarded by the {@link DisplayManagerService.SyncRoot} lock. |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 33 | * </p> |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 34 | */ |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 35 | abstract class DisplayDevice { |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 36 | private final DisplayAdapter mDisplayAdapter; |
| 37 | private final IBinder mDisplayToken; |
Wale Ogunwale | 361ca21 | 2014-11-20 11:42:38 -0800 | [diff] [blame] | 38 | private final String mUniqueId; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 39 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 40 | // The display device does not manage these properties itself, they are set by |
| 41 | // the display manager service. The display device shouldn't really be looking at these. |
| 42 | private int mCurrentLayerStack = -1; |
| 43 | private int mCurrentOrientation = -1; |
Mathias Agopian | 63f1c43 | 2012-09-04 19:29:13 -0700 | [diff] [blame] | 44 | private Rect mCurrentLayerStackRect; |
| 45 | private Rect mCurrentDisplayRect; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 46 | |
Jeff Brown | cbad976 | 2012-09-04 21:57:59 -0700 | [diff] [blame] | 47 | // The display device owns its surface, but it should only set it |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 48 | // within a transaction from performTraversalLocked. |
Jeff Brown | cbad976 | 2012-09-04 21:57:59 -0700 | [diff] [blame] | 49 | private Surface mCurrentSurface; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 50 | |
Jeff Brown | 10acf6d | 2015-04-14 14:20:47 -0700 | [diff] [blame] | 51 | // DEBUG STATE: Last device info which was written to the log, or null if none. |
| 52 | // Do not use for any other purpose. |
| 53 | DisplayDeviceInfo mDebugLastLoggedDeviceInfo; |
| 54 | |
Wale Ogunwale | 361ca21 | 2014-11-20 11:42:38 -0800 | [diff] [blame] | 55 | public DisplayDevice(DisplayAdapter displayAdapter, IBinder displayToken, String uniqueId) { |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 56 | mDisplayAdapter = displayAdapter; |
| 57 | mDisplayToken = displayToken; |
Wale Ogunwale | 361ca21 | 2014-11-20 11:42:38 -0800 | [diff] [blame] | 58 | mUniqueId = uniqueId; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 59 | } |
| 60 | |
Jeff Brown | 848c2dc | 2012-08-19 20:18:08 -0700 | [diff] [blame] | 61 | /** |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 62 | * Gets the display adapter that owns the display device. |
Jeff Brown | 848c2dc | 2012-08-19 20:18:08 -0700 | [diff] [blame] | 63 | * |
| 64 | * @return The display adapter. |
| 65 | */ |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 66 | public final DisplayAdapter getAdapterLocked() { |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 67 | return mDisplayAdapter; |
| 68 | } |
Jeff Brown | 848c2dc | 2012-08-19 20:18:08 -0700 | [diff] [blame] | 69 | |
| 70 | /** |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 71 | * Gets the Surface Flinger display token for this display. |
| 72 | * |
| 73 | * @return The display token, or null if the display is not being managed |
| 74 | * by Surface Flinger. |
| 75 | */ |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 76 | public final IBinder getDisplayTokenLocked() { |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 77 | return mDisplayToken; |
| 78 | } |
Jeff Brown | 64a55af | 2012-08-26 02:47:39 -0700 | [diff] [blame] | 79 | |
| 80 | /** |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 81 | * Gets the name of the display device. |
| 82 | * |
| 83 | * @return The display device name. |
| 84 | */ |
| 85 | public final String getNameLocked() { |
| 86 | return getDisplayDeviceInfoLocked().name; |
| 87 | } |
| 88 | |
| 89 | /** |
Wale Ogunwale | 361ca21 | 2014-11-20 11:42:38 -0800 | [diff] [blame] | 90 | * Returns the unique id of the display device. |
| 91 | */ |
| 92 | public final String getUniqueId() { |
| 93 | return mUniqueId; |
| 94 | } |
| 95 | |
| 96 | /** |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 97 | * Returns whether the unique id of the device is stable across reboots. |
| 98 | */ |
| 99 | public abstract boolean hasStableUniqueId(); |
| 100 | |
| 101 | /** |
Jeff Brown | 848c2dc | 2012-08-19 20:18:08 -0700 | [diff] [blame] | 102 | * Gets information about the display device. |
| 103 | * |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 104 | * The information returned should not change between calls unless the display |
| 105 | * adapter sent a {@link DisplayAdapter#DISPLAY_DEVICE_EVENT_CHANGED} event and |
| 106 | * {@link #applyPendingDisplayDeviceInfoChangesLocked()} has been called to apply |
| 107 | * the pending changes. |
| 108 | * |
| 109 | * @return The display device info, which should be treated as immutable by the caller. |
| 110 | * The display device should allocate a new display device info object whenever |
| 111 | * the data changes. |
Jeff Brown | 848c2dc | 2012-08-19 20:18:08 -0700 | [diff] [blame] | 112 | */ |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 113 | public abstract DisplayDeviceInfo getDisplayDeviceInfoLocked(); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 114 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 115 | /** |
| 116 | * Applies any pending changes to the observable state of the display device |
| 117 | * if the display adapter sent a {@link DisplayAdapter#DISPLAY_DEVICE_EVENT_CHANGED} event. |
| 118 | */ |
| 119 | public void applyPendingDisplayDeviceInfoChangesLocked() { |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Gives the display device a chance to update its properties while in a transaction. |
| 124 | */ |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 125 | public void performTraversalLocked(SurfaceControl.Transaction t) { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | /** |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 129 | * Sets the display state, if supported. |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 130 | * |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 131 | * @param state The new display state. |
| 132 | * @param brightness The new display brightness. |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 133 | * @return A runnable containing work to be deferred until after we have |
| 134 | * exited the critical section, or null if none. |
Jeff Brown | 9e316a1 | 2012-10-08 19:17:06 -0700 | [diff] [blame] | 135 | */ |
Jeff Brown | 5d6443b | 2015-04-10 20:15:01 -0700 | [diff] [blame] | 136 | public Runnable requestDisplayStateLocked(int state, int brightness) { |
Jeff Brown | e75926d | 2014-09-18 15:24:49 -0700 | [diff] [blame] | 137 | return null; |
Jeff Brown | 9e316a1 | 2012-10-08 19:17:06 -0700 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | /** |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 141 | * Sets the display modes the system is allowed to switch between, roughly ordered by |
| 142 | * preference. |
| 143 | * |
| 144 | * Not all display devices will automatically switch between modes, so it's important that the |
| 145 | * most-desired modes are at the beginning of the allowed array. |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 146 | */ |
Michael Wright | a3dab23 | 2019-02-22 16:54:21 +0000 | [diff] [blame] | 147 | public void setAllowedDisplayModesLocked(int[] modes) { |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * Sets the requested color mode. |
| 152 | */ |
| 153 | public void setRequestedColorModeLocked(int colorMode) { |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 154 | } |
| 155 | |
Adrian Roos | 898ec38 | 2018-01-17 12:54:50 +0100 | [diff] [blame] | 156 | public void onOverlayChangedLocked() { |
| 157 | } |
| 158 | |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 159 | /** |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 160 | * Sets the display layer stack while in a transaction. |
| 161 | */ |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 162 | public final void setLayerStackLocked(SurfaceControl.Transaction t, int layerStack) { |
Jeff Brown | cbad976 | 2012-09-04 21:57:59 -0700 | [diff] [blame] | 163 | if (mCurrentLayerStack != layerStack) { |
| 164 | mCurrentLayerStack = layerStack; |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 165 | t.setDisplayLayerStack(mDisplayToken, layerStack); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 166 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | /** |
Mathias Agopian | 63f1c43 | 2012-09-04 19:29:13 -0700 | [diff] [blame] | 170 | * Sets the display projection while in a transaction. |
| 171 | * |
| 172 | * @param orientation defines the display's orientation |
| 173 | * @param layerStackRect defines which area of the window manager coordinate |
| 174 | * space will be used |
| 175 | * @param displayRect defines where on the display will layerStackRect be |
| 176 | * mapped to. displayRect is specified post-orientation, that is |
| 177 | * it uses the orientation seen by the end-user |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 178 | */ |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 179 | public final void setProjectionLocked(SurfaceControl.Transaction t, int orientation, |
Jeff Brown | cbad976 | 2012-09-04 21:57:59 -0700 | [diff] [blame] | 180 | Rect layerStackRect, Rect displayRect) { |
| 181 | if (mCurrentOrientation != orientation |
| 182 | || mCurrentLayerStackRect == null |
| 183 | || !mCurrentLayerStackRect.equals(layerStackRect) |
| 184 | || mCurrentDisplayRect == null |
| 185 | || !mCurrentDisplayRect.equals(displayRect)) { |
| 186 | mCurrentOrientation = orientation; |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 187 | |
Jeff Brown | cbad976 | 2012-09-04 21:57:59 -0700 | [diff] [blame] | 188 | if (mCurrentLayerStackRect == null) { |
| 189 | mCurrentLayerStackRect = new Rect(); |
| 190 | } |
| 191 | mCurrentLayerStackRect.set(layerStackRect); |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 192 | |
Jeff Brown | cbad976 | 2012-09-04 21:57:59 -0700 | [diff] [blame] | 193 | if (mCurrentDisplayRect == null) { |
| 194 | mCurrentDisplayRect = new Rect(); |
| 195 | } |
| 196 | mCurrentDisplayRect.set(displayRect); |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 197 | |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 198 | t.setDisplayProjection(mDisplayToken, |
Jeff Brown | cbad976 | 2012-09-04 21:57:59 -0700 | [diff] [blame] | 199 | orientation, layerStackRect, displayRect); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 200 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | /** |
Jeff Brown | cbad976 | 2012-09-04 21:57:59 -0700 | [diff] [blame] | 204 | * Sets the display surface while in a transaction. |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 205 | */ |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 206 | public final void setSurfaceLocked(SurfaceControl.Transaction t, Surface surface) { |
Jeff Brown | cbad976 | 2012-09-04 21:57:59 -0700 | [diff] [blame] | 207 | if (mCurrentSurface != surface) { |
| 208 | mCurrentSurface = surface; |
Robert Carr | ae606b4 | 2018-02-15 15:36:23 -0800 | [diff] [blame] | 209 | t.setDisplaySurface(mDisplayToken, surface); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 210 | } |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | /** |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 214 | * Populates the specified viewport object with orientation, |
| 215 | * physical and logical rects based on the display's current projection. |
| 216 | */ |
| 217 | public final void populateViewportLocked(DisplayViewport viewport) { |
| 218 | viewport.orientation = mCurrentOrientation; |
| 219 | |
| 220 | if (mCurrentLayerStackRect != null) { |
| 221 | viewport.logicalFrame.set(mCurrentLayerStackRect); |
| 222 | } else { |
| 223 | viewport.logicalFrame.setEmpty(); |
| 224 | } |
| 225 | |
| 226 | if (mCurrentDisplayRect != null) { |
| 227 | viewport.physicalFrame.set(mCurrentDisplayRect); |
| 228 | } else { |
| 229 | viewport.physicalFrame.setEmpty(); |
| 230 | } |
Jeff Brown | 83d616a | 2012-09-09 20:33:43 -0700 | [diff] [blame] | 231 | |
| 232 | boolean isRotated = (mCurrentOrientation == Surface.ROTATION_90 |
| 233 | || mCurrentOrientation == Surface.ROTATION_270); |
| 234 | DisplayDeviceInfo info = getDisplayDeviceInfoLocked(); |
| 235 | viewport.deviceWidth = isRotated ? info.height : info.width; |
| 236 | viewport.deviceHeight = isRotated ? info.width : info.height; |
Siarhei Vishniakou | 2eb0f8f | 2018-07-06 23:30:12 +0100 | [diff] [blame] | 237 | |
| 238 | viewport.uniqueId = info.uniqueId; |
Dominik Laskowski | db84596 | 2019-01-27 21:20:00 -0800 | [diff] [blame] | 239 | |
| 240 | if (info.address instanceof DisplayAddress.Physical) { |
| 241 | viewport.physicalPort = ((DisplayAddress.Physical) info.address).getPort(); |
| 242 | } else { |
| 243 | viewport.physicalPort = null; |
| 244 | } |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | /** |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 248 | * Dumps the local state of the display device. |
| 249 | * Does not need to dump the display device info because that is already dumped elsewhere. |
| 250 | */ |
| 251 | public void dumpLocked(PrintWriter pw) { |
| 252 | pw.println("mAdapter=" + mDisplayAdapter.getName()); |
Wale Ogunwale | 361ca21 | 2014-11-20 11:42:38 -0800 | [diff] [blame] | 253 | pw.println("mUniqueId=" + mUniqueId); |
Jeff Brown | cbad976 | 2012-09-04 21:57:59 -0700 | [diff] [blame] | 254 | pw.println("mDisplayToken=" + mDisplayToken); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 255 | pw.println("mCurrentLayerStack=" + mCurrentLayerStack); |
| 256 | pw.println("mCurrentOrientation=" + mCurrentOrientation); |
Jeff Brown | cbad976 | 2012-09-04 21:57:59 -0700 | [diff] [blame] | 257 | pw.println("mCurrentLayerStackRect=" + mCurrentLayerStackRect); |
| 258 | pw.println("mCurrentDisplayRect=" + mCurrentDisplayRect); |
| 259 | pw.println("mCurrentSurface=" + mCurrentSurface); |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 260 | } |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 261 | } |