Provide prediction time from the application
After further discussion with the graphics team, it turns out that the
Choreographer isn't the best way to compute the prediction time.
There may be some strategy that would use the Choreographer, like
looking at the last vsync and trying to guess when the next drawing will
occur.
However, for now, let's just provide this time from the application and
experiment with it. If we do need the Choreographer, we should be able
to get this data from libgui here in the native layer, so we don't need
the java to set this time, anyways.
Bug: 167946763
Test: atest libinput_tests inputflinger_tests
Change-Id: I496a9c184745d4cec085b880f913983cc2be9e3f
diff --git a/libs/input/MotionPredictor.cpp b/libs/input/MotionPredictor.cpp
index 0719fe5..5e2ffa6 100644
--- a/libs/input/MotionPredictor.cpp
+++ b/libs/input/MotionPredictor.cpp
@@ -55,7 +55,7 @@
* The returned event should not contain any of the real, existing data. It should only
* contain the predicted samples.
*/
-std::vector<std::unique_ptr<MotionEvent>> MotionPredictor::predict() {
+std::vector<std::unique_ptr<MotionEvent>> MotionPredictor::predict(nsecs_t timestamp) {
if (mEvents.size() < 2) {
return {};
}
@@ -67,7 +67,7 @@
std::unique_ptr<MotionEvent> prediction = std::make_unique<MotionEvent>();
std::vector<PointerCoords> futureCoords;
- const int64_t futureTime = getExpectedPresentationTimeNanos() + mPredictionTimestampOffsetNanos;
+ const nsecs_t futureTime = timestamp + mPredictionTimestampOffsetNanos;
const nsecs_t currentTime = event.getEventTime();
const MotionEvent& previous = mEvents.rbegin()[1];
const nsecs_t oldTime = previous.getEventTime();
@@ -143,14 +143,4 @@
return true;
}
-int64_t MotionPredictor::getExpectedPresentationTimeNanos() {
- std::scoped_lock lock(mLock);
- return mExpectedPresentationTimeNanos;
-}
-
-void MotionPredictor::setExpectedPresentationTimeNanos(int64_t expectedPresentationTimeNanos) {
- std::scoped_lock lock(mLock);
- mExpectedPresentationTimeNanos = expectedPresentationTimeNanos;
-}
-
} // namespace android