Chromium Code Reviews| 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/field_trial.h" | 7 #include "base/metrics/field_trial.h" |
| 8 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "content/common/input/event_with_latency_info.h" | 10 #include "content/common/input/event_with_latency_info.h" |
| 11 #include "content/common/input_messages.h" | 11 #include "content/common/input_messages.h" |
| 12 | 12 |
| 13 namespace content { | 13 namespace content { |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 const size_t kTenSeconds = 10 * 1000 * 1000; | 17 const size_t kTenSeconds = 10 * 1000 * 1000; |
| 18 | 18 |
| 19 class QueuedClosure : public MainThreadEventQueueTask { | 19 class QueuedClosure : public MainThreadEventQueueTask { |
| 20 public: | 20 public: |
| 21 QueuedClosure(const base::Closure& closure) : closure_(closure) {} | 21 QueuedClosure(const base::Closure& closure) : closure_(closure) {} |
| 22 | 22 |
| 23 ~QueuedClosure() override {} | 23 ~QueuedClosure() override {} |
| 24 | 24 |
| 25 CoalesceResult CoalesceWith( | 25 FilterResult FilterNewEvent( |
| 26 const MainThreadEventQueueTask& other_task) override { | 26 const MainThreadEventQueueTask& other_task) override { |
| 27 return other_task.IsWebInputEvent() ? CoalesceResult::KeepSearching | 27 return other_task.IsWebInputEvent() ? FilterResult::KeepIterating |
| 28 : CoalesceResult::CannotCoalesce; | 28 : FilterResult::StopIterating; |
| 29 } | 29 } |
| 30 | 30 |
| 31 bool IsWebInputEvent() const override { return false; } | 31 bool IsWebInputEvent() const override { return false; } |
| 32 | 32 |
| 33 void Dispatch(int routing_id, MainThreadEventQueueClient*) override { | 33 void Dispatch(int routing_id, MainThreadEventQueueClient*) override { |
| 34 closure_.Run(); | 34 closure_.Run(); |
| 35 } | 35 } |
| 36 | 36 |
| 37 void EventHandled(int routing_id, | 37 void EventHandled(int routing_id, |
| 38 blink::scheduler::RendererScheduler* renderer_scheduler, | 38 blink::scheduler::RendererScheduler* renderer_scheduler, |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 54 bool originally_cancelable) | 54 bool originally_cancelable) |
| 55 : ScopedWebInputEventWithLatencyInfo(std::move(event), latency), | 55 : ScopedWebInputEventWithLatencyInfo(std::move(event), latency), |
| 56 dispatch_type_(dispatch_type), | 56 dispatch_type_(dispatch_type), |
| 57 non_blocking_coalesced_count_(0), | 57 non_blocking_coalesced_count_(0), |
| 58 creation_timestamp_(base::TimeTicks::Now()), | 58 creation_timestamp_(base::TimeTicks::Now()), |
| 59 last_coalesced_timestamp_(creation_timestamp_), | 59 last_coalesced_timestamp_(creation_timestamp_), |
| 60 originally_cancelable_(originally_cancelable) {} | 60 originally_cancelable_(originally_cancelable) {} |
| 61 | 61 |
| 62 ~QueuedWebInputEvent() override {} | 62 ~QueuedWebInputEvent() override {} |
| 63 | 63 |
| 64 CoalesceResult CoalesceWith( | 64 FilterResult FilterNewEvent( |
| 65 const MainThreadEventQueueTask& other_item) override { | 65 const MainThreadEventQueueTask& other_task) override { |
| 66 if (!other_item.IsWebInputEvent()) | 66 if (!other_task.IsWebInputEvent()) |
| 67 return CoalesceResult::CannotCoalesce; | 67 return FilterResult::StopIterating; |
| 68 | 68 |
| 69 const QueuedWebInputEvent& other_event = | 69 const QueuedWebInputEvent& other_event = |
| 70 static_cast<const QueuedWebInputEvent&>(other_item); | 70 static_cast<const QueuedWebInputEvent&>(other_task); |
| 71 if (other_event.event().type() == | |
| 72 blink::WebInputEvent::TouchScrollStarted) { | |
| 73 return HandleTouchScrollStartQueued(); | |
| 74 } | |
| 75 | |
| 71 if (!event().isSameEventClass(other_event.event())) | 76 if (!event().isSameEventClass(other_event.event())) |
| 72 return CoalesceResult::KeepSearching; | 77 return FilterResult::KeepIterating; |
| 73 | 78 |
| 74 if (!ScopedWebInputEventWithLatencyInfo::CanCoalesceWith(other_event)) | 79 if (!ScopedWebInputEventWithLatencyInfo::CanCoalesceWith(other_event)) |
| 75 return CoalesceResult::CannotCoalesce; | 80 return FilterResult::StopIterating; |
| 76 | 81 |
| 77 // If this event was blocking push the event id to the blocking | 82 // If this event was blocking push the event id to the blocking |
| 78 // list before updating the dispatch_type of this event. | 83 // list before updating the dispatch_type of this event. |
| 79 if (dispatch_type_ == DISPATCH_TYPE_BLOCKING) { | 84 if (dispatch_type_ == DISPATCH_TYPE_BLOCKING) { |
| 80 blocking_coalesced_event_ids_.push_back( | 85 blocking_coalesced_event_ids_.push_back( |
| 81 ui::WebInputEventTraits::GetUniqueTouchEventId(event())); | 86 ui::WebInputEventTraits::GetUniqueTouchEventId(event())); |
| 82 } else { | 87 } else { |
| 83 non_blocking_coalesced_count_++; | 88 non_blocking_coalesced_count_++; |
| 84 } | 89 } |
| 85 ScopedWebInputEventWithLatencyInfo::CoalesceWith(other_event); | 90 ScopedWebInputEventWithLatencyInfo::CoalesceWith(other_event); |
| 86 last_coalesced_timestamp_ = base::TimeTicks::Now(); | 91 last_coalesced_timestamp_ = base::TimeTicks::Now(); |
| 87 | 92 |
| 88 // The newest event (|other_item|) always wins when updating fields. | 93 // The newest event (|other_item|) always wins when updating fields. |
| 89 dispatch_type_ = other_event.dispatch_type_; | 94 dispatch_type_ = other_event.dispatch_type_; |
| 90 originally_cancelable_ = other_event.originally_cancelable_; | 95 originally_cancelable_ = other_event.originally_cancelable_; |
| 91 | 96 |
| 92 return CoalesceResult::Coalesced; | 97 return FilterResult::PreventQueuingEvent; |
|
tdresser
2017/03/31 20:50:20
It seems a bit weird to me that we consider coales
dtapuska
2017/03/31 21:06:10
Done.
| |
| 93 } | 98 } |
| 94 | 99 |
| 95 bool IsWebInputEvent() const override { return true; } | 100 bool IsWebInputEvent() const override { return true; } |
| 96 | 101 |
| 97 void Dispatch(int routing_id, MainThreadEventQueueClient* client) override { | 102 void Dispatch(int routing_id, MainThreadEventQueueClient* client) override { |
| 98 // Report the coalesced count only for continuous events; otherwise | 103 // Report the coalesced count only for continuous events; otherwise |
| 99 // the zero value would be dominated by non-continuous events. | 104 // the zero value would be dominated by non-continuous events. |
| 100 base::TimeTicks now = base::TimeTicks::Now(); | 105 base::TimeTicks now = base::TimeTicks::Now(); |
| 101 if (IsContinuousEvent()) { | 106 if (IsContinuousEvent()) { |
| 102 UMA_HISTOGRAM_CUSTOM_COUNTS( | 107 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 client->SendInputEventAck(routing_id, type, ack_result, id); | 148 client->SendInputEventAck(routing_id, type, ack_result, id); |
| 144 if (renderer_scheduler) { | 149 if (renderer_scheduler) { |
| 145 renderer_scheduler->DidHandleInputEventOnMainThread(event(), result); | 150 renderer_scheduler->DidHandleInputEventOnMainThread(event(), result); |
| 146 } | 151 } |
| 147 } | 152 } |
| 148 } | 153 } |
| 149 | 154 |
| 150 bool originallyCancelable() const { return originally_cancelable_; } | 155 bool originallyCancelable() const { return originally_cancelable_; } |
| 151 | 156 |
| 152 private: | 157 private: |
| 158 FilterResult HandleTouchScrollStartQueued() { | |
| 159 // A TouchScrollStart will queued after this touch move which will make all | |
| 160 // previous touch moves that are queued uncancelable. | |
| 161 switch (event().type()) { | |
| 162 case blink::WebInputEvent::TouchMove: { | |
| 163 blink::WebTouchEvent& touch_event = | |
| 164 static_cast<blink::WebTouchEvent&>(event()); | |
| 165 if (touch_event.dispatchType == | |
| 166 blink::WebInputEvent::DispatchType::Blocking) { | |
| 167 touch_event.dispatchType = | |
| 168 blink::WebInputEvent::DispatchType::EventNonBlocking; | |
| 169 } | |
| 170 return FilterResult::KeepIterating; | |
| 171 } | |
| 172 case blink::WebInputEvent::TouchStart: | |
| 173 case blink::WebInputEvent::TouchEnd: | |
| 174 return FilterResult::StopIterating; | |
| 175 default: | |
| 176 return FilterResult::KeepIterating; | |
| 177 } | |
| 178 } | |
| 179 | |
| 153 const std::deque<uint32_t>& blockingCoalescedEventIds() const { | 180 const std::deque<uint32_t>& blockingCoalescedEventIds() const { |
| 154 return blocking_coalesced_event_ids_; | 181 return blocking_coalesced_event_ids_; |
| 155 } | 182 } |
| 156 InputEventDispatchType dispatchType() const { return dispatch_type_; } | 183 InputEventDispatchType dispatchType() const { return dispatch_type_; } |
| 157 base::TimeTicks creationTimestamp() const { return creation_timestamp_; } | 184 base::TimeTicks creationTimestamp() const { return creation_timestamp_; } |
| 158 base::TimeTicks lastCoalescedTimestamp() const { | 185 base::TimeTicks lastCoalescedTimestamp() const { |
| 159 return last_coalesced_timestamp_; | 186 return last_coalesced_timestamp_; |
| 160 } | 187 } |
| 161 | 188 |
| 162 size_t coalescedCount() const { | 189 size_t coalescedCount() const { |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 502 case blink::WebInputEvent::MouseWheel: | 529 case blink::WebInputEvent::MouseWheel: |
| 503 return handle_raf_aligned_mouse_input_; | 530 return handle_raf_aligned_mouse_input_; |
| 504 case blink::WebInputEvent::TouchMove: | 531 case blink::WebInputEvent::TouchMove: |
| 505 return handle_raf_aligned_touch_input_; | 532 return handle_raf_aligned_touch_input_; |
| 506 default: | 533 default: |
| 507 return false; | 534 return false; |
| 508 } | 535 } |
| 509 } | 536 } |
| 510 | 537 |
| 511 } // namespace content | 538 } // namespace content |
| OLD | NEW |