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 android.graphics.Rect; 20 import android.text.TextUtils; 21 22 /** 23 * Describes how the pixels of physical display device reflects the content of 24 * a logical display. 25 * <p> 26 * This information is used by the input system to translate touch input from 27 * physical display coordinates into logical display coordinates. 28 * </p> 29 * 30 * @hide Only for use within the system server. 31 */ 32 public final class DisplayViewport { 33 // True if this viewport is valid. 34 public boolean valid; 35 36 // The logical display id. 37 public int displayId; 38 39 // The rotation applied to the physical coordinate system. 40 public int orientation; 41 42 // The portion of the logical display that are presented on this physical display. 43 public final Rect logicalFrame = new Rect(); 44 45 // The portion of the (rotated) physical display that shows the logical display contents. 46 // The relation between logical and physical frame defines how the coordinate system 47 // should be scaled or translated after rotation. 48 public final Rect physicalFrame = new Rect(); 49 50 // The full width and height of the display device, rotated in the same 51 // manner as physicalFrame. This expresses the full native size of the display device. 52 // The physical frame should usually fit within this area. 53 public int deviceWidth; 54 public int deviceHeight; 55 56 // The ID used to uniquely identify this display. 57 public String uniqueId; 58 copyFrom(DisplayViewport viewport)59 public void copyFrom(DisplayViewport viewport) { 60 valid = viewport.valid; 61 displayId = viewport.displayId; 62 orientation = viewport.orientation; 63 logicalFrame.set(viewport.logicalFrame); 64 physicalFrame.set(viewport.physicalFrame); 65 deviceWidth = viewport.deviceWidth; 66 deviceHeight = viewport.deviceHeight; 67 uniqueId = viewport.uniqueId; 68 } 69 makeCopy()70 public DisplayViewport makeCopy() { 71 DisplayViewport dv = new DisplayViewport(); 72 dv.copyFrom(this); 73 return dv; 74 } 75 76 @Override equals(Object o)77 public boolean equals(Object o) { 78 if (o == this) { 79 return true; 80 } 81 82 if (!(o instanceof DisplayViewport)) { 83 return false; 84 } 85 86 DisplayViewport other = (DisplayViewport) o; 87 return valid == other.valid && 88 displayId == other.displayId && 89 orientation == other.orientation && 90 logicalFrame.equals(other.logicalFrame) && 91 physicalFrame.equals(other.physicalFrame) && 92 deviceWidth == other.deviceWidth && 93 deviceHeight == other.deviceHeight && 94 TextUtils.equals(uniqueId, other.uniqueId); 95 } 96 97 @Override hashCode()98 public int hashCode() { 99 final int prime = 31; 100 int result = 1; 101 result += prime * result + (valid ? 1 : 0); 102 result += prime * result + displayId; 103 result += prime * result + orientation; 104 result += prime * result + logicalFrame.hashCode(); 105 result += prime * result + physicalFrame.hashCode(); 106 result += prime * result + deviceWidth; 107 result += prime * result + deviceHeight; 108 result += prime * result + uniqueId.hashCode(); 109 return result; 110 } 111 112 // For debugging purposes. 113 @Override toString()114 public String toString() { 115 return "DisplayViewport{valid=" + valid 116 + ", displayId=" + displayId 117 + ", uniqueId='" + uniqueId + "'" 118 + ", orientation=" + orientation 119 + ", logicalFrame=" + logicalFrame 120 + ", physicalFrame=" + physicalFrame 121 + ", deviceWidth=" + deviceWidth 122 + ", deviceHeight=" + deviceHeight 123 + "}"; 124 } 125 } 126