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 70 /** 71 * Creates a copy of this DisplayViewport. 72 */ makeCopy()73 public DisplayViewport makeCopy() { 74 DisplayViewport dv = new DisplayViewport(); 75 dv.copyFrom(this); 76 return dv; 77 } 78 79 @Override equals(Object o)80 public boolean equals(Object o) { 81 if (o == this) { 82 return true; 83 } 84 85 if (!(o instanceof DisplayViewport)) { 86 return false; 87 } 88 89 DisplayViewport other = (DisplayViewport) o; 90 return valid == other.valid 91 && displayId == other.displayId 92 && orientation == other.orientation 93 && logicalFrame.equals(other.logicalFrame) 94 && physicalFrame.equals(other.physicalFrame) 95 && deviceWidth == other.deviceWidth 96 && deviceHeight == other.deviceHeight 97 && TextUtils.equals(uniqueId, other.uniqueId); 98 } 99 100 @Override hashCode()101 public int hashCode() { 102 final int prime = 31; 103 int result = 1; 104 result += prime * result + (valid ? 1 : 0); 105 result += prime * result + displayId; 106 result += prime * result + orientation; 107 result += prime * result + logicalFrame.hashCode(); 108 result += prime * result + physicalFrame.hashCode(); 109 result += prime * result + deviceWidth; 110 result += prime * result + deviceHeight; 111 result += prime * result + uniqueId.hashCode(); 112 return result; 113 } 114 115 // For debugging purposes. 116 @Override toString()117 public String toString() { 118 return "DisplayViewport{valid=" + valid 119 + ", displayId=" + displayId 120 + ", uniqueId='" + uniqueId + "'" 121 + ", orientation=" + orientation 122 + ", logicalFrame=" + logicalFrame 123 + ", physicalFrame=" + physicalFrame 124 + ", deviceWidth=" + deviceWidth 125 + ", deviceHeight=" + deviceHeight 126 + "}"; 127 } 128 } 129