blob: 98a18c9560bef52f73e62b52a9ad2a7acfbc8dbb [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>
24
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
Dominik Laskowski718f9602019-11-09 20:01:35 -080032enum {
33 DISPLAY_ORIENTATION_0 = 0,
34 DISPLAY_ORIENTATION_90 = 1,
35 DISPLAY_ORIENTATION_180 = 2,
36 DISPLAY_ORIENTATION_270 = 3
37};
38
Siarhei Vishniakoud6343922018-07-06 23:33:37 +010039/**
40 * Describes the different type of viewports supported by input flinger.
41 * Keep in sync with values in InputManagerService.java.
42 */
43enum class ViewportType : int32_t {
Michael Wrightfe3de7d2020-07-02 19:05:30 +010044 INTERNAL = 1,
45 EXTERNAL = 2,
46 VIRTUAL = 3,
Dominik Laskowski75788452021-02-09 18:51:25 -080047
48 ftl_last = VIRTUAL
Siarhei Vishniakoud6343922018-07-06 23:33:37 +010049};
50
Santos Cordonfa5cf462017-04-05 10:37:00 -070051/*
52 * Describes how coordinates are mapped on a physical display.
53 * See com.android.server.display.DisplayViewport.
54 */
55struct DisplayViewport {
56 int32_t displayId; // -1 if invalid
57 int32_t orientation;
58 int32_t logicalLeft;
59 int32_t logicalTop;
60 int32_t logicalRight;
61 int32_t logicalBottom;
62 int32_t physicalLeft;
63 int32_t physicalTop;
64 int32_t physicalRight;
65 int32_t physicalBottom;
66 int32_t deviceWidth;
67 int32_t deviceHeight;
Chris Ye13b16852020-04-25 10:58:45 -070068 bool isActive;
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +010069 std::string uniqueId;
Siarhei Vishniakou8158e7e2018-10-15 14:28:20 -070070 // The actual (hardware) port that the associated display is connected to.
71 // Not all viewports will have this specified.
72 std::optional<uint8_t> physicalPort;
Siarhei Vishniakoud6343922018-07-06 23:33:37 +010073 ViewportType type;
Santos Cordonfa5cf462017-04-05 10:37:00 -070074
Chris Ye13b16852020-04-25 10:58:45 -070075 DisplayViewport()
76 : displayId(ADISPLAY_ID_NONE),
77 orientation(DISPLAY_ORIENTATION_0),
78 logicalLeft(0),
79 logicalTop(0),
80 logicalRight(0),
81 logicalBottom(0),
82 physicalLeft(0),
83 physicalTop(0),
84 physicalRight(0),
85 physicalBottom(0),
86 deviceWidth(0),
87 deviceHeight(0),
88 isActive(false),
89 uniqueId(),
90 physicalPort(std::nullopt),
Michael Wrightfe3de7d2020-07-02 19:05:30 +010091 type(ViewportType::INTERNAL) {}
Santos Cordonfa5cf462017-04-05 10:37:00 -070092
93 bool operator==(const DisplayViewport& other) const {
Chris Ye13b16852020-04-25 10:58:45 -070094 return displayId == other.displayId && orientation == other.orientation &&
95 logicalLeft == other.logicalLeft && logicalTop == other.logicalTop &&
96 logicalRight == other.logicalRight && logicalBottom == other.logicalBottom &&
97 physicalLeft == other.physicalLeft && physicalTop == other.physicalTop &&
98 physicalRight == other.physicalRight && physicalBottom == other.physicalBottom &&
99 deviceWidth == other.deviceWidth && deviceHeight == other.deviceHeight &&
100 isActive == other.isActive && uniqueId == other.uniqueId &&
101 physicalPort == other.physicalPort && type == other.type;
Santos Cordonfa5cf462017-04-05 10:37:00 -0700102 }
103
104 bool operator!=(const DisplayViewport& other) const {
105 return !(*this == other);
106 }
107
108 inline bool isValid() const {
109 return displayId >= 0;
110 }
111
112 void setNonDisplayViewport(int32_t width, int32_t height) {
113 displayId = ADISPLAY_ID_NONE;
114 orientation = DISPLAY_ORIENTATION_0;
115 logicalLeft = 0;
116 logicalTop = 0;
117 logicalRight = width;
118 logicalBottom = height;
119 physicalLeft = 0;
120 physicalTop = 0;
121 physicalRight = width;
122 physicalBottom = height;
123 deviceWidth = width;
124 deviceHeight = height;
Siarhei Vishniakou6f778462020-12-09 23:39:07 +0000125 isActive = true;
Santos Cordonfa5cf462017-04-05 10:37:00 -0700126 uniqueId.clear();
Siarhei Vishniakou8158e7e2018-10-15 14:28:20 -0700127 physicalPort = std::nullopt;
Michael Wrightfe3de7d2020-07-02 19:05:30 +0100128 type = ViewportType::INTERNAL;
Santos Cordonfa5cf462017-04-05 10:37:00 -0700129 }
Santos Cordonfa5cf462017-04-05 10:37:00 -0700130
Siarhei Vishniakoud6343922018-07-06 23:33:37 +0100131 std::string toString() const {
Siarhei Vishniakou8158e7e2018-10-15 14:28:20 -0700132 return StringPrintf("Viewport %s: displayId=%d, uniqueId=%s, port=%s, orientation=%d, "
Chris Ye13b16852020-04-25 10:58:45 -0700133 "logicalFrame=[%d, %d, %d, %d], "
134 "physicalFrame=[%d, %d, %d, %d], "
135 "deviceSize=[%d, %d], "
136 "isActive=[%d]",
Dominik Laskowski75788452021-02-09 18:51:25 -0800137 ftl::enum_string(type).c_str(), displayId, uniqueId.c_str(),
138 physicalPort ? ftl::to_string(*physicalPort).c_str() : "<none>",
Chris Ye13b16852020-04-25 10:58:45 -0700139 orientation, logicalLeft, logicalTop, logicalRight, logicalBottom,
140 physicalLeft, physicalTop, physicalRight, physicalBottom, deviceWidth,
141 deviceHeight, isActive);
Siarhei Vishniakoud6343922018-07-06 23:33:37 +0100142 }
Santos Cordonfa5cf462017-04-05 10:37:00 -0700143};
144
145} // namespace android