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

Commit 1dcef1b4 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Pass MotionEvent by reference

When the object being passed isn't nullable, it should be passed by
reference rather than by pointer.

This makes it clear to the caller that the passed object should always
be valid.

Bug: 236772648
Test: TEST=libinput_tests; m $TEST && $ANDROID_HOST_OUT/nativetest64/$TEST/$TEST
Change-Id: Ib3d4ef1c4a93471dff8de53b7c7873ccf55e7266
parent ce725ae0
Loading
Loading
Loading
Loading
+4 −4
Original line number Original line Diff line number Diff line
@@ -39,7 +39,7 @@ public:
    explicit VelocityTrackerState(const VelocityTracker::Strategy strategy);
    explicit VelocityTrackerState(const VelocityTracker::Strategy strategy);


    void clear();
    void clear();
    void addMovement(const MotionEvent* event);
    void addMovement(const MotionEvent& event);
    // TODO(b/32830165): consider supporting an overload that supports computing velocity only for
    // TODO(b/32830165): consider supporting an overload that supports computing velocity only for
    // a subset of the supported axes.
    // a subset of the supported axes.
    void computeCurrentVelocity(int32_t units, float maxVelocity);
    void computeCurrentVelocity(int32_t units, float maxVelocity);
@@ -57,7 +57,7 @@ void VelocityTrackerState::clear() {
    mVelocityTracker.clear();
    mVelocityTracker.clear();
}
}


void VelocityTrackerState::addMovement(const MotionEvent* event) {
void VelocityTrackerState::addMovement(const MotionEvent& event) {
    mVelocityTracker.addMovement(event);
    mVelocityTracker.addMovement(event);
}
}


@@ -102,13 +102,13 @@ static void android_view_VelocityTracker_nativeClear(JNIEnv* env, jclass clazz,
static void android_view_VelocityTracker_nativeAddMovement(JNIEnv* env, jclass clazz, jlong ptr,
static void android_view_VelocityTracker_nativeAddMovement(JNIEnv* env, jclass clazz, jlong ptr,
        jobject eventObj) {
        jobject eventObj) {
    const MotionEvent* event = android_view_MotionEvent_getNativePtr(env, eventObj);
    const MotionEvent* event = android_view_MotionEvent_getNativePtr(env, eventObj);
    if (!event) {
    if (event == nullptr) {
        LOG(WARNING) << "nativeAddMovement failed because MotionEvent was finalized.";
        LOG(WARNING) << "nativeAddMovement failed because MotionEvent was finalized.";
        return;
        return;
    }
    }


    VelocityTrackerState* state = reinterpret_cast<VelocityTrackerState*>(ptr);
    VelocityTrackerState* state = reinterpret_cast<VelocityTrackerState*>(ptr);
    state->addMovement(event);
    state->addMovement(*event);
}
}


static void android_view_VelocityTracker_nativeComputeCurrentVelocity(JNIEnv* env, jclass clazz,
static void android_view_VelocityTracker_nativeComputeCurrentVelocity(JNIEnv* env, jclass clazz,