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

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

Issue 2342603003: Don't process more than the queued events during rAF. (Closed)
Patch Set: Created 4 years, 3 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
« no previous file with comments | « no previous file | content/renderer/input/main_thread_event_queue_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // The maximum number of post-coalesced events processed per rAF task. 10 was
16 // chosen because it really should never be hit yet prevents an infinite loop if
17 // the compositor keeps delivering events faster than the main thread can
18 // process them.
19 const size_t kMaxEventsPerRafTask = 10;
20
21 const size_t kTenSeconds = 10 * 1000 * 1000; 15 const size_t kTenSeconds = 10 * 1000 * 1000;
22 16
23 bool isContinuousEvent(const std::unique_ptr<EventWithDispatchType>& event) { 17 bool isContinuousEvent(const std::unique_ptr<EventWithDispatchType>& event) {
24 switch (event->event().type) { 18 switch (event->event().type) {
25 case blink::WebInputEvent::MouseMove: 19 case blink::WebInputEvent::MouseMove:
26 case blink::WebInputEvent::MouseWheel: 20 case blink::WebInputEvent::MouseWheel:
27 return true; 21 return true;
28 case blink::WebInputEvent::TouchMove: 22 case blink::WebInputEvent::TouchMove:
29 // TouchMoves that are blocking end up blocking scroll. Do not treat 23 // TouchMoves that are blocking end up blocking scroll. Do not treat
30 // 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
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 in_flight_event_->event()); 217 in_flight_event_->event());
224 } 218 }
225 } 219 }
226 } 220 }
227 } 221 }
228 222
229 void MainThreadEventQueue::DispatchRafAlignedInput() { 223 void MainThreadEventQueue::DispatchRafAlignedInput() {
230 if (!handle_raf_aligned_input_) 224 if (!handle_raf_aligned_input_)
231 return; 225 return;
232 226
227 std::deque<std::unique_ptr<EventWithDispatchType>> events_to_process;
233 { 228 {
234 base::AutoLock lock(shared_state_lock_); 229 base::AutoLock lock(shared_state_lock_);
235 shared_state_.sent_main_frame_request_ = false; 230 shared_state_.sent_main_frame_request_ = false;
231
232 while(!shared_state_.events_.empty()) {
233 if (!isContinuousEvent(shared_state_.events_.front()))
234 break;
235 events_to_process.emplace_back(shared_state_.events_.Pop());
236 }
236 } 237 }
237 238
238 for (size_t i = 0; i < kMaxEventsPerRafTask; ++i) { 239 while(!events_to_process.empty()) {
239 { 240 in_flight_event_.reset(events_to_process.front().release());
tdresser 2016/09/14 16:33:26 Can we use in_flight_event_ = std::move(events_to
dtapuska 2016/09/14 17:19:31 Done.
240 base::AutoLock lock(shared_state_lock_); 241 events_to_process.pop_front();
241 if (shared_state_.events_.empty())
242 break;
243
244 if (!isContinuousEvent(shared_state_.events_.front()))
245 break;
246 in_flight_event_ = shared_state_.events_.Pop();
247 }
248 DispatchInFlightEvent(); 242 DispatchInFlightEvent();
249 } 243 }
250 PossiblyScheduleMainFrame(); 244 PossiblyScheduleMainFrame();
251 } 245 }
252 246
253 void MainThreadEventQueue::SendEventNotificationToMainThread() { 247 void MainThreadEventQueue::SendEventNotificationToMainThread() {
254 main_task_runner_->PostTask( 248 main_task_runner_->PostTask(
255 FROM_HERE, base::Bind(&MainThreadEventQueue::DispatchSingleEvent, this)); 249 FROM_HERE, base::Bind(&MainThreadEventQueue::DispatchSingleEvent, this));
256 } 250 }
257 251
(...skipping 26 matching lines...) Expand all
284 } 278 }
285 } 279 }
286 } 280 }
287 for (size_t i = 0; i < send_notification_count; ++i) 281 for (size_t i = 0; i < send_notification_count; ++i)
288 SendEventNotificationToMainThread(); 282 SendEventNotificationToMainThread();
289 if (needs_main_frame) 283 if (needs_main_frame)
290 client_->NeedsMainFrame(routing_id_); 284 client_->NeedsMainFrame(routing_id_);
291 } 285 }
292 286
293 } // namespace content 287 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/renderer/input/main_thread_event_queue_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698