Home | History | Annotate | Download | only in input
      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 
     20 #include <ui/DisplayInfo.h>
     21 #include <input/Input.h>
     22 
     23 namespace android {
     24 
     25 /*
     26  * Describes how coordinates are mapped on a physical display.
     27  * See com.android.server.display.DisplayViewport.
     28  */
     29 struct DisplayViewport {
     30     int32_t displayId; // -1 if invalid
     31     int32_t orientation;
     32     int32_t logicalLeft;
     33     int32_t logicalTop;
     34     int32_t logicalRight;
     35     int32_t logicalBottom;
     36     int32_t physicalLeft;
     37     int32_t physicalTop;
     38     int32_t physicalRight;
     39     int32_t physicalBottom;
     40     int32_t deviceWidth;
     41     int32_t deviceHeight;
     42     String8 uniqueId;
     43 
     44     DisplayViewport() :
     45             displayId(ADISPLAY_ID_NONE), orientation(DISPLAY_ORIENTATION_0),
     46             logicalLeft(0), logicalTop(0), logicalRight(0), logicalBottom(0),
     47             physicalLeft(0), physicalTop(0), physicalRight(0), physicalBottom(0),
     48             deviceWidth(0), deviceHeight(0) {
     49     }
     50 
     51     bool operator==(const DisplayViewport& other) const {
     52         return displayId == other.displayId
     53                 && orientation == other.orientation
     54                 && logicalLeft == other.logicalLeft
     55                 && logicalTop == other.logicalTop
     56                 && logicalRight == other.logicalRight
     57                 && logicalBottom == other.logicalBottom
     58                 && physicalLeft == other.physicalLeft
     59                 && physicalTop == other.physicalTop
     60                 && physicalRight == other.physicalRight
     61                 && physicalBottom == other.physicalBottom
     62                 && deviceWidth == other.deviceWidth
     63                 && deviceHeight == other.deviceHeight
     64                 && uniqueId == other.uniqueId;
     65     }
     66 
     67     bool operator!=(const DisplayViewport& other) const {
     68         return !(*this == other);
     69     }
     70 
     71     inline bool isValid() const {
     72         return displayId >= 0;
     73     }
     74 
     75     void setNonDisplayViewport(int32_t width, int32_t height) {
     76         displayId = ADISPLAY_ID_NONE;
     77         orientation = DISPLAY_ORIENTATION_0;
     78         logicalLeft = 0;
     79         logicalTop = 0;
     80         logicalRight = width;
     81         logicalBottom = height;
     82         physicalLeft = 0;
     83         physicalTop = 0;
     84         physicalRight = width;
     85         physicalBottom = height;
     86         deviceWidth = width;
     87         deviceHeight = height;
     88         uniqueId.clear();
     89     }
     90 };
     91 
     92 /**
     93  * Describes the different type of viewports supported by input flinger.
     94  * Keep in sync with values in InputManagerService.java.
     95  */
     96 enum class ViewportType : int32_t {
     97     VIEWPORT_INTERNAL = 1,
     98     VIEWPORT_EXTERNAL = 2,
     99     VIEWPORT_VIRTUAL = 3,
    100 };
    101 
    102 } // namespace android
    103 
    104 #endif // _LIBINPUT_DISPLAY_VIEWPORT_H
    105