Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 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 | |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 20 | #include <android-base/stringprintf.h> |
Dominik Laskowski | 7578845 | 2021-02-09 18:51:25 -0800 | [diff] [blame^] | 21 | #include <ftl/enum.h> |
| 22 | #include <ftl/string.h> |
chaviw | 98318de | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 23 | #include <gui/constants.h> |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 24 | #include <input/Input.h> |
| 25 | |
Michael Wright | fe3de7d | 2020-07-02 19:05:30 +0100 | [diff] [blame] | 26 | #include <cinttypes> |
| 27 | #include <optional> |
| 28 | |
Siarhei Vishniakou | d634392 | 2018-07-06 23:33:37 +0100 | [diff] [blame] | 29 | using android::base::StringPrintf; |
| 30 | |
Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 31 | namespace android { |
| 32 | |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 33 | enum { |
| 34 | DISPLAY_ORIENTATION_0 = 0, |
| 35 | DISPLAY_ORIENTATION_90 = 1, |
| 36 | DISPLAY_ORIENTATION_180 = 2, |
| 37 | DISPLAY_ORIENTATION_270 = 3 |
| 38 | }; |
| 39 | |
Siarhei Vishniakou | d634392 | 2018-07-06 23:33:37 +0100 | [diff] [blame] | 40 | /** |
| 41 | * Describes the different type of viewports supported by input flinger. |
| 42 | * Keep in sync with values in InputManagerService.java. |
| 43 | */ |
| 44 | enum class ViewportType : int32_t { |
Michael Wright | fe3de7d | 2020-07-02 19:05:30 +0100 | [diff] [blame] | 45 | INTERNAL = 1, |
| 46 | EXTERNAL = 2, |
| 47 | VIRTUAL = 3, |
Dominik Laskowski | 7578845 | 2021-02-09 18:51:25 -0800 | [diff] [blame^] | 48 | |
| 49 | ftl_last = VIRTUAL |
Siarhei Vishniakou | d634392 | 2018-07-06 23:33:37 +0100 | [diff] [blame] | 50 | }; |
| 51 | |
Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 52 | /* |
| 53 | * Describes how coordinates are mapped on a physical display. |
| 54 | * See com.android.server.display.DisplayViewport. |
| 55 | */ |
| 56 | struct 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 Ye | 13b1685 | 2020-04-25 10:58:45 -0700 | [diff] [blame] | 69 | bool isActive; |
Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 70 | std::string uniqueId; |
Siarhei Vishniakou | 8158e7e | 2018-10-15 14:28:20 -0700 | [diff] [blame] | 71 | // 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 Vishniakou | d634392 | 2018-07-06 23:33:37 +0100 | [diff] [blame] | 74 | ViewportType type; |
Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 75 | |
Chris Ye | 13b1685 | 2020-04-25 10:58:45 -0700 | [diff] [blame] | 76 | 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 Wright | fe3de7d | 2020-07-02 19:05:30 +0100 | [diff] [blame] | 92 | type(ViewportType::INTERNAL) {} |
Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 93 | |
| 94 | bool operator==(const DisplayViewport& other) const { |
Chris Ye | 13b1685 | 2020-04-25 10:58:45 -0700 | [diff] [blame] | 95 | 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 Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 103 | } |
| 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 Vishniakou | 6f77846 | 2020-12-09 23:39:07 +0000 | [diff] [blame] | 126 | isActive = true; |
Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 127 | uniqueId.clear(); |
Siarhei Vishniakou | 8158e7e | 2018-10-15 14:28:20 -0700 | [diff] [blame] | 128 | physicalPort = std::nullopt; |
Michael Wright | fe3de7d | 2020-07-02 19:05:30 +0100 | [diff] [blame] | 129 | type = ViewportType::INTERNAL; |
Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 130 | } |
Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 131 | |
Siarhei Vishniakou | d634392 | 2018-07-06 23:33:37 +0100 | [diff] [blame] | 132 | std::string toString() const { |
Siarhei Vishniakou | 8158e7e | 2018-10-15 14:28:20 -0700 | [diff] [blame] | 133 | return StringPrintf("Viewport %s: displayId=%d, uniqueId=%s, port=%s, orientation=%d, " |
Chris Ye | 13b1685 | 2020-04-25 10:58:45 -0700 | [diff] [blame] | 134 | "logicalFrame=[%d, %d, %d, %d], " |
| 135 | "physicalFrame=[%d, %d, %d, %d], " |
| 136 | "deviceSize=[%d, %d], " |
| 137 | "isActive=[%d]", |
Dominik Laskowski | 7578845 | 2021-02-09 18:51:25 -0800 | [diff] [blame^] | 138 | ftl::enum_string(type).c_str(), displayId, uniqueId.c_str(), |
| 139 | physicalPort ? ftl::to_string(*physicalPort).c_str() : "<none>", |
Chris Ye | 13b1685 | 2020-04-25 10:58:45 -0700 | [diff] [blame] | 140 | orientation, logicalLeft, logicalTop, logicalRight, logicalBottom, |
| 141 | physicalLeft, physicalTop, physicalRight, physicalBottom, deviceWidth, |
| 142 | deviceHeight, isActive); |
Siarhei Vishniakou | d634392 | 2018-07-06 23:33:37 +0100 | [diff] [blame] | 143 | } |
Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 144 | }; |
| 145 | |
| 146 | } // namespace android |
| 147 | |
| 148 | #endif // _LIBINPUT_DISPLAY_VIEWPORT_H |