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

Commit b51719b9 authored by Jeff Brown's avatar Jeff Brown
Browse files

Improve thread safety of input mappers.

Also fixed bug where old touch screen size could be reported by
getMotionRange if an orientation change occurred but the user has not
yet touched the screen.

Bug: 2877345
Change-Id: I7878f47458f310ed6ebe6a5d1b2c9bec2c598ab9
parent a48bcf62
Loading
Loading
Loading
Loading
+83 −67
Original line number Original line Diff line number Diff line
@@ -210,7 +210,7 @@ public:
 * IMPORTANT INVARIANT:
 * IMPORTANT INVARIANT:
 *     Because the policy and dispatcher can potentially block or cause re-entrance into
 *     Because the policy and dispatcher can potentially block or cause re-entrance into
 *     the input reader, the input reader never calls into other components while holding
 *     the input reader, the input reader never calls into other components while holding
 *     an exclusive internal lock.
 *     an exclusive internal lock whenever re-entrance can happen.
 */
 */
class InputReader : public InputReaderInterface, private InputReaderContext {
class InputReader : public InputReaderInterface, private InputReaderContext {
public:
public:
@@ -414,6 +414,8 @@ public:
    virtual int32_t getMetaState();
    virtual int32_t getMetaState();


private:
private:
    Mutex mLock;

    struct KeyDown {
    struct KeyDown {
        int32_t keyCode;
        int32_t keyCode;
        int32_t scanCode;
        int32_t scanCode;
@@ -423,17 +425,22 @@ private:
    uint32_t mSources;
    uint32_t mSources;
    int32_t mKeyboardType;
    int32_t mKeyboardType;


    Vector<KeyDown> mKeyDowns; // keys that are down
    struct LockedState {
    int32_t mMetaState;
        Vector<KeyDown> keyDowns; // keys that are down
    nsecs_t mDownTime; // time of most recent key down
        int32_t metaState;
        nsecs_t downTime; // time of most recent key down
    } mLocked;


    void initialize();
    void initializeLocked();


    bool isKeyboardOrGamepadKey(int32_t scanCode);
    bool isKeyboardOrGamepadKey(int32_t scanCode);

    void processKey(nsecs_t when, bool down, int32_t keyCode, int32_t scanCode,
    void processKey(nsecs_t when, bool down, int32_t keyCode, int32_t scanCode,
            uint32_t policyFlags);
            uint32_t policyFlags);
    void applyPolicyAndDispatch(nsecs_t when, uint32_t policyFlags,
            bool down, int32_t keyCode, int32_t scanCode, int32_t metaState, nsecs_t downTime);


    ssize_t findKeyDown(int32_t scanCode);
    ssize_t findKeyDownLocked(int32_t scanCode);
};
};




@@ -451,6 +458,8 @@ private:
    // Amount that trackball needs to move in order to generate a key event.
    // Amount that trackball needs to move in order to generate a key event.
    static const int32_t TRACKBALL_MOVEMENT_THRESHOLD = 6;
    static const int32_t TRACKBALL_MOVEMENT_THRESHOLD = 6;


    Mutex mLock;

    int32_t mAssociatedDisplayId;
    int32_t mAssociatedDisplayId;


    struct Accumulator {
    struct Accumulator {
@@ -475,17 +484,21 @@ private:
        }
        }
    } mAccumulator;
    } mAccumulator;


    bool mDown;
    nsecs_t mDownTime;

    float mXScale;
    float mXScale;
    float mYScale;
    float mYScale;
    float mXPrecision;
    float mXPrecision;
    float mYPrecision;
    float mYPrecision;


    void initialize();
    struct LockedState {
        bool down;
        nsecs_t downTime;
    } mLocked;

    void initializeLocked();


    void sync(nsecs_t when);
    void sync(nsecs_t when);
    void applyPolicyAndDispatch(nsecs_t when, int32_t motionEventAction,
            PointerCoords* pointerCoords, nsecs_t downTime);
};
};




@@ -509,6 +522,8 @@ protected:
     * (This is limited by our use of BitSet32 to track pointer assignments.) */
     * (This is limited by our use of BitSet32 to track pointer assignments.) */
    static const uint32_t MAX_POINTER_ID = 31;
    static const uint32_t MAX_POINTER_ID = 31;


    Mutex mLock;

    struct VirtualKey {
    struct VirtualKey {
        int32_t keyCode;
        int32_t keyCode;
        int32_t scanCode;
        int32_t scanCode;
@@ -561,7 +576,6 @@ protected:
    };
    };


    int32_t mAssociatedDisplayId;
    int32_t mAssociatedDisplayId;
    Vector<VirtualKey> mVirtualKeys;


    // Immutable configuration parameters.
    // Immutable configuration parameters.
    struct Parameters {
    struct Parameters {
@@ -583,26 +597,36 @@ protected:
        RawAbsoluteAxisInfo orientation;
        RawAbsoluteAxisInfo orientation;
    } mAxes;
    } mAxes;


    // The surface orientation and width and height set by configureSurface().
    // Current and previous touch sample data.
    int32_t mSurfaceOrientation;
    TouchData mCurrentTouch;
    int32_t mSurfaceWidth, mSurfaceHeight;
    TouchData mLastTouch;

    // The time the primary pointer last went down.
    nsecs_t mDownTime;

    struct LockedState {
        Vector<VirtualKey> virtualKeys;

        // The surface orientation and width and height set by configureSurfaceLocked().
        int32_t surfaceOrientation;
        int32_t surfaceWidth, surfaceHeight;


        // Translation and scaling factors, orientation-independent.
        // Translation and scaling factors, orientation-independent.
    int32_t mXOrigin;
        int32_t xOrigin;
    float mXScale;
        float xScale;
    float mXPrecision;
        float xPrecision;


    int32_t mYOrigin;
        int32_t yOrigin;
    float mYScale;
        float yScale;
    float mYPrecision;
        float yPrecision;


    int32_t mPressureOrigin;
        int32_t pressureOrigin;
    float mPressureScale;
        float pressureScale;


    int32_t mSizeOrigin;
        int32_t sizeOrigin;
    float mSizeScale;
        float sizeScale;


    float mOrientationScale;
        float orientationScale;


        // Oriented motion ranges for input device info.
        // Oriented motion ranges for input device info.
        struct OrientedRanges {
        struct OrientedRanges {
@@ -615,35 +639,23 @@ protected:
            InputDeviceInfo::MotionRange toolMajor;
            InputDeviceInfo::MotionRange toolMajor;
            InputDeviceInfo::MotionRange toolMinor;
            InputDeviceInfo::MotionRange toolMinor;
            InputDeviceInfo::MotionRange orientation;
            InputDeviceInfo::MotionRange orientation;
    } mOrientedRanges;
        } orientedRanges;


        // Oriented dimensions and precision.
        // Oriented dimensions and precision.
    float mOrientedSurfaceWidth, mOrientedSurfaceHeight;
        float orientedSurfaceWidth, orientedSurfaceHeight;
    float mOrientedXPrecision, mOrientedYPrecision;
        float orientedXPrecision, orientedYPrecision;

    // The touch data of the current sample being processed.
    TouchData mCurrentTouch;

    // The touch data of the previous sample that was processed.  This is updated
    // incrementally while the current sample is being processed.
    TouchData mLastTouch;

    // The time the primary pointer last went down.
    nsecs_t mDownTime;


        struct CurrentVirtualKeyState {
        struct CurrentVirtualKeyState {
            bool down;
            bool down;
            nsecs_t downTime;
            nsecs_t downTime;
            int32_t keyCode;
            int32_t keyCode;
            int32_t scanCode;
            int32_t scanCode;
    } mCurrentVirtualKey;
        } currentVirtualKey;

    } mLocked;
    // Lock for virtual key state.
    Mutex mVirtualKeyLock; // methods use "Lvk" suffix


    virtual void configureAxes();
    virtual void configureAxes();
    virtual bool configureSurface();
    virtual bool configureSurfaceLocked();
    virtual void configureVirtualKeys();
    virtual void configureVirtualKeysLocked();


    enum TouchResult {
    enum TouchResult {
        // Dispatch the touch normally.
        // Dispatch the touch normally.
@@ -696,15 +708,19 @@ private:
        uint64_t distance : 48; // squared distance
        uint64_t distance : 48; // squared distance
    };
    };


    void initialize();
    void initializeLocked();


    TouchResult consumeOffScreenTouches(nsecs_t when, uint32_t policyFlags);
    TouchResult consumeOffScreenTouches(nsecs_t when, uint32_t policyFlags);
    void dispatchTouches(nsecs_t when, uint32_t policyFlags);
    void dispatchTouches(nsecs_t when, uint32_t policyFlags);
    void dispatchTouch(nsecs_t when, uint32_t policyFlags, TouchData* touch,
    void dispatchTouch(nsecs_t when, uint32_t policyFlags, TouchData* touch,
            BitSet32 idBits, uint32_t changedId, int32_t motionEventAction);
            BitSet32 idBits, uint32_t changedId, int32_t motionEventAction);


    bool isPointInsideSurface(int32_t x, int32_t y);
    void applyPolicyAndDispatchVirtualKey(nsecs_t when, uint32_t policyFlags,
    const VirtualKey* findVirtualKeyHitLvk(int32_t x, int32_t y);
            int32_t keyEventAction, int32_t keyEventFlags,
            int32_t keyCode, int32_t scanCode, nsecs_t downTime);

    bool isPointInsideSurfaceLocked(int32_t x, int32_t y);
    const VirtualKey* findVirtualKeyHitLocked(int32_t x, int32_t y);


    bool applyBadTouchFilter();
    bool applyBadTouchFilter();
    bool applyJumpyTouchFilter();
    bool applyJumpyTouchFilter();
+496 −423

File changed.

Preview size limit exceeded, changes collapsed.