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 <cinttypes> |
Siarhei Vishniakou | 8158e7e | 2018-10-15 14:28:20 -0700 | [diff] [blame] | 21 | #include <optional> |
Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 22 | |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame^] | 23 | #include <android-base/stringprintf.h> |
| 24 | #include <input/Input.h> |
| 25 | |
Siarhei Vishniakou | d634392 | 2018-07-06 23:33:37 +0100 | [diff] [blame] | 26 | using android::base::StringPrintf; |
| 27 | |
Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 28 | namespace android { |
| 29 | |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame^] | 30 | enum { |
| 31 | DISPLAY_ORIENTATION_0 = 0, |
| 32 | DISPLAY_ORIENTATION_90 = 1, |
| 33 | DISPLAY_ORIENTATION_180 = 2, |
| 34 | DISPLAY_ORIENTATION_270 = 3 |
| 35 | }; |
| 36 | |
Siarhei Vishniakou | d634392 | 2018-07-06 23:33:37 +0100 | [diff] [blame] | 37 | /** |
| 38 | * Describes the different type of viewports supported by input flinger. |
| 39 | * Keep in sync with values in InputManagerService.java. |
| 40 | */ |
| 41 | enum class ViewportType : int32_t { |
| 42 | VIEWPORT_INTERNAL = 1, |
| 43 | VIEWPORT_EXTERNAL = 2, |
| 44 | VIEWPORT_VIRTUAL = 3, |
| 45 | }; |
| 46 | |
| 47 | static 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 Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 60 | /* |
| 61 | * Describes how coordinates are mapped on a physical display. |
| 62 | * See com.android.server.display.DisplayViewport. |
| 63 | */ |
| 64 | struct 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 Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 77 | std::string uniqueId; |
Siarhei Vishniakou | 8158e7e | 2018-10-15 14:28:20 -0700 | [diff] [blame] | 78 | // 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 Vishniakou | d634392 | 2018-07-06 23:33:37 +0100 | [diff] [blame] | 81 | ViewportType type; |
Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 82 | |
| 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 Vishniakou | 8158e7e | 2018-10-15 14:28:20 -0700 | [diff] [blame] | 87 | deviceWidth(0), deviceHeight(0), uniqueId(), physicalPort(std::nullopt), |
| 88 | type(ViewportType::VIEWPORT_INTERNAL) { |
Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 89 | } |
| 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 Vishniakou | d634392 | 2018-07-06 23:33:37 +0100 | [diff] [blame] | 104 | && uniqueId == other.uniqueId |
Siarhei Vishniakou | 8158e7e | 2018-10-15 14:28:20 -0700 | [diff] [blame] | 105 | && physicalPort == other.physicalPort |
Siarhei Vishniakou | d634392 | 2018-07-06 23:33:37 +0100 | [diff] [blame] | 106 | && type == other.type; |
Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 107 | } |
| 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 Vishniakou | 8158e7e | 2018-10-15 14:28:20 -0700 | [diff] [blame] | 131 | physicalPort = std::nullopt; |
Siarhei Vishniakou | d634392 | 2018-07-06 23:33:37 +0100 | [diff] [blame] | 132 | type = ViewportType::VIEWPORT_INTERNAL; |
Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 133 | } |
Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 134 | |
Siarhei Vishniakou | d634392 | 2018-07-06 23:33:37 +0100 | [diff] [blame] | 135 | std::string toString() const { |
Siarhei Vishniakou | 8158e7e | 2018-10-15 14:28:20 -0700 | [diff] [blame] | 136 | return StringPrintf("Viewport %s: displayId=%d, uniqueId=%s, port=%s, orientation=%d, " |
Siarhei Vishniakou | d634392 | 2018-07-06 23:33:37 +0100 | [diff] [blame] | 137 | "logicalFrame=[%d, %d, %d, %d], " |
| 138 | "physicalFrame=[%d, %d, %d, %d], " |
| 139 | "deviceSize=[%d, %d]", |
Siarhei Vishniakou | 8158e7e | 2018-10-15 14:28:20 -0700 | [diff] [blame] | 140 | viewportTypeToString(type), displayId, |
| 141 | uniqueId.c_str(), |
| 142 | physicalPort ? StringPrintf("%" PRIu8, *physicalPort).c_str() : "<none>", |
| 143 | orientation, |
Siarhei Vishniakou | d634392 | 2018-07-06 23:33:37 +0100 | [diff] [blame] | 144 | logicalLeft, logicalTop, |
| 145 | logicalRight, logicalBottom, |
| 146 | physicalLeft, physicalTop, |
| 147 | physicalRight, physicalBottom, |
| 148 | deviceWidth, deviceHeight); |
| 149 | } |
Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 150 | }; |
| 151 | |
| 152 | } // namespace android |
| 153 | |
| 154 | #endif // _LIBINPUT_DISPLAY_VIEWPORT_H |