blob: b90d57eb2563d526442ed3af8692e94e22e090ff [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 <android-base/stringprintf.h>
21#include <input/Input.h>
Michael Wrightdde67b82020-10-27 16:09:22 +000022#include <input/NamedEnum.h>
Dominik Laskowski718f9602019-11-09 20:01:35 -080023
Michael Wrightfe3de7d2020-07-02 19:05:30 +010024#include <cinttypes>
25#include <optional>
26
Siarhei Vishniakoud6343922018-07-06 23:33:37 +010027using android::base::StringPrintf;
28
Santos Cordonfa5cf462017-04-05 10:37:00 -070029namespace android {
30
Dominik Laskowski718f9602019-11-09 20:01:35 -080031enum {
32 DISPLAY_ORIENTATION_0 = 0,
33 DISPLAY_ORIENTATION_90 = 1,
34 DISPLAY_ORIENTATION_180 = 2,
35 DISPLAY_ORIENTATION_270 = 3
36};
37
Siarhei Vishniakoud6343922018-07-06 23:33:37 +010038/**
39 * Describes the different type of viewports supported by input flinger.
40 * Keep in sync with values in InputManagerService.java.
41 */
42enum class ViewportType : int32_t {
Michael Wrightfe3de7d2020-07-02 19:05:30 +010043 INTERNAL = 1,
44 EXTERNAL = 2,
45 VIRTUAL = 3,
Siarhei Vishniakoud6343922018-07-06 23:33:37 +010046};
47
Santos Cordonfa5cf462017-04-05 10:37:00 -070048/*
49 * Describes how coordinates are mapped on a physical display.
50 * See com.android.server.display.DisplayViewport.
51 */
52struct 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;
Chris Ye13b16852020-04-25 10:58:45 -070065 bool isActive;
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +010066 std::string uniqueId;
Siarhei Vishniakou8158e7e2018-10-15 14:28:20 -070067 // 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;
Siarhei Vishniakoud6343922018-07-06 23:33:37 +010070 ViewportType type;
Santos Cordonfa5cf462017-04-05 10:37:00 -070071
Chris Ye13b16852020-04-25 10:58:45 -070072 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),
Michael Wrightfe3de7d2020-07-02 19:05:30 +010088 type(ViewportType::INTERNAL) {}
Santos Cordonfa5cf462017-04-05 10:37:00 -070089
90 bool operator==(const DisplayViewport& other) const {
Chris Ye13b16852020-04-25 10:58:45 -070091 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;
Santos Cordonfa5cf462017-04-05 10:37:00 -070099 }
100
101 bool operator!=(const DisplayViewport& other) const {
102 return !(*this == other);
103 }
104
105 inline bool isValid() const {
106 return displayId >= 0;
107 }
108
109 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;
Chris Ye13b16852020-04-25 10:58:45 -0700122 isActive = false;
Santos Cordonfa5cf462017-04-05 10:37:00 -0700123 uniqueId.clear();
Siarhei Vishniakou8158e7e2018-10-15 14:28:20 -0700124 physicalPort = std::nullopt;
Michael Wrightfe3de7d2020-07-02 19:05:30 +0100125 type = ViewportType::INTERNAL;
Santos Cordonfa5cf462017-04-05 10:37:00 -0700126 }
Santos Cordonfa5cf462017-04-05 10:37:00 -0700127
Siarhei Vishniakoud6343922018-07-06 23:33:37 +0100128 std::string toString() const {
Siarhei Vishniakou8158e7e2018-10-15 14:28:20 -0700129 return StringPrintf("Viewport %s: displayId=%d, uniqueId=%s, port=%s, orientation=%d, "
Chris Ye13b16852020-04-25 10:58:45 -0700130 "logicalFrame=[%d, %d, %d, %d], "
131 "physicalFrame=[%d, %d, %d, %d], "
132 "deviceSize=[%d, %d], "
133 "isActive=[%d]",
Michael Wrightdde67b82020-10-27 16:09:22 +0000134 NamedEnum::string(type).c_str(), displayId, uniqueId.c_str(),
Chris Ye13b16852020-04-25 10:58:45 -0700135 physicalPort ? StringPrintf("%" PRIu8, *physicalPort).c_str()
136 : "<none>",
137 orientation, logicalLeft, logicalTop, logicalRight, logicalBottom,
138 physicalLeft, physicalTop, physicalRight, physicalBottom, deviceWidth,
139 deviceHeight, isActive);
Siarhei Vishniakoud6343922018-07-06 23:33:37 +0100140 }
Santos Cordonfa5cf462017-04-05 10:37:00 -0700141};
142
143} // namespace android
144
145#endif // _LIBINPUT_DISPLAY_VIEWPORT_H