blob: ee36972f7c82fe65e5db189e9cee1032acb04645 [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;
Jeff Brown4ed8fe72012-08-30 18:18:29 -070022import android.view.Surface;
Mathias Agopian3866f0d2013-02-11 22:08:48 -080023import android.view.SurfaceControl;
Jeff Brown4ed8fe72012-08-30 18:18:29 -070024
25import java.io.PrintWriter;
Jeff Brown64a55af2012-08-26 02:47:39 -070026
Jeff Brownfa25bf52012-07-23 19:26:30 -070027/**
28 * Represents a physical display device such as the built-in display
Jeff Brown848c2dc2012-08-19 20:18:08 -070029 * an external monitor, or a WiFi display.
Jeff Brownbd6e1502012-08-28 03:27:37 -070030 * <p>
Jeff Brown4ed8fe72012-08-30 18:18:29 -070031 * Display devices are guarded by the {@link DisplayManagerService.SyncRoot} lock.
Jeff Brownbd6e1502012-08-28 03:27:37 -070032 * </p>
Jeff Brownfa25bf52012-07-23 19:26:30 -070033 */
Jeff Brown4ed8fe72012-08-30 18:18:29 -070034abstract class DisplayDevice {
Jeff Brownbd6e1502012-08-28 03:27:37 -070035 private final DisplayAdapter mDisplayAdapter;
36 private final IBinder mDisplayToken;
Wale Ogunwale361ca212014-11-20 11:42:38 -080037 private final String mUniqueId;
Jeff Brownbd6e1502012-08-28 03:27:37 -070038
Jeff Brown4ed8fe72012-08-30 18:18:29 -070039 // 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 Agopian63f1c432012-09-04 19:29:13 -070043 private Rect mCurrentLayerStackRect;
44 private Rect mCurrentDisplayRect;
Jeff Brown4ed8fe72012-08-30 18:18:29 -070045
Jeff Browncbad9762012-09-04 21:57:59 -070046 // The display device owns its surface, but it should only set it
Jeff Brown4ed8fe72012-08-30 18:18:29 -070047 // within a transaction from performTraversalInTransactionLocked.
Jeff Browncbad9762012-09-04 21:57:59 -070048 private Surface mCurrentSurface;
Jeff Brown4ed8fe72012-08-30 18:18:29 -070049
Jeff Brown10acf6d2015-04-14 14:20:47 -070050 // 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 Ogunwale361ca212014-11-20 11:42:38 -080054 public DisplayDevice(DisplayAdapter displayAdapter, IBinder displayToken, String uniqueId) {
Jeff Brownbd6e1502012-08-28 03:27:37 -070055 mDisplayAdapter = displayAdapter;
56 mDisplayToken = displayToken;
Wale Ogunwale361ca212014-11-20 11:42:38 -080057 mUniqueId = uniqueId;
Jeff Brownbd6e1502012-08-28 03:27:37 -070058 }
59
Jeff Brown848c2dc2012-08-19 20:18:08 -070060 /**
Jeff Brownbd6e1502012-08-28 03:27:37 -070061 * Gets the display adapter that owns the display device.
Jeff Brown848c2dc2012-08-19 20:18:08 -070062 *
63 * @return The display adapter.
64 */
Jeff Brown4ed8fe72012-08-30 18:18:29 -070065 public final DisplayAdapter getAdapterLocked() {
Jeff Brownbd6e1502012-08-28 03:27:37 -070066 return mDisplayAdapter;
67 }
Jeff Brown848c2dc2012-08-19 20:18:08 -070068
69 /**
Jeff Brown64a55af2012-08-26 02:47:39 -070070 * 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 Brown4ed8fe72012-08-30 18:18:29 -070075 public final IBinder getDisplayTokenLocked() {
Jeff Brownbd6e1502012-08-28 03:27:37 -070076 return mDisplayToken;
77 }
Jeff Brown64a55af2012-08-26 02:47:39 -070078
79 /**
Jeff Brown4ed8fe72012-08-30 18:18:29 -070080 * 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 Ogunwale361ca212014-11-20 11:42:38 -080089 * Returns the unique id of the display device.
90 */
91 public final String getUniqueId() {
92 return mUniqueId;
93 }
94
95 /**
Jeff Brown848c2dc2012-08-19 20:18:08 -070096 * Gets information about the display device.
97 *
Jeff Brown4ed8fe72012-08-30 18:18:29 -070098 * 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 Brown848c2dc2012-08-19 20:18:08 -0700106 */
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700107 public abstract DisplayDeviceInfo getDisplayDeviceInfoLocked();
Jeff Brownbd6e1502012-08-28 03:27:37 -0700108
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700109 /**
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 Brown037c33e2014-04-09 00:31:55 -0700123 * Sets the display state, if supported.
Jeff Browne75926d2014-09-18 15:24:49 -0700124 *
Jeff Brown5d6443b2015-04-10 20:15:01 -0700125 * @param state The new display state.
126 * @param brightness The new display brightness.
Jeff Browne75926d2014-09-18 15:24:49 -0700127 * @return A runnable containing work to be deferred until after we have
128 * exited the critical section, or null if none.
Jeff Brown9e316a12012-10-08 19:17:06 -0700129 */
Jeff Brown5d6443b2015-04-10 20:15:01 -0700130 public Runnable requestDisplayStateLocked(int state, int brightness) {
Jeff Browne75926d2014-09-18 15:24:49 -0700131 return null;
Jeff Brown9e316a12012-10-08 19:17:06 -0700132 }
133
134 /**
Michael Wright3f145a22014-07-22 19:46:03 -0700135 * Sets the refresh rate, if supported.
136 */
137 public void requestRefreshRateLocked(float refreshRate) {
138 }
139
140 /**
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700141 * Sets the display layer stack while in a transaction.
142 */
143 public final void setLayerStackInTransactionLocked(int layerStack) {
Jeff Browncbad9762012-09-04 21:57:59 -0700144 if (mCurrentLayerStack != layerStack) {
145 mCurrentLayerStack = layerStack;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800146 SurfaceControl.setDisplayLayerStack(mDisplayToken, layerStack);
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700147 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700148 }
149
150 /**
Mathias Agopian63f1c432012-09-04 19:29:13 -0700151 * 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 Brown4ed8fe72012-08-30 18:18:29 -0700159 */
Jeff Browncbad9762012-09-04 21:57:59 -0700160 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 Brownd728bf52012-09-08 18:05:28 -0700168
Jeff Browncbad9762012-09-04 21:57:59 -0700169 if (mCurrentLayerStackRect == null) {
170 mCurrentLayerStackRect = new Rect();
171 }
172 mCurrentLayerStackRect.set(layerStackRect);
Jeff Brownd728bf52012-09-08 18:05:28 -0700173
Jeff Browncbad9762012-09-04 21:57:59 -0700174 if (mCurrentDisplayRect == null) {
175 mCurrentDisplayRect = new Rect();
176 }
177 mCurrentDisplayRect.set(displayRect);
Jeff Brownd728bf52012-09-08 18:05:28 -0700178
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800179 SurfaceControl.setDisplayProjection(mDisplayToken,
Jeff Browncbad9762012-09-04 21:57:59 -0700180 orientation, layerStackRect, displayRect);
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700181 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700182 }
183
184 /**
Jeff Browncbad9762012-09-04 21:57:59 -0700185 * Sets the display surface while in a transaction.
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700186 */
Jeff Browncbad9762012-09-04 21:57:59 -0700187 public final void setSurfaceInTransactionLocked(Surface surface) {
188 if (mCurrentSurface != surface) {
189 mCurrentSurface = surface;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800190 SurfaceControl.setDisplaySurface(mDisplayToken, surface);
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700191 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700192 }
193
194 /**
Jeff Brownd728bf52012-09-08 18:05:28 -0700195 * 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 Brown83d616a2012-09-09 20:33:43 -0700212
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 Brownd728bf52012-09-08 18:05:28 -0700218 }
219
220 /**
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700221 * 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 Ogunwale361ca212014-11-20 11:42:38 -0800226 pw.println("mUniqueId=" + mUniqueId);
Jeff Browncbad9762012-09-04 21:57:59 -0700227 pw.println("mDisplayToken=" + mDisplayToken);
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700228 pw.println("mCurrentLayerStack=" + mCurrentLayerStack);
229 pw.println("mCurrentOrientation=" + mCurrentOrientation);
Jeff Browncbad9762012-09-04 21:57:59 -0700230 pw.println("mCurrentLayerStackRect=" + mCurrentLayerStackRect);
231 pw.println("mCurrentDisplayRect=" + mCurrentDisplayRect);
232 pw.println("mCurrentSurface=" + mCurrentSurface);
Jeff Brownbd6e1502012-08-28 03:27:37 -0700233 }
Jeff Brownfa25bf52012-07-23 19:26:30 -0700234}