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

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

Merge "Send mapper events via context"

parents 9f0f02eb cec3f6a9
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -505,8 +505,7 @@ void InputDevice::bumpGeneration() {
}

void InputDevice::notifyReset(nsecs_t when) {
    NotifyDeviceResetArgs args(mContext->getNextId(), when, mId);
    mContext->getListener()->notifyDeviceReset(&args);
    mContext->notifyDeviceReset(when, mId);
}

std::optional<int32_t> InputDevice::getAssociatedDisplayId() {
+56 −11
Original line number Diff line number Diff line
@@ -339,8 +339,7 @@ void InputReader::handleConfigurationChangedLocked(nsecs_t when) {
    updateGlobalMetaStateLocked();

    // Enqueue configuration changed.
    NotifyConfigurationChangedArgs args(mContext.getNextId(), when);
    mQueuedListener->notifyConfigurationChanged(&args);
    mContext.notifyConfigurationChanged(when);
}

void InputReader::refreshConfigurationLocked(uint32_t changes) {
@@ -367,9 +366,7 @@ void InputReader::refreshConfigurationLocked(uint32_t changes) {
    }

    if (changes & InputReaderConfiguration::CHANGE_POINTER_CAPTURE) {
        const NotifyPointerCaptureChangedArgs args(mContext.getNextId(), now,
                                                   mConfig.pointerCapture);
        mQueuedListener->notifyPointerCaptureChanged(&args);
        mContext.notifyPointerCaptureChanged(now, mConfig.pointerCapture);
    }
}

@@ -868,16 +865,64 @@ InputReaderPolicyInterface* InputReader::ContextImpl::getPolicy() {
    return mReader->mPolicy.get();
}

InputListenerInterface* InputReader::ContextImpl::getListener() {
    return mReader->mQueuedListener.get();
}

EventHubInterface* InputReader::ContextImpl::getEventHub() {
    return mReader->mEventHub.get();
}

int32_t InputReader::ContextImpl::getNextId() {
    return mIdGenerator.nextId();
void InputReader::ContextImpl::notifyConfigurationChanged(nsecs_t when) {
    NotifyConfigurationChangedArgs args(mIdGenerator.nextId(), when);
    mReader->mQueuedListener->notifyConfigurationChanged(&args);
}

void InputReader::ContextImpl::notifyKey(nsecs_t eventTime, int32_t deviceId, uint32_t source,
                                         int32_t displayId, uint32_t policyFlags, int32_t action,
                                         int32_t flags, int32_t keyCode, int32_t scanCode,
                                         int32_t metaState, nsecs_t downTime) {
    NotifyKeyArgs args(mIdGenerator.nextId(), eventTime, deviceId, source, displayId, policyFlags,
                       action, flags, keyCode, scanCode, metaState, downTime);
    mReader->mQueuedListener->notifyKey(&args);
}
void InputReader::ContextImpl::notifyMotion(
        nsecs_t eventTime, int32_t deviceId, uint32_t source, int32_t displayId,
        uint32_t policyFlags, int32_t action, int32_t actionButton, int32_t flags,
        int32_t metaState, int32_t buttonState, MotionClassification classification,
        int32_t edgeFlags, uint32_t pointerCount, const PointerProperties* pointerProperties,
        const PointerCoords* pointerCoords, float xPrecision, float yPrecision,
        float xCursorPosition, float yCursorPosition, nsecs_t downTime,
        const std::vector<TouchVideoFrame>& videoFrames) {
    NotifyMotionArgs args(mIdGenerator.nextId(), eventTime, deviceId, source, displayId,
                          policyFlags, action, actionButton, flags, metaState, buttonState,
                          classification, edgeFlags, pointerCount, pointerProperties, pointerCoords,
                          xPrecision, yPrecision, xCursorPosition, yCursorPosition, downTime,
                          videoFrames);
    mReader->mQueuedListener->notifyMotion(&args);
}

void InputReader::ContextImpl::notifySensor(nsecs_t when, int32_t deviceId,
                                            InputDeviceSensorType sensorType,
                                            InputDeviceSensorAccuracy accuracy,
                                            bool accuracyChanged, nsecs_t timestamp,
                                            std::vector<float> values) {
    NotifySensorArgs args(mIdGenerator.nextId(), when, deviceId, AINPUT_SOURCE_SENSOR, sensorType,
                          accuracy, accuracyChanged, timestamp, std::move(values));
    mReader->mQueuedListener->notifySensor(&args);
}

void InputReader::ContextImpl::notifySwitch(nsecs_t eventTime, uint32_t switchValues,
                                            uint32_t switchMask) {
    NotifySwitchArgs args(mIdGenerator.nextId(), eventTime, 0 /*policyFlags*/, switchValues,
                          switchMask);
    mReader->mQueuedListener->notifySwitch(&args);
}

void InputReader::ContextImpl::notifyDeviceReset(nsecs_t when, int32_t deviceId) {
    NotifyDeviceResetArgs args(mIdGenerator.nextId(), when, deviceId);
    mReader->mQueuedListener->notifyDeviceReset(&args);
}

void InputReader::ContextImpl::notifyPointerCaptureChanged(nsecs_t when, bool hasCapture) {
    const NotifyPointerCaptureChangedArgs args(mIdGenerator.nextId(), when, hasCapture);
    mReader->mQueuedListener->notifyPointerCaptureChanged(&args);
}

} // namespace android
+21 −2
Original line number Diff line number Diff line
@@ -127,11 +127,30 @@ protected:
        void dispatchExternalStylusState(const StylusState& outState)
                NO_THREAD_SAFETY_ANALYSIS override;
        InputReaderPolicyInterface* getPolicy() NO_THREAD_SAFETY_ANALYSIS override;
        InputListenerInterface* getListener() NO_THREAD_SAFETY_ANALYSIS override;
        EventHubInterface* getEventHub() NO_THREAD_SAFETY_ANALYSIS override;
        int32_t getNextId() NO_THREAD_SAFETY_ANALYSIS override;
        void updateLedMetaState(int32_t metaState) NO_THREAD_SAFETY_ANALYSIS override;
        int32_t getLedMetaState() NO_THREAD_SAFETY_ANALYSIS override;

        // Send events to InputListener interface
        void notifyConfigurationChanged(nsecs_t when) override;
        void notifyKey(nsecs_t eventTime, int32_t deviceId, uint32_t source, int32_t displayId,
                       uint32_t policyFlags, int32_t action, int32_t flags, int32_t keyCode,
                       int32_t scanCode, int32_t metaState, nsecs_t downTime) override;
        void notifyMotion(nsecs_t eventTime, int32_t deviceId, uint32_t source, int32_t displayId,
                          uint32_t policyFlags, int32_t action, int32_t actionButton, int32_t flags,
                          int32_t metaState, int32_t buttonState,
                          MotionClassification classification, int32_t edgeFlags,
                          uint32_t pointerCount, const PointerProperties* pointerProperties,
                          const PointerCoords* pointerCoords, float xPrecision, float yPrecision,
                          float xCursorPosition, float yCursorPosition, nsecs_t downTime,
                          const std::vector<TouchVideoFrame>& videoFrames) override;
        void notifySwitch(nsecs_t eventTime, uint32_t switchValues, uint32_t switchMask) override;
        void notifySensor(nsecs_t when, int32_t deviceId, InputDeviceSensorType sensorType,
                          InputDeviceSensorAccuracy accuracy, bool accuracyChanged,
                          nsecs_t timestamp, std::vector<float> values) override;
        void notifyDeviceReset(nsecs_t when, int32_t deviceId) override;
        void notifyPointerCaptureChanged(nsecs_t when, bool hasCapture) override;

    } mContext;

    friend class ContextImpl;
+23 −3
Original line number Diff line number Diff line
@@ -55,13 +55,33 @@ public:
    virtual void dispatchExternalStylusState(const StylusState& outState) = 0;

    virtual InputReaderPolicyInterface* getPolicy() = 0;
    virtual InputListenerInterface* getListener() = 0;
    virtual EventHubInterface* getEventHub() = 0;

    virtual int32_t getNextId() = 0;

    virtual void updateLedMetaState(int32_t metaState) = 0;
    virtual int32_t getLedMetaState() = 0;

    // Send events to InputListener interface

    virtual void notifyConfigurationChanged(nsecs_t when) = 0;
    virtual void notifyKey(nsecs_t eventTime, int32_t deviceId, uint32_t source, int32_t displayId,
                           uint32_t policyFlags, int32_t action, int32_t flags, int32_t keyCode,
                           int32_t scanCode, int32_t metaState, nsecs_t downTime) = 0;
    virtual void notifyMotion(nsecs_t eventTime, int32_t deviceId, uint32_t source,
                              int32_t displayId, uint32_t policyFlags, int32_t action,
                              int32_t actionButton, int32_t flags, int32_t metaState,
                              int32_t buttonState, MotionClassification classification,
                              int32_t edgeFlags, uint32_t pointerCount,
                              const PointerProperties* pointerProperties,
                              const PointerCoords* pointerCoords, float xPrecision,
                              float yPrecision, float xCursorPosition, float yCursorPosition,
                              nsecs_t downTime,
                              const std::vector<TouchVideoFrame>& videoFrames) = 0;
    virtual void notifySwitch(nsecs_t eventTime, uint32_t switchValues, uint32_t switchMask) = 0;
    virtual void notifySensor(nsecs_t when, int32_t deviceId, InputDeviceSensorType sensorType,
                              InputDeviceSensorAccuracy accuracy, bool accuracyChanged,
                              nsecs_t timestamp, std::vector<float> values) = 0;
    virtual void notifyDeviceReset(nsecs_t when, int32_t deviceId) = 0;
    virtual void notifyPointerCaptureChanged(nsecs_t when, bool hasCapture) = 0;
};

} // namespace android
+24 −32
Original line number Diff line number Diff line
@@ -175,8 +175,7 @@ void CursorInputMapper::configure(nsecs_t when, const InputReaderConfiguration*
        }
        bumpGeneration();
        if (changes) {
            NotifyDeviceResetArgs args(getContext()->getNextId(), when, getDeviceId());
            getListener()->notifyDeviceReset(&args);
            getContext()->notifyDeviceReset(when, getDeviceId());
        }
    }

@@ -383,40 +382,35 @@ void CursorInputMapper::sync(nsecs_t when) {
            while (!released.isEmpty()) {
                int32_t actionButton = BitSet32::valueForBit(released.clearFirstMarkedBit());
                buttonState &= ~actionButton;
                NotifyMotionArgs releaseArgs(getContext()->getNextId(), when, getDeviceId(),
                                             mSource, displayId, policyFlags,
                getContext()->notifyMotion(when, getDeviceId(), mSource, displayId, policyFlags,
                                           AMOTION_EVENT_ACTION_BUTTON_RELEASE, actionButton, 0,
                                           metaState, buttonState, MotionClassification::NONE,
                                           AMOTION_EVENT_EDGE_FLAG_NONE, 1, &pointerProperties,
                                           &pointerCoords, mXPrecision, mYPrecision,
                                           xCursorPosition, yCursorPosition, downTime,
                                           /* videoFrames */ {});
                getListener()->notifyMotion(&releaseArgs);
            }
        }

        NotifyMotionArgs args(getContext()->getNextId(), when, getDeviceId(), mSource, displayId,
                              policyFlags, motionEventAction, 0, 0, metaState, currentButtonState,
        getContext()->notifyMotion(when, getDeviceId(), mSource, displayId, policyFlags,
                                   motionEventAction, 0, 0, metaState, currentButtonState,
                                   MotionClassification::NONE, AMOTION_EVENT_EDGE_FLAG_NONE, 1,
                                   &pointerProperties, &pointerCoords, mXPrecision, mYPrecision,
                                   xCursorPosition, yCursorPosition, downTime,
                                   /* videoFrames */ {});
        getListener()->notifyMotion(&args);

        if (buttonsPressed) {
            BitSet32 pressed(buttonsPressed);
            while (!pressed.isEmpty()) {
                int32_t actionButton = BitSet32::valueForBit(pressed.clearFirstMarkedBit());
                buttonState |= actionButton;
                NotifyMotionArgs pressArgs(getContext()->getNextId(), when, getDeviceId(), mSource,
                                           displayId, policyFlags,
                getContext()->notifyMotion(when, getDeviceId(), mSource, displayId, policyFlags,
                                           AMOTION_EVENT_ACTION_BUTTON_PRESS, actionButton, 0,
                                           metaState, buttonState, MotionClassification::NONE,
                                           AMOTION_EVENT_EDGE_FLAG_NONE, 1, &pointerProperties,
                                           &pointerCoords, mXPrecision, mYPrecision,
                                           xCursorPosition, yCursorPosition, downTime,
                                           /* videoFrames */ {});
                getListener()->notifyMotion(&pressArgs);
            }
        }

@@ -424,13 +418,12 @@ void CursorInputMapper::sync(nsecs_t when) {

        // Send hover move after UP to tell the application that the mouse is hovering now.
        if (motionEventAction == AMOTION_EVENT_ACTION_UP && (mSource == AINPUT_SOURCE_MOUSE)) {
            NotifyMotionArgs hoverArgs(getContext()->getNextId(), when, getDeviceId(), mSource,
                                       displayId, policyFlags, AMOTION_EVENT_ACTION_HOVER_MOVE, 0,
                                       0, metaState, currentButtonState, MotionClassification::NONE,
            getContext()->notifyMotion(when, getDeviceId(), mSource, displayId, policyFlags,
                                       AMOTION_EVENT_ACTION_HOVER_MOVE, 0, 0, metaState,
                                       currentButtonState, MotionClassification::NONE,
                                       AMOTION_EVENT_EDGE_FLAG_NONE, 1, &pointerProperties,
                                       &pointerCoords, mXPrecision, mYPrecision, xCursorPosition,
                                       yCursorPosition, downTime, /* videoFrames */ {});
            getListener()->notifyMotion(&hoverArgs);
        }

        // Send scroll events.
@@ -438,13 +431,12 @@ void CursorInputMapper::sync(nsecs_t when) {
            pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_VSCROLL, vscroll);
            pointerCoords.setAxisValue(AMOTION_EVENT_AXIS_HSCROLL, hscroll);

            NotifyMotionArgs scrollArgs(getContext()->getNextId(), when, getDeviceId(), mSource,
                                        displayId, policyFlags, AMOTION_EVENT_ACTION_SCROLL, 0, 0,
                                        metaState, currentButtonState, MotionClassification::NONE,
            getContext()->notifyMotion(when, getDeviceId(), mSource, displayId, policyFlags,
                                       AMOTION_EVENT_ACTION_SCROLL, 0, 0, metaState,
                                       currentButtonState, MotionClassification::NONE,
                                       AMOTION_EVENT_EDGE_FLAG_NONE, 1, &pointerProperties,
                                       &pointerCoords, mXPrecision, mYPrecision, xCursorPosition,
                                       yCursorPosition, downTime, /* videoFrames */ {});
            getListener()->notifyMotion(&scrollArgs);
        }
    }

Loading