1d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown/*
2d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown * Copyright (C) 2012 The Android Open Source Project
3d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown *
4d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown * Licensed under the Apache License, Version 2.0 (the "License");
5d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown * you may not use this file except in compliance with the License.
6d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown * You may obtain a copy of the License at
7d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown *
8d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown *      http://www.apache.org/licenses/LICENSE-2.0
9d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown *
10d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown * Unless required by applicable law or agreed to in writing, software
11d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown * distributed under the License is distributed on an "AS IS" BASIS,
12d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown * See the License for the specific language governing permissions and
14d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown * limitations under the License.
15d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown */
16d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown
17d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brownpackage com.android.server.display;
18d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown
19d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brownimport android.graphics.Rect;
20d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown
21d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown/**
22d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown * Describes how the pixels of physical display device reflects the content of
23d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown * a logical display.
24d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown * <p>
25d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown * This information is used by the input system to translate touch input from
26d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown * physical display coordinates into logical display coordinates.
27d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown * </p>
28d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown */
29d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brownpublic final class DisplayViewport {
30d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown    // True if this viewport is valid.
31d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown    public boolean valid;
32d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown
33d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown    // The logical display id.
34d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown    public int displayId;
35d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown
36d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown    // The rotation applied to the physical coordinate system.
37d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown    public int orientation;
38d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown
39d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown    // The portion of the logical display that are presented on this physical display.
40d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown    public final Rect logicalFrame = new Rect();
41d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown
42d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown    // The portion of the (rotated) physical display that shows the logical display contents.
43d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown    // The relation between logical and physical frame defines how the coordinate system
44d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown    // should be scaled or translated after rotation.
45d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown    public final Rect physicalFrame = new Rect();
46d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown
4783d616a9c7b9505153d258511eb5c16b552e268dJeff Brown    // The full width and height of the display device, rotated in the same
4883d616a9c7b9505153d258511eb5c16b552e268dJeff Brown    // manner as physicalFrame.  This expresses the full native size of the display device.
4983d616a9c7b9505153d258511eb5c16b552e268dJeff Brown    // The physical frame should usually fit within this area.
5083d616a9c7b9505153d258511eb5c16b552e268dJeff Brown    public int deviceWidth;
5183d616a9c7b9505153d258511eb5c16b552e268dJeff Brown    public int deviceHeight;
5283d616a9c7b9505153d258511eb5c16b552e268dJeff Brown
53d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown    public void copyFrom(DisplayViewport viewport) {
54d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown        valid = viewport.valid;
55d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown        displayId = viewport.displayId;
56d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown        orientation = viewport.orientation;
57d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown        logicalFrame.set(viewport.logicalFrame);
58d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown        physicalFrame.set(viewport.physicalFrame);
5983d616a9c7b9505153d258511eb5c16b552e268dJeff Brown        deviceWidth = viewport.deviceWidth;
6083d616a9c7b9505153d258511eb5c16b552e268dJeff Brown        deviceHeight = viewport.deviceHeight;
61d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown    }
62d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown
63d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown    // For debugging purposes.
64d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown    @Override
65d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown    public String toString() {
66d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown        return "DisplayViewport{valid=" + valid
67d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown                + ", displayId=" + displayId
68d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown                + ", orientation=" + orientation
69d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown                + ", logicalFrame=" + logicalFrame
70d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown                + ", physicalFrame=" + physicalFrame
7183d616a9c7b9505153d258511eb5c16b552e268dJeff Brown                + ", deviceWidth=" + deviceWidth
7283d616a9c7b9505153d258511eb5c16b552e268dJeff Brown                + ", deviceHeight=" + deviceHeight
73d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown                + "}";
74d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown    }
75d728bf514f257670fcb9aa22c6eaf97626072c93Jeff Brown}
76