Commit 6482b50d authored by Ella Ge's avatar Ella Ge Committed by Commit Bot

Scroll resampling use linear resampling when no predictor type specified

This CL changes linear resampling to scroll predictor's default predictor
type and also fix related unit tests.
This is to prepare the enabling of scroll resampling. So when the flag
turn on, it will default to use linear resampling predictor type.

This is to get a better scroll experience on scrolling, detail see the doc:
https://docs.google.com/document/d/1KrlQ0m5Ty9RKE1IorjEXDldYFJvUV_Ww10lnjh-TRN0/

Bug: 1000682
Change-Id: I3928428700a36f8c25ac2c0c1294b3a4478bc579
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1786868
Commit-Queue: Ella Ge <eirage@chromium.org>
Reviewed-by: default avatarDavid Bokan <bokan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#697065}
parent ce1baa20
......@@ -9,6 +9,7 @@
#include "base/macros.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "content/browser/renderer_host/input/synthetic_gesture.h"
#include "content/browser/renderer_host/input/synthetic_smooth_scroll_gesture.h"
......@@ -165,6 +166,9 @@ class CompositedScrollingBrowserTest : public ContentBrowserTest {
#endif
IN_PROC_BROWSER_TEST_F(CompositedScrollingBrowserTest,
MAYBE_Scroll3DTransformedScroller) {
// Disable scroll resampling because this is checking scroll distance.
base::test::ScopedFeatureList scoped_feature_list_;
scoped_feature_list_.InitAndDisableFeature(features::kResamplingScrollEvents);
LoadURL();
double scroll_distance =
DoTouchScroll(gfx::Point(50, 150), gfx::Vector2d(0, 100));
......
......@@ -81,11 +81,11 @@ MATCHER_P(WheelEventsMatch, expected, "") {
WebScopedInputEvent CreateGestureScrollPinch(WebInputEvent::Type type,
WebGestureDevice source_device,
base::TimeTicks event_time,
float delta_y_or_scale = 0,
int x = 0,
int y = 0) {
WebGestureEvent gesture(type, WebInputEvent::kNoModifiers,
WebInputEvent::GetStaticTimeStampForTests(),
WebGestureEvent gesture(type, WebInputEvent::kNoModifiers, event_time,
source_device);
if (type == WebInputEvent::kGestureScrollUpdate) {
gesture.data.scroll_update.delta_y = delta_y_or_scale;
......@@ -446,7 +446,9 @@ class InputHandlerProxyEventQueueTest : public testing::Test {
int y = 0) {
LatencyInfo latency;
input_handler_proxy_.HandleInputEventWithLatencyInfo(
CreateGestureScrollPinch(type, source_device, delta_y_or_scale, x, y),
CreateGestureScrollPinch(type, source_device,
input_handler_proxy_.tick_clock_->NowTicks(),
delta_y_or_scale, x, y),
latency,
base::BindOnce(
&InputHandlerProxyEventQueueTest::DidHandleInputEventAndOverscroll,
......@@ -1972,6 +1974,10 @@ TEST_F(InputHandlerProxyEventQueueTest, CoalescedEventSwitchToMainThread) {
}
TEST_F(InputHandlerProxyEventQueueTest, ScrollPredictorTest) {
base::SimpleTestTickClock tick_clock;
tick_clock.SetNowTicks(base::TimeTicks());
SetInputHandlerProxyTickClockForTesting(&tick_clock);
cc::InputHandlerScrollResult scroll_result_did_scroll_;
scroll_result_did_scroll_.did_scroll = true;
EXPECT_CALL(mock_input_handler_, ScrollBegin(_, _))
......@@ -1984,16 +1990,19 @@ TEST_F(InputHandlerProxyEventQueueTest, ScrollPredictorTest) {
// No prediction when start with a GSB
ui::InputPredictor::InputData result;
tick_clock.Advance(base::TimeDelta::FromMilliseconds(8));
HandleGestureEvent(WebInputEvent::kGestureScrollBegin);
DeliverInputForBeginFrame();
EXPECT_FALSE(GestureScrollEventPredictionAvailable(&result));
// Test predictor returns last GSU delta.
tick_clock.Advance(base::TimeDelta::FromMilliseconds(8));
HandleGestureEvent(WebInputEvent::kGestureScrollUpdate, -20);
tick_clock.Advance(base::TimeDelta::FromMilliseconds(8));
HandleGestureEvent(WebInputEvent::kGestureScrollUpdate, -15);
DeliverInputForBeginFrame();
EXPECT_TRUE(GestureScrollEventPredictionAvailable(&result));
EXPECT_EQ(-35, result.pos.y());
EXPECT_NE(0, result.pos.y());
testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
......@@ -2001,6 +2010,7 @@ TEST_F(InputHandlerProxyEventQueueTest, ScrollPredictorTest) {
EXPECT_CALL(mock_input_handler_, SetNeedsAnimateInput()).Times(1);
EXPECT_CALL(mock_input_handler_, ScrollBegin(_, _))
.WillOnce(testing::Return(kImplThreadScrollState));
tick_clock.Advance(base::TimeDelta::FromMilliseconds(8));
HandleGestureEvent(WebInputEvent::kGestureScrollBegin);
DeliverInputForBeginFrame();
EXPECT_FALSE(GestureScrollEventPredictionAvailable(&result));
......@@ -2544,6 +2554,8 @@ class InputHandlerProxyMomentumScrollJankTest : public testing::Test {
&mock_client_,
/*force_input_to_main_thread=*/false) {
tick_clock_.SetNowTicks(base::TimeTicks::Now());
// Disable scroll predictor for this test.
input_handler_proxy_.scroll_predictor_ = nullptr;
input_handler_proxy_.SetTickClockForTesting(&tick_clock_);
}
......
......@@ -20,6 +20,9 @@ ScrollPredictor::ScrollPredictor() {
std::string predictor_name = GetFieldTrialParamValueByFeature(
features::kResamplingScrollEvents, "predictor");
if (predictor_name.empty())
predictor_name = ui::input_prediction::kScrollPredictorNameLinearResampling;
input_prediction::PredictorType predictor_type =
ui::PredictorFactory::GetPredictorTypeFromName(predictor_name);
predictor_ = ui::PredictorFactory::GetPredictor(predictor_type);
......
......@@ -420,9 +420,9 @@ TEST_F(ScrollPredictorTest, ScrollPredictorNotChangeScrollDirection) {
}
TEST_F(ScrollPredictorTest, ScrollPredictorTypeSelection) {
// Empty Predictor when kResamplingScrollEvents is disabled.
// Use LinearResampling predictor by default.
scroll_predictor_ = std::make_unique<ScrollPredictor>();
VerifyPredictorType(input_prediction::kScrollPredictorNameEmpty);
VerifyPredictorType(input_prediction::kScrollPredictorNameLinearResampling);
// When resampling is enabled, predictor type is set from
// kResamplingScrollEvents.
......
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