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 // The logical display id. 53 public int displayId; 54 55 // The rotation applied to the physical coordinate system. 56 public int orientation; 57 58 // The portion of the logical display that are presented on this physical display. 59 public final Rect logicalFrame = new Rect(); 60 61 // The portion of the (rotated) physical display that shows the logical display contents. 62 // The relation between logical and physical frame defines how the coordinate system 63 // should be scaled or translated after rotation. 64 public final Rect physicalFrame = new Rect(); 65 66 // The full width and height of the display device, rotated in the same 67 // manner as physicalFrame. This expresses the full native size of the display device. 68 // The physical frame should usually fit within this area. 69 public int deviceWidth; 70 public int deviceHeight; 71 72 // The ID used to uniquely identify this display. 73 public String uniqueId; 74 75 // The physical port that the associated display device is connected to. 76 public @Nullable Byte physicalPort; 77 78 public @ViewportType int type; 79 copyFrom(DisplayViewport viewport)80 public void copyFrom(DisplayViewport viewport) { 81 valid = viewport.valid; 82 displayId = viewport.displayId; 83 orientation = viewport.orientation; 84 logicalFrame.set(viewport.logicalFrame); 85 physicalFrame.set(viewport.physicalFrame); 86 deviceWidth = viewport.deviceWidth; 87 deviceHeight = viewport.deviceHeight; 88 uniqueId = viewport.uniqueId; 89 physicalPort = viewport.physicalPort; 90 type = viewport.type; 91 } 92 93 /** 94 * Creates a copy of this DisplayViewport. 95 */ makeCopy()96 public DisplayViewport makeCopy() { 97 DisplayViewport dv = new DisplayViewport(); 98 dv.copyFrom(this); 99 return dv; 100 } 101 102 @Override equals(Object o)103 public boolean equals(Object o) { 104 if (o == this) { 105 return true; 106 } 107 108 if (!(o instanceof DisplayViewport)) { 109 return false; 110 } 111 112 DisplayViewport other = (DisplayViewport) o; 113 return valid == other.valid 114 && displayId == other.displayId 115 && orientation == other.orientation 116 && logicalFrame.equals(other.logicalFrame) 117 && physicalFrame.equals(other.physicalFrame) 118 && deviceWidth == other.deviceWidth 119 && deviceHeight == other.deviceHeight 120 && TextUtils.equals(uniqueId, other.uniqueId) 121 && physicalPort == other.physicalPort 122 && type == other.type; 123 } 124 125 @Override hashCode()126 public int hashCode() { 127 final int prime = 31; 128 int result = 1; 129 result += prime * result + (valid ? 1 : 0); 130 result += prime * result + displayId; 131 result += prime * result + orientation; 132 result += prime * result + logicalFrame.hashCode(); 133 result += prime * result + physicalFrame.hashCode(); 134 result += prime * result + deviceWidth; 135 result += prime * result + deviceHeight; 136 result += prime * result + uniqueId.hashCode(); 137 result += prime * result + physicalPort; 138 result += prime * result + type; 139 return result; 140 } 141 142 // For debugging purposes. 143 @Override toString()144 public String toString() { 145 return "DisplayViewport{type=" + typeToString(type) 146 + ", valid=" + valid 147 + ", displayId=" + displayId 148 + ", uniqueId='" + uniqueId + "'" 149 + ", physicalPort=" + physicalPort 150 + ", orientation=" + orientation 151 + ", logicalFrame=" + logicalFrame 152 + ", physicalFrame=" + physicalFrame 153 + ", deviceWidth=" + deviceWidth 154 + ", deviceHeight=" + deviceHeight 155 + "}"; 156 } 157 158 /** 159 * Human-readable viewport type. 160 */ typeToString(@iewportType int viewportType)161 public static String typeToString(@ViewportType int viewportType) { 162 switch (viewportType) { 163 case VIEWPORT_INTERNAL: 164 return "INTERNAL"; 165 case VIEWPORT_EXTERNAL: 166 return "EXTERNAL"; 167 case VIEWPORT_VIRTUAL: 168 return "VIRTUAL"; 169 default: 170 return "UNKNOWN (" + viewportType + ")"; 171 } 172 } 173 } 174