blob: d1e73f075e8056c9c3811b018497bbf0ca67f6c7 [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 Brown4ccb8232014-01-16 22:16:42 -080019import android.hardware.display.DisplayViewport;
Jeff Browncbad9762012-09-04 21:57:59 -070020import android.util.DisplayMetrics;
Jeff Brown92130f62012-10-24 21:28:33 -070021import android.view.Display;
Jeff Brown27f1d672012-10-17 18:32:34 -070022import android.view.Surface;
Jeff Browncbad9762012-09-04 21:57:59 -070023
Michael Wright3f145a22014-07-22 19:46:03 -070024import java.util.Arrays;
25
26import libcore.util.EmptyArray;
Jeff Brown4ed8fe72012-08-30 18:18:29 -070027import libcore.util.Objects;
28
Jeff Brownfa25bf52012-07-23 19:26:30 -070029/**
30 * Describes the characteristics of a physical display device.
31 */
Jeff Brown4ed8fe72012-08-30 18:18:29 -070032final class DisplayDeviceInfo {
33 /**
34 * Flag: Indicates that this display device should be considered the default display
35 * device of the system.
36 */
Jeff Brownbd6e1502012-08-28 03:27:37 -070037 public static final int FLAG_DEFAULT_DISPLAY = 1 << 0;
Jeff Brown4ed8fe72012-08-30 18:18:29 -070038
39 /**
Jeff Brown27f1d672012-10-17 18:32:34 -070040 * Flag: Indicates that the orientation of this display device is coupled to the
41 * rotation of its associated logical display.
42 * <p>
43 * This flag should be applied to the default display to indicate that the user
44 * physically rotates the display when content is presented in a different orientation.
45 * The display manager will apply a coordinate transformation assuming that the
46 * physical orientation of the display matches the logical orientation of its content.
47 * </p><p>
48 * The flag should not be set when the display device is mounted in a fixed orientation
49 * such as on a desk. The display manager will apply a coordinate transformation
50 * such as a scale and translation to letterbox or pillarbox format under the
51 * assumption that the physical orientation of the display is invariant.
52 * </p>
Jeff Brown4ed8fe72012-08-30 18:18:29 -070053 */
Jeff Brown27f1d672012-10-17 18:32:34 -070054 public static final int FLAG_ROTATES_WITH_CONTENT = 1 << 1;
Jeff Brownc5df37c2012-09-13 11:45:07 -070055
56 /**
Jeff Brown77aebfd2012-10-01 21:07:03 -070057 * Flag: Indicates that this display device has secure video output, such as HDCP.
Jeff Brownc5df37c2012-09-13 11:45:07 -070058 */
Jeff Brown77aebfd2012-10-01 21:07:03 -070059 public static final int FLAG_SECURE = 1 << 2;
60
61 /**
62 * Flag: Indicates that this display device supports compositing
63 * from gralloc protected buffers.
64 */
65 public static final int FLAG_SUPPORTS_PROTECTED_BUFFERS = 1 << 3;
Jeff Brown4ed8fe72012-08-30 18:18:29 -070066
67 /**
Jeff Browna506a6e2013-06-04 00:02:38 -070068 * Flag: Indicates that the display device is owned by a particular application
69 * and that no other application should be able to interact with it.
Jeff Brownd14c8c92014-01-07 18:13:09 -080070 * Should typically be used together with {@link #FLAG_OWN_CONTENT_ONLY}.
Jeff Browna506a6e2013-06-04 00:02:38 -070071 */
72 public static final int FLAG_PRIVATE = 1 << 4;
73
74 /**
75 * Flag: Indicates that the display device is not blanked automatically by
76 * the power manager.
77 */
78 public static final int FLAG_NEVER_BLANK = 1 << 5;
79
80 /**
Jeff Brown7d00aff2013-08-02 19:03:49 -070081 * Flag: Indicates that the display is suitable for presentations.
82 */
83 public static final int FLAG_PRESENTATION = 1 << 6;
84
85 /**
Jeff Brownd14c8c92014-01-07 18:13:09 -080086 * Flag: Only show this display's own content; do not mirror
87 * the content of another display.
88 */
89 public static final int FLAG_OWN_CONTENT_ONLY = 1 << 7;
90
91 /**
Jeff Brownd728bf52012-09-08 18:05:28 -070092 * Touch attachment: Display does not receive touch.
93 */
94 public static final int TOUCH_NONE = 0;
95
96 /**
97 * Touch attachment: Touch input is via the internal interface.
98 */
99 public static final int TOUCH_INTERNAL = 1;
100
101 /**
102 * Touch attachment: Touch input is via an external interface, such as USB.
103 */
104 public static final int TOUCH_EXTERNAL = 2;
105
106 /**
Wale Ogunwale361ca212014-11-20 11:42:38 -0800107 * Gets the name of the display device, which may be derived from EDID or
108 * other sources. The name may be localized and displayed to the user.
Jeff Brown848c2dc2012-08-19 20:18:08 -0700109 */
110 public String name;
111
112 /**
Wale Ogunwale361ca212014-11-20 11:42:38 -0800113 * Unique Id of display device.
114 */
115 public String uniqueId;
116
117 /**
Jeff Brownfa25bf52012-07-23 19:26:30 -0700118 * The width of the display in its natural orientation, in pixels.
119 * This value is not affected by display rotation.
120 */
121 public int width;
122
123 /**
124 * The height of the display in its natural orientation, in pixels.
125 * This value is not affected by display rotation.
126 */
127 public int height;
128
Jeff Browncbad9762012-09-04 21:57:59 -0700129 /**
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700130 * The refresh rate of the display, in frames per second.
Jeff Browncbad9762012-09-04 21:57:59 -0700131 */
Jeff Brownfa25bf52012-07-23 19:26:30 -0700132 public float refreshRate;
Jeff Browncbad9762012-09-04 21:57:59 -0700133
134 /**
Michael Wright3f145a22014-07-22 19:46:03 -0700135 * The supported refresh rates of the display at the current resolution in frames per second.
136 */
137 public float[] supportedRefreshRates = EmptyArray.FLOAT;
138
139 /**
Jeff Browncbad9762012-09-04 21:57:59 -0700140 * The nominal apparent density of the display in DPI used for layout calculations.
141 * This density is sensitive to the viewing distance. A big TV and a tablet may have
142 * the same apparent density even though the pixels on the TV are much bigger than
143 * those on the tablet.
144 */
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700145 public int densityDpi;
Jeff Browncbad9762012-09-04 21:57:59 -0700146
147 /**
148 * The physical density of the display in DPI in the X direction.
149 * This density should specify the physical size of each pixel.
150 */
Jeff Brownfa25bf52012-07-23 19:26:30 -0700151 public float xDpi;
Jeff Browncbad9762012-09-04 21:57:59 -0700152
153 /**
154 * The physical density of the display in DPI in the X direction.
155 * This density should specify the physical size of each pixel.
156 */
Jeff Brownfa25bf52012-07-23 19:26:30 -0700157 public float yDpi;
158
Jeff Browncbad9762012-09-04 21:57:59 -0700159 /**
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700160 * This is a positive value indicating the phase offset of the VSYNC events provided by
161 * Choreographer relative to the display refresh. For example, if Choreographer reports
162 * that the refresh occurred at time N, it actually occurred at (N - appVsyncOffsetNanos).
163 */
164 public long appVsyncOffsetNanos;
165
166 /**
167 * This is how far in advance a buffer must be queued for presentation at
168 * a given time. If you want a buffer to appear on the screen at
169 * time N, you must submit the buffer before (N - bufferDeadlineNanos).
170 */
171 public long presentationDeadlineNanos;
172
173 /**
Jeff Browncbad9762012-09-04 21:57:59 -0700174 * Display flags.
175 */
Jeff Brownbd6e1502012-08-28 03:27:37 -0700176 public int flags;
177
Jeff Brownd728bf52012-09-08 18:05:28 -0700178 /**
179 * The touch attachment, per {@link DisplayViewport#touch}.
180 */
181 public int touch;
182
Jeff Brown27f1d672012-10-17 18:32:34 -0700183 /**
184 * The additional rotation to apply to all content presented on the display device
185 * relative to its physical coordinate system. Default is {@link Surface#ROTATION_0}.
186 * <p>
187 * This field can be used to compensate for the fact that the display has been
188 * physically rotated relative to its natural orientation such as an HDMI monitor
189 * that has been mounted sideways to appear to be portrait rather than landscape.
190 * </p>
191 */
192 public int rotation = Surface.ROTATION_0;
193
Jeff Brown92130f62012-10-24 21:28:33 -0700194 /**
195 * Display type.
196 */
197 public int type;
198
199 /**
200 * Display address, or null if none.
201 * Interpretation varies by display type.
202 */
203 public String address;
204
Jeff Browna506a6e2013-06-04 00:02:38 -0700205 /**
Jeff Brown037c33e2014-04-09 00:31:55 -0700206 * Display state.
207 */
208 public int state = Display.STATE_ON;
209
210 /**
Jeff Browna506a6e2013-06-04 00:02:38 -0700211 * The UID of the application that owns this display, or zero if it is owned by the system.
212 * <p>
213 * If the display is private, then only the owner can use it.
214 * </p>
215 */
216 public int ownerUid;
217
218 /**
219 * The package name of the application that owns this display, or null if it is
220 * owned by the system.
221 * <p>
222 * If the display is private, then only the owner can use it.
223 * </p>
224 */
225 public String ownerPackageName;
226
Jeff Browncbad9762012-09-04 21:57:59 -0700227 public void setAssumedDensityForExternalDisplay(int width, int height) {
228 densityDpi = Math.min(width, height) * DisplayMetrics.DENSITY_XHIGH / 1080;
229 // Technically, these values should be smaller than the apparent density
230 // but we don't know the physical size of the display.
231 xDpi = densityDpi;
232 yDpi = densityDpi;
233 }
234
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700235 @Override
236 public boolean equals(Object o) {
237 return o instanceof DisplayDeviceInfo && equals((DisplayDeviceInfo)o);
238 }
239
240 public boolean equals(DisplayDeviceInfo other) {
241 return other != null
242 && Objects.equal(name, other.name)
Wale Ogunwale361ca212014-11-20 11:42:38 -0800243 && Objects.equal(uniqueId, other.uniqueId)
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700244 && width == other.width
245 && height == other.height
246 && refreshRate == other.refreshRate
Michael Wright3f145a22014-07-22 19:46:03 -0700247 && Arrays.equals(supportedRefreshRates, other.supportedRefreshRates)
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700248 && densityDpi == other.densityDpi
249 && xDpi == other.xDpi
250 && yDpi == other.yDpi
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700251 && appVsyncOffsetNanos == other.appVsyncOffsetNanos
252 && presentationDeadlineNanos == other.presentationDeadlineNanos
Jeff Brownd728bf52012-09-08 18:05:28 -0700253 && flags == other.flags
Jeff Brown27f1d672012-10-17 18:32:34 -0700254 && touch == other.touch
Jeff Brown92130f62012-10-24 21:28:33 -0700255 && rotation == other.rotation
256 && type == other.type
Jeff Browna506a6e2013-06-04 00:02:38 -0700257 && Objects.equal(address, other.address)
Jeff Brown037c33e2014-04-09 00:31:55 -0700258 && state == other.state
Jeff Browna506a6e2013-06-04 00:02:38 -0700259 && ownerUid == other.ownerUid
260 && Objects.equal(ownerPackageName, other.ownerPackageName);
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700261 }
262
263 @Override
264 public int hashCode() {
265 return 0; // don't care
266 }
267
Jeff Brownfa25bf52012-07-23 19:26:30 -0700268 public void copyFrom(DisplayDeviceInfo other) {
Jeff Brown848c2dc2012-08-19 20:18:08 -0700269 name = other.name;
Wale Ogunwale361ca212014-11-20 11:42:38 -0800270 uniqueId = other.uniqueId;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700271 width = other.width;
272 height = other.height;
273 refreshRate = other.refreshRate;
Michael Wright3f145a22014-07-22 19:46:03 -0700274 supportedRefreshRates = other.supportedRefreshRates;
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700275 densityDpi = other.densityDpi;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700276 xDpi = other.xDpi;
277 yDpi = other.yDpi;
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700278 appVsyncOffsetNanos = other.appVsyncOffsetNanos;
279 presentationDeadlineNanos = other.presentationDeadlineNanos;
Jeff Brownbd6e1502012-08-28 03:27:37 -0700280 flags = other.flags;
Jeff Brownd728bf52012-09-08 18:05:28 -0700281 touch = other.touch;
Jeff Brown27f1d672012-10-17 18:32:34 -0700282 rotation = other.rotation;
Jeff Brown92130f62012-10-24 21:28:33 -0700283 type = other.type;
284 address = other.address;
Jeff Brown037c33e2014-04-09 00:31:55 -0700285 state = other.state;
Jeff Browna506a6e2013-06-04 00:02:38 -0700286 ownerUid = other.ownerUid;
287 ownerPackageName = other.ownerPackageName;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700288 }
289
Jeff Brown848c2dc2012-08-19 20:18:08 -0700290 // For debugging purposes
Jeff Brownfa25bf52012-07-23 19:26:30 -0700291 @Override
292 public String toString() {
Jeff Browna506a6e2013-06-04 00:02:38 -0700293 StringBuilder sb = new StringBuilder();
294 sb.append("DisplayDeviceInfo{\"");
Wale Ogunwale361ca212014-11-20 11:42:38 -0800295 sb.append(name).append("\": uniqueId=\"").append(uniqueId).append("\", ");
296 sb.append(width).append(" x ").append(height);
Michael Wright3f145a22014-07-22 19:46:03 -0700297 sb.append(", ").append(refreshRate).append(" fps");
298 sb.append(", supportedRefreshRates ").append(Arrays.toString(supportedRefreshRates));
299 sb.append(", density ").append(densityDpi);
Jeff Browna506a6e2013-06-04 00:02:38 -0700300 sb.append(", ").append(xDpi).append(" x ").append(yDpi).append(" dpi");
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700301 sb.append(", appVsyncOff ").append(appVsyncOffsetNanos);
302 sb.append(", presDeadline ").append(presentationDeadlineNanos);
Jeff Browna506a6e2013-06-04 00:02:38 -0700303 sb.append(", touch ").append(touchToString(touch));
304 sb.append(", rotation ").append(rotation);
305 sb.append(", type ").append(Display.typeToString(type));
306 if (address != null) {
307 sb.append(", address ").append(address);
308 }
Jeff Brown037c33e2014-04-09 00:31:55 -0700309 sb.append(", state ").append(Display.stateToString(state));
Jeff Browna506a6e2013-06-04 00:02:38 -0700310 if (ownerUid != 0 || ownerPackageName != null) {
311 sb.append(", owner ").append(ownerPackageName);
312 sb.append(" (uid ").append(ownerUid).append(")");
313 }
314 sb.append(flagsToString(flags));
315 sb.append("}");
316 return sb.toString();
Jeff Brownd728bf52012-09-08 18:05:28 -0700317 }
318
319 private static String touchToString(int touch) {
320 switch (touch) {
321 case TOUCH_NONE:
322 return "NONE";
323 case TOUCH_INTERNAL:
324 return "INTERNAL";
325 case TOUCH_EXTERNAL:
326 return "EXTERNAL";
327 default:
328 return Integer.toString(touch);
329 }
Jeff Brownbd6e1502012-08-28 03:27:37 -0700330 }
331
332 private static String flagsToString(int flags) {
333 StringBuilder msg = new StringBuilder();
334 if ((flags & FLAG_DEFAULT_DISPLAY) != 0) {
335 msg.append(", FLAG_DEFAULT_DISPLAY");
336 }
Jeff Brown27f1d672012-10-17 18:32:34 -0700337 if ((flags & FLAG_ROTATES_WITH_CONTENT) != 0) {
338 msg.append(", FLAG_ROTATES_WITH_CONTENT");
Jeff Brownc5df37c2012-09-13 11:45:07 -0700339 }
Jeff Brown77aebfd2012-10-01 21:07:03 -0700340 if ((flags & FLAG_SECURE) != 0) {
341 msg.append(", FLAG_SECURE");
342 }
343 if ((flags & FLAG_SUPPORTS_PROTECTED_BUFFERS) != 0) {
344 msg.append(", FLAG_SUPPORTS_PROTECTED_BUFFERS");
Jeff Brownbd6e1502012-08-28 03:27:37 -0700345 }
Jeff Browna506a6e2013-06-04 00:02:38 -0700346 if ((flags & FLAG_PRIVATE) != 0) {
347 msg.append(", FLAG_PRIVATE");
348 }
349 if ((flags & FLAG_NEVER_BLANK) != 0) {
350 msg.append(", FLAG_NEVER_BLANK");
351 }
Jeff Brown7d00aff2013-08-02 19:03:49 -0700352 if ((flags & FLAG_PRESENTATION) != 0) {
353 msg.append(", FLAG_PRESENTATION");
354 }
Jeff Brownd14c8c92014-01-07 18:13:09 -0800355 if ((flags & FLAG_OWN_CONTENT_ONLY) != 0) {
356 msg.append(", FLAG_OWN_CONTENT_ONLY");
357 }
Jeff Brownbd6e1502012-08-28 03:27:37 -0700358 return msg.toString();
Jeff Brownfa25bf52012-07-23 19:26:30 -0700359 }
360}