DisplayDeviceInfo.java revision d14c8c9039c0056e1f30ad5d410c8fde20d63df5
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 17package com.android.server.display; 18 19import android.util.DisplayMetrics; 20import android.view.Display; 21import android.view.Surface; 22 23import libcore.util.Objects; 24 25/** 26 * Describes the characteristics of a physical display device. 27 */ 28final class DisplayDeviceInfo { 29 /** 30 * Flag: Indicates that this display device should be considered the default display 31 * device of the system. 32 */ 33 public static final int FLAG_DEFAULT_DISPLAY = 1 << 0; 34 35 /** 36 * 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> 49 */ 50 public static final int FLAG_ROTATES_WITH_CONTENT = 1 << 1; 51 52 /** 53 * Flag: Indicates that this display device has secure video output, such as HDCP. 54 */ 55 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; 62 63 /** 64 * 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 * Should typically be used together with {@link #FLAG_OWN_CONTENT_ONLY}. 67 */ 68 public static final int FLAG_PRIVATE = 1 << 4; 69 70 /** 71 * Flag: Indicates that the display device is not blanked automatically by 72 * the power manager. 73 */ 74 public static final int FLAG_NEVER_BLANK = 1 << 5; 75 76 /** 77 * Flag: Indicates that the display is suitable for presentations. 78 */ 79 public static final int FLAG_PRESENTATION = 1 << 6; 80 81 /** 82 * Flag: Only show this display's own content; do not mirror 83 * the content of another display. 84 */ 85 public static final int FLAG_OWN_CONTENT_ONLY = 1 << 7; 86 87 /** 88 * Touch attachment: Display does not receive touch. 89 */ 90 public static final int TOUCH_NONE = 0; 91 92 /** 93 * Touch attachment: Touch input is via the internal interface. 94 */ 95 public static final int TOUCH_INTERNAL = 1; 96 97 /** 98 * Touch attachment: Touch input is via an external interface, such as USB. 99 */ 100 public static final int TOUCH_EXTERNAL = 2; 101 102 /** 103 * Gets the name of the display device, which may be derived from 104 * EDID or other sources. The name may be displayed to the user. 105 */ 106 public String name; 107 108 /** 109 * The width of the display in its natural orientation, in pixels. 110 * This value is not affected by display rotation. 111 */ 112 public int width; 113 114 /** 115 * The height of the display in its natural orientation, in pixels. 116 * This value is not affected by display rotation. 117 */ 118 public int height; 119 120 /** 121 * The refresh rate of the display. 122 */ 123 public float refreshRate; 124 125 /** 126 * The nominal apparent density of the display in DPI used for layout calculations. 127 * This density is sensitive to the viewing distance. A big TV and a tablet may have 128 * the same apparent density even though the pixels on the TV are much bigger than 129 * those on the tablet. 130 */ 131 public int densityDpi; 132 133 /** 134 * The physical density of the display in DPI in the X direction. 135 * This density should specify the physical size of each pixel. 136 */ 137 public float xDpi; 138 139 /** 140 * The physical density of the display in DPI in the X direction. 141 * This density should specify the physical size of each pixel. 142 */ 143 public float yDpi; 144 145 /** 146 * Display flags. 147 */ 148 public int flags; 149 150 /** 151 * The touch attachment, per {@link DisplayViewport#touch}. 152 */ 153 public int touch; 154 155 /** 156 * The additional rotation to apply to all content presented on the display device 157 * relative to its physical coordinate system. Default is {@link Surface#ROTATION_0}. 158 * <p> 159 * This field can be used to compensate for the fact that the display has been 160 * physically rotated relative to its natural orientation such as an HDMI monitor 161 * that has been mounted sideways to appear to be portrait rather than landscape. 162 * </p> 163 */ 164 public int rotation = Surface.ROTATION_0; 165 166 /** 167 * Display type. 168 */ 169 public int type; 170 171 /** 172 * Display address, or null if none. 173 * Interpretation varies by display type. 174 */ 175 public String address; 176 177 /** 178 * The UID of the application that owns this display, or zero if it is owned by the system. 179 * <p> 180 * If the display is private, then only the owner can use it. 181 * </p> 182 */ 183 public int ownerUid; 184 185 /** 186 * The package name of the application that owns this display, or null if it is 187 * owned by the system. 188 * <p> 189 * If the display is private, then only the owner can use it. 190 * </p> 191 */ 192 public String ownerPackageName; 193 194 public void setAssumedDensityForExternalDisplay(int width, int height) { 195 densityDpi = Math.min(width, height) * DisplayMetrics.DENSITY_XHIGH / 1080; 196 // Technically, these values should be smaller than the apparent density 197 // but we don't know the physical size of the display. 198 xDpi = densityDpi; 199 yDpi = densityDpi; 200 } 201 202 @Override 203 public boolean equals(Object o) { 204 return o instanceof DisplayDeviceInfo && equals((DisplayDeviceInfo)o); 205 } 206 207 public boolean equals(DisplayDeviceInfo other) { 208 return other != null 209 && Objects.equal(name, other.name) 210 && width == other.width 211 && height == other.height 212 && refreshRate == other.refreshRate 213 && densityDpi == other.densityDpi 214 && xDpi == other.xDpi 215 && yDpi == other.yDpi 216 && flags == other.flags 217 && touch == other.touch 218 && rotation == other.rotation 219 && type == other.type 220 && Objects.equal(address, other.address) 221 && ownerUid == other.ownerUid 222 && Objects.equal(ownerPackageName, other.ownerPackageName); 223 } 224 225 @Override 226 public int hashCode() { 227 return 0; // don't care 228 } 229 230 public void copyFrom(DisplayDeviceInfo other) { 231 name = other.name; 232 width = other.width; 233 height = other.height; 234 refreshRate = other.refreshRate; 235 densityDpi = other.densityDpi; 236 xDpi = other.xDpi; 237 yDpi = other.yDpi; 238 flags = other.flags; 239 touch = other.touch; 240 rotation = other.rotation; 241 type = other.type; 242 address = other.address; 243 ownerUid = other.ownerUid; 244 ownerPackageName = other.ownerPackageName; 245 } 246 247 // For debugging purposes 248 @Override 249 public String toString() { 250 StringBuilder sb = new StringBuilder(); 251 sb.append("DisplayDeviceInfo{\""); 252 sb.append(name).append("\": ").append(width).append(" x ").append(height); 253 sb.append(", ").append(refreshRate).append(" fps, "); 254 sb.append("density ").append(densityDpi); 255 sb.append(", ").append(xDpi).append(" x ").append(yDpi).append(" dpi"); 256 sb.append(", touch ").append(touchToString(touch)); 257 sb.append(", rotation ").append(rotation); 258 sb.append(", type ").append(Display.typeToString(type)); 259 if (address != null) { 260 sb.append(", address ").append(address); 261 } 262 if (ownerUid != 0 || ownerPackageName != null) { 263 sb.append(", owner ").append(ownerPackageName); 264 sb.append(" (uid ").append(ownerUid).append(")"); 265 } 266 sb.append(flagsToString(flags)); 267 sb.append("}"); 268 return sb.toString(); 269 } 270 271 private static String touchToString(int touch) { 272 switch (touch) { 273 case TOUCH_NONE: 274 return "NONE"; 275 case TOUCH_INTERNAL: 276 return "INTERNAL"; 277 case TOUCH_EXTERNAL: 278 return "EXTERNAL"; 279 default: 280 return Integer.toString(touch); 281 } 282 } 283 284 private static String flagsToString(int flags) { 285 StringBuilder msg = new StringBuilder(); 286 if ((flags & FLAG_DEFAULT_DISPLAY) != 0) { 287 msg.append(", FLAG_DEFAULT_DISPLAY"); 288 } 289 if ((flags & FLAG_ROTATES_WITH_CONTENT) != 0) { 290 msg.append(", FLAG_ROTATES_WITH_CONTENT"); 291 } 292 if ((flags & FLAG_SECURE) != 0) { 293 msg.append(", FLAG_SECURE"); 294 } 295 if ((flags & FLAG_SUPPORTS_PROTECTED_BUFFERS) != 0) { 296 msg.append(", FLAG_SUPPORTS_PROTECTED_BUFFERS"); 297 } 298 if ((flags & FLAG_PRIVATE) != 0) { 299 msg.append(", FLAG_PRIVATE"); 300 } 301 if ((flags & FLAG_NEVER_BLANK) != 0) { 302 msg.append(", FLAG_NEVER_BLANK"); 303 } 304 if ((flags & FLAG_PRESENTATION) != 0) { 305 msg.append(", FLAG_PRESENTATION"); 306 } 307 if ((flags & FLAG_OWN_CONTENT_ONLY) != 0) { 308 msg.append(", FLAG_OWN_CONTENT_ONLY"); 309 } 310 return msg.toString(); 311 } 312} 313