blob: 56294dd91a0981123d6480ee2a1ef522576f5b18 [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
Prabir Pradhanc08b0db2022-09-10 00:57:15 +000017#pragma once
Santos Cordonfa5cf462017-04-05 10:37:00 -070018
Dominik Laskowski718f9602019-11-09 20:01:35 -080019#include <android-base/stringprintf.h>
Dominik Laskowski75788452021-02-09 18:51:25 -080020#include <ftl/enum.h>
21#include <ftl/string.h>
Dominik Laskowski718f9602019-11-09 20:01:35 -080022#include <input/Input.h>
Michael Wrighta9cf4192022-12-01 23:46:39 +000023#include <ui/Rotation.h>
Dominik Laskowski718f9602019-11-09 20:01:35 -080024
Michael Wrightfe3de7d2020-07-02 19:05:30 +010025#include <cinttypes>
26#include <optional>
27
Siarhei Vishniakoud6343922018-07-06 23:33:37 +010028using android::base::StringPrintf;
29
Santos Cordonfa5cf462017-04-05 10:37:00 -070030namespace android {
31
Siarhei Vishniakoud6343922018-07-06 23:33:37 +010032/**
33 * Describes the different type of viewports supported by input flinger.
34 * Keep in sync with values in InputManagerService.java.
35 */
36enum class ViewportType : int32_t {
Michael Wrightfe3de7d2020-07-02 19:05:30 +010037 INTERNAL = 1,
38 EXTERNAL = 2,
39 VIRTUAL = 3,
Dominik Laskowski75788452021-02-09 18:51:25 -080040
41 ftl_last = VIRTUAL
Siarhei Vishniakoud6343922018-07-06 23:33:37 +010042};
43
Santos Cordonfa5cf462017-04-05 10:37:00 -070044/*
45 * Describes how coordinates are mapped on a physical display.
46 * See com.android.server.display.DisplayViewport.
47 */
48struct DisplayViewport {
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -070049 ui::LogicalDisplayId displayId;
Michael Wrighta9cf4192022-12-01 23:46:39 +000050 ui::Rotation orientation;
Santos Cordonfa5cf462017-04-05 10:37:00 -070051 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 Ye13b16852020-04-25 10:58:45 -070061 bool isActive;
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +010062 std::string uniqueId;
Siarhei Vishniakou8158e7e2018-10-15 14:28:20 -070063 // 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 Vishniakoud6343922018-07-06 23:33:37 +010066 ViewportType type;
Santos Cordonfa5cf462017-04-05 10:37:00 -070067
Chris Ye13b16852020-04-25 10:58:45 -070068 DisplayViewport()
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -070069 : displayId(ui::LogicalDisplayId::INVALID),
Michael Wrighta9cf4192022-12-01 23:46:39 +000070 orientation(ui::ROTATION_0),
Chris Ye13b16852020-04-25 10:58:45 -070071 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 Wrightfe3de7d2020-07-02 19:05:30 +010084 type(ViewportType::INTERNAL) {}
Santos Cordonfa5cf462017-04-05 10:37:00 -070085
86 bool operator==(const DisplayViewport& other) const {
Chris Ye13b16852020-04-25 10:58:45 -070087 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 Cordonfa5cf462017-04-05 10:37:00 -070095 }
96
97 bool operator!=(const DisplayViewport& other) const {
98 return !(*this == other);
99 }
100
Linnan Li13bf76a2024-05-05 19:18:02 +0800101 inline bool isValid() const { return displayId.isValid(); }
Santos Cordonfa5cf462017-04-05 10:37:00 -0700102
103 void setNonDisplayViewport(int32_t width, int32_t height) {
Siarhei Vishniakoucfbee532024-05-10 13:41:35 -0700104 displayId = ui::LogicalDisplayId::INVALID;
Michael Wrighta9cf4192022-12-01 23:46:39 +0000105 orientation = ui::ROTATION_0;
Santos Cordonfa5cf462017-04-05 10:37:00 -0700106 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 Vishniakou6f778462020-12-09 23:39:07 +0000116 isActive = true;
Santos Cordonfa5cf462017-04-05 10:37:00 -0700117 uniqueId.clear();
Siarhei Vishniakou8158e7e2018-10-15 14:28:20 -0700118 physicalPort = std::nullopt;
Michael Wrightfe3de7d2020-07-02 19:05:30 +0100119 type = ViewportType::INTERNAL;
Santos Cordonfa5cf462017-04-05 10:37:00 -0700120 }
Santos Cordonfa5cf462017-04-05 10:37:00 -0700121
Siarhei Vishniakoud6343922018-07-06 23:33:37 +0100122 std::string toString() const {
Linnan Li13bf76a2024-05-05 19:18:02 +0800123 return StringPrintf("Viewport %s: displayId=%s, uniqueId=%s, port=%s, orientation=%d, "
Chris Ye13b16852020-04-25 10:58:45 -0700124 "logicalFrame=[%d, %d, %d, %d], "
125 "physicalFrame=[%d, %d, %d, %d], "
126 "deviceSize=[%d, %d], "
127 "isActive=[%d]",
Linnan Li13bf76a2024-05-05 19:18:02 +0800128 ftl::enum_string(type).c_str(), displayId.toString().c_str(),
129 uniqueId.c_str(),
Dominik Laskowski75788452021-02-09 18:51:25 -0800130 physicalPort ? ftl::to_string(*physicalPort).c_str() : "<none>",
Yi Kong9a421032023-12-11 14:21:35 +0900131 static_cast<int>(orientation), logicalLeft, logicalTop, logicalRight,
132 logicalBottom, physicalLeft, physicalTop, physicalRight, physicalBottom,
133 deviceWidth, deviceHeight, isActive);
Siarhei Vishniakoud6343922018-07-06 23:33:37 +0100134 }
Santos Cordonfa5cf462017-04-05 10:37:00 -0700135};
136
137} // namespace android