blob: 75f1f53f79db62dd600b2bb7bb8fbb5163a9d220 [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
Jeff Brown4ed8fe72012-08-30 18:18:29 -070024import libcore.util.Objects;
25
Jeff Brownfa25bf52012-07-23 19:26:30 -070026/**
27 * Describes the characteristics of a physical display device.
28 */
Jeff Brown4ed8fe72012-08-30 18:18:29 -070029final class DisplayDeviceInfo {
30 /**
31 * Flag: Indicates that this display device should be considered the default display
32 * device of the system.
33 */
Jeff Brownbd6e1502012-08-28 03:27:37 -070034 public static final int FLAG_DEFAULT_DISPLAY = 1 << 0;
Jeff Brown4ed8fe72012-08-30 18:18:29 -070035
36 /**
Jeff Brown27f1d672012-10-17 18:32:34 -070037 * Flag: Indicates that the orientation of this display device is coupled to the
38 * rotation of its associated logical display.
39 * <p>
40 * This flag should be applied to the default display to indicate that the user
41 * physically rotates the display when content is presented in a different orientation.
42 * The display manager will apply a coordinate transformation assuming that the
43 * physical orientation of the display matches the logical orientation of its content.
44 * </p><p>
45 * The flag should not be set when the display device is mounted in a fixed orientation
46 * such as on a desk. The display manager will apply a coordinate transformation
47 * such as a scale and translation to letterbox or pillarbox format under the
48 * assumption that the physical orientation of the display is invariant.
49 * </p>
Jeff Brown4ed8fe72012-08-30 18:18:29 -070050 */
Jeff Brown27f1d672012-10-17 18:32:34 -070051 public static final int FLAG_ROTATES_WITH_CONTENT = 1 << 1;
Jeff Brownc5df37c2012-09-13 11:45:07 -070052
53 /**
Jeff Brown77aebfd2012-10-01 21:07:03 -070054 * Flag: Indicates that this display device has secure video output, such as HDCP.
Jeff Brownc5df37c2012-09-13 11:45:07 -070055 */
Jeff Brown77aebfd2012-10-01 21:07:03 -070056 public static final int FLAG_SECURE = 1 << 2;
57
58 /**
59 * Flag: Indicates that this display device supports compositing
60 * from gralloc protected buffers.
61 */
62 public static final int FLAG_SUPPORTS_PROTECTED_BUFFERS = 1 << 3;
Jeff Brown4ed8fe72012-08-30 18:18:29 -070063
64 /**
Jeff Browna506a6e2013-06-04 00:02:38 -070065 * Flag: Indicates that the display device is owned by a particular application
66 * and that no other application should be able to interact with it.
Jeff Brownd14c8c92014-01-07 18:13:09 -080067 * Should typically be used together with {@link #FLAG_OWN_CONTENT_ONLY}.
Jeff Browna506a6e2013-06-04 00:02:38 -070068 */
69 public static final int FLAG_PRIVATE = 1 << 4;
70
71 /**
72 * Flag: Indicates that the display device is not blanked automatically by
73 * the power manager.
74 */
75 public static final int FLAG_NEVER_BLANK = 1 << 5;
76
77 /**
Jeff Brown7d00aff2013-08-02 19:03:49 -070078 * Flag: Indicates that the display is suitable for presentations.
79 */
80 public static final int FLAG_PRESENTATION = 1 << 6;
81
82 /**
Jeff Brownd14c8c92014-01-07 18:13:09 -080083 * Flag: Only show this display's own content; do not mirror
84 * the content of another display.
85 */
86 public static final int FLAG_OWN_CONTENT_ONLY = 1 << 7;
87
88 /**
Jeff Brownd728bf52012-09-08 18:05:28 -070089 * Touch attachment: Display does not receive touch.
90 */
91 public static final int TOUCH_NONE = 0;
92
93 /**
94 * Touch attachment: Touch input is via the internal interface.
95 */
96 public static final int TOUCH_INTERNAL = 1;
97
98 /**
99 * Touch attachment: Touch input is via an external interface, such as USB.
100 */
101 public static final int TOUCH_EXTERNAL = 2;
102
103 /**
Jeff Brown848c2dc2012-08-19 20:18:08 -0700104 * Gets the name of the display device, which may be derived from
105 * EDID or other sources. The name may be displayed to the user.
106 */
107 public String name;
108
109 /**
Jeff Brownfa25bf52012-07-23 19:26:30 -0700110 * The width of the display in its natural orientation, in pixels.
111 * This value is not affected by display rotation.
112 */
113 public int width;
114
115 /**
116 * The height of the display in its natural orientation, in pixels.
117 * This value is not affected by display rotation.
118 */
119 public int height;
120
Jeff Browncbad9762012-09-04 21:57:59 -0700121 /**
122 * The refresh rate of the display.
123 */
Jeff Brownfa25bf52012-07-23 19:26:30 -0700124 public float refreshRate;
Jeff Browncbad9762012-09-04 21:57:59 -0700125
126 /**
127 * The nominal apparent density of the display in DPI used for layout calculations.
128 * This density is sensitive to the viewing distance. A big TV and a tablet may have
129 * the same apparent density even though the pixels on the TV are much bigger than
130 * those on the tablet.
131 */
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700132 public int densityDpi;
Jeff Browncbad9762012-09-04 21:57:59 -0700133
134 /**
135 * The physical density of the display in DPI in the X direction.
136 * This density should specify the physical size of each pixel.
137 */
Jeff Brownfa25bf52012-07-23 19:26:30 -0700138 public float xDpi;
Jeff Browncbad9762012-09-04 21:57:59 -0700139
140 /**
141 * The physical density of the display in DPI in the X direction.
142 * This density should specify the physical size of each pixel.
143 */
Jeff Brownfa25bf52012-07-23 19:26:30 -0700144 public float yDpi;
145
Jeff Browncbad9762012-09-04 21:57:59 -0700146 /**
147 * Display flags.
148 */
Jeff Brownbd6e1502012-08-28 03:27:37 -0700149 public int flags;
150
Jeff Brownd728bf52012-09-08 18:05:28 -0700151 /**
152 * The touch attachment, per {@link DisplayViewport#touch}.
153 */
154 public int touch;
155
Jeff Brown27f1d672012-10-17 18:32:34 -0700156 /**
157 * The additional rotation to apply to all content presented on the display device
158 * relative to its physical coordinate system. Default is {@link Surface#ROTATION_0}.
159 * <p>
160 * This field can be used to compensate for the fact that the display has been
161 * physically rotated relative to its natural orientation such as an HDMI monitor
162 * that has been mounted sideways to appear to be portrait rather than landscape.
163 * </p>
164 */
165 public int rotation = Surface.ROTATION_0;
166
Jeff Brown92130f62012-10-24 21:28:33 -0700167 /**
168 * Display type.
169 */
170 public int type;
171
172 /**
173 * Display address, or null if none.
174 * Interpretation varies by display type.
175 */
176 public String address;
177
Jeff Browna506a6e2013-06-04 00:02:38 -0700178 /**
179 * The UID of the application that owns this display, or zero if it is owned by the system.
180 * <p>
181 * If the display is private, then only the owner can use it.
182 * </p>
183 */
184 public int ownerUid;
185
186 /**
187 * The package name of the application that owns this display, or null if it is
188 * owned by the system.
189 * <p>
190 * If the display is private, then only the owner can use it.
191 * </p>
192 */
193 public String ownerPackageName;
194
Jeff Browncbad9762012-09-04 21:57:59 -0700195 public void setAssumedDensityForExternalDisplay(int width, int height) {
196 densityDpi = Math.min(width, height) * DisplayMetrics.DENSITY_XHIGH / 1080;
197 // Technically, these values should be smaller than the apparent density
198 // but we don't know the physical size of the display.
199 xDpi = densityDpi;
200 yDpi = densityDpi;
201 }
202
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700203 @Override
204 public boolean equals(Object o) {
205 return o instanceof DisplayDeviceInfo && equals((DisplayDeviceInfo)o);
206 }
207
208 public boolean equals(DisplayDeviceInfo other) {
209 return other != null
210 && Objects.equal(name, other.name)
211 && width == other.width
212 && height == other.height
213 && refreshRate == other.refreshRate
214 && densityDpi == other.densityDpi
215 && xDpi == other.xDpi
216 && yDpi == other.yDpi
Jeff Brownd728bf52012-09-08 18:05:28 -0700217 && flags == other.flags
Jeff Brown27f1d672012-10-17 18:32:34 -0700218 && touch == other.touch
Jeff Brown92130f62012-10-24 21:28:33 -0700219 && rotation == other.rotation
220 && type == other.type
Jeff Browna506a6e2013-06-04 00:02:38 -0700221 && Objects.equal(address, other.address)
222 && ownerUid == other.ownerUid
223 && Objects.equal(ownerPackageName, other.ownerPackageName);
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700224 }
225
226 @Override
227 public int hashCode() {
228 return 0; // don't care
229 }
230
Jeff Brownfa25bf52012-07-23 19:26:30 -0700231 public void copyFrom(DisplayDeviceInfo other) {
Jeff Brown848c2dc2012-08-19 20:18:08 -0700232 name = other.name;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700233 width = other.width;
234 height = other.height;
235 refreshRate = other.refreshRate;
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700236 densityDpi = other.densityDpi;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700237 xDpi = other.xDpi;
238 yDpi = other.yDpi;
Jeff Brownbd6e1502012-08-28 03:27:37 -0700239 flags = other.flags;
Jeff Brownd728bf52012-09-08 18:05:28 -0700240 touch = other.touch;
Jeff Brown27f1d672012-10-17 18:32:34 -0700241 rotation = other.rotation;
Jeff Brown92130f62012-10-24 21:28:33 -0700242 type = other.type;
243 address = other.address;
Jeff Browna506a6e2013-06-04 00:02:38 -0700244 ownerUid = other.ownerUid;
245 ownerPackageName = other.ownerPackageName;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700246 }
247
Jeff Brown848c2dc2012-08-19 20:18:08 -0700248 // For debugging purposes
Jeff Brownfa25bf52012-07-23 19:26:30 -0700249 @Override
250 public String toString() {
Jeff Browna506a6e2013-06-04 00:02:38 -0700251 StringBuilder sb = new StringBuilder();
252 sb.append("DisplayDeviceInfo{\"");
253 sb.append(name).append("\": ").append(width).append(" x ").append(height);
254 sb.append(", ").append(refreshRate).append(" fps, ");
255 sb.append("density ").append(densityDpi);
256 sb.append(", ").append(xDpi).append(" x ").append(yDpi).append(" dpi");
257 sb.append(", touch ").append(touchToString(touch));
258 sb.append(", rotation ").append(rotation);
259 sb.append(", type ").append(Display.typeToString(type));
260 if (address != null) {
261 sb.append(", address ").append(address);
262 }
263 if (ownerUid != 0 || ownerPackageName != null) {
264 sb.append(", owner ").append(ownerPackageName);
265 sb.append(" (uid ").append(ownerUid).append(")");
266 }
267 sb.append(flagsToString(flags));
268 sb.append("}");
269 return sb.toString();
Jeff Brownd728bf52012-09-08 18:05:28 -0700270 }
271
272 private static String touchToString(int touch) {
273 switch (touch) {
274 case TOUCH_NONE:
275 return "NONE";
276 case TOUCH_INTERNAL:
277 return "INTERNAL";
278 case TOUCH_EXTERNAL:
279 return "EXTERNAL";
280 default:
281 return Integer.toString(touch);
282 }
Jeff Brownbd6e1502012-08-28 03:27:37 -0700283 }
284
285 private static String flagsToString(int flags) {
286 StringBuilder msg = new StringBuilder();
287 if ((flags & FLAG_DEFAULT_DISPLAY) != 0) {
288 msg.append(", FLAG_DEFAULT_DISPLAY");
289 }
Jeff Brown27f1d672012-10-17 18:32:34 -0700290 if ((flags & FLAG_ROTATES_WITH_CONTENT) != 0) {
291 msg.append(", FLAG_ROTATES_WITH_CONTENT");
Jeff Brownc5df37c2012-09-13 11:45:07 -0700292 }
Jeff Brown77aebfd2012-10-01 21:07:03 -0700293 if ((flags & FLAG_SECURE) != 0) {
294 msg.append(", FLAG_SECURE");
295 }
296 if ((flags & FLAG_SUPPORTS_PROTECTED_BUFFERS) != 0) {
297 msg.append(", FLAG_SUPPORTS_PROTECTED_BUFFERS");
Jeff Brownbd6e1502012-08-28 03:27:37 -0700298 }
Jeff Browna506a6e2013-06-04 00:02:38 -0700299 if ((flags & FLAG_PRIVATE) != 0) {
300 msg.append(", FLAG_PRIVATE");
301 }
302 if ((flags & FLAG_NEVER_BLANK) != 0) {
303 msg.append(", FLAG_NEVER_BLANK");
304 }
Jeff Brown7d00aff2013-08-02 19:03:49 -0700305 if ((flags & FLAG_PRESENTATION) != 0) {
306 msg.append(", FLAG_PRESENTATION");
307 }
Jeff Brownd14c8c92014-01-07 18:13:09 -0800308 if ((flags & FLAG_OWN_CONTENT_ONLY) != 0) {
309 msg.append(", FLAG_OWN_CONTENT_ONLY");
310 }
Jeff Brownbd6e1502012-08-28 03:27:37 -0700311 return msg.toString();
Jeff Brownfa25bf52012-07-23 19:26:30 -0700312 }
313}