blob: 610062697c3056666c89d509f77e9fc3186ba3d5 [file] [log] [blame]
Santos Cordonfa5cf462017-04-05 10:37:00 -07001/*
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
Dominik Laskowski718f9602019-11-09 20:01:35 -080020#include <cinttypes>
Siarhei Vishniakou8158e7e2018-10-15 14:28:20 -070021#include <optional>
Santos Cordonfa5cf462017-04-05 10:37:00 -070022
Dominik Laskowski718f9602019-11-09 20:01:35 -080023#include <android-base/stringprintf.h>
24#include <input/Input.h>
25
Siarhei Vishniakoud6343922018-07-06 23:33:37 +010026using android::base::StringPrintf;
27
Santos Cordonfa5cf462017-04-05 10:37:00 -070028namespace android {
29
Dominik Laskowski718f9602019-11-09 20:01:35 -080030enum {
31 DISPLAY_ORIENTATION_0 = 0,
32 DISPLAY_ORIENTATION_90 = 1,
33 DISPLAY_ORIENTATION_180 = 2,
34 DISPLAY_ORIENTATION_270 = 3
35};
36
Siarhei Vishniakoud6343922018-07-06 23:33:37 +010037/**
38 * Describes the different type of viewports supported by input flinger.
39 * Keep in sync with values in InputManagerService.java.
40 */
41enum class ViewportType : int32_t {
42 VIEWPORT_INTERNAL = 1,
43 VIEWPORT_EXTERNAL = 2,
44 VIEWPORT_VIRTUAL = 3,
45};
46
47static const char* viewportTypeToString(ViewportType type) {
48 switch(type) {
49 case ViewportType::VIEWPORT_INTERNAL:
50 return "INTERNAL";
51 case ViewportType::VIEWPORT_EXTERNAL:
52 return "EXTERNAL";
53 case ViewportType::VIEWPORT_VIRTUAL:
54 return "VIRTUAL";
55 default:
56 return "UNKNOWN";
57 }
58}
59
Santos Cordonfa5cf462017-04-05 10:37:00 -070060/*
61 * Describes how coordinates are mapped on a physical display.
62 * See com.android.server.display.DisplayViewport.
63 */
64struct DisplayViewport {
65 int32_t displayId; // -1 if invalid
66 int32_t orientation;
67 int32_t logicalLeft;
68 int32_t logicalTop;
69 int32_t logicalRight;
70 int32_t logicalBottom;
71 int32_t physicalLeft;
72 int32_t physicalTop;
73 int32_t physicalRight;
74 int32_t physicalBottom;
75 int32_t deviceWidth;
76 int32_t deviceHeight;
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +010077 std::string uniqueId;
Siarhei Vishniakou8158e7e2018-10-15 14:28:20 -070078 // The actual (hardware) port that the associated display is connected to.
79 // Not all viewports will have this specified.
80 std::optional<uint8_t> physicalPort;
Siarhei Vishniakoud6343922018-07-06 23:33:37 +010081 ViewportType type;
Santos Cordonfa5cf462017-04-05 10:37:00 -070082
83 DisplayViewport() :
84 displayId(ADISPLAY_ID_NONE), orientation(DISPLAY_ORIENTATION_0),
85 logicalLeft(0), logicalTop(0), logicalRight(0), logicalBottom(0),
86 physicalLeft(0), physicalTop(0), physicalRight(0), physicalBottom(0),
Siarhei Vishniakou8158e7e2018-10-15 14:28:20 -070087 deviceWidth(0), deviceHeight(0), uniqueId(), physicalPort(std::nullopt),
88 type(ViewportType::VIEWPORT_INTERNAL) {
Santos Cordonfa5cf462017-04-05 10:37:00 -070089 }
90
91 bool operator==(const DisplayViewport& other) const {
92 return displayId == other.displayId
93 && orientation == other.orientation
94 && logicalLeft == other.logicalLeft
95 && logicalTop == other.logicalTop
96 && logicalRight == other.logicalRight
97 && logicalBottom == other.logicalBottom
98 && physicalLeft == other.physicalLeft
99 && physicalTop == other.physicalTop
100 && physicalRight == other.physicalRight
101 && physicalBottom == other.physicalBottom
102 && deviceWidth == other.deviceWidth
103 && deviceHeight == other.deviceHeight
Siarhei Vishniakoud6343922018-07-06 23:33:37 +0100104 && uniqueId == other.uniqueId
Siarhei Vishniakou8158e7e2018-10-15 14:28:20 -0700105 && physicalPort == other.physicalPort
Siarhei Vishniakoud6343922018-07-06 23:33:37 +0100106 && type == other.type;
Santos Cordonfa5cf462017-04-05 10:37:00 -0700107 }
108
109 bool operator!=(const DisplayViewport& other) const {
110 return !(*this == other);
111 }
112
113 inline bool isValid() const {
114 return displayId >= 0;
115 }
116
117 void setNonDisplayViewport(int32_t width, int32_t height) {
118 displayId = ADISPLAY_ID_NONE;
119 orientation = DISPLAY_ORIENTATION_0;
120 logicalLeft = 0;
121 logicalTop = 0;
122 logicalRight = width;
123 logicalBottom = height;
124 physicalLeft = 0;
125 physicalTop = 0;
126 physicalRight = width;
127 physicalBottom = height;
128 deviceWidth = width;
129 deviceHeight = height;
130 uniqueId.clear();
Siarhei Vishniakou8158e7e2018-10-15 14:28:20 -0700131 physicalPort = std::nullopt;
Siarhei Vishniakoud6343922018-07-06 23:33:37 +0100132 type = ViewportType::VIEWPORT_INTERNAL;
Santos Cordonfa5cf462017-04-05 10:37:00 -0700133 }
Santos Cordonfa5cf462017-04-05 10:37:00 -0700134
Siarhei Vishniakoud6343922018-07-06 23:33:37 +0100135 std::string toString() const {
Siarhei Vishniakou8158e7e2018-10-15 14:28:20 -0700136 return StringPrintf("Viewport %s: displayId=%d, uniqueId=%s, port=%s, orientation=%d, "
Siarhei Vishniakoud6343922018-07-06 23:33:37 +0100137 "logicalFrame=[%d, %d, %d, %d], "
138 "physicalFrame=[%d, %d, %d, %d], "
139 "deviceSize=[%d, %d]",
Siarhei Vishniakou8158e7e2018-10-15 14:28:20 -0700140 viewportTypeToString(type), displayId,
141 uniqueId.c_str(),
142 physicalPort ? StringPrintf("%" PRIu8, *physicalPort).c_str() : "<none>",
143 orientation,
Siarhei Vishniakoud6343922018-07-06 23:33:37 +0100144 logicalLeft, logicalTop,
145 logicalRight, logicalBottom,
146 physicalLeft, physicalTop,
147 physicalRight, physicalBottom,
148 deviceWidth, deviceHeight);
149 }
Santos Cordonfa5cf462017-04-05 10:37:00 -0700150};
151
152} // namespace android
153
154#endif // _LIBINPUT_DISPLAY_VIEWPORT_H