Commit f7afddcd authored by Ella Ge's avatar Ella Ge Committed by Commit Bot

Input Predictors returns pointer of InputData

Input predictor's GeneratePrediction used to return a boolean for
whether the prediction exist and also a InputData class contains the
prediction results. This is unnecessary.
This CL makes:
1. GeneratePrediction returns a unique_ptr of InputData class. If
prediction exist, it's the predict result; otherwise, it's nullptr.
2. No need to check HasPrediction before GeneratePrediction.
It should be decided by predictor itself and returns result or nullptr
accordingly.

Change-Id: Id5e092dc98f4c0fa4e66ac709e05fbf7cae8c734
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1849173
Commit-Queue: Ella Ge <eirage@chromium.org>
Reviewed-by: default avatarNavid Zolghadr <nzolghadr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#708030}
parent d9776b2d
...@@ -243,11 +243,9 @@ bool InputEventPrediction::GetPointerPrediction(base::TimeTicks predict_time, ...@@ -243,11 +243,9 @@ bool InputEventPrediction::GetPointerPrediction(base::TimeTicks predict_time,
if (event->pointer_type != WebPointerProperties::PointerType::kMouse) if (event->pointer_type != WebPointerProperties::PointerType::kMouse)
mouse_predictor_->Reset(); mouse_predictor_->Reset();
ui::InputPredictor::InputData predict_result;
if (auto* predictor = GetPredictor(*event)) { if (auto* predictor = GetPredictor(*event)) {
if (predictor->HasPrediction() && if (auto predict_result = predictor->GeneratePrediction(predict_time)) {
predictor->GeneratePrediction(predict_time, &predict_result)) { event->SetPositionInWidget(predict_result->pos);
event->SetPositionInWidget(predict_result.pos);
return true; return true;
} }
} }
......
...@@ -37,24 +37,18 @@ class InputEventPredictionTest : public testing::Test { ...@@ -37,24 +37,18 @@ class InputEventPredictionTest : public testing::Test {
return event_predictor_->pointer_id_predictor_map_.size(); return event_predictor_->pointer_id_predictor_map_.size();
} }
bool GetPrediction(const WebPointerProperties& event, std::unique_ptr<ui::InputPredictor::InputData> GetPrediction(
ui::InputPredictor::InputData* result) const { const WebPointerProperties& event) const {
if (!event_predictor_)
return false;
if (event.pointer_type == WebPointerProperties::PointerType::kMouse) { if (event.pointer_type == WebPointerProperties::PointerType::kMouse) {
return event_predictor_->mouse_predictor_->GeneratePrediction( return event_predictor_->mouse_predictor_->GeneratePrediction(
ui::EventTimeForNow(), result); ui::EventTimeForNow());
} else { } else {
auto predictor = auto predictor =
event_predictor_->pointer_id_predictor_map_.find(event.id); event_predictor_->pointer_id_predictor_map_.find(event.id);
if (predictor != event_predictor_->pointer_id_predictor_map_.end()) if (predictor != event_predictor_->pointer_id_predictor_map_.end())
return predictor->second->GeneratePrediction(ui::EventTimeForNow(), return predictor->second->GeneratePrediction(ui::EventTimeForNow());
result);
else
return false;
} }
return nullptr;
} }
void HandleEvents(const WebInputEvent& event) { void HandleEvents(const WebInputEvent& event) {
...@@ -138,44 +132,43 @@ TEST_F(InputEventPredictionTest, MouseEvent) { ...@@ -138,44 +132,43 @@ TEST_F(InputEventPredictionTest, MouseEvent) {
WebMouseEvent mouse_move = SyntheticWebMouseEventBuilder::Build( WebMouseEvent mouse_move = SyntheticWebMouseEventBuilder::Build(
WebInputEvent::kMouseMove, 10, 10, 0); WebInputEvent::kMouseMove, 10, 10, 0);
ui::InputPredictor::InputData last_point; EXPECT_FALSE(GetPrediction(mouse_move));
EXPECT_FALSE(GetPrediction(mouse_move, &last_point));
HandleEvents(mouse_move); HandleEvents(mouse_move);
EXPECT_EQ(GetPredictorMapSize(), 0); EXPECT_EQ(GetPredictorMapSize(), 0);
EXPECT_TRUE(GetPrediction(mouse_move, &last_point)); auto predicted_point = GetPrediction(mouse_move);
EXPECT_EQ(last_point.pos.x(), 10); EXPECT_TRUE(predicted_point);
EXPECT_EQ(last_point.pos.y(), 10); EXPECT_EQ(predicted_point->pos.x(), 10);
EXPECT_EQ(predicted_point->pos.y(), 10);
WebMouseEvent mouse_down = SyntheticWebMouseEventBuilder::Build( WebMouseEvent mouse_down = SyntheticWebMouseEventBuilder::Build(
WebInputEvent::kMouseDown, 10, 10, 0); WebInputEvent::kMouseDown, 10, 10, 0);
HandleEvents(mouse_down); HandleEvents(mouse_down);
EXPECT_FALSE(GetPrediction(mouse_down, &last_point)); EXPECT_FALSE(GetPrediction(mouse_down));
} }
TEST_F(InputEventPredictionTest, SingleTouchPoint) { TEST_F(InputEventPredictionTest, SingleTouchPoint) {
SyntheticWebTouchEvent touch_event; SyntheticWebTouchEvent touch_event;
ui::InputPredictor::InputData last_point;
touch_event.PressPoint(10, 10); touch_event.PressPoint(10, 10);
touch_event.touches[0].pointer_type = touch_event.touches[0].pointer_type =
WebPointerProperties::PointerType::kTouch; WebPointerProperties::PointerType::kTouch;
HandleEvents(touch_event); HandleEvents(touch_event);
EXPECT_FALSE(GetPrediction(touch_event.touches[0], &last_point)); EXPECT_FALSE(GetPrediction(touch_event.touches[0]));
touch_event.MovePoint(0, 11, 12); touch_event.MovePoint(0, 11, 12);
HandleEvents(touch_event); HandleEvents(touch_event);
EXPECT_EQ(GetPredictorMapSize(), 1); EXPECT_EQ(GetPredictorMapSize(), 1);
EXPECT_TRUE(GetPrediction(touch_event.touches[0], &last_point)); auto predicted_point = GetPrediction(touch_event.touches[0]);
EXPECT_EQ(last_point.pos.x(), 11); EXPECT_TRUE(predicted_point);
EXPECT_EQ(last_point.pos.y(), 12); EXPECT_EQ(predicted_point->pos.x(), 11);
EXPECT_EQ(predicted_point->pos.y(), 12);
touch_event.ReleasePoint(0); touch_event.ReleasePoint(0);
HandleEvents(touch_event); HandleEvents(touch_event);
EXPECT_FALSE(GetPrediction(touch_event.touches[0], &last_point)); EXPECT_FALSE(GetPrediction(touch_event.touches[0]));
} }
TEST_F(InputEventPredictionTest, MouseEventTypePen) { TEST_F(InputEventPredictionTest, MouseEventTypePen) {
...@@ -183,13 +176,13 @@ TEST_F(InputEventPredictionTest, MouseEventTypePen) { ...@@ -183,13 +176,13 @@ TEST_F(InputEventPredictionTest, MouseEventTypePen) {
WebInputEvent::kMouseMove, 10, 10, 0, WebInputEvent::kMouseMove, 10, 10, 0,
WebPointerProperties::PointerType::kPen); WebPointerProperties::PointerType::kPen);
ui::InputPredictor::InputData last_point; EXPECT_FALSE(GetPrediction(pen_move));
EXPECT_FALSE(GetPrediction(pen_move, &last_point));
HandleEvents(pen_move); HandleEvents(pen_move);
EXPECT_EQ(GetPredictorMapSize(), 1); EXPECT_EQ(GetPredictorMapSize(), 1);
EXPECT_TRUE(GetPrediction(pen_move, &last_point)); auto predicted_point = GetPrediction(pen_move);
EXPECT_EQ(last_point.pos.x(), 10); EXPECT_TRUE(predicted_point);
EXPECT_EQ(last_point.pos.y(), 10); EXPECT_EQ(predicted_point->pos.x(), 10);
EXPECT_EQ(predicted_point->pos.y(), 10);
WebMouseEvent pen_leave = SyntheticWebMouseEventBuilder::Build( WebMouseEvent pen_leave = SyntheticWebMouseEventBuilder::Build(
WebInputEvent::kMouseLeave, 10, 10, 0, WebInputEvent::kMouseLeave, 10, 10, 0,
...@@ -197,7 +190,7 @@ TEST_F(InputEventPredictionTest, MouseEventTypePen) { ...@@ -197,7 +190,7 @@ TEST_F(InputEventPredictionTest, MouseEventTypePen) {
HandleEvents(pen_leave); HandleEvents(pen_leave);
EXPECT_EQ(GetPredictorMapSize(), 0); EXPECT_EQ(GetPredictorMapSize(), 0);
EXPECT_FALSE(GetPrediction(pen_leave, &last_point)); EXPECT_FALSE(GetPrediction(pen_leave));
} }
TEST_F(InputEventPredictionTest, MultipleTouchPoint) { TEST_F(InputEventPredictionTest, MultipleTouchPoint) {
...@@ -222,14 +215,15 @@ TEST_F(InputEventPredictionTest, MultipleTouchPoint) { ...@@ -222,14 +215,15 @@ TEST_F(InputEventPredictionTest, MultipleTouchPoint) {
HandleEvents(touch_event); HandleEvents(touch_event);
EXPECT_EQ(GetPredictorMapSize(), 2); EXPECT_EQ(GetPredictorMapSize(), 2);
ui::InputPredictor::InputData last_point; auto predicted_point = GetPrediction(touch_event.touches[0]);
EXPECT_TRUE(GetPrediction(touch_event.touches[0], &last_point)); EXPECT_TRUE(predicted_point);
EXPECT_EQ(last_point.pos.x(), 11); EXPECT_EQ(predicted_point->pos.x(), 11);
EXPECT_EQ(last_point.pos.y(), 12); EXPECT_EQ(predicted_point->pos.y(), 12);
EXPECT_TRUE(GetPrediction(touch_event.touches[1], &last_point)); predicted_point = GetPrediction(touch_event.touches[1]);
EXPECT_EQ(last_point.pos.x(), 25); EXPECT_TRUE(predicted_point);
EXPECT_EQ(last_point.pos.y(), 25); EXPECT_EQ(predicted_point->pos.x(), 25);
EXPECT_EQ(predicted_point->pos.y(), 25);
touch_event.ReleasePoint(0); touch_event.ReleasePoint(0);
HandleEvents(touch_event); HandleEvents(touch_event);
...@@ -241,8 +235,8 @@ TEST_F(InputEventPredictionTest, TouchAndStylusResetMousePredictor) { ...@@ -241,8 +235,8 @@ TEST_F(InputEventPredictionTest, TouchAndStylusResetMousePredictor) {
WebInputEvent::kMouseMove, 10, 10, 0); WebInputEvent::kMouseMove, 10, 10, 0);
HandleEvents(mouse_move); HandleEvents(mouse_move);
ui::InputPredictor::InputData last_point; auto predicted_point = GetPrediction(mouse_move);
EXPECT_TRUE(GetPrediction(mouse_move, &last_point)); EXPECT_TRUE(predicted_point);
WebMouseEvent pen_move = SyntheticWebMouseEventBuilder::Build( WebMouseEvent pen_move = SyntheticWebMouseEventBuilder::Build(
WebInputEvent::kMouseMove, 20, 20, 0, WebInputEvent::kMouseMove, 20, 20, 0,
...@@ -250,11 +244,13 @@ TEST_F(InputEventPredictionTest, TouchAndStylusResetMousePredictor) { ...@@ -250,11 +244,13 @@ TEST_F(InputEventPredictionTest, TouchAndStylusResetMousePredictor) {
pen_move.id = 1; pen_move.id = 1;
HandleEvents(pen_move); HandleEvents(pen_move);
EXPECT_TRUE(GetPrediction(pen_move, &last_point)); predicted_point = GetPrediction(pen_move);
EXPECT_FALSE(GetPrediction(mouse_move, &last_point)); EXPECT_TRUE(predicted_point);
EXPECT_FALSE(GetPrediction(mouse_move));
HandleEvents(mouse_move); HandleEvents(mouse_move);
EXPECT_TRUE(GetPrediction(mouse_move, &last_point)); predicted_point = GetPrediction(mouse_move);
EXPECT_TRUE(predicted_point);
SyntheticWebTouchEvent touch_event; SyntheticWebTouchEvent touch_event;
touch_event.PressPoint(10, 10); touch_event.PressPoint(10, 10);
...@@ -264,8 +260,9 @@ TEST_F(InputEventPredictionTest, TouchAndStylusResetMousePredictor) { ...@@ -264,8 +260,9 @@ TEST_F(InputEventPredictionTest, TouchAndStylusResetMousePredictor) {
HandleEvents(touch_event); HandleEvents(touch_event);
touch_event.MovePoint(0, 10, 10); touch_event.MovePoint(0, 10, 10);
HandleEvents(touch_event); HandleEvents(touch_event);
EXPECT_TRUE(GetPrediction(touch_event.touches[0], &last_point)); predicted_point = GetPrediction(touch_event.touches[0]);
EXPECT_FALSE(GetPrediction(mouse_move, &last_point)); EXPECT_TRUE(predicted_point);
EXPECT_FALSE(GetPrediction(mouse_move));
} }
// TouchScrollStarted event removes all touch points. // TouchScrollStarted event removes all touch points.
......
...@@ -504,11 +504,10 @@ class InputHandlerProxyEventQueueTest : public testing::Test { ...@@ -504,11 +504,10 @@ class InputHandlerProxyEventQueueTest : public testing::Test {
enabled ? std::make_unique<ScrollPredictor>() : nullptr; enabled ? std::make_unique<ScrollPredictor>() : nullptr;
} }
bool GestureScrollEventPredictionAvailable( std::unique_ptr<ui::InputPredictor::InputData>
ui::InputPredictor::InputData* result) { GestureScrollEventPredictionAvailable() {
return input_handler_proxy_.scroll_predictor_->predictor_ return input_handler_proxy_.scroll_predictor_->predictor_
->GeneratePrediction(WebInputEvent::GetStaticTimeStampForTests(), ->GeneratePrediction(WebInputEvent::GetStaticTimeStampForTests());
result);
} }
protected: protected:
...@@ -2001,11 +2000,10 @@ TEST_F(InputHandlerProxyEventQueueTest, ScrollPredictorTest) { ...@@ -2001,11 +2000,10 @@ TEST_F(InputHandlerProxyEventQueueTest, ScrollPredictorTest) {
.WillOnce(testing::Return(scroll_result_did_scroll_)); .WillOnce(testing::Return(scroll_result_did_scroll_));
// No prediction when start with a GSB // No prediction when start with a GSB
ui::InputPredictor::InputData result;
tick_clock.Advance(base::TimeDelta::FromMilliseconds(8)); tick_clock.Advance(base::TimeDelta::FromMilliseconds(8));
HandleGestureEvent(WebInputEvent::kGestureScrollBegin); HandleGestureEvent(WebInputEvent::kGestureScrollBegin);
DeliverInputForBeginFrame(); DeliverInputForBeginFrame();
EXPECT_FALSE(GestureScrollEventPredictionAvailable(&result)); EXPECT_FALSE(GestureScrollEventPredictionAvailable());
// Test predictor returns last GSU delta. // Test predictor returns last GSU delta.
tick_clock.Advance(base::TimeDelta::FromMilliseconds(8)); tick_clock.Advance(base::TimeDelta::FromMilliseconds(8));
...@@ -2013,8 +2011,9 @@ TEST_F(InputHandlerProxyEventQueueTest, ScrollPredictorTest) { ...@@ -2013,8 +2011,9 @@ TEST_F(InputHandlerProxyEventQueueTest, ScrollPredictorTest) {
tick_clock.Advance(base::TimeDelta::FromMilliseconds(8)); tick_clock.Advance(base::TimeDelta::FromMilliseconds(8));
HandleGestureEvent(WebInputEvent::kGestureScrollUpdate, -15); HandleGestureEvent(WebInputEvent::kGestureScrollUpdate, -15);
DeliverInputForBeginFrame(); DeliverInputForBeginFrame();
EXPECT_TRUE(GestureScrollEventPredictionAvailable(&result)); auto result = GestureScrollEventPredictionAvailable();
EXPECT_NE(0, result.pos.y()); EXPECT_TRUE(result);
EXPECT_NE(0, result->pos.y());
testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
...@@ -2025,7 +2024,7 @@ TEST_F(InputHandlerProxyEventQueueTest, ScrollPredictorTest) { ...@@ -2025,7 +2024,7 @@ TEST_F(InputHandlerProxyEventQueueTest, ScrollPredictorTest) {
tick_clock.Advance(base::TimeDelta::FromMilliseconds(8)); tick_clock.Advance(base::TimeDelta::FromMilliseconds(8));
HandleGestureEvent(WebInputEvent::kGestureScrollBegin); HandleGestureEvent(WebInputEvent::kGestureScrollBegin);
DeliverInputForBeginFrame(); DeliverInputForBeginFrame();
EXPECT_FALSE(GestureScrollEventPredictionAvailable(&result)); EXPECT_FALSE(GestureScrollEventPredictionAvailable());
testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
} }
......
...@@ -26,17 +26,14 @@ void EmptyPredictor::Update(const InputData& cur_input) { ...@@ -26,17 +26,14 @@ void EmptyPredictor::Update(const InputData& cur_input) {
} }
bool EmptyPredictor::HasPrediction() const { bool EmptyPredictor::HasPrediction() const {
return last_input_ != base::nullopt; return last_input_.has_value();
} }
bool EmptyPredictor::GeneratePrediction(base::TimeTicks predict_time, std::unique_ptr<InputPredictor::InputData> EmptyPredictor::GeneratePrediction(
InputData* result) const { base::TimeTicks predict_time) const {
if (!HasPrediction()) if (!HasPrediction())
return false; return nullptr;
return std::make_unique<InputData>(last_input_.value());
result->pos = last_input_.value().pos;
result->time_stamp = last_input_.value().time_stamp;
return true;
} }
base::TimeDelta EmptyPredictor::TimeInterval() const { base::TimeDelta EmptyPredictor::TimeInterval() const {
......
...@@ -27,8 +27,8 @@ class EmptyPredictor : public InputPredictor { ...@@ -27,8 +27,8 @@ class EmptyPredictor : public InputPredictor {
bool HasPrediction() const override; bool HasPrediction() const override;
// Returns the last_input_ for testing. // Returns the last_input_ for testing.
bool GeneratePrediction(base::TimeTicks predict_time, std::unique_ptr<InputData> GeneratePrediction(
InputData* result) const override; base::TimeTicks predict_time) const override;
// Returns kTimeInterval for testing. // Returns kTimeInterval for testing.
base::TimeDelta TimeInterval() const override; base::TimeDelta TimeInterval() const override;
......
...@@ -23,6 +23,14 @@ class InputPredictor { ...@@ -23,6 +23,14 @@ class InputPredictor {
struct InputData { struct InputData {
gfx::PointF pos; gfx::PointF pos;
base::TimeTicks time_stamp; base::TimeTicks time_stamp;
InputData() {
pos = gfx::PointF();
time_stamp = base::TimeTicks();
}
InputData(const gfx::PointF& event_pos, const base::TimeTicks& event_time) {
pos = event_pos;
time_stamp = event_time;
}
}; };
// Returns the name of the predictor. // Returns the name of the predictor.
...@@ -38,8 +46,8 @@ class InputPredictor { ...@@ -38,8 +46,8 @@ class InputPredictor {
virtual bool HasPrediction() const = 0; virtual bool HasPrediction() const = 0;
// Generate the prediction based on current points. // Generate the prediction based on current points.
virtual bool GeneratePrediction(base::TimeTicks predict_time, virtual std::unique_ptr<InputData> GeneratePrediction(
InputData* result) const = 0; base::TimeTicks predict_time) const = 0;
// Returns the maximum of prediction available for resampling // Returns the maximum of prediction available for resampling
// before having side effects (jitter, wrong orientation, etc..) // before having side effects (jitter, wrong orientation, etc..)
......
...@@ -16,11 +16,11 @@ void InputPredictorTest::ValidatePredictor( ...@@ -16,11 +16,11 @@ void InputPredictorTest::ValidatePredictor(
predictor_->Reset(); predictor_->Reset();
for (size_t i = 0; i < timestamp_ms.size(); i++) { for (size_t i = 0; i < timestamp_ms.size(); i++) {
if (predictor_->HasPrediction()) { if (predictor_->HasPrediction()) {
ui::InputPredictor::InputData result; auto result =
EXPECT_TRUE(predictor_->GeneratePrediction( predictor_->GeneratePrediction(FromMilliseconds(timestamp_ms[i]));
FromMilliseconds(timestamp_ms[i]), &result)); EXPECT_TRUE(result);
EXPECT_NEAR(result.pos.x(), x[i], kEpsilon); EXPECT_NEAR(result->pos.x(), x[i], kEpsilon);
EXPECT_NEAR(result.pos.y(), y[i], kEpsilon); EXPECT_NEAR(result->pos.y(), y[i], kEpsilon);
} }
InputPredictor::InputData data = {gfx::PointF(x[i], y[i]), InputPredictor::InputData data = {gfx::PointF(x[i], y[i]),
FromMilliseconds(timestamp_ms[i])}; FromMilliseconds(timestamp_ms[i])};
...@@ -45,13 +45,12 @@ void InputPredictorTest::ValidatePredictor( ...@@ -45,13 +45,12 @@ void InputPredictorTest::ValidatePredictor(
predictor_->Update(data); predictor_->Update(data);
if (predictor_->HasPrediction()) { if (predictor_->HasPrediction()) {
InputPredictor::InputData result; auto result = predictor_->GeneratePrediction(
EXPECT_TRUE(predictor_->GeneratePrediction( FromMilliseconds(prediction_time_ms[current_prediction_index]));
FromMilliseconds(prediction_time_ms[current_prediction_index]), EXPECT_TRUE(result);
&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()); EXPECT_GT(result->time_stamp, base::TimeTicks());
EXPECT_GT(result.time_stamp, base::TimeTicks());
current_prediction_index++; current_prediction_index++;
} }
} }
......
...@@ -70,18 +70,17 @@ bool KalmanPredictor::HasPrediction() const { ...@@ -70,18 +70,17 @@ bool KalmanPredictor::HasPrediction() const {
return x_predictor_.Stable() && y_predictor_.Stable(); return x_predictor_.Stable() && y_predictor_.Stable();
} }
bool KalmanPredictor::GeneratePrediction(base::TimeTicks predict_time, std::unique_ptr<InputPredictor::InputData> KalmanPredictor::GeneratePrediction(
InputData* result) const { base::TimeTicks predict_time) const {
if (!HasPrediction()) if (!HasPrediction())
return false; return nullptr;
DCHECK(last_points_.size()); DCHECK(last_points_.size());
float pred_dt = float pred_dt =
(predict_time - last_points_.back().time_stamp).InMillisecondsF(); (predict_time - last_points_.back().time_stamp).InMillisecondsF();
std::vector<InputData> pred_points; gfx::PointF position(last_points_.back().pos.x(),
gfx::Vector2dF position(last_points_.back().pos.x(), last_points_.back().pos.y());
last_points_.back().pos.y());
gfx::Vector2dF velocity = PredictVelocity(); gfx::Vector2dF velocity = PredictVelocity();
gfx::Vector2dF acceleration = PredictAcceleration(); gfx::Vector2dF acceleration = PredictAcceleration();
...@@ -107,9 +106,7 @@ bool KalmanPredictor::GeneratePrediction(base::TimeTicks predict_time, ...@@ -107,9 +106,7 @@ bool KalmanPredictor::GeneratePrediction(base::TimeTicks predict_time,
ScaleVector2d(acceleration, kAccelerationInfluence * pred_dt * pred_dt); ScaleVector2d(acceleration, kAccelerationInfluence * pred_dt * pred_dt);
} }
result->pos.SetPoint(position.x(), position.y()); return std::make_unique<InputData>(position, predict_time);
result->time_stamp = predict_time;
return true;
} }
base::TimeDelta KalmanPredictor::TimeInterval() const { base::TimeDelta KalmanPredictor::TimeInterval() const {
......
...@@ -38,8 +38,8 @@ class KalmanPredictor : public InputPredictor { ...@@ -38,8 +38,8 @@ class KalmanPredictor : public InputPredictor {
// Generate the prediction based on stored points and given time_stamp. // Generate the prediction based on stored points and given time_stamp.
// Return false if no prediction available. // Return false if no prediction available.
bool GeneratePrediction(base::TimeTicks predict_time, std::unique_ptr<InputData> GeneratePrediction(
InputData* result) const override; base::TimeTicks predict_time) const override;
// Return the filtered value of time intervals. // Return the filtered value of time intervals.
base::TimeDelta TimeInterval() const override; base::TimeDelta TimeInterval() const override;
......
...@@ -111,11 +111,10 @@ TEST_F(KalmanPredictorTest, PredictLinearValue) { ...@@ -111,11 +111,10 @@ TEST_F(KalmanPredictorTest, PredictLinearValue) {
std::vector<double> t = {0, 8, 16, 24, 32, 40, 48, 60}; std::vector<double> t = {0, 8, 16, 24, 32, 40, 48, 60};
for (size_t i = 0; i < t.size(); i++) { for (size_t i = 0; i < t.size(); i++) {
if (predictor_->HasPrediction()) { if (predictor_->HasPrediction()) {
ui::InputPredictor::InputData result; auto result = predictor_->GeneratePrediction(FromMilliseconds(t[i]));
EXPECT_TRUE( EXPECT_TRUE(result);
predictor_->GeneratePrediction(FromMilliseconds(t[i]), &result)); EXPECT_NEAR(result->pos.x(), x[i], kEpsilon);
EXPECT_NEAR(result.pos.x(), x[i], kEpsilon); EXPECT_NEAR(result->pos.y(), y[i], kEpsilon);
EXPECT_NEAR(result.pos.y(), y[i], kEpsilon);
} }
InputPredictor::InputData data = {gfx::PointF(x[i], y[i]), InputPredictor::InputData data = {gfx::PointF(x[i], y[i]),
FromMilliseconds(t[i])}; FromMilliseconds(t[i])};
...@@ -168,13 +167,13 @@ TEST_F(KalmanPredictorTest, HeuristicApproach) { ...@@ -168,13 +167,13 @@ TEST_F(KalmanPredictorTest, HeuristicApproach) {
for (size_t i = 0; i < t.size(); i++) { for (size_t i = 0; i < t.size(); i++) {
gfx::PointF point(x[i], y[i]); gfx::PointF point(x[i], y[i]);
if (heuristic_predictor->HasPrediction() && predictor_->HasPrediction()) { if (heuristic_predictor->HasPrediction() && predictor_->HasPrediction()) {
ui::InputPredictor::InputData result, heuristic_result; auto heuristic_result =
EXPECT_TRUE(heuristic_predictor->GeneratePrediction( heuristic_predictor->GeneratePrediction(FromMilliseconds(t[i]));
FromMilliseconds(t[i]), &heuristic_result)); auto result = predictor_->GeneratePrediction(FromMilliseconds(t[i]));
EXPECT_TRUE( EXPECT_TRUE(heuristic_result);
predictor_->GeneratePrediction(FromMilliseconds(t[i]), &result)); EXPECT_TRUE(result);
EXPECT_LE((heuristic_result.pos - point).Length(), EXPECT_LE((heuristic_result->pos - point).Length(),
(result.pos - point).Length()); (result->pos - point).Length());
} }
InputPredictor::InputData data = {point, FromMilliseconds(t[i])}; InputPredictor::InputData data = {point, FromMilliseconds(t[i])};
heuristic_predictor->Update(data); heuristic_predictor->Update(data);
......
...@@ -78,10 +78,10 @@ gfx::Matrix3F LeastSquaresPredictor::GetXMatrix() const { ...@@ -78,10 +78,10 @@ gfx::Matrix3F LeastSquaresPredictor::GetXMatrix() const {
return x; return x;
} }
bool LeastSquaresPredictor::GeneratePrediction(base::TimeTicks predict_time, std::unique_ptr<InputPredictor::InputData>
InputData* result) const { LeastSquaresPredictor::GeneratePrediction(base::TimeTicks predict_time) const {
if (!HasPrediction()) if (!HasPrediction())
return false; return nullptr;
float pred_dt = (predict_time - time_[0]).InMillisecondsF(); float pred_dt = (predict_time - time_[0]).InMillisecondsF();
...@@ -91,12 +91,12 @@ bool LeastSquaresPredictor::GeneratePrediction(base::TimeTicks predict_time, ...@@ -91,12 +91,12 @@ 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; return std::make_unique<InputData>(
result->pos.set_x(gfx::DotProduct(prediction_time, b1)); gfx::PointF(gfx::DotProduct(prediction_time, b1),
result->pos.set_y(gfx::DotProduct(prediction_time, b2)); gfx::DotProduct(prediction_time, b2)),
return true; predict_time);
} }
return false; return nullptr;
} }
base::TimeDelta LeastSquaresPredictor::TimeInterval() const { base::TimeDelta LeastSquaresPredictor::TimeInterval() const {
......
...@@ -35,8 +35,8 @@ class LeastSquaresPredictor : public InputPredictor { ...@@ -35,8 +35,8 @@ class LeastSquaresPredictor : public InputPredictor {
// Generate the prediction based on stored points and given time_stamp. // Generate the prediction based on stored points and given time_stamp.
// Return false if no prediction available. // Return false if no prediction available.
bool GeneratePrediction(base::TimeTicks predict_time, std::unique_ptr<InputData> GeneratePrediction(
InputData* result) const override; base::TimeTicks predict_time) const override;
// Return the averaged value of time intervals. // Return the averaged value of time intervals.
base::TimeDelta TimeInterval() const override; base::TimeDelta TimeInterval() const override;
......
...@@ -74,8 +74,7 @@ TEST_F(LSQPredictorTest, ConstantTimeStampNotCrash) { ...@@ -74,8 +74,7 @@ TEST_F(LSQPredictorTest, ConstantTimeStampNotCrash) {
} }
// Expect false because the matrix is singular // Expect false because the matrix is singular
// and the predictor cannot compute a prediction // and the predictor cannot compute a prediction
ui::InputPredictor::InputData result; EXPECT_FALSE(predictor_->GeneratePrediction(FromMilliseconds(42)));
EXPECT_FALSE(predictor_->GeneratePrediction(FromMilliseconds(42), &result));
x = {100, 100, 100}; x = {100, 100, 100};
y = {100, 100, 100}; y = {100, 100, 100};
...@@ -85,7 +84,7 @@ TEST_F(LSQPredictorTest, ConstantTimeStampNotCrash) { ...@@ -85,7 +84,7 @@ TEST_F(LSQPredictorTest, ConstantTimeStampNotCrash) {
FromMilliseconds(t[i])}; FromMilliseconds(t[i])};
predictor_->Update(data); predictor_->Update(data);
} }
EXPECT_TRUE(predictor_->GeneratePrediction(FromMilliseconds(142), &result)); EXPECT_TRUE(predictor_->GeneratePrediction(FromMilliseconds(142)));
} }
// Tests the LSQ predictor produce the time interval correctly. // Tests the LSQ predictor produce the time interval correctly.
......
...@@ -77,10 +77,10 @@ bool LinearPredictor::HasPrediction() const { ...@@ -77,10 +77,10 @@ bool LinearPredictor::HasPrediction() const {
static_cast<size_t>(EquationOrder::kFirstOrder); static_cast<size_t>(EquationOrder::kFirstOrder);
} }
bool LinearPredictor::GeneratePrediction(base::TimeTicks predict_time, std::unique_ptr<InputPredictor::InputData> LinearPredictor::GeneratePrediction(
InputData* result) const { base::TimeTicks predict_time) const {
if (!HasPrediction()) if (!HasPrediction())
return false; return nullptr;
float pred_dt = float pred_dt =
(predict_time - events_queue_.back().time_stamp).InMillisecondsF(); (predict_time - events_queue_.back().time_stamp).InMillisecondsF();
...@@ -88,31 +88,29 @@ bool LinearPredictor::GeneratePrediction(base::TimeTicks predict_time, ...@@ -88,31 +88,29 @@ bool LinearPredictor::GeneratePrediction(base::TimeTicks predict_time,
// Compute the prediction // Compute the prediction
// Note : a first order prediction is computed when only 2 events are // Note : a first order prediction is computed when only 2 events are
// available in the second order predictor // available in the second order predictor
GeneratePredictionFirstOrder(pred_dt, result);
if (equation_order_ == EquationOrder::kSecondOrder && events_dt_ > 0 && if (equation_order_ == EquationOrder::kSecondOrder && events_dt_ > 0 &&
events_queue_.size() == static_cast<size_t>(EquationOrder::kSecondOrder)) events_queue_.size() ==
static_cast<size_t>(EquationOrder::kSecondOrder)) {
// Add the acceleration term to the current result // Add the acceleration term to the current result
GeneratePredictionSecondOrder(pred_dt, result); return std::make_unique<InputData>(GeneratePredictionSecondOrder(pred_dt),
predict_time);
result->time_stamp = predict_time; }
return true; return std::make_unique<InputData>(GeneratePredictionFirstOrder(pred_dt),
predict_time);
} }
void LinearPredictor::GeneratePredictionFirstOrder(float pred_dt, gfx::PointF LinearPredictor::GeneratePredictionFirstOrder(float pred_dt) const {
InputData* result) const { return events_queue_.back().pos + ScaleVector2d(cur_velocity_, pred_dt);
result->pos =
events_queue_.back().pos + ScaleVector2d(cur_velocity_, pred_dt);
} }
void LinearPredictor::GeneratePredictionSecondOrder(float pred_dt, gfx::PointF LinearPredictor::GeneratePredictionSecondOrder(
InputData* result) const { float pred_dt) const {
DCHECK(equation_order_ == EquationOrder::kSecondOrder); DCHECK(equation_order_ == EquationOrder::kSecondOrder);
// Compute the acceleration between the last two velocities
gfx::Vector2dF acceleration = gfx::Vector2dF acceleration =
ScaleVector2d(cur_velocity_ - last_velocity_, 1.0 / events_dt_); ScaleVector2d(cur_velocity_ - last_velocity_, 1.0 / events_dt_);
// Update the prediction return events_queue_.back().pos + ScaleVector2d(cur_velocity_, pred_dt) +
result->pos += ScaleVector2d(acceleration, 0.5 * pred_dt * pred_dt); ScaleVector2d(acceleration, 0.5 * pred_dt * pred_dt);
} }
base::TimeDelta LinearPredictor::TimeInterval() const { base::TimeDelta LinearPredictor::TimeInterval() const {
......
...@@ -39,8 +39,8 @@ class LinearPredictor : public InputPredictor { ...@@ -39,8 +39,8 @@ class LinearPredictor : public InputPredictor {
// Generate the prediction based on stored points and given time_stamp. // Generate the prediction based on stored points and given time_stamp.
// Return false if no prediction available. // Return false if no prediction available.
bool GeneratePrediction(base::TimeTicks predict_time, std::unique_ptr<InputData> GeneratePrediction(
InputData* result) const override; base::TimeTicks predict_time) const override;
// Return the average time delta in the event queue. // Return the average time delta in the event queue.
base::TimeDelta TimeInterval() const override; base::TimeDelta TimeInterval() const override;
...@@ -49,11 +49,9 @@ class LinearPredictor : public InputPredictor { ...@@ -49,11 +49,9 @@ class LinearPredictor : public InputPredictor {
size_t NumberOfEventsNeeded(); size_t NumberOfEventsNeeded();
private: private:
// Add the velocity term to the current prediction gfx::PointF GeneratePredictionFirstOrder(float pred_dt) const;
void GeneratePredictionFirstOrder(float pred_dt, InputData* result) const;
// Add the acceleration term to the current prediction gfx::PointF GeneratePredictionSecondOrder(float pred_dt) const;
void GeneratePredictionSecondOrder(float pred_dt, InputData* result) const;
// Store the last events received // Store the last events received
std::deque<InputData> events_queue_; std::deque<InputData> events_queue_;
......
...@@ -71,10 +71,10 @@ bool LinearResampling::HasPrediction() const { ...@@ -71,10 +71,10 @@ bool LinearResampling::HasPrediction() const {
events_dt_ >= kResampleMinDelta; events_dt_ >= kResampleMinDelta;
} }
bool LinearResampling::GeneratePrediction(base::TimeTicks frame_time, std::unique_ptr<InputPredictor::InputData> LinearResampling::GeneratePrediction(
InputData* result) const { base::TimeTicks frame_time) const {
if (!HasPrediction()) if (!HasPrediction())
return false; return nullptr;
base::TimeTicks sample_time = frame_time - kResampleLatency; base::TimeTicks sample_time = frame_time - kResampleLatency;
...@@ -84,9 +84,8 @@ bool LinearResampling::GeneratePrediction(base::TimeTicks frame_time, ...@@ -84,9 +84,8 @@ bool LinearResampling::GeneratePrediction(base::TimeTicks frame_time,
sample_time = sample_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); return std::make_unique<InputData>(
result->time_stamp = sample_time; lerp(events_queue_[0], events_queue_[1], sample_time), sample_time);
return true;
} }
base::TimeDelta LinearResampling::TimeInterval() const { base::TimeDelta LinearResampling::TimeInterval() const {
......
...@@ -35,8 +35,8 @@ class LinearResampling : public InputPredictor { ...@@ -35,8 +35,8 @@ class LinearResampling : public InputPredictor {
// Generate the prediction based on stored points and given frame_time. // Generate the prediction based on stored points and given frame_time.
// Return false if no prediction available. // Return false if no prediction available.
bool GeneratePrediction(base::TimeTicks frame_time, std::unique_ptr<InputData> GeneratePrediction(
InputData* result) const override; base::TimeTicks frame_time) const override;
// Return the average time delta in the event queue. // Return the average time delta in the event queue.
base::TimeDelta TimeInterval() const override; base::TimeDelta TimeInterval() const override;
......
...@@ -137,7 +137,6 @@ void ScrollPredictor::ResampleEvent(base::TimeTicks frame_time, ...@@ -137,7 +137,6 @@ void ScrollPredictor::ResampleEvent(base::TimeTicks frame_time,
gesture_event->data.scroll_update.delta_y) gesture_event->data.scroll_update.delta_y)
.ToString()); .ToString());
gfx::PointF predicted_accumulated_delta = current_event_accumulated_delta_; gfx::PointF predicted_accumulated_delta = current_event_accumulated_delta_;
InputPredictor::InputData result;
base::TimeDelta prediction_delta = frame_time - gesture_event->TimeStamp(); base::TimeDelta prediction_delta = frame_time - gesture_event->TimeStamp();
bool predicted = false; bool predicted = false;
...@@ -150,10 +149,10 @@ void ScrollPredictor::ResampleEvent(base::TimeTicks frame_time, ...@@ -150,10 +149,10 @@ void ScrollPredictor::ResampleEvent(base::TimeTicks frame_time,
base::TimeTicks prediction_time = base::TimeTicks prediction_time =
gesture_event->TimeStamp() + prediction_delta; gesture_event->TimeStamp() + prediction_delta;
if (predictor_->HasPrediction() && auto result = predictor_->GeneratePrediction(prediction_time);
predictor_->GeneratePrediction(prediction_time, &result)) { if (result) {
predicted_accumulated_delta = result.pos; predicted_accumulated_delta = result->pos;
gesture_event->SetTimeStamp(result.time_stamp); gesture_event->SetTimeStamp(result->time_stamp);
predicted = true; predicted = true;
} }
...@@ -193,7 +192,7 @@ void ScrollPredictor::ResampleEvent(base::TimeTicks frame_time, ...@@ -193,7 +192,7 @@ void ScrollPredictor::ResampleEvent(base::TimeTicks frame_time,
if (predicted) { if (predicted) {
metrics_handler_.AddPredictedEvent(predicted_accumulated_delta, metrics_handler_.AddPredictedEvent(predicted_accumulated_delta,
result.time_stamp, frame_time, result->time_stamp, frame_time,
true /* Scrolling */); true /* Scrolling */);
} }
} }
......
...@@ -93,12 +93,11 @@ class ScrollPredictorTest : public testing::Test { ...@@ -93,12 +93,11 @@ class ScrollPredictorTest : public testing::Test {
event = WebInputEventTraits::Clone(event_with_callback->event()); event = WebInputEventTraits::Clone(event_with_callback->event());
} }
bool PredictionAvailable(ui::InputPredictor::InputData* result, std::unique_ptr<ui::InputPredictor::InputData> PredictionAvailable(
double time_delta_in_milliseconds = 0) { double time_delta_in_milliseconds = 0) {
return scroll_predictor_->predictor_->GeneratePrediction( return scroll_predictor_->predictor_->GeneratePrediction(
WebInputEvent::GetStaticTimeStampForTests() + WebInputEvent::GetStaticTimeStampForTests() +
base::TimeDelta::FromMillisecondsD(time_delta_in_milliseconds), base::TimeDelta::FromMillisecondsD(time_delta_in_milliseconds));
result);
} }
gfx::PointF GetLastAccumulatedDelta() { gfx::PointF GetLastAccumulatedDelta() {
...@@ -211,8 +210,7 @@ TEST_F(ScrollPredictorTest, ScrollResamplingStates) { ...@@ -211,8 +210,7 @@ TEST_F(ScrollPredictorTest, ScrollResamplingStates) {
TEST_F(ScrollPredictorTest, ResampleGestureScrollEvents) { TEST_F(ScrollPredictorTest, ResampleGestureScrollEvents) {
SendGestureScrollBegin(); SendGestureScrollBegin();
ui::InputPredictor::InputData result; EXPECT_FALSE(PredictionAvailable());
EXPECT_FALSE(PredictionAvailable(&result));
WebScopedInputEvent gesture_update = CreateGestureScrollUpdate(0, -20); WebScopedInputEvent gesture_update = CreateGestureScrollUpdate(0, -20);
HandleResampleScrollEvents(gesture_update); HandleResampleScrollEvents(gesture_update);
...@@ -232,12 +230,13 @@ TEST_F(ScrollPredictorTest, ResampleGestureScrollEvents) { ...@@ -232,12 +230,13 @@ TEST_F(ScrollPredictorTest, ResampleGestureScrollEvents) {
->data.scroll_update.delta_y); ->data.scroll_update.delta_y);
// Cumulative amount of scroll from the GSB is stored in the empty predictor. // Cumulative amount of scroll from the GSB is stored in the empty predictor.
EXPECT_TRUE(PredictionAvailable(&result)); auto result = PredictionAvailable();
EXPECT_EQ(-80, result.pos.y()); EXPECT_TRUE(result);
EXPECT_EQ(-80, result->pos.y());
// Send another GSB, Prediction will be reset. // Send another GSB, Prediction will be reset.
SendGestureScrollBegin(); SendGestureScrollBegin();
EXPECT_FALSE(PredictionAvailable(&result)); EXPECT_FALSE(PredictionAvailable());
// Sent another GSU. // Sent another GSU.
gesture_update = CreateGestureScrollUpdate(0, -35); gesture_update = CreateGestureScrollUpdate(0, -35);
...@@ -246,13 +245,13 @@ TEST_F(ScrollPredictorTest, ResampleGestureScrollEvents) { ...@@ -246,13 +245,13 @@ TEST_F(ScrollPredictorTest, ResampleGestureScrollEvents) {
static_cast<const blink::WebGestureEvent*>(gesture_update.get()) static_cast<const blink::WebGestureEvent*>(gesture_update.get())
->data.scroll_update.delta_y); ->data.scroll_update.delta_y);
// Total amount of scroll is track from the last GSB. // Total amount of scroll is track from the last GSB.
EXPECT_TRUE(PredictionAvailable(&result)); result = PredictionAvailable();
EXPECT_EQ(-35, result.pos.y()); EXPECT_TRUE(result);
EXPECT_EQ(-35, result->pos.y());
} }
TEST_F(ScrollPredictorTest, ScrollInDifferentDirection) { TEST_F(ScrollPredictorTest, ScrollInDifferentDirection) {
SendGestureScrollBegin(); SendGestureScrollBegin();
ui::InputPredictor::InputData result;
// Scroll down. // Scroll down.
WebScopedInputEvent gesture_update = CreateGestureScrollUpdate(0, -20); WebScopedInputEvent gesture_update = CreateGestureScrollUpdate(0, -20);
...@@ -260,8 +259,9 @@ TEST_F(ScrollPredictorTest, ScrollInDifferentDirection) { ...@@ -260,8 +259,9 @@ TEST_F(ScrollPredictorTest, ScrollInDifferentDirection) {
EXPECT_EQ(-20, EXPECT_EQ(-20,
static_cast<const blink::WebGestureEvent*>(gesture_update.get()) static_cast<const blink::WebGestureEvent*>(gesture_update.get())
->data.scroll_update.delta_y); ->data.scroll_update.delta_y);
EXPECT_TRUE(PredictionAvailable(&result)); auto result = PredictionAvailable();
EXPECT_EQ(-20, result.pos.y()); EXPECT_TRUE(result);
EXPECT_EQ(-20, result->pos.y());
// Scroll up. // Scroll up.
gesture_update = CreateGestureScrollUpdate(0, 25); gesture_update = CreateGestureScrollUpdate(0, 25);
...@@ -270,9 +270,10 @@ TEST_F(ScrollPredictorTest, ScrollInDifferentDirection) { ...@@ -270,9 +270,10 @@ TEST_F(ScrollPredictorTest, ScrollInDifferentDirection) {
->data.scroll_update.delta_x); ->data.scroll_update.delta_x);
EXPECT_EQ(25, static_cast<const blink::WebGestureEvent*>(gesture_update.get()) EXPECT_EQ(25, static_cast<const blink::WebGestureEvent*>(gesture_update.get())
->data.scroll_update.delta_y); ->data.scroll_update.delta_y);
EXPECT_TRUE(PredictionAvailable(&result)); result = PredictionAvailable();
EXPECT_EQ(0, result.pos.x()); EXPECT_TRUE(result);
EXPECT_EQ(5, result.pos.y()); EXPECT_EQ(0, result->pos.x());
EXPECT_EQ(5, result->pos.y());
// Scroll left + right. // Scroll left + right.
gesture_update = CreateGestureScrollUpdate(-35, 0); gesture_update = CreateGestureScrollUpdate(-35, 0);
...@@ -282,9 +283,10 @@ TEST_F(ScrollPredictorTest, ScrollInDifferentDirection) { ...@@ -282,9 +283,10 @@ TEST_F(ScrollPredictorTest, ScrollInDifferentDirection) {
->data.scroll_update.delta_x); ->data.scroll_update.delta_x);
EXPECT_EQ(0, static_cast<const blink::WebGestureEvent*>(gesture_update.get()) EXPECT_EQ(0, static_cast<const blink::WebGestureEvent*>(gesture_update.get())
->data.scroll_update.delta_y); ->data.scroll_update.delta_y);
EXPECT_TRUE(PredictionAvailable(&result)); result = PredictionAvailable();
EXPECT_EQ(25, result.pos.x()); EXPECT_TRUE(result);
EXPECT_EQ(5, result.pos.y()); EXPECT_EQ(25, result->pos.x());
EXPECT_EQ(5, result->pos.y());
} }
TEST_F(ScrollPredictorTest, ScrollUpdateWithEmptyOriginalEventList) { TEST_F(ScrollPredictorTest, ScrollUpdateWithEmptyOriginalEventList) {
...@@ -299,8 +301,7 @@ TEST_F(ScrollPredictorTest, ScrollUpdateWithEmptyOriginalEventList) { ...@@ -299,8 +301,7 @@ TEST_F(ScrollPredictorTest, ScrollUpdateWithEmptyOriginalEventList) {
->data.scroll_update.delta_y); ->data.scroll_update.delta_y);
// No prediction available because the event is skipped. // No prediction available because the event is skipped.
ui::InputPredictor::InputData result; EXPECT_FALSE(PredictionAvailable());
EXPECT_FALSE(PredictionAvailable(&result));
// Send a GSU with original event. // Send a GSU with original event.
gesture_update = CreateGestureScrollUpdate(0, -30); gesture_update = CreateGestureScrollUpdate(0, -30);
...@@ -318,21 +319,20 @@ TEST_F(ScrollPredictorTest, ScrollUpdateWithEmptyOriginalEventList) { ...@@ -318,21 +319,20 @@ TEST_F(ScrollPredictorTest, ScrollUpdateWithEmptyOriginalEventList) {
->data.scroll_update.delta_y); ->data.scroll_update.delta_y);
// Prediction only track GSU with original event list. // Prediction only track GSU with original event list.
EXPECT_TRUE(PredictionAvailable(&result)); auto result = PredictionAvailable();
EXPECT_EQ(-30, result.pos.y()); EXPECT_TRUE(result);
EXPECT_EQ(-30, result->pos.y());
} }
TEST_F(ScrollPredictorTest, LSQPredictorTest) { TEST_F(ScrollPredictorTest, LSQPredictorTest) {
SetUpLSQPredictor(); SetUpLSQPredictor();
SendGestureScrollBegin(); SendGestureScrollBegin();
ui::InputPredictor::InputData result;
// Send 1st GSU, no prediction available. // Send 1st GSU, no prediction available.
WebScopedInputEvent gesture_update = WebScopedInputEvent gesture_update =
CreateGestureScrollUpdate(0, -30, 8 /* ms */); CreateGestureScrollUpdate(0, -30, 8 /* ms */);
HandleResampleScrollEvents(gesture_update, 16 /* ms */); HandleResampleScrollEvents(gesture_update, 16 /* ms */);
EXPECT_FALSE(PredictionAvailable(&result, 16 /* ms */)); EXPECT_FALSE(PredictionAvailable(16 /* ms */));
EXPECT_EQ(-30, EXPECT_EQ(-30,
static_cast<const blink::WebGestureEvent*>(gesture_update.get()) static_cast<const blink::WebGestureEvent*>(gesture_update.get())
->data.scroll_update.delta_y); ->data.scroll_update.delta_y);
...@@ -351,7 +351,7 @@ TEST_F(ScrollPredictorTest, LSQPredictorTest) { ...@@ -351,7 +351,7 @@ TEST_F(ScrollPredictorTest, LSQPredictorTest) {
base::TimeDelta::FromMillisecondsD(16 /* ms */), base::TimeDelta::FromMillisecondsD(16 /* ms */),
static_cast<const blink::WebGestureEvent*>(gesture_update.get()) static_cast<const blink::WebGestureEvent*>(gesture_update.get())
->TimeStamp()); ->TimeStamp());
EXPECT_FALSE(PredictionAvailable(&result, 24 /* ms */)); EXPECT_FALSE(PredictionAvailable(24 /* ms */));
// Send 3rd and 4th GSU, prediction result returns the sum of delta_y, event // Send 3rd and 4th GSU, prediction result returns the sum of delta_y, event
// aligned at frame time. // aligned at frame time.
...@@ -364,8 +364,9 @@ TEST_F(ScrollPredictorTest, LSQPredictorTest) { ...@@ -364,8 +364,9 @@ TEST_F(ScrollPredictorTest, LSQPredictorTest) {
base::TimeDelta::FromMillisecondsD(32 /* ms */), base::TimeDelta::FromMillisecondsD(32 /* ms */),
static_cast<const blink::WebGestureEvent*>(gesture_update.get()) static_cast<const blink::WebGestureEvent*>(gesture_update.get())
->TimeStamp()); ->TimeStamp());
EXPECT_TRUE(PredictionAvailable(&result, 32 /* ms */)); auto result = PredictionAvailable(32 /* ms */);
EXPECT_EQ(-120, result.pos.y()); EXPECT_TRUE(result);
EXPECT_EQ(-120, result->pos.y());
gesture_update = CreateGestureScrollUpdate(0, -30, 32 /* ms */); gesture_update = CreateGestureScrollUpdate(0, -30, 32 /* ms */);
HandleResampleScrollEvents(gesture_update, 40 /* ms */); HandleResampleScrollEvents(gesture_update, 40 /* ms */);
...@@ -376,8 +377,9 @@ TEST_F(ScrollPredictorTest, LSQPredictorTest) { ...@@ -376,8 +377,9 @@ TEST_F(ScrollPredictorTest, LSQPredictorTest) {
base::TimeDelta::FromMillisecondsD(40 /* ms */), base::TimeDelta::FromMillisecondsD(40 /* ms */),
static_cast<const blink::WebGestureEvent*>(gesture_update.get()) static_cast<const blink::WebGestureEvent*>(gesture_update.get())
->TimeStamp()); ->TimeStamp());
EXPECT_TRUE(PredictionAvailable(&result, 40 /* ms */)); result = PredictionAvailable(40 /* ms */);
EXPECT_EQ(-150, result.pos.y()); EXPECT_TRUE(result);
EXPECT_EQ(-150, result->pos.y());
} }
TEST_F(ScrollPredictorTest, ScrollPredictorNotChangeScrollDirection) { TEST_F(ScrollPredictorTest, ScrollPredictorNotChangeScrollDirection) {
......
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