1*38e8c45fSAndroid Build Coastguard Worker /* 2*38e8c45fSAndroid Build Coastguard Worker * Copyright (C) 2017 The Android Open Source Project 3*38e8c45fSAndroid Build Coastguard Worker * 4*38e8c45fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*38e8c45fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*38e8c45fSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*38e8c45fSAndroid Build Coastguard Worker * 8*38e8c45fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*38e8c45fSAndroid Build Coastguard Worker * 10*38e8c45fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*38e8c45fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*38e8c45fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*38e8c45fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*38e8c45fSAndroid Build Coastguard Worker * limitations under the License. 15*38e8c45fSAndroid Build Coastguard Worker */ 16*38e8c45fSAndroid Build Coastguard Worker 17*38e8c45fSAndroid Build Coastguard Worker #pragma once 18*38e8c45fSAndroid Build Coastguard Worker 19*38e8c45fSAndroid Build Coastguard Worker #include <android-base/stringprintf.h> 20*38e8c45fSAndroid Build Coastguard Worker #include <ftl/enum.h> 21*38e8c45fSAndroid Build Coastguard Worker #include <ftl/string.h> 22*38e8c45fSAndroid Build Coastguard Worker #include <input/Input.h> 23*38e8c45fSAndroid Build Coastguard Worker #include <ui/Rotation.h> 24*38e8c45fSAndroid Build Coastguard Worker 25*38e8c45fSAndroid Build Coastguard Worker #include <cinttypes> 26*38e8c45fSAndroid Build Coastguard Worker #include <optional> 27*38e8c45fSAndroid Build Coastguard Worker 28*38e8c45fSAndroid Build Coastguard Worker using android::base::StringPrintf; 29*38e8c45fSAndroid Build Coastguard Worker 30*38e8c45fSAndroid Build Coastguard Worker namespace android { 31*38e8c45fSAndroid Build Coastguard Worker 32*38e8c45fSAndroid Build Coastguard Worker /** 33*38e8c45fSAndroid Build Coastguard Worker * Describes the different type of viewports supported by input flinger. 34*38e8c45fSAndroid Build Coastguard Worker * Keep in sync with values in InputManagerService.java. 35*38e8c45fSAndroid Build Coastguard Worker */ 36*38e8c45fSAndroid Build Coastguard Worker enum class ViewportType : int32_t { 37*38e8c45fSAndroid Build Coastguard Worker INTERNAL = 1, 38*38e8c45fSAndroid Build Coastguard Worker EXTERNAL = 2, 39*38e8c45fSAndroid Build Coastguard Worker VIRTUAL = 3, 40*38e8c45fSAndroid Build Coastguard Worker 41*38e8c45fSAndroid Build Coastguard Worker ftl_last = VIRTUAL 42*38e8c45fSAndroid Build Coastguard Worker }; 43*38e8c45fSAndroid Build Coastguard Worker 44*38e8c45fSAndroid Build Coastguard Worker /* 45*38e8c45fSAndroid Build Coastguard Worker * Describes how coordinates are mapped on a physical display. 46*38e8c45fSAndroid Build Coastguard Worker * See com.android.server.display.DisplayViewport. 47*38e8c45fSAndroid Build Coastguard Worker */ 48*38e8c45fSAndroid Build Coastguard Worker struct DisplayViewport { 49*38e8c45fSAndroid Build Coastguard Worker ui::LogicalDisplayId displayId; 50*38e8c45fSAndroid Build Coastguard Worker ui::Rotation orientation; 51*38e8c45fSAndroid Build Coastguard Worker int32_t logicalLeft; 52*38e8c45fSAndroid Build Coastguard Worker int32_t logicalTop; 53*38e8c45fSAndroid Build Coastguard Worker int32_t logicalRight; 54*38e8c45fSAndroid Build Coastguard Worker int32_t logicalBottom; 55*38e8c45fSAndroid Build Coastguard Worker int32_t physicalLeft; 56*38e8c45fSAndroid Build Coastguard Worker int32_t physicalTop; 57*38e8c45fSAndroid Build Coastguard Worker int32_t physicalRight; 58*38e8c45fSAndroid Build Coastguard Worker int32_t physicalBottom; 59*38e8c45fSAndroid Build Coastguard Worker int32_t deviceWidth; 60*38e8c45fSAndroid Build Coastguard Worker int32_t deviceHeight; 61*38e8c45fSAndroid Build Coastguard Worker bool isActive; 62*38e8c45fSAndroid Build Coastguard Worker std::string uniqueId; 63*38e8c45fSAndroid Build Coastguard Worker // The actual (hardware) port that the associated display is connected to. 64*38e8c45fSAndroid Build Coastguard Worker // Not all viewports will have this specified. 65*38e8c45fSAndroid Build Coastguard Worker std::optional<uint8_t> physicalPort; 66*38e8c45fSAndroid Build Coastguard Worker ViewportType type; 67*38e8c45fSAndroid Build Coastguard Worker DisplayViewportDisplayViewport68*38e8c45fSAndroid Build Coastguard Worker DisplayViewport() 69*38e8c45fSAndroid Build Coastguard Worker : displayId(ui::LogicalDisplayId::INVALID), 70*38e8c45fSAndroid Build Coastguard Worker orientation(ui::ROTATION_0), 71*38e8c45fSAndroid Build Coastguard Worker logicalLeft(0), 72*38e8c45fSAndroid Build Coastguard Worker logicalTop(0), 73*38e8c45fSAndroid Build Coastguard Worker logicalRight(0), 74*38e8c45fSAndroid Build Coastguard Worker logicalBottom(0), 75*38e8c45fSAndroid Build Coastguard Worker physicalLeft(0), 76*38e8c45fSAndroid Build Coastguard Worker physicalTop(0), 77*38e8c45fSAndroid Build Coastguard Worker physicalRight(0), 78*38e8c45fSAndroid Build Coastguard Worker physicalBottom(0), 79*38e8c45fSAndroid Build Coastguard Worker deviceWidth(0), 80*38e8c45fSAndroid Build Coastguard Worker deviceHeight(0), 81*38e8c45fSAndroid Build Coastguard Worker isActive(false), 82*38e8c45fSAndroid Build Coastguard Worker uniqueId(), 83*38e8c45fSAndroid Build Coastguard Worker physicalPort(std::nullopt), 84*38e8c45fSAndroid Build Coastguard Worker type(ViewportType::INTERNAL) {} 85*38e8c45fSAndroid Build Coastguard Worker 86*38e8c45fSAndroid Build Coastguard Worker bool operator==(const DisplayViewport& other) const { 87*38e8c45fSAndroid Build Coastguard Worker return displayId == other.displayId && orientation == other.orientation && 88*38e8c45fSAndroid Build Coastguard Worker logicalLeft == other.logicalLeft && logicalTop == other.logicalTop && 89*38e8c45fSAndroid Build Coastguard Worker logicalRight == other.logicalRight && logicalBottom == other.logicalBottom && 90*38e8c45fSAndroid Build Coastguard Worker physicalLeft == other.physicalLeft && physicalTop == other.physicalTop && 91*38e8c45fSAndroid Build Coastguard Worker physicalRight == other.physicalRight && physicalBottom == other.physicalBottom && 92*38e8c45fSAndroid Build Coastguard Worker deviceWidth == other.deviceWidth && deviceHeight == other.deviceHeight && 93*38e8c45fSAndroid Build Coastguard Worker isActive == other.isActive && uniqueId == other.uniqueId && 94*38e8c45fSAndroid Build Coastguard Worker physicalPort == other.physicalPort && type == other.type; 95*38e8c45fSAndroid Build Coastguard Worker } 96*38e8c45fSAndroid Build Coastguard Worker 97*38e8c45fSAndroid Build Coastguard Worker bool operator!=(const DisplayViewport& other) const { 98*38e8c45fSAndroid Build Coastguard Worker return !(*this == other); 99*38e8c45fSAndroid Build Coastguard Worker } 100*38e8c45fSAndroid Build Coastguard Worker isValidDisplayViewport101*38e8c45fSAndroid Build Coastguard Worker inline bool isValid() const { return displayId.isValid(); } 102*38e8c45fSAndroid Build Coastguard Worker setNonDisplayViewportDisplayViewport103*38e8c45fSAndroid Build Coastguard Worker void setNonDisplayViewport(int32_t width, int32_t height) { 104*38e8c45fSAndroid Build Coastguard Worker displayId = ui::LogicalDisplayId::INVALID; 105*38e8c45fSAndroid Build Coastguard Worker orientation = ui::ROTATION_0; 106*38e8c45fSAndroid Build Coastguard Worker logicalLeft = 0; 107*38e8c45fSAndroid Build Coastguard Worker logicalTop = 0; 108*38e8c45fSAndroid Build Coastguard Worker logicalRight = width; 109*38e8c45fSAndroid Build Coastguard Worker logicalBottom = height; 110*38e8c45fSAndroid Build Coastguard Worker physicalLeft = 0; 111*38e8c45fSAndroid Build Coastguard Worker physicalTop = 0; 112*38e8c45fSAndroid Build Coastguard Worker physicalRight = width; 113*38e8c45fSAndroid Build Coastguard Worker physicalBottom = height; 114*38e8c45fSAndroid Build Coastguard Worker deviceWidth = width; 115*38e8c45fSAndroid Build Coastguard Worker deviceHeight = height; 116*38e8c45fSAndroid Build Coastguard Worker isActive = true; 117*38e8c45fSAndroid Build Coastguard Worker uniqueId.clear(); 118*38e8c45fSAndroid Build Coastguard Worker physicalPort = std::nullopt; 119*38e8c45fSAndroid Build Coastguard Worker type = ViewportType::INTERNAL; 120*38e8c45fSAndroid Build Coastguard Worker } 121*38e8c45fSAndroid Build Coastguard Worker toStringDisplayViewport122*38e8c45fSAndroid Build Coastguard Worker std::string toString() const { 123*38e8c45fSAndroid Build Coastguard Worker return StringPrintf("Viewport %s: displayId=%s, uniqueId=%s, port=%s, orientation=%d, " 124*38e8c45fSAndroid Build Coastguard Worker "logicalFrame=[%d, %d, %d, %d], " 125*38e8c45fSAndroid Build Coastguard Worker "physicalFrame=[%d, %d, %d, %d], " 126*38e8c45fSAndroid Build Coastguard Worker "deviceSize=[%d, %d], " 127*38e8c45fSAndroid Build Coastguard Worker "isActive=[%d]", 128*38e8c45fSAndroid Build Coastguard Worker ftl::enum_string(type).c_str(), displayId.toString().c_str(), 129*38e8c45fSAndroid Build Coastguard Worker uniqueId.c_str(), 130*38e8c45fSAndroid Build Coastguard Worker physicalPort ? ftl::to_string(*physicalPort).c_str() : "<none>", 131*38e8c45fSAndroid Build Coastguard Worker static_cast<int>(orientation), logicalLeft, logicalTop, logicalRight, 132*38e8c45fSAndroid Build Coastguard Worker logicalBottom, physicalLeft, physicalTop, physicalRight, physicalBottom, 133*38e8c45fSAndroid Build Coastguard Worker deviceWidth, deviceHeight, isActive); 134*38e8c45fSAndroid Build Coastguard Worker } 135*38e8c45fSAndroid Build Coastguard Worker }; 136*38e8c45fSAndroid Build Coastguard Worker 137*38e8c45fSAndroid Build Coastguard Worker } // namespace android 138