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