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

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

Merge "Treat Bluetooth-smoothened events with modified timestmaps as synthetic"

parents 31208418 61a243a3
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -300,10 +300,11 @@ std::list<NotifyArgs> CursorInputMapper::process(const RawEvent* rawEvent) {
    mCursorScrollAccumulator.process(rawEvent);

    if (rawEvent->type == EV_SYN && rawEvent->code == SYN_REPORT) {
        const nsecs_t eventTime =
        const auto [eventTime, readTime] =
                applyBluetoothTimestampSmoothening(getDeviceContext().getDeviceIdentifier(),
                                                   rawEvent->when, mLastEventTime);
        out += sync(eventTime, rawEvent->readTime);
                                                   rawEvent->when, rawEvent->readTime,
                                                   mLastEventTime);
        out += sync(eventTime, readTime);
        mLastEventTime = eventTime;
    }
    return out;
+12 −5
Original line number Diff line number Diff line
@@ -110,10 +110,11 @@ static bool isPointerDown(int32_t buttonState) {
// coordinates result in extremely large instantaneous velocities, which can negatively impact
// user experience. To avoid this, we augment the timestamps so that subsequent event timestamps
// differ by at least a minimum delta value.
static nsecs_t applyBluetoothTimestampSmoothening(const InputDeviceIdentifier& identifier,
                                                  nsecs_t currentEventTime, nsecs_t lastEventTime) {
static std::tuple<nsecs_t /*eventTime*/, nsecs_t /*readTime*/> applyBluetoothTimestampSmoothening(
        const InputDeviceIdentifier& identifier, nsecs_t currentEventTime, nsecs_t readTime,
        nsecs_t lastEventTime) {
    if (identifier.bus != BUS_BLUETOOTH) {
        return currentEventTime;
        return {currentEventTime, readTime};
    }

    // Assume the fastest rate at which a Bluetooth touch device can report input events is one
@@ -123,8 +124,14 @@ static nsecs_t applyBluetoothTimestampSmoothening(const InputDeviceIdentifier& i
    // We define a maximum smoothing time delta so that we don't generate events too far into the
    // future.
    constexpr static nsecs_t MAX_BLUETOOTH_SMOOTHING_DELTA = ms2ns(32);
    return std::min(std::max(currentEventTime, lastEventTime + MIN_BLUETOOTH_TIMESTAMP_DELTA),
    const nsecs_t smoothenedEventTime =
            std::min(std::max(currentEventTime, lastEventTime + MIN_BLUETOOTH_TIMESTAMP_DELTA),
                     currentEventTime + MAX_BLUETOOTH_SMOOTHING_DELTA);
    // If we are modifying the event time, treat this event as a synthetically generated event for
    // latency tracking purposes and use the event time as the read time (zero read latency).
    const nsecs_t smoothenedReadTime =
            smoothenedEventTime != currentEventTime ? currentEventTime : readTime;
    return {smoothenedEventTime, smoothenedReadTime};
}

} // namespace android
+3 −2
Original line number Diff line number Diff line
@@ -1467,8 +1467,9 @@ std::list<NotifyArgs> TouchInputMapper::sync(nsecs_t when, nsecs_t readTime) {
    const RawState& last =
            mRawStatesPending.size() == 1 ? mCurrentRawState : mRawStatesPending.rbegin()[1];

    next.when = applyBluetoothTimestampSmoothening(getDeviceContext().getDeviceIdentifier(), when,
                                                   last.when);
    std::tie(next.when, next.readTime) =
            applyBluetoothTimestampSmoothening(getDeviceContext().getDeviceIdentifier(), when,
                                               readTime, last.when);

    // Assign pointer ids.
    if (!mHavePointerIds) {