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 android.view; |
| 18 | |
| 19 | import android.content.res.CompatibilityInfo; |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 20 | import android.content.res.Configuration; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 21 | import android.os.Parcel; |
| 22 | import android.os.Parcelable; |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 23 | import android.util.ArraySet; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 24 | import android.util.DisplayMetrics; |
| 25 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 26 | import libcore.util.Objects; |
| 27 | |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 28 | import java.util.Arrays; |
| 29 | |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 30 | /** |
| 31 | * Describes the characteristics of a particular logical display. |
| 32 | * @hide |
| 33 | */ |
| 34 | public final class DisplayInfo implements Parcelable { |
| 35 | /** |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 36 | * The surface flinger layer stack associated with this logical display. |
| 37 | */ |
| 38 | public int layerStack; |
| 39 | |
| 40 | /** |
Jeff Brown | c5df37c | 2012-09-13 11:45:07 -0700 | [diff] [blame] | 41 | * Display flags. |
| 42 | */ |
| 43 | public int flags; |
| 44 | |
| 45 | /** |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 46 | * Display type. |
| 47 | */ |
| 48 | public int type; |
| 49 | |
| 50 | /** |
| 51 | * Display address, or null if none. |
| 52 | * Interpretation varies by display type. |
| 53 | */ |
| 54 | public String address; |
| 55 | |
| 56 | /** |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 57 | * The human-readable name of the display. |
| 58 | */ |
| 59 | public String name; |
| 60 | |
| 61 | /** |
Wale Ogunwale | 361ca21 | 2014-11-20 11:42:38 -0800 | [diff] [blame] | 62 | * Unique identifier for the display. Shouldn't be displayed to the user. |
| 63 | */ |
| 64 | public String uniqueId; |
| 65 | |
| 66 | /** |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 67 | * The width of the portion of the display that is available to applications, in pixels. |
| 68 | * Represents the size of the display minus any system decorations. |
| 69 | */ |
| 70 | public int appWidth; |
| 71 | |
| 72 | /** |
| 73 | * The height of the portion of the display that is available to applications, in pixels. |
| 74 | * Represents the size of the display minus any system decorations. |
| 75 | */ |
| 76 | public int appHeight; |
| 77 | |
| 78 | /** |
| 79 | * The smallest value of {@link #appWidth} that an application is likely to encounter, |
| 80 | * in pixels, excepting cases where the width may be even smaller due to the presence |
| 81 | * of a soft keyboard, for example. |
| 82 | */ |
| 83 | public int smallestNominalAppWidth; |
| 84 | |
| 85 | /** |
| 86 | * The smallest value of {@link #appHeight} that an application is likely to encounter, |
| 87 | * in pixels, excepting cases where the height may be even smaller due to the presence |
| 88 | * of a soft keyboard, for example. |
| 89 | */ |
| 90 | public int smallestNominalAppHeight; |
| 91 | |
| 92 | /** |
| 93 | * The largest value of {@link #appWidth} that an application is likely to encounter, |
| 94 | * in pixels, excepting cases where the width may be even larger due to system decorations |
| 95 | * such as the status bar being hidden, for example. |
| 96 | */ |
| 97 | public int largestNominalAppWidth; |
| 98 | |
| 99 | /** |
| 100 | * The largest value of {@link #appHeight} that an application is likely to encounter, |
| 101 | * in pixels, excepting cases where the height may be even larger due to system decorations |
| 102 | * such as the status bar being hidden, for example. |
| 103 | */ |
| 104 | public int largestNominalAppHeight; |
| 105 | |
| 106 | /** |
| 107 | * The logical width of the display, in pixels. |
| 108 | * Represents the usable size of the display which may be smaller than the |
| 109 | * physical size when the system is emulating a smaller display. |
| 110 | */ |
| 111 | public int logicalWidth; |
| 112 | |
| 113 | /** |
| 114 | * The logical height of the display, in pixels. |
| 115 | * Represents the usable size of the display which may be smaller than the |
| 116 | * physical size when the system is emulating a smaller display. |
| 117 | */ |
| 118 | public int logicalHeight; |
| 119 | |
| 120 | /** |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 121 | * @hide |
| 122 | * Number of overscan pixels on the left side of the display. |
| 123 | */ |
| 124 | public int overscanLeft; |
| 125 | |
| 126 | /** |
| 127 | * @hide |
| 128 | * Number of overscan pixels on the top side of the display. |
| 129 | */ |
| 130 | public int overscanTop; |
| 131 | |
| 132 | /** |
| 133 | * @hide |
| 134 | * Number of overscan pixels on the right side of the display. |
| 135 | */ |
| 136 | public int overscanRight; |
| 137 | |
| 138 | /** |
| 139 | * @hide |
| 140 | * Number of overscan pixels on the bottom side of the display. |
| 141 | */ |
| 142 | public int overscanBottom; |
| 143 | |
| 144 | /** |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 145 | * The rotation of the display relative to its natural orientation. |
| 146 | * May be one of {@link android.view.Surface#ROTATION_0}, |
| 147 | * {@link android.view.Surface#ROTATION_90}, {@link android.view.Surface#ROTATION_180}, |
| 148 | * {@link android.view.Surface#ROTATION_270}. |
| 149 | * <p> |
| 150 | * The value of this field is indeterminate if the logical display is presented on |
| 151 | * more than one physical display. |
| 152 | * </p> |
| 153 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 154 | @Surface.Rotation |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 155 | public int rotation; |
| 156 | |
| 157 | /** |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 158 | * The active display mode. |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 159 | */ |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 160 | public int modeId; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 161 | |
| 162 | /** |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 163 | * The default display mode. |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 164 | */ |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 165 | public int defaultModeId; |
| 166 | |
| 167 | /** |
| 168 | * The supported modes of this display. |
| 169 | */ |
| 170 | public Display.Mode[] supportedModes = Display.Mode.EMPTY_ARRAY; |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 171 | |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 172 | /** The active color mode. */ |
| 173 | public int colorMode; |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 174 | |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 175 | /** The list of supported color modes */ |
| 176 | public int[] supportedColorModes = { Display.COLOR_MODE_DEFAULT }; |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 177 | |
Michael Wright | 9ff94c0 | 2016-03-30 18:05:40 -0700 | [diff] [blame] | 178 | /** The display's HDR capabilities */ |
| 179 | public Display.HdrCapabilities hdrCapabilities; |
| 180 | |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 181 | /** |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 182 | * The logical display density which is the basis for density-independent |
| 183 | * pixels. |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 184 | */ |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 185 | public int logicalDensityDpi; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 186 | |
| 187 | /** |
| 188 | * The exact physical pixels per inch of the screen in the X dimension. |
| 189 | * <p> |
| 190 | * The value of this field is indeterminate if the logical display is presented on |
| 191 | * more than one physical display. |
| 192 | * </p> |
| 193 | */ |
| 194 | public float physicalXDpi; |
| 195 | |
| 196 | /** |
| 197 | * The exact physical pixels per inch of the screen in the Y dimension. |
| 198 | * <p> |
| 199 | * The value of this field is indeterminate if the logical display is presented on |
| 200 | * more than one physical display. |
| 201 | * </p> |
| 202 | */ |
| 203 | public float physicalYDpi; |
| 204 | |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 205 | /** |
Andy McFadden | e8b1aeb | 2014-06-13 14:05:40 -0700 | [diff] [blame] | 206 | * This is a positive value indicating the phase offset of the VSYNC events provided by |
| 207 | * Choreographer relative to the display refresh. For example, if Choreographer reports |
| 208 | * that the refresh occurred at time N, it actually occurred at (N - appVsyncOffsetNanos). |
| 209 | */ |
| 210 | public long appVsyncOffsetNanos; |
| 211 | |
| 212 | /** |
| 213 | * This is how far in advance a buffer must be queued for presentation at |
| 214 | * a given time. If you want a buffer to appear on the screen at |
| 215 | * time N, you must submit the buffer before (N - bufferDeadlineNanos). |
| 216 | */ |
| 217 | public long presentationDeadlineNanos; |
| 218 | |
| 219 | /** |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 220 | * The state of the display, such as {@link android.view.Display#STATE_ON}. |
| 221 | */ |
| 222 | public int state; |
| 223 | |
| 224 | /** |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 225 | * The UID of the application that owns this display, or zero if it is owned by the system. |
| 226 | * <p> |
| 227 | * If the display is private, then only the owner can use it. |
| 228 | * </p> |
| 229 | */ |
| 230 | public int ownerUid; |
| 231 | |
| 232 | /** |
| 233 | * The package name of the application that owns this display, or null if it is |
| 234 | * owned by the system. |
| 235 | * <p> |
| 236 | * If the display is private, then only the owner can use it. |
| 237 | * </p> |
| 238 | */ |
| 239 | public String ownerPackageName; |
| 240 | |
Andrii Kulian | 250d653 | 2017-02-08 23:30:45 -0800 | [diff] [blame] | 241 | /** |
| 242 | * @hide |
| 243 | * Get current remove mode of the display - what actions should be performed with the display's |
| 244 | * content when it is removed. |
| 245 | * |
| 246 | * @see Display#getRemoveMode() |
| 247 | */ |
| 248 | public int removeMode = Display.REMOVE_MODE_MOVE_CONTENT_TO_PRIMARY; |
| 249 | |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 250 | public static final Creator<DisplayInfo> CREATOR = new Creator<DisplayInfo>() { |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 251 | @Override |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 252 | public DisplayInfo createFromParcel(Parcel source) { |
| 253 | return new DisplayInfo(source); |
| 254 | } |
| 255 | |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 256 | @Override |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 257 | public DisplayInfo[] newArray(int size) { |
| 258 | return new DisplayInfo[size]; |
| 259 | } |
| 260 | }; |
| 261 | |
| 262 | public DisplayInfo() { |
| 263 | } |
| 264 | |
Jeff Brown | bd6e150 | 2012-08-28 03:27:37 -0700 | [diff] [blame] | 265 | public DisplayInfo(DisplayInfo other) { |
| 266 | copyFrom(other); |
| 267 | } |
| 268 | |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 269 | private DisplayInfo(Parcel source) { |
| 270 | readFromParcel(source); |
| 271 | } |
| 272 | |
| 273 | @Override |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 274 | public boolean equals(Object o) { |
| 275 | return o instanceof DisplayInfo && equals((DisplayInfo)o); |
| 276 | } |
| 277 | |
| 278 | public boolean equals(DisplayInfo other) { |
| 279 | return other != null |
| 280 | && layerStack == other.layerStack |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 281 | && flags == other.flags |
| 282 | && type == other.type |
| 283 | && Objects.equal(address, other.address) |
Wale Ogunwale | 361ca21 | 2014-11-20 11:42:38 -0800 | [diff] [blame] | 284 | && Objects.equal(uniqueId, other.uniqueId) |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 285 | && appWidth == other.appWidth |
| 286 | && appHeight == other.appHeight |
| 287 | && smallestNominalAppWidth == other.smallestNominalAppWidth |
| 288 | && smallestNominalAppHeight == other.smallestNominalAppHeight |
| 289 | && largestNominalAppWidth == other.largestNominalAppWidth |
| 290 | && largestNominalAppHeight == other.largestNominalAppHeight |
| 291 | && logicalWidth == other.logicalWidth |
| 292 | && logicalHeight == other.logicalHeight |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 293 | && overscanLeft == other.overscanLeft |
| 294 | && overscanTop == other.overscanTop |
| 295 | && overscanRight == other.overscanRight |
| 296 | && overscanBottom == other.overscanBottom |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 297 | && rotation == other.rotation |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 298 | && modeId == other.modeId |
| 299 | && defaultModeId == other.defaultModeId |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 300 | && colorMode == other.colorMode |
Michael Wright | 16ae042 | 2016-07-26 18:18:53 +0100 | [diff] [blame] | 301 | && Arrays.equals(supportedColorModes, other.supportedColorModes) |
Michael Wright | 9ff94c0 | 2016-03-30 18:05:40 -0700 | [diff] [blame] | 302 | && Objects.equal(hdrCapabilities, other.hdrCapabilities) |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 303 | && logicalDensityDpi == other.logicalDensityDpi |
| 304 | && physicalXDpi == other.physicalXDpi |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 305 | && physicalYDpi == other.physicalYDpi |
Andy McFadden | e8b1aeb | 2014-06-13 14:05:40 -0700 | [diff] [blame] | 306 | && appVsyncOffsetNanos == other.appVsyncOffsetNanos |
| 307 | && presentationDeadlineNanos == other.presentationDeadlineNanos |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 308 | && state == other.state |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 309 | && ownerUid == other.ownerUid |
Andrii Kulian | 250d653 | 2017-02-08 23:30:45 -0800 | [diff] [blame] | 310 | && Objects.equal(ownerPackageName, other.ownerPackageName) |
| 311 | && removeMode == other.removeMode; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | @Override |
| 315 | public int hashCode() { |
| 316 | return 0; // don't care |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | public void copyFrom(DisplayInfo other) { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 320 | layerStack = other.layerStack; |
Jeff Brown | c5df37c | 2012-09-13 11:45:07 -0700 | [diff] [blame] | 321 | flags = other.flags; |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 322 | type = other.type; |
| 323 | address = other.address; |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 324 | name = other.name; |
Wale Ogunwale | 361ca21 | 2014-11-20 11:42:38 -0800 | [diff] [blame] | 325 | uniqueId = other.uniqueId; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 326 | appWidth = other.appWidth; |
| 327 | appHeight = other.appHeight; |
| 328 | smallestNominalAppWidth = other.smallestNominalAppWidth; |
| 329 | smallestNominalAppHeight = other.smallestNominalAppHeight; |
| 330 | largestNominalAppWidth = other.largestNominalAppWidth; |
| 331 | largestNominalAppHeight = other.largestNominalAppHeight; |
| 332 | logicalWidth = other.logicalWidth; |
| 333 | logicalHeight = other.logicalHeight; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 334 | overscanLeft = other.overscanLeft; |
| 335 | overscanTop = other.overscanTop; |
| 336 | overscanRight = other.overscanRight; |
| 337 | overscanBottom = other.overscanBottom; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 338 | rotation = other.rotation; |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 339 | modeId = other.modeId; |
| 340 | defaultModeId = other.defaultModeId; |
| 341 | supportedModes = Arrays.copyOf(other.supportedModes, other.supportedModes.length); |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 342 | colorMode = other.colorMode; |
| 343 | supportedColorModes = Arrays.copyOf( |
| 344 | other.supportedColorModes, other.supportedColorModes.length); |
Michael Wright | 9ff94c0 | 2016-03-30 18:05:40 -0700 | [diff] [blame] | 345 | hdrCapabilities = other.hdrCapabilities; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 346 | logicalDensityDpi = other.logicalDensityDpi; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 347 | physicalXDpi = other.physicalXDpi; |
| 348 | physicalYDpi = other.physicalYDpi; |
Andy McFadden | e8b1aeb | 2014-06-13 14:05:40 -0700 | [diff] [blame] | 349 | appVsyncOffsetNanos = other.appVsyncOffsetNanos; |
| 350 | presentationDeadlineNanos = other.presentationDeadlineNanos; |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 351 | state = other.state; |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 352 | ownerUid = other.ownerUid; |
| 353 | ownerPackageName = other.ownerPackageName; |
Andrii Kulian | 250d653 | 2017-02-08 23:30:45 -0800 | [diff] [blame] | 354 | removeMode = other.removeMode; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | public void readFromParcel(Parcel source) { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 358 | layerStack = source.readInt(); |
Jeff Brown | c5df37c | 2012-09-13 11:45:07 -0700 | [diff] [blame] | 359 | flags = source.readInt(); |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 360 | type = source.readInt(); |
| 361 | address = source.readString(); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 362 | name = source.readString(); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 363 | appWidth = source.readInt(); |
| 364 | appHeight = source.readInt(); |
| 365 | smallestNominalAppWidth = source.readInt(); |
| 366 | smallestNominalAppHeight = source.readInt(); |
| 367 | largestNominalAppWidth = source.readInt(); |
| 368 | largestNominalAppHeight = source.readInt(); |
| 369 | logicalWidth = source.readInt(); |
| 370 | logicalHeight = source.readInt(); |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 371 | overscanLeft = source.readInt(); |
| 372 | overscanTop = source.readInt(); |
| 373 | overscanRight = source.readInt(); |
| 374 | overscanBottom = source.readInt(); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 375 | rotation = source.readInt(); |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 376 | modeId = source.readInt(); |
| 377 | defaultModeId = source.readInt(); |
| 378 | int nModes = source.readInt(); |
| 379 | supportedModes = new Display.Mode[nModes]; |
| 380 | for (int i = 0; i < nModes; i++) { |
| 381 | supportedModes[i] = Display.Mode.CREATOR.createFromParcel(source); |
| 382 | } |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 383 | colorMode = source.readInt(); |
| 384 | int nColorModes = source.readInt(); |
| 385 | supportedColorModes = new int[nColorModes]; |
| 386 | for (int i = 0; i < nColorModes; i++) { |
| 387 | supportedColorModes[i] = source.readInt(); |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 388 | } |
Michael Wright | b082890 | 2016-04-27 19:26:16 -0400 | [diff] [blame] | 389 | hdrCapabilities = source.readParcelable(null); |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 390 | logicalDensityDpi = source.readInt(); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 391 | physicalXDpi = source.readFloat(); |
| 392 | physicalYDpi = source.readFloat(); |
Andy McFadden | e8b1aeb | 2014-06-13 14:05:40 -0700 | [diff] [blame] | 393 | appVsyncOffsetNanos = source.readLong(); |
| 394 | presentationDeadlineNanos = source.readLong(); |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 395 | state = source.readInt(); |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 396 | ownerUid = source.readInt(); |
| 397 | ownerPackageName = source.readString(); |
Wale Ogunwale | 361ca21 | 2014-11-20 11:42:38 -0800 | [diff] [blame] | 398 | uniqueId = source.readString(); |
Andrii Kulian | 250d653 | 2017-02-08 23:30:45 -0800 | [diff] [blame] | 399 | removeMode = source.readInt(); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | @Override |
| 403 | public void writeToParcel(Parcel dest, int flags) { |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 404 | dest.writeInt(layerStack); |
Jeff Brown | 3f2ba62 | 2012-10-04 14:57:44 -0700 | [diff] [blame] | 405 | dest.writeInt(this.flags); |
Jeff Brown | 92130f6 | 2012-10-24 21:28:33 -0700 | [diff] [blame] | 406 | dest.writeInt(type); |
| 407 | dest.writeString(address); |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 408 | dest.writeString(name); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 409 | dest.writeInt(appWidth); |
| 410 | dest.writeInt(appHeight); |
| 411 | dest.writeInt(smallestNominalAppWidth); |
| 412 | dest.writeInt(smallestNominalAppHeight); |
| 413 | dest.writeInt(largestNominalAppWidth); |
| 414 | dest.writeInt(largestNominalAppHeight); |
| 415 | dest.writeInt(logicalWidth); |
| 416 | dest.writeInt(logicalHeight); |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 417 | dest.writeInt(overscanLeft); |
| 418 | dest.writeInt(overscanTop); |
| 419 | dest.writeInt(overscanRight); |
| 420 | dest.writeInt(overscanBottom); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 421 | dest.writeInt(rotation); |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 422 | dest.writeInt(modeId); |
| 423 | dest.writeInt(defaultModeId); |
| 424 | dest.writeInt(supportedModes.length); |
| 425 | for (int i = 0; i < supportedModes.length; i++) { |
| 426 | supportedModes[i].writeToParcel(dest, flags); |
| 427 | } |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 428 | dest.writeInt(colorMode); |
| 429 | dest.writeInt(supportedColorModes.length); |
| 430 | for (int i = 0; i < supportedColorModes.length; i++) { |
| 431 | dest.writeInt(supportedColorModes[i]); |
Michael Wright | 58e829f | 2015-09-15 00:13:26 +0100 | [diff] [blame] | 432 | } |
Michael Wright | b082890 | 2016-04-27 19:26:16 -0400 | [diff] [blame] | 433 | dest.writeParcelable(hdrCapabilities, flags); |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 434 | dest.writeInt(logicalDensityDpi); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 435 | dest.writeFloat(physicalXDpi); |
| 436 | dest.writeFloat(physicalYDpi); |
Andy McFadden | e8b1aeb | 2014-06-13 14:05:40 -0700 | [diff] [blame] | 437 | dest.writeLong(appVsyncOffsetNanos); |
| 438 | dest.writeLong(presentationDeadlineNanos); |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 439 | dest.writeInt(state); |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 440 | dest.writeInt(ownerUid); |
| 441 | dest.writeString(ownerPackageName); |
Wale Ogunwale | 361ca21 | 2014-11-20 11:42:38 -0800 | [diff] [blame] | 442 | dest.writeString(uniqueId); |
Andrii Kulian | 250d653 | 2017-02-08 23:30:45 -0800 | [diff] [blame] | 443 | dest.writeInt(removeMode); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 444 | } |
| 445 | |
Jeff Brown | 4ed8fe7 | 2012-08-30 18:18:29 -0700 | [diff] [blame] | 446 | @Override |
| 447 | public int describeContents() { |
| 448 | return 0; |
| 449 | } |
| 450 | |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 451 | public Display.Mode getMode() { |
| 452 | return findMode(modeId); |
| 453 | } |
| 454 | |
| 455 | public Display.Mode getDefaultMode() { |
| 456 | return findMode(defaultModeId); |
| 457 | } |
| 458 | |
| 459 | private Display.Mode findMode(int id) { |
| 460 | for (int i = 0; i < supportedModes.length; i++) { |
| 461 | if (supportedModes[i].getModeId() == id) { |
| 462 | return supportedModes[i]; |
| 463 | } |
| 464 | } |
| 465 | throw new IllegalStateException("Unable to locate mode " + id); |
| 466 | } |
| 467 | |
| 468 | /** |
| 469 | * Returns the id of the "default" mode with the given refresh rate, or {@code 0} if no suitable |
| 470 | * mode could be found. |
| 471 | */ |
| 472 | public int findDefaultModeByRefreshRate(float refreshRate) { |
| 473 | Display.Mode[] modes = supportedModes; |
| 474 | Display.Mode defaultMode = getDefaultMode(); |
| 475 | for (int i = 0; i < modes.length; i++) { |
| 476 | if (modes[i].matches( |
| 477 | defaultMode.getPhysicalWidth(), defaultMode.getPhysicalHeight(), refreshRate)) { |
| 478 | return modes[i].getModeId(); |
| 479 | } |
| 480 | } |
| 481 | return 0; |
| 482 | } |
| 483 | |
| 484 | /** |
| 485 | * Returns the list of supported refresh rates in the default mode. |
| 486 | */ |
| 487 | public float[] getDefaultRefreshRates() { |
| 488 | Display.Mode[] modes = supportedModes; |
| 489 | ArraySet<Float> rates = new ArraySet<>(); |
| 490 | Display.Mode defaultMode = getDefaultMode(); |
| 491 | for (int i = 0; i < modes.length; i++) { |
| 492 | Display.Mode mode = modes[i]; |
| 493 | if (mode.getPhysicalWidth() == defaultMode.getPhysicalWidth() |
| 494 | && mode.getPhysicalHeight() == defaultMode.getPhysicalHeight()) { |
| 495 | rates.add(mode.getRefreshRate()); |
| 496 | } |
| 497 | } |
| 498 | float[] result = new float[rates.size()]; |
| 499 | int i = 0; |
| 500 | for (Float rate : rates) { |
| 501 | result[i++] = rate; |
| 502 | } |
| 503 | return result; |
| 504 | } |
| 505 | |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 506 | public void getAppMetrics(DisplayMetrics outMetrics) { |
| 507 | getAppMetrics(outMetrics, CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 508 | } |
| 509 | |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 510 | public void getAppMetrics(DisplayMetrics outMetrics, DisplayAdjustments displayAdjustments) { |
| 511 | getMetricsWithSize(outMetrics, displayAdjustments.getCompatibilityInfo(), |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 512 | displayAdjustments.getConfiguration(), appWidth, appHeight); |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 513 | } |
| 514 | |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 515 | public void getAppMetrics(DisplayMetrics outMetrics, CompatibilityInfo ci, |
| 516 | Configuration configuration) { |
| 517 | getMetricsWithSize(outMetrics, ci, configuration, appWidth, appHeight); |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | public void getLogicalMetrics(DisplayMetrics outMetrics, CompatibilityInfo compatInfo, |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 521 | Configuration configuration) { |
| 522 | getMetricsWithSize(outMetrics, compatInfo, configuration, logicalWidth, logicalHeight); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 523 | } |
| 524 | |
Jeff Brown | 7f3994e | 2012-12-04 14:04:28 -0800 | [diff] [blame] | 525 | public int getNaturalWidth() { |
| 526 | return rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180 ? |
| 527 | logicalWidth : logicalHeight; |
| 528 | } |
| 529 | |
| 530 | public int getNaturalHeight() { |
| 531 | return rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180 ? |
| 532 | logicalHeight : logicalWidth; |
| 533 | } |
| 534 | |
Romain Guy | 408afbf | 2017-01-25 10:23:03 -0800 | [diff] [blame] | 535 | public boolean isHdr() { |
Andrii Kulian | 4acfd85 | 2017-01-26 19:43:13 -0800 | [diff] [blame] | 536 | int[] types = hdrCapabilities != null ? hdrCapabilities.getSupportedHdrTypes() : null; |
Romain Guy | 408afbf | 2017-01-25 10:23:03 -0800 | [diff] [blame] | 537 | return types != null && types.length > 0; |
| 538 | } |
| 539 | |
| 540 | public boolean isWideColorGamut() { |
| 541 | for (int colorMode : supportedColorModes) { |
| 542 | if (colorMode == Display.COLOR_MODE_DCI_P3 || colorMode > Display.COLOR_MODE_SRGB) { |
| 543 | return true; |
| 544 | } |
| 545 | } |
| 546 | return false; |
| 547 | } |
| 548 | |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 549 | /** |
| 550 | * Returns true if the specified UID has access to this display. |
| 551 | */ |
| 552 | public boolean hasAccess(int uid) { |
| 553 | return Display.hasAccess(uid, flags, ownerUid); |
| 554 | } |
| 555 | |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 556 | private void getMetricsWithSize(DisplayMetrics outMetrics, CompatibilityInfo compatInfo, |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 557 | Configuration configuration, int width, int height) { |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 558 | outMetrics.densityDpi = outMetrics.noncompatDensityDpi = logicalDensityDpi; |
Dianne Hackborn | 908aecc | 2012-07-31 16:37:34 -0700 | [diff] [blame] | 559 | outMetrics.density = outMetrics.noncompatDensity = |
| 560 | logicalDensityDpi * DisplayMetrics.DENSITY_DEFAULT_SCALE; |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 561 | outMetrics.scaledDensity = outMetrics.noncompatScaledDensity = outMetrics.density; |
| 562 | outMetrics.xdpi = outMetrics.noncompatXdpi = physicalXDpi; |
| 563 | outMetrics.ydpi = outMetrics.noncompatYdpi = physicalYDpi; |
| 564 | |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 565 | width = (configuration != null |
| 566 | && configuration.screenWidthDp != Configuration.SCREEN_WIDTH_DP_UNDEFINED) |
| 567 | ? (int)((configuration.screenWidthDp * outMetrics.density) + 0.5f) : width; |
| 568 | height = (configuration != null |
| 569 | && configuration.screenHeightDp != Configuration.SCREEN_HEIGHT_DP_UNDEFINED) |
| 570 | ? (int)((configuration.screenHeightDp * outMetrics.density) + 0.5f) : height; |
| 571 | |
| 572 | outMetrics.noncompatWidthPixels = outMetrics.widthPixels = width; |
| 573 | outMetrics.noncompatHeightPixels = outMetrics.heightPixels = height; |
| 574 | |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 575 | if (!compatInfo.equals(CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO)) { |
| 576 | compatInfo.applyToDisplayMetrics(outMetrics); |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 577 | } |
| 578 | } |
Jeff Brown | bf5740e | 2012-08-19 23:20:02 -0700 | [diff] [blame] | 579 | |
| 580 | // For debugging purposes |
| 581 | @Override |
| 582 | public String toString() { |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 583 | StringBuilder sb = new StringBuilder(); |
| 584 | sb.append("DisplayInfo{\""); |
| 585 | sb.append(name); |
Wale Ogunwale | 361ca21 | 2014-11-20 11:42:38 -0800 | [diff] [blame] | 586 | sb.append("\", uniqueId \""); |
| 587 | sb.append(uniqueId); |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 588 | sb.append("\", app "); |
| 589 | sb.append(appWidth); |
| 590 | sb.append(" x "); |
| 591 | sb.append(appHeight); |
| 592 | sb.append(", real "); |
| 593 | sb.append(logicalWidth); |
| 594 | sb.append(" x "); |
| 595 | sb.append(logicalHeight); |
| 596 | if (overscanLeft != 0 || overscanTop != 0 || overscanRight != 0 || overscanBottom != 0) { |
| 597 | sb.append(", overscan ("); |
| 598 | sb.append(overscanLeft); |
| 599 | sb.append(","); |
| 600 | sb.append(overscanTop); |
| 601 | sb.append(","); |
| 602 | sb.append(overscanRight); |
| 603 | sb.append(","); |
| 604 | sb.append(overscanBottom); |
| 605 | sb.append(")"); |
| 606 | } |
| 607 | sb.append(", largest app "); |
| 608 | sb.append(largestNominalAppWidth); |
| 609 | sb.append(" x "); |
| 610 | sb.append(largestNominalAppHeight); |
| 611 | sb.append(", smallest app "); |
| 612 | sb.append(smallestNominalAppWidth); |
| 613 | sb.append(" x "); |
| 614 | sb.append(smallestNominalAppHeight); |
P.Y. Laligand | b3b9eb3 | 2015-05-11 15:02:07 -0700 | [diff] [blame] | 615 | sb.append(", mode "); |
| 616 | sb.append(modeId); |
| 617 | sb.append(", defaultMode "); |
| 618 | sb.append(defaultModeId); |
| 619 | sb.append(", modes "); |
| 620 | sb.append(Arrays.toString(supportedModes)); |
Michael Wright | 1c9977b | 2016-07-12 13:30:10 -0700 | [diff] [blame] | 621 | sb.append(", colorMode "); |
| 622 | sb.append(colorMode); |
| 623 | sb.append(", supportedColorModes "); |
| 624 | sb.append(Arrays.toString(supportedColorModes)); |
Michael Wright | 9ff94c0 | 2016-03-30 18:05:40 -0700 | [diff] [blame] | 625 | sb.append(", hdrCapabilities "); |
| 626 | sb.append(hdrCapabilities); |
Michael Wright | 3f145a2 | 2014-07-22 19:46:03 -0700 | [diff] [blame] | 627 | sb.append(", rotation "); |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 628 | sb.append(rotation); |
| 629 | sb.append(", density "); |
| 630 | sb.append(logicalDensityDpi); |
| 631 | sb.append(" ("); |
| 632 | sb.append(physicalXDpi); |
| 633 | sb.append(" x "); |
| 634 | sb.append(physicalYDpi); |
| 635 | sb.append(") dpi, layerStack "); |
| 636 | sb.append(layerStack); |
Andy McFadden | e8b1aeb | 2014-06-13 14:05:40 -0700 | [diff] [blame] | 637 | sb.append(", appVsyncOff "); |
| 638 | sb.append(appVsyncOffsetNanos); |
| 639 | sb.append(", presDeadline "); |
| 640 | sb.append(presentationDeadlineNanos); |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 641 | sb.append(", type "); |
| 642 | sb.append(Display.typeToString(type)); |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 643 | if (address != null) { |
| 644 | sb.append(", address ").append(address); |
| 645 | } |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 646 | sb.append(", state "); |
| 647 | sb.append(Display.stateToString(state)); |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 648 | if (ownerUid != 0 || ownerPackageName != null) { |
| 649 | sb.append(", owner ").append(ownerPackageName); |
| 650 | sb.append(" (uid ").append(ownerUid).append(")"); |
| 651 | } |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 652 | sb.append(flagsToString(flags)); |
Andrii Kulian | 250d653 | 2017-02-08 23:30:45 -0800 | [diff] [blame] | 653 | sb.append(", removeMode "); |
| 654 | sb.append(removeMode); |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 655 | sb.append("}"); |
| 656 | return sb.toString(); |
Jeff Brown | c5df37c | 2012-09-13 11:45:07 -0700 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | private static String flagsToString(int flags) { |
| 660 | StringBuilder result = new StringBuilder(); |
Jeff Brown | f0681b3 | 2012-10-23 17:35:57 -0700 | [diff] [blame] | 661 | if ((flags & Display.FLAG_SECURE) != 0) { |
| 662 | result.append(", FLAG_SECURE"); |
| 663 | } |
Jeff Brown | 77aebfd | 2012-10-01 21:07:03 -0700 | [diff] [blame] | 664 | if ((flags & Display.FLAG_SUPPORTS_PROTECTED_BUFFERS) != 0) { |
| 665 | result.append(", FLAG_SUPPORTS_PROTECTED_BUFFERS"); |
Jeff Brown | c5df37c | 2012-09-13 11:45:07 -0700 | [diff] [blame] | 666 | } |
Jeff Brown | a506a6e | 2013-06-04 00:02:38 -0700 | [diff] [blame] | 667 | if ((flags & Display.FLAG_PRIVATE) != 0) { |
| 668 | result.append(", FLAG_PRIVATE"); |
| 669 | } |
Jeff Brown | 7d00aff | 2013-08-02 19:03:49 -0700 | [diff] [blame] | 670 | if ((flags & Display.FLAG_PRESENTATION) != 0) { |
| 671 | result.append(", FLAG_PRESENTATION"); |
| 672 | } |
Jeff Brown | d46747a | 2015-04-15 19:02:36 -0700 | [diff] [blame] | 673 | if ((flags & Display.FLAG_SCALING_DISABLED) != 0) { |
| 674 | result.append(", FLAG_SCALING_DISABLED"); |
| 675 | } |
Adam Powell | 49e7ff9 | 2015-05-14 16:18:53 -0700 | [diff] [blame] | 676 | if ((flags & Display.FLAG_ROUND) != 0) { |
| 677 | result.append(", FLAG_ROUND"); |
| 678 | } |
Jeff Brown | c5df37c | 2012-09-13 11:45:07 -0700 | [diff] [blame] | 679 | return result.toString(); |
Jeff Brown | bf5740e | 2012-08-19 23:20:02 -0700 | [diff] [blame] | 680 | } |
Jeff Brown | fa25bf5 | 2012-07-23 19:26:30 -0700 | [diff] [blame] | 681 | } |