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

Commit 0ced3cc7 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Add touch resampling native tests

Add native tests for touch resampling.
These test the resampling logic in InputTransport.cpp by
sending a pre-determined set of InputEvents via InputPublisher
and read the events back from InputConsumer. The events that are
read back are compared to pre-determined set of events.

Bug: 35412046
Bug: 68840121
Bug: 119214052
Test: atest libinput_tests

Change-Id: I596a6528b8ab27a68d0e9baafa3a8cb6b62d0422
parent bcb90882
Loading
Loading
Loading
Loading
+4 −1
Original line number Original line Diff line number Diff line
@@ -452,8 +452,11 @@ private:
 */
 */
class InputConsumer {
class InputConsumer {
public:
public:
    /* Creates a consumer associated with an input channel. */
    /* Create a consumer associated with an input channel. */
    explicit InputConsumer(const std::shared_ptr<InputChannel>& channel);
    explicit InputConsumer(const std::shared_ptr<InputChannel>& channel);
    /* Create a consumer associated with an input channel, override resampling system property */
    explicit InputConsumer(const std::shared_ptr<InputChannel>& channel,
                           bool enableTouchResampling);


    /* Destroys the consumer and releases its input channel. */
    /* Destroys the consumer and releases its input channel. */
    ~InputConsumer();
    ~InputConsumer();
+16 −4
Original line number Original line Diff line number Diff line
@@ -51,7 +51,7 @@ static const nsecs_t NANOS_PER_MS = 1000000;


// Latency added during resampling.  A few milliseconds doesn't hurt much but
// Latency added during resampling.  A few milliseconds doesn't hurt much but
// reduces the impact of mispredicted touch positions.
// reduces the impact of mispredicted touch positions.
static const nsecs_t RESAMPLE_LATENCY = 5 * NANOS_PER_MS;
const std::chrono::duration RESAMPLE_LATENCY = 5ms;


// Minimum time difference between consecutive samples before attempting to resample.
// Minimum time difference between consecutive samples before attempting to resample.
static const nsecs_t RESAMPLE_MIN_DELTA = 2 * NANOS_PER_MS;
static const nsecs_t RESAMPLE_MIN_DELTA = 2 * NANOS_PER_MS;
@@ -721,7 +721,11 @@ android::base::Result<InputPublisher::ConsumerResponse> InputPublisher::receiveC
// --- InputConsumer ---
// --- InputConsumer ---


InputConsumer::InputConsumer(const std::shared_ptr<InputChannel>& channel)
InputConsumer::InputConsumer(const std::shared_ptr<InputChannel>& channel)
      : mResampleTouch(isTouchResamplingEnabled()), mChannel(channel), mMsgDeferred(false) {}
      : InputConsumer(channel, isTouchResamplingEnabled()) {}

InputConsumer::InputConsumer(const std::shared_ptr<InputChannel>& channel,
                             bool enableTouchResampling)
      : mResampleTouch(enableTouchResampling), mChannel(channel), mMsgDeferred(false) {}


InputConsumer::~InputConsumer() {
InputConsumer::~InputConsumer() {
}
}
@@ -751,7 +755,10 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory, bool consum
            // Receive a fresh message.
            // Receive a fresh message.
            status_t result = mChannel->receiveMessage(&mMsg);
            status_t result = mChannel->receiveMessage(&mMsg);
            if (result == OK) {
            if (result == OK) {
                const auto [_, inserted] =
                        mConsumeTimes.emplace(mMsg.header.seq, systemTime(SYSTEM_TIME_MONOTONIC));
                        mConsumeTimes.emplace(mMsg.header.seq, systemTime(SYSTEM_TIME_MONOTONIC));
                LOG_ALWAYS_FATAL_IF(!inserted, "Already have a consume time for seq=%" PRIu32,
                                    mMsg.header.seq);
            }
            }
            if (result) {
            if (result) {
                // Consume the next batched event unless batches are being held for later.
                // Consume the next batched event unless batches are being held for later.
@@ -918,7 +925,7 @@ status_t InputConsumer::consumeBatch(InputEventFactoryInterface* factory,


        nsecs_t sampleTime = frameTime;
        nsecs_t sampleTime = frameTime;
        if (mResampleTouch) {
        if (mResampleTouch) {
            sampleTime -= RESAMPLE_LATENCY;
            sampleTime -= std::chrono::nanoseconds(RESAMPLE_LATENCY).count();
        }
        }
        ssize_t split = findSampleNoLaterThan(batch, sampleTime);
        ssize_t split = findSampleNoLaterThan(batch, sampleTime);
        if (split < 0) {
        if (split < 0) {
@@ -1166,6 +1173,11 @@ void InputConsumer::resampleTouchState(nsecs_t sampleTime, MotionEvent* event,
        return;
        return;
    }
    }


    if (current->eventTime == sampleTime) {
        // Prevents having 2 events with identical times and coordinates.
        return;
    }

    // Resample touch coordinates.
    // Resample touch coordinates.
    History oldLastResample;
    History oldLastResample;
    oldLastResample.initializeFrom(touchState.lastResample);
    oldLastResample.initializeFrom(touchState.lastResample);
+1 −0
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@ cc_test {
        "InputDevice_test.cpp",
        "InputDevice_test.cpp",
        "InputEvent_test.cpp",
        "InputEvent_test.cpp",
        "InputPublisherAndConsumer_test.cpp",
        "InputPublisherAndConsumer_test.cpp",
        "TouchResampling_test.cpp",
        "TouchVideoFrame_test.cpp",
        "TouchVideoFrame_test.cpp",
        "VelocityTracker_test.cpp",
        "VelocityTracker_test.cpp",
        "VerifiedInputEvent_test.cpp",
        "VerifiedInputEvent_test.cpp",
+0 −7
Original line number Original line Diff line number Diff line
@@ -16,17 +16,10 @@


#include "TestHelpers.h"
#include "TestHelpers.h"


#include <unistd.h>
#include <sys/mman.h>
#include <time.h>

#include <attestation/HmacKeyManager.h>
#include <attestation/HmacKeyManager.h>
#include <cutils/ashmem.h>
#include <gtest/gtest.h>
#include <gtest/gtest.h>
#include <gui/constants.h>
#include <gui/constants.h>
#include <input/InputTransport.h>
#include <input/InputTransport.h>
#include <utils/StopWatch.h>
#include <utils/Timers.h>


using android::base::Result;
using android::base::Result;