blob: e16be71d1e465e93b2f601cce981334bd7363fdc [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
Wale Ogunwale361ca212014-11-20 11:42:38 -080050 public DisplayDevice(DisplayAdapter displayAdapter, IBinder displayToken, String uniqueId) {
Jeff Brownbd6e1502012-08-28 03:27:37 -070051 mDisplayAdapter = displayAdapter;
52 mDisplayToken = displayToken;
Wale Ogunwale361ca212014-11-20 11:42:38 -080053 mUniqueId = uniqueId;
Jeff Brownbd6e1502012-08-28 03:27:37 -070054 }
55
Jeff Brown848c2dc2012-08-19 20:18:08 -070056 /**
Jeff Brownbd6e1502012-08-28 03:27:37 -070057 * Gets the display adapter that owns the display device.
Jeff Brown848c2dc2012-08-19 20:18:08 -070058 *
59 * @return The display adapter.
60 */
Jeff Brown4ed8fe72012-08-30 18:18:29 -070061 public final DisplayAdapter getAdapterLocked() {
Jeff Brownbd6e1502012-08-28 03:27:37 -070062 return mDisplayAdapter;
63 }
Jeff Brown848c2dc2012-08-19 20:18:08 -070064
65 /**
Jeff Brown64a55af2012-08-26 02:47:39 -070066 * 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 Brown4ed8fe72012-08-30 18:18:29 -070071 public final IBinder getDisplayTokenLocked() {
Jeff Brownbd6e1502012-08-28 03:27:37 -070072 return mDisplayToken;
73 }
Jeff Brown64a55af2012-08-26 02:47:39 -070074
75 /**
Jeff Brown4ed8fe72012-08-30 18:18:29 -070076 * 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 Ogunwale361ca212014-11-20 11:42:38 -080085 * Returns the unique id of the display device.
86 */
87 public final String getUniqueId() {
88 return mUniqueId;
89 }
90
91 /**
Jeff Brown848c2dc2012-08-19 20:18:08 -070092 * Gets information about the display device.
93 *
Jeff Brown4ed8fe72012-08-30 18:18:29 -070094 * 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 Brown848c2dc2012-08-19 20:18:08 -0700102 */
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700103 public abstract DisplayDeviceInfo getDisplayDeviceInfoLocked();
Jeff Brownbd6e1502012-08-28 03:27:37 -0700104
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700105 /**
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 Brown037c33e2014-04-09 00:31:55 -0700119 * Sets the display state, if supported.
Jeff Browne75926d2014-09-18 15:24:49 -0700120 *
Jeff Brown5d6443b2015-04-10 20:15:01 -0700121 * @param state The new display state.
122 * @param brightness The new display brightness.
Jeff Browne75926d2014-09-18 15:24:49 -0700123 * @return A runnable containing work to be deferred until after we have
124 * exited the critical section, or null if none.
Jeff Brown9e316a12012-10-08 19:17:06 -0700125 */
Jeff Brown5d6443b2015-04-10 20:15:01 -0700126 public Runnable requestDisplayStateLocked(int state, int brightness) {
Jeff Browne75926d2014-09-18 15:24:49 -0700127 return null;
Jeff Brown9e316a12012-10-08 19:17:06 -0700128 }
129
130 /**
Michael Wright3f145a22014-07-22 19:46:03 -0700131 * Sets the refresh rate, if supported.
132 */
133 public void requestRefreshRateLocked(float refreshRate) {
134 }
135
136 /**
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700137 * Sets the display layer stack while in a transaction.
138 */
139 public final void setLayerStackInTransactionLocked(int layerStack) {
Jeff Browncbad9762012-09-04 21:57:59 -0700140 if (mCurrentLayerStack != layerStack) {
141 mCurrentLayerStack = layerStack;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800142 SurfaceControl.setDisplayLayerStack(mDisplayToken, layerStack);
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700143 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700144 }
145
146 /**
Mathias Agopian63f1c432012-09-04 19:29:13 -0700147 * 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 Brown4ed8fe72012-08-30 18:18:29 -0700155 */
Jeff Browncbad9762012-09-04 21:57:59 -0700156 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 Brownd728bf52012-09-08 18:05:28 -0700164
Jeff Browncbad9762012-09-04 21:57:59 -0700165 if (mCurrentLayerStackRect == null) {
166 mCurrentLayerStackRect = new Rect();
167 }
168 mCurrentLayerStackRect.set(layerStackRect);
Jeff Brownd728bf52012-09-08 18:05:28 -0700169
Jeff Browncbad9762012-09-04 21:57:59 -0700170 if (mCurrentDisplayRect == null) {
171 mCurrentDisplayRect = new Rect();
172 }
173 mCurrentDisplayRect.set(displayRect);
Jeff Brownd728bf52012-09-08 18:05:28 -0700174
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800175 SurfaceControl.setDisplayProjection(mDisplayToken,
Jeff Browncbad9762012-09-04 21:57:59 -0700176 orientation, layerStackRect, displayRect);
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700177 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700178 }
179
180 /**
Jeff Browncbad9762012-09-04 21:57:59 -0700181 * Sets the display surface while in a transaction.
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700182 */
Jeff Browncbad9762012-09-04 21:57:59 -0700183 public final void setSurfaceInTransactionLocked(Surface surface) {
184 if (mCurrentSurface != surface) {
185 mCurrentSurface = surface;
Mathias Agopian3866f0d2013-02-11 22:08:48 -0800186 SurfaceControl.setDisplaySurface(mDisplayToken, surface);
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700187 }
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700188 }
189
190 /**
Jeff Brownd728bf52012-09-08 18:05:28 -0700191 * 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 Brown83d616a2012-09-09 20:33:43 -0700208
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 Brownd728bf52012-09-08 18:05:28 -0700214 }
215
216 /**
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700217 * 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 Ogunwale361ca212014-11-20 11:42:38 -0800222 pw.println("mUniqueId=" + mUniqueId);
Jeff Browncbad9762012-09-04 21:57:59 -0700223 pw.println("mDisplayToken=" + mDisplayToken);
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700224 pw.println("mCurrentLayerStack=" + mCurrentLayerStack);
225 pw.println("mCurrentOrientation=" + mCurrentOrientation);
Jeff Browncbad9762012-09-04 21:57:59 -0700226 pw.println("mCurrentLayerStackRect=" + mCurrentLayerStackRect);
227 pw.println("mCurrentDisplayRect=" + mCurrentDisplayRect);
228 pw.println("mCurrentSurface=" + mCurrentSurface);
Jeff Brownbd6e1502012-08-28 03:27:37 -0700229 }
Jeff Brownfa25bf52012-07-23 19:26:30 -0700230}