Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 02207005 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add uniqueId to Virtual Display and pass through to inputflinger (2/2)" into oc-dev

parents c8ddb017 06936feb
Loading
Loading
Loading
Loading
+104 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef _LIBINPUT_DISPLAY_VIEWPORT_H
#define _LIBINPUT_DISPLAY_VIEWPORT_H

#include <ui/DisplayInfo.h>
#include <input/Input.h>

namespace android {

/*
 * Describes how coordinates are mapped on a physical display.
 * See com.android.server.display.DisplayViewport.
 */
struct DisplayViewport {
    int32_t displayId; // -1 if invalid
    int32_t orientation;
    int32_t logicalLeft;
    int32_t logicalTop;
    int32_t logicalRight;
    int32_t logicalBottom;
    int32_t physicalLeft;
    int32_t physicalTop;
    int32_t physicalRight;
    int32_t physicalBottom;
    int32_t deviceWidth;
    int32_t deviceHeight;
    String8 uniqueId;

    DisplayViewport() :
            displayId(ADISPLAY_ID_NONE), orientation(DISPLAY_ORIENTATION_0),
            logicalLeft(0), logicalTop(0), logicalRight(0), logicalBottom(0),
            physicalLeft(0), physicalTop(0), physicalRight(0), physicalBottom(0),
            deviceWidth(0), deviceHeight(0) {
    }

    bool operator==(const DisplayViewport& other) const {
        return displayId == other.displayId
                && orientation == other.orientation
                && logicalLeft == other.logicalLeft
                && logicalTop == other.logicalTop
                && logicalRight == other.logicalRight
                && logicalBottom == other.logicalBottom
                && physicalLeft == other.physicalLeft
                && physicalTop == other.physicalTop
                && physicalRight == other.physicalRight
                && physicalBottom == other.physicalBottom
                && deviceWidth == other.deviceWidth
                && deviceHeight == other.deviceHeight
                && uniqueId == other.uniqueId;
    }

    bool operator!=(const DisplayViewport& other) const {
        return !(*this == other);
    }

    inline bool isValid() const {
        return displayId >= 0;
    }

    void setNonDisplayViewport(int32_t width, int32_t height) {
        displayId = ADISPLAY_ID_NONE;
        orientation = DISPLAY_ORIENTATION_0;
        logicalLeft = 0;
        logicalTop = 0;
        logicalRight = width;
        logicalBottom = height;
        physicalLeft = 0;
        physicalTop = 0;
        physicalRight = width;
        physicalBottom = height;
        deviceWidth = width;
        deviceHeight = height;
        uniqueId.clear();
    }
};

/**
 * Describes the different type of viewports supported by input flinger.
 * Keep in sync with values in InputManagerService.java.
 */
enum class ViewportType : int32_t {
    VIEWPORT_INTERNAL = 1,
    VIEWPORT_EXTERNAL = 2,
    VIEWPORT_VIRTUAL = 3,
};

} // namespace android

#endif // _LIBINPUT_DISPLAY_VIEWPORT_H
+100 −16
Original line number Diff line number Diff line
@@ -227,18 +227,65 @@ static void synthesizeButtonKeys(InputReaderContext* context, int32_t action,

// --- InputReaderConfiguration ---

bool InputReaderConfiguration::getDisplayInfo(bool external, DisplayViewport* outViewport) const {
    const DisplayViewport& viewport = external ? mExternalDisplay : mInternalDisplay;
    if (viewport.displayId >= 0) {
        *outViewport = viewport;
bool InputReaderConfiguration::getDisplayViewport(ViewportType viewportType,
        const String8* uniqueDisplayId, DisplayViewport* outViewport) const {
    const DisplayViewport* viewport = NULL;
    if (viewportType == ViewportType::VIEWPORT_VIRTUAL && uniqueDisplayId != NULL) {
        for (DisplayViewport currentViewport : mVirtualDisplays) {
            if (currentViewport.uniqueId == *uniqueDisplayId) {
                viewport = &currentViewport;
                break;
            }
        }
    } else if (viewportType == ViewportType::VIEWPORT_EXTERNAL) {
        viewport = &mExternalDisplay;
    } else if (viewportType == ViewportType::VIEWPORT_INTERNAL) {
        viewport = &mInternalDisplay;
    }

    if (viewport != NULL && viewport->displayId >= 0) {
        *outViewport = *viewport;
        return true;
    }
    return false;
}

void InputReaderConfiguration::setDisplayInfo(bool external, const DisplayViewport& viewport) {
    DisplayViewport& v = external ? mExternalDisplay : mInternalDisplay;
    v = viewport;
void InputReaderConfiguration::setPhysicalDisplayViewport(ViewportType viewportType,
        const DisplayViewport& viewport) {
    if (viewportType == ViewportType::VIEWPORT_EXTERNAL) {
        mExternalDisplay = viewport;
    } else if (viewportType == ViewportType::VIEWPORT_INTERNAL) {
        mInternalDisplay = viewport;
    }
}

void InputReaderConfiguration::setVirtualDisplayViewports(
        const Vector<DisplayViewport>& viewports) {
    mVirtualDisplays = viewports;
}

void InputReaderConfiguration::dump(String8& dump) const {
    dump.append(INDENT4 "ViewportInternal:\n");
    dumpViewport(dump, mInternalDisplay);
    dump.append(INDENT4 "ViewportExternal:\n");
    dumpViewport(dump, mExternalDisplay);
    dump.append(INDENT4 "ViewportVirtual:\n");
    for (const DisplayViewport& viewport : mVirtualDisplays) {
        dumpViewport(dump, viewport);
    }
}

void InputReaderConfiguration::dumpViewport(String8& dump, const DisplayViewport& viewport) const {
    dump.appendFormat(INDENT5 "Viewport: displayId=%d, orientation=%d, uniqueId='%s', "
            "logicalFrame=[%d, %d, %d, %d], "
            "physicalFrame=[%d, %d, %d, %d], "
            "deviceSize=[%d, %d]\n",
            viewport.displayId, viewport.orientation, viewport.uniqueId.c_str(),
            viewport.logicalLeft, viewport.logicalTop,
            viewport.logicalRight, viewport.logicalBottom,
            viewport.physicalLeft, viewport.physicalTop,
            viewport.physicalRight, viewport.physicalBottom,
            viewport.deviceWidth, viewport.deviceHeight);
}


@@ -851,6 +898,9 @@ void InputReader::dump(String8& dump) {
            mConfig.pointerGestureMovementSpeedRatio);
    dump.appendFormat(INDENT3 "ZoomSpeedRatio: %0.1f\n",
            mConfig.pointerGestureZoomSpeedRatio);

    dump.append(INDENT3 "Viewports:\n");
    mConfig.dump(dump);
}

void InputReader::monitor() {
@@ -2161,7 +2211,7 @@ void KeyboardInputMapper::configure(nsecs_t when,
    if (!changes || (changes & InputReaderConfiguration::CHANGE_DISPLAY_INFO)) {
        if (mParameters.orientationAware && mParameters.hasAssociatedDisplay) {
            DisplayViewport v;
            if (config->getDisplayInfo(false /*external*/, &v)) {
            if (config->getDisplayViewport(ViewportType::VIEWPORT_INTERNAL, NULL, &v)) {
                mOrientation = v.orientation;
            } else {
                mOrientation = DISPLAY_ORIENTATION_0;
@@ -2534,7 +2584,7 @@ void CursorInputMapper::configure(nsecs_t when,
    if (!changes || (changes & InputReaderConfiguration::CHANGE_DISPLAY_INFO)) {
        if (mParameters.orientationAware && mParameters.hasAssociatedDisplay) {
            DisplayViewport v;
            if (config->getDisplayInfo(false /*external*/, &v)) {
            if (config->getDisplayViewport(ViewportType::VIEWPORT_INTERNAL, NULL, &v)) {
                mOrientation = v.orientation;
            } else {
                mOrientation = DISPLAY_ORIENTATION_0;
@@ -2979,7 +3029,7 @@ void TouchInputMapper::populateDeviceInfo(InputDeviceInfo* info) {
}

void TouchInputMapper::dump(String8& dump) {
    dump.append(INDENT2 "Touch Input Mapper:\n");
    dump.appendFormat(INDENT2 "Touch Input Mapper (mode - %s):\n", modeToString(mDeviceMode));
    dumpParameters(dump);
    dumpVirtualKeys(dump);
    dumpRawPointerAxes(dump);
@@ -3071,6 +3121,22 @@ void TouchInputMapper::dump(String8& dump) {
    }
}

const char* TouchInputMapper::modeToString(DeviceMode deviceMode) {
    switch (deviceMode) {
    case DEVICE_MODE_DISABLED:
        return "disabled";
    case DEVICE_MODE_DIRECT:
        return "direct";
    case DEVICE_MODE_UNSCALED:
        return "unscaled";
    case DEVICE_MODE_NAVIGATION:
        return "navigation";
    case DEVICE_MODE_POINTER:
        return "pointer";
    }
    return "unknown";
}

void TouchInputMapper::configure(nsecs_t when,
        const InputReaderConfiguration* config, uint32_t changes) {
    InputMapper::configure(when, config, changes);
@@ -3196,9 +3262,11 @@ void TouchInputMapper::configureParameters() {
            || mParameters.deviceType == Parameters::DEVICE_TYPE_TOUCH_SCREEN
            || mParameters.deviceType == Parameters::DEVICE_TYPE_POINTER) {
        mParameters.hasAssociatedDisplay = true;
        mParameters.associatedDisplayIsExternal =
                mParameters.deviceType == Parameters::DEVICE_TYPE_TOUCH_SCREEN
                        && getDevice()->isExternal();
        if (mParameters.deviceType == Parameters::DEVICE_TYPE_TOUCH_SCREEN) {
            mParameters.associatedDisplayIsExternal = getDevice()->isExternal();
            getDevice()->getConfiguration().tryGetProperty(String8("touch.displayId"),
                    mParameters.uniqueDisplayId);
        }
    }

    // Initial downs on external touch devices should wake the device.
@@ -3240,9 +3308,11 @@ void TouchInputMapper::dumpParameters(String8& dump) {
        ALOG_ASSERT(false);
    }

    dump.appendFormat(INDENT4 "AssociatedDisplay: hasAssociatedDisplay=%s, isExternal=%s\n",
    dump.appendFormat(
            INDENT4 "AssociatedDisplay: hasAssociatedDisplay=%s, isExternal=%s, displayId='%s'\n",
            toString(mParameters.hasAssociatedDisplay),
            toString(mParameters.associatedDisplayIsExternal));
            toString(mParameters.associatedDisplayIsExternal),
            mParameters.uniqueDisplayId.c_str());
    dump.appendFormat(INDENT4 "OrientationAware: %s\n",
            toString(mParameters.orientationAware));
}
@@ -3318,7 +3388,21 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) {
    // Get associated display dimensions.
    DisplayViewport newViewport;
    if (mParameters.hasAssociatedDisplay) {
        if (!mConfig.getDisplayInfo(mParameters.associatedDisplayIsExternal, &newViewport)) {
        const String8* uniqueDisplayId = NULL;
        ViewportType viewportTypeToUse;

        if (mParameters.associatedDisplayIsExternal) {
            viewportTypeToUse = ViewportType::VIEWPORT_EXTERNAL;
        } else if (!mParameters.uniqueDisplayId.isEmpty()) {
            // If the IDC file specified a unique display Id, then it expects to be linked to a
            // virtual display with the same unique ID.
            uniqueDisplayId = &mParameters.uniqueDisplayId;
            viewportTypeToUse = ViewportType::VIEWPORT_VIRTUAL;
        } else {
            viewportTypeToUse = ViewportType::VIEWPORT_INTERNAL;
        }

        if (!mConfig.getDisplayViewport(viewportTypeToUse, uniqueDisplayId, &newViewport)) {
            ALOGI(INDENT "Touch device '%s' could not query the properties of its associated "
                    "display.  The device will be inoperable until the display size "
                    "becomes available.",
+13 −66
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@
#include "PointerControllerInterface.h"
#include "InputListener.h"

#include <input/DisplayViewport.h>
#include <input/Input.h>
#include <input/VelocityControl.h>
#include <input/VelocityTracker.h>
@@ -48,70 +49,6 @@ namespace android {
class InputDevice;
class InputMapper;

/*
 * Describes how coordinates are mapped on a physical display.
 * See com.android.server.display.DisplayViewport.
 */
struct DisplayViewport {
    int32_t displayId; // -1 if invalid
    int32_t orientation;
    int32_t logicalLeft;
    int32_t logicalTop;
    int32_t logicalRight;
    int32_t logicalBottom;
    int32_t physicalLeft;
    int32_t physicalTop;
    int32_t physicalRight;
    int32_t physicalBottom;
    int32_t deviceWidth;
    int32_t deviceHeight;

    DisplayViewport() :
            displayId(ADISPLAY_ID_NONE), orientation(DISPLAY_ORIENTATION_0),
            logicalLeft(0), logicalTop(0), logicalRight(0), logicalBottom(0),
            physicalLeft(0), physicalTop(0), physicalRight(0), physicalBottom(0),
            deviceWidth(0), deviceHeight(0) {
    }

    bool operator==(const DisplayViewport& other) const {
        return displayId == other.displayId
                && orientation == other.orientation
                && logicalLeft == other.logicalLeft
                && logicalTop == other.logicalTop
                && logicalRight == other.logicalRight
                && logicalBottom == other.logicalBottom
                && physicalLeft == other.physicalLeft
                && physicalTop == other.physicalTop
                && physicalRight == other.physicalRight
                && physicalBottom == other.physicalBottom
                && deviceWidth == other.deviceWidth
                && deviceHeight == other.deviceHeight;
    }

    bool operator!=(const DisplayViewport& other) const {
        return !(*this == other);
    }

    inline bool isValid() const {
        return displayId >= 0;
    }

    void setNonDisplayViewport(int32_t width, int32_t height) {
        displayId = ADISPLAY_ID_NONE;
        orientation = DISPLAY_ORIENTATION_0;
        logicalLeft = 0;
        logicalTop = 0;
        logicalRight = width;
        logicalBottom = height;
        physicalLeft = 0;
        physicalTop = 0;
        physicalRight = width;
        physicalBottom = height;
        deviceWidth = width;
        deviceHeight = height;
    }
};

/*
 * Input reader configuration.
 *
@@ -255,12 +192,19 @@ struct InputReaderConfiguration {
            pointerGestureZoomSpeedRatio(0.3f),
            showTouches(false) { }

    bool getDisplayInfo(bool external, DisplayViewport* outViewport) const;
    void setDisplayInfo(bool external, const DisplayViewport& viewport);
    bool getDisplayViewport(ViewportType viewportType, const String8* displayId,
            DisplayViewport* outViewport) const;
    void setPhysicalDisplayViewport(ViewportType viewportType, const DisplayViewport& viewport);
    void setVirtualDisplayViewports(const Vector<DisplayViewport>& viewports);


    void dump(String8& dump) const;
    void dumpViewport(String8& dump, const DisplayViewport& viewport) const;

private:
    DisplayViewport mInternalDisplay;
    DisplayViewport mExternalDisplay;
    Vector<DisplayViewport> mVirtualDisplays;
};


@@ -1341,6 +1285,7 @@ protected:
        bool associatedDisplayIsExternal;
        bool orientationAware;
        bool hasButtonUnderPad;
        String8 uniqueDisplayId;

        enum GestureMode {
            GESTURE_MODE_SINGLE_TOUCH,
@@ -1889,6 +1834,8 @@ private:
    const VirtualKey* findVirtualKeyHit(int32_t x, int32_t y);

    static void assignPointerIds(const RawState* last, RawState* current);

    const char* modeToString(DeviceMode deviceMode);
};


+168 −21

File changed.

Preview size limit exceeded, changes collapsed.

+1 −1
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ namespace {
// use it to look up device configuration, so it must be unique. Vendor and
// product values must be 0 to indicate an internal device and prevent a
// similar lookup that could conflict with a physical device.
static const char* const kDeviceNameFormat = "vr virtual touchpad %d";
static const char* const kDeviceNameFormat = "vr-virtual-touchpad-%d";
static constexpr int16_t kDeviceBusType = BUS_VIRTUAL;
static constexpr int16_t kDeviceVendor = 0;
static constexpr int16_t kDeviceProduct = 0;
Loading