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

Commit 771526c8 authored by Jeff Brown's avatar Jeff Brown
Browse files

Resample touch events on frame boundaries.

Bug: 6375101
Change-Id: I8774e366306bb2b6b4e42b913525bf25b0380ec3
parent 330314c6
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -46,7 +46,8 @@ public abstract class InputEventReceiver {
            InputChannel inputChannel, MessageQueue messageQueue);
    private static native void nativeDispose(int receiverPtr);
    private static native void nativeFinishInputEvent(int receiverPtr, int seq, boolean handled);
    private static native void nativeConsumeBatchedInputEvents(int receiverPtr);
    private static native void nativeConsumeBatchedInputEvents(int receiverPtr,
            long frameTimeNanos);

    /**
     * Creates an input event receiver bound to the specified input channel.
@@ -114,7 +115,7 @@ public abstract class InputEventReceiver {
     * immediately (such as a pointer up event).
     */
    public void onBatchedInputEventPending() {
        consumeBatchedInputEvents();
        consumeBatchedInputEvents(-1);
    }

    /**
@@ -150,13 +151,16 @@ public abstract class InputEventReceiver {
     *
     * This method forces all batched input events to be delivered immediately.
     * Should be called just before animating or drawing a new frame in the UI.
     *
     * @param frameTimeNanos The time in the {@link System#nanoTime()} time base
     * when the current display frame started rendering, or -1 if unknown.
     */
    public final void consumeBatchedInputEvents() {
    public final void consumeBatchedInputEvents(long frameTimeNanos) {
        if (mReceiverPtr == 0) {
            Log.w(TAG, "Attempted to consume batched input events but the input event "
                    + "receiver has already been disposed.");
        } else {
            nativeConsumeBatchedInputEvents(mReceiverPtr);
            nativeConsumeBatchedInputEvents(mReceiverPtr, frameTimeNanos);
        }
    }

+3 −3
Original line number Diff line number Diff line
@@ -4204,11 +4204,11 @@ public final class ViewRootImpl implements ViewParent,
        }
    }

    void doConsumeBatchedInput() {
    void doConsumeBatchedInput(long frameTimeNanos) {
        if (mConsumeBatchedInputScheduled) {
            mConsumeBatchedInputScheduled = false;
            if (mInputEventReceiver != null) {
                mInputEventReceiver.consumeBatchedInputEvents();
                mInputEventReceiver.consumeBatchedInputEvents(frameTimeNanos);
            }
            doProcessInputEvents();
        }
@@ -4248,7 +4248,7 @@ public final class ViewRootImpl implements ViewParent,
    final class ConsumeBatchedInputRunnable implements Runnable {
        @Override
        public void run() {
            doConsumeBatchedInput();
            doConsumeBatchedInput(mChoreographer.getFrameTimeNanos());
        }
    }
    final ConsumeBatchedInputRunnable mConsumedBatchedInputRunnable =
+1 −1
Original line number Diff line number Diff line
@@ -207,7 +207,7 @@ int32_t AInputQueue::getEvent(AInputEvent** outEvent) {

    uint32_t consumerSeq;
    InputEvent* myEvent = NULL;
    status_t res = mConsumer.consume(&mPooledInputEventFactory, true /*consumeBatches*/,
    status_t res = mConsumer.consume(&mPooledInputEventFactory, true /*consumeBatches*/, -1,
            &consumerSeq, &myEvent);
    if (res != android::OK) {
        if (res != android::WOULD_BLOCK) {
+11 −9
Original line number Diff line number Diff line
@@ -52,7 +52,7 @@ public:

    status_t initialize();
    status_t finishInputEvent(uint32_t seq, bool handled);
    status_t consumeEvents(JNIEnv* env, bool consumeBatches);
    status_t consumeEvents(JNIEnv* env, bool consumeBatches, nsecs_t frameTime);

protected:
    virtual ~NativeInputEventReceiver();
@@ -130,15 +130,16 @@ int NativeInputEventReceiver::handleReceiveCallback(int receiveFd, int events, v
    }

    JNIEnv* env = AndroidRuntime::getJNIEnv();
    status_t status = r->consumeEvents(env, false /*consumeBatches*/);
    status_t status = r->consumeEvents(env, false /*consumeBatches*/, -1);
    r->mMessageQueue->raiseAndClearException(env, "handleReceiveCallback");
    return status == OK || status == NO_MEMORY ? 1 : 0;
}

status_t NativeInputEventReceiver::consumeEvents(JNIEnv* env, bool consumeBatches) {
status_t NativeInputEventReceiver::consumeEvents(JNIEnv* env,
        bool consumeBatches, nsecs_t frameTime) {
#if DEBUG_DISPATCH_CYCLE
    ALOGD("channel '%s' ~ Consuming input events, consumeBatches=%s.", getInputChannelName(),
            consumeBatches ? "true" : "false");
    ALOGD("channel '%s' ~ Consuming input events, consumeBatches=%s, frameTime=%lld.",
            getInputChannelName(), consumeBatches ? "true" : "false", frameTime);
#endif

    if (consumeBatches) {
@@ -150,7 +151,7 @@ status_t NativeInputEventReceiver::consumeEvents(JNIEnv* env, bool consumeBatche
        uint32_t seq;
        InputEvent* inputEvent;
        status_t status = mInputConsumer.consume(&mInputEventFactory,
                consumeBatches, &seq, &inputEvent);
                consumeBatches, frameTime, &seq, &inputEvent);
        if (status) {
            if (status == WOULD_BLOCK) {
                if (!skipCallbacks && !mBatchedInputEventPending
@@ -270,10 +271,11 @@ static void nativeFinishInputEvent(JNIEnv* env, jclass clazz, jint receiverPtr,
    }
}

static void nativeConsumeBatchedInputEvents(JNIEnv* env, jclass clazz, jint receiverPtr) {
static void nativeConsumeBatchedInputEvents(JNIEnv* env, jclass clazz, jint receiverPtr,
        jlong frameTimeNanos) {
    sp<NativeInputEventReceiver> receiver =
            reinterpret_cast<NativeInputEventReceiver*>(receiverPtr);
    status_t status = receiver->consumeEvents(env, true /*consumeBatches*/);
    status_t status = receiver->consumeEvents(env, true /*consumeBatches*/, frameTimeNanos);
    if (status && status != DEAD_OBJECT && !env->ExceptionCheck()) {
        String8 message;
        message.appendFormat("Failed to consume batched input event.  status=%d", status);
@@ -291,7 +293,7 @@ static JNINativeMethod gMethods[] = {
            (void*)nativeDispose },
    { "nativeFinishInputEvent", "(IIZ)V",
            (void*)nativeFinishInputEvent },
    { "nativeConsumeBatchedInputEvents", "(I)V",
    { "nativeConsumeBatchedInputEvents", "(IJ)V",
            (void*)nativeConsumeBatchedInputEvents },
};

+1 −0
Original line number Diff line number Diff line
@@ -208,6 +208,7 @@ struct PointerCoords {
    status_t setAxisValue(int32_t axis, float value);

    void scale(float scale);
    void lerp(const PointerCoords& a, const PointerCoords& b, float alpha);

    inline float getX() const {
        return getAxisValue(AMOTION_EVENT_AXIS_X);
Loading