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

Commit 27dd43be authored by Prabir Pradhan's avatar Prabir Pradhan Committed by Android (Google) Code Review
Browse files

Merge "Mouse: Cleanup after PointerChoreographer refactor" into main

parents c1240726 0b4891a9
Loading
Loading
Loading
Loading
+4 −57
Original line number Original line Diff line number Diff line
@@ -40,8 +40,6 @@ namespace android {
// The default velocity control parameters that has no effect.
// The default velocity control parameters that has no effect.
static const VelocityControlParameters FLAT_VELOCITY_CONTROL_PARAMS{};
static const VelocityControlParameters FLAT_VELOCITY_CONTROL_PARAMS{};


static const bool ENABLE_POINTER_CHOREOGRAPHER = input_flags::enable_pointer_choreographer();

// --- CursorMotionAccumulator ---
// --- CursorMotionAccumulator ---


CursorMotionAccumulator::CursorMotionAccumulator() {
CursorMotionAccumulator::CursorMotionAccumulator() {
@@ -78,22 +76,10 @@ void CursorMotionAccumulator::finishSync() {


CursorInputMapper::CursorInputMapper(InputDeviceContext& deviceContext,
CursorInputMapper::CursorInputMapper(InputDeviceContext& deviceContext,
                                     const InputReaderConfiguration& readerConfig)
                                     const InputReaderConfiguration& readerConfig)
      : CursorInputMapper(deviceContext, readerConfig, ENABLE_POINTER_CHOREOGRAPHER) {}

CursorInputMapper::CursorInputMapper(InputDeviceContext& deviceContext,
                                     const InputReaderConfiguration& readerConfig,
                                     bool enablePointerChoreographer)
      : InputMapper(deviceContext, readerConfig),
      : InputMapper(deviceContext, readerConfig),
        mLastEventTime(std::numeric_limits<nsecs_t>::min()),
        mLastEventTime(std::numeric_limits<nsecs_t>::min()),
        mEnablePointerChoreographer(enablePointerChoreographer),
        mEnableNewMousePointerBallistics(input_flags::enable_new_mouse_pointer_ballistics()) {}
        mEnableNewMousePointerBallistics(input_flags::enable_new_mouse_pointer_ballistics()) {}


CursorInputMapper::~CursorInputMapper() {
    if (mPointerController != nullptr) {
        mPointerController->fade(PointerControllerInterface::Transition::IMMEDIATE);
    }
}

uint32_t CursorInputMapper::getSources() const {
uint32_t CursorInputMapper::getSources() const {
    return mSource;
    return mSource;
}
}
@@ -304,22 +290,6 @@ std::list<NotifyArgs> CursorInputMapper::sync(nsecs_t when, nsecs_t readTime) {
    float xCursorPosition = AMOTION_EVENT_INVALID_CURSOR_POSITION;
    float xCursorPosition = AMOTION_EVENT_INVALID_CURSOR_POSITION;
    float yCursorPosition = AMOTION_EVENT_INVALID_CURSOR_POSITION;
    float yCursorPosition = AMOTION_EVENT_INVALID_CURSOR_POSITION;
    if (mSource == AINPUT_SOURCE_MOUSE) {
    if (mSource == AINPUT_SOURCE_MOUSE) {
        if (!mEnablePointerChoreographer) {
            if (moved || scrolled || buttonsChanged) {
                mPointerController->setPresentation(
                        PointerControllerInterface::Presentation::POINTER);

                if (moved) {
                    mPointerController->move(deltaX, deltaY);
                }
                mPointerController->unfade(PointerControllerInterface::Transition::IMMEDIATE);
            }

            std::tie(xCursorPosition, yCursorPosition) = mPointerController->getPosition();

            pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_X, xCursorPosition);
            pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_Y, yCursorPosition);
        }
        pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X, deltaX);
        pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X, deltaX);
        pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y, deltaY);
        pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y, deltaY);
    } else {
    } else {
@@ -470,7 +440,6 @@ void CursorInputMapper::configureBasicParams() {
            mYPrecision = 1.0f;
            mYPrecision = 1.0f;
            mXScale = 1.0f;
            mXScale = 1.0f;
            mYScale = 1.0f;
            mYScale = 1.0f;
            mPointerController = getContext()->getPointerController(getDeviceId());
            break;
            break;
        case Parameters::Mode::NAVIGATION:
        case Parameters::Mode::NAVIGATION:
            mSource = AINPUT_SOURCE_TRACKBALL;
            mSource = AINPUT_SOURCE_TRACKBALL;
@@ -490,8 +459,6 @@ void CursorInputMapper::configureOnPointerCapture(const InputReaderConfiguration
        if (mParameters.mode == Parameters::Mode::POINTER) {
        if (mParameters.mode == Parameters::Mode::POINTER) {
            mParameters.mode = Parameters::Mode::POINTER_RELATIVE;
            mParameters.mode = Parameters::Mode::POINTER_RELATIVE;
            mSource = AINPUT_SOURCE_MOUSE_RELATIVE;
            mSource = AINPUT_SOURCE_MOUSE_RELATIVE;
            // Keep PointerController around in order to preserve the pointer position.
            mPointerController->fade(PointerControllerInterface::Transition::IMMEDIATE);
        } else {
        } else {
            ALOGE("Cannot request pointer capture, device is not in MODE_POINTER");
            ALOGE("Cannot request pointer capture, device is not in MODE_POINTER");
        }
        }
@@ -546,32 +513,12 @@ void CursorInputMapper::configureOnChangeDisplayInfo(const InputReaderConfigurat
        // Only generate events for the associated display.
        // Only generate events for the associated display.
        mDisplayId = assocViewport->displayId;
        mDisplayId = assocViewport->displayId;
        resolvedViewport = *assocViewport;
        resolvedViewport = *assocViewport;
        if (!mEnablePointerChoreographer) {
            const bool mismatchedPointerDisplay =
                    isPointer && (assocViewport->displayId != mPointerController->getDisplayId());
            if (mismatchedPointerDisplay) {
                // This device's associated display doesn't match PointerController's current
                // display. Do not associate it with any display.
                mDisplayId.reset();
            }
        }
    } else if (isPointer) {
    } else if (isPointer) {
        // The InputDevice is not associated with a viewport, but it controls the mouse pointer.
        // The InputDevice is not associated with a viewport, but it controls the mouse pointer.
        if (mEnablePointerChoreographer) {
        // Always use DISPLAY_ID_NONE for mouse events.
        // Always use DISPLAY_ID_NONE for mouse events.
        // PointerChoreographer will make it target the correct the displayId later.
        // PointerChoreographer will make it target the correct the displayId later.
        resolvedViewport = getContext()->getPolicy()->getPointerViewportForAssociatedDisplay();
        resolvedViewport = getContext()->getPolicy()->getPointerViewportForAssociatedDisplay();
        mDisplayId = resolvedViewport ? std::make_optional(ADISPLAY_ID_NONE) : std::nullopt;
        mDisplayId = resolvedViewport ? std::make_optional(ADISPLAY_ID_NONE) : std::nullopt;
        } else {
            mDisplayId = mPointerController->getDisplayId();
            if (auto v = config.getDisplayViewportById(*mDisplayId); v) {
                resolvedViewport = *v;
            }
            if (auto bounds = mPointerController->getBounds(); bounds) {
                mBoundsInLogicalDisplay = *bounds;
                isBoundsSet = true;
            }
        }
    }
    }


    mOrientation = (mParameters.orientationAware && mParameters.hasAssociatedDisplay) ||
    mOrientation = (mParameters.orientationAware && mParameters.hasAssociatedDisplay) ||
+1 −11
Original line number Original line Diff line number Diff line
@@ -20,14 +20,11 @@
#include "CursorScrollAccumulator.h"
#include "CursorScrollAccumulator.h"
#include "InputMapper.h"
#include "InputMapper.h"


#include <PointerControllerInterface.h>
#include <input/VelocityControl.h>
#include <input/VelocityControl.h>
#include <ui/Rotation.h>
#include <ui/Rotation.h>


namespace android {
namespace android {


class PointerControllerInterface;

class CursorButtonAccumulator;
class CursorButtonAccumulator;
class CursorScrollAccumulator;
class CursorScrollAccumulator;


@@ -56,7 +53,7 @@ public:
    friend std::unique_ptr<T> createInputMapper(InputDeviceContext& deviceContext,
    friend std::unique_ptr<T> createInputMapper(InputDeviceContext& deviceContext,
                                                const InputReaderConfiguration& readerConfig,
                                                const InputReaderConfiguration& readerConfig,
                                                Args... args);
                                                Args... args);
    virtual ~CursorInputMapper();
    virtual ~CursorInputMapper() = default;


    virtual uint32_t getSources() const override;
    virtual uint32_t getSources() const override;
    virtual void populateDeviceInfo(InputDeviceInfo& deviceInfo) override;
    virtual void populateDeviceInfo(InputDeviceInfo& deviceInfo) override;
@@ -122,21 +119,14 @@ private:
    ui::Rotation mOrientation{ui::ROTATION_0};
    ui::Rotation mOrientation{ui::ROTATION_0};
    FloatRect mBoundsInLogicalDisplay{};
    FloatRect mBoundsInLogicalDisplay{};


    std::shared_ptr<PointerControllerInterface> mPointerController;

    int32_t mButtonState;
    int32_t mButtonState;
    nsecs_t mDownTime;
    nsecs_t mDownTime;
    nsecs_t mLastEventTime;
    nsecs_t mLastEventTime;


    const bool mEnablePointerChoreographer;
    const bool mEnableNewMousePointerBallistics;
    const bool mEnableNewMousePointerBallistics;


    explicit CursorInputMapper(InputDeviceContext& deviceContext,
    explicit CursorInputMapper(InputDeviceContext& deviceContext,
                               const InputReaderConfiguration& readerConfig);
                               const InputReaderConfiguration& readerConfig);
    // Constructor for testing.
    explicit CursorInputMapper(InputDeviceContext& deviceContext,
                               const InputReaderConfiguration& readerConfig,
                               bool enablePointerChoreographer);
    void dumpParameters(std::string& dump);
    void dumpParameters(std::string& dump);
    void configureBasicParams();
    void configureBasicParams();
    void configureOnPointerCapture(const InputReaderConfiguration& config);
    void configureOnPointerCapture(const InputReaderConfiguration& config);
+22 −528

File changed.

Preview size limit exceeded, changes collapsed.

+0 −6
Original line number Original line Diff line number Diff line
@@ -29,14 +29,8 @@ using testing::_;
using testing::Return;
using testing::Return;


void InputMapperUnitTest::SetUpWithBus(int bus) {
void InputMapperUnitTest::SetUpWithBus(int bus) {
    mFakePointerController = std::make_shared<FakePointerController>();
    mFakePointerController->setBounds(0, 0, 800 - 1, 480 - 1);
    mFakePointerController->setPosition(INITIAL_CURSOR_X, INITIAL_CURSOR_Y);
    mFakePolicy = sp<FakeInputReaderPolicy>::make();
    mFakePolicy = sp<FakeInputReaderPolicy>::make();


    EXPECT_CALL(mMockInputReaderContext, getPointerController(DEVICE_ID))
            .WillRepeatedly(Return(mFakePointerController));

    EXPECT_CALL(mMockInputReaderContext, getPolicy()).WillRepeatedly(Return(mFakePolicy.get()));
    EXPECT_CALL(mMockInputReaderContext, getPolicy()).WillRepeatedly(Return(mFakePolicy.get()));


    EXPECT_CALL(mMockInputReaderContext, getEventHub()).WillRepeatedly(Return(&mMockEventHub));
    EXPECT_CALL(mMockInputReaderContext, getEventHub()).WillRepeatedly(Return(&mMockEventHub));
+0 −3
Original line number Original line Diff line number Diff line
@@ -40,8 +40,6 @@ class InputMapperUnitTest : public testing::Test {
protected:
protected:
    static constexpr int32_t EVENTHUB_ID = 1;
    static constexpr int32_t EVENTHUB_ID = 1;
    static constexpr int32_t DEVICE_ID = END_RESERVED_ID + 1000;
    static constexpr int32_t DEVICE_ID = END_RESERVED_ID + 1000;
    static constexpr float INITIAL_CURSOR_X = 400;
    static constexpr float INITIAL_CURSOR_Y = 240;
    virtual void SetUp() override { SetUpWithBus(0); }
    virtual void SetUp() override { SetUpWithBus(0); }
    virtual void SetUpWithBus(int bus);
    virtual void SetUpWithBus(int bus);


@@ -66,7 +64,6 @@ protected:
    InputDeviceIdentifier mIdentifier;
    InputDeviceIdentifier mIdentifier;
    MockEventHubInterface mMockEventHub;
    MockEventHubInterface mMockEventHub;
    sp<FakeInputReaderPolicy> mFakePolicy;
    sp<FakeInputReaderPolicy> mFakePolicy;
    std::shared_ptr<FakePointerController> mFakePointerController;
    MockInputReaderContext mMockInputReaderContext;
    MockInputReaderContext mMockInputReaderContext;
    std::unique_ptr<InputDevice> mDevice;
    std::unique_ptr<InputDevice> mDevice;