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

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

Merge "Add touch resampling native tests"

parents 99937fac 0ced3cc7
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -452,8 +452,11 @@ private:
 */
class InputConsumer {
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);
    /* 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. */
    ~InputConsumer();
+16 −4
Original line number 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
// 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.
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(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() {
}
@@ -751,7 +755,10 @@ status_t InputConsumer::consume(InputEventFactoryInterface* factory, bool consum
            // Receive a fresh message.
            status_t result = mChannel->receiveMessage(&mMsg);
            if (result == OK) {
                const auto [_, inserted] =
                        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) {
                // 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;
        if (mResampleTouch) {
            sampleTime -= RESAMPLE_LATENCY;
            sampleTime -= std::chrono::nanoseconds(RESAMPLE_LATENCY).count();
        }
        ssize_t split = findSampleNoLaterThan(batch, sampleTime);
        if (split < 0) {
@@ -1166,6 +1173,11 @@ void InputConsumer::resampleTouchState(nsecs_t sampleTime, MotionEvent* event,
        return;
    }

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

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

#include "TestHelpers.h"

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

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

using android::base::Result;

+562 −0

File added.

Preview size limit exceeded, changes collapsed.