Chromium Code Reviews| Index: content/renderer/input/main_thread_event_queue.cc |
| diff --git a/content/renderer/input/main_thread_event_queue.cc b/content/renderer/input/main_thread_event_queue.cc |
| index 241c0bcb0b11b38f91044f4e0ac50f1c2d949b2e..522e39c23aae839afba4e34e5a07b8648d990e45 100644 |
| --- a/content/renderer/input/main_thread_event_queue.cc |
| +++ b/content/renderer/input/main_thread_event_queue.cc |
| @@ -414,25 +414,36 @@ void MainThreadEventQueue::PossiblyScheduleMainFrame() { |
| } |
| void MainThreadEventQueue::DispatchEvents() { |
| - std::deque<std::unique_ptr<MainThreadEventQueueTask>> events_to_process; |
| + size_t queue_size_at_start; |
| + |
| + // Record the queue size so that we only process |
| + // that maximum number of events. |
| { |
| base::AutoLock lock(shared_state_lock_); |
| shared_state_.sent_post_task_ = false; |
| + queue_size_at_start = shared_state_.events_.size(); |
| + } |
| - shared_state_.events_.swap(&events_to_process); |
| + while (queue_size_at_start--) { |
| + { |
| + base::AutoLock lock(shared_state_lock_); |
| - // Now take any raf aligned events that are at the tail of the queue |
| - // and put them back. |
| - while (!events_to_process.empty()) { |
| - if (!IsRafAlignedEvent(events_to_process.back())) |
| + // If all the events are rAF aligned we won't process them |
| + // now, wait until the rAF signal. |
| + bool all_raf_aligned = true; |
| + for (size_t i = 0; i < shared_state_.events_.size(); ++i) { |
|
mustaq
2017/04/04 14:59:22
The use of .size() here seems suspicious: since we
dtapuska
2017/04/04 15:27:45
Done.
|
| + if (!IsRafAlignedEvent(shared_state_.events_.at(i))) { |
| + all_raf_aligned = false; |
| + break; |
| + } |
| + } |
| + if (all_raf_aligned) |
| break; |
| - shared_state_.events_.emplace_front(std::move(events_to_process.back())); |
| - events_to_process.pop_back(); |
| + |
| + in_flight_event_ = shared_state_.events_.Pop(); |
| } |
| - } |
| - while (!events_to_process.empty()) { |
| - in_flight_event_ = std::move(events_to_process.front()); |
| - events_to_process.pop_front(); |
| + |
| + // Dispatching the event is outside of critical section. |
| DispatchInFlightEvent(); |
| } |
| PossiblyScheduleMainFrame(); |
| @@ -451,12 +462,23 @@ void MainThreadEventQueue::DispatchRafAlignedInput(base::TimeTicks frame_time) { |
| if (IsRafAlignedInputDisabled()) |
| return; |
| - std::deque<std::unique_ptr<MainThreadEventQueueTask>> events_to_process; |
| + size_t queue_size_at_start; |
| + |
| + // Record the queue size so that we only process |
| + // that maximum number of events. |
| { |
| base::AutoLock lock(shared_state_lock_); |
| shared_state_.sent_main_frame_request_ = false; |
| + queue_size_at_start = shared_state_.events_.size(); |
| + } |
| + |
| + while (queue_size_at_start--) { |
| + { |
| + base::AutoLock lock(shared_state_lock_); |
| + |
| + if (shared_state_.events_.empty()) |
| + return; |
| - while (!shared_state_.events_.empty()) { |
| if (IsRafAlignedEvent(shared_state_.events_.front())) { |
| // Throttle touchmoves that are async. |
| if (handle_raf_aligned_touch_input_ && |
| @@ -469,15 +491,13 @@ void MainThreadEventQueue::DispatchRafAlignedInput(base::TimeTicks frame_time) { |
| shared_state_.last_async_touch_move_timestamp_ = frame_time; |
| } |
| } |
| - events_to_process.emplace_back(shared_state_.events_.Pop()); |
| + in_flight_event_ = shared_state_.events_.Pop(); |
| } |
| - } |
| - while(!events_to_process.empty()) { |
| - in_flight_event_ = std::move(events_to_process.front()); |
| - events_to_process.pop_front(); |
| + // Dispatching the event is outside of critical section. |
| DispatchInFlightEvent(); |
| } |
| + |
| PossiblyScheduleMainFrame(); |
| } |