blob: 11f8d6a3943ea001c151248b620ce787d8f15879 [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 Browncbad9762012-09-04 21:57:59 -070019import android.util.DisplayMetrics;
Jeff Brown92130f62012-10-24 21:28:33 -070020import android.view.Display;
Jeff Brown27f1d672012-10-17 18:32:34 -070021import android.view.Surface;
Jeff Browncbad9762012-09-04 21:57:59 -070022
Jeff Brown4ed8fe72012-08-30 18:18:29 -070023import libcore.util.Objects;
24
Jeff Brownfa25bf52012-07-23 19:26:30 -070025/**
26 * Describes the characteristics of a physical display device.
27 */
Jeff Brown4ed8fe72012-08-30 18:18:29 -070028final class DisplayDeviceInfo {
29 /**
30 * Flag: Indicates that this display device should be considered the default display
31 * device of the system.
32 */
Jeff Brownbd6e1502012-08-28 03:27:37 -070033 public static final int FLAG_DEFAULT_DISPLAY = 1 << 0;
Jeff Brown4ed8fe72012-08-30 18:18:29 -070034
35 /**
Jeff Brown27f1d672012-10-17 18:32:34 -070036 * Flag: Indicates that the orientation of this display device is coupled to the
37 * rotation of its associated logical display.
38 * <p>
39 * This flag should be applied to the default display to indicate that the user
40 * physically rotates the display when content is presented in a different orientation.
41 * The display manager will apply a coordinate transformation assuming that the
42 * physical orientation of the display matches the logical orientation of its content.
43 * </p><p>
44 * The flag should not be set when the display device is mounted in a fixed orientation
45 * such as on a desk. The display manager will apply a coordinate transformation
46 * such as a scale and translation to letterbox or pillarbox format under the
47 * assumption that the physical orientation of the display is invariant.
48 * </p>
Jeff Brown4ed8fe72012-08-30 18:18:29 -070049 */
Jeff Brown27f1d672012-10-17 18:32:34 -070050 public static final int FLAG_ROTATES_WITH_CONTENT = 1 << 1;
Jeff Brownc5df37c2012-09-13 11:45:07 -070051
52 /**
Jeff Brown77aebfd2012-10-01 21:07:03 -070053 * Flag: Indicates that this display device has secure video output, such as HDCP.
Jeff Brownc5df37c2012-09-13 11:45:07 -070054 */
Jeff Brown77aebfd2012-10-01 21:07:03 -070055 public static final int FLAG_SECURE = 1 << 2;
56
57 /**
58 * Flag: Indicates that this display device supports compositing
59 * from gralloc protected buffers.
60 */
61 public static final int FLAG_SUPPORTS_PROTECTED_BUFFERS = 1 << 3;
Jeff Brown4ed8fe72012-08-30 18:18:29 -070062
63 /**
Jeff Browna506a6e2013-06-04 00:02:38 -070064 * Flag: Indicates that the display device is owned by a particular application
65 * and that no other application should be able to interact with it.
66 */
67 public static final int FLAG_PRIVATE = 1 << 4;
68
69 /**
70 * Flag: Indicates that the display device is not blanked automatically by
71 * the power manager.
72 */
73 public static final int FLAG_NEVER_BLANK = 1 << 5;
74
75 /**
Jeff Brownd728bf52012-09-08 18:05:28 -070076 * Touch attachment: Display does not receive touch.
77 */
78 public static final int TOUCH_NONE = 0;
79
80 /**
81 * Touch attachment: Touch input is via the internal interface.
82 */
83 public static final int TOUCH_INTERNAL = 1;
84
85 /**
86 * Touch attachment: Touch input is via an external interface, such as USB.
87 */
88 public static final int TOUCH_EXTERNAL = 2;
89
90 /**
Jeff Brown848c2dc2012-08-19 20:18:08 -070091 * Gets the name of the display device, which may be derived from
92 * EDID or other sources. The name may be displayed to the user.
93 */
94 public String name;
95
96 /**
Jeff Brownfa25bf52012-07-23 19:26:30 -070097 * The width of the display in its natural orientation, in pixels.
98 * This value is not affected by display rotation.
99 */
100 public int width;
101
102 /**
103 * The height of the display in its natural orientation, in pixels.
104 * This value is not affected by display rotation.
105 */
106 public int height;
107
Jeff Browncbad9762012-09-04 21:57:59 -0700108 /**
109 * The refresh rate of the display.
110 */
Jeff Brownfa25bf52012-07-23 19:26:30 -0700111 public float refreshRate;
Jeff Browncbad9762012-09-04 21:57:59 -0700112
113 /**
114 * The nominal apparent density of the display in DPI used for layout calculations.
115 * This density is sensitive to the viewing distance. A big TV and a tablet may have
116 * the same apparent density even though the pixels on the TV are much bigger than
117 * those on the tablet.
118 */
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700119 public int densityDpi;
Jeff Browncbad9762012-09-04 21:57:59 -0700120
121 /**
122 * The physical density of the display in DPI in the X direction.
123 * This density should specify the physical size of each pixel.
124 */
Jeff Brownfa25bf52012-07-23 19:26:30 -0700125 public float xDpi;
Jeff Browncbad9762012-09-04 21:57:59 -0700126
127 /**
128 * The physical density of the display in DPI in the X direction.
129 * This density should specify the physical size of each pixel.
130 */
Jeff Brownfa25bf52012-07-23 19:26:30 -0700131 public float yDpi;
132
Jeff Browncbad9762012-09-04 21:57:59 -0700133 /**
134 * Display flags.
135 */
Jeff Brownbd6e1502012-08-28 03:27:37 -0700136 public int flags;
137
Jeff Brownd728bf52012-09-08 18:05:28 -0700138 /**
139 * The touch attachment, per {@link DisplayViewport#touch}.
140 */
141 public int touch;
142
Jeff Brown27f1d672012-10-17 18:32:34 -0700143 /**
144 * The additional rotation to apply to all content presented on the display device
145 * relative to its physical coordinate system. Default is {@link Surface#ROTATION_0}.
146 * <p>
147 * This field can be used to compensate for the fact that the display has been
148 * physically rotated relative to its natural orientation such as an HDMI monitor
149 * that has been mounted sideways to appear to be portrait rather than landscape.
150 * </p>
151 */
152 public int rotation = Surface.ROTATION_0;
153
Jeff Brown92130f62012-10-24 21:28:33 -0700154 /**
155 * Display type.
156 */
157 public int type;
158
159 /**
160 * Display address, or null if none.
161 * Interpretation varies by display type.
162 */
163 public String address;
164
Jeff Browna506a6e2013-06-04 00:02:38 -0700165 /**
166 * The UID of the application that owns this display, or zero if it is owned by the system.
167 * <p>
168 * If the display is private, then only the owner can use it.
169 * </p>
170 */
171 public int ownerUid;
172
173 /**
174 * The package name of the application that owns this display, or null if it is
175 * owned by the system.
176 * <p>
177 * If the display is private, then only the owner can use it.
178 * </p>
179 */
180 public String ownerPackageName;
181
Jeff Browncbad9762012-09-04 21:57:59 -0700182 public void setAssumedDensityForExternalDisplay(int width, int height) {
183 densityDpi = Math.min(width, height) * DisplayMetrics.DENSITY_XHIGH / 1080;
184 // Technically, these values should be smaller than the apparent density
185 // but we don't know the physical size of the display.
186 xDpi = densityDpi;
187 yDpi = densityDpi;
188 }
189
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700190 @Override
191 public boolean equals(Object o) {
192 return o instanceof DisplayDeviceInfo && equals((DisplayDeviceInfo)o);
193 }
194
195 public boolean equals(DisplayDeviceInfo other) {
196 return other != null
197 && Objects.equal(name, other.name)
198 && width == other.width
199 && height == other.height
200 && refreshRate == other.refreshRate
201 && densityDpi == other.densityDpi
202 && xDpi == other.xDpi
203 && yDpi == other.yDpi
Jeff Brownd728bf52012-09-08 18:05:28 -0700204 && flags == other.flags
Jeff Brown27f1d672012-10-17 18:32:34 -0700205 && touch == other.touch
Jeff Brown92130f62012-10-24 21:28:33 -0700206 && rotation == other.rotation
207 && type == other.type
Jeff Browna506a6e2013-06-04 00:02:38 -0700208 && Objects.equal(address, other.address)
209 && ownerUid == other.ownerUid
210 && Objects.equal(ownerPackageName, other.ownerPackageName);
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700211 }
212
213 @Override
214 public int hashCode() {
215 return 0; // don't care
216 }
217
Jeff Brownfa25bf52012-07-23 19:26:30 -0700218 public void copyFrom(DisplayDeviceInfo other) {
Jeff Brown848c2dc2012-08-19 20:18:08 -0700219 name = other.name;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700220 width = other.width;
221 height = other.height;
222 refreshRate = other.refreshRate;
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700223 densityDpi = other.densityDpi;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700224 xDpi = other.xDpi;
225 yDpi = other.yDpi;
Jeff Brownbd6e1502012-08-28 03:27:37 -0700226 flags = other.flags;
Jeff Brownd728bf52012-09-08 18:05:28 -0700227 touch = other.touch;
Jeff Brown27f1d672012-10-17 18:32:34 -0700228 rotation = other.rotation;
Jeff Brown92130f62012-10-24 21:28:33 -0700229 type = other.type;
230 address = other.address;
Jeff Browna506a6e2013-06-04 00:02:38 -0700231 ownerUid = other.ownerUid;
232 ownerPackageName = other.ownerPackageName;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700233 }
234
Jeff Brown848c2dc2012-08-19 20:18:08 -0700235 // For debugging purposes
Jeff Brownfa25bf52012-07-23 19:26:30 -0700236 @Override
237 public String toString() {
Jeff Browna506a6e2013-06-04 00:02:38 -0700238 StringBuilder sb = new StringBuilder();
239 sb.append("DisplayDeviceInfo{\"");
240 sb.append(name).append("\": ").append(width).append(" x ").append(height);
241 sb.append(", ").append(refreshRate).append(" fps, ");
242 sb.append("density ").append(densityDpi);
243 sb.append(", ").append(xDpi).append(" x ").append(yDpi).append(" dpi");
244 sb.append(", touch ").append(touchToString(touch));
245 sb.append(", rotation ").append(rotation);
246 sb.append(", type ").append(Display.typeToString(type));
247 if (address != null) {
248 sb.append(", address ").append(address);
249 }
250 if (ownerUid != 0 || ownerPackageName != null) {
251 sb.append(", owner ").append(ownerPackageName);
252 sb.append(" (uid ").append(ownerUid).append(")");
253 }
254 sb.append(flagsToString(flags));
255 sb.append("}");
256 return sb.toString();
Jeff Brownd728bf52012-09-08 18:05:28 -0700257 }
258
259 private static String touchToString(int touch) {
260 switch (touch) {
261 case TOUCH_NONE:
262 return "NONE";
263 case TOUCH_INTERNAL:
264 return "INTERNAL";
265 case TOUCH_EXTERNAL:
266 return "EXTERNAL";
267 default:
268 return Integer.toString(touch);
269 }
Jeff Brownbd6e1502012-08-28 03:27:37 -0700270 }
271
272 private static String flagsToString(int flags) {
273 StringBuilder msg = new StringBuilder();
274 if ((flags & FLAG_DEFAULT_DISPLAY) != 0) {
275 msg.append(", FLAG_DEFAULT_DISPLAY");
276 }
Jeff Brown27f1d672012-10-17 18:32:34 -0700277 if ((flags & FLAG_ROTATES_WITH_CONTENT) != 0) {
278 msg.append(", FLAG_ROTATES_WITH_CONTENT");
Jeff Brownc5df37c2012-09-13 11:45:07 -0700279 }
Jeff Brown77aebfd2012-10-01 21:07:03 -0700280 if ((flags & FLAG_SECURE) != 0) {
281 msg.append(", FLAG_SECURE");
282 }
283 if ((flags & FLAG_SUPPORTS_PROTECTED_BUFFERS) != 0) {
284 msg.append(", FLAG_SUPPORTS_PROTECTED_BUFFERS");
Jeff Brownbd6e1502012-08-28 03:27:37 -0700285 }
Jeff Browna506a6e2013-06-04 00:02:38 -0700286 if ((flags & FLAG_PRIVATE) != 0) {
287 msg.append(", FLAG_PRIVATE");
288 }
289 if ((flags & FLAG_NEVER_BLANK) != 0) {
290 msg.append(", FLAG_NEVER_BLANK");
291 }
Jeff Brownbd6e1502012-08-28 03:27:37 -0700292 return msg.toString();
Jeff Brownfa25bf52012-07-23 19:26:30 -0700293 }
294}