blob: 9148fee53233e3569a0af7c44857d94e2a125d1b [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>
Dominik Laskowski75788452021-02-09 18:51:25 -080021#include <ftl/enum.h>
22#include <ftl/string.h>
chaviw98318de2021-05-19 16:45:23 -050023#include <gui/constants.h>
Dominik Laskowski718f9602019-11-09 20:01:35 -080024#include <input/Input.h>
25
Michael Wrightfe3de7d2020-07-02 19:05:30 +010026#include <cinttypes>
27#include <optional>
28
Siarhei Vishniakoud6343922018-07-06 23:33:37 +010029using android::base::StringPrintf;
30
Santos Cordonfa5cf462017-04-05 10:37:00 -070031namespace android {
32
Dominik Laskowski718f9602019-11-09 20:01:35 -080033enum {
34 DISPLAY_ORIENTATION_0 = 0,
35 DISPLAY_ORIENTATION_90 = 1,
36 DISPLAY_ORIENTATION_180 = 2,
37 DISPLAY_ORIENTATION_270 = 3
38};
39
Siarhei Vishniakoud6343922018-07-06 23:33:37 +010040/**
41 * Describes the different type of viewports supported by input flinger.
42 * Keep in sync with values in InputManagerService.java.
43 */
44enum class ViewportType : int32_t {
Michael Wrightfe3de7d2020-07-02 19:05:30 +010045 INTERNAL = 1,
46 EXTERNAL = 2,
47 VIRTUAL = 3,
Dominik Laskowski75788452021-02-09 18:51:25 -080048
49 ftl_last = VIRTUAL
Siarhei Vishniakoud6343922018-07-06 23:33:37 +010050};
51
Santos Cordonfa5cf462017-04-05 10:37:00 -070052/*
53 * Describes how coordinates are mapped on a physical display.
54 * See com.android.server.display.DisplayViewport.
55 */
56struct DisplayViewport {
57 int32_t displayId; // -1 if invalid
58 int32_t orientation;
59 int32_t logicalLeft;
60 int32_t logicalTop;
61 int32_t logicalRight;
62 int32_t logicalBottom;
63 int32_t physicalLeft;
64 int32_t physicalTop;
65 int32_t physicalRight;
66 int32_t physicalBottom;
67 int32_t deviceWidth;
68 int32_t deviceHeight;
Chris Ye13b16852020-04-25 10:58:45 -070069 bool isActive;
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +010070 std::string uniqueId;
Siarhei Vishniakou8158e7e2018-10-15 14:28:20 -070071 // The actual (hardware) port that the associated display is connected to.
72 // Not all viewports will have this specified.
73 std::optional<uint8_t> physicalPort;
Siarhei Vishniakoud6343922018-07-06 23:33:37 +010074 ViewportType type;
Santos Cordonfa5cf462017-04-05 10:37:00 -070075
Chris Ye13b16852020-04-25 10:58:45 -070076 DisplayViewport()
77 : displayId(ADISPLAY_ID_NONE),
78 orientation(DISPLAY_ORIENTATION_0),
79 logicalLeft(0),
80 logicalTop(0),
81 logicalRight(0),
82 logicalBottom(0),
83 physicalLeft(0),
84 physicalTop(0),
85 physicalRight(0),
86 physicalBottom(0),
87 deviceWidth(0),
88 deviceHeight(0),
89 isActive(false),
90 uniqueId(),
91 physicalPort(std::nullopt),
Michael Wrightfe3de7d2020-07-02 19:05:30 +010092 type(ViewportType::INTERNAL) {}
Santos Cordonfa5cf462017-04-05 10:37:00 -070093
94 bool operator==(const DisplayViewport& other) const {
Chris Ye13b16852020-04-25 10:58:45 -070095 return displayId == other.displayId && orientation == other.orientation &&
96 logicalLeft == other.logicalLeft && logicalTop == other.logicalTop &&
97 logicalRight == other.logicalRight && logicalBottom == other.logicalBottom &&
98 physicalLeft == other.physicalLeft && physicalTop == other.physicalTop &&
99 physicalRight == other.physicalRight && physicalBottom == other.physicalBottom &&
100 deviceWidth == other.deviceWidth && deviceHeight == other.deviceHeight &&
101 isActive == other.isActive && uniqueId == other.uniqueId &&
102 physicalPort == other.physicalPort && type == other.type;
Santos Cordonfa5cf462017-04-05 10:37:00 -0700103 }
104
105 bool operator!=(const DisplayViewport& other) const {
106 return !(*this == other);
107 }
108
109 inline bool isValid() const {
110 return displayId >= 0;
111 }
112
113 void setNonDisplayViewport(int32_t width, int32_t height) {
114 displayId = ADISPLAY_ID_NONE;
115 orientation = DISPLAY_ORIENTATION_0;
116 logicalLeft = 0;
117 logicalTop = 0;
118 logicalRight = width;
119 logicalBottom = height;
120 physicalLeft = 0;
121 physicalTop = 0;
122 physicalRight = width;
123 physicalBottom = height;
124 deviceWidth = width;
125 deviceHeight = height;
Siarhei Vishniakou6f778462020-12-09 23:39:07 +0000126 isActive = true;
Santos Cordonfa5cf462017-04-05 10:37:00 -0700127 uniqueId.clear();
Siarhei Vishniakou8158e7e2018-10-15 14:28:20 -0700128 physicalPort = std::nullopt;
Michael Wrightfe3de7d2020-07-02 19:05:30 +0100129 type = ViewportType::INTERNAL;
Santos Cordonfa5cf462017-04-05 10:37:00 -0700130 }
Santos Cordonfa5cf462017-04-05 10:37:00 -0700131
Siarhei Vishniakoud6343922018-07-06 23:33:37 +0100132 std::string toString() const {
Siarhei Vishniakou8158e7e2018-10-15 14:28:20 -0700133 return StringPrintf("Viewport %s: displayId=%d, uniqueId=%s, port=%s, orientation=%d, "
Chris Ye13b16852020-04-25 10:58:45 -0700134 "logicalFrame=[%d, %d, %d, %d], "
135 "physicalFrame=[%d, %d, %d, %d], "
136 "deviceSize=[%d, %d], "
137 "isActive=[%d]",
Dominik Laskowski75788452021-02-09 18:51:25 -0800138 ftl::enum_string(type).c_str(), displayId, uniqueId.c_str(),
139 physicalPort ? ftl::to_string(*physicalPort).c_str() : "<none>",
Chris Ye13b16852020-04-25 10:58:45 -0700140 orientation, logicalLeft, logicalTop, logicalRight, logicalBottom,
141 physicalLeft, physicalTop, physicalRight, physicalBottom, deviceWidth,
142 deviceHeight, isActive);
Siarhei Vishniakoud6343922018-07-06 23:33:37 +0100143 }
Santos Cordonfa5cf462017-04-05 10:37:00 -0700144};
145
146} // namespace android
147
148#endif // _LIBINPUT_DISPLAY_VIEWPORT_H