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

Commit 07d83380 authored by Yeabkal Wubshit's avatar Yeabkal Wubshit Committed by Android (Google) Code Review
Browse files

Merge "Updates to SlopController"

parents 02c678fe f1ed7055
Loading
Loading
Loading
Loading
+12 −8
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@

#include "RotaryEncoderInputMapper.h"

#include <utils/Timers.h>
#include <optional>

#include "CursorScrollAccumulator.h"
@@ -30,14 +31,6 @@ RotaryEncoderInputMapper::RotaryEncoderInputMapper(InputDeviceContext& deviceCon
                                                   const InputReaderConfiguration& readerConfig)
      : InputMapper(deviceContext, readerConfig), mOrientation(ui::ROTATION_0) {
    mSource = AINPUT_SOURCE_ROTARY_ENCODER;

    const PropertyMap& config = getDeviceContext().getConfiguration();
    float slopThreshold = config.getInt("rotary_encoder.slop_threshold").value_or(0);
    int32_t slopDurationMs = config.getInt("rotary_encoder.slop_duration_ms").value_or(0);
    if (slopThreshold > 0 && slopDurationMs > 0) {
        mSlopController = std::make_unique<SlopController>(slopThreshold,
                                                           (nsecs_t)(slopDurationMs * 1000000));
    }
}

RotaryEncoderInputMapper::~RotaryEncoderInputMapper() {}
@@ -70,6 +63,7 @@ void RotaryEncoderInputMapper::dump(std::string& dump) {
    dump += INDENT2 "Rotary Encoder Input Mapper:\n";
    dump += StringPrintf(INDENT3 "HaveWheel: %s\n",
                         toString(mRotaryEncoderScrollAccumulator.haveRelativeVWheel()));
    dump += StringPrintf(INDENT3 "HaveSlopController: %s\n", toString(mSlopController != nullptr));
}

std::list<NotifyArgs> RotaryEncoderInputMapper::reconfigure(nsecs_t when,
@@ -78,6 +72,16 @@ std::list<NotifyArgs> RotaryEncoderInputMapper::reconfigure(nsecs_t when,
    std::list<NotifyArgs> out = InputMapper::reconfigure(when, config, changes);
    if (!changes.any()) {
        mRotaryEncoderScrollAccumulator.configure(getDeviceContext());

        const PropertyMap& propertyMap = getDeviceContext().getConfiguration();
        float slopThreshold = propertyMap.getInt("rotary_encoder.slop_threshold").value_or(0);
        int32_t slopDurationNs = milliseconds_to_nanoseconds(
                propertyMap.getInt("rotary_encoder.slop_duration_ms").value_or(0));
        if (slopThreshold > 0 && slopDurationNs > 0) {
            mSlopController = std::make_unique<SlopController>(slopThreshold, slopDurationNs);
        } else {
            mSlopController = nullptr;
        }
    }
    if (!changes.any() || changes.test(InputReaderConfiguration::Change::DISPLAY_INFO)) {
        std::optional<DisplayViewport> internalViewport =
+1 −1
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@ private:
    int32_t mSource;
    float mScalingFactor;
    ui::Rotation mOrientation;
    std::unique_ptr<SlopController> mSlopController = nullptr;
    std::unique_ptr<SlopController> mSlopController;

    explicit RotaryEncoderInputMapper(InputDeviceContext& deviceContext,
                                      const InputReaderConfiguration& readerConfig);
+1 −3
Original line number Diff line number Diff line
@@ -33,8 +33,6 @@ namespace android {
SlopController::SlopController(float slopThreshold, nsecs_t slopDurationNanos)
      : mSlopThreshold(slopThreshold), mSlopDurationNanos(slopDurationNanos) {}

SlopController::~SlopController() {}

float SlopController::consumeEvent(nsecs_t eventTimeNanos, float value) {
    if (mSlopDurationNanos == 0) {
        return value;
@@ -64,7 +62,7 @@ float SlopController::consumeEvent(nsecs_t eventTimeNanos, float value) {
    return 0;
}

bool SlopController::shouldResetSlopTracking(nsecs_t eventTimeNanos, float value) {
bool SlopController::shouldResetSlopTracking(nsecs_t eventTimeNanos, float value) const {
    const nsecs_t ageNanos = eventTimeNanos - mLastEventTimeNanos;
    if (ageNanos >= mSlopDurationNanos) {
        return true;
+2 −3
Original line number Diff line number Diff line
@@ -28,10 +28,9 @@ namespace android {
 * Current slop logic:
 *      "If time since last event > Xns, then discard the next N values."
 */
class SlopController {
class SlopController final {
public:
    SlopController(float slopThreshold, nsecs_t slopDurationNanos);
    virtual ~SlopController();

    /**
     * Consumes an event with a given time and value for slop processing.
@@ -40,7 +39,7 @@ public:
    float consumeEvent(nsecs_t eventTime, float value);

private:
    bool shouldResetSlopTracking(nsecs_t eventTimeNanos, float value);
    bool shouldResetSlopTracking(nsecs_t eventTimeNanos, float value) const;

    /** The amount of event values ignored after an inactivity of the slop duration. */
    const float mSlopThreshold;