blob: ef6de4c1ee51fc9005e249c66d5c76864b883446 [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
Jeff Brown4ed8fe72012-08-30 18:18:29 -070026import libcore.util.Objects;
27
Jeff Brownfa25bf52012-07-23 19:26:30 -070028/**
29 * Describes the characteristics of a physical display device.
30 */
Jeff Brown4ed8fe72012-08-30 18:18:29 -070031final class DisplayDeviceInfo {
32 /**
33 * Flag: Indicates that this display device should be considered the default display
34 * device of the system.
35 */
Jeff Brownbd6e1502012-08-28 03:27:37 -070036 public static final int FLAG_DEFAULT_DISPLAY = 1 << 0;
Jeff Brown4ed8fe72012-08-30 18:18:29 -070037
38 /**
Jeff Brown27f1d672012-10-17 18:32:34 -070039 * Flag: Indicates that the orientation of this display device is coupled to the
40 * rotation of its associated logical display.
41 * <p>
42 * This flag should be applied to the default display to indicate that the user
43 * physically rotates the display when content is presented in a different orientation.
44 * The display manager will apply a coordinate transformation assuming that the
45 * physical orientation of the display matches the logical orientation of its content.
46 * </p><p>
47 * The flag should not be set when the display device is mounted in a fixed orientation
48 * such as on a desk. The display manager will apply a coordinate transformation
49 * such as a scale and translation to letterbox or pillarbox format under the
50 * assumption that the physical orientation of the display is invariant.
51 * </p>
Jeff Brown4ed8fe72012-08-30 18:18:29 -070052 */
Jeff Brown27f1d672012-10-17 18:32:34 -070053 public static final int FLAG_ROTATES_WITH_CONTENT = 1 << 1;
Jeff Brownc5df37c2012-09-13 11:45:07 -070054
55 /**
Jeff Brown77aebfd2012-10-01 21:07:03 -070056 * Flag: Indicates that this display device has secure video output, such as HDCP.
Jeff Brownc5df37c2012-09-13 11:45:07 -070057 */
Jeff Brown77aebfd2012-10-01 21:07:03 -070058 public static final int FLAG_SECURE = 1 << 2;
59
60 /**
61 * Flag: Indicates that this display device supports compositing
62 * from gralloc protected buffers.
63 */
64 public static final int FLAG_SUPPORTS_PROTECTED_BUFFERS = 1 << 3;
Jeff Brown4ed8fe72012-08-30 18:18:29 -070065
66 /**
Jeff Browna506a6e2013-06-04 00:02:38 -070067 * Flag: Indicates that the display device is owned by a particular application
68 * and that no other application should be able to interact with it.
Jeff Brownd14c8c92014-01-07 18:13:09 -080069 * Should typically be used together with {@link #FLAG_OWN_CONTENT_ONLY}.
Jeff Browna506a6e2013-06-04 00:02:38 -070070 */
71 public static final int FLAG_PRIVATE = 1 << 4;
72
73 /**
74 * Flag: Indicates that the display device is not blanked automatically by
75 * the power manager.
76 */
77 public static final int FLAG_NEVER_BLANK = 1 << 5;
78
79 /**
Jeff Brown7d00aff2013-08-02 19:03:49 -070080 * Flag: Indicates that the display is suitable for presentations.
81 */
82 public static final int FLAG_PRESENTATION = 1 << 6;
83
84 /**
Jeff Brownd14c8c92014-01-07 18:13:09 -080085 * Flag: Only show this display's own content; do not mirror
86 * the content of another display.
87 */
88 public static final int FLAG_OWN_CONTENT_ONLY = 1 << 7;
89
90 /**
Adam Powell49e7ff92015-05-14 16:18:53 -070091 * Flag: This display device has a round shape.
92 */
93 public static final int FLAG_ROUND = 1 << 8;
94
95 /**
Andrii Kulianfc8f82b2017-01-26 13:17:27 -080096 * Flag: This display can show its content when non-secure keyguard is shown.
97 */
Andrii Kulian7211d2e2017-01-27 15:58:05 -080098 public static final int FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD = 1 << 9;
Andrii Kulianfc8f82b2017-01-26 13:17:27 -080099
100 /**
Jeff Brownd728bf52012-09-08 18:05:28 -0700101 * Touch attachment: Display does not receive touch.
102 */
103 public static final int TOUCH_NONE = 0;
104
105 /**
106 * Touch attachment: Touch input is via the internal interface.
107 */
108 public static final int TOUCH_INTERNAL = 1;
109
110 /**
111 * Touch attachment: Touch input is via an external interface, such as USB.
112 */
113 public static final int TOUCH_EXTERNAL = 2;
114
115 /**
Santos Cordonee8931e2017-04-05 10:31:15 -0700116 * Touch attachment: Touch input is via an input device matching {@link VirtualDisplay}'s
117 * uniqueId.
118 * @hide
119 */
120 public static final int TOUCH_VIRTUAL = 3;
121
122 /**
Jeff Brown10acf6d2015-04-14 14:20:47 -0700123 * Diff result: The {@link #state} fields differ.
124 */
125 public static final int DIFF_STATE = 1 << 0;
126
127 /**
128 * Diff result: Other fields differ.
129 */
130 public static final int DIFF_OTHER = 1 << 1;
131
132 /**
Michael Wright1c9977b2016-07-12 13:30:10 -0700133 * Diff result: The color mode fields differ.
134 */
135 public static final int DIFF_COLOR_MODE = 1 << 2;
136
137 /**
Wale Ogunwale361ca212014-11-20 11:42:38 -0800138 * Gets the name of the display device, which may be derived from EDID or
139 * other sources. The name may be localized and displayed to the user.
Jeff Brown848c2dc2012-08-19 20:18:08 -0700140 */
141 public String name;
142
143 /**
Wale Ogunwale361ca212014-11-20 11:42:38 -0800144 * Unique Id of display device.
145 */
146 public String uniqueId;
147
148 /**
Jeff Brownfa25bf52012-07-23 19:26:30 -0700149 * The width of the display in its natural orientation, in pixels.
150 * This value is not affected by display rotation.
151 */
152 public int width;
153
154 /**
155 * The height of the display in its natural orientation, in pixels.
156 * This value is not affected by display rotation.
157 */
158 public int height;
159
Jeff Browncbad9762012-09-04 21:57:59 -0700160 /**
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700161 * The active mode of the display.
Jeff Browncbad9762012-09-04 21:57:59 -0700162 */
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700163 public int modeId;
Jeff Browncbad9762012-09-04 21:57:59 -0700164
165 /**
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700166 * The default mode of the display.
Michael Wright3f145a22014-07-22 19:46:03 -0700167 */
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700168 public int defaultModeId;
169
170 /**
171 * The supported modes of the display.
172 */
173 public Display.Mode[] supportedModes = Display.Mode.EMPTY_ARRAY;
Michael Wright3f145a22014-07-22 19:46:03 -0700174
Michael Wright1c9977b2016-07-12 13:30:10 -0700175 /** The active color mode of the display */
176 public int colorMode;
Michael Wright58e829f2015-09-15 00:13:26 +0100177
Michael Wright1c9977b2016-07-12 13:30:10 -0700178 /** The supported color modes of the display */
179 public int[] supportedColorModes = { Display.COLOR_MODE_DEFAULT };
Michael Wright58e829f2015-09-15 00:13:26 +0100180
Michael Wright3f145a22014-07-22 19:46:03 -0700181 /**
Michael Wright9ff94c02016-03-30 18:05:40 -0700182 * The HDR capabilities this display claims to support.
183 */
184 public Display.HdrCapabilities hdrCapabilities;
185
186 /**
Jeff Browncbad9762012-09-04 21:57:59 -0700187 * The nominal apparent density of the display in DPI used for layout calculations.
188 * This density is sensitive to the viewing distance. A big TV and a tablet may have
189 * the same apparent density even though the pixels on the TV are much bigger than
190 * those on the tablet.
191 */
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700192 public int densityDpi;
Jeff Browncbad9762012-09-04 21:57:59 -0700193
194 /**
195 * The physical density of the display in DPI in the X direction.
196 * This density should specify the physical size of each pixel.
197 */
Jeff Brownfa25bf52012-07-23 19:26:30 -0700198 public float xDpi;
Jeff Browncbad9762012-09-04 21:57:59 -0700199
200 /**
201 * The physical density of the display in DPI in the X direction.
202 * This density should specify the physical size of each pixel.
203 */
Jeff Brownfa25bf52012-07-23 19:26:30 -0700204 public float yDpi;
205
Jeff Browncbad9762012-09-04 21:57:59 -0700206 /**
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700207 * This is a positive value indicating the phase offset of the VSYNC events provided by
208 * Choreographer relative to the display refresh. For example, if Choreographer reports
209 * that the refresh occurred at time N, it actually occurred at (N - appVsyncOffsetNanos).
210 */
211 public long appVsyncOffsetNanos;
212
213 /**
214 * This is how far in advance a buffer must be queued for presentation at
215 * a given time. If you want a buffer to appear on the screen at
216 * time N, you must submit the buffer before (N - bufferDeadlineNanos).
217 */
218 public long presentationDeadlineNanos;
219
220 /**
Jeff Browncbad9762012-09-04 21:57:59 -0700221 * Display flags.
222 */
Jeff Brownbd6e1502012-08-28 03:27:37 -0700223 public int flags;
224
Jeff Brownd728bf52012-09-08 18:05:28 -0700225 /**
226 * The touch attachment, per {@link DisplayViewport#touch}.
227 */
228 public int touch;
229
Jeff Brown27f1d672012-10-17 18:32:34 -0700230 /**
231 * The additional rotation to apply to all content presented on the display device
232 * relative to its physical coordinate system. Default is {@link Surface#ROTATION_0}.
233 * <p>
234 * This field can be used to compensate for the fact that the display has been
235 * physically rotated relative to its natural orientation such as an HDMI monitor
236 * that has been mounted sideways to appear to be portrait rather than landscape.
237 * </p>
238 */
239 public int rotation = Surface.ROTATION_0;
240
Jeff Brown92130f62012-10-24 21:28:33 -0700241 /**
242 * Display type.
243 */
244 public int type;
245
246 /**
247 * Display address, or null if none.
248 * Interpretation varies by display type.
249 */
250 public String address;
251
Jeff Browna506a6e2013-06-04 00:02:38 -0700252 /**
Jeff Brown037c33e2014-04-09 00:31:55 -0700253 * Display state.
254 */
255 public int state = Display.STATE_ON;
256
257 /**
Jeff Browna506a6e2013-06-04 00:02:38 -0700258 * The UID of the application that owns this display, or zero if it is owned by the system.
259 * <p>
260 * If the display is private, then only the owner can use it.
261 * </p>
262 */
263 public int ownerUid;
264
265 /**
266 * The package name of the application that owns this display, or null if it is
267 * owned by the system.
268 * <p>
269 * If the display is private, then only the owner can use it.
270 * </p>
271 */
272 public String ownerPackageName;
273
Jeff Browncbad9762012-09-04 21:57:59 -0700274 public void setAssumedDensityForExternalDisplay(int width, int height) {
275 densityDpi = Math.min(width, height) * DisplayMetrics.DENSITY_XHIGH / 1080;
276 // Technically, these values should be smaller than the apparent density
277 // but we don't know the physical size of the display.
278 xDpi = densityDpi;
279 yDpi = densityDpi;
280 }
281
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700282 @Override
283 public boolean equals(Object o) {
284 return o instanceof DisplayDeviceInfo && equals((DisplayDeviceInfo)o);
285 }
286
287 public boolean equals(DisplayDeviceInfo other) {
Jeff Brown10acf6d2015-04-14 14:20:47 -0700288 return other != null && diff(other) == 0;
289 }
290
291 /**
292 * Computes the difference between display device infos.
293 * Assumes other is not null.
294 */
295 public int diff(DisplayDeviceInfo other) {
296 int diff = 0;
297 if (state != other.state) {
298 diff |= DIFF_STATE;
299 }
Michael Wright1c9977b2016-07-12 13:30:10 -0700300 if (colorMode != other.colorMode) {
301 diff |= DIFF_COLOR_MODE;
302 }
Jeff Brown10acf6d2015-04-14 14:20:47 -0700303 if (!Objects.equal(name, other.name)
304 || !Objects.equal(uniqueId, other.uniqueId)
305 || width != other.width
306 || height != other.height
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700307 || modeId != other.modeId
308 || defaultModeId != other.defaultModeId
309 || !Arrays.equals(supportedModes, other.supportedModes)
Michael Wright1c9977b2016-07-12 13:30:10 -0700310 || !Arrays.equals(supportedColorModes, other.supportedColorModes)
Michael Wright9ff94c02016-03-30 18:05:40 -0700311 || !Objects.equal(hdrCapabilities, other.hdrCapabilities)
Jeff Brown10acf6d2015-04-14 14:20:47 -0700312 || densityDpi != other.densityDpi
313 || xDpi != other.xDpi
314 || yDpi != other.yDpi
315 || appVsyncOffsetNanos != other.appVsyncOffsetNanos
316 || presentationDeadlineNanos != other.presentationDeadlineNanos
317 || flags != other.flags
318 || touch != other.touch
319 || rotation != other.rotation
320 || type != other.type
321 || !Objects.equal(address, other.address)
322 || ownerUid != other.ownerUid
323 || !Objects.equal(ownerPackageName, other.ownerPackageName)) {
324 diff |= DIFF_OTHER;
325 }
326 return diff;
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700327 }
328
329 @Override
330 public int hashCode() {
331 return 0; // don't care
332 }
333
Jeff Brownfa25bf52012-07-23 19:26:30 -0700334 public void copyFrom(DisplayDeviceInfo other) {
Jeff Brown848c2dc2012-08-19 20:18:08 -0700335 name = other.name;
Wale Ogunwale361ca212014-11-20 11:42:38 -0800336 uniqueId = other.uniqueId;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700337 width = other.width;
338 height = other.height;
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700339 modeId = other.modeId;
340 defaultModeId = other.defaultModeId;
341 supportedModes = other.supportedModes;
Michael Wright1c9977b2016-07-12 13:30:10 -0700342 colorMode = other.colorMode;
343 supportedColorModes = other.supportedColorModes;
Michael Wright9ff94c02016-03-30 18:05:40 -0700344 hdrCapabilities = other.hdrCapabilities;
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700345 densityDpi = other.densityDpi;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700346 xDpi = other.xDpi;
347 yDpi = other.yDpi;
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700348 appVsyncOffsetNanos = other.appVsyncOffsetNanos;
349 presentationDeadlineNanos = other.presentationDeadlineNanos;
Jeff Brownbd6e1502012-08-28 03:27:37 -0700350 flags = other.flags;
Jeff Brownd728bf52012-09-08 18:05:28 -0700351 touch = other.touch;
Jeff Brown27f1d672012-10-17 18:32:34 -0700352 rotation = other.rotation;
Jeff Brown92130f62012-10-24 21:28:33 -0700353 type = other.type;
354 address = other.address;
Jeff Brown037c33e2014-04-09 00:31:55 -0700355 state = other.state;
Jeff Browna506a6e2013-06-04 00:02:38 -0700356 ownerUid = other.ownerUid;
357 ownerPackageName = other.ownerPackageName;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700358 }
359
Jeff Brown848c2dc2012-08-19 20:18:08 -0700360 // For debugging purposes
Jeff Brownfa25bf52012-07-23 19:26:30 -0700361 @Override
362 public String toString() {
Jeff Browna506a6e2013-06-04 00:02:38 -0700363 StringBuilder sb = new StringBuilder();
364 sb.append("DisplayDeviceInfo{\"");
Wale Ogunwale361ca212014-11-20 11:42:38 -0800365 sb.append(name).append("\": uniqueId=\"").append(uniqueId).append("\", ");
366 sb.append(width).append(" x ").append(height);
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700367 sb.append(", modeId ").append(modeId);
368 sb.append(", defaultModeId ").append(defaultModeId);
369 sb.append(", supportedModes ").append(Arrays.toString(supportedModes));
Michael Wright1c9977b2016-07-12 13:30:10 -0700370 sb.append(", colorMode ").append(colorMode);
371 sb.append(", supportedColorModes ").append(Arrays.toString(supportedColorModes));
Michael Wright9ff94c02016-03-30 18:05:40 -0700372 sb.append(", HdrCapabilities ").append(hdrCapabilities);
Michael Wright3f145a22014-07-22 19:46:03 -0700373 sb.append(", density ").append(densityDpi);
Jeff Browna506a6e2013-06-04 00:02:38 -0700374 sb.append(", ").append(xDpi).append(" x ").append(yDpi).append(" dpi");
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700375 sb.append(", appVsyncOff ").append(appVsyncOffsetNanos);
376 sb.append(", presDeadline ").append(presentationDeadlineNanos);
Jeff Browna506a6e2013-06-04 00:02:38 -0700377 sb.append(", touch ").append(touchToString(touch));
378 sb.append(", rotation ").append(rotation);
379 sb.append(", type ").append(Display.typeToString(type));
380 if (address != null) {
381 sb.append(", address ").append(address);
382 }
Jeff Brown037c33e2014-04-09 00:31:55 -0700383 sb.append(", state ").append(Display.stateToString(state));
Jeff Browna506a6e2013-06-04 00:02:38 -0700384 if (ownerUid != 0 || ownerPackageName != null) {
385 sb.append(", owner ").append(ownerPackageName);
386 sb.append(" (uid ").append(ownerUid).append(")");
387 }
388 sb.append(flagsToString(flags));
389 sb.append("}");
390 return sb.toString();
Jeff Brownd728bf52012-09-08 18:05:28 -0700391 }
392
393 private static String touchToString(int touch) {
394 switch (touch) {
395 case TOUCH_NONE:
396 return "NONE";
397 case TOUCH_INTERNAL:
398 return "INTERNAL";
399 case TOUCH_EXTERNAL:
400 return "EXTERNAL";
Santos Cordonee8931e2017-04-05 10:31:15 -0700401 case TOUCH_VIRTUAL:
402 return "VIRTUAL";
Jeff Brownd728bf52012-09-08 18:05:28 -0700403 default:
404 return Integer.toString(touch);
405 }
Jeff Brownbd6e1502012-08-28 03:27:37 -0700406 }
407
408 private static String flagsToString(int flags) {
409 StringBuilder msg = new StringBuilder();
410 if ((flags & FLAG_DEFAULT_DISPLAY) != 0) {
411 msg.append(", FLAG_DEFAULT_DISPLAY");
412 }
Jeff Brown27f1d672012-10-17 18:32:34 -0700413 if ((flags & FLAG_ROTATES_WITH_CONTENT) != 0) {
414 msg.append(", FLAG_ROTATES_WITH_CONTENT");
Jeff Brownc5df37c2012-09-13 11:45:07 -0700415 }
Jeff Brown77aebfd2012-10-01 21:07:03 -0700416 if ((flags & FLAG_SECURE) != 0) {
417 msg.append(", FLAG_SECURE");
418 }
419 if ((flags & FLAG_SUPPORTS_PROTECTED_BUFFERS) != 0) {
420 msg.append(", FLAG_SUPPORTS_PROTECTED_BUFFERS");
Jeff Brownbd6e1502012-08-28 03:27:37 -0700421 }
Jeff Browna506a6e2013-06-04 00:02:38 -0700422 if ((flags & FLAG_PRIVATE) != 0) {
423 msg.append(", FLAG_PRIVATE");
424 }
425 if ((flags & FLAG_NEVER_BLANK) != 0) {
426 msg.append(", FLAG_NEVER_BLANK");
427 }
Jeff Brown7d00aff2013-08-02 19:03:49 -0700428 if ((flags & FLAG_PRESENTATION) != 0) {
429 msg.append(", FLAG_PRESENTATION");
430 }
Jeff Brownd14c8c92014-01-07 18:13:09 -0800431 if ((flags & FLAG_OWN_CONTENT_ONLY) != 0) {
432 msg.append(", FLAG_OWN_CONTENT_ONLY");
433 }
Adam Powell49e7ff92015-05-14 16:18:53 -0700434 if ((flags & FLAG_ROUND) != 0) {
435 msg.append(", FLAG_ROUND");
436 }
Andrii Kulian7211d2e2017-01-27 15:58:05 -0800437 if ((flags & FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD) != 0) {
438 msg.append(", FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD");
Andrii Kulianfc8f82b2017-01-26 13:17:27 -0800439 }
Jeff Brownbd6e1502012-08-28 03:27:37 -0700440 return msg.toString();
Jeff Brownfa25bf52012-07-23 19:26:30 -0700441 }
442}