Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.server.display; |
| 18 | |
Jeff Brown | 4ccb823 | 2014-01-16 22:16:42 -0800 | [diff] [blame] | 19 | import android.hardware.display.DisplayViewport; |
Jeff Brown | cbad976 | 2012-09-04 21:57:59 -0700 | [diff] [blame] | 20 | import android.util.DisplayMetrics; |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 21 | import android.view.Display; |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 22 | import android.view.Surface; |
Jeff Brown | cbad976 | 2012-09-04 21:57:59 -0700 | [diff] [blame] | 23 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 24 | import libcore.util.Objects; |
| 25 | |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 26 | /** |
| 27 | * Describes the characteristics of a physical display device. |
| 28 | */ |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 29 | final class DisplayDeviceInfo { |
| 30 | /** |
| 31 | * Flag: Indicates that this display device should be considered the default display |
| 32 | * device of the system. |
| 33 | */ |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 34 | public static final int FLAG_DEFAULT_DISPLAY = 1 << 0; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 35 | |
| 36 | /** |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 37 | * 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 Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 50 | */ |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 51 | public static final int FLAG_ROTATES_WITH_CONTENT = 1 << 1; |
Jeff Brown | c5df37c | 2012-09-13 11:45:07 -0700 | [diff] [blame] | 52 | |
| 53 | /** |
Jeff Brown | 77aebfd | 2012-10-01 21:07:03 -0700 | [diff] [blame] | 54 | * Flag: Indicates that this display device has secure video output, such as HDCP. |
Jeff Brown | c5df37c | 2012-09-13 11:45:07 -0700 | [diff] [blame] | 55 | */ |
Jeff Brown | 77aebfd | 2012-10-01 21:07:03 -0700 | [diff] [blame] | 56 | 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 Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 63 | |
| 64 | /** |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 65 | * 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 Brown | d14c8c9 | 2014-01-07 18:13:09 -0800 | [diff] [blame] | 67 | * Should typically be used together with {@link #FLAG_OWN_CONTENT_ONLY}. |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 68 | */ |
| 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 Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 78 | * Flag: Indicates that the display is suitable for presentations. |
| 79 | */ |
| 80 | public static final int FLAG_PRESENTATION = 1 << 6; |
| 81 | |
| 82 | /** |
Jeff Brown | d14c8c9 | 2014-01-07 18:13:09 -0800 | [diff] [blame] | 83 | * 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 Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 89 | * 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 Brown | 848c2dc | 2012-08-19 20:18:08 -0700 | [diff] [blame] | 104 | * 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 Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 110 | * 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 Brown | cbad976 | 2012-09-04 21:57:59 -0700 | [diff] [blame] | 121 | /** |
| 122 | * The refresh rate of the display. |
| 123 | */ |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 124 | public float refreshRate; |
Jeff Brown | cbad976 | 2012-09-04 21:57:59 -0700 | [diff] [blame] | 125 | |
| 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 Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 132 | public int densityDpi; |
Jeff Brown | cbad976 | 2012-09-04 21:57:59 -0700 | [diff] [blame] | 133 | |
| 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 Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 138 | public float xDpi; |
Jeff Brown | cbad976 | 2012-09-04 21:57:59 -0700 | [diff] [blame] | 139 | |
| 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 Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 144 | public float yDpi; |
| 145 | |
Jeff Brown | cbad976 | 2012-09-04 21:57:59 -0700 | [diff] [blame] | 146 | /** |
| 147 | * Display flags. |
| 148 | */ |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 149 | public int flags; |
| 150 | |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 151 | /** |
| 152 | * The touch attachment, per {@link DisplayViewport#touch}. |
| 153 | */ |
| 154 | public int touch; |
| 155 | |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 156 | /** |
| 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 Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 167 | /** |
| 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 Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 178 | /** |
| 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 Brown | cbad976 | 2012-09-04 21:57:59 -0700 | [diff] [blame] | 195 | 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 Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 203 | @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 Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 217 | && flags == other.flags |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 218 | && touch == other.touch |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 219 | && rotation == other.rotation |
| 220 | && type == other.type |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 221 | && Objects.equal(address, other.address) |
| 222 | && ownerUid == other.ownerUid |
| 223 | && Objects.equal(ownerPackageName, other.ownerPackageName); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | @Override |
| 227 | public int hashCode() { |
| 228 | return 0; // don't care |
| 229 | } |
| 230 | |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 231 | public void copyFrom(DisplayDeviceInfo other) { |
Jeff Brown | 848c2dc | 2012-08-19 20:18:08 -0700 | [diff] [blame] | 232 | name = other.name; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 233 | width = other.width; |
| 234 | height = other.height; |
| 235 | refreshRate = other.refreshRate; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 236 | densityDpi = other.densityDpi; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 237 | xDpi = other.xDpi; |
| 238 | yDpi = other.yDpi; |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 239 | flags = other.flags; |
Jeff Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 240 | touch = other.touch; |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 241 | rotation = other.rotation; |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 242 | type = other.type; |
| 243 | address = other.address; |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 244 | ownerUid = other.ownerUid; |
| 245 | ownerPackageName = other.ownerPackageName; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 246 | } |
| 247 | |
Jeff Brown | 848c2dc | 2012-08-19 20:18:08 -0700 | [diff] [blame] | 248 | // For debugging purposes |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 249 | @Override |
| 250 | public String toString() { |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 251 | 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 Brown | d728bf5 | 2012-09-08 18:05:28 -0700 | [diff] [blame] | 270 | } |
| 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 Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 283 | } |
| 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 Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 290 | if ((flags & FLAG_ROTATES_WITH_CONTENT) != 0) { |
| 291 | msg.append(", FLAG_ROTATES_WITH_CONTENT"); |
Jeff Brown | c5df37c | 2012-09-13 11:45:07 -0700 | [diff] [blame] | 292 | } |
Jeff Brown | 77aebfd | 2012-10-01 21:07:03 -0700 | [diff] [blame] | 293 | 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 Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 298 | } |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 299 | 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 Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 305 | if ((flags & FLAG_PRESENTATION) != 0) { |
| 306 | msg.append(", FLAG_PRESENTATION"); |
| 307 | } |
Jeff Brown | d14c8c9 | 2014-01-07 18:13:09 -0800 | [diff] [blame] | 308 | if ((flags & FLAG_OWN_CONTENT_ONLY) != 0) { |
| 309 | msg.append(", FLAG_OWN_CONTENT_ONLY"); |
| 310 | } |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 311 | return msg.toString(); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 312 | } |
| 313 | } |