| 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> | 
|  | 23 |  | 
| Siarhei Vishniakou | d634392 | 2018-07-06 23:33:37 +0100 | [diff] [blame] | 24 | using android::base::StringPrintf; | 
|  | 25 |  | 
| Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 26 | namespace android { | 
|  | 27 |  | 
| Siarhei Vishniakou | d634392 | 2018-07-06 23:33:37 +0100 | [diff] [blame] | 28 | /** | 
|  | 29 | * Describes the different type of viewports supported by input flinger. | 
|  | 30 | * Keep in sync with values in InputManagerService.java. | 
|  | 31 | */ | 
|  | 32 | enum class ViewportType : int32_t { | 
|  | 33 | VIEWPORT_INTERNAL = 1, | 
|  | 34 | VIEWPORT_EXTERNAL = 2, | 
|  | 35 | VIEWPORT_VIRTUAL = 3, | 
|  | 36 | }; | 
|  | 37 |  | 
|  | 38 | static 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 Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 51 | /* | 
|  | 52 | * Describes how coordinates are mapped on a physical display. | 
|  | 53 | * See com.android.server.display.DisplayViewport. | 
|  | 54 | */ | 
|  | 55 | struct 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 Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 68 | std::string uniqueId; | 
| Siarhei Vishniakou | d634392 | 2018-07-06 23:33:37 +0100 | [diff] [blame] | 69 | ViewportType type; | 
| Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 70 |  | 
|  | 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 Vishniakou | d634392 | 2018-07-06 23:33:37 +0100 | [diff] [blame] | 75 | deviceWidth(0), deviceHeight(0), uniqueId(), type(ViewportType::VIEWPORT_INTERNAL) { | 
| Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 76 | } | 
|  | 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 Vishniakou | d634392 | 2018-07-06 23:33:37 +0100 | [diff] [blame] | 91 | && uniqueId == other.uniqueId | 
|  | 92 | && type == other.type; | 
| Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 93 | } | 
|  | 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 Vishniakou | d634392 | 2018-07-06 23:33:37 +0100 | [diff] [blame] | 117 | type = ViewportType::VIEWPORT_INTERNAL; | 
| Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 118 | } | 
| Santos Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 119 |  | 
| Siarhei Vishniakou | d634392 | 2018-07-06 23:33:37 +0100 | [diff] [blame] | 120 | 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 Cordon | fa5cf46 | 2017-04-05 10:37:00 -0700 | [diff] [blame] | 133 | }; | 
|  | 134 |  | 
|  | 135 | } // namespace android | 
|  | 136 |  | 
|  | 137 | #endif // _LIBINPUT_DISPLAY_VIEWPORT_H |