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

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

Merge "Move display id into MotionEvent"

parents 95ae4c17 777a10ba
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -373,6 +373,10 @@ public:

    virtual int32_t getType() const { return AINPUT_EVENT_TYPE_MOTION; }

    inline int32_t getDisplayId() const { return mDisplayId; }

    inline void setDisplayId(int32_t displayId) { mDisplayId = displayId; }

    inline int32_t getAction() const { return mAction; }

    inline int32_t getActionMasked() const { return mAction & AMOTION_EVENT_ACTION_MASK; }
@@ -556,6 +560,7 @@ public:
    void initialize(
            int32_t deviceId,
            int32_t source,
            int32_t displayId,
            int32_t action,
            int32_t actionButton,
            int32_t flags,
@@ -609,6 +614,7 @@ public:
    static int32_t getAxisFromLabel(const char* label);

protected:
    int32_t mDisplayId;
    int32_t mAction;
    int32_t mActionButton;
    int32_t mFlags;
+3 −5
Original line number Diff line number Diff line
@@ -64,7 +64,6 @@ struct InputMessage {
            nsecs_t eventTime __attribute__((aligned(8)));
            int32_t deviceId;
            int32_t source;
            int32_t displayId;
            int32_t action;
            int32_t flags;
            int32_t keyCode;
@@ -305,7 +304,7 @@ public:
     * Other errors probably indicate that the channel is broken.
     */
    status_t consume(InputEventFactoryInterface* factory, bool consumeBatches,
            nsecs_t frameTime, uint32_t* outSeq, InputEvent** outEvent, int32_t* displayId);
            nsecs_t frameTime, uint32_t* outSeq, InputEvent** outEvent);

    /* Sends a finished signal to the publisher to inform it that the message
     * with the specified sequence number has finished being process and whether
@@ -460,10 +459,9 @@ private:
    Vector<SeqChain> mSeqChains;

    status_t consumeBatch(InputEventFactoryInterface* factory,
            nsecs_t frameTime, uint32_t* outSeq, InputEvent** outEvent, int32_t* displayId);
            nsecs_t frameTime, uint32_t* outSeq, InputEvent** outEvent);
    status_t consumeSamples(InputEventFactoryInterface* factory,
            Batch& batch, size_t count, uint32_t* outSeq, InputEvent** outEvent,
            int32_t* displayId);
            Batch& batch, size_t count, uint32_t* outSeq, InputEvent** outEvent);

    void updateTouchState(InputMessage& msg);
    void resampleTouchState(nsecs_t frameTime, MotionEvent* event,
+5 −0
Original line number Diff line number Diff line
@@ -215,6 +215,7 @@ void PointerProperties::copyFrom(const PointerProperties& other) {
void MotionEvent::initialize(
        int32_t deviceId,
        int32_t source,
        int32_t displayId,
        int32_t action,
        int32_t actionButton,
        int32_t flags,
@@ -231,6 +232,7 @@ void MotionEvent::initialize(
        const PointerProperties* pointerProperties,
        const PointerCoords* pointerCoords) {
    InputEvent::initialize(deviceId, source);
    mDisplayId = displayId;
    mAction = action;
    mActionButton = actionButton;
    mFlags = flags;
@@ -251,6 +253,7 @@ void MotionEvent::initialize(

void MotionEvent::copyFrom(const MotionEvent* other, bool keepHistory) {
    InputEvent::initialize(other->mDeviceId, other->mSource);
    mDisplayId = other->mDisplayId;
    mAction = other->mAction;
    mActionButton = other->mActionButton;
    mFlags = other->mFlags;
@@ -431,6 +434,7 @@ status_t MotionEvent::readFromParcel(Parcel* parcel) {

    mDeviceId = parcel->readInt32();
    mSource = parcel->readInt32();
    mDisplayId = parcel->readInt32();
    mAction = parcel->readInt32();
    mActionButton = parcel->readInt32();
    mFlags = parcel->readInt32();
@@ -480,6 +484,7 @@ status_t MotionEvent::writeToParcel(Parcel* parcel) const {

    parcel->writeInt32(mDeviceId);
    parcel->writeInt32(mSource);
    parcel->writeInt32(mDisplayId);
    parcel->writeInt32(mAction);
    parcel->writeInt32(mActionButton);
    parcel->writeInt32(mFlags);
+13 −14
Original line number Diff line number Diff line
@@ -303,13 +303,15 @@ status_t InputPublisher::publishMotionEvent(
        const PointerCoords* pointerCoords) {
#if DEBUG_TRANSPORT_ACTIONS
    ALOGD("channel '%s' publisher ~ publishMotionEvent: seq=%u, deviceId=%d, source=0x%x, "
            "displayId=%" PRId32 ", "
            "action=0x%x, actionButton=0x%08x, flags=0x%x, edgeFlags=0x%x, "
            "metaState=0x%x, buttonState=0x%x, xOffset=%f, yOffset=%f, "
            "xPrecision=%f, yPrecision=%f, downTime=%" PRId64 ", eventTime=%" PRId64 ", "
            "pointerCount=%" PRIu32,
            mChannel->getName().c_str(), seq,
            deviceId, source, action, actionButton, flags, edgeFlags, metaState, buttonState,
            xOffset, yOffset, xPrecision, yPrecision, downTime, eventTime, pointerCount);
            deviceId, source, displayId, action, actionButton, flags, edgeFlags, metaState,
            buttonState, xOffset, yOffset, xPrecision, yPrecision, downTime, eventTime,
            pointerCount);
#endif

    if (!seq) {
@@ -398,8 +400,7 @@ bool InputConsumer::isTouchResamplingEnabled() {
}

status_t InputConsumer::consume(InputEventFactoryInterface* factory,
        bool consumeBatches, nsecs_t frameTime, uint32_t* outSeq, InputEvent** outEvent,
        int32_t* displayId) {
        bool consumeBatches, nsecs_t frameTime, uint32_t* outSeq, InputEvent** outEvent) {
#if DEBUG_TRANSPORT_ACTIONS
    ALOGD("channel '%s' consumer ~ consume: consumeBatches=%s, frameTime=%" PRId64,
            mChannel->getName().c_str(), consumeBatches ? "true" : "false", frameTime);
@@ -407,7 +408,6 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory,

    *outSeq = 0;
    *outEvent = NULL;
    *displayId = -1;  // Invalid display.

    // Fetch the next input message.
    // Loop until an event can be returned or no additional events are received.
@@ -422,7 +422,7 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory,
            if (result) {
                // Consume the next batched event unless batches are being held for later.
                if (consumeBatches || result != WOULD_BLOCK) {
                    result = consumeBatch(factory, frameTime, outSeq, outEvent, displayId);
                    result = consumeBatch(factory, frameTime, outSeq, outEvent);
                    if (*outEvent) {
#if DEBUG_TRANSPORT_ACTIONS
                        ALOGD("channel '%s' consumer ~ consumed batch event, seq=%u",
@@ -466,7 +466,7 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory,
                    // the previous batch right now and defer the new message until later.
                    mMsgDeferred = true;
                    status_t result = consumeSamples(factory,
                            batch, batch.samples.size(), outSeq, outEvent, displayId);
                            batch, batch.samples.size(), outSeq, outEvent);
                    mBatches.removeAt(batchIndex);
                    if (result) {
                        return result;
@@ -500,7 +500,7 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory,
            initializeMotionEvent(motionEvent, &mMsg);
            *outSeq = mMsg.body.motion.seq;
            *outEvent = motionEvent;
            *displayId = mMsg.body.motion.displayId;

#if DEBUG_TRANSPORT_ACTIONS
            ALOGD("channel '%s' consumer ~ consumed motion event, seq=%u",
                    mChannel->getName().c_str(), *outSeq);
@@ -518,14 +518,13 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory,
}

status_t InputConsumer::consumeBatch(InputEventFactoryInterface* factory,
        nsecs_t frameTime, uint32_t* outSeq, InputEvent** outEvent, int32_t* displayId) {
        nsecs_t frameTime, uint32_t* outSeq, InputEvent** outEvent) {
    status_t result;
    for (size_t i = mBatches.size(); i > 0; ) {
        i--;
        Batch& batch = mBatches.editItemAt(i);
        if (frameTime < 0) {
            result = consumeSamples(factory, batch, batch.samples.size(),
                    outSeq, outEvent, displayId);
            result = consumeSamples(factory, batch, batch.samples.size(), outSeq, outEvent);
            mBatches.removeAt(i);
            return result;
        }
@@ -539,7 +538,7 @@ status_t InputConsumer::consumeBatch(InputEventFactoryInterface* factory,
            continue;
        }

        result = consumeSamples(factory, batch, split + 1, outSeq, outEvent, displayId);
        result = consumeSamples(factory, batch, split + 1, outSeq, outEvent);
        const InputMessage* next;
        if (batch.samples.isEmpty()) {
            mBatches.removeAt(i);
@@ -557,7 +556,7 @@ status_t InputConsumer::consumeBatch(InputEventFactoryInterface* factory,
}

status_t InputConsumer::consumeSamples(InputEventFactoryInterface* factory,
        Batch& batch, size_t count, uint32_t* outSeq, InputEvent** outEvent, int32_t* displayId) {
        Batch& batch, size_t count, uint32_t* outSeq, InputEvent** outEvent) {
    MotionEvent* motionEvent = factory->createMotionEvent();
    if (! motionEvent) return NO_MEMORY;

@@ -572,7 +571,6 @@ status_t InputConsumer::consumeSamples(InputEventFactoryInterface* factory,
            mSeqChains.push(seqChain);
            addSample(motionEvent, &msg);
        } else {
            *displayId = msg.body.motion.displayId;
            initializeMotionEvent(motionEvent, &msg);
        }
        chain = msg.body.motion.seq;
@@ -950,6 +948,7 @@ void InputConsumer::initializeMotionEvent(MotionEvent* event, const InputMessage
    event->initialize(
            msg->body.motion.deviceId,
            msg->body.motion.source,
            msg->body.motion.displayId,
            msg->body.motion.action,
            msg->body.motion.actionButton,
            msg->body.motion.flags,
+11 −2
Original line number Diff line number Diff line
@@ -22,6 +22,9 @@

namespace android {

// Default display id.
static constexpr int32_t DISPLAY_ID = ADISPLAY_ID_DEFAULT;

class BaseTest : public testing::Test {
protected:
    virtual void SetUp() { }
@@ -248,7 +251,7 @@ void MotionEventTest::initializeEventWithHistory(MotionEvent* event) {
    pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, 26);
    pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR, 27);
    pointerCoords[1].setAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, 28);
    event->initialize(2, AINPUT_SOURCE_TOUCHSCREEN, AMOTION_EVENT_ACTION_MOVE, 0,
    event->initialize(2, AINPUT_SOURCE_TOUCHSCREEN, DISPLAY_ID, AMOTION_EVENT_ACTION_MOVE, 0,
            AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED,
            AMOTION_EVENT_EDGE_FLAG_TOP, AMETA_ALT_ON, AMOTION_EVENT_BUTTON_PRIMARY,
            X_OFFSET, Y_OFFSET, 2.0f, 2.1f,
@@ -301,6 +304,7 @@ void MotionEventTest::assertEqualsEventWithHistory(const MotionEvent* event) {
    ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, event->getType());
    ASSERT_EQ(2, event->getDeviceId());
    ASSERT_EQ(static_cast<int>(AINPUT_SOURCE_TOUCHSCREEN), event->getSource());
    ASSERT_EQ(DISPLAY_ID, event->getDisplayId());
    ASSERT_EQ(AMOTION_EVENT_ACTION_MOVE, event->getAction());
    ASSERT_EQ(AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED, event->getFlags());
    ASSERT_EQ(AMOTION_EVENT_EDGE_FLAG_TOP, event->getEdgeFlags());
@@ -434,6 +438,11 @@ TEST_F(MotionEventTest, Properties) {
    event.setSource(AINPUT_SOURCE_JOYSTICK);
    ASSERT_EQ(static_cast<int>(AINPUT_SOURCE_JOYSTICK), event.getSource());

    // Set displayId.
    constexpr int32_t newDisplayId = 2;
    event.setDisplayId(newDisplayId);
    ASSERT_EQ(newDisplayId, event.getDisplayId());

    // Set action.
    event.setAction(AMOTION_EVENT_ACTION_CANCEL);
    ASSERT_EQ(AMOTION_EVENT_ACTION_CANCEL, event.getAction());
@@ -557,7 +566,7 @@ TEST_F(MotionEventTest, Transform) {
        pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, angle);
    }
    MotionEvent event;
    event.initialize(0, 0, AMOTION_EVENT_ACTION_MOVE, 0, 0, 0, 0, 0,
    event.initialize(0, 0, DISPLAY_ID, AMOTION_EVENT_ACTION_MOVE, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, pointerCount, pointerProperties, pointerCoords);
    float originalRawX = 0 + 3;
    float originalRawY = -RADIUS + 2;
Loading