blob: 839ab4d4867d4842739a773462e79854553d0952 [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;
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -070022import android.view.Display;
Jeff Brown4ed8fe72012-08-30 18:18:29 -070023import android.view.Surface;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080024import android.view.SurfaceControl;
Jeff Brown4ed8fe72012-08-30 18:18:29 -070025
26import java.io.PrintWriter;
Jeff Brown64a55af2012-08-26 02:47:39 -070027
Jeff Brownfa25bf52012-07-23 19:26:30 -070028/**
29 * Represents a physical display device such as the built-in display
Jeff Brown848c2dc2012-08-19 20:18:08 -070030 * an external monitor, or a WiFi display.
Jeff Brownbd6e1502012-08-28 03:27:37 -070031 * <p>
Jeff Brown4ed8fe72012-08-30 18:18:29 -070032 * Display devices are guarded by the {@link DisplayManagerService.SyncRoot} lock.
Jeff Brownbd6e1502012-08-28 03:27:37 -070033 * </p>
Jeff Brownfa25bf52012-07-23 19:26:30 -070034 */
Jeff Brown4ed8fe72012-08-30 18:18:29 -070035abstract class DisplayDevice {
Jeff Brownbd6e1502012-08-28 03:27:37 -070036 private final DisplayAdapter mDisplayAdapter;
37 private final IBinder mDisplayToken;
Wale Ogunwale361ca212014-11-20 11:42:38 -080038 private final String mUniqueId;
Jeff Brownbd6e1502012-08-28 03:27:37 -070039
Jeff Brown4ed8fe72012-08-30 18:18:29 -070040 // 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 Agopian63f1c432012-09-04 19:29:13 -070044 private Rect mCurrentLayerStackRect;
45 private Rect mCurrentDisplayRect;
Jeff Brown4ed8fe72012-08-30 18:18:29 -070046
Jeff Browncbad9762012-09-04 21:57:59 -070047 // The display device owns its surface, but it should only set it
Jeff Brown4ed8fe72012-08-30 18:18:29 -070048 // within a transaction from performTraversalInTransactionLocked.
Jeff Browncbad9762012-09-04 21:57:59 -070049 private Surface mCurrentSurface;
Jeff Brown4ed8fe72012-08-30 18:18:29 -070050
Jeff Brown10acf6d2015-04-14 14:20:47 -070051 // 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 Ogunwale361ca212014-11-20 11:42:38 -080055 public DisplayDevice(DisplayAdapter displayAdapter, IBinder displayToken, String uniqueId) {
Jeff Brownbd6e1502012-08-28 03:27:37 -070056 mDisplayAdapter = displayAdapter;
57 mDisplayToken = displayToken;
Wale Ogunwale361ca212014-11-20 11:42:38 -080058 mUniqueId = uniqueId;
Jeff Brownbd6e1502012-08-28 03:27:37 -070059 }
60
Jeff Brown848c2dc2012-08-19 20:18:08 -070061 /**
Jeff Brownbd6e1502012-08-28 03:27:37 -070062 * Gets the display adapter that owns the display device.
Jeff Brown848c2dc2012-08-19 20:18:08 -070063 *
64 * @return The display adapter.
65 */
Jeff Brown4ed8fe72012-08-30 18:18:29 -070066 public final DisplayAdapter getAdapterLocked() {
Jeff Brownbd6e1502012-08-28 03:27:37 -070067 return mDisplayAdapter;
68 }
Jeff Brown848c2dc2012-08-19 20:18:08 -070069
70 /**
Jeff Brown64a55af2012-08-26 02:47:39 -070071 * 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 Brown4ed8fe72012-08-30 18:18:29 -070076 public final IBinder getDisplayTokenLocked() {
Jeff Brownbd6e1502012-08-28 03:27:37 -070077 return mDisplayToken;
78 }
Jeff Brown64a55af2012-08-26 02:47:39 -070079
80 /**
Jeff Brown4ed8fe72012-08-30 18:18:29 -070081 * 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 Ogunwale361ca212014-11-20 11:42:38 -080090 * Returns the unique id of the display device.
91 */
92 public final String getUniqueId() {
93 return mUniqueId;
94 }
95
96 /**
Michael Wright1c9977b2016-07-12 13:30:10 -070097 * Returns whether the unique id of the device is stable across reboots.
98 */
99 public abstract boolean hasStableUniqueId();
100
101 /**
Jeff Brown848c2dc2012-08-19 20:18:08 -0700102 * Gets information about the display device.
103 *
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700104 * 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 Brown848c2dc2012-08-19 20:18:08 -0700112 */
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700113 public abstract DisplayDeviceInfo getDisplayDeviceInfoLocked();
Jeff Brownbd6e1502012-08-28 03:27:37 -0700114
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700115 /**
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 */
125 public void performTraversalInTransactionLocked() {
126 }
127
128 /**
Jeff Brown037c33e2014-04-09 00:31:55 -0700129 * Sets the display state, if supported.
Jeff Browne75926d2014-09-18 15:24:49 -0700130 *
Jeff Brown5d6443b2015-04-10 20:15:01 -0700131 * @param state The new display state.
132 * @param brightness The new display brightness.
Jeff Browne75926d2014-09-18 15:24:49 -0700133 * @return A runnable containing work to be deferred until after we have
134 * exited the critical section, or null if none.
Jeff Brown9e316a12012-10-08 19:17:06 -0700135 */
Jeff Brown5d6443b2015-04-10 20:15:01 -0700136 public Runnable requestDisplayStateLocked(int state, int brightness) {
Jeff Browne75926d2014-09-18 15:24:49 -0700137 return null;
Jeff Brown9e316a12012-10-08 19:17:06 -0700138 }
139
140 /**
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700141 * Sets the mode, if supported.
Michael Wright3f145a22014-07-22 19:46:03 -0700142 */
Michael Wright1c9977b2016-07-12 13:30:10 -0700143 public void requestDisplayModesInTransactionLocked(int colorMode, int modeId) {
Michael Wright3f145a22014-07-22 19:46:03 -0700144 }
145
146 /**
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700147 * Sets the display layer stack while in a transaction.
148 */
149 public final void setLayerStackInTransactionLocked(int layerStack) {
Jeff Browncbad9762012-09-04 21:57:59 -0700150 if (mCurrentLayerStack != layerStack) {
151 mCurrentLayerStack = layerStack;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800152 SurfaceControl.setDisplayLayerStack(mDisplayToken, layerStack);
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700153 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700154 }
155
156 /**
Mathias Agopian63f1c432012-09-04 19:29:13 -0700157 * Sets the display projection while in a transaction.
158 *
159 * @param orientation defines the display's orientation
160 * @param layerStackRect defines which area of the window manager coordinate
161 * space will be used
162 * @param displayRect defines where on the display will layerStackRect be
163 * mapped to. displayRect is specified post-orientation, that is
164 * it uses the orientation seen by the end-user
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700165 */
Jeff Browncbad9762012-09-04 21:57:59 -0700166 public final void setProjectionInTransactionLocked(int orientation,
167 Rect layerStackRect, Rect displayRect) {
168 if (mCurrentOrientation != orientation
169 || mCurrentLayerStackRect == null
170 || !mCurrentLayerStackRect.equals(layerStackRect)
171 || mCurrentDisplayRect == null
172 || !mCurrentDisplayRect.equals(displayRect)) {
173 mCurrentOrientation = orientation;
Jeff Brownd728bf52012-09-08 18:05:28 -0700174
Jeff Browncbad9762012-09-04 21:57:59 -0700175 if (mCurrentLayerStackRect == null) {
176 mCurrentLayerStackRect = new Rect();
177 }
178 mCurrentLayerStackRect.set(layerStackRect);
Jeff Brownd728bf52012-09-08 18:05:28 -0700179
Jeff Browncbad9762012-09-04 21:57:59 -0700180 if (mCurrentDisplayRect == null) {
181 mCurrentDisplayRect = new Rect();
182 }
183 mCurrentDisplayRect.set(displayRect);
Jeff Brownd728bf52012-09-08 18:05:28 -0700184
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800185 SurfaceControl.setDisplayProjection(mDisplayToken,
Jeff Browncbad9762012-09-04 21:57:59 -0700186 orientation, layerStackRect, displayRect);
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700187 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700188 }
189
190 /**
Jeff Browncbad9762012-09-04 21:57:59 -0700191 * Sets the display surface while in a transaction.
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700192 */
Jeff Browncbad9762012-09-04 21:57:59 -0700193 public final void setSurfaceInTransactionLocked(Surface surface) {
194 if (mCurrentSurface != surface) {
195 mCurrentSurface = surface;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800196 SurfaceControl.setDisplaySurface(mDisplayToken, surface);
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700197 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700198 }
199
200 /**
Jeff Brownd728bf52012-09-08 18:05:28 -0700201 * Populates the specified viewport object with orientation,
202 * physical and logical rects based on the display's current projection.
203 */
204 public final void populateViewportLocked(DisplayViewport viewport) {
205 viewport.orientation = mCurrentOrientation;
206
207 if (mCurrentLayerStackRect != null) {
208 viewport.logicalFrame.set(mCurrentLayerStackRect);
209 } else {
210 viewport.logicalFrame.setEmpty();
211 }
212
213 if (mCurrentDisplayRect != null) {
214 viewport.physicalFrame.set(mCurrentDisplayRect);
215 } else {
216 viewport.physicalFrame.setEmpty();
217 }
Jeff Brown83d616a2012-09-09 20:33:43 -0700218
219 boolean isRotated = (mCurrentOrientation == Surface.ROTATION_90
220 || mCurrentOrientation == Surface.ROTATION_270);
221 DisplayDeviceInfo info = getDisplayDeviceInfoLocked();
222 viewport.deviceWidth = isRotated ? info.height : info.width;
223 viewport.deviceHeight = isRotated ? info.width : info.height;
Jeff Brownd728bf52012-09-08 18:05:28 -0700224 }
225
226 /**
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700227 * Dumps the local state of the display device.
228 * Does not need to dump the display device info because that is already dumped elsewhere.
229 */
230 public void dumpLocked(PrintWriter pw) {
231 pw.println("mAdapter=" + mDisplayAdapter.getName());
Wale Ogunwale361ca212014-11-20 11:42:38 -0800232 pw.println("mUniqueId=" + mUniqueId);
Jeff Browncbad9762012-09-04 21:57:59 -0700233 pw.println("mDisplayToken=" + mDisplayToken);
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700234 pw.println("mCurrentLayerStack=" + mCurrentLayerStack);
235 pw.println("mCurrentOrientation=" + mCurrentOrientation);
Jeff Browncbad9762012-09-04 21:57:59 -0700236 pw.println("mCurrentLayerStackRect=" + mCurrentLayerStackRect);
237 pw.println("mCurrentDisplayRect=" + mCurrentDisplayRect);
238 pw.println("mCurrentSurface=" + mCurrentSurface);
Jeff Brownbd6e1502012-08-28 03:27:37 -0700239 }
Jeff Brownfa25bf52012-07-23 19:26:30 -0700240}