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

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

Issue 2793963002: Allow events in queue to coalesce while executing other events. (Closed)
Patch Set: Created 3 years, 8 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_task_list.h » ('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/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"
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 void MainThreadEventQueue::PossiblyScheduleMainFrame() { 399 void MainThreadEventQueue::PossiblyScheduleMainFrame() {
400 if (IsRafAlignedInputDisabled()) 400 if (IsRafAlignedInputDisabled())
401 return; 401 return;
402 bool needs_main_frame = false; 402 bool needs_main_frame = false;
403 { 403 {
404 base::AutoLock lock(shared_state_lock_); 404 base::AutoLock lock(shared_state_lock_);
405 if (!shared_state_.sent_main_frame_request_ && 405 if (!shared_state_.sent_main_frame_request_ &&
406 !shared_state_.events_.empty() && 406 !shared_state_.events_.empty() &&
407 IsRafAlignedEvent(shared_state_.events_.front())) { 407 IsRafAlignedEvent(shared_state_.events_.front())) {
408 needs_main_frame = !shared_state_.sent_main_frame_request_; 408 needs_main_frame = !shared_state_.sent_main_frame_request_;
409 shared_state_.sent_main_frame_request_ = false; 409 shared_state_.sent_main_frame_request_ = false;
mustaq 2017/04/04 14:59:22 Just spotted this nit from before: |shared_state_.
dtapuska 2017/04/04 15:27:45 Done.
410 } 410 }
411 } 411 }
412 if (needs_main_frame) 412 if (needs_main_frame)
413 client_->NeedsMainFrame(routing_id_); 413 client_->NeedsMainFrame(routing_id_);
414 } 414 }
415 415
416 void MainThreadEventQueue::DispatchEvents() { 416 void MainThreadEventQueue::DispatchEvents() {
417 std::deque<std::unique_ptr<MainThreadEventQueueTask>> events_to_process; 417 size_t queue_size_at_start;
418
419 // Record the queue size so that we only process
420 // that maximum number of events.
418 { 421 {
419 base::AutoLock lock(shared_state_lock_); 422 base::AutoLock lock(shared_state_lock_);
420 shared_state_.sent_post_task_ = false; 423 shared_state_.sent_post_task_ = false;
424 queue_size_at_start = shared_state_.events_.size();
425 }
421 426
422 shared_state_.events_.swap(&events_to_process); 427 while (queue_size_at_start--) {
428 {
429 base::AutoLock lock(shared_state_lock_);
423 430
424 // Now take any raf aligned events that are at the tail of the queue 431 // If all the events are rAF aligned we won't process them
425 // and put them back. 432 // now, wait until the rAF signal.
426 while (!events_to_process.empty()) { 433 bool all_raf_aligned = true;
427 if (!IsRafAlignedEvent(events_to_process.back())) 434 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.
435 if (!IsRafAlignedEvent(shared_state_.events_.at(i))) {
436 all_raf_aligned = false;
437 break;
438 }
439 }
440 if (all_raf_aligned)
428 break; 441 break;
429 shared_state_.events_.emplace_front(std::move(events_to_process.back())); 442
430 events_to_process.pop_back(); 443 in_flight_event_ = shared_state_.events_.Pop();
431 } 444 }
432 } 445
433 while (!events_to_process.empty()) { 446 // Dispatching the event is outside of critical section.
434 in_flight_event_ = std::move(events_to_process.front());
435 events_to_process.pop_front();
436 DispatchInFlightEvent(); 447 DispatchInFlightEvent();
437 } 448 }
438 PossiblyScheduleMainFrame(); 449 PossiblyScheduleMainFrame();
439 } 450 }
440 451
441 void MainThreadEventQueue::EventHandled(blink::WebInputEvent::Type type, 452 void MainThreadEventQueue::EventHandled(blink::WebInputEvent::Type type,
442 blink::WebInputEventResult result, 453 blink::WebInputEventResult result,
443 InputEventAckState ack_result) { 454 InputEventAckState ack_result) {
444 if (in_flight_event_) { 455 if (in_flight_event_) {
445 in_flight_event_->EventHandled(routing_id_, renderer_scheduler_, client_, 456 in_flight_event_->EventHandled(routing_id_, renderer_scheduler_, client_,
446 type, result, ack_result); 457 type, result, ack_result);
447 } 458 }
448 } 459 }
449 460
450 void MainThreadEventQueue::DispatchRafAlignedInput(base::TimeTicks frame_time) { 461 void MainThreadEventQueue::DispatchRafAlignedInput(base::TimeTicks frame_time) {
451 if (IsRafAlignedInputDisabled()) 462 if (IsRafAlignedInputDisabled())
452 return; 463 return;
453 464
454 std::deque<std::unique_ptr<MainThreadEventQueueTask>> events_to_process; 465 size_t queue_size_at_start;
466
467 // Record the queue size so that we only process
468 // that maximum number of events.
455 { 469 {
456 base::AutoLock lock(shared_state_lock_); 470 base::AutoLock lock(shared_state_lock_);
457 shared_state_.sent_main_frame_request_ = false; 471 shared_state_.sent_main_frame_request_ = false;
472 queue_size_at_start = shared_state_.events_.size();
473 }
458 474
459 while (!shared_state_.events_.empty()) { 475 while (queue_size_at_start--) {
476 {
477 base::AutoLock lock(shared_state_lock_);
478
479 if (shared_state_.events_.empty())
480 return;
481
460 if (IsRafAlignedEvent(shared_state_.events_.front())) { 482 if (IsRafAlignedEvent(shared_state_.events_.front())) {
461 // Throttle touchmoves that are async. 483 // Throttle touchmoves that are async.
462 if (handle_raf_aligned_touch_input_ && 484 if (handle_raf_aligned_touch_input_ &&
463 IsAsyncTouchMove(shared_state_.events_.front())) { 485 IsAsyncTouchMove(shared_state_.events_.front())) {
464 if (shared_state_.events_.size() == 1 && 486 if (shared_state_.events_.size() == 1 &&
465 frame_time < shared_state_.last_async_touch_move_timestamp_ + 487 frame_time < shared_state_.last_async_touch_move_timestamp_ +
466 kAsyncTouchMoveInterval) { 488 kAsyncTouchMoveInterval) {
467 break; 489 break;
468 } 490 }
469 shared_state_.last_async_touch_move_timestamp_ = frame_time; 491 shared_state_.last_async_touch_move_timestamp_ = frame_time;
470 } 492 }
471 } 493 }
472 events_to_process.emplace_back(shared_state_.events_.Pop()); 494 in_flight_event_ = shared_state_.events_.Pop();
473 } 495 }
496
497 // Dispatching the event is outside of critical section.
498 DispatchInFlightEvent();
474 } 499 }
475 500
476 while(!events_to_process.empty()) {
477 in_flight_event_ = std::move(events_to_process.front());
478 events_to_process.pop_front();
479 DispatchInFlightEvent();
480 }
481 PossiblyScheduleMainFrame(); 501 PossiblyScheduleMainFrame();
482 } 502 }
483 503
484 void MainThreadEventQueue::PostTaskToMainThread() { 504 void MainThreadEventQueue::PostTaskToMainThread() {
485 main_task_runner_->PostTask( 505 main_task_runner_->PostTask(
486 FROM_HERE, base::Bind(&MainThreadEventQueue::DispatchEvents, this)); 506 FROM_HERE, base::Bind(&MainThreadEventQueue::DispatchEvents, this));
487 } 507 }
488 508
489 void MainThreadEventQueue::QueueEvent( 509 void MainThreadEventQueue::QueueEvent(
490 std::unique_ptr<MainThreadEventQueueTask> event) { 510 std::unique_ptr<MainThreadEventQueueTask> event) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 case blink::WebInputEvent::MouseWheel: 549 case blink::WebInputEvent::MouseWheel:
530 return handle_raf_aligned_mouse_input_; 550 return handle_raf_aligned_mouse_input_;
531 case blink::WebInputEvent::TouchMove: 551 case blink::WebInputEvent::TouchMove:
532 return handle_raf_aligned_touch_input_; 552 return handle_raf_aligned_touch_input_;
533 default: 553 default:
534 return false; 554 return false;
535 } 555 }
536 } 556 }
537 557
538 } // namespace content 558 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/renderer/input/main_thread_event_queue_task_list.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698