Commit 3289d053 authored by Ella Ge's avatar Ella Ge Committed by Commit Bot

Scroll prediction use actual predict timestamp

In scroll prediction, we set the resampled event time to the
prediction_time (frame time or the timestamp we try to predict to).
However some predictor (linear resampling) may change the sample time.
LinearResampling changes it to frame_time - 5ms.

This causes the prediction metrics (introduced in crrev.com/c/1764409)
comparing the predicted result with wrong interpolated point.

This CL makes the predictors' return value (InputData type) also applies
the actual predict time.

Change-Id: Ib84db552f7e41976b9418e57056d9948781c2c92
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1848111Reviewed-by: default avatarElla Ge <eirage@chromium.org>
Reviewed-by: default avatarNavid Zolghadr <nzolghadr@chromium.org>
Commit-Queue: Ella Ge <eirage@chromium.org>
Cr-Commit-Position: refs/heads/master@{#707964}
parent 7ea9ca55
...@@ -35,6 +35,7 @@ bool EmptyPredictor::GeneratePrediction(base::TimeTicks predict_time, ...@@ -35,6 +35,7 @@ bool EmptyPredictor::GeneratePrediction(base::TimeTicks predict_time,
return false; return false;
result->pos = last_input_.value().pos; result->pos = last_input_.value().pos;
result->time_stamp = last_input_.value().time_stamp;
return true; return true;
} }
......
...@@ -31,26 +31,28 @@ void InputPredictorTest::ValidatePredictor( ...@@ -31,26 +31,28 @@ void InputPredictorTest::ValidatePredictor(
void InputPredictorTest::ValidatePredictor( void InputPredictorTest::ValidatePredictor(
const std::vector<double>& events_x, const std::vector<double>& events_x,
const std::vector<double>& events_y, const std::vector<double>& events_y,
const std::vector<double>& events_ts_ms, const std::vector<double>& events_time_ms,
const std::vector<double>& prediction_ts_ms, const std::vector<double>& prediction_time_ms,
const std::vector<double>& predicted_x, const std::vector<double>& predicted_x,
const std::vector<double>& predicted_y) { const std::vector<double>& predicted_y) {
predictor_->Reset(); predictor_->Reset();
std::vector<double> computed_x; std::vector<double> computed_x;
std::vector<double> computed_y; std::vector<double> computed_y;
size_t current_prediction_ts = 0; size_t current_prediction_index = 0;
for (size_t i = 0; i < events_ts_ms.size(); i++) { for (size_t i = 0; i < events_time_ms.size(); i++) {
InputPredictor::InputData data = {gfx::PointF(events_x[i], events_y[i]), InputPredictor::InputData data = {gfx::PointF(events_x[i], events_y[i]),
FromMilliseconds(events_ts_ms[i])}; FromMilliseconds(events_time_ms[i])};
predictor_->Update(data); predictor_->Update(data);
if (predictor_->HasPrediction()) { if (predictor_->HasPrediction()) {
InputPredictor::InputData result; InputPredictor::InputData result;
EXPECT_TRUE(predictor_->GeneratePrediction( EXPECT_TRUE(predictor_->GeneratePrediction(
FromMilliseconds(prediction_ts_ms[current_prediction_ts]), &result)); FromMilliseconds(prediction_time_ms[current_prediction_index]),
&result));
computed_x.push_back(result.pos.x()); computed_x.push_back(result.pos.x());
computed_y.push_back(result.pos.y()); computed_y.push_back(result.pos.y());
current_prediction_ts++; EXPECT_GT(result.time_stamp, base::TimeTicks());
current_prediction_index++;
} }
} }
......
...@@ -107,8 +107,8 @@ bool KalmanPredictor::GeneratePrediction(base::TimeTicks predict_time, ...@@ -107,8 +107,8 @@ bool KalmanPredictor::GeneratePrediction(base::TimeTicks predict_time,
ScaleVector2d(acceleration, kAccelerationInfluence * pred_dt * pred_dt); ScaleVector2d(acceleration, kAccelerationInfluence * pred_dt * pred_dt);
} }
result->pos.set_x(position.x()); result->pos.SetPoint(position.x(), position.y());
result->pos.set_y(position.y()); result->time_stamp = predict_time;
return true; return true;
} }
......
...@@ -91,6 +91,7 @@ bool LeastSquaresPredictor::GeneratePrediction(base::TimeTicks predict_time, ...@@ -91,6 +91,7 @@ bool LeastSquaresPredictor::GeneratePrediction(base::TimeTicks predict_time,
SolveLeastSquares(time_matrix, y_queue_, b2)) { SolveLeastSquares(time_matrix, y_queue_, b2)) {
gfx::Vector3dF prediction_time(1, pred_dt, pred_dt * pred_dt); gfx::Vector3dF prediction_time(1, pred_dt, pred_dt * pred_dt);
result->time_stamp = predict_time;
result->pos.set_x(gfx::DotProduct(prediction_time, b1)); result->pos.set_x(gfx::DotProduct(prediction_time, b1));
result->pos.set_y(gfx::DotProduct(prediction_time, b2)); result->pos.set_y(gfx::DotProduct(prediction_time, b2));
return true; return true;
......
...@@ -94,6 +94,7 @@ bool LinearPredictor::GeneratePrediction(base::TimeTicks predict_time, ...@@ -94,6 +94,7 @@ bool LinearPredictor::GeneratePrediction(base::TimeTicks predict_time,
// Add the acceleration term to the current result // Add the acceleration term to the current result
GeneratePredictionSecondOrder(pred_dt, result); GeneratePredictionSecondOrder(pred_dt, result);
result->time_stamp = predict_time;
return true; return true;
} }
...@@ -123,4 +124,4 @@ base::TimeDelta LinearPredictor::TimeInterval() const { ...@@ -123,4 +124,4 @@ base::TimeDelta LinearPredictor::TimeInterval() const {
return kTimeInterval; return kTimeInterval;
} }
} // namespace ui } // namespace ui
\ No newline at end of file
...@@ -85,6 +85,7 @@ bool LinearResampling::GeneratePrediction(base::TimeTicks frame_time, ...@@ -85,6 +85,7 @@ bool LinearResampling::GeneratePrediction(base::TimeTicks frame_time,
std::min(sample_time, events_queue_[0].time_stamp + max_prediction); std::min(sample_time, events_queue_[0].time_stamp + max_prediction);
result->pos = lerp(events_queue_[0], events_queue_[1], sample_time); result->pos = lerp(events_queue_[0], events_queue_[1], sample_time);
result->time_stamp = sample_time;
return true; return true;
} }
......
...@@ -147,14 +147,13 @@ void ScrollPredictor::ResampleEvent(base::TimeTicks frame_time, ...@@ -147,14 +147,13 @@ void ScrollPredictor::ResampleEvent(base::TimeTicks frame_time,
// maximum available for the current predictor // maximum available for the current predictor
prediction_delta = std::min(prediction_delta, predictor_->MaxResampleTime()); prediction_delta = std::min(prediction_delta, predictor_->MaxResampleTime());
// Compute the prediction timestamp
base::TimeTicks prediction_time = base::TimeTicks prediction_time =
gesture_event->TimeStamp() + prediction_delta; gesture_event->TimeStamp() + prediction_delta;
if (predictor_->HasPrediction() && if (predictor_->HasPrediction() &&
predictor_->GeneratePrediction(prediction_time, &result)) { predictor_->GeneratePrediction(prediction_time, &result)) {
predicted_accumulated_delta = result.pos; predicted_accumulated_delta = result.pos;
gesture_event->SetTimeStamp(prediction_time); gesture_event->SetTimeStamp(result.time_stamp);
predicted = true; predicted = true;
} }
...@@ -194,7 +193,7 @@ void ScrollPredictor::ResampleEvent(base::TimeTicks frame_time, ...@@ -194,7 +193,7 @@ void ScrollPredictor::ResampleEvent(base::TimeTicks frame_time,
if (predicted) { if (predicted) {
metrics_handler_.AddPredictedEvent(predicted_accumulated_delta, metrics_handler_.AddPredictedEvent(predicted_accumulated_delta,
prediction_time, frame_time, result.time_stamp, frame_time,
true /* Scrolling */); true /* Scrolling */);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment