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 #include "content/renderer/render_widget.h" | 12 #include "content/renderer/render_widget.h" |
13 | 13 |
14 namespace content { | 14 namespace content { |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 const size_t kTenSeconds = 10 * 1000 * 1000; | 18 const size_t kTenSeconds = 10 * 1000 * 1000; |
| 19 const base::TimeDelta kMaxRafDelay = |
| 20 base::TimeDelta::FromMilliseconds(5 * 1000); |
19 | 21 |
20 class QueuedClosure : public MainThreadEventQueueTask { | 22 class QueuedClosure : public MainThreadEventQueueTask { |
21 public: | 23 public: |
22 QueuedClosure(const base::Closure& closure) : closure_(closure) {} | 24 QueuedClosure(const base::Closure& closure) : closure_(closure) {} |
23 | 25 |
24 ~QueuedClosure() override {} | 26 ~QueuedClosure() override {} |
25 | 27 |
26 FilterResult FilterNewEvent( | 28 FilterResult FilterNewEvent( |
27 const MainThreadEventQueueTask& other_task) override { | 29 const MainThreadEventQueueTask& other_task) override { |
28 return other_task.IsWebInputEvent() ? FilterResult::KeepIterating | 30 return other_task.IsWebInputEvent() ? FilterResult::KeepIterating |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 return false; | 401 return false; |
400 const QueuedWebInputEvent* event = | 402 const QueuedWebInputEvent* event = |
401 static_cast<const QueuedWebInputEvent*>(queued_item.get()); | 403 static_cast<const QueuedWebInputEvent*>(queued_item.get()); |
402 if (event->event().GetType() != blink::WebInputEvent::kTouchMove) | 404 if (event->event().GetType() != blink::WebInputEvent::kTouchMove) |
403 return false; | 405 return false; |
404 const blink::WebTouchEvent& touch_event = | 406 const blink::WebTouchEvent& touch_event = |
405 static_cast<const blink::WebTouchEvent&>(event->event()); | 407 static_cast<const blink::WebTouchEvent&>(event->event()); |
406 return touch_event.moved_beyond_slop_region && !event->originallyCancelable(); | 408 return touch_event.moved_beyond_slop_region && !event->originallyCancelable(); |
407 } | 409 } |
408 | 410 |
| 411 void MainThreadEventQueue::RafFallbackTimerFired() { |
| 412 UMA_HISTOGRAM_BOOLEAN("Event.MainThreadEventQueue.FlushQueueNoBeginMainFrame", |
| 413 true); |
| 414 DispatchRafAlignedInput(base::TimeTicks::Now()); |
| 415 } |
| 416 |
409 void MainThreadEventQueue::DispatchRafAlignedInput(base::TimeTicks frame_time) { | 417 void MainThreadEventQueue::DispatchRafAlignedInput(base::TimeTicks frame_time) { |
410 if (IsRafAlignedInputDisabled()) | 418 if (IsRafAlignedInputDisabled()) |
411 return; | 419 return; |
412 | 420 |
| 421 raf_fallback_timer_.Stop(); |
413 size_t queue_size_at_start; | 422 size_t queue_size_at_start; |
414 | 423 |
415 // Record the queue size so that we only process | 424 // Record the queue size so that we only process |
416 // that maximum number of events. | 425 // that maximum number of events. |
417 { | 426 { |
418 base::AutoLock lock(shared_state_lock_); | 427 base::AutoLock lock(shared_state_lock_); |
419 shared_state_.sent_main_frame_request_ = false; | 428 shared_state_.sent_main_frame_request_ = false; |
420 queue_size_at_start = shared_state_.events_.size(); | 429 queue_size_at_start = shared_state_.events_.size(); |
421 } | 430 } |
422 | 431 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 if (renderer_scheduler_) { | 531 if (renderer_scheduler_) { |
523 renderer_scheduler_->DidHandleInputEventOnMainThread( | 532 renderer_scheduler_->DidHandleInputEventOnMainThread( |
524 event, ack_result == INPUT_EVENT_ACK_STATE_CONSUMED | 533 event, ack_result == INPUT_EVENT_ACK_STATE_CONSUMED |
525 ? blink::WebInputEventResult::kHandledApplication | 534 ? blink::WebInputEventResult::kHandledApplication |
526 : blink::WebInputEventResult::kNotHandled); | 535 : blink::WebInputEventResult::kNotHandled); |
527 } | 536 } |
528 } | 537 } |
529 | 538 |
530 void MainThreadEventQueue::SetNeedsMainFrame() { | 539 void MainThreadEventQueue::SetNeedsMainFrame() { |
531 if (main_task_runner_->BelongsToCurrentThread()) { | 540 if (main_task_runner_->BelongsToCurrentThread()) { |
| 541 raf_fallback_timer_.Start( |
| 542 FROM_HERE, kMaxRafDelay, |
| 543 base::Bind(&MainThreadEventQueue::RafFallbackTimerFired, this)); |
532 if (client_) | 544 if (client_) |
533 client_->SetNeedsMainFrame(); | 545 client_->SetNeedsMainFrame(); |
534 return; | 546 return; |
535 } | 547 } |
536 | 548 |
537 main_task_runner_->PostTask( | 549 main_task_runner_->PostTask( |
538 FROM_HERE, base::Bind(&MainThreadEventQueue::SetNeedsMainFrame, this)); | 550 FROM_HERE, base::Bind(&MainThreadEventQueue::SetNeedsMainFrame, this)); |
539 } | 551 } |
540 | 552 |
541 void MainThreadEventQueue::ClearClient() { | 553 void MainThreadEventQueue::ClearClient() { |
542 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 554 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
543 client_ = nullptr; | 555 client_ = nullptr; |
544 } | 556 } |
545 | 557 |
546 } // namespace content | 558 } // namespace content |
OLD | NEW |