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

Side by Side Diff: content/browser/renderer_host/input/input_router_impl.cc

Issue 2162143002: Don't use PostTask queueing between compositor and main thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Don't ack mouse move right away send them unthrottled Created 4 years, 5 months 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/browser/renderer_host/input/input_router_impl.h" 5 #include "content/browser/renderer_host/input/input_router_impl.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 InputAckHandler* ack_handler, 72 InputAckHandler* ack_handler,
73 int routing_id, 73 int routing_id,
74 const Config& config) 74 const Config& config)
75 : sender_(sender), 75 : sender_(sender),
76 client_(client), 76 client_(client),
77 ack_handler_(ack_handler), 77 ack_handler_(ack_handler),
78 routing_id_(routing_id), 78 routing_id_(routing_id),
79 frame_tree_node_id_(-1), 79 frame_tree_node_id_(-1),
80 select_message_pending_(false), 80 select_message_pending_(false),
81 move_caret_pending_(false), 81 move_caret_pending_(false),
82 mouse_move_pending_(false),
83 current_ack_source_(ACK_SOURCE_NONE), 82 current_ack_source_(ACK_SOURCE_NONE),
84 flush_requested_(false), 83 flush_requested_(false),
85 active_renderer_fling_count_(0), 84 active_renderer_fling_count_(0),
86 touch_scroll_started_sent_(false), 85 touch_scroll_started_sent_(false),
87 wheel_event_queue_(this, kDefaultWheelScrollTransactionMs), 86 wheel_event_queue_(this, kDefaultWheelScrollTransactionMs),
88 touch_event_queue_(this, config.touch_config), 87 touch_event_queue_(this, config.touch_config),
89 gesture_event_queue_(this, this, config.gesture_config), 88 gesture_event_queue_(this, this, config.gesture_config),
90 device_scale_factor_(1.f) { 89 device_scale_factor_(1.f) {
91 DCHECK(sender); 90 DCHECK(sender);
92 DCHECK(client); 91 DCHECK(client);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 void InputRouterImpl::SendTouchEvent( 180 void InputRouterImpl::SendTouchEvent(
182 const TouchEventWithLatencyInfo& touch_event) { 181 const TouchEventWithLatencyInfo& touch_event) {
183 input_stream_validator_.Validate(touch_event.event); 182 input_stream_validator_.Validate(touch_event.event);
184 touch_event_queue_.QueueEvent(touch_event); 183 touch_event_queue_.QueueEvent(touch_event);
185 } 184 }
186 185
187 // Forwards MouseEvent without passing it through 186 // Forwards MouseEvent without passing it through
188 // TouchpadTapSuppressionController. 187 // TouchpadTapSuppressionController.
189 void InputRouterImpl::SendMouseEventImmediately( 188 void InputRouterImpl::SendMouseEventImmediately(
190 const MouseEventWithLatencyInfo& mouse_event) { 189 const MouseEventWithLatencyInfo& mouse_event) {
191 // Avoid spamming the renderer with mouse move events. It is important 190 if (mouse_event.event.type == blink::WebInputEvent::MouseMove)
192 // to note that WM_MOUSEMOVE events are anyways synthetic, but since our 191 mouse_move_queue_.push_back(mouse_event);
tdresser 2016/07/20 20:52:27 Don't we still only need the most recent mousemove
dtapuska 2016/07/27 05:29:00 Unfortunately with the latency info we need to hav
193 // thread is able to rapidly consume WM_MOUSEMOVE events, we may get way
194 // more WM_MOUSEMOVE events than we wish to send to the renderer.
195 if (mouse_event.event.type == WebInputEvent::MouseMove) {
196 if (mouse_move_pending_) {
197 if (!next_mouse_move_)
198 next_mouse_move_.reset(new MouseEventWithLatencyInfo(mouse_event));
199 else
200 next_mouse_move_->CoalesceWith(mouse_event);
201 return;
202 }
203 mouse_move_pending_ = true;
204 current_mouse_move_ = mouse_event;
205 }
206 192
207 FilterAndSendWebInputEvent(mouse_event.event, mouse_event.latency); 193 FilterAndSendWebInputEvent(mouse_event.event, mouse_event.latency);
208 } 194 }
209 195
210 void InputRouterImpl::SendTouchEventImmediately( 196 void InputRouterImpl::SendTouchEventImmediately(
211 const TouchEventWithLatencyInfo& touch_event) { 197 const TouchEventWithLatencyInfo& touch_event) {
212 if (WebTouchEventTraits::IsTouchSequenceStart(touch_event.event)) { 198 if (WebTouchEventTraits::IsTouchSequenceStart(touch_event.event)) {
213 touch_action_filter_.ResetTouchAction(); 199 touch_action_filter_.ResetTouchAction();
214 // Note that if the previous touch-action was TOUCH_ACTION_NONE, enabling 200 // Note that if the previous touch-action was TOUCH_ACTION_NONE, enabling
215 // the timeout here will not take effect until the *following* touch 201 // the timeout here will not take effect until the *following* touch
(...skipping 20 matching lines...) Expand all
236 touch_event_queue_.SetIsMobileOptimizedSite(is_mobile_optimized); 222 touch_event_queue_.SetIsMobileOptimizedSite(is_mobile_optimized);
237 } 223 }
238 224
239 void InputRouterImpl::RequestNotificationWhenFlushed() { 225 void InputRouterImpl::RequestNotificationWhenFlushed() {
240 flush_requested_ = true; 226 flush_requested_ = true;
241 SignalFlushedIfNecessary(); 227 SignalFlushedIfNecessary();
242 } 228 }
243 229
244 bool InputRouterImpl::HasPendingEvents() const { 230 bool InputRouterImpl::HasPendingEvents() const {
245 return !touch_event_queue_.empty() || !gesture_event_queue_.empty() || 231 return !touch_event_queue_.empty() || !gesture_event_queue_.empty() ||
246 !key_queue_.empty() || mouse_move_pending_ || 232 !key_queue_.empty() || !mouse_move_queue_.empty() ||
247 wheel_event_queue_.has_pending() || select_message_pending_ || 233 wheel_event_queue_.has_pending() || select_message_pending_ ||
248 move_caret_pending_ || active_renderer_fling_count_ > 0; 234 move_caret_pending_ || active_renderer_fling_count_ > 0;
249 } 235 }
250 236
251 void InputRouterImpl::SetDeviceScaleFactor(float device_scale_factor) { 237 void InputRouterImpl::SetDeviceScaleFactor(float device_scale_factor) {
252 device_scale_factor_ = device_scale_factor; 238 device_scale_factor_ = device_scale_factor;
253 } 239 }
254 240
255 bool InputRouterImpl::OnMessageReceived(const IPC::Message& message) { 241 bool InputRouterImpl::OnMessageReceived(const IPC::Message& message) {
256 bool handled = true; 242 bool handled = true;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 "InputRouterImpl::FilterAndSendWebInputEvent", 349 "InputRouterImpl::FilterAndSendWebInputEvent",
364 "type", 350 "type",
365 WebInputEventTraits::GetName(input_event.type)); 351 WebInputEventTraits::GetName(input_event.type));
366 TRACE_EVENT_WITH_FLOW2("input,benchmark,devtools.timeline", 352 TRACE_EVENT_WITH_FLOW2("input,benchmark,devtools.timeline",
367 "LatencyInfo.Flow", 353 "LatencyInfo.Flow",
368 TRACE_ID_DONT_MANGLE(latency_info.trace_id()), 354 TRACE_ID_DONT_MANGLE(latency_info.trace_id()),
369 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT, 355 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT,
370 "step", "SendInputEventUI", 356 "step", "SendInputEventUI",
371 "frameTreeNodeId", frame_tree_node_id_); 357 "frameTreeNodeId", frame_tree_node_id_);
372 358
373 // Any input event cancels a pending mouse move event.
374 next_mouse_move_.reset();
375
376 OfferToHandlers(input_event, latency_info); 359 OfferToHandlers(input_event, latency_info);
377 } 360 }
378 361
379 void InputRouterImpl::OfferToHandlers(const WebInputEvent& input_event, 362 void InputRouterImpl::OfferToHandlers(const WebInputEvent& input_event,
380 const ui::LatencyInfo& latency_info) { 363 const ui::LatencyInfo& latency_info) {
381 output_stream_validator_.Validate(input_event); 364 output_stream_validator_.Validate(input_event);
382 365
383 if (OfferToClient(input_event, latency_info)) 366 if (OfferToClient(input_event, latency_info))
384 return; 367 return;
385 368
(...skipping 15 matching lines...) Expand all
401 bool InputRouterImpl::OfferToClient(const WebInputEvent& input_event, 384 bool InputRouterImpl::OfferToClient(const WebInputEvent& input_event,
402 const ui::LatencyInfo& latency_info) { 385 const ui::LatencyInfo& latency_info) {
403 bool consumed = false; 386 bool consumed = false;
404 387
405 InputEventAckState filter_ack = 388 InputEventAckState filter_ack =
406 client_->FilterInputEvent(input_event, latency_info); 389 client_->FilterInputEvent(input_event, latency_info);
407 switch (filter_ack) { 390 switch (filter_ack) {
408 case INPUT_EVENT_ACK_STATE_CONSUMED: 391 case INPUT_EVENT_ACK_STATE_CONSUMED:
409 case INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS: 392 case INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS:
410 // Send the ACK and early exit. 393 // Send the ACK and early exit.
411 next_mouse_move_.reset();
412 ProcessInputEventAck( 394 ProcessInputEventAck(
413 input_event.type, filter_ack, latency_info, 395 input_event.type, filter_ack, latency_info,
414 WebInputEventTraits::GetUniqueTouchEventId(input_event), CLIENT); 396 WebInputEventTraits::GetUniqueTouchEventId(input_event), CLIENT);
415 // WARNING: |this| may be deleted at this point. 397 // WARNING: |this| may be deleted at this point.
416 consumed = true; 398 consumed = true;
417 break; 399 break;
418 case INPUT_EVENT_ACK_STATE_UNKNOWN: 400 case INPUT_EVENT_ACK_STATE_UNKNOWN:
419 // Simply drop the event. 401 // Simply drop the event.
420 consumed = true; 402 consumed = true;
421 break; 403 break;
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 // TODO(jdduke): crbug.com/274029 - Make ack-triggered shutdown async. 566 // TODO(jdduke): crbug.com/274029 - Make ack-triggered shutdown async.
585 } 567 }
586 } 568 }
587 569
588 void InputRouterImpl::ProcessMouseAck(blink::WebInputEvent::Type type, 570 void InputRouterImpl::ProcessMouseAck(blink::WebInputEvent::Type type,
589 InputEventAckState ack_result, 571 InputEventAckState ack_result,
590 const ui::LatencyInfo& latency) { 572 const ui::LatencyInfo& latency) {
591 if (type != WebInputEvent::MouseMove) 573 if (type != WebInputEvent::MouseMove)
592 return; 574 return;
593 575
594 current_mouse_move_.latency.AddNewLatencyFrom(latency); 576 if (mouse_move_queue_.empty()) {
595 ack_handler_->OnMouseEventAck(current_mouse_move_, ack_result); 577 ack_handler_->OnUnexpectedEventAck(InputAckHandler::UNEXPECTED_ACK);
596 578 } else {
597 DCHECK(mouse_move_pending_); 579 MouseEventWithLatencyInfo front_item = mouse_move_queue_.front();
598 mouse_move_pending_ = false; 580 front_item.latency.AddNewLatencyFrom(latency);
599 581 mouse_move_queue_.pop_front();
600 if (next_mouse_move_) { 582 ack_handler_->OnMouseEventAck(front_item, ack_result);
601 DCHECK(next_mouse_move_->event.type == WebInputEvent::MouseMove);
602 std::unique_ptr<MouseEventWithLatencyInfo> next_mouse_move =
603 std::move(next_mouse_move_);
604 SendMouseEvent(*next_mouse_move);
605 } 583 }
606 } 584 }
607 585
608 void InputRouterImpl::ProcessWheelAck(InputEventAckState ack_result, 586 void InputRouterImpl::ProcessWheelAck(InputEventAckState ack_result,
609 const ui::LatencyInfo& latency) { 587 const ui::LatencyInfo& latency) {
610 wheel_event_queue_.ProcessMouseWheelAck(ack_result, latency); 588 wheel_event_queue_.ProcessMouseWheelAck(ack_result, latency);
611 } 589 }
612 590
613 void InputRouterImpl::ProcessGestureAck(WebInputEvent::Type type, 591 void InputRouterImpl::ProcessGestureAck(WebInputEvent::Type type,
614 InputEventAckState ack_result, 592 InputEventAckState ack_result,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 626
649 flush_requested_ = false; 627 flush_requested_ = false;
650 client_->DidFlush(); 628 client_->DidFlush();
651 } 629 }
652 630
653 void InputRouterImpl::SetFrameTreeNodeId(int frameTreeNodeId) { 631 void InputRouterImpl::SetFrameTreeNodeId(int frameTreeNodeId) {
654 frame_tree_node_id_ = frameTreeNodeId; 632 frame_tree_node_id_ = frameTreeNodeId;
655 } 633 }
656 634
657 } // namespace content 635 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698