| 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 |  | 
|  | 17 | #ifndef _LIBINPUT_DISPLAY_VIEWPORT_H | 
|  | 18 | #define _LIBINPUT_DISPLAY_VIEWPORT_H | 
|  | 19 |  | 
| Siarhei Vishniakou | d634392 | 2018-07-06 23:33:37 +0100 | [diff] [blame] | 20 | #include <android-base/stringprintf.h> | 
| Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 21 | #include <ui/DisplayInfo.h> | 
|  | 22 | #include <input/Input.h> | 
| Siarhei Vishniakou | 8158e7e | 2018-10-15 14:28:20 -0700 | [diff] [blame] | 23 | #include <inttypes.h> | 
|  | 24 | #include <optional> | 
| Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 25 |  | 
| Siarhei Vishniakou | d634392 | 2018-07-06 23:33:37 +0100 | [diff] [blame] | 26 | using android::base::StringPrintf; | 
|  | 27 |  | 
| Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 28 | namespace android { | 
|  | 29 |  | 
| Siarhei Vishniakou | d634392 | 2018-07-06 23:33:37 +0100 | [diff] [blame] | 30 | /** | 
|  | 31 | * Describes the different type of viewports supported by input flinger. | 
|  | 32 | * Keep in sync with values in InputManagerService.java. | 
|  | 33 | */ | 
|  | 34 | enum class ViewportType : int32_t { | 
|  | 35 | VIEWPORT_INTERNAL = 1, | 
|  | 36 | VIEWPORT_EXTERNAL = 2, | 
|  | 37 | VIEWPORT_VIRTUAL = 3, | 
|  | 38 | }; | 
|  | 39 |  | 
|  | 40 | static const char* viewportTypeToString(ViewportType type) { | 
|  | 41 | switch(type) { | 
|  | 42 | case ViewportType::VIEWPORT_INTERNAL: | 
|  | 43 | return "INTERNAL"; | 
|  | 44 | case ViewportType::VIEWPORT_EXTERNAL: | 
|  | 45 | return "EXTERNAL"; | 
|  | 46 | case ViewportType::VIEWPORT_VIRTUAL: | 
|  | 47 | return "VIRTUAL"; | 
|  | 48 | default: | 
|  | 49 | return "UNKNOWN"; | 
|  | 50 | } | 
|  | 51 | } | 
|  | 52 |  | 
| Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 53 | /* | 
|  | 54 | * Describes how coordinates are mapped on a physical display. | 
|  | 55 | * See com.android.server.display.DisplayViewport. | 
|  | 56 | */ | 
|  | 57 | struct DisplayViewport { | 
|  | 58 | int32_t displayId; // -1 if invalid | 
|  | 59 | int32_t orientation; | 
|  | 60 | int32_t logicalLeft; | 
|  | 61 | int32_t logicalTop; | 
|  | 62 | int32_t logicalRight; | 
|  | 63 | int32_t logicalBottom; | 
|  | 64 | int32_t physicalLeft; | 
|  | 65 | int32_t physicalTop; | 
|  | 66 | int32_t physicalRight; | 
|  | 67 | int32_t physicalBottom; | 
|  | 68 | int32_t deviceWidth; | 
|  | 69 | int32_t deviceHeight; | 
| Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 70 | std::string uniqueId; | 
| Siarhei Vishniakou | 8158e7e | 2018-10-15 14:28:20 -0700 | [diff] [blame] | 71 | // The actual (hardware) port that the associated display is connected to. | 
|  | 72 | // Not all viewports will have this specified. | 
|  | 73 | std::optional<uint8_t> physicalPort; | 
| Siarhei Vishniakou | d634392 | 2018-07-06 23:33:37 +0100 | [diff] [blame] | 74 | ViewportType type; | 
| Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 75 |  | 
|  | 76 | DisplayViewport() : | 
|  | 77 | displayId(ADISPLAY_ID_NONE), orientation(DISPLAY_ORIENTATION_0), | 
|  | 78 | logicalLeft(0), logicalTop(0), logicalRight(0), logicalBottom(0), | 
|  | 79 | physicalLeft(0), physicalTop(0), physicalRight(0), physicalBottom(0), | 
| Siarhei Vishniakou | 8158e7e | 2018-10-15 14:28:20 -0700 | [diff] [blame] | 80 | deviceWidth(0), deviceHeight(0), uniqueId(), physicalPort(std::nullopt), | 
|  | 81 | type(ViewportType::VIEWPORT_INTERNAL) { | 
| Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 82 | } | 
|  | 83 |  | 
|  | 84 | bool operator==(const DisplayViewport& other) const { | 
|  | 85 | return displayId == other.displayId | 
|  | 86 | && orientation == other.orientation | 
|  | 87 | && logicalLeft == other.logicalLeft | 
|  | 88 | && logicalTop == other.logicalTop | 
|  | 89 | && logicalRight == other.logicalRight | 
|  | 90 | && logicalBottom == other.logicalBottom | 
|  | 91 | && physicalLeft == other.physicalLeft | 
|  | 92 | && physicalTop == other.physicalTop | 
|  | 93 | && physicalRight == other.physicalRight | 
|  | 94 | && physicalBottom == other.physicalBottom | 
|  | 95 | && deviceWidth == other.deviceWidth | 
|  | 96 | && deviceHeight == other.deviceHeight | 
| Siarhei Vishniakou | d634392 | 2018-07-06 23:33:37 +0100 | [diff] [blame] | 97 | && uniqueId == other.uniqueId | 
| Siarhei Vishniakou | 8158e7e | 2018-10-15 14:28:20 -0700 | [diff] [blame] | 98 | && physicalPort == other.physicalPort | 
| Siarhei Vishniakou | d634392 | 2018-07-06 23:33:37 +0100 | [diff] [blame] | 99 | && type == other.type; | 
| Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 100 | } | 
|  | 101 |  | 
|  | 102 | bool operator!=(const DisplayViewport& other) const { | 
|  | 103 | return !(*this == other); | 
|  | 104 | } | 
|  | 105 |  | 
|  | 106 | inline bool isValid() const { | 
|  | 107 | return displayId >= 0; | 
|  | 108 | } | 
|  | 109 |  | 
|  | 110 | void setNonDisplayViewport(int32_t width, int32_t height) { | 
|  | 111 | displayId = ADISPLAY_ID_NONE; | 
|  | 112 | orientation = DISPLAY_ORIENTATION_0; | 
|  | 113 | logicalLeft = 0; | 
|  | 114 | logicalTop = 0; | 
|  | 115 | logicalRight = width; | 
|  | 116 | logicalBottom = height; | 
|  | 117 | physicalLeft = 0; | 
|  | 118 | physicalTop = 0; | 
|  | 119 | physicalRight = width; | 
|  | 120 | physicalBottom = height; | 
|  | 121 | deviceWidth = width; | 
|  | 122 | deviceHeight = height; | 
|  | 123 | uniqueId.clear(); | 
| Siarhei Vishniakou | 8158e7e | 2018-10-15 14:28:20 -0700 | [diff] [blame] | 124 | physicalPort = std::nullopt; | 
| Siarhei Vishniakou | d634392 | 2018-07-06 23:33:37 +0100 | [diff] [blame] | 125 | type = ViewportType::VIEWPORT_INTERNAL; | 
| Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 126 | } | 
| Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 127 |  | 
| Siarhei Vishniakou | d634392 | 2018-07-06 23:33:37 +0100 | [diff] [blame] | 128 | std::string toString() const { | 
| Siarhei Vishniakou | 8158e7e | 2018-10-15 14:28:20 -0700 | [diff] [blame] | 129 | return StringPrintf("Viewport %s: displayId=%d, uniqueId=%s, port=%s, orientation=%d, " | 
| Siarhei Vishniakou | d634392 | 2018-07-06 23:33:37 +0100 | [diff] [blame] | 130 | "logicalFrame=[%d, %d, %d, %d], " | 
|  | 131 | "physicalFrame=[%d, %d, %d, %d], " | 
|  | 132 | "deviceSize=[%d, %d]", | 
| Siarhei Vishniakou | 8158e7e | 2018-10-15 14:28:20 -0700 | [diff] [blame] | 133 | viewportTypeToString(type), displayId, | 
|  | 134 | uniqueId.c_str(), | 
|  | 135 | physicalPort ? StringPrintf("%" PRIu8, *physicalPort).c_str() : "<none>", | 
|  | 136 | orientation, | 
| Siarhei Vishniakou | d634392 | 2018-07-06 23:33:37 +0100 | [diff] [blame] | 137 | logicalLeft, logicalTop, | 
|  | 138 | logicalRight, logicalBottom, | 
|  | 139 | physicalLeft, physicalTop, | 
|  | 140 | physicalRight, physicalBottom, | 
|  | 141 | deviceWidth, deviceHeight); | 
|  | 142 | } | 
| Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 143 | }; | 
|  | 144 |  | 
|  | 145 | } // namespace android | 
|  | 146 |  | 
|  | 147 | #endif // _LIBINPUT_DISPLAY_VIEWPORT_H |