void GeckoTouchDispatcher::ResampleTouchMoves(MultiTouchInput& aOutTouch, TimeStamp aVsyncTime) { MOZ_RELEASE_ASSERT(mTouchMoveEvents.size() >= 2); mTouchQueueLock.AssertCurrentThreadOwns(); MultiTouchInput currentTouch = mTouchMoveEvents.back(); mTouchMoveEvents.pop_back(); MultiTouchInput baseTouch = mTouchMoveEvents.back(); mTouchMoveEvents.clear(); mTouchMoveEvents.push_back(currentTouch); TimeStamp sampleTime = aVsyncTime - mVsyncAdjust; TimeDuration touchDiff = currentTouch.mTimeStamp - baseTouch.mTimeStamp; if (touchDiff < mMinDelta) { aOutTouch = currentTouch; #ifdef LOG_RESAMPLE_DATA LOG("The touches are too close, skip resampling\n"); #endif return; } if (currentTouch.mTimeStamp < sampleTime) { TimeDuration maxResampleTime = std::min(touchDiff / int64_t(2), mMaxPredict); TimeStamp maxTimestamp = currentTouch.mTimeStamp + maxResampleTime; if (sampleTime > maxTimestamp) { sampleTime = maxTimestamp; #ifdef LOG_RESAMPLE_DATA LOG("Overshot extrapolation time, adjusting sample time\n"); #endif } } ResampleTouch(aOutTouch, baseTouch, currentTouch, sampleTime - baseTouch.mTimeStamp, touchDiff); // Both mTimeStamp and mTime are being updated to sampleTime here. // mTime needs to be updated using a delta since TimeStamp doesn't // provide a way to obtain a raw value. aOutTouch.mTime += (sampleTime - aOutTouch.mTimeStamp).ToMilliseconds(); aOutTouch.mTimeStamp = sampleTime; }
// Interpolates with the touch event prior to SampleTime // and with the future touch event past sample time int32_t GeckoTouchDispatcher::InterpolateTouch(MultiTouchInput& aOutTouch, uint64_t aSampleTime) { MOZ_RELEASE_ASSERT(mTouchMoveEvents.size() >= 2); mTouchQueueLock.AssertCurrentThreadOwns(); // currentTouch < SampleTime < futureTouch MultiTouchInput futureTouch = mTouchMoveEvents.back(); mTouchMoveEvents.pop_back(); MultiTouchInput currentTouch = mTouchMoveEvents.back(); mTouchMoveEvents.clear(); mTouchMoveEvents.push_back(futureTouch); uint64_t currentTouchTime = mLastTouchTime - mTouchTimeDiff; int64_t frameDiff = aSampleTime - currentTouchTime; ResampleTouch(aOutTouch, currentTouch, futureTouch, frameDiff, mTouchTimeDiff, true); return nanosecToMillisec(frameDiff); }