Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: content/renderer/input/main_thread_event_queue.cc

Issue 2479123003: WIP Add getCoalescedEvents API using vector of WebInputEvents (Closed)
Patch Set: Creating CoalescedWebInputEvent Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/input/main_thread_event_queue.h" 5 #include "content/renderer/input/main_thread_event_queue.h"
6 6
7 #include "base/metrics/histogram_macros.h" 7 #include "base/metrics/histogram_macros.h"
8 #include "content/common/input/event_with_latency_info.h" 8 #include "content/common/input/event_with_latency_info.h"
9 #include "content/common/input_messages.h" 9 #include "content/common/input_messages.h"
10 10
11 namespace content { 11 namespace content {
12 12
13 namespace { 13 namespace {
14 14
15 const size_t kTenSeconds = 10 * 1000 * 1000; 15 const size_t kTenSeconds = 10 * 1000 * 1000;
16 16
17 bool IsContinuousEvent(const std::unique_ptr<EventWithDispatchType>& event) { 17 bool IsContinuousEvent(const std::unique_ptr<EventWithDispatchType>& event) {
18 switch (event->event().type) { 18 switch (event->coalescedEvent().event().type) {
19 case blink::WebInputEvent::MouseMove: 19 case blink::WebInputEvent::MouseMove:
20 case blink::WebInputEvent::MouseWheel: 20 case blink::WebInputEvent::MouseWheel:
21 return true; 21 return true;
22 case blink::WebInputEvent::TouchMove: 22 case blink::WebInputEvent::TouchMove:
23 // TouchMoves that are blocking end up blocking scroll. Do not treat 23 // TouchMoves that are blocking end up blocking scroll. Do not treat
24 // them as continuous events otherwise we will end up waiting up to an 24 // them as continuous events otherwise we will end up waiting up to an
25 // additional frame. 25 // additional frame.
26 return static_cast<const blink::WebTouchEvent&>(event->event()) 26 return static_cast<const blink::WebTouchEvent&>(
27 event->coalescedEvent().event())
27 .dispatchType != blink::WebInputEvent::Blocking; 28 .dispatchType != blink::WebInputEvent::Blocking;
28 default: 29 default:
29 return false; 30 return false;
30 } 31 }
31 } 32 }
32 33
33 } // namespace 34 } // namespace
34 35
35 EventWithDispatchType::EventWithDispatchType( 36 EventWithDispatchType::EventWithDispatchType(
36 ui::ScopedWebInputEvent event, 37 blink::CoalescedWebInputEvent::ScopedWebInputEvent event,
37 const ui::LatencyInfo& latency, 38 const ui::LatencyInfo& latency,
38 InputEventDispatchType dispatch_type) 39 InputEventDispatchType dispatch_type)
39 : ScopedWebInputEventWithLatencyInfo(std::move(event), latency), 40 : ScopedWebInputEventWithLatencyInfo(std::move(event), latency),
40 dispatch_type_(dispatch_type), 41 dispatch_type_(dispatch_type),
41 creation_timestamp_(base::TimeTicks::Now()), 42 creation_timestamp_(base::TimeTicks::Now()),
42 last_coalesced_timestamp_(creation_timestamp_) {} 43 last_coalesced_timestamp_(creation_timestamp_) {}
43 44
44 EventWithDispatchType::~EventWithDispatchType() {} 45 EventWithDispatchType::~EventWithDispatchType() {}
45 46
46 bool EventWithDispatchType::CanCoalesceWith( 47 bool EventWithDispatchType::CanCoalesceWith(
47 const EventWithDispatchType& other) const { 48 const EventWithDispatchType& other) const {
48 return other.dispatch_type_ == dispatch_type_ && 49 return other.dispatch_type_ == dispatch_type_ &&
49 ScopedWebInputEventWithLatencyInfo::CanCoalesceWith(other); 50 ScopedWebInputEventWithLatencyInfo::CanCoalesceWith(other);
50 } 51 }
51 52
52 void EventWithDispatchType::CoalesceWith(const EventWithDispatchType& other) { 53 void EventWithDispatchType::CoalesceWith(const EventWithDispatchType& other) {
53 coalesced_event_ids_.push_back( 54 coalesced_event_ids_.push_back(ui::WebInputEventTraits::GetUniqueTouchEventId(
54 ui::WebInputEventTraits::GetUniqueTouchEventId(other.event())); 55 other.coalescedEvent().event()));
55 ScopedWebInputEventWithLatencyInfo::CoalesceWith(other); 56 ScopedWebInputEventWithLatencyInfo::CoalesceWith(other);
56 last_coalesced_timestamp_ = base::TimeTicks::Now(); 57 last_coalesced_timestamp_ = base::TimeTicks::Now();
57 } 58 }
58 59
59 MainThreadEventQueue::SharedState::SharedState() 60 MainThreadEventQueue::SharedState::SharedState()
60 : sent_main_frame_request_(false) {} 61 : sent_main_frame_request_(false) {}
61 62
62 MainThreadEventQueue::SharedState::~SharedState() {} 63 MainThreadEventQueue::SharedState::~SharedState() {}
63 64
64 MainThreadEventQueue::MainThreadEventQueue( 65 MainThreadEventQueue::MainThreadEventQueue(
65 int routing_id, 66 int routing_id,
66 MainThreadEventQueueClient* client, 67 MainThreadEventQueueClient* client,
67 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner, 68 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner,
68 blink::scheduler::RendererScheduler* renderer_scheduler) 69 blink::scheduler::RendererScheduler* renderer_scheduler)
69 : routing_id_(routing_id), 70 : routing_id_(routing_id),
70 client_(client), 71 client_(client),
71 last_touch_start_forced_nonblocking_due_to_fling_(false), 72 last_touch_start_forced_nonblocking_due_to_fling_(false),
72 enable_fling_passive_listener_flag_(base::FeatureList::IsEnabled( 73 enable_fling_passive_listener_flag_(base::FeatureList::IsEnabled(
73 features::kPassiveEventListenersDueToFling)), 74 features::kPassiveEventListenersDueToFling)),
74 handle_raf_aligned_touch_input_( 75 handle_raf_aligned_touch_input_(
75 base::FeatureList::IsEnabled(features::kRafAlignedTouchInputEvents)), 76 base::FeatureList::IsEnabled(features::kRafAlignedTouchInputEvents)),
76 handle_raf_aligned_mouse_input_( 77 handle_raf_aligned_mouse_input_(
77 base::FeatureList::IsEnabled(features::kRafAlignedMouseInputEvents)), 78 base::FeatureList::IsEnabled(features::kRafAlignedMouseInputEvents)),
78 main_task_runner_(main_task_runner), 79 main_task_runner_(main_task_runner),
79 renderer_scheduler_(renderer_scheduler) {} 80 renderer_scheduler_(renderer_scheduler) {}
80 81
81 MainThreadEventQueue::~MainThreadEventQueue() {} 82 MainThreadEventQueue::~MainThreadEventQueue() {}
82 83
83 bool MainThreadEventQueue::HandleEvent( 84 bool MainThreadEventQueue::HandleEvent(
84 ui::ScopedWebInputEvent event, 85 blink::CoalescedWebInputEvent::ScopedWebInputEvent event,
85 const ui::LatencyInfo& latency, 86 const ui::LatencyInfo& latency,
86 InputEventDispatchType original_dispatch_type, 87 InputEventDispatchType original_dispatch_type,
87 InputEventAckState ack_result) { 88 InputEventAckState ack_result) {
88 DCHECK(original_dispatch_type == DISPATCH_TYPE_BLOCKING || 89 DCHECK(original_dispatch_type == DISPATCH_TYPE_BLOCKING ||
89 original_dispatch_type == DISPATCH_TYPE_NON_BLOCKING); 90 original_dispatch_type == DISPATCH_TYPE_NON_BLOCKING);
90 DCHECK(ack_result == INPUT_EVENT_ACK_STATE_SET_NON_BLOCKING || 91 DCHECK(ack_result == INPUT_EVENT_ACK_STATE_SET_NON_BLOCKING ||
91 ack_result == INPUT_EVENT_ACK_STATE_SET_NON_BLOCKING_DUE_TO_FLING || 92 ack_result == INPUT_EVENT_ACK_STATE_SET_NON_BLOCKING_DUE_TO_FLING ||
92 ack_result == INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 93 ack_result == INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
93 94
94 bool non_blocking = original_dispatch_type == DISPATCH_TYPE_NON_BLOCKING || 95 bool non_blocking = original_dispatch_type == DISPATCH_TYPE_NON_BLOCKING ||
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 (now - in_flight_event_->creationTimestamp()).InMicroseconds(), 1, 166 (now - in_flight_event_->creationTimestamp()).InMicroseconds(), 1,
166 kTenSeconds, 50); 167 kTenSeconds, 50);
167 } 168 }
168 169
169 InputEventDispatchType dispatch_type = in_flight_event_->dispatchType(); 170 InputEventDispatchType dispatch_type = in_flight_event_->dispatchType();
170 if (!in_flight_event_->coalescedEventIds().empty() && 171 if (!in_flight_event_->coalescedEventIds().empty() &&
171 dispatch_type == DISPATCH_TYPE_BLOCKING) { 172 dispatch_type == DISPATCH_TYPE_BLOCKING) {
172 dispatch_type = DISPATCH_TYPE_BLOCKING_NOTIFY_MAIN; 173 dispatch_type = DISPATCH_TYPE_BLOCKING_NOTIFY_MAIN;
173 } 174 }
174 175
175 client_->HandleEventOnMainThread(routing_id_, &in_flight_event_->event(), 176 client_->HandleEventOnMainThread(
176 in_flight_event_->latencyInfo(), 177 routing_id_, &in_flight_event_->coalescedEvent(),
177 dispatch_type); 178 in_flight_event_->latencyInfo(), dispatch_type);
178 } 179 }
179 180
180 in_flight_event_.reset(); 181 in_flight_event_.reset();
181 } 182 }
182 183
183 void MainThreadEventQueue::PossiblyScheduleMainFrame() { 184 void MainThreadEventQueue::PossiblyScheduleMainFrame() {
184 if (IsRafAlignedInputDisabled()) 185 if (IsRafAlignedInputDisabled())
185 return; 186 return;
186 bool needs_main_frame = false; 187 bool needs_main_frame = false;
187 { 188 {
(...skipping 22 matching lines...) Expand all
210 } 211 }
211 212
212 void MainThreadEventQueue::EventHandled(blink::WebInputEvent::Type type, 213 void MainThreadEventQueue::EventHandled(blink::WebInputEvent::Type type,
213 InputEventAckState ack_result) { 214 InputEventAckState ack_result) {
214 if (in_flight_event_ && 215 if (in_flight_event_ &&
215 in_flight_event_->dispatchType() == DISPATCH_TYPE_BLOCKING) { 216 in_flight_event_->dispatchType() == DISPATCH_TYPE_BLOCKING) {
216 for (const auto id : in_flight_event_->coalescedEventIds()) { 217 for (const auto id : in_flight_event_->coalescedEventIds()) {
217 client_->SendInputEventAck(routing_id_, type, ack_result, id); 218 client_->SendInputEventAck(routing_id_, type, ack_result, id);
218 if (renderer_scheduler_) { 219 if (renderer_scheduler_) {
219 renderer_scheduler_->DidHandleInputEventOnMainThread( 220 renderer_scheduler_->DidHandleInputEventOnMainThread(
220 in_flight_event_->event()); 221 in_flight_event_->coalescedEvent().event());
221 } 222 }
222 } 223 }
223 } 224 }
224 } 225 }
225 226
226 void MainThreadEventQueue::DispatchRafAlignedInput() { 227 void MainThreadEventQueue::DispatchRafAlignedInput() {
227 if (IsRafAlignedInputDisabled()) 228 if (IsRafAlignedInputDisabled())
228 return; 229 return;
229 230
230 std::deque<std::unique_ptr<EventWithDispatchType>> events_to_process; 231 std::deque<std::unique_ptr<EventWithDispatchType>> events_to_process;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 if (needs_main_frame) 288 if (needs_main_frame)
288 client_->NeedsMainFrame(routing_id_); 289 client_->NeedsMainFrame(routing_id_);
289 } 290 }
290 291
291 bool MainThreadEventQueue::IsRafAlignedInputDisabled() { 292 bool MainThreadEventQueue::IsRafAlignedInputDisabled() {
292 return !handle_raf_aligned_mouse_input_ && !handle_raf_aligned_touch_input_; 293 return !handle_raf_aligned_mouse_input_ && !handle_raf_aligned_touch_input_;
293 } 294 }
294 295
295 bool MainThreadEventQueue::IsRafAlignedEvent( 296 bool MainThreadEventQueue::IsRafAlignedEvent(
296 const std::unique_ptr<EventWithDispatchType>& event) { 297 const std::unique_ptr<EventWithDispatchType>& event) {
297 switch (event->event().type) { 298 switch (event->coalescedEvent().event().type) {
298 case blink::WebInputEvent::MouseMove: 299 case blink::WebInputEvent::MouseMove:
299 case blink::WebInputEvent::MouseWheel: 300 case blink::WebInputEvent::MouseWheel:
300 return handle_raf_aligned_mouse_input_; 301 return handle_raf_aligned_mouse_input_;
301 case blink::WebInputEvent::TouchMove: 302 case blink::WebInputEvent::TouchMove:
302 // TouchMoves that are blocking end up blocking scroll. Do not treat 303 // TouchMoves that are blocking end up blocking scroll. Do not treat
303 // them as continuous events otherwise we will end up waiting up to an 304 // them as continuous events otherwise we will end up waiting up to an
304 // additional frame. 305 // additional frame.
305 return static_cast<const blink::WebTouchEvent&>(event->event()) 306 return static_cast<const blink::WebTouchEvent&>(
307 event->coalescedEvent().event())
306 .dispatchType != blink::WebInputEvent::Blocking && 308 .dispatchType != blink::WebInputEvent::Blocking &&
307 handle_raf_aligned_touch_input_; 309 handle_raf_aligned_touch_input_;
308 default: 310 default:
309 return false; 311 return false;
310 } 312 }
311 } 313 }
312 314
313 } // namespace content 315 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698