blob: 0de3bb7a08b647dfd679658763e315433a98339e [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
17#ifndef _LIBINPUT_DISPLAY_VIEWPORT_H
18#define _LIBINPUT_DISPLAY_VIEWPORT_H
19
Siarhei Vishniakoud6343922018-07-06 23:33:37 +010020#include <android-base/stringprintf.h>
Santos Cordonfa5cf462017-04-05 10:37:00 -070021#include <ui/DisplayInfo.h>
22#include <input/Input.h>
23
Siarhei Vishniakoud6343922018-07-06 23:33:37 +010024using android::base::StringPrintf;
25
Santos Cordonfa5cf462017-04-05 10:37:00 -070026namespace android {
27
Siarhei Vishniakoud6343922018-07-06 23:33:37 +010028/**
29 * Describes the different type of viewports supported by input flinger.
30 * Keep in sync with values in InputManagerService.java.
31 */
32enum class ViewportType : int32_t {
33 VIEWPORT_INTERNAL = 1,
34 VIEWPORT_EXTERNAL = 2,
35 VIEWPORT_VIRTUAL = 3,
36};
37
38static const char* viewportTypeToString(ViewportType type) {
39 switch(type) {
40 case ViewportType::VIEWPORT_INTERNAL:
41 return "INTERNAL";
42 case ViewportType::VIEWPORT_EXTERNAL:
43 return "EXTERNAL";
44 case ViewportType::VIEWPORT_VIRTUAL:
45 return "VIRTUAL";
46 default:
47 return "UNKNOWN";
48 }
49}
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;
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +010068 std::string uniqueId;
Siarhei Vishniakoud6343922018-07-06 23:33:37 +010069 ViewportType type;
Santos Cordonfa5cf462017-04-05 10:37:00 -070070
71 DisplayViewport() :
72 displayId(ADISPLAY_ID_NONE), orientation(DISPLAY_ORIENTATION_0),
73 logicalLeft(0), logicalTop(0), logicalRight(0), logicalBottom(0),
74 physicalLeft(0), physicalTop(0), physicalRight(0), physicalBottom(0),
Siarhei Vishniakoud6343922018-07-06 23:33:37 +010075 deviceWidth(0), deviceHeight(0), uniqueId(), type(ViewportType::VIEWPORT_INTERNAL) {
Santos Cordonfa5cf462017-04-05 10:37:00 -070076 }
77
78 bool operator==(const DisplayViewport& other) const {
79 return displayId == other.displayId
80 && orientation == other.orientation
81 && logicalLeft == other.logicalLeft
82 && logicalTop == other.logicalTop
83 && logicalRight == other.logicalRight
84 && logicalBottom == other.logicalBottom
85 && physicalLeft == other.physicalLeft
86 && physicalTop == other.physicalTop
87 && physicalRight == other.physicalRight
88 && physicalBottom == other.physicalBottom
89 && deviceWidth == other.deviceWidth
90 && deviceHeight == other.deviceHeight
Siarhei Vishniakoud6343922018-07-06 23:33:37 +010091 && uniqueId == other.uniqueId
92 && type == other.type;
Santos Cordonfa5cf462017-04-05 10:37:00 -070093 }
94
95 bool operator!=(const DisplayViewport& other) const {
96 return !(*this == other);
97 }
98
99 inline bool isValid() const {
100 return displayId >= 0;
101 }
102
103 void setNonDisplayViewport(int32_t width, int32_t height) {
104 displayId = ADISPLAY_ID_NONE;
105 orientation = DISPLAY_ORIENTATION_0;
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;
116 uniqueId.clear();
Siarhei Vishniakoud6343922018-07-06 23:33:37 +0100117 type = ViewportType::VIEWPORT_INTERNAL;
Santos Cordonfa5cf462017-04-05 10:37:00 -0700118 }
Santos Cordonfa5cf462017-04-05 10:37:00 -0700119
Siarhei Vishniakoud6343922018-07-06 23:33:37 +0100120 std::string toString() const {
121 return StringPrintf("Viewport %s: displayId=%d, orientation=%d, "
122 "logicalFrame=[%d, %d, %d, %d], "
123 "physicalFrame=[%d, %d, %d, %d], "
124 "deviceSize=[%d, %d]",
125 viewportTypeToString(type),
126 displayId, orientation,
127 logicalLeft, logicalTop,
128 logicalRight, logicalBottom,
129 physicalLeft, physicalTop,
130 physicalRight, physicalBottom,
131 deviceWidth, deviceHeight);
132 }
Santos Cordonfa5cf462017-04-05 10:37:00 -0700133};
134
135} // namespace android
136
137#endif // _LIBINPUT_DISPLAY_VIEWPORT_H