blob: 4a52b3ce5d95c39aac3a959832d25b20af4915a9 [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 /**
Jeff Brown10acf6d2015-04-14 14:20:47 -0700116 * Diff result: The {@link #state} fields differ.
117 */
118 public static final int DIFF_STATE = 1 << 0;
119
120 /**
121 * Diff result: Other fields differ.
122 */
123 public static final int DIFF_OTHER = 1 << 1;
124
125 /**
Michael Wright1c9977b2016-07-12 13:30:10 -0700126 * Diff result: The color mode fields differ.
127 */
128 public static final int DIFF_COLOR_MODE = 1 << 2;
129
130 /**
Wale Ogunwale361ca212014-11-20 11:42:38 -0800131 * Gets the name of the display device, which may be derived from EDID or
132 * other sources. The name may be localized and displayed to the user.
Jeff Brown848c2dc2012-08-19 20:18:08 -0700133 */
134 public String name;
135
136 /**
Wale Ogunwale361ca212014-11-20 11:42:38 -0800137 * Unique Id of display device.
138 */
139 public String uniqueId;
140
141 /**
Jeff Brownfa25bf52012-07-23 19:26:30 -0700142 * The width of the display in its natural orientation, in pixels.
143 * This value is not affected by display rotation.
144 */
145 public int width;
146
147 /**
148 * The height of the display in its natural orientation, in pixels.
149 * This value is not affected by display rotation.
150 */
151 public int height;
152
Jeff Browncbad9762012-09-04 21:57:59 -0700153 /**
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700154 * The active mode of the display.
Jeff Browncbad9762012-09-04 21:57:59 -0700155 */
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700156 public int modeId;
Jeff Browncbad9762012-09-04 21:57:59 -0700157
158 /**
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700159 * The default mode of the display.
Michael Wright3f145a22014-07-22 19:46:03 -0700160 */
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700161 public int defaultModeId;
162
163 /**
164 * The supported modes of the display.
165 */
166 public Display.Mode[] supportedModes = Display.Mode.EMPTY_ARRAY;
Michael Wright3f145a22014-07-22 19:46:03 -0700167
Michael Wright1c9977b2016-07-12 13:30:10 -0700168 /** The active color mode of the display */
169 public int colorMode;
Michael Wright58e829f2015-09-15 00:13:26 +0100170
Michael Wright1c9977b2016-07-12 13:30:10 -0700171 /** The supported color modes of the display */
172 public int[] supportedColorModes = { Display.COLOR_MODE_DEFAULT };
Michael Wright58e829f2015-09-15 00:13:26 +0100173
Michael Wright3f145a22014-07-22 19:46:03 -0700174 /**
Michael Wright9ff94c02016-03-30 18:05:40 -0700175 * The HDR capabilities this display claims to support.
176 */
177 public Display.HdrCapabilities hdrCapabilities;
178
179 /**
Jeff Browncbad9762012-09-04 21:57:59 -0700180 * The nominal apparent density of the display in DPI used for layout calculations.
181 * This density is sensitive to the viewing distance. A big TV and a tablet may have
182 * the same apparent density even though the pixels on the TV are much bigger than
183 * those on the tablet.
184 */
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700185 public int densityDpi;
Jeff Browncbad9762012-09-04 21:57:59 -0700186
187 /**
188 * The physical density of the display in DPI in the X direction.
189 * This density should specify the physical size of each pixel.
190 */
Jeff Brownfa25bf52012-07-23 19:26:30 -0700191 public float xDpi;
Jeff Browncbad9762012-09-04 21:57:59 -0700192
193 /**
194 * The physical density of the display in DPI in the X direction.
195 * This density should specify the physical size of each pixel.
196 */
Jeff Brownfa25bf52012-07-23 19:26:30 -0700197 public float yDpi;
198
Jeff Browncbad9762012-09-04 21:57:59 -0700199 /**
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700200 * This is a positive value indicating the phase offset of the VSYNC events provided by
201 * Choreographer relative to the display refresh. For example, if Choreographer reports
202 * that the refresh occurred at time N, it actually occurred at (N - appVsyncOffsetNanos).
203 */
204 public long appVsyncOffsetNanos;
205
206 /**
207 * This is how far in advance a buffer must be queued for presentation at
208 * a given time. If you want a buffer to appear on the screen at
209 * time N, you must submit the buffer before (N - bufferDeadlineNanos).
210 */
211 public long presentationDeadlineNanos;
212
213 /**
Jeff Browncbad9762012-09-04 21:57:59 -0700214 * Display flags.
215 */
Jeff Brownbd6e1502012-08-28 03:27:37 -0700216 public int flags;
217
Jeff Brownd728bf52012-09-08 18:05:28 -0700218 /**
219 * The touch attachment, per {@link DisplayViewport#touch}.
220 */
221 public int touch;
222
Jeff Brown27f1d672012-10-17 18:32:34 -0700223 /**
224 * The additional rotation to apply to all content presented on the display device
225 * relative to its physical coordinate system. Default is {@link Surface#ROTATION_0}.
226 * <p>
227 * This field can be used to compensate for the fact that the display has been
228 * physically rotated relative to its natural orientation such as an HDMI monitor
229 * that has been mounted sideways to appear to be portrait rather than landscape.
230 * </p>
231 */
232 public int rotation = Surface.ROTATION_0;
233
Jeff Brown92130f62012-10-24 21:28:33 -0700234 /**
235 * Display type.
236 */
237 public int type;
238
239 /**
240 * Display address, or null if none.
241 * Interpretation varies by display type.
242 */
243 public String address;
244
Jeff Browna506a6e2013-06-04 00:02:38 -0700245 /**
Jeff Brown037c33e2014-04-09 00:31:55 -0700246 * Display state.
247 */
248 public int state = Display.STATE_ON;
249
250 /**
Jeff Browna506a6e2013-06-04 00:02:38 -0700251 * The UID of the application that owns this display, or zero if it is owned by the system.
252 * <p>
253 * If the display is private, then only the owner can use it.
254 * </p>
255 */
256 public int ownerUid;
257
258 /**
259 * The package name of the application that owns this display, or null if it is
260 * owned by the system.
261 * <p>
262 * If the display is private, then only the owner can use it.
263 * </p>
264 */
265 public String ownerPackageName;
266
Jeff Browncbad9762012-09-04 21:57:59 -0700267 public void setAssumedDensityForExternalDisplay(int width, int height) {
268 densityDpi = Math.min(width, height) * DisplayMetrics.DENSITY_XHIGH / 1080;
269 // Technically, these values should be smaller than the apparent density
270 // but we don't know the physical size of the display.
271 xDpi = densityDpi;
272 yDpi = densityDpi;
273 }
274
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700275 @Override
276 public boolean equals(Object o) {
277 return o instanceof DisplayDeviceInfo && equals((DisplayDeviceInfo)o);
278 }
279
280 public boolean equals(DisplayDeviceInfo other) {
Jeff Brown10acf6d2015-04-14 14:20:47 -0700281 return other != null && diff(other) == 0;
282 }
283
284 /**
285 * Computes the difference between display device infos.
286 * Assumes other is not null.
287 */
288 public int diff(DisplayDeviceInfo other) {
289 int diff = 0;
290 if (state != other.state) {
291 diff |= DIFF_STATE;
292 }
Michael Wright1c9977b2016-07-12 13:30:10 -0700293 if (colorMode != other.colorMode) {
294 diff |= DIFF_COLOR_MODE;
295 }
Jeff Brown10acf6d2015-04-14 14:20:47 -0700296 if (!Objects.equal(name, other.name)
297 || !Objects.equal(uniqueId, other.uniqueId)
298 || width != other.width
299 || height != other.height
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700300 || modeId != other.modeId
301 || defaultModeId != other.defaultModeId
302 || !Arrays.equals(supportedModes, other.supportedModes)
Michael Wright1c9977b2016-07-12 13:30:10 -0700303 || !Arrays.equals(supportedColorModes, other.supportedColorModes)
Michael Wright9ff94c02016-03-30 18:05:40 -0700304 || !Objects.equal(hdrCapabilities, other.hdrCapabilities)
Jeff Brown10acf6d2015-04-14 14:20:47 -0700305 || densityDpi != other.densityDpi
306 || xDpi != other.xDpi
307 || yDpi != other.yDpi
308 || appVsyncOffsetNanos != other.appVsyncOffsetNanos
309 || presentationDeadlineNanos != other.presentationDeadlineNanos
310 || flags != other.flags
311 || touch != other.touch
312 || rotation != other.rotation
313 || type != other.type
314 || !Objects.equal(address, other.address)
315 || ownerUid != other.ownerUid
316 || !Objects.equal(ownerPackageName, other.ownerPackageName)) {
317 diff |= DIFF_OTHER;
318 }
319 return diff;
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700320 }
321
322 @Override
323 public int hashCode() {
324 return 0; // don't care
325 }
326
Jeff Brownfa25bf52012-07-23 19:26:30 -0700327 public void copyFrom(DisplayDeviceInfo other) {
Jeff Brown848c2dc2012-08-19 20:18:08 -0700328 name = other.name;
Wale Ogunwale361ca212014-11-20 11:42:38 -0800329 uniqueId = other.uniqueId;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700330 width = other.width;
331 height = other.height;
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700332 modeId = other.modeId;
333 defaultModeId = other.defaultModeId;
334 supportedModes = other.supportedModes;
Michael Wright1c9977b2016-07-12 13:30:10 -0700335 colorMode = other.colorMode;
336 supportedColorModes = other.supportedColorModes;
Michael Wright9ff94c02016-03-30 18:05:40 -0700337 hdrCapabilities = other.hdrCapabilities;
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700338 densityDpi = other.densityDpi;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700339 xDpi = other.xDpi;
340 yDpi = other.yDpi;
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700341 appVsyncOffsetNanos = other.appVsyncOffsetNanos;
342 presentationDeadlineNanos = other.presentationDeadlineNanos;
Jeff Brownbd6e1502012-08-28 03:27:37 -0700343 flags = other.flags;
Jeff Brownd728bf52012-09-08 18:05:28 -0700344 touch = other.touch;
Jeff Brown27f1d672012-10-17 18:32:34 -0700345 rotation = other.rotation;
Jeff Brown92130f62012-10-24 21:28:33 -0700346 type = other.type;
347 address = other.address;
Jeff Brown037c33e2014-04-09 00:31:55 -0700348 state = other.state;
Jeff Browna506a6e2013-06-04 00:02:38 -0700349 ownerUid = other.ownerUid;
350 ownerPackageName = other.ownerPackageName;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700351 }
352
Jeff Brown848c2dc2012-08-19 20:18:08 -0700353 // For debugging purposes
Jeff Brownfa25bf52012-07-23 19:26:30 -0700354 @Override
355 public String toString() {
Jeff Browna506a6e2013-06-04 00:02:38 -0700356 StringBuilder sb = new StringBuilder();
357 sb.append("DisplayDeviceInfo{\"");
Wale Ogunwale361ca212014-11-20 11:42:38 -0800358 sb.append(name).append("\": uniqueId=\"").append(uniqueId).append("\", ");
359 sb.append(width).append(" x ").append(height);
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700360 sb.append(", modeId ").append(modeId);
361 sb.append(", defaultModeId ").append(defaultModeId);
362 sb.append(", supportedModes ").append(Arrays.toString(supportedModes));
Michael Wright1c9977b2016-07-12 13:30:10 -0700363 sb.append(", colorMode ").append(colorMode);
364 sb.append(", supportedColorModes ").append(Arrays.toString(supportedColorModes));
Michael Wright9ff94c02016-03-30 18:05:40 -0700365 sb.append(", HdrCapabilities ").append(hdrCapabilities);
Michael Wright3f145a22014-07-22 19:46:03 -0700366 sb.append(", density ").append(densityDpi);
Jeff Browna506a6e2013-06-04 00:02:38 -0700367 sb.append(", ").append(xDpi).append(" x ").append(yDpi).append(" dpi");
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700368 sb.append(", appVsyncOff ").append(appVsyncOffsetNanos);
369 sb.append(", presDeadline ").append(presentationDeadlineNanos);
Jeff Browna506a6e2013-06-04 00:02:38 -0700370 sb.append(", touch ").append(touchToString(touch));
371 sb.append(", rotation ").append(rotation);
372 sb.append(", type ").append(Display.typeToString(type));
373 if (address != null) {
374 sb.append(", address ").append(address);
375 }
Jeff Brown037c33e2014-04-09 00:31:55 -0700376 sb.append(", state ").append(Display.stateToString(state));
Jeff Browna506a6e2013-06-04 00:02:38 -0700377 if (ownerUid != 0 || ownerPackageName != null) {
378 sb.append(", owner ").append(ownerPackageName);
379 sb.append(" (uid ").append(ownerUid).append(")");
380 }
381 sb.append(flagsToString(flags));
382 sb.append("}");
383 return sb.toString();
Jeff Brownd728bf52012-09-08 18:05:28 -0700384 }
385
386 private static String touchToString(int touch) {
387 switch (touch) {
388 case TOUCH_NONE:
389 return "NONE";
390 case TOUCH_INTERNAL:
391 return "INTERNAL";
392 case TOUCH_EXTERNAL:
393 return "EXTERNAL";
394 default:
395 return Integer.toString(touch);
396 }
Jeff Brownbd6e1502012-08-28 03:27:37 -0700397 }
398
399 private static String flagsToString(int flags) {
400 StringBuilder msg = new StringBuilder();
401 if ((flags & FLAG_DEFAULT_DISPLAY) != 0) {
402 msg.append(", FLAG_DEFAULT_DISPLAY");
403 }
Jeff Brown27f1d672012-10-17 18:32:34 -0700404 if ((flags & FLAG_ROTATES_WITH_CONTENT) != 0) {
405 msg.append(", FLAG_ROTATES_WITH_CONTENT");
Jeff Brownc5df37c2012-09-13 11:45:07 -0700406 }
Jeff Brown77aebfd2012-10-01 21:07:03 -0700407 if ((flags & FLAG_SECURE) != 0) {
408 msg.append(", FLAG_SECURE");
409 }
410 if ((flags & FLAG_SUPPORTS_PROTECTED_BUFFERS) != 0) {
411 msg.append(", FLAG_SUPPORTS_PROTECTED_BUFFERS");
Jeff Brownbd6e1502012-08-28 03:27:37 -0700412 }
Jeff Browna506a6e2013-06-04 00:02:38 -0700413 if ((flags & FLAG_PRIVATE) != 0) {
414 msg.append(", FLAG_PRIVATE");
415 }
416 if ((flags & FLAG_NEVER_BLANK) != 0) {
417 msg.append(", FLAG_NEVER_BLANK");
418 }
Jeff Brown7d00aff2013-08-02 19:03:49 -0700419 if ((flags & FLAG_PRESENTATION) != 0) {
420 msg.append(", FLAG_PRESENTATION");
421 }
Jeff Brownd14c8c92014-01-07 18:13:09 -0800422 if ((flags & FLAG_OWN_CONTENT_ONLY) != 0) {
423 msg.append(", FLAG_OWN_CONTENT_ONLY");
424 }
Adam Powell49e7ff92015-05-14 16:18:53 -0700425 if ((flags & FLAG_ROUND) != 0) {
426 msg.append(", FLAG_ROUND");
427 }
Andrii Kulian7211d2e2017-01-27 15:58:05 -0800428 if ((flags & FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD) != 0) {
429 msg.append(", FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD");
Andrii Kulianfc8f82b2017-01-26 13:17:27 -0800430 }
Jeff Brownbd6e1502012-08-28 03:27:37 -0700431 return msg.toString();
Jeff Brownfa25bf52012-07-23 19:26:30 -0700432 }
433}