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

Commit 117b7579 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Create viewports in a separate function

This will allow the caller to re-use the viewport object for other
purposes.

That said, the whole thing is poorly designed, and there are many places
where we are mixing viewports and display ids, and not just in tests,
but also in production. For example, InputDevice has the concept of
associating with displays, but mappers also have a way to keep track of
their own associations.

The current approach allows us to slightly simplify some of the current
and new tests written in InputReader area.

Bug: 378308551
Test: TEST=inputflinger_tests; m $TEST && $ANDROID_HOST_OUT/nativetest64/$TEST/$TEST
Flag: TEST_ONLY
Change-Id: Ic9b476f3e991d128e429afcc096c9dc12e68f01e
parent 12c5cc40
Loading
Loading
Loading
Loading
+24 −27
Original line number Diff line number Diff line
@@ -31,6 +31,30 @@ static const int HW_TIMEOUT_MULTIPLIER = base::GetIntProperty("ro.hw_timeout_mul

} // namespace

DisplayViewport createViewport(ui::LogicalDisplayId displayId, int32_t width, int32_t height,
                               ui::Rotation orientation, bool isActive, const std::string& uniqueId,
                               std::optional<uint8_t> physicalPort, ViewportType type) {
    const bool isRotated = orientation == ui::ROTATION_90 || orientation == ui::ROTATION_270;
    DisplayViewport v;
    v.displayId = displayId;
    v.orientation = orientation;
    v.logicalLeft = 0;
    v.logicalTop = 0;
    v.logicalRight = isRotated ? height : width;
    v.logicalBottom = isRotated ? width : height;
    v.physicalLeft = 0;
    v.physicalTop = 0;
    v.physicalRight = isRotated ? height : width;
    v.physicalBottom = isRotated ? width : height;
    v.deviceWidth = isRotated ? height : width;
    v.deviceHeight = isRotated ? width : height;
    v.isActive = isActive;
    v.uniqueId = uniqueId;
    v.physicalPort = physicalPort;
    v.type = type;
    return v;
};

void FakeInputReaderPolicy::assertInputDevicesChanged() {
    waitForInputDevices(
            [](bool devicesChanged) {
@@ -115,33 +139,6 @@ void FakeInputReaderPolicy::addDisplayViewport(DisplayViewport viewport) {
    mConfig.setDisplayViewports(mViewports);
}

void FakeInputReaderPolicy::addDisplayViewport(ui::LogicalDisplayId displayId, int32_t width,
                                               int32_t height, ui::Rotation orientation,
                                               bool isActive, const std::string& uniqueId,
                                               std::optional<uint8_t> physicalPort,
                                               ViewportType type) {
    const bool isRotated = orientation == ui::ROTATION_90 || orientation == ui::ROTATION_270;
    DisplayViewport v;
    v.displayId = displayId;
    v.orientation = orientation;
    v.logicalLeft = 0;
    v.logicalTop = 0;
    v.logicalRight = isRotated ? height : width;
    v.logicalBottom = isRotated ? width : height;
    v.physicalLeft = 0;
    v.physicalTop = 0;
    v.physicalRight = isRotated ? height : width;
    v.physicalBottom = isRotated ? width : height;
    v.deviceWidth = isRotated ? height : width;
    v.deviceHeight = isRotated ? width : height;
    v.isActive = isActive;
    v.uniqueId = uniqueId;
    v.physicalPort = physicalPort;
    v.type = type;

    addDisplayViewport(v);
}

bool FakeInputReaderPolicy::updateViewport(const DisplayViewport& viewport) {
    size_t count = mViewports.size();
    for (size_t i = 0; i < count; i++) {
+4 −3
Original line number Diff line number Diff line
@@ -31,6 +31,10 @@

namespace android {

DisplayViewport createViewport(ui::LogicalDisplayId displayId, int32_t width, int32_t height,
                               ui::Rotation orientation, bool isActive, const std::string& uniqueId,
                               std::optional<uint8_t> physicalPort, ViewportType type);

class FakeInputReaderPolicy : public InputReaderPolicyInterface {
protected:
    virtual ~FakeInputReaderPolicy() {}
@@ -50,9 +54,6 @@ public:
    std::optional<DisplayViewport> getDisplayViewportByType(ViewportType type) const;
    std::optional<DisplayViewport> getDisplayViewportByPort(uint8_t displayPort) const;
    void addDisplayViewport(DisplayViewport viewport);
    void addDisplayViewport(ui::LogicalDisplayId displayId, int32_t width, int32_t height,
                            ui::Rotation orientation, bool isActive, const std::string& uniqueId,
                            std::optional<uint8_t> physicalPort, ViewportType type);
    bool updateViewport(const DisplayViewport& viewport);
    void addExcludedDeviceName(const std::string& deviceName);
    void addInputPortAssociation(const std::string& inputPort, uint8_t displayPort);
+4 −2
Original line number Diff line number Diff line
@@ -186,8 +186,10 @@ void InputMapperTest::setDisplayInfoAndReconfigure(ui::LogicalDisplayId displayI
                                                   const std::string& uniqueId,
                                                   std::optional<uint8_t> physicalPort,
                                                   ViewportType viewportType) {
    mFakePolicy->addDisplayViewport(displayId, width, height, orientation, /* isActive= */ true,
                                    uniqueId, physicalPort, viewportType);
    DisplayViewport viewport =
            createViewport(displayId, width, height, orientation, /* isActive= */ true, uniqueId,
                           physicalPort, viewportType);
    mFakePolicy->addDisplayViewport(viewport);
    configureDevice(InputReaderConfiguration::Change::DISPLAY_INFO);
}

+137 −126

File changed.

Preview size limit exceeded, changes collapsed.

+4 −3
Original line number Diff line number Diff line
@@ -109,9 +109,10 @@ protected:
        mockSlotValues({});

        mFakePolicy->setDefaultPointerDisplayId(DISPLAY_ID);
        mFakePolicy->addDisplayViewport(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, ui::ROTATION_0,
                                        /*isActive=*/true, "local:0", NO_PORT,
                                        ViewportType::INTERNAL);
        DisplayViewport internalViewport =
                createViewport(DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, ui::ROTATION_0,
                               /*isActive=*/true, "local:0", NO_PORT, ViewportType::INTERNAL);
        mFakePolicy->addDisplayViewport(internalViewport);
        mMapper = createInputMapper<MultiTouchInputMapper>(*mDeviceContext,
                                                           mFakePolicy->getReaderConfiguration());
    }
Loading