• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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 #ifndef _LIBINPUT_DISPLAY_VIEWPORT_H
18 #define _LIBINPUT_DISPLAY_VIEWPORT_H
19 
20 #include <android-base/stringprintf.h>
21 #include <input/Input.h>
22 #include <input/NamedEnum.h>
23 
24 #include <cinttypes>
25 #include <optional>
26 
27 using android::base::StringPrintf;
28 
29 namespace android {
30 
31 enum {
32     DISPLAY_ORIENTATION_0 = 0,
33     DISPLAY_ORIENTATION_90 = 1,
34     DISPLAY_ORIENTATION_180 = 2,
35     DISPLAY_ORIENTATION_270 = 3
36 };
37 
38 /**
39  * Describes the different type of viewports supported by input flinger.
40  * Keep in sync with values in InputManagerService.java.
41  */
42 enum class ViewportType : int32_t {
43     INTERNAL = 1,
44     EXTERNAL = 2,
45     VIRTUAL = 3,
46 };
47 
48 /*
49  * Describes how coordinates are mapped on a physical display.
50  * See com.android.server.display.DisplayViewport.
51  */
52 struct DisplayViewport {
53     int32_t displayId; // -1 if invalid
54     int32_t orientation;
55     int32_t logicalLeft;
56     int32_t logicalTop;
57     int32_t logicalRight;
58     int32_t logicalBottom;
59     int32_t physicalLeft;
60     int32_t physicalTop;
61     int32_t physicalRight;
62     int32_t physicalBottom;
63     int32_t deviceWidth;
64     int32_t deviceHeight;
65     bool isActive;
66     std::string uniqueId;
67     // The actual (hardware) port that the associated display is connected to.
68     // Not all viewports will have this specified.
69     std::optional<uint8_t> physicalPort;
70     ViewportType type;
71 
DisplayViewportDisplayViewport72     DisplayViewport()
73           : displayId(ADISPLAY_ID_NONE),
74             orientation(DISPLAY_ORIENTATION_0),
75             logicalLeft(0),
76             logicalTop(0),
77             logicalRight(0),
78             logicalBottom(0),
79             physicalLeft(0),
80             physicalTop(0),
81             physicalRight(0),
82             physicalBottom(0),
83             deviceWidth(0),
84             deviceHeight(0),
85             isActive(false),
86             uniqueId(),
87             physicalPort(std::nullopt),
88             type(ViewportType::INTERNAL) {}
89 
90     bool operator==(const DisplayViewport& other) const {
91         return displayId == other.displayId && orientation == other.orientation &&
92                 logicalLeft == other.logicalLeft && logicalTop == other.logicalTop &&
93                 logicalRight == other.logicalRight && logicalBottom == other.logicalBottom &&
94                 physicalLeft == other.physicalLeft && physicalTop == other.physicalTop &&
95                 physicalRight == other.physicalRight && physicalBottom == other.physicalBottom &&
96                 deviceWidth == other.deviceWidth && deviceHeight == other.deviceHeight &&
97                 isActive == other.isActive && uniqueId == other.uniqueId &&
98                 physicalPort == other.physicalPort && type == other.type;
99     }
100 
101     bool operator!=(const DisplayViewport& other) const {
102         return !(*this == other);
103     }
104 
isValidDisplayViewport105     inline bool isValid() const {
106         return displayId >= 0;
107     }
108 
setNonDisplayViewportDisplayViewport109     void setNonDisplayViewport(int32_t width, int32_t height) {
110         displayId = ADISPLAY_ID_NONE;
111         orientation = DISPLAY_ORIENTATION_0;
112         logicalLeft = 0;
113         logicalTop = 0;
114         logicalRight = width;
115         logicalBottom = height;
116         physicalLeft = 0;
117         physicalTop = 0;
118         physicalRight = width;
119         physicalBottom = height;
120         deviceWidth = width;
121         deviceHeight = height;
122         isActive = true;
123         uniqueId.clear();
124         physicalPort = std::nullopt;
125         type = ViewportType::INTERNAL;
126     }
127 
toStringDisplayViewport128     std::string toString() const {
129         return StringPrintf("Viewport %s: displayId=%d, uniqueId=%s, port=%s, orientation=%d, "
130                             "logicalFrame=[%d, %d, %d, %d], "
131                             "physicalFrame=[%d, %d, %d, %d], "
132                             "deviceSize=[%d, %d], "
133                             "isActive=[%d]",
134                             NamedEnum::string(type).c_str(), displayId, uniqueId.c_str(),
135                             physicalPort ? StringPrintf("%" PRIu8, *physicalPort).c_str()
136                                          : "<none>",
137                             orientation, logicalLeft, logicalTop, logicalRight, logicalBottom,
138                             physicalLeft, physicalTop, physicalRight, physicalBottom, deviceWidth,
139                             deviceHeight, isActive);
140     }
141 };
142 
143 } // namespace android
144 
145 #endif // _LIBINPUT_DISPLAY_VIEWPORT_H
146