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

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

Issue 2835193002: Get rid of the in_flight_event. (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 | « content/renderer/input/main_thread_event_queue.h ('k') | no next file » | 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 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 base::AutoLock lock(shared_state_lock_); 337 base::AutoLock lock(shared_state_lock_);
338 shared_state_.events_.Queue(std::move(item)); 338 shared_state_.events_.Queue(std::move(item));
339 needs_post_task = !shared_state_.sent_post_task_; 339 needs_post_task = !shared_state_.sent_post_task_;
340 shared_state_.sent_post_task_ = true; 340 shared_state_.sent_post_task_ = true;
341 } 341 }
342 342
343 if (needs_post_task) 343 if (needs_post_task)
344 PostTaskToMainThread(); 344 PostTaskToMainThread();
345 } 345 }
346 346
347 void MainThreadEventQueue::DispatchInFlightEvent() {
348 if (in_flight_event_) {
349 in_flight_event_->Dispatch(this);
350 in_flight_event_.reset();
351 }
352 }
353
354 void MainThreadEventQueue::PossiblyScheduleMainFrame() { 347 void MainThreadEventQueue::PossiblyScheduleMainFrame() {
355 if (IsRafAlignedInputDisabled()) 348 if (IsRafAlignedInputDisabled())
356 return; 349 return;
357 bool needs_main_frame = false; 350 bool needs_main_frame = false;
358 { 351 {
359 base::AutoLock lock(shared_state_lock_); 352 base::AutoLock lock(shared_state_lock_);
360 if (!shared_state_.sent_main_frame_request_ && 353 if (!shared_state_.sent_main_frame_request_ &&
361 !shared_state_.events_.empty() && 354 !shared_state_.events_.empty() &&
362 IsRafAlignedEvent(shared_state_.events_.front())) { 355 IsRafAlignedEvent(shared_state_.events_.front())) {
363 needs_main_frame = true; 356 needs_main_frame = true;
(...skipping 15 matching lines...) Expand all
379 events_to_process = shared_state_.events_.size(); 372 events_to_process = shared_state_.events_.size();
380 373
381 // Don't process rAF aligned events at tail of queue. 374 // Don't process rAF aligned events at tail of queue.
382 while (events_to_process > 0 && 375 while (events_to_process > 0 &&
383 IsRafAlignedEvent(shared_state_.events_.at(events_to_process - 1))) { 376 IsRafAlignedEvent(shared_state_.events_.at(events_to_process - 1))) {
384 --events_to_process; 377 --events_to_process;
385 } 378 }
386 } 379 }
387 380
388 while (events_to_process--) { 381 while (events_to_process--) {
382 std::unique_ptr<MainThreadEventQueueTask> task;
389 { 383 {
390 base::AutoLock lock(shared_state_lock_); 384 base::AutoLock lock(shared_state_lock_);
391 if (shared_state_.events_.empty()) 385 if (shared_state_.events_.empty())
392 return; 386 return;
393 in_flight_event_ = shared_state_.events_.Pop(); 387 task = shared_state_.events_.Pop();
394 } 388 }
395 389
396 // Dispatching the event is outside of critical section. 390 // Dispatching the event is outside of critical section.
397 DispatchInFlightEvent(); 391 task->Dispatch(this);
398 } 392 }
399 PossiblyScheduleMainFrame(); 393 PossiblyScheduleMainFrame();
400 } 394 }
401 395
402 static bool IsAsyncTouchMove( 396 static bool IsAsyncTouchMove(
403 const std::unique_ptr<MainThreadEventQueueTask>& queued_item) { 397 const std::unique_ptr<MainThreadEventQueueTask>& queued_item) {
404 if (!queued_item->IsWebInputEvent()) 398 if (!queued_item->IsWebInputEvent())
405 return false; 399 return false;
406 const QueuedWebInputEvent* event = 400 const QueuedWebInputEvent* event =
407 static_cast<const QueuedWebInputEvent*>(queued_item.get()); 401 static_cast<const QueuedWebInputEvent*>(queued_item.get());
(...skipping 12 matching lines...) Expand all
420 414
421 // Record the queue size so that we only process 415 // Record the queue size so that we only process
422 // that maximum number of events. 416 // that maximum number of events.
423 { 417 {
424 base::AutoLock lock(shared_state_lock_); 418 base::AutoLock lock(shared_state_lock_);
425 shared_state_.sent_main_frame_request_ = false; 419 shared_state_.sent_main_frame_request_ = false;
426 queue_size_at_start = shared_state_.events_.size(); 420 queue_size_at_start = shared_state_.events_.size();
427 } 421 }
428 422
429 while (queue_size_at_start--) { 423 while (queue_size_at_start--) {
424 std::unique_ptr<MainThreadEventQueueTask> task;
430 { 425 {
431 base::AutoLock lock(shared_state_lock_); 426 base::AutoLock lock(shared_state_lock_);
432 427
433 if (shared_state_.events_.empty()) 428 if (shared_state_.events_.empty())
434 return; 429 return;
435 430
436 if (IsRafAlignedEvent(shared_state_.events_.front())) { 431 if (IsRafAlignedEvent(shared_state_.events_.front())) {
437 // Throttle touchmoves that are async. 432 // Throttle touchmoves that are async.
438 if (handle_raf_aligned_touch_input_ && 433 if (handle_raf_aligned_touch_input_ &&
439 IsAsyncTouchMove(shared_state_.events_.front())) { 434 IsAsyncTouchMove(shared_state_.events_.front())) {
440 if (shared_state_.events_.size() == 1 && 435 if (shared_state_.events_.size() == 1 &&
441 frame_time < shared_state_.last_async_touch_move_timestamp_ + 436 frame_time < shared_state_.last_async_touch_move_timestamp_ +
442 kAsyncTouchMoveInterval) { 437 kAsyncTouchMoveInterval) {
443 break; 438 break;
444 } 439 }
445 shared_state_.last_async_touch_move_timestamp_ = frame_time; 440 shared_state_.last_async_touch_move_timestamp_ = frame_time;
446 } 441 }
447 } 442 }
448 in_flight_event_ = shared_state_.events_.Pop(); 443 task = shared_state_.events_.Pop();
449 } 444 }
450
451 // Dispatching the event is outside of critical section. 445 // Dispatching the event is outside of critical section.
452 DispatchInFlightEvent(); 446 task->Dispatch(this);
453 } 447 }
454 448
455 PossiblyScheduleMainFrame(); 449 PossiblyScheduleMainFrame();
456 } 450 }
457 451
458 void MainThreadEventQueue::PostTaskToMainThread() { 452 void MainThreadEventQueue::PostTaskToMainThread() {
459 main_task_runner_->PostTask( 453 main_task_runner_->PostTask(
460 FROM_HERE, base::Bind(&MainThreadEventQueue::DispatchEvents, this)); 454 FROM_HERE, base::Bind(&MainThreadEventQueue::DispatchEvents, this));
461 } 455 }
462 456
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 main_task_runner_->PostTask( 537 main_task_runner_->PostTask(
544 FROM_HERE, base::Bind(&MainThreadEventQueue::SetNeedsMainFrame, this)); 538 FROM_HERE, base::Bind(&MainThreadEventQueue::SetNeedsMainFrame, this));
545 } 539 }
546 540
547 void MainThreadEventQueue::ClearClient() { 541 void MainThreadEventQueue::ClearClient() {
548 DCHECK(main_task_runner_->BelongsToCurrentThread()); 542 DCHECK(main_task_runner_->BelongsToCurrentThread());
549 client_ = nullptr; 543 client_ = nullptr;
550 } 544 }
551 545
552 } // namespace content 546 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/input/main_thread_event_queue.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698