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