blob: a6213f3ddd5cef741d7ce22caa49a0d203cb34d2 [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>
chaviw98318de2021-05-19 16:45:23 -050021#include <ftl/NamedEnum.h>
22#include <gui/constants.h>
Dominik Laskowski718f9602019-11-09 20:01:35 -080023#include <input/Input.h>
24
Michael Wrightfe3de7d2020-07-02 19:05:30 +010025#include <cinttypes>
26#include <optional>
27
Siarhei Vishniakoud6343922018-07-06 23:33:37 +010028using android::base::StringPrintf;
29
Santos Cordonfa5cf462017-04-05 10:37:00 -070030namespace android {
31
Dominik Laskowski718f9602019-11-09 20:01:35 -080032enum {
33 DISPLAY_ORIENTATION_0 = 0,
34 DISPLAY_ORIENTATION_90 = 1,
35 DISPLAY_ORIENTATION_180 = 2,
36 DISPLAY_ORIENTATION_270 = 3
37};
38
Siarhei Vishniakoud6343922018-07-06 23:33:37 +010039/**
40 * Describes the different type of viewports supported by input flinger.
41 * Keep in sync with values in InputManagerService.java.
42 */
43enum class ViewportType : int32_t {
Michael Wrightfe3de7d2020-07-02 19:05:30 +010044 INTERNAL = 1,
45 EXTERNAL = 2,
46 VIRTUAL = 3,
Siarhei Vishniakoud6343922018-07-06 23:33:37 +010047};
48
Santos Cordonfa5cf462017-04-05 10:37:00 -070049/*
50 * Describes how coordinates are mapped on a physical display.
51 * See com.android.server.display.DisplayViewport.
52 */
53struct DisplayViewport {
54 int32_t displayId; // -1 if invalid
55 int32_t orientation;
56 int32_t logicalLeft;
57 int32_t logicalTop;
58 int32_t logicalRight;
59 int32_t logicalBottom;
60 int32_t physicalLeft;
61 int32_t physicalTop;
62 int32_t physicalRight;
63 int32_t physicalBottom;
64 int32_t deviceWidth;
65 int32_t deviceHeight;
Chris Ye13b16852020-04-25 10:58:45 -070066 bool isActive;
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +010067 std::string uniqueId;
Siarhei Vishniakou8158e7e2018-10-15 14:28:20 -070068 // The actual (hardware) port that the associated display is connected to.
69 // Not all viewports will have this specified.
70 std::optional<uint8_t> physicalPort;
Siarhei Vishniakoud6343922018-07-06 23:33:37 +010071 ViewportType type;
Santos Cordonfa5cf462017-04-05 10:37:00 -070072
Chris Ye13b16852020-04-25 10:58:45 -070073 DisplayViewport()
74 : displayId(ADISPLAY_ID_NONE),
75 orientation(DISPLAY_ORIENTATION_0),
76 logicalLeft(0),
77 logicalTop(0),
78 logicalRight(0),
79 logicalBottom(0),
80 physicalLeft(0),
81 physicalTop(0),
82 physicalRight(0),
83 physicalBottom(0),
84 deviceWidth(0),
85 deviceHeight(0),
86 isActive(false),
87 uniqueId(),
88 physicalPort(std::nullopt),
Michael Wrightfe3de7d2020-07-02 19:05:30 +010089 type(ViewportType::INTERNAL) {}
Santos Cordonfa5cf462017-04-05 10:37:00 -070090
91 bool operator==(const DisplayViewport& other) const {
Chris Ye13b16852020-04-25 10:58:45 -070092 return displayId == other.displayId && orientation == other.orientation &&
93 logicalLeft == other.logicalLeft && logicalTop == other.logicalTop &&
94 logicalRight == other.logicalRight && logicalBottom == other.logicalBottom &&
95 physicalLeft == other.physicalLeft && physicalTop == other.physicalTop &&
96 physicalRight == other.physicalRight && physicalBottom == other.physicalBottom &&
97 deviceWidth == other.deviceWidth && deviceHeight == other.deviceHeight &&
98 isActive == other.isActive && uniqueId == other.uniqueId &&
99 physicalPort == other.physicalPort && type == other.type;
Santos Cordonfa5cf462017-04-05 10:37:00 -0700100 }
101
102 bool operator!=(const DisplayViewport& other) const {
103 return !(*this == other);
104 }
105
106 inline bool isValid() const {
107 return displayId >= 0;
108 }
109
110 void setNonDisplayViewport(int32_t width, int32_t height) {
111 displayId = ADISPLAY_ID_NONE;
112 orientation = DISPLAY_ORIENTATION_0;
113 logicalLeft = 0;
114 logicalTop = 0;
115 logicalRight = width;
116 logicalBottom = height;
117 physicalLeft = 0;
118 physicalTop = 0;
119 physicalRight = width;
120 physicalBottom = height;
121 deviceWidth = width;
122 deviceHeight = height;
Siarhei Vishniakou6f778462020-12-09 23:39:07 +0000123 isActive = true;
Santos Cordonfa5cf462017-04-05 10:37:00 -0700124 uniqueId.clear();
Siarhei Vishniakou8158e7e2018-10-15 14:28:20 -0700125 physicalPort = std::nullopt;
Michael Wrightfe3de7d2020-07-02 19:05:30 +0100126 type = ViewportType::INTERNAL;
Santos Cordonfa5cf462017-04-05 10:37:00 -0700127 }
Santos Cordonfa5cf462017-04-05 10:37:00 -0700128
Siarhei Vishniakoud6343922018-07-06 23:33:37 +0100129 std::string toString() const {
Siarhei Vishniakou8158e7e2018-10-15 14:28:20 -0700130 return StringPrintf("Viewport %s: displayId=%d, uniqueId=%s, port=%s, orientation=%d, "
Chris Ye13b16852020-04-25 10:58:45 -0700131 "logicalFrame=[%d, %d, %d, %d], "
132 "physicalFrame=[%d, %d, %d, %d], "
133 "deviceSize=[%d, %d], "
134 "isActive=[%d]",
Michael Wrightdde67b82020-10-27 16:09:22 +0000135 NamedEnum::string(type).c_str(), displayId, uniqueId.c_str(),
Chris Ye13b16852020-04-25 10:58:45 -0700136 physicalPort ? StringPrintf("%" PRIu8, *physicalPort).c_str()
137 : "<none>",
138 orientation, logicalLeft, logicalTop, logicalRight, logicalBottom,
139 physicalLeft, physicalTop, physicalRight, physicalBottom, deviceWidth,
140 deviceHeight, isActive);
Siarhei Vishniakoud6343922018-07-06 23:33:37 +0100141 }
Santos Cordonfa5cf462017-04-05 10:37:00 -0700142};
143
144} // namespace android
145
146#endif // _LIBINPUT_DISPLAY_VIEWPORT_H