blob: 671918209b25c6965eea205e45453abc27a22c20 [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 /**
Jeff Brownd728bf52012-09-08 18:05:28 -070096 * Touch attachment: Display does not receive touch.
97 */
98 public static final int TOUCH_NONE = 0;
99
100 /**
101 * Touch attachment: Touch input is via the internal interface.
102 */
103 public static final int TOUCH_INTERNAL = 1;
104
105 /**
106 * Touch attachment: Touch input is via an external interface, such as USB.
107 */
108 public static final int TOUCH_EXTERNAL = 2;
109
110 /**
Jeff Brown10acf6d2015-04-14 14:20:47 -0700111 * Diff result: The {@link #state} fields differ.
112 */
113 public static final int DIFF_STATE = 1 << 0;
114
115 /**
116 * Diff result: Other fields differ.
117 */
118 public static final int DIFF_OTHER = 1 << 1;
119
120 /**
Michael Wright1c9977b2016-07-12 13:30:10 -0700121 * Diff result: The color mode fields differ.
122 */
123 public static final int DIFF_COLOR_MODE = 1 << 2;
124
125 /**
Wale Ogunwale361ca212014-11-20 11:42:38 -0800126 * Gets the name of the display device, which may be derived from EDID or
127 * other sources. The name may be localized and displayed to the user.
Jeff Brown848c2dc2012-08-19 20:18:08 -0700128 */
129 public String name;
130
131 /**
Wale Ogunwale361ca212014-11-20 11:42:38 -0800132 * Unique Id of display device.
133 */
134 public String uniqueId;
135
136 /**
Jeff Brownfa25bf52012-07-23 19:26:30 -0700137 * The width of the display in its natural orientation, in pixels.
138 * This value is not affected by display rotation.
139 */
140 public int width;
141
142 /**
143 * The height of the display in its natural orientation, in pixels.
144 * This value is not affected by display rotation.
145 */
146 public int height;
147
Jeff Browncbad9762012-09-04 21:57:59 -0700148 /**
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700149 * The active mode of the display.
Jeff Browncbad9762012-09-04 21:57:59 -0700150 */
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700151 public int modeId;
Jeff Browncbad9762012-09-04 21:57:59 -0700152
153 /**
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700154 * The default mode of the display.
Michael Wright3f145a22014-07-22 19:46:03 -0700155 */
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700156 public int defaultModeId;
157
158 /**
159 * The supported modes of the display.
160 */
161 public Display.Mode[] supportedModes = Display.Mode.EMPTY_ARRAY;
Michael Wright3f145a22014-07-22 19:46:03 -0700162
Michael Wright1c9977b2016-07-12 13:30:10 -0700163 /** The active color mode of the display */
164 public int colorMode;
Michael Wright58e829f2015-09-15 00:13:26 +0100165
Michael Wright1c9977b2016-07-12 13:30:10 -0700166 /** The supported color modes of the display */
167 public int[] supportedColorModes = { Display.COLOR_MODE_DEFAULT };
Michael Wright58e829f2015-09-15 00:13:26 +0100168
Michael Wright3f145a22014-07-22 19:46:03 -0700169 /**
Michael Wright9ff94c02016-03-30 18:05:40 -0700170 * The HDR capabilities this display claims to support.
171 */
172 public Display.HdrCapabilities hdrCapabilities;
173
174 /**
Jeff Browncbad9762012-09-04 21:57:59 -0700175 * The nominal apparent density of the display in DPI used for layout calculations.
176 * This density is sensitive to the viewing distance. A big TV and a tablet may have
177 * the same apparent density even though the pixels on the TV are much bigger than
178 * those on the tablet.
179 */
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700180 public int densityDpi;
Jeff Browncbad9762012-09-04 21:57:59 -0700181
182 /**
183 * The physical density of the display in DPI in the X direction.
184 * This density should specify the physical size of each pixel.
185 */
Jeff Brownfa25bf52012-07-23 19:26:30 -0700186 public float xDpi;
Jeff Browncbad9762012-09-04 21:57:59 -0700187
188 /**
189 * The physical density of the display in DPI in the X direction.
190 * This density should specify the physical size of each pixel.
191 */
Jeff Brownfa25bf52012-07-23 19:26:30 -0700192 public float yDpi;
193
Jeff Browncbad9762012-09-04 21:57:59 -0700194 /**
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700195 * This is a positive value indicating the phase offset of the VSYNC events provided by
196 * Choreographer relative to the display refresh. For example, if Choreographer reports
197 * that the refresh occurred at time N, it actually occurred at (N - appVsyncOffsetNanos).
198 */
199 public long appVsyncOffsetNanos;
200
201 /**
202 * This is how far in advance a buffer must be queued for presentation at
203 * a given time. If you want a buffer to appear on the screen at
204 * time N, you must submit the buffer before (N - bufferDeadlineNanos).
205 */
206 public long presentationDeadlineNanos;
207
208 /**
Jeff Browncbad9762012-09-04 21:57:59 -0700209 * Display flags.
210 */
Jeff Brownbd6e1502012-08-28 03:27:37 -0700211 public int flags;
212
Jeff Brownd728bf52012-09-08 18:05:28 -0700213 /**
214 * The touch attachment, per {@link DisplayViewport#touch}.
215 */
216 public int touch;
217
Jeff Brown27f1d672012-10-17 18:32:34 -0700218 /**
219 * The additional rotation to apply to all content presented on the display device
220 * relative to its physical coordinate system. Default is {@link Surface#ROTATION_0}.
221 * <p>
222 * This field can be used to compensate for the fact that the display has been
223 * physically rotated relative to its natural orientation such as an HDMI monitor
224 * that has been mounted sideways to appear to be portrait rather than landscape.
225 * </p>
226 */
227 public int rotation = Surface.ROTATION_0;
228
Jeff Brown92130f62012-10-24 21:28:33 -0700229 /**
230 * Display type.
231 */
232 public int type;
233
234 /**
235 * Display address, or null if none.
236 * Interpretation varies by display type.
237 */
238 public String address;
239
Jeff Browna506a6e2013-06-04 00:02:38 -0700240 /**
Jeff Brown037c33e2014-04-09 00:31:55 -0700241 * Display state.
242 */
243 public int state = Display.STATE_ON;
244
245 /**
Jeff Browna506a6e2013-06-04 00:02:38 -0700246 * The UID of the application that owns this display, or zero if it is owned by the system.
247 * <p>
248 * If the display is private, then only the owner can use it.
249 * </p>
250 */
251 public int ownerUid;
252
253 /**
254 * The package name of the application that owns this display, or null if it is
255 * owned by the system.
256 * <p>
257 * If the display is private, then only the owner can use it.
258 * </p>
259 */
260 public String ownerPackageName;
261
Jeff Browncbad9762012-09-04 21:57:59 -0700262 public void setAssumedDensityForExternalDisplay(int width, int height) {
263 densityDpi = Math.min(width, height) * DisplayMetrics.DENSITY_XHIGH / 1080;
264 // Technically, these values should be smaller than the apparent density
265 // but we don't know the physical size of the display.
266 xDpi = densityDpi;
267 yDpi = densityDpi;
268 }
269
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700270 @Override
271 public boolean equals(Object o) {
272 return o instanceof DisplayDeviceInfo && equals((DisplayDeviceInfo)o);
273 }
274
275 public boolean equals(DisplayDeviceInfo other) {
Jeff Brown10acf6d2015-04-14 14:20:47 -0700276 return other != null && diff(other) == 0;
277 }
278
279 /**
280 * Computes the difference between display device infos.
281 * Assumes other is not null.
282 */
283 public int diff(DisplayDeviceInfo other) {
284 int diff = 0;
285 if (state != other.state) {
286 diff |= DIFF_STATE;
287 }
Michael Wright1c9977b2016-07-12 13:30:10 -0700288 if (colorMode != other.colorMode) {
289 diff |= DIFF_COLOR_MODE;
290 }
Jeff Brown10acf6d2015-04-14 14:20:47 -0700291 if (!Objects.equal(name, other.name)
292 || !Objects.equal(uniqueId, other.uniqueId)
293 || width != other.width
294 || height != other.height
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700295 || modeId != other.modeId
296 || defaultModeId != other.defaultModeId
297 || !Arrays.equals(supportedModes, other.supportedModes)
Michael Wright1c9977b2016-07-12 13:30:10 -0700298 || !Arrays.equals(supportedColorModes, other.supportedColorModes)
Michael Wright9ff94c02016-03-30 18:05:40 -0700299 || !Objects.equal(hdrCapabilities, other.hdrCapabilities)
Jeff Brown10acf6d2015-04-14 14:20:47 -0700300 || densityDpi != other.densityDpi
301 || xDpi != other.xDpi
302 || yDpi != other.yDpi
303 || appVsyncOffsetNanos != other.appVsyncOffsetNanos
304 || presentationDeadlineNanos != other.presentationDeadlineNanos
305 || flags != other.flags
306 || touch != other.touch
307 || rotation != other.rotation
308 || type != other.type
309 || !Objects.equal(address, other.address)
310 || ownerUid != other.ownerUid
311 || !Objects.equal(ownerPackageName, other.ownerPackageName)) {
312 diff |= DIFF_OTHER;
313 }
314 return diff;
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700315 }
316
317 @Override
318 public int hashCode() {
319 return 0; // don't care
320 }
321
Jeff Brownfa25bf52012-07-23 19:26:30 -0700322 public void copyFrom(DisplayDeviceInfo other) {
Jeff Brown848c2dc2012-08-19 20:18:08 -0700323 name = other.name;
Wale Ogunwale361ca212014-11-20 11:42:38 -0800324 uniqueId = other.uniqueId;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700325 width = other.width;
326 height = other.height;
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700327 modeId = other.modeId;
328 defaultModeId = other.defaultModeId;
329 supportedModes = other.supportedModes;
Michael Wright1c9977b2016-07-12 13:30:10 -0700330 colorMode = other.colorMode;
331 supportedColorModes = other.supportedColorModes;
Michael Wright9ff94c02016-03-30 18:05:40 -0700332 hdrCapabilities = other.hdrCapabilities;
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700333 densityDpi = other.densityDpi;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700334 xDpi = other.xDpi;
335 yDpi = other.yDpi;
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700336 appVsyncOffsetNanos = other.appVsyncOffsetNanos;
337 presentationDeadlineNanos = other.presentationDeadlineNanos;
Jeff Brownbd6e1502012-08-28 03:27:37 -0700338 flags = other.flags;
Jeff Brownd728bf52012-09-08 18:05:28 -0700339 touch = other.touch;
Jeff Brown27f1d672012-10-17 18:32:34 -0700340 rotation = other.rotation;
Jeff Brown92130f62012-10-24 21:28:33 -0700341 type = other.type;
342 address = other.address;
Jeff Brown037c33e2014-04-09 00:31:55 -0700343 state = other.state;
Jeff Browna506a6e2013-06-04 00:02:38 -0700344 ownerUid = other.ownerUid;
345 ownerPackageName = other.ownerPackageName;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700346 }
347
Jeff Brown848c2dc2012-08-19 20:18:08 -0700348 // For debugging purposes
Jeff Brownfa25bf52012-07-23 19:26:30 -0700349 @Override
350 public String toString() {
Jeff Browna506a6e2013-06-04 00:02:38 -0700351 StringBuilder sb = new StringBuilder();
352 sb.append("DisplayDeviceInfo{\"");
Wale Ogunwale361ca212014-11-20 11:42:38 -0800353 sb.append(name).append("\": uniqueId=\"").append(uniqueId).append("\", ");
354 sb.append(width).append(" x ").append(height);
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700355 sb.append(", modeId ").append(modeId);
356 sb.append(", defaultModeId ").append(defaultModeId);
357 sb.append(", supportedModes ").append(Arrays.toString(supportedModes));
Michael Wright1c9977b2016-07-12 13:30:10 -0700358 sb.append(", colorMode ").append(colorMode);
359 sb.append(", supportedColorModes ").append(Arrays.toString(supportedColorModes));
Michael Wright9ff94c02016-03-30 18:05:40 -0700360 sb.append(", HdrCapabilities ").append(hdrCapabilities);
Michael Wright3f145a22014-07-22 19:46:03 -0700361 sb.append(", density ").append(densityDpi);
Jeff Browna506a6e2013-06-04 00:02:38 -0700362 sb.append(", ").append(xDpi).append(" x ").append(yDpi).append(" dpi");
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700363 sb.append(", appVsyncOff ").append(appVsyncOffsetNanos);
364 sb.append(", presDeadline ").append(presentationDeadlineNanos);
Jeff Browna506a6e2013-06-04 00:02:38 -0700365 sb.append(", touch ").append(touchToString(touch));
366 sb.append(", rotation ").append(rotation);
367 sb.append(", type ").append(Display.typeToString(type));
368 if (address != null) {
369 sb.append(", address ").append(address);
370 }
Jeff Brown037c33e2014-04-09 00:31:55 -0700371 sb.append(", state ").append(Display.stateToString(state));
Jeff Browna506a6e2013-06-04 00:02:38 -0700372 if (ownerUid != 0 || ownerPackageName != null) {
373 sb.append(", owner ").append(ownerPackageName);
374 sb.append(" (uid ").append(ownerUid).append(")");
375 }
376 sb.append(flagsToString(flags));
377 sb.append("}");
378 return sb.toString();
Jeff Brownd728bf52012-09-08 18:05:28 -0700379 }
380
381 private static String touchToString(int touch) {
382 switch (touch) {
383 case TOUCH_NONE:
384 return "NONE";
385 case TOUCH_INTERNAL:
386 return "INTERNAL";
387 case TOUCH_EXTERNAL:
388 return "EXTERNAL";
389 default:
390 return Integer.toString(touch);
391 }
Jeff Brownbd6e1502012-08-28 03:27:37 -0700392 }
393
394 private static String flagsToString(int flags) {
395 StringBuilder msg = new StringBuilder();
396 if ((flags & FLAG_DEFAULT_DISPLAY) != 0) {
397 msg.append(", FLAG_DEFAULT_DISPLAY");
398 }
Jeff Brown27f1d672012-10-17 18:32:34 -0700399 if ((flags & FLAG_ROTATES_WITH_CONTENT) != 0) {
400 msg.append(", FLAG_ROTATES_WITH_CONTENT");
Jeff Brownc5df37c2012-09-13 11:45:07 -0700401 }
Jeff Brown77aebfd2012-10-01 21:07:03 -0700402 if ((flags & FLAG_SECURE) != 0) {
403 msg.append(", FLAG_SECURE");
404 }
405 if ((flags & FLAG_SUPPORTS_PROTECTED_BUFFERS) != 0) {
406 msg.append(", FLAG_SUPPORTS_PROTECTED_BUFFERS");
Jeff Brownbd6e1502012-08-28 03:27:37 -0700407 }
Jeff Browna506a6e2013-06-04 00:02:38 -0700408 if ((flags & FLAG_PRIVATE) != 0) {
409 msg.append(", FLAG_PRIVATE");
410 }
411 if ((flags & FLAG_NEVER_BLANK) != 0) {
412 msg.append(", FLAG_NEVER_BLANK");
413 }
Jeff Brown7d00aff2013-08-02 19:03:49 -0700414 if ((flags & FLAG_PRESENTATION) != 0) {
415 msg.append(", FLAG_PRESENTATION");
416 }
Jeff Brownd14c8c92014-01-07 18:13:09 -0800417 if ((flags & FLAG_OWN_CONTENT_ONLY) != 0) {
418 msg.append(", FLAG_OWN_CONTENT_ONLY");
419 }
Adam Powell49e7ff92015-05-14 16:18:53 -0700420 if ((flags & FLAG_ROUND) != 0) {
421 msg.append(", FLAG_ROUND");
422 }
Jeff Brownbd6e1502012-08-28 03:27:37 -0700423 return msg.toString();
Jeff Brownfa25bf52012-07-23 19:26:30 -0700424 }
425}