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

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

Merge "InputDispatcher: Remove transform for non-pointer events" into sc-dev

parents 30c6ac31 bd52771b
Loading
Loading
Loading
Loading
+4 −3
Original line number Original line Diff line number Diff line
@@ -332,10 +332,11 @@ static std::unique_ptr<DispatchEntry> createDispatchEntry(const InputTarget& inp
                                                          int32_t inputTargetFlags) {
                                                          int32_t inputTargetFlags) {
    if (eventEntry->type == EventEntry::Type::MOTION) {
    if (eventEntry->type == EventEntry::Type::MOTION) {
        const MotionEntry& motionEntry = static_cast<const MotionEntry&>(*eventEntry);
        const MotionEntry& motionEntry = static_cast<const MotionEntry&>(*eventEntry);
        if (motionEntry.source & AINPUT_SOURCE_CLASS_JOYSTICK) {
        if ((motionEntry.source & AINPUT_SOURCE_CLASS_POINTER) == 0) {
            const ui::Transform identityTransform;
            const ui::Transform identityTransform;
            // Use identity transform for joystick events events because they don't depend on
            // Use identity transform for events that are not pointer events because their axes
            // the window info
            // values do not represent on-screen coordinates, so they should not have any window
            // transformations applied to them.
            return std::make_unique<DispatchEntry>(eventEntry, inputTargetFlags, identityTransform,
            return std::make_unique<DispatchEntry>(eventEntry, inputTargetFlags, identityTransform,
                                                   1.0f /*globalScaleFactor*/);
                                                   1.0f /*globalScaleFactor*/);
        }
        }
+34 −21
Original line number Original line Diff line number Diff line
@@ -2183,7 +2183,7 @@ TEST_F(InputDispatcherTest, VerifyInputEvent_MotionEvent) {
    EXPECT_EQ(motionArgs.buttonState, verifiedMotion.buttonState);
    EXPECT_EQ(motionArgs.buttonState, verifiedMotion.buttonState);
}
}


TEST_F(InputDispatcherTest, NonPointerMotionEvent_JoystickNotTransformed) {
TEST_F(InputDispatcherTest, NonPointerMotionEvent_NotTransformed) {
    std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
    std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
    sp<FakeWindowHandle> window =
    sp<FakeWindowHandle> window =
            new FakeWindowHandle(application, mDispatcher, "Test window", ADISPLAY_ID_DEFAULT);
            new FakeWindowHandle(application, mDispatcher, "Test window", ADISPLAY_ID_DEFAULT);
@@ -2203,11 +2203,15 @@ TEST_F(InputDispatcherTest, NonPointerMotionEvent_JoystickNotTransformed) {
    // Second, we consume focus event if it is right or wrong according to onFocusChangedLocked.
    // Second, we consume focus event if it is right or wrong according to onFocusChangedLocked.
    window->consumeFocusEvent(true);
    window->consumeFocusEvent(true);


    NotifyMotionArgs motionArgs = generateMotionArgs(AMOTION_EVENT_ACTION_MOVE,
    constexpr const std::array nonPointerSources = {AINPUT_SOURCE_TRACKBALL,
                                                     AINPUT_SOURCE_JOYSTICK, ADISPLAY_ID_DEFAULT);
                                                    AINPUT_SOURCE_MOUSE_RELATIVE,
                                                    AINPUT_SOURCE_JOYSTICK};
    for (const int source : nonPointerSources) {
        // Notify motion with a non-pointer source.
        NotifyMotionArgs motionArgs =
                generateMotionArgs(AMOTION_EVENT_ACTION_MOVE, source, ADISPLAY_ID_DEFAULT);
        mDispatcher->notifyMotion(&motionArgs);
        mDispatcher->notifyMotion(&motionArgs);


    // Third, we consume motion event.
        InputEvent* event = window->consume();
        InputEvent* event = window->consume();
        ASSERT_NE(event, nullptr);
        ASSERT_NE(event, nullptr);
        ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, event->getType())
        ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, event->getType())
@@ -2215,16 +2219,25 @@ TEST_F(InputDispatcherTest, NonPointerMotionEvent_JoystickNotTransformed) {
                << " event, got " << inputEventTypeToString(event->getType()) << " event";
                << " event, got " << inputEventTypeToString(event->getType()) << " event";


        const MotionEvent& motionEvent = static_cast<const MotionEvent&>(*event);
        const MotionEvent& motionEvent = static_cast<const MotionEvent&>(*event);
    EXPECT_EQ(AINPUT_EVENT_TYPE_MOTION, motionEvent.getAction());
        EXPECT_EQ(AMOTION_EVENT_ACTION_MOVE, motionEvent.getAction());
        EXPECT_EQ(motionArgs.pointerCount, motionEvent.getPointerCount());


        float expectedX = motionArgs.pointerCoords[0].getX();
        float expectedX = motionArgs.pointerCoords[0].getX();
        float expectedY = motionArgs.pointerCoords[0].getY();
        float expectedY = motionArgs.pointerCoords[0].getY();


    // Finally we test if the axis values from the final motion event are not transformed
        // Ensure the axis values from the final motion event are not transformed.
    EXPECT_EQ(expectedX, motionEvent.getX(0)) << "expected " << expectedX << " for x coord of "
        EXPECT_EQ(expectedX, motionEvent.getX(0))
                                              << name.c_str() << ", got " << motionEvent.getX(0);
                << "expected " << expectedX << " for x coord of " << name.c_str() << ", got "
    EXPECT_EQ(expectedY, motionEvent.getY(0)) << "expected " << expectedY << " for y coord of "
                << motionEvent.getX(0);
                                              << name.c_str() << ", got " << motionEvent.getY(0);
        EXPECT_EQ(expectedY, motionEvent.getY(0))
                << "expected " << expectedY << " for y coord of " << name.c_str() << ", got "
                << motionEvent.getY(0);
        // Ensure the raw and transformed axis values for the motion event are the same.
        EXPECT_EQ(motionEvent.getRawX(0), motionEvent.getX(0))
                << "expected raw and transformed X-axis values to be equal";
        EXPECT_EQ(motionEvent.getRawY(0), motionEvent.getY(0))
                << "expected raw and transformed Y-axis values to be equal";
    }
}
}


/**
/**