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