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