Debian Codegraph @

core/java/android/hardware/display/DisplayViewport.java

raw symbols SCIP
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.hardware.display;
18
19 import static java.lang.annotation.RetentionPolicy.SOURCE;
20
21 import android.annotation.IntDef;
22 import android.annotation.Nullable;
23 import android.graphics.Rect;
24 import android.text.TextUtils;
25
26 import java.lang.annotation.Retention;
27 import java.util.Objects;
28
29 /**
30 * Describes how the pixels of physical display device reflects the content of
31 * a logical display.
32 * <p>
33 * This information is used by the input system to translate touch input from
34 * physical display coordinates into logical display coordinates.
35 * </p>
36 *
37 * @hide Only for use within the system server.
38 */
39 public final class DisplayViewport {
40
41 // Viewport constants defined in InputReader.h.
42 public static final int VIEWPORT_INTERNAL = 1;
43 public static final int VIEWPORT_EXTERNAL = 2;
44 public static final int VIEWPORT_VIRTUAL = 3;
45 @IntDef(prefix = { "VIEWPORT_" }, value = {
46 VIEWPORT_INTERNAL, VIEWPORT_EXTERNAL, VIEWPORT_VIRTUAL})
47 @Retention(SOURCE)
48 public @interface ViewportType {};
49
50 // True if this viewport is valid.
51 public boolean valid;
52
53 // True if this viewport is active.
54 public boolean isActive;
55
56 // The logical display id.
57 public int displayId;
58
59 // The rotation applied to the physical coordinate system.
60 public int orientation;
61
62 // The portion of the logical display that are presented on this physical display.
63 public final Rect logicalFrame = new Rect();
64
65 // The portion of the (rotated) physical display that shows the logical display contents.
66 // The relation between logical and physical frame defines how the coordinate system
67 // should be scaled or translated after rotation.
68 public final Rect physicalFrame = new Rect();
69
70 // The full width and height of the display device, rotated in the same
71 // manner as physicalFrame. This expresses the full native size of the display device.
72 // The physical frame should usually fit within this area.
73 public int deviceWidth;
74 public int deviceHeight;
75
76 // The ID used to uniquely identify this display.
77 public String uniqueId;
78
79 // The physical port that the associated display device is connected to.
80 public @Nullable Integer physicalPort;
81
82 public @ViewportType int type;
83
84 public void copyFrom(DisplayViewport viewport) {
85 valid = viewport.valid;
86 isActive = viewport.isActive;
87 displayId = viewport.displayId;
88 orientation = viewport.orientation;
89 logicalFrame.set(viewport.logicalFrame);
90 physicalFrame.set(viewport.physicalFrame);
91 deviceWidth = viewport.deviceWidth;
92 deviceHeight = viewport.deviceHeight;
93 uniqueId = viewport.uniqueId;
94 physicalPort = viewport.physicalPort;
95 type = viewport.type;
96 }
97
98 /**
99 * Creates a copy of this DisplayViewport.
100 */
101 public DisplayViewport makeCopy() {
102 DisplayViewport dv = new DisplayViewport();
103 dv.copyFrom(this);
104 return dv;
105 }
106
107 @Override
108 public boolean equals(@Nullable Object o) {
109 if (o == this) {
110 return true;
111 }
112
113 if (!(o instanceof DisplayViewport)) {
114 return false;
115 }
116
117 DisplayViewport other = (DisplayViewport) o;
118 return valid == other.valid
119 && isActive == other.isActive
120 && displayId == other.displayId
121 && orientation == other.orientation
122 && logicalFrame.equals(other.logicalFrame)
123 && physicalFrame.equals(other.physicalFrame)
124 && deviceWidth == other.deviceWidth
125 && deviceHeight == other.deviceHeight
126 && TextUtils.equals(uniqueId, other.uniqueId)
127 && Objects.equals(physicalPort, other.physicalPort)
128 && type == other.type;
129 }
130
131 @Override
132 public int hashCode() {
133 final int prime = 31;
134 int result = 1;
135 result += prime * result + (valid ? 1 : 0);
136 result += prime * result + (isActive ? 1 : 0);
137 result += prime * result + displayId;
138 result += prime * result + orientation;
139 result += prime * result + logicalFrame.hashCode();
140 result += prime * result + physicalFrame.hashCode();
141 result += prime * result + deviceWidth;
142 result += prime * result + deviceHeight;
143 result += prime * result + uniqueId.hashCode();
144 if (physicalPort != null) {
145 result += prime * result + physicalPort.hashCode();
146 }
147 result += prime * result + type;
148 return result;
149 }
150
151 // For debugging purposes.
152 @Override
153 public String toString() {
154 return "DisplayViewport{type=" + typeToString(type)
155 + ", valid=" + valid
156 + ", isActive=" + isActive
157 + ", displayId=" + displayId
158 + ", uniqueId='" + uniqueId + "'"
159 + ", physicalPort=" + physicalPort
160 + ", orientation=" + orientation
161 + ", logicalFrame=" + logicalFrame
162 + ", physicalFrame=" + physicalFrame
163 + ", deviceWidth=" + deviceWidth
164 + ", deviceHeight=" + deviceHeight
165 + "}";
166 }
167
168 /**
169 * Human-readable viewport type.
170 */
171 public static String typeToString(@ViewportType int viewportType) {
172 switch (viewportType) {
173 case VIEWPORT_INTERNAL:
174 return "INTERNAL";
175 case VIEWPORT_EXTERNAL:
176 return "EXTERNAL";
177 case VIEWPORT_VIRTUAL:
178 return "VIRTUAL";
179 default:
180 return "UNKNOWN (" + viewportType + ")";
181 }
182 }
183 }