Commit 4ef63445 authored by Ella Ge's avatar Ella Ge Committed by Commit Bot

Add latency_info to original event list

When events are not handled on cc, they will be re-coalesced and handled
on main thread. Use the original latency instead of coalesced latency
in tracing.

Bug: 789041
Change-Id: Ie9bfd7339b45c4a78ca8065a63cd6d61d0dfc051
Reviewed-on: https://chromium-review.googlesource.com/1049059Reviewed-by: default avatarDave Tapuska <dtapuska@chromium.org>
Reviewed-by: default avatarJuan Antonio Navarro Pérez <perezju@chromium.org>
Commit-Queue: Dave Tapuska <dtapuska@chromium.org>
Cr-Commit-Position: refs/heads/master@{#558691}
parent 3ca5ccfe
......@@ -469,6 +469,7 @@ void WidgetInputHandlerManager::DidHandleInputEventAndOverscroll(
ack_state == INPUT_EVENT_ACK_STATE_SET_NON_BLOCKING_DUE_TO_FLING ||
ack_state == INPUT_EVENT_ACK_STATE_NOT_CONSUMED) {
DCHECK(!overscroll_params);
DCHECK(!latency_info.coalesced());
InputEventDispatchType dispatch_type = callback.is_null()
? DISPATCH_TYPE_NON_BLOCKING
: DISPATCH_TYPE_BLOCKING;
......
......@@ -297,9 +297,6 @@ crbug.com/836406 [ Linux ] system_health.memory_desktop/browse:news:flipboard [
crbug.com/836407 [ Linux ] system_health.memory_desktop/browse:tools:maps [ Skip ]
crbug.com/837397 [ Linux ] system_health.memory_desktop/load_accessibility:shopping:amazon [ Skip ]
crbug.com/836447 [ ChromeOS ] system_health.memory_desktop/multitab:misc:typical24 [ Skip ]
crbug.com/789041 [ Linux ] system_health.memory_desktop/browse:news:reddit [ Skip ]
crbug.com/789041 [ Win ] system_health.memory_desktop/browse:news:reddit [ Skip ]
crbug.com/789041 [ Win ] system_health.memory_desktop/browse:news:nytimes [ Skip ]
# Benchmark: system_health.memory_mobile
crbug.com/787001 [ Android_Webview ] system_health.memory_mobile/load:media:soundcloud [ Skip ]
......
......@@ -23,7 +23,7 @@ EventWithCallback::EventWithCallback(
latency_(latency),
creation_timestamp_(timestamp_now),
last_coalesced_timestamp_(timestamp_now) {
original_events_.emplace_back(std::move(event), std::move(callback));
original_events_.emplace_back(std::move(event), latency, std::move(callback));
}
EventWithCallback::EventWithCallback(
......@@ -68,6 +68,14 @@ void EventWithCallback::CoalesceWith(EventWithCallback* other,
last_coalesced_timestamp_ = timestamp_now;
}
static bool HandledOnCompositorThread(
InputHandlerProxy::EventDisposition disposition) {
return (disposition != InputHandlerProxy::DID_NOT_HANDLE &&
disposition !=
InputHandlerProxy::DID_NOT_HANDLE_NON_BLOCKING_DUE_TO_FLING &&
disposition != InputHandlerProxy::DID_HANDLE_NON_BLOCKING);
}
void EventWithCallback::RunCallbacks(
InputHandlerProxy::EventDisposition disposition,
const LatencyInfo& latency,
......@@ -85,12 +93,18 @@ void EventWithCallback::RunCallbacks(
: nullptr);
original_events_.pop_front();
// Ack other events with coalesced latency to avoid redundant tracking.
LatencyInfo coalesced_latency = latency;
coalesced_latency.set_coalesced();
// If the event was handled on compositor thread, ack other events with
// coalesced latency to avoid redundant tracking. If not, the event should
// be handle on main thread, use the original latency instead.
bool handled = HandledOnCompositorThread(disposition);
for (auto& coalesced_event : original_events_) {
if (handled) {
coalesced_event.latency_ = latency;
coalesced_event.latency_.set_coalesced();
}
std::move(coalesced_event.callback_)
.Run(disposition, std::move(coalesced_event.event_), coalesced_latency,
.Run(disposition, std::move(coalesced_event.event_),
coalesced_event.latency_,
did_overscroll_params
? std::make_unique<DidOverscrollParams>(*did_overscroll_params)
: nullptr);
......@@ -99,8 +113,11 @@ void EventWithCallback::RunCallbacks(
EventWithCallback::OriginalEventWithCallback::OriginalEventWithCallback(
WebScopedInputEvent event,
const LatencyInfo& latency,
InputHandlerProxy::EventDispositionCallback callback)
: event_(std::move(event)), callback_(std::move(callback)) {}
: event_(std::move(event)),
latency_(latency),
callback_(std::move(callback)) {}
EventWithCallback::OriginalEventWithCallback::~OriginalEventWithCallback() {}
......
......@@ -21,9 +21,11 @@ class EventWithCallback {
struct OriginalEventWithCallback {
OriginalEventWithCallback(
WebScopedInputEvent event,
const LatencyInfo& latency,
InputHandlerProxy::EventDispositionCallback callback);
~OriginalEventWithCallback();
WebScopedInputEvent event_;
LatencyInfo latency_;
InputHandlerProxy::EventDispositionCallback callback_;
};
using OriginalEventList = std::list<OriginalEventWithCallback>;
......
......@@ -2126,6 +2126,71 @@ TEST_P(InputHandlerProxyEventQueueTest, CoalescedLatencyInfo) {
testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
}
TEST_P(InputHandlerProxyEventQueueTest, CoalescedEventSwitchToMainThread) {
cc::InputHandlerScrollResult scroll_result_did_scroll_;
cc::InputHandlerScrollResult scroll_result_did_not_scroll_;
scroll_result_did_scroll_.did_scroll = true;
scroll_result_did_not_scroll_.did_scroll = false;
// scroll begin on main thread
EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
.WillOnce(testing::Return(kMainThreadScrollState));
EXPECT_CALL(mock_input_handler_, SetNeedsAnimateInput()).Times(2);
EXPECT_CALL(mock_input_handler_, ScrollingShouldSwitchtoMainThread())
.WillOnce(testing::Return(false));
EXPECT_CALL(
mock_input_handler_,
ScrollBy(testing::Property(&cc::ScrollState::delta_y, testing::Gt(0))))
.WillOnce(testing::Return(scroll_result_did_not_scroll_));
HandleGestureEvent(WebInputEvent::kGestureScrollBegin);
HandleGestureEvent(WebInputEvent::kGestureScrollUpdate, -20);
HandleGestureEvent(WebInputEvent::kGestureScrollUpdate, -10);
input_handler_proxy_->DeliverInputForBeginFrame();
EXPECT_EQ(3ul, event_disposition_recorder_.size());
EXPECT_EQ(InputHandlerProxy::DID_NOT_HANDLE,
event_disposition_recorder_.back());
// GSU should not be coalesced
EXPECT_EQ(false, latency_info_recorder_[1].coalesced());
EXPECT_EQ(false, latency_info_recorder_[2].coalesced());
// pinch start, handle scroll and pinch on compositor.
EXPECT_CALL(mock_input_handler_, PinchGestureBegin());
EXPECT_CALL(mock_input_handler_, PinchGestureUpdate(testing::_, testing::_));
EXPECT_CALL(mock_input_handler_, PinchGestureEnd(testing::_, testing::_));
HandleGestureEvent(WebInputEvent::kGesturePinchBegin);
HandleGestureEvent(WebInputEvent::kGesturePinchUpdate, 10.0f, 1, 10);
HandleGestureEvent(WebInputEvent::kGestureScrollUpdate, -10);
HandleGestureEvent(WebInputEvent::kGestureScrollUpdate, -30);
EXPECT_EQ(2ul, event_queue().size());
input_handler_proxy_->DeliverInputForBeginFrame();
EXPECT_EQ(7ul, event_disposition_recorder_.size());
EXPECT_EQ(false, latency_info_recorder_[4].coalesced());
// Coalesced events should have latency set to coalesced.
EXPECT_EQ(true, latency_info_recorder_[5].coalesced());
EXPECT_EQ(true, latency_info_recorder_[6].coalesced());
EXPECT_EQ(InputHandlerProxy::DID_HANDLE, event_disposition_recorder_.back());
// Pinch end, handle scroll on main thread.
HandleGestureEvent(WebInputEvent::kGesturePinchEnd);
HandleGestureEvent(WebInputEvent::kGestureScrollUpdate, -40);
HandleGestureEvent(WebInputEvent::kGestureScrollUpdate, -30);
input_handler_proxy_->DeliverInputForBeginFrame();
EXPECT_EQ(0ul, event_queue().size());
// Should run callbacks for every original events.
EXPECT_EQ(10ul, event_disposition_recorder_.size());
EXPECT_EQ(10ul, latency_info_recorder_.size());
// Latency should not be set to coalesced when send to main thread
EXPECT_EQ(false, latency_info_recorder_[8].coalesced());
EXPECT_EQ(false, latency_info_recorder_[9].coalesced());
EXPECT_EQ(InputHandlerProxy::DID_NOT_HANDLE,
event_disposition_recorder_.back());
testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
}
INSTANTIATE_TEST_CASE_P(AnimateInput,
InputHandlerProxyTest,
testing::ValuesIn(test_types));
......
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