| OLD | NEW |
| 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->event().type) { |
| 19 case blink::WebInputEvent::MouseMove: | 19 case blink::WebInputEvent::MouseMove: |
| 20 case blink::WebInputEvent::MouseWheel: | 20 case blink::WebInputEvent::MouseWheel: |
| 21 case blink::WebInputEvent::TouchMove: |
| 21 return true; | 22 return true; |
| 22 case blink::WebInputEvent::TouchMove: | |
| 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 | |
| 25 // additional frame. | |
| 26 return static_cast<const blink::WebTouchEvent&>(event->event()) | |
| 27 .dispatchType != blink::WebInputEvent::Blocking; | |
| 28 default: | 23 default: |
| 29 return false; | 24 return false; |
| 30 } | 25 } |
| 31 } | 26 } |
| 32 | 27 |
| 33 } // namespace | 28 } // namespace |
| 34 | 29 |
| 35 EventWithDispatchType::EventWithDispatchType( | 30 EventWithDispatchType::EventWithDispatchType( |
| 36 ui::ScopedWebInputEvent event, | 31 ui::ScopedWebInputEvent event, |
| 37 const ui::LatencyInfo& latency, | 32 const ui::LatencyInfo& latency, |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 // touch move should also be passive. | 113 // touch move should also be passive. |
| 119 if (ack_result == INPUT_EVENT_ACK_STATE_SET_NON_BLOCKING_DUE_TO_FLING || | 114 if (ack_result == INPUT_EVENT_ACK_STATE_SET_NON_BLOCKING_DUE_TO_FLING || |
| 120 last_touch_start_forced_nonblocking_due_to_fling_) { | 115 last_touch_start_forced_nonblocking_due_to_fling_) { |
| 121 touch_event->dispatchType = | 116 touch_event->dispatchType = |
| 122 blink::WebInputEvent::ListenersForcedNonBlockingDueToFling; | 117 blink::WebInputEvent::ListenersForcedNonBlockingDueToFling; |
| 123 non_blocking = true; | 118 non_blocking = true; |
| 124 last_touch_start_forced_nonblocking_due_to_fling_ = true; | 119 last_touch_start_forced_nonblocking_due_to_fling_ = true; |
| 125 } | 120 } |
| 126 } | 121 } |
| 127 | 122 |
| 128 // If handling rAF aligned touch input ACK non-cancelable events right | |
| 129 // away. | |
| 130 if (!non_blocking && IsRafAlignedEvent(*touch_event)) | |
| 131 non_blocking = true; | |
| 132 | |
| 133 if (enable_non_blocking_due_to_main_thread_responsiveness_flag_ && | 123 if (enable_non_blocking_due_to_main_thread_responsiveness_flag_ && |
| 134 touch_event->dispatchType == blink::WebInputEvent::Blocking) { | 124 touch_event->dispatchType == blink::WebInputEvent::Blocking) { |
| 135 bool passive_due_to_unresponsive_main = | 125 bool passive_due_to_unresponsive_main = |
| 136 renderer_scheduler_->MainThreadSeemsUnresponsive(); | 126 renderer_scheduler_->MainThreadSeemsUnresponsive(); |
| 137 if (passive_due_to_unresponsive_main) { | 127 if (passive_due_to_unresponsive_main) { |
| 138 touch_event->dispatchType = blink::WebInputEvent:: | 128 touch_event->dispatchType = blink::WebInputEvent:: |
| 139 ListenersForcedNonBlockingDueToMainThreadResponsiveness; | 129 ListenersForcedNonBlockingDueToMainThreadResponsiveness; |
| 140 non_blocking = true; | 130 non_blocking = true; |
| 141 } | 131 } |
| 142 } | 132 } |
| 133 // If the event is non-cancelable ACK it right away. |
| 134 if (!non_blocking && |
| 135 touch_event->dispatchType != blink::WebInputEvent::Blocking) |
| 136 non_blocking = true; |
| 143 } | 137 } |
| 138 |
| 144 if (is_wheel && non_blocking) { | 139 if (is_wheel && non_blocking) { |
| 145 // Adjust the |dispatchType| on the event since the compositor | 140 // Adjust the |dispatchType| on the event since the compositor |
| 146 // determined all event listeners are passive. | 141 // determined all event listeners are passive. |
| 147 static_cast<blink::WebMouseWheelEvent*>(event.get()) | 142 static_cast<blink::WebMouseWheelEvent*>(event.get()) |
| 148 ->dispatchType = blink::WebInputEvent::ListenersNonBlockingPassive; | 143 ->dispatchType = blink::WebInputEvent::ListenersNonBlockingPassive; |
| 149 } | 144 } |
| 150 | 145 |
| 151 InputEventDispatchType dispatch_type = | 146 InputEventDispatchType dispatch_type = |
| 152 non_blocking ? DISPATCH_TYPE_NON_BLOCKING : DISPATCH_TYPE_BLOCKING; | 147 non_blocking ? DISPATCH_TYPE_NON_BLOCKING : DISPATCH_TYPE_BLOCKING; |
| 153 | 148 |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 return !handle_raf_aligned_mouse_input_ && !handle_raf_aligned_touch_input_; | 328 return !handle_raf_aligned_mouse_input_ && !handle_raf_aligned_touch_input_; |
| 334 } | 329 } |
| 335 | 330 |
| 336 bool MainThreadEventQueue::IsRafAlignedEvent( | 331 bool MainThreadEventQueue::IsRafAlignedEvent( |
| 337 const blink::WebInputEvent& event) { | 332 const blink::WebInputEvent& event) { |
| 338 switch (event.type) { | 333 switch (event.type) { |
| 339 case blink::WebInputEvent::MouseMove: | 334 case blink::WebInputEvent::MouseMove: |
| 340 case blink::WebInputEvent::MouseWheel: | 335 case blink::WebInputEvent::MouseWheel: |
| 341 return handle_raf_aligned_mouse_input_; | 336 return handle_raf_aligned_mouse_input_; |
| 342 case blink::WebInputEvent::TouchMove: | 337 case blink::WebInputEvent::TouchMove: |
| 343 // TouchMoves that are blocking end up blocking scroll. Do not treat | 338 return handle_raf_aligned_touch_input_; |
| 344 // them as continuous events otherwise we will end up waiting up to an | |
| 345 // additional frame. | |
| 346 return static_cast<const blink::WebTouchEvent&>(event).dispatchType != | |
| 347 blink::WebInputEvent::Blocking && | |
| 348 handle_raf_aligned_touch_input_; | |
| 349 default: | 339 default: |
| 350 return false; | 340 return false; |
| 351 } | 341 } |
| 352 } | 342 } |
| 353 | 343 |
| 354 } // namespace content | 344 } // namespace content |
| OLD | NEW |