blob: 3516981c92a61b5f2a4450a3d037485ab5d59cf7 [file] [log] [blame]
Jeff Brownfa25bf52012-07-23 19:26:30 -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
Jeff Brown4ed8fe72012-08-30 18:18:29 -070019import android.graphics.Rect;
Jeff Brown4ccb8232014-01-16 22:16:42 -080020import android.hardware.display.DisplayViewport;
Jeff Brown64a55af2012-08-26 02:47:39 -070021import android.os.IBinder;
b0202.jung925435c2020-01-08 18:46:59 +090022import android.view.Display;
Dominik Laskowskidb845962019-01-27 21:20:00 -080023import android.view.DisplayAddress;
Jeff Brown4ed8fe72012-08-30 18:18:29 -070024import android.view.Surface;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080025import android.view.SurfaceControl;
Jeff Brown4ed8fe72012-08-30 18:18:29 -070026
27import java.io.PrintWriter;
Jeff Brown64a55af2012-08-26 02:47:39 -070028
Jeff Brownfa25bf52012-07-23 19:26:30 -070029/**
30 * Represents a physical display device such as the built-in display
Jeff Brown848c2dc2012-08-19 20:18:08 -070031 * an external monitor, or a WiFi display.
Jeff Brownbd6e1502012-08-28 03:27:37 -070032 * <p>
Jeff Brown4ed8fe72012-08-30 18:18:29 -070033 * Display devices are guarded by the {@link DisplayManagerService.SyncRoot} lock.
Jeff Brownbd6e1502012-08-28 03:27:37 -070034 * </p>
Jeff Brownfa25bf52012-07-23 19:26:30 -070035 */
Jeff Brown4ed8fe72012-08-30 18:18:29 -070036abstract class DisplayDevice {
Jeff Brownbd6e1502012-08-28 03:27:37 -070037 private final DisplayAdapter mDisplayAdapter;
38 private final IBinder mDisplayToken;
Wale Ogunwale361ca212014-11-20 11:42:38 -080039 private final String mUniqueId;
Fiona Campbell172fd4a2020-03-13 16:34:30 +000040 private DisplayDeviceConfig mDisplayDeviceConfig;
Jeff Brownbd6e1502012-08-28 03:27:37 -070041
Jeff Brown4ed8fe72012-08-30 18:18:29 -070042 // The display device does not manage these properties itself, they are set by
43 // the display manager service. The display device shouldn't really be looking at these.
44 private int mCurrentLayerStack = -1;
45 private int mCurrentOrientation = -1;
Mathias Agopian63f1c432012-09-04 19:29:13 -070046 private Rect mCurrentLayerStackRect;
47 private Rect mCurrentDisplayRect;
Jeff Brown4ed8fe72012-08-30 18:18:29 -070048
Jeff Browncbad9762012-09-04 21:57:59 -070049 // The display device owns its surface, but it should only set it
Robert Carrae606b42018-02-15 15:36:23 -080050 // within a transaction from performTraversalLocked.
Jeff Browncbad9762012-09-04 21:57:59 -070051 private Surface mCurrentSurface;
Jeff Brown4ed8fe72012-08-30 18:18:29 -070052
Jeff Brown10acf6d2015-04-14 14:20:47 -070053 // DEBUG STATE: Last device info which was written to the log, or null if none.
54 // Do not use for any other purpose.
55 DisplayDeviceInfo mDebugLastLoggedDeviceInfo;
56
Wale Ogunwale361ca212014-11-20 11:42:38 -080057 public DisplayDevice(DisplayAdapter displayAdapter, IBinder displayToken, String uniqueId) {
Jeff Brownbd6e1502012-08-28 03:27:37 -070058 mDisplayAdapter = displayAdapter;
59 mDisplayToken = displayToken;
Wale Ogunwale361ca212014-11-20 11:42:38 -080060 mUniqueId = uniqueId;
Jeff Brownbd6e1502012-08-28 03:27:37 -070061 }
62
Jeff Brown848c2dc2012-08-19 20:18:08 -070063 /**
Jeff Brownbd6e1502012-08-28 03:27:37 -070064 * Gets the display adapter that owns the display device.
Jeff Brown848c2dc2012-08-19 20:18:08 -070065 *
66 * @return The display adapter.
67 */
Jeff Brown4ed8fe72012-08-30 18:18:29 -070068 public final DisplayAdapter getAdapterLocked() {
Jeff Brownbd6e1502012-08-28 03:27:37 -070069 return mDisplayAdapter;
70 }
Jeff Brown848c2dc2012-08-19 20:18:08 -070071
Fiona Campbell172fd4a2020-03-13 16:34:30 +000072 /*
73 * Gets the DisplayDeviceConfig for this DisplayDevice.
74 * Returns null for this device but is overridden in LocalDisplayDevice.
75 *
76 * @return The DisplayDeviceConfig.
77 */
78 public DisplayDeviceConfig getDisplayDeviceConfig() {
79 return mDisplayDeviceConfig;
80 }
81
Jeff Brown848c2dc2012-08-19 20:18:08 -070082 /**
Jeff Brown64a55af2012-08-26 02:47:39 -070083 * Gets the Surface Flinger display token for this display.
84 *
85 * @return The display token, or null if the display is not being managed
86 * by Surface Flinger.
87 */
Jeff Brown4ed8fe72012-08-30 18:18:29 -070088 public final IBinder getDisplayTokenLocked() {
Jeff Brownbd6e1502012-08-28 03:27:37 -070089 return mDisplayToken;
90 }
Jeff Brown64a55af2012-08-26 02:47:39 -070091
92 /**
b0202.jung925435c2020-01-08 18:46:59 +090093 * Gets the id of the display to mirror.
94 */
95 public int getDisplayIdToMirrorLocked() {
96 return Display.DEFAULT_DISPLAY;
97 }
98
99 /**
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700100 * Gets the name of the display device.
101 *
102 * @return The display device name.
103 */
104 public final String getNameLocked() {
105 return getDisplayDeviceInfoLocked().name;
106 }
107
108 /**
Wale Ogunwale361ca212014-11-20 11:42:38 -0800109 * Returns the unique id of the display device.
110 */
111 public final String getUniqueId() {
112 return mUniqueId;
113 }
114
115 /**
Michael Wright1c9977b2016-07-12 13:30:10 -0700116 * Returns whether the unique id of the device is stable across reboots.
117 */
118 public abstract boolean hasStableUniqueId();
119
120 /**
Jeff Brown848c2dc2012-08-19 20:18:08 -0700121 * Gets information about the display device.
122 *
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700123 * The information returned should not change between calls unless the display
124 * adapter sent a {@link DisplayAdapter#DISPLAY_DEVICE_EVENT_CHANGED} event and
125 * {@link #applyPendingDisplayDeviceInfoChangesLocked()} has been called to apply
126 * the pending changes.
127 *
128 * @return The display device info, which should be treated as immutable by the caller.
129 * The display device should allocate a new display device info object whenever
130 * the data changes.
Jeff Brown848c2dc2012-08-19 20:18:08 -0700131 */
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700132 public abstract DisplayDeviceInfo getDisplayDeviceInfoLocked();
Jeff Brownbd6e1502012-08-28 03:27:37 -0700133
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700134 /**
135 * Applies any pending changes to the observable state of the display device
136 * if the display adapter sent a {@link DisplayAdapter#DISPLAY_DEVICE_EVENT_CHANGED} event.
137 */
138 public void applyPendingDisplayDeviceInfoChangesLocked() {
139 }
140
141 /**
142 * Gives the display device a chance to update its properties while in a transaction.
143 */
Robert Carrae606b42018-02-15 15:36:23 -0800144 public void performTraversalLocked(SurfaceControl.Transaction t) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700145 }
146
147 /**
Jeff Brown037c33e2014-04-09 00:31:55 -0700148 * Sets the display state, if supported.
Jeff Browne75926d2014-09-18 15:24:49 -0700149 *
Jeff Brown5d6443b2015-04-10 20:15:01 -0700150 * @param state The new display state.
Fiona Campbelld4eb2952019-11-04 17:19:56 +0000151 * @param brightnessState The new display brightnessState.
Jeff Browne75926d2014-09-18 15:24:49 -0700152 * @return A runnable containing work to be deferred until after we have
153 * exited the critical section, or null if none.
Jeff Brown9e316a12012-10-08 19:17:06 -0700154 */
Fiona Campbelld4eb2952019-11-04 17:19:56 +0000155 public Runnable requestDisplayStateLocked(int state, float brightnessState) {
Jeff Browne75926d2014-09-18 15:24:49 -0700156 return null;
Jeff Brown9e316a12012-10-08 19:17:06 -0700157 }
158
159 /**
Ana Kruleca74a8642019-11-14 00:51:00 +0100160 * Sets the display mode specs.
Michael Wrighta3dab232019-02-22 16:54:21 +0000161 *
162 * Not all display devices will automatically switch between modes, so it's important that the
Ana Kruleca74a8642019-11-14 00:51:00 +0100163 * default modeId is set correctly.
Michael Wright3f145a22014-07-22 19:46:03 -0700164 */
Ana Kruleca74a8642019-11-14 00:51:00 +0100165 public void setDesiredDisplayModeSpecsLocked(
166 DisplayModeDirector.DesiredDisplayModeSpecs displayModeSpecs) {}
Michael Wrighta3dab232019-02-22 16:54:21 +0000167
168 /**
169 * Sets the requested color mode.
170 */
171 public void setRequestedColorModeLocked(int colorMode) {
Michael Wright3f145a22014-07-22 19:46:03 -0700172 }
173
Galia Peycheva056b3ee2019-06-26 14:05:12 +0200174 /**
175 * Sends the Auto Low Latency Mode (ALLM) signal over HDMI, or requests an internal display to
176 * switch to a low-latency mode.
177 *
178 * @param on Whether to set ALLM on or off.
179 */
180 public void setAutoLowLatencyModeLocked(boolean on) {
181 }
182
183 /**
184 * Sends a ContentType=Game signal over HDMI, or requests an internal display to switch to a
185 * game mode (generally lower latency).
186 *
187 * @param on Whether to send a ContentType=Game signal or not
188 */
189 public void setGameContentTypeLocked(boolean on) {
190 }
191
Adrian Roos898ec382018-01-17 12:54:50 +0100192 public void onOverlayChangedLocked() {
193 }
194
Michael Wright3f145a22014-07-22 19:46:03 -0700195 /**
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700196 * Sets the display layer stack while in a transaction.
197 */
Robert Carrae606b42018-02-15 15:36:23 -0800198 public final void setLayerStackLocked(SurfaceControl.Transaction t, int layerStack) {
Jeff Browncbad9762012-09-04 21:57:59 -0700199 if (mCurrentLayerStack != layerStack) {
200 mCurrentLayerStack = layerStack;
Robert Carrae606b42018-02-15 15:36:23 -0800201 t.setDisplayLayerStack(mDisplayToken, layerStack);
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700202 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700203 }
204
205 /**
Mathias Agopian63f1c432012-09-04 19:29:13 -0700206 * Sets the display projection while in a transaction.
207 *
208 * @param orientation defines the display's orientation
209 * @param layerStackRect defines which area of the window manager coordinate
210 * space will be used
211 * @param displayRect defines where on the display will layerStackRect be
212 * mapped to. displayRect is specified post-orientation, that is
213 * it uses the orientation seen by the end-user
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700214 */
Robert Carrae606b42018-02-15 15:36:23 -0800215 public final void setProjectionLocked(SurfaceControl.Transaction t, int orientation,
Jeff Browncbad9762012-09-04 21:57:59 -0700216 Rect layerStackRect, Rect displayRect) {
217 if (mCurrentOrientation != orientation
218 || mCurrentLayerStackRect == null
219 || !mCurrentLayerStackRect.equals(layerStackRect)
220 || mCurrentDisplayRect == null
221 || !mCurrentDisplayRect.equals(displayRect)) {
222 mCurrentOrientation = orientation;
Jeff Brownd728bf52012-09-08 18:05:28 -0700223
Jeff Browncbad9762012-09-04 21:57:59 -0700224 if (mCurrentLayerStackRect == null) {
225 mCurrentLayerStackRect = new Rect();
226 }
227 mCurrentLayerStackRect.set(layerStackRect);
Jeff Brownd728bf52012-09-08 18:05:28 -0700228
Jeff Browncbad9762012-09-04 21:57:59 -0700229 if (mCurrentDisplayRect == null) {
230 mCurrentDisplayRect = new Rect();
231 }
232 mCurrentDisplayRect.set(displayRect);
Jeff Brownd728bf52012-09-08 18:05:28 -0700233
Robert Carrae606b42018-02-15 15:36:23 -0800234 t.setDisplayProjection(mDisplayToken,
Jeff Browncbad9762012-09-04 21:57:59 -0700235 orientation, layerStackRect, displayRect);
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700236 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700237 }
238
239 /**
Jeff Browncbad9762012-09-04 21:57:59 -0700240 * Sets the display surface while in a transaction.
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700241 */
Robert Carrae606b42018-02-15 15:36:23 -0800242 public final void setSurfaceLocked(SurfaceControl.Transaction t, Surface surface) {
Jeff Browncbad9762012-09-04 21:57:59 -0700243 if (mCurrentSurface != surface) {
244 mCurrentSurface = surface;
Robert Carrae606b42018-02-15 15:36:23 -0800245 t.setDisplaySurface(mDisplayToken, surface);
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700246 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700247 }
248
249 /**
Jeff Brownd728bf52012-09-08 18:05:28 -0700250 * Populates the specified viewport object with orientation,
251 * physical and logical rects based on the display's current projection.
252 */
253 public final void populateViewportLocked(DisplayViewport viewport) {
254 viewport.orientation = mCurrentOrientation;
255
256 if (mCurrentLayerStackRect != null) {
257 viewport.logicalFrame.set(mCurrentLayerStackRect);
258 } else {
259 viewport.logicalFrame.setEmpty();
260 }
261
262 if (mCurrentDisplayRect != null) {
263 viewport.physicalFrame.set(mCurrentDisplayRect);
264 } else {
265 viewport.physicalFrame.setEmpty();
266 }
Jeff Brown83d616a2012-09-09 20:33:43 -0700267
268 boolean isRotated = (mCurrentOrientation == Surface.ROTATION_90
269 || mCurrentOrientation == Surface.ROTATION_270);
270 DisplayDeviceInfo info = getDisplayDeviceInfoLocked();
271 viewport.deviceWidth = isRotated ? info.height : info.width;
272 viewport.deviceHeight = isRotated ? info.width : info.height;
Siarhei Vishniakou2eb0f8f2018-07-06 23:30:12 +0100273
274 viewport.uniqueId = info.uniqueId;
Dominik Laskowskidb845962019-01-27 21:20:00 -0800275
276 if (info.address instanceof DisplayAddress.Physical) {
277 viewport.physicalPort = ((DisplayAddress.Physical) info.address).getPort();
278 } else {
279 viewport.physicalPort = null;
280 }
Jeff Brownd728bf52012-09-08 18:05:28 -0700281 }
282
283 /**
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700284 * Dumps the local state of the display device.
285 * Does not need to dump the display device info because that is already dumped elsewhere.
286 */
287 public void dumpLocked(PrintWriter pw) {
288 pw.println("mAdapter=" + mDisplayAdapter.getName());
Wale Ogunwale361ca212014-11-20 11:42:38 -0800289 pw.println("mUniqueId=" + mUniqueId);
Jeff Browncbad9762012-09-04 21:57:59 -0700290 pw.println("mDisplayToken=" + mDisplayToken);
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700291 pw.println("mCurrentLayerStack=" + mCurrentLayerStack);
292 pw.println("mCurrentOrientation=" + mCurrentOrientation);
Jeff Browncbad9762012-09-04 21:57:59 -0700293 pw.println("mCurrentLayerStackRect=" + mCurrentLayerStackRect);
294 pw.println("mCurrentDisplayRect=" + mCurrentDisplayRect);
295 pw.println("mCurrentSurface=" + mCurrentSurface);
Jeff Brownbd6e1502012-08-28 03:27:37 -0700296 }
Jeff Brownfa25bf52012-07-23 19:26:30 -0700297}