DisplayDeviceInfo.java revision 4ed8fe75e1dde1a2b9576f3862aecc5a572c56b5
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 libcore.util.Objects;
20
21/**
22 * Describes the characteristics of a physical display device.
23 */
24final class DisplayDeviceInfo {
25    /**
26     * Flag: Indicates that this display device should be considered the default display
27     * device of the system.
28     */
29    public static final int FLAG_DEFAULT_DISPLAY = 1 << 0;
30
31    /**
32     * Flag: Indicates that this display device can show secure surfaces.
33     */
34    public static final int FLAG_SECURE = 1 << 1;
35
36    /**
37     * Flag: Indicates that this display device can rotate to show contents in a
38     * different orientation.  Otherwise the rotation is assumed to be fixed in the
39     * natural orientation and the display manager should transform the content to fit.
40     */
41    public static final int FLAG_SUPPORTS_ROTATION = 1 << 2;
42
43    /**
44     * Gets the name of the display device, which may be derived from
45     * EDID or other sources.  The name may be displayed to the user.
46     */
47    public String name;
48
49    /**
50     * The width of the display in its natural orientation, in pixels.
51     * This value is not affected by display rotation.
52     */
53    public int width;
54
55    /**
56     * The height of the display in its natural orientation, in pixels.
57     * This value is not affected by display rotation.
58     */
59    public int height;
60
61    public float refreshRate;
62    public int densityDpi;
63    public float xDpi;
64    public float yDpi;
65
66    public int flags;
67
68    @Override
69    public boolean equals(Object o) {
70        return o instanceof DisplayDeviceInfo && equals((DisplayDeviceInfo)o);
71    }
72
73    public boolean equals(DisplayDeviceInfo other) {
74        return other != null
75                && Objects.equal(name, other.name)
76                && width == other.width
77                && height == other.height
78                && refreshRate == other.refreshRate
79                && densityDpi == other.densityDpi
80                && xDpi == other.xDpi
81                && yDpi == other.yDpi
82                && flags == other.flags;
83    }
84
85    @Override
86    public int hashCode() {
87        return 0; // don't care
88    }
89
90    public void copyFrom(DisplayDeviceInfo other) {
91        name = other.name;
92        width = other.width;
93        height = other.height;
94        refreshRate = other.refreshRate;
95        densityDpi = other.densityDpi;
96        xDpi = other.xDpi;
97        yDpi = other.yDpi;
98        flags = other.flags;
99    }
100
101    // For debugging purposes
102    @Override
103    public String toString() {
104        return "DisplayDeviceInfo{\"" + name + "\": " + width + " x " + height + ", " + refreshRate + " fps, "
105                + "density " + densityDpi + ", " + xDpi + " x " + yDpi + " dpi"
106                + flagsToString(flags) + "}";
107    }
108
109    private static String flagsToString(int flags) {
110        StringBuilder msg = new StringBuilder();
111        if ((flags & FLAG_DEFAULT_DISPLAY) != 0) {
112            msg.append(", FLAG_DEFAULT_DISPLAY");
113        }
114        if ((flags & FLAG_SECURE) != 0) {
115            msg.append(", FLAG_SECURE");
116        }
117        return msg.toString();
118    }
119}
120