blob: 0cec496fa2645d7aead01920b868a44c55e730e8 [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 android.view;
18
19import android.content.res.CompatibilityInfo;
Wale Ogunwale7c726682015-02-06 17:34:28 -080020import android.content.res.Configuration;
Jeff Brownfa25bf52012-07-23 19:26:30 -070021import android.os.Parcel;
22import android.os.Parcelable;
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -070023import android.util.ArraySet;
Jeff Brownfa25bf52012-07-23 19:26:30 -070024import android.util.DisplayMetrics;
25
Jeff Brown4ed8fe72012-08-30 18:18:29 -070026import libcore.util.Objects;
27
Aurimas Liutikas67e2ae82016-10-11 18:17:42 -070028import java.util.Arrays;
29
Jeff Brownfa25bf52012-07-23 19:26:30 -070030/**
31 * Describes the characteristics of a particular logical display.
32 * @hide
33 */
34public final class DisplayInfo implements Parcelable {
35 /**
Jeff Brown4ed8fe72012-08-30 18:18:29 -070036 * The surface flinger layer stack associated with this logical display.
37 */
38 public int layerStack;
39
40 /**
Jeff Brownc5df37c2012-09-13 11:45:07 -070041 * Display flags.
42 */
43 public int flags;
44
45 /**
Jeff Brown92130f62012-10-24 21:28:33 -070046 * 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 Brown4ed8fe72012-08-30 18:18:29 -070057 * The human-readable name of the display.
58 */
59 public String name;
60
61 /**
Wale Ogunwale361ca212014-11-20 11:42:38 -080062 * Unique identifier for the display. Shouldn't be displayed to the user.
63 */
64 public String uniqueId;
65
66 /**
Jeff Brownfa25bf52012-07-23 19:26:30 -070067 * 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 Hackbornc652de82013-02-15 16:32:56 -0800121 * @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 Brownfa25bf52012-07-23 19:26:30 -0700145 * 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 Norbyed9273d62013-05-30 15:59:53 -0700154 @Surface.Rotation
Jeff Brownfa25bf52012-07-23 19:26:30 -0700155 public int rotation;
156
157 /**
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700158 * The active display mode.
Jeff Brownfa25bf52012-07-23 19:26:30 -0700159 */
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700160 public int modeId;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700161
162 /**
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700163 * The default display mode.
Michael Wright3f145a22014-07-22 19:46:03 -0700164 */
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700165 public int defaultModeId;
166
167 /**
168 * The supported modes of this display.
169 */
170 public Display.Mode[] supportedModes = Display.Mode.EMPTY_ARRAY;
Michael Wright3f145a22014-07-22 19:46:03 -0700171
Michael Wright1c9977b2016-07-12 13:30:10 -0700172 /** The active color mode. */
173 public int colorMode;
Michael Wright58e829f2015-09-15 00:13:26 +0100174
Michael Wright1c9977b2016-07-12 13:30:10 -0700175 /** The list of supported color modes */
176 public int[] supportedColorModes = { Display.COLOR_MODE_DEFAULT };
Michael Wright58e829f2015-09-15 00:13:26 +0100177
Michael Wright9ff94c02016-03-30 18:05:40 -0700178 /** The display's HDR capabilities */
179 public Display.HdrCapabilities hdrCapabilities;
180
Michael Wright3f145a22014-07-22 19:46:03 -0700181 /**
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700182 * The logical display density which is the basis for density-independent
183 * pixels.
Jeff Brownfa25bf52012-07-23 19:26:30 -0700184 */
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700185 public int logicalDensityDpi;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700186
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 Browna506a6e2013-06-04 00:02:38 -0700205 /**
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700206 * 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 Brown037c33e2014-04-09 00:31:55 -0700220 * The state of the display, such as {@link android.view.Display#STATE_ON}.
221 */
222 public int state;
223
224 /**
Jeff Browna506a6e2013-06-04 00:02:38 -0700225 * 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 Kulian250d6532017-02-08 23:30:45 -0800241 /**
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 Brownfa25bf52012-07-23 19:26:30 -0700250 public static final Creator<DisplayInfo> CREATOR = new Creator<DisplayInfo>() {
Jeff Brown92130f62012-10-24 21:28:33 -0700251 @Override
Jeff Brownfa25bf52012-07-23 19:26:30 -0700252 public DisplayInfo createFromParcel(Parcel source) {
253 return new DisplayInfo(source);
254 }
255
Jeff Brown92130f62012-10-24 21:28:33 -0700256 @Override
Jeff Brownfa25bf52012-07-23 19:26:30 -0700257 public DisplayInfo[] newArray(int size) {
258 return new DisplayInfo[size];
259 }
260 };
261
262 public DisplayInfo() {
263 }
264
Jeff Brownbd6e1502012-08-28 03:27:37 -0700265 public DisplayInfo(DisplayInfo other) {
266 copyFrom(other);
267 }
268
Jeff Brownfa25bf52012-07-23 19:26:30 -0700269 private DisplayInfo(Parcel source) {
270 readFromParcel(source);
271 }
272
273 @Override
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700274 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 Brown92130f62012-10-24 21:28:33 -0700281 && flags == other.flags
282 && type == other.type
283 && Objects.equal(address, other.address)
Wale Ogunwale361ca212014-11-20 11:42:38 -0800284 && Objects.equal(uniqueId, other.uniqueId)
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700285 && 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 Hackbornc652de82013-02-15 16:32:56 -0800293 && overscanLeft == other.overscanLeft
294 && overscanTop == other.overscanTop
295 && overscanRight == other.overscanRight
296 && overscanBottom == other.overscanBottom
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700297 && rotation == other.rotation
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700298 && modeId == other.modeId
299 && defaultModeId == other.defaultModeId
Michael Wright1c9977b2016-07-12 13:30:10 -0700300 && colorMode == other.colorMode
Michael Wright16ae0422016-07-26 18:18:53 +0100301 && Arrays.equals(supportedColorModes, other.supportedColorModes)
Michael Wright9ff94c02016-03-30 18:05:40 -0700302 && Objects.equal(hdrCapabilities, other.hdrCapabilities)
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700303 && logicalDensityDpi == other.logicalDensityDpi
304 && physicalXDpi == other.physicalXDpi
Jeff Browna506a6e2013-06-04 00:02:38 -0700305 && physicalYDpi == other.physicalYDpi
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700306 && appVsyncOffsetNanos == other.appVsyncOffsetNanos
307 && presentationDeadlineNanos == other.presentationDeadlineNanos
Jeff Brown037c33e2014-04-09 00:31:55 -0700308 && state == other.state
Jeff Browna506a6e2013-06-04 00:02:38 -0700309 && ownerUid == other.ownerUid
Andrii Kulian250d6532017-02-08 23:30:45 -0800310 && Objects.equal(ownerPackageName, other.ownerPackageName)
311 && removeMode == other.removeMode;
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700312 }
313
314 @Override
315 public int hashCode() {
316 return 0; // don't care
Jeff Brownfa25bf52012-07-23 19:26:30 -0700317 }
318
319 public void copyFrom(DisplayInfo other) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700320 layerStack = other.layerStack;
Jeff Brownc5df37c2012-09-13 11:45:07 -0700321 flags = other.flags;
Jeff Brown92130f62012-10-24 21:28:33 -0700322 type = other.type;
323 address = other.address;
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700324 name = other.name;
Wale Ogunwale361ca212014-11-20 11:42:38 -0800325 uniqueId = other.uniqueId;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700326 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 Hackbornc652de82013-02-15 16:32:56 -0800334 overscanLeft = other.overscanLeft;
335 overscanTop = other.overscanTop;
336 overscanRight = other.overscanRight;
337 overscanBottom = other.overscanBottom;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700338 rotation = other.rotation;
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700339 modeId = other.modeId;
340 defaultModeId = other.defaultModeId;
341 supportedModes = Arrays.copyOf(other.supportedModes, other.supportedModes.length);
Michael Wright1c9977b2016-07-12 13:30:10 -0700342 colorMode = other.colorMode;
343 supportedColorModes = Arrays.copyOf(
344 other.supportedColorModes, other.supportedColorModes.length);
Michael Wright9ff94c02016-03-30 18:05:40 -0700345 hdrCapabilities = other.hdrCapabilities;
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700346 logicalDensityDpi = other.logicalDensityDpi;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700347 physicalXDpi = other.physicalXDpi;
348 physicalYDpi = other.physicalYDpi;
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700349 appVsyncOffsetNanos = other.appVsyncOffsetNanos;
350 presentationDeadlineNanos = other.presentationDeadlineNanos;
Jeff Brown037c33e2014-04-09 00:31:55 -0700351 state = other.state;
Jeff Browna506a6e2013-06-04 00:02:38 -0700352 ownerUid = other.ownerUid;
353 ownerPackageName = other.ownerPackageName;
Andrii Kulian250d6532017-02-08 23:30:45 -0800354 removeMode = other.removeMode;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700355 }
356
357 public void readFromParcel(Parcel source) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700358 layerStack = source.readInt();
Jeff Brownc5df37c2012-09-13 11:45:07 -0700359 flags = source.readInt();
Jeff Brown92130f62012-10-24 21:28:33 -0700360 type = source.readInt();
361 address = source.readString();
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700362 name = source.readString();
Jeff Brownfa25bf52012-07-23 19:26:30 -0700363 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 Hackbornc652de82013-02-15 16:32:56 -0800371 overscanLeft = source.readInt();
372 overscanTop = source.readInt();
373 overscanRight = source.readInt();
374 overscanBottom = source.readInt();
Jeff Brownfa25bf52012-07-23 19:26:30 -0700375 rotation = source.readInt();
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700376 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 Wright1c9977b2016-07-12 13:30:10 -0700383 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 Wright58e829f2015-09-15 00:13:26 +0100388 }
Michael Wrightb0828902016-04-27 19:26:16 -0400389 hdrCapabilities = source.readParcelable(null);
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700390 logicalDensityDpi = source.readInt();
Jeff Brownfa25bf52012-07-23 19:26:30 -0700391 physicalXDpi = source.readFloat();
392 physicalYDpi = source.readFloat();
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700393 appVsyncOffsetNanos = source.readLong();
394 presentationDeadlineNanos = source.readLong();
Jeff Brown037c33e2014-04-09 00:31:55 -0700395 state = source.readInt();
Jeff Browna506a6e2013-06-04 00:02:38 -0700396 ownerUid = source.readInt();
397 ownerPackageName = source.readString();
Wale Ogunwale361ca212014-11-20 11:42:38 -0800398 uniqueId = source.readString();
Andrii Kulian250d6532017-02-08 23:30:45 -0800399 removeMode = source.readInt();
Jeff Brownfa25bf52012-07-23 19:26:30 -0700400 }
401
402 @Override
403 public void writeToParcel(Parcel dest, int flags) {
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700404 dest.writeInt(layerStack);
Jeff Brown3f2ba622012-10-04 14:57:44 -0700405 dest.writeInt(this.flags);
Jeff Brown92130f62012-10-24 21:28:33 -0700406 dest.writeInt(type);
407 dest.writeString(address);
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700408 dest.writeString(name);
Jeff Brownfa25bf52012-07-23 19:26:30 -0700409 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 Hackbornc652de82013-02-15 16:32:56 -0800417 dest.writeInt(overscanLeft);
418 dest.writeInt(overscanTop);
419 dest.writeInt(overscanRight);
420 dest.writeInt(overscanBottom);
Jeff Brownfa25bf52012-07-23 19:26:30 -0700421 dest.writeInt(rotation);
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700422 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 Wright1c9977b2016-07-12 13:30:10 -0700428 dest.writeInt(colorMode);
429 dest.writeInt(supportedColorModes.length);
430 for (int i = 0; i < supportedColorModes.length; i++) {
431 dest.writeInt(supportedColorModes[i]);
Michael Wright58e829f2015-09-15 00:13:26 +0100432 }
Michael Wrightb0828902016-04-27 19:26:16 -0400433 dest.writeParcelable(hdrCapabilities, flags);
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700434 dest.writeInt(logicalDensityDpi);
Jeff Brownfa25bf52012-07-23 19:26:30 -0700435 dest.writeFloat(physicalXDpi);
436 dest.writeFloat(physicalYDpi);
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700437 dest.writeLong(appVsyncOffsetNanos);
438 dest.writeLong(presentationDeadlineNanos);
Jeff Brown037c33e2014-04-09 00:31:55 -0700439 dest.writeInt(state);
Jeff Browna506a6e2013-06-04 00:02:38 -0700440 dest.writeInt(ownerUid);
441 dest.writeString(ownerPackageName);
Wale Ogunwale361ca212014-11-20 11:42:38 -0800442 dest.writeString(uniqueId);
Andrii Kulian250d6532017-02-08 23:30:45 -0800443 dest.writeInt(removeMode);
Jeff Brownfa25bf52012-07-23 19:26:30 -0700444 }
445
Jeff Brown4ed8fe72012-08-30 18:18:29 -0700446 @Override
447 public int describeContents() {
448 return 0;
449 }
450
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700451 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 Mautner48d0d182013-06-11 07:53:06 -0700506 public void getAppMetrics(DisplayMetrics outMetrics) {
507 getAppMetrics(outMetrics, CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null);
Jeff Brownfa25bf52012-07-23 19:26:30 -0700508 }
509
Craig Mautner48d0d182013-06-11 07:53:06 -0700510 public void getAppMetrics(DisplayMetrics outMetrics, DisplayAdjustments displayAdjustments) {
511 getMetricsWithSize(outMetrics, displayAdjustments.getCompatibilityInfo(),
Wale Ogunwale7c726682015-02-06 17:34:28 -0800512 displayAdjustments.getConfiguration(), appWidth, appHeight);
Craig Mautner48d0d182013-06-11 07:53:06 -0700513 }
514
Wale Ogunwale7c726682015-02-06 17:34:28 -0800515 public void getAppMetrics(DisplayMetrics outMetrics, CompatibilityInfo ci,
516 Configuration configuration) {
517 getMetricsWithSize(outMetrics, ci, configuration, appWidth, appHeight);
Craig Mautner48d0d182013-06-11 07:53:06 -0700518 }
519
520 public void getLogicalMetrics(DisplayMetrics outMetrics, CompatibilityInfo compatInfo,
Wale Ogunwale7c726682015-02-06 17:34:28 -0800521 Configuration configuration) {
522 getMetricsWithSize(outMetrics, compatInfo, configuration, logicalWidth, logicalHeight);
Jeff Brownfa25bf52012-07-23 19:26:30 -0700523 }
524
Jeff Brown7f3994e2012-12-04 14:04:28 -0800525 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 Guy408afbf2017-01-25 10:23:03 -0800535 public boolean isHdr() {
Andrii Kulian4acfd852017-01-26 19:43:13 -0800536 int[] types = hdrCapabilities != null ? hdrCapabilities.getSupportedHdrTypes() : null;
Romain Guy408afbf2017-01-25 10:23:03 -0800537 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 Browna506a6e2013-06-04 00:02:38 -0700549 /**
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 Mautner48d0d182013-06-11 07:53:06 -0700556 private void getMetricsWithSize(DisplayMetrics outMetrics, CompatibilityInfo compatInfo,
Wale Ogunwale7c726682015-02-06 17:34:28 -0800557 Configuration configuration, int width, int height) {
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700558 outMetrics.densityDpi = outMetrics.noncompatDensityDpi = logicalDensityDpi;
Dianne Hackborn908aecc2012-07-31 16:37:34 -0700559 outMetrics.density = outMetrics.noncompatDensity =
560 logicalDensityDpi * DisplayMetrics.DENSITY_DEFAULT_SCALE;
Jeff Brownfa25bf52012-07-23 19:26:30 -0700561 outMetrics.scaledDensity = outMetrics.noncompatScaledDensity = outMetrics.density;
562 outMetrics.xdpi = outMetrics.noncompatXdpi = physicalXDpi;
563 outMetrics.ydpi = outMetrics.noncompatYdpi = physicalYDpi;
564
Bryce Lee7566d762017-03-30 09:34:15 -0700565 width = configuration != null && configuration.appBounds != null
566 ? configuration.appBounds.width() : width;
567 height = configuration != null && configuration.appBounds != null
568 ? configuration.appBounds.height() : height;
Wale Ogunwale7c726682015-02-06 17:34:28 -0800569
570 outMetrics.noncompatWidthPixels = outMetrics.widthPixels = width;
571 outMetrics.noncompatHeightPixels = outMetrics.heightPixels = height;
572
Craig Mautner48d0d182013-06-11 07:53:06 -0700573 if (!compatInfo.equals(CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO)) {
574 compatInfo.applyToDisplayMetrics(outMetrics);
Jeff Brownfa25bf52012-07-23 19:26:30 -0700575 }
576 }
Jeff Brownbf5740e2012-08-19 23:20:02 -0700577
578 // For debugging purposes
579 @Override
580 public String toString() {
Dianne Hackbornc652de82013-02-15 16:32:56 -0800581 StringBuilder sb = new StringBuilder();
582 sb.append("DisplayInfo{\"");
583 sb.append(name);
Wale Ogunwale361ca212014-11-20 11:42:38 -0800584 sb.append("\", uniqueId \"");
585 sb.append(uniqueId);
Dianne Hackbornc652de82013-02-15 16:32:56 -0800586 sb.append("\", app ");
587 sb.append(appWidth);
588 sb.append(" x ");
589 sb.append(appHeight);
590 sb.append(", real ");
591 sb.append(logicalWidth);
592 sb.append(" x ");
593 sb.append(logicalHeight);
594 if (overscanLeft != 0 || overscanTop != 0 || overscanRight != 0 || overscanBottom != 0) {
595 sb.append(", overscan (");
596 sb.append(overscanLeft);
597 sb.append(",");
598 sb.append(overscanTop);
599 sb.append(",");
600 sb.append(overscanRight);
601 sb.append(",");
602 sb.append(overscanBottom);
603 sb.append(")");
604 }
605 sb.append(", largest app ");
606 sb.append(largestNominalAppWidth);
607 sb.append(" x ");
608 sb.append(largestNominalAppHeight);
609 sb.append(", smallest app ");
610 sb.append(smallestNominalAppWidth);
611 sb.append(" x ");
612 sb.append(smallestNominalAppHeight);
P.Y. Laligandb3b9eb32015-05-11 15:02:07 -0700613 sb.append(", mode ");
614 sb.append(modeId);
615 sb.append(", defaultMode ");
616 sb.append(defaultModeId);
617 sb.append(", modes ");
618 sb.append(Arrays.toString(supportedModes));
Michael Wright1c9977b2016-07-12 13:30:10 -0700619 sb.append(", colorMode ");
620 sb.append(colorMode);
621 sb.append(", supportedColorModes ");
622 sb.append(Arrays.toString(supportedColorModes));
Michael Wright9ff94c02016-03-30 18:05:40 -0700623 sb.append(", hdrCapabilities ");
624 sb.append(hdrCapabilities);
Michael Wright3f145a22014-07-22 19:46:03 -0700625 sb.append(", rotation ");
Dianne Hackbornc652de82013-02-15 16:32:56 -0800626 sb.append(rotation);
627 sb.append(", density ");
628 sb.append(logicalDensityDpi);
629 sb.append(" (");
630 sb.append(physicalXDpi);
631 sb.append(" x ");
632 sb.append(physicalYDpi);
633 sb.append(") dpi, layerStack ");
634 sb.append(layerStack);
Andy McFaddene8b1aeb2014-06-13 14:05:40 -0700635 sb.append(", appVsyncOff ");
636 sb.append(appVsyncOffsetNanos);
637 sb.append(", presDeadline ");
638 sb.append(presentationDeadlineNanos);
Dianne Hackbornc652de82013-02-15 16:32:56 -0800639 sb.append(", type ");
640 sb.append(Display.typeToString(type));
Jeff Browna506a6e2013-06-04 00:02:38 -0700641 if (address != null) {
642 sb.append(", address ").append(address);
643 }
Jeff Brown037c33e2014-04-09 00:31:55 -0700644 sb.append(", state ");
645 sb.append(Display.stateToString(state));
Jeff Browna506a6e2013-06-04 00:02:38 -0700646 if (ownerUid != 0 || ownerPackageName != null) {
647 sb.append(", owner ").append(ownerPackageName);
648 sb.append(" (uid ").append(ownerUid).append(")");
649 }
Dianne Hackbornc652de82013-02-15 16:32:56 -0800650 sb.append(flagsToString(flags));
Andrii Kulian250d6532017-02-08 23:30:45 -0800651 sb.append(", removeMode ");
652 sb.append(removeMode);
Dianne Hackbornc652de82013-02-15 16:32:56 -0800653 sb.append("}");
654 return sb.toString();
Jeff Brownc5df37c2012-09-13 11:45:07 -0700655 }
656
657 private static String flagsToString(int flags) {
658 StringBuilder result = new StringBuilder();
Jeff Brownf0681b32012-10-23 17:35:57 -0700659 if ((flags & Display.FLAG_SECURE) != 0) {
660 result.append(", FLAG_SECURE");
661 }
Jeff Brown77aebfd2012-10-01 21:07:03 -0700662 if ((flags & Display.FLAG_SUPPORTS_PROTECTED_BUFFERS) != 0) {
663 result.append(", FLAG_SUPPORTS_PROTECTED_BUFFERS");
Jeff Brownc5df37c2012-09-13 11:45:07 -0700664 }
Jeff Browna506a6e2013-06-04 00:02:38 -0700665 if ((flags & Display.FLAG_PRIVATE) != 0) {
666 result.append(", FLAG_PRIVATE");
667 }
Jeff Brown7d00aff2013-08-02 19:03:49 -0700668 if ((flags & Display.FLAG_PRESENTATION) != 0) {
669 result.append(", FLAG_PRESENTATION");
670 }
Jeff Brownd46747a2015-04-15 19:02:36 -0700671 if ((flags & Display.FLAG_SCALING_DISABLED) != 0) {
672 result.append(", FLAG_SCALING_DISABLED");
673 }
Adam Powell49e7ff92015-05-14 16:18:53 -0700674 if ((flags & Display.FLAG_ROUND) != 0) {
675 result.append(", FLAG_ROUND");
676 }
Jeff Brownc5df37c2012-09-13 11:45:07 -0700677 return result.toString();
Jeff Brownbf5740e2012-08-19 23:20:02 -0700678 }
Jeff Brownfa25bf52012-07-23 19:26:30 -0700679}