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

Commit 38a7fabd authored by Jeff Brown's avatar Jeff Brown
Browse files

Input device calibration and capabilities.

Finished the input device capability API.
Added a mechanism for calibrating touch devices to obtain more
accurate information about the touch contact area.
Improved pointer location to show new coordinates and capabilities.
Optimized pointer location display and formatting to avoid allocating large
numbers of temporary objects.  The GC churn was causing the application to
stutter very badly when more than a couple of fingers were down).
Added more diagnostics.

Change-Id: Ie25380278ed6f16c5b04cd9df848015850383498
parent 296e9b71
Loading
Loading
Loading
Loading
+8 −0
Original line number Original line Diff line number Diff line
@@ -82,6 +82,14 @@ struct RawAbsoluteAxisInfo {
    int32_t fuzz;      // error tolerance, eg. fuzz == 4 means value is +/- 4 due to noise
    int32_t fuzz;      // error tolerance, eg. fuzz == 4 means value is +/- 4 due to noise


    inline int32_t getRange() { return maxValue - minValue; }
    inline int32_t getRange() { return maxValue - minValue; }

    inline void clear() {
        valid = false;
        minValue = 0;
        maxValue = 0;
        flat = 0;
        fuzz = 0;
    }
};
};


/*
/*
+4 −0
Original line number Original line Diff line number Diff line
@@ -453,6 +453,10 @@ public:
    inline void setKeyboardType(int32_t keyboardType) { mKeyboardType = keyboardType; }
    inline void setKeyboardType(int32_t keyboardType) { mKeyboardType = keyboardType; }
    inline int32_t getKeyboardType() const { return mKeyboardType; }
    inline int32_t getKeyboardType() const { return mKeyboardType; }


    inline const KeyedVector<int32_t, MotionRange> getMotionRanges() const {
        return mMotionRanges;
    }

private:
private:
    int32_t mId;
    int32_t mId;
    String8 mName;
    String8 mName;
+134 −23
Original line number Original line Diff line number Diff line
@@ -35,6 +35,34 @@ namespace android {
class InputDevice;
class InputDevice;
class InputMapper;
class InputMapper;


/* Describes a virtual key. */
struct VirtualKeyDefinition {
    int32_t scanCode;

    // configured position data, specified in display coords
    int32_t centerX;
    int32_t centerY;
    int32_t width;
    int32_t height;
};


/* Specifies input device calibration settings. */
class InputDeviceCalibration {
public:
    InputDeviceCalibration();

    void clear();
    void addProperty(const String8& key, const String8& value);

    bool tryGetProperty(const String8& key, String8& outValue) const;
    bool tryGetProperty(const String8& key, int32_t& outValue) const;
    bool tryGetProperty(const String8& key, float& outValue) const;

private:
    KeyedVector<String8, String8> mProperties;
};



/*
/*
 * Input reader policy interface.
 * Input reader policy interface.
@@ -73,17 +101,6 @@ public:
        ACTION_APP_SWITCH_COMING = 0x00000002,
        ACTION_APP_SWITCH_COMING = 0x00000002,
    };
    };


    /* Describes a virtual key. */
    struct VirtualKeyDefinition {
        int32_t scanCode;

        // configured position data, specified in display coords
        int32_t centerX;
        int32_t centerY;
        int32_t width;
        int32_t height;
    };

    /* Gets information about the display with the specified id.
    /* Gets information about the display with the specified id.
     * Returns true if the display info is available, false otherwise.
     * Returns true if the display info is available, false otherwise.
     */
     */
@@ -135,6 +152,10 @@ public:
    virtual void getVirtualKeyDefinitions(const String8& deviceName,
    virtual void getVirtualKeyDefinitions(const String8& deviceName,
            Vector<VirtualKeyDefinition>& outVirtualKeyDefinitions) = 0;
            Vector<VirtualKeyDefinition>& outVirtualKeyDefinitions) = 0;


    /* Gets the calibration for an input device. */
    virtual void getInputDeviceCalibration(const String8& deviceName,
            InputDeviceCalibration& outCalibration) = 0;

    /* Gets the excluded device names for the platform. */
    /* Gets the excluded device names for the platform. */
    virtual void getExcludedDeviceNames(Vector<String8>& outExcludedDeviceNames) = 0;
    virtual void getExcludedDeviceNames(Vector<String8>& outExcludedDeviceNames) = 0;
};
};
@@ -327,6 +348,10 @@ public:


    int32_t getMetaState();
    int32_t getMetaState();


    inline const InputDeviceCalibration& getCalibration() {
        return mCalibration;
    }

private:
private:
    InputReaderContext* mContext;
    InputReaderContext* mContext;
    int32_t mId;
    int32_t mId;
@@ -338,6 +363,8 @@ private:


    typedef int32_t (InputMapper::*GetStateFunc)(uint32_t sourceMask, int32_t code);
    typedef int32_t (InputMapper::*GetStateFunc)(uint32_t sourceMask, int32_t code);
    int32_t getState(uint32_t sourceMask, int32_t code, GetStateFunc getStateFunc);
    int32_t getState(uint32_t sourceMask, int32_t code, GetStateFunc getStateFunc);

    InputDeviceCalibration mCalibration;
};
};




@@ -538,12 +565,12 @@ protected:
        }
        }
    };
    };


    // Raw data for a single pointer.
    struct PointerData {
    struct PointerData {
        uint32_t id;
        uint32_t id;
        int32_t x;
        int32_t x;
        int32_t y;
        int32_t y;
        int32_t pressure;
        int32_t pressure;
        int32_t size;
        int32_t touchMajor;
        int32_t touchMajor;
        int32_t touchMinor;
        int32_t touchMinor;
        int32_t toolMajor;
        int32_t toolMajor;
@@ -551,6 +578,7 @@ protected:
        int32_t orientation;
        int32_t orientation;
    };
    };


    // Raw data for a collection of pointers including a pointer id mapping table.
    struct TouchData {
    struct TouchData {
        uint32_t pointerCount;
        uint32_t pointerCount;
        PointerData pointers[MAX_POINTERS];
        PointerData pointers[MAX_POINTERS];
@@ -584,18 +612,82 @@ protected:
        bool useAveragingTouchFilter;
        bool useAveragingTouchFilter;
    } mParameters;
    } mParameters;


    // Raw axis information.
    // Immutable calibration parameters in parsed form.
    struct Axes {
    struct Calibration {
        // Touch Area
        enum TouchAreaCalibration {
            TOUCH_AREA_CALIBRATION_DEFAULT,
            TOUCH_AREA_CALIBRATION_NONE,
            TOUCH_AREA_CALIBRATION_GEOMETRIC,
            TOUCH_AREA_CALIBRATION_PRESSURE,
        };

        TouchAreaCalibration touchAreaCalibration;

        // Tool Area
        enum ToolAreaCalibration {
            TOOL_AREA_CALIBRATION_DEFAULT,
            TOOL_AREA_CALIBRATION_NONE,
            TOOL_AREA_CALIBRATION_GEOMETRIC,
            TOOL_AREA_CALIBRATION_LINEAR,
        };

        ToolAreaCalibration toolAreaCalibration;
        bool haveToolAreaLinearScale;
        float toolAreaLinearScale;
        bool haveToolAreaLinearBias;
        float toolAreaLinearBias;
        bool haveToolAreaIsSummed;
        int32_t toolAreaIsSummed;

        // Pressure
        enum PressureCalibration {
            PRESSURE_CALIBRATION_DEFAULT,
            PRESSURE_CALIBRATION_NONE,
            PRESSURE_CALIBRATION_PHYSICAL,
            PRESSURE_CALIBRATION_AMPLITUDE,
        };
        enum PressureSource {
            PRESSURE_SOURCE_DEFAULT,
            PRESSURE_SOURCE_PRESSURE,
            PRESSURE_SOURCE_TOUCH,
        };

        PressureCalibration pressureCalibration;
        PressureSource pressureSource;
        bool havePressureScale;
        float pressureScale;

        // Size
        enum SizeCalibration {
            SIZE_CALIBRATION_DEFAULT,
            SIZE_CALIBRATION_NONE,
            SIZE_CALIBRATION_NORMALIZED,
        };

        SizeCalibration sizeCalibration;

        // Orientation
        enum OrientationCalibration {
            ORIENTATION_CALIBRATION_DEFAULT,
            ORIENTATION_CALIBRATION_NONE,
            ORIENTATION_CALIBRATION_INTERPOLATED,
        };

        OrientationCalibration orientationCalibration;
    } mCalibration;

    // Raw axis information from the driver.
    struct RawAxes {
        RawAbsoluteAxisInfo x;
        RawAbsoluteAxisInfo x;
        RawAbsoluteAxisInfo y;
        RawAbsoluteAxisInfo y;
        RawAbsoluteAxisInfo pressure;
        RawAbsoluteAxisInfo pressure;
        RawAbsoluteAxisInfo size;
        RawAbsoluteAxisInfo touchMajor;
        RawAbsoluteAxisInfo touchMajor;
        RawAbsoluteAxisInfo touchMinor;
        RawAbsoluteAxisInfo touchMinor;
        RawAbsoluteAxisInfo toolMajor;
        RawAbsoluteAxisInfo toolMajor;
        RawAbsoluteAxisInfo toolMinor;
        RawAbsoluteAxisInfo toolMinor;
        RawAbsoluteAxisInfo orientation;
        RawAbsoluteAxisInfo orientation;
    } mAxes;
    } mRawAxes;


    // Current and previous touch sample data.
    // Current and previous touch sample data.
    TouchData mCurrentTouch;
    TouchData mCurrentTouch;
@@ -620,10 +712,13 @@ protected:
        float yScale;
        float yScale;
        float yPrecision;
        float yPrecision;


        int32_t pressureOrigin;
        float geometricScale;

        float toolAreaLinearScale;
        float toolAreaLinearBias;

        float pressureScale;
        float pressureScale;


        int32_t sizeOrigin;
        float sizeScale;
        float sizeScale;


        float orientationScale;
        float orientationScale;
@@ -632,12 +727,22 @@ protected:
        struct OrientedRanges {
        struct OrientedRanges {
            InputDeviceInfo::MotionRange x;
            InputDeviceInfo::MotionRange x;
            InputDeviceInfo::MotionRange y;
            InputDeviceInfo::MotionRange y;

            bool havePressure;
            InputDeviceInfo::MotionRange pressure;
            InputDeviceInfo::MotionRange pressure;

            bool haveSize;
            InputDeviceInfo::MotionRange size;
            InputDeviceInfo::MotionRange size;

            bool haveTouchArea;
            InputDeviceInfo::MotionRange touchMajor;
            InputDeviceInfo::MotionRange touchMajor;
            InputDeviceInfo::MotionRange touchMinor;
            InputDeviceInfo::MotionRange touchMinor;

            bool haveToolArea;
            InputDeviceInfo::MotionRange toolMajor;
            InputDeviceInfo::MotionRange toolMajor;
            InputDeviceInfo::MotionRange toolMinor;
            InputDeviceInfo::MotionRange toolMinor;

            bool haveOrientation;
            InputDeviceInfo::MotionRange orientation;
            InputDeviceInfo::MotionRange orientation;
        } orientedRanges;
        } orientedRanges;


@@ -653,9 +758,14 @@ protected:
        } currentVirtualKey;
        } currentVirtualKey;
    } mLocked;
    } mLocked;


    virtual void configureAxes();
    virtual void configureParameters();
    virtual void configureRawAxes();
    virtual void logRawAxes();
    virtual bool configureSurfaceLocked();
    virtual bool configureSurfaceLocked();
    virtual void configureVirtualKeysLocked();
    virtual void configureVirtualKeysLocked();
    virtual void parseCalibration();
    virtual void resolveCalibration();
    virtual void logCalibration();


    enum TouchResult {
    enum TouchResult {
        // Dispatch the touch normally.
        // Dispatch the touch normally.
@@ -713,7 +823,8 @@ private:
    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, uint32_t pointerCount,
            int32_t motionEventAction);


    void applyPolicyAndDispatchVirtualKey(nsecs_t when, uint32_t policyFlags,
    void applyPolicyAndDispatchVirtualKey(nsecs_t when, uint32_t policyFlags,
            int32_t keyEventAction, int32_t keyEventFlags,
            int32_t keyEventAction, int32_t keyEventFlags,
@@ -738,7 +849,7 @@ public:
    virtual void process(const RawEvent* rawEvent);
    virtual void process(const RawEvent* rawEvent);


protected:
protected:
    virtual void configureAxes();
    virtual void configureRawAxes();


private:
private:
    struct Accumulator {
    struct Accumulator {
@@ -767,7 +878,7 @@ private:
    int32_t mX;
    int32_t mX;
    int32_t mY;
    int32_t mY;
    int32_t mPressure;
    int32_t mPressure;
    int32_t mSize;
    int32_t mToolWidth;


    void initialize();
    void initialize();


@@ -784,7 +895,7 @@ public:
    virtual void process(const RawEvent* rawEvent);
    virtual void process(const RawEvent* rawEvent);


protected:
protected:
    virtual void configureAxes();
    virtual void configureRawAxes();


private:
private:
    struct Accumulator {
    struct Accumulator {
+2 −7
Original line number Original line Diff line number Diff line
@@ -139,11 +139,7 @@ uint32_t EventHub::getDeviceClasses(int32_t deviceId) const


status_t EventHub::getAbsoluteAxisInfo(int32_t deviceId, int axis,
status_t EventHub::getAbsoluteAxisInfo(int32_t deviceId, int axis,
        RawAbsoluteAxisInfo* outAxisInfo) const {
        RawAbsoluteAxisInfo* outAxisInfo) const {
    outAxisInfo->valid = false;
    outAxisInfo->clear();
    outAxisInfo->minValue = 0;
    outAxisInfo->maxValue = 0;
    outAxisInfo->flat = 0;
    outAxisInfo->fuzz = 0;


    AutoMutex _l(mLock);
    AutoMutex _l(mLock);
    device_t* device = getDevice(deviceId);
    device_t* device = getDevice(deviceId);
@@ -709,8 +705,7 @@ int EventHub::open_device(const char *deviceName)
    LOGV("Getting absolute controllers...");
    LOGV("Getting absolute controllers...");
    if (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(abs_bitmask)), abs_bitmask) >= 0) {
    if (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(abs_bitmask)), abs_bitmask) >= 0) {
        // Is this a new modern multi-touch driver?
        // Is this a new modern multi-touch driver?
        if (test_bit(ABS_MT_TOUCH_MAJOR, abs_bitmask)
        if (test_bit(ABS_MT_POSITION_X, abs_bitmask)
                && test_bit(ABS_MT_POSITION_X, abs_bitmask)
                && test_bit(ABS_MT_POSITION_Y, abs_bitmask)) {
                && test_bit(ABS_MT_POSITION_Y, abs_bitmask)) {
            device->classes |= INPUT_DEVICE_CLASS_TOUCHSCREEN | INPUT_DEVICE_CLASS_TOUCHSCREEN_MT;
            device->classes |= INPUT_DEVICE_CLASS_TOUCHSCREEN | INPUT_DEVICE_CLASS_TOUCHSCREEN_MT;


+15 −7
Original line number Original line Diff line number Diff line
@@ -405,12 +405,15 @@ void InputDispatcher::processMotionLockedInterruptible(
        sampleCount += 1;
        sampleCount += 1;
    }
    }
    for (uint32_t i = 0; i < entry->pointerCount; i++) {
    for (uint32_t i = 0; i < entry->pointerCount; i++) {
        LOGD("  Pointer %d: id=%d, x=%f, y=%f, pressure=%f, size=%f",
        LOGD("  Pointer %d: id=%d, x=%f, y=%f, pressure=%f, size=%f, "
                "touchMajor=%f, touchMinor=%d, toolMajor=%f, toolMinor=%f, "
                "orientation=%f",
                i, entry->pointerIds[i],
                i, entry->pointerIds[i],
                sample->pointerCoords[i].x,
                sample->pointerCoords[i].x, sample->pointerCoords[i].y,
                sample->pointerCoords[i].y,
                sample->pointerCoords[i].pressure, sample->pointerCoords[i].size,
                sample->pointerCoords[i].pressure,
                sample->pointerCoords[i].touchMajor, sample->pointerCoords[i].touchMinor,
                sample->pointerCoords[i].size);
                sample->pointerCoords[i].toolMajor, sample->pointerCoords[i].toolMinor,
                sample->pointerCoords[i].orientation);
    }
    }


    // Keep in mind that due to batching, it is possible for the number of samples actually
    // Keep in mind that due to batching, it is possible for the number of samples actually
@@ -1080,9 +1083,14 @@ void InputDispatcher::notifyMotion(nsecs_t eventTime, int32_t deviceId, int32_t
            eventTime, deviceId, source, policyFlags, action, metaState, edgeFlags,
            eventTime, deviceId, source, policyFlags, action, metaState, edgeFlags,
            xPrecision, yPrecision, downTime);
            xPrecision, yPrecision, downTime);
    for (uint32_t i = 0; i < pointerCount; i++) {
    for (uint32_t i = 0; i < pointerCount; i++) {
        LOGD("  Pointer %d: id=%d, x=%f, y=%f, pressure=%f, size=%f",
        LOGD("  Pointer %d: id=%d, x=%f, y=%f, pressure=%f, size=%f, "
                "touchMajor=%f, touchMinor=%d, toolMajor=%f, toolMinor=%f, "
                "orientation=%f",
                i, pointerIds[i], pointerCoords[i].x, pointerCoords[i].y,
                i, pointerIds[i], pointerCoords[i].x, pointerCoords[i].y,
                pointerCoords[i].pressure, pointerCoords[i].size);
                pointerCoords[i].pressure, pointerCoords[i].size,
                pointerCoords[i].touchMajor, pointerCoords[i].touchMinor,
                pointerCoords[i].toolMajor, pointerCoords[i].toolMinor,
                pointerCoords[i].orientation);
    }
    }
#endif
#endif


Loading