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 | |
Prabir Pradhan | c08b0db | 2022-09-10 00:57:15 +0000 | [diff] [blame] | 17 | #pragma once |
Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 18 | |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 19 | #include <android-base/stringprintf.h> |
Dominik Laskowski | 7578845 | 2021-02-09 18:51:25 -0800 | [diff] [blame] | 20 | #include <ftl/enum.h> |
| 21 | #include <ftl/string.h> |
chaviw | 98318de | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 22 | #include <gui/constants.h> |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 23 | #include <input/Input.h> |
Michael Wright | a9cf419 | 2022-12-01 23:46:39 +0000 | [diff] [blame] | 24 | #include <ui/Rotation.h> |
Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 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 | |
Siarhei Vishniakou | d634392 | 2018-07-06 23:33:37 +0100 | [diff] [blame] | 33 | /** |
| 34 | * Describes the different type of viewports supported by input flinger. |
| 35 | * Keep in sync with values in InputManagerService.java. |
| 36 | */ |
| 37 | enum class ViewportType : int32_t { |
Michael Wright | fe3de7d | 2020-07-02 19:05:30 +0100 | [diff] [blame] | 38 | INTERNAL = 1, |
| 39 | EXTERNAL = 2, |
| 40 | VIRTUAL = 3, |
Dominik Laskowski | 7578845 | 2021-02-09 18:51:25 -0800 | [diff] [blame] | 41 | |
| 42 | ftl_last = VIRTUAL |
Siarhei Vishniakou | d634392 | 2018-07-06 23:33:37 +0100 | [diff] [blame] | 43 | }; |
| 44 | |
Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 45 | /* |
| 46 | * Describes how coordinates are mapped on a physical display. |
| 47 | * See com.android.server.display.DisplayViewport. |
| 48 | */ |
| 49 | struct DisplayViewport { |
| 50 | int32_t displayId; // -1 if invalid |
Michael Wright | a9cf419 | 2022-12-01 23:46:39 +0000 | [diff] [blame] | 51 | ui::Rotation orientation; |
Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 52 | int32_t logicalLeft; |
| 53 | int32_t logicalTop; |
| 54 | int32_t logicalRight; |
| 55 | int32_t logicalBottom; |
| 56 | int32_t physicalLeft; |
| 57 | int32_t physicalTop; |
| 58 | int32_t physicalRight; |
| 59 | int32_t physicalBottom; |
| 60 | int32_t deviceWidth; |
| 61 | int32_t deviceHeight; |
Chris Ye | 13b1685 | 2020-04-25 10:58:45 -0700 | [diff] [blame] | 62 | bool isActive; |
Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 63 | std::string uniqueId; |
Siarhei Vishniakou | 8158e7e | 2018-10-15 14:28:20 -0700 | [diff] [blame] | 64 | // The actual (hardware) port that the associated display is connected to. |
| 65 | // Not all viewports will have this specified. |
| 66 | std::optional<uint8_t> physicalPort; |
Siarhei Vishniakou | d634392 | 2018-07-06 23:33:37 +0100 | [diff] [blame] | 67 | ViewportType type; |
Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 68 | |
Chris Ye | 13b1685 | 2020-04-25 10:58:45 -0700 | [diff] [blame] | 69 | DisplayViewport() |
| 70 | : displayId(ADISPLAY_ID_NONE), |
Michael Wright | a9cf419 | 2022-12-01 23:46:39 +0000 | [diff] [blame] | 71 | orientation(ui::ROTATION_0), |
Chris Ye | 13b1685 | 2020-04-25 10:58:45 -0700 | [diff] [blame] | 72 | logicalLeft(0), |
| 73 | logicalTop(0), |
| 74 | logicalRight(0), |
| 75 | logicalBottom(0), |
| 76 | physicalLeft(0), |
| 77 | physicalTop(0), |
| 78 | physicalRight(0), |
| 79 | physicalBottom(0), |
| 80 | deviceWidth(0), |
| 81 | deviceHeight(0), |
| 82 | isActive(false), |
| 83 | uniqueId(), |
| 84 | physicalPort(std::nullopt), |
Michael Wright | fe3de7d | 2020-07-02 19:05:30 +0100 | [diff] [blame] | 85 | type(ViewportType::INTERNAL) {} |
Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 86 | |
| 87 | bool operator==(const DisplayViewport& other) const { |
Chris Ye | 13b1685 | 2020-04-25 10:58:45 -0700 | [diff] [blame] | 88 | return displayId == other.displayId && orientation == other.orientation && |
| 89 | logicalLeft == other.logicalLeft && logicalTop == other.logicalTop && |
| 90 | logicalRight == other.logicalRight && logicalBottom == other.logicalBottom && |
| 91 | physicalLeft == other.physicalLeft && physicalTop == other.physicalTop && |
| 92 | physicalRight == other.physicalRight && physicalBottom == other.physicalBottom && |
| 93 | deviceWidth == other.deviceWidth && deviceHeight == other.deviceHeight && |
| 94 | isActive == other.isActive && uniqueId == other.uniqueId && |
| 95 | physicalPort == other.physicalPort && type == other.type; |
Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | bool operator!=(const DisplayViewport& other) const { |
| 99 | return !(*this == other); |
| 100 | } |
| 101 | |
| 102 | inline bool isValid() const { |
| 103 | return displayId >= 0; |
| 104 | } |
| 105 | |
| 106 | void setNonDisplayViewport(int32_t width, int32_t height) { |
| 107 | displayId = ADISPLAY_ID_NONE; |
Michael Wright | a9cf419 | 2022-12-01 23:46:39 +0000 | [diff] [blame] | 108 | orientation = ui::ROTATION_0; |
Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 109 | logicalLeft = 0; |
| 110 | logicalTop = 0; |
| 111 | logicalRight = width; |
| 112 | logicalBottom = height; |
| 113 | physicalLeft = 0; |
| 114 | physicalTop = 0; |
| 115 | physicalRight = width; |
| 116 | physicalBottom = height; |
| 117 | deviceWidth = width; |
| 118 | deviceHeight = height; |
Siarhei Vishniakou | 6f77846 | 2020-12-09 23:39:07 +0000 | [diff] [blame] | 119 | isActive = true; |
Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 120 | uniqueId.clear(); |
Siarhei Vishniakou | 8158e7e | 2018-10-15 14:28:20 -0700 | [diff] [blame] | 121 | physicalPort = std::nullopt; |
Michael Wright | fe3de7d | 2020-07-02 19:05:30 +0100 | [diff] [blame] | 122 | type = ViewportType::INTERNAL; |
Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 123 | } |
Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 124 | |
Siarhei Vishniakou | d634392 | 2018-07-06 23:33:37 +0100 | [diff] [blame] | 125 | std::string toString() const { |
Siarhei Vishniakou | 8158e7e | 2018-10-15 14:28:20 -0700 | [diff] [blame] | 126 | return StringPrintf("Viewport %s: displayId=%d, uniqueId=%s, port=%s, orientation=%d, " |
Chris Ye | 13b1685 | 2020-04-25 10:58:45 -0700 | [diff] [blame] | 127 | "logicalFrame=[%d, %d, %d, %d], " |
| 128 | "physicalFrame=[%d, %d, %d, %d], " |
| 129 | "deviceSize=[%d, %d], " |
| 130 | "isActive=[%d]", |
Dominik Laskowski | 7578845 | 2021-02-09 18:51:25 -0800 | [diff] [blame] | 131 | ftl::enum_string(type).c_str(), displayId, uniqueId.c_str(), |
| 132 | physicalPort ? ftl::to_string(*physicalPort).c_str() : "<none>", |
Yi Kong | 9a42103 | 2023-12-11 14:21:35 +0900 | [diff] [blame] | 133 | static_cast<int>(orientation), logicalLeft, logicalTop, logicalRight, |
| 134 | logicalBottom, physicalLeft, physicalTop, physicalRight, physicalBottom, |
| 135 | deviceWidth, deviceHeight, isActive); |
Siarhei Vishniakou | d634392 | 2018-07-06 23:33:37 +0100 | [diff] [blame] | 136 | } |
Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 137 | }; |
| 138 | |
| 139 | } // namespace android |