blob: 7457496784110bb00a35c12a1e8404f3ca5e2ed8 [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>
chaviw98318de2021-05-19 16:45:23 -050022#include <gui/constants.h>
Dominik Laskowski718f9602019-11-09 20:01:35 -080023#include <input/Input.h>
Michael Wrighta9cf4192022-12-01 23:46:39 +000024#include <ui/Rotation.h>
Dominik Laskowski718f9602019-11-09 20:01:35 -080025
Michael Wrightfe3de7d2020-07-02 19:05:30 +010026#include <cinttypes>
27#include <optional>
28
Siarhei Vishniakoud6343922018-07-06 23:33:37 +010029using android::base::StringPrintf;
30
Santos Cordonfa5cf462017-04-05 10:37:00 -070031namespace android {
32
Siarhei Vishniakoud6343922018-07-06 23:33:37 +010033/**
34 * Describes the different type of viewports supported by input flinger.
35 * Keep in sync with values in InputManagerService.java.
36 */
37enum class ViewportType : int32_t {
Michael Wrightfe3de7d2020-07-02 19:05:30 +010038 INTERNAL = 1,
39 EXTERNAL = 2,
40 VIRTUAL = 3,
Dominik Laskowski75788452021-02-09 18:51:25 -080041
42 ftl_last = VIRTUAL
Siarhei Vishniakoud6343922018-07-06 23:33:37 +010043};
44
Santos Cordonfa5cf462017-04-05 10:37:00 -070045/*
46 * Describes how coordinates are mapped on a physical display.
47 * See com.android.server.display.DisplayViewport.
48 */
49struct DisplayViewport {
50 int32_t displayId; // -1 if invalid
Michael Wrighta9cf4192022-12-01 23:46:39 +000051 ui::Rotation orientation;
Santos Cordonfa5cf462017-04-05 10:37:00 -070052 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 Ye13b16852020-04-25 10:58:45 -070062 bool isActive;
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +010063 std::string uniqueId;
Siarhei Vishniakou8158e7e2018-10-15 14:28:20 -070064 // 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 Vishniakoud6343922018-07-06 23:33:37 +010067 ViewportType type;
Santos Cordonfa5cf462017-04-05 10:37:00 -070068
Chris Ye13b16852020-04-25 10:58:45 -070069 DisplayViewport()
70 : displayId(ADISPLAY_ID_NONE),
Michael Wrighta9cf4192022-12-01 23:46:39 +000071 orientation(ui::ROTATION_0),
Chris Ye13b16852020-04-25 10:58:45 -070072 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 Wrightfe3de7d2020-07-02 19:05:30 +010085 type(ViewportType::INTERNAL) {}
Santos Cordonfa5cf462017-04-05 10:37:00 -070086
87 bool operator==(const DisplayViewport& other) const {
Chris Ye13b16852020-04-25 10:58:45 -070088 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 Cordonfa5cf462017-04-05 10:37:00 -070096 }
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 Wrighta9cf4192022-12-01 23:46:39 +0000108 orientation = ui::ROTATION_0;
Santos Cordonfa5cf462017-04-05 10:37:00 -0700109 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 Vishniakou6f778462020-12-09 23:39:07 +0000119 isActive = true;
Santos Cordonfa5cf462017-04-05 10:37:00 -0700120 uniqueId.clear();
Siarhei Vishniakou8158e7e2018-10-15 14:28:20 -0700121 physicalPort = std::nullopt;
Michael Wrightfe3de7d2020-07-02 19:05:30 +0100122 type = ViewportType::INTERNAL;
Santos Cordonfa5cf462017-04-05 10:37:00 -0700123 }
Santos Cordonfa5cf462017-04-05 10:37:00 -0700124
Siarhei Vishniakoud6343922018-07-06 23:33:37 +0100125 std::string toString() const {
Siarhei Vishniakou8158e7e2018-10-15 14:28:20 -0700126 return StringPrintf("Viewport %s: displayId=%d, uniqueId=%s, port=%s, orientation=%d, "
Chris Ye13b16852020-04-25 10:58:45 -0700127 "logicalFrame=[%d, %d, %d, %d], "
128 "physicalFrame=[%d, %d, %d, %d], "
129 "deviceSize=[%d, %d], "
130 "isActive=[%d]",
Dominik Laskowski75788452021-02-09 18:51:25 -0800131 ftl::enum_string(type).c_str(), displayId, uniqueId.c_str(),
132 physicalPort ? ftl::to_string(*physicalPort).c_str() : "<none>",
Chris Ye13b16852020-04-25 10:58:45 -0700133 orientation, logicalLeft, logicalTop, logicalRight, logicalBottom,
134 physicalLeft, physicalTop, physicalRight, physicalBottom, deviceWidth,
135 deviceHeight, isActive);
Siarhei Vishniakoud6343922018-07-06 23:33:37 +0100136 }
Santos Cordonfa5cf462017-04-05 10:37:00 -0700137};
138
139} // namespace android